Commit graph

2410 commits

Author SHA1 Message Date
Michael Scott 157115c7d8 net: lwm2m: temp_sensor: fix min/max measurement values
Initial values for the min/max measurements were 0 and this caused
issues with sensors maximums that weren't above 0 and minimums that
went below 0.  Let's update those to MAX_INT so the first sensor
value update will set those to correct values.

When resetting the measured values, let's use the current sensor
value not 0.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-11-15 15:31:45 +02:00
Michael Scott 806d8f3baa net: lwm2m: refactor min / max measurement update code
Split out update code to make it re-usable.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-11-15 15:31:45 +02:00
Johan Hedberg c8b51ded29 Bluetooth: Mesh: shell: Fix newline in incorrect place
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:38:54 +01:00
Johan Hedberg d4be608036 Bluetooth: Mesh: Allow changing cfg client message timeout
10 seconds is quite long for configuration messages, and way too much
currently since we only talk through the local networking interface.
Set the default timeout to 2 seconds, and provide APIs through which
the timeout may be changed at run-time (mainly useful for the shell).

Note: The timeout_set() API is normally assumed to be called just once
for an application, based on the expected size of the network (hops &
latency). Trying to change it e.g. in a multi-threaded environment for
every message may not yield the expected results.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 882ce59e97 Bluetooth: Mesh: shell: Convert hb-sub-set command to hb-sub
Convert the hb-ub-set command to a more generic hb-sub that can be
used both for getting and setting the Heartrate Subscription State.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 7b27d96f96 Bluetooth: Mesh: Add support for sending Heartbeat Subscription Get
Add support for sending the Heartrate Subscription Get message.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 135fd92492 Bluetooth: Mesh: shell: Convert hb-pub-set command to hb-pub
Convert the hb-pub-set command to a more generic hb-pub that can be
used both for getting and setting the Heartrate Publication State.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 9bf8af8507 Bluetooth: Mesh: Add support for sending Heartbeat Publication Get
Add support for sending the Heartrate Publication Get message.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 8e9e039700 Bluetooth: Mesh: shell: Implicitly initialize Bluetooth support
Avoid having to go do "init" for the bt module before issuing "init"
for the mesh module. Instead perform Bluetooth init implicitly. The
bt_enable() API will cleanly fail with -EALREADY if it was previously
called.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg d35061357a Bluetooth: Mesh: shell: Add provision command for self-provisioning
This is for testing purposes, in case an external provisioner is not
available or not wanted.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg e631d6d6cc Bluetooth: Mesh: shell: Add hb-pub-set command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 5e3804b11d Bluetooth: Mesh: Add support for sending Heartbeat Publication Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 2d40c1673c Bluetooth: Mesh: Fix calling complete callback for bt_mesh_provision()
If the app does direct provisioning, it may still want to do common
handling through its provisioning complete callback (if it has one
registered). This also means that we always require a non-NULL
provisioning context provided to bt_enable(), and that it needs to
fail if NULL was given.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 255edcfde2 Bluetooth: Mesh: Provisioning: Add NetKeyIndex to complete callback
It may be useful for the app to know what the initial NetKeyIndex that
it was given during provisioning is.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 0b53341d92 Bluetooth: Mesh: shell: Group global variables in a dedicated struct
This avoids conflicts with function-local variables being called the
same way.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 70cbcef576 Bluetooth: Mesh: Rename health server code from health to health_srv
This is in anticipation of soon adding health client support, which
could then cause confusion due to the ambiguous API names.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 3b252ca2be Bluetooth: Mesh: Rename configuration server code from cfg to cfg_srv
Now that there's support for configuration client as well, rename cfg
to cfg_srv to avoid any confusion.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 0ef7c6e09a Bluetooth: Mesh: Add more flexible APIs for provisioning bearers
Add the ability to track the provisioning bearer through an extra
parameter to link_open/close. Also introduce new public functions to
enable/disable specific provisioning bearers. This also means that one
now needs to explicitly enable provisioning bearers after calling
bt_mesh_init().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg a81fa43a59 Bluetooth: Mesh: Use proper _t suffix for typedefs
To be consistent with the coding style, use a _t suffix for typedefs.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
june li c6407659f3 net: tcp: Add the frag back to caller allocated net_pkt
The original fragment chain of incoming packet will be lost and leaked
in case of early error, add frag back to packet and
let the caller do unref.

Fixes #4323

Signed-off-by: june li <junelizh@foxmail.com>
2017-11-15 12:28:18 +02:00
Jukka Rissanen 8dab561689 net: loopback: Skip neighbor checks for local packets
No need to do any IPv6 neighbor checks if the packet is routed back
to us by loopback driver.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-15 12:27:14 +02:00
Jukka Rissanen d315b430d4 net: Let loopback driver handle lo if it is enabled
If there is loopback interface, then let it handle all local
traffic. Loopback interface is only needed for test applications.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-15 12:27:14 +02:00
Johan Hedberg 7f6070fb6c shell: Add optional command description
The command name and a shortened form of valid parameters is not
necessarily enough to understand its usage. Add the option of
providing a more lengthy description of the command usage.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 07:51:02 +02:00
Jukka Rissanen 9663287bf0 net: context: Check if TCP header is found
If the packet is too short, the TCP header pointer might be
NULL. In this case we just need to bail out.

Coverity-CID: 178787
Fixes #4787

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-14 23:03:16 +02:00
Johan Hedberg c87ecf58de shell: Include the command help when listing all commands
Most commands provide a short string to describe the parameters it
takes. Provide this help text as part of the list of supported
commands for each module.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 21:32:20 +02:00
Johan Hedberg d235f9cc6f Bluetooth: Mesh: shell: Add hb-sub-set command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 63329b79d6 Bluetooth: Mesh: shell: Add mod-sub-add command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg c233ce4fdb Bluetooth: Mesh: shell: Add app-key-bind command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 5429f14a69 Bluetooth: Mesh: shell: Add app-key-add command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 6585347f78 Bluetooth: Mesh: shell: Add for relay and 1-byte state commands
Add commands for 1-byte states such as Default TTL, Friend and GATT
Proxy, as well as the 2-byte Relay state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg cc54f8c84c Bluetooth: Mesh: shell: Add support for Beacon Get/Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 96934bd3d4 Bluetooth: Mesh: shell: Add "dst" & "netidx" commands
Add commands to modify the used destination address and NetIdx.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 7a1c0b979e Bluetooth: Mesh: shell: Add support for getting composition data
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg f50b99572f Bluetooth: Mesh: Add support for sending Heartbeat Subscription Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg b4688bdc84 Bluetooth: Mesh: Add support for sending Model Subscription Add
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg e4db09e919 Bluetooth: Mesh: Add support for sending Model App Bind message
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg e1bc6a6141 Bluetooth: Mesh: Add support for sending AppKeyAdd message
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg cbfea942f6 Bluetooth: Mesh: Add support for Relay and 1-byte state Get/Set
Add support to the Configuration Client Model for getting and setting
1-byte states (which can be nicely generalized in code) as well as the
2-byte Relay state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 07305fd71d Bluetooth: Mesh: Add support for sending Beacon Get & Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 3d1ce43eb0 Bluetooth: Mesh: Add support for sending Get Composition Data
Add Get Composition Data support to the Configuration Client Model.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 588887c9b7 Bluetooth: Mesh: Add primary address to provisioning complete callback
It may be useful for the app to know that the local node's primary
address is.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 2a1e16c2a3 Bluetooth: Mesh: Add skeleton for Configuration Client Model
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 17c9b3a105 Bluetooth: Mesh: Make TRANSMIT_COUNT & TRANSMIT_INT macros public
These are useful for apps who want to implement/use the Configuration
Client Model.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Grzegorz Kolodziejczyk 1ff3ab5f82 Bluetooth: Mesh: Add read callback for ccc in provisioning service
This patch adds read permission for client characteristic configuration
descriptor. This is required by MESH/NODE/MPS/BV-06-C,
MESH/NODE/MPS/BV-07-C PTS tests.

Signed-off-by: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@codecoup.pl>
2017-11-14 14:27:37 +02:00
Tomasz Bursztyka acd10bf7a0 net/ieee802154: Shell handles extended address in EUI-64 format
802.15.4, as other radio tech, works in little endian on network level.
To keeps things simple, the inner context per-interface, stores the
extended address that way. But it can be confusing in shell then, so
let's work handle these addreses through EUI-64 format there.

Fixes #4936

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-11-14 07:00:19 -05:00
Robert Chou 1d70a39d1b net: samples: replace tag zoap with coap
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-14 06:42:57 -05:00
Johan Hedberg 1c0ff01ac7 Bluetooth: Mesh: shell: Add command for Node Identity
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 11:03:58 +02:00
Johan Hedberg a6af281f04 Bluetooth: Mesh: shell: Take advantage of link open/close callbacks
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 11:03:58 +02:00
Johan Hedberg 75253195a4 Bluetooth: Mesh: shell: Add LPN toggling command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 11:03:58 +02:00
Johan Hedberg e2e74f705b Bluetooth: Mesh: shell: Add basic skeleton
Add a basic shell skeleton for Mesh, containing basic command for
initialization, provisioning and reset.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 11:03:58 +02:00
Michael Scott e04a5412a1 net: http: client: remove payload send_chunk logic
Logic for sending chunks of data is incompatible with adding
Content-Length: header.

Per https://tools.ietf.org/html/rfc7230#section-3.3.1:
"A sender MUST NOT send a Content-Length header field in any
message that contains a Transfer-Encoding header field."

Going a bit further in my mind: also don't send Transfer-Encoded
chunked data either when the Content-Length header is present.

In general, there will be problems if the http client library
makes payload changes without the user code knowing about it.

This patch removes the use of http_send_chunk() from the new
HTTP client code and instead sends the payload directly to
http_prepare_and_send()

This fixes an issue where every available buffer would be allocated
with repeating payload data because the for loop in http_request()
wasn't ending until we ran out of memory.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-11-14 09:52:59 +02:00
Michael Scott 865d617772 net: http: honor CONFIG_HTTP_CLIENT_NETWORK_TIMEOUT setting
We should not use the user suppied timeout setting in
http_client_send_req() for the connection timeout.  In the
previous API the call to tcp_connect() used
CONFIG_HTTP_CLIENT_NETWORK_TIMEOUT as the timeout setting.

Let's do that here too.

This fixes -ETIMEDOUT error generation when using K_NO_WAIT
for http_client_send_req().

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-11-14 09:52:59 +02:00
Jukka Rissanen 7784518d37 net: http: Add error status string to HTTP server error
Add status error string when sending a error message from
HTTP server to client as described in RFC 2616 ch 6.1.
Previously only error code was sent except for 400 (Bad Request).

This also fixes uninitialized memory access in error message.

Coverity-CID: 178792
Fixes #4782

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-14 09:52:46 +02:00
David Leach 09ce2e218f subsys/random: Add _ASSERT() test on returned device_get_binding
If there is a build setup problem where a device driver has not been
setup for the entropy driver then the call to device_get_binding()
will return a NULL value and the code will continue to use this NULL
value. The result is a hard fault later in code execution.

Note that CONFIG_ASSERT is by default off so one has to turn this
configuration on to catch this problem.

Signed-off-by: David Leach <david.leach@nxp.com>
2017-11-13 13:50:15 -08:00
Sebastian Bøe 578c91ae18 Bluetooth: storage: Fix linking with subsys__fs
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-13 15:10:20 +02:00
Johan Hedberg cc55e86cc8 Bluetooth: Mesh: Fix relaying packets
The restoring of the buffer parsing state was only correct for the
friend queue (which needs the app-layer data). Relaying on the other
hand requires the network layer data, i.e. it needs a different state
to be restored.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg 02d98d0da0 Bluetooth: Mesh: Fix missing tracking of segment callback
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg e70f6dfc88 Bluetooth: Mesh: Take advantage of BT_MESH_TTL_MAX macro
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg a2a46e66e1 Bluetooth: Mesh: Export key packing helpers internally
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg 9cbb979db7 Bluetooth: Mesh: Fix sending messages when not provisioned
The message sending APIs should fail cleanly if we are not yet
provisioned.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg 514cebcfe8 Bluetooth: Mesh: Change local_queue from k_fifo to sys_slist_t
We never access the local network interface queue in a blocking
fashing, so it's unnecessary to have all the infrastructure that
k_fifo provides. Use the simpler sys_slist_t instead.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg 092a28541a Bluetooth: Mesh: Provisioning: Introduce link open/close callbacks
It may be useful for the app to know when the provisioning link is
active and when it has been closed. This can be used e.g. to signal
the user the state of the device. Some PTS tests also require
verifying the link state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg 25604f979d Bluetooth: Mesh: Provisioning: Fix encoding of OOB values into link.auth
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg 32399a4cd2 Bluetooth: Mesh: Provisioning: Fix input OOB support
The code was missing the sending of the Input Complete PDU, and was
also setting the link.auth value too late.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg 497fef85c3 Bluetooth: Mesh: Provisioning: Fix coding style (too long line)
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg ec6fd3575b Bluetooth: Mesh: Provisioning: Fix OOB string output
The OOB string was being generated in an incorrect way, resulting
essentially in garbage.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Jukka Rissanen 198d96cc9a net: shell: Ping command needs target host set
The ping command was not checking if the user gave target
host as a parameter. This would lead to NULL pointer access.

Fixes #4827

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-13 10:18:22 +02:00
Johan Hedberg d43a92b1c8 Bluetooth: Fix clearing advertising & scanning parameters
The parameter structs for advertising and scanning contain many
members that may not get explicitly set when enabling these states. Do
a memset to zero on them to make sure we don't operate on
uninitialized memory.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-12 21:48:03 +02:00
Johan Hedberg cb8470f3a0 Bluetooth: Mesh: Kconfig: Use a saner default ReceiveDelay
A value of 20ms means it's possible the LPN will end up doing
simultaneous advertising & scanning, which increases the risk of lost
packets. Use a default of 100ms to keep these separate.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg 50a656ff16 Bluetooth: Mesh: Implement handling of Friend Clear messages
Handling Friend Clear messages and sending the Friend Clear
Confirmation responses wasn't so far properly implemented. One of the
requirements is to keep sending the reponses even though we no-longer
have a friendship. This means that we need to keep the net_idx, frnd
and lpn_counter values valid, which in turn requires the introduction
of a separate "valid" boolean value.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg cb89cc7fdc Bluetooth: Mesh: Kconfig: Set PTS-friendly Friendship values
The PTS tests for the Friend node expect a minimum of 16 queued
messages and the ability to have two LPNs. Set these as defaults.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg b644bad5c0 Bluetooth: Mesh: Use network transmit count and interval for Friend
When sending PDUs from Friend to LPN we should adhere to the
configured network transmit count & interval to get better
reliability for the PDUs to be received by the LPN.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg ed8ed9ea7d Bluetooth: Mesh: Implement the Friend Clear procedure
When a Friend Node receives a Friend Request with a unicast
PreviousAddress that's not an element on the Friend Node, it needs to
start the Friend Clear procedure. This procedure involves sending
periodic Friend Clear messages to the old Friend of the LPN.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg eb23d688f2 Bluetooth: Mesh: Fix network credential selection
The only messages that should be encrypted using the friendship
credentials are those coming through the Friend Queue on the Friend
node, most request-response pairs between LPN & Friend (exceptions are
Friend Request - Friend Offer, and Friend Clear - Friend Clear
Confirm), as well as Model Publication messages when the Friendship
Credentials Flag has been enabled in the model publication.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg d43a23652c Bluetooth: Mesh: Introduce LPN-specific adv transmit properties
When the node is in LPN node, the LPN-Friend messages has its own
retries, so doing this on the advertising level (i.e. following the
network transmit state) is sub-optimal.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg 01d3940cdb Bluetooth: Mesh: Allow passing adv transmit info in net_tx
This makes it possible (in a subsequent patch) to fine-tune some
special cases, like the LPN poll messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg 1d86ef0955 Bluetooth: Mesh: Use more accurate timing for LPN functions
Update the advertising callback to include the exact duration that we
will be sending out the packet. This is useful since sometimes we want
to use the end point of the advertising as the reference time to count
when some other action should take place.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg e74f4a6c39 Bluetooth: Mesh: Fix clearing friendship
Lower the attempts and make sure we track the old Friend address for
subsequent Friend Requests, in case we never receive a Clear
Confirmation.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg 4d7757fab1 Bluetooth: Mesh: Fix sending Friend Clear messages indefinitely
We should give up after a small number of attempts.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg b95d70c3f0 Bluetooth: Mesh: Improve Low Power establishment procedure
Add some automated policies for starting LPN establishment and make it
possible to perform the establishment in a "low power" way, i.e.
switching to low duty-cycle already when starting to send Friend
Requests.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Loic Poulain f38482a8fd usb: netusb: Use lower addresses for default endpoint config
Even if endpoint addresses are configurable by each platform,
it would be better to make the default configuration compatible
with a larger board range.

e.g. STM32 OTG FS device has only four endpoints (0x84 is out).

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-10 13:10:00 -05:00
Loic Poulain 94c6e47667 usb: netusb: Fix CMakeLists
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-10 11:27:50 -05:00
Paul Sokolovsky 91e810f87a net: sockets: sendto: Remove adhoc handling of max pkt payload size
Now the check happens on the level of the core IP stack, in
net_pkt_append().

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-10 16:30:42 +02:00
Paul Sokolovsky 4718dac560 net: net_pkt_append: Take into account MTU when adding data to a packet
If we were asked to add 10KB to a packet, adding it won't help -
such packet won't be even sent by hardware on our side, and if
it is, it will be dropped by receiving side. So, make sure we
never add more data than MTU as set for the owning interface.
This actually gets a bit tricky, because we need also to account
for protocol header space. Typically, when net_pkt_append() is
called, protocol headers aren't even added to packet yet (they
are added in net_context_send() currently), so we have little
choice than to assume the standard header length, without any
extensions.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-10 16:30:42 +02:00
Johan Hedberg 1f76023ad4 Bluetooth: Mesh: Fix ignoring prohibited ReceiveWindow value
According to the Mesh Spec value 0x00 of ReceiveWindow parameter is
prohibited. This is needed to pass MESH/NODE/FRND/LPN/BI-03-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 15:35:15 +02:00
Johan Hedberg 85e7a3d47e Bluetooth: Mesh: Fix typo when iterating GATT clients
The intention of the code was to access client->conn and not
clients->conn (which would always access the first client struct).

Fixes #4738

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 15:13:01 +02:00
Johan Hedberg 9c8ce3d7c4 Bluetooth: Mesh: Fix Mesh feature description in Kconfig
Use the correct term for the feature, and reformulate the help text
for BT_MESH.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 08:11:52 -05:00
Johan Hedberg e980d45c13 Bluetooth: Mesh: Fix net_find_and_decrypt() function
The function return type was declared incorrectly. Also, the magic
checking for i after exiting the loop could cause some false positive
compiler warnings. Instead, return directly from the loop (with the
downside of duplicating a few lines of code).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 14:52:23 +02:00
Johan Hedberg 25c5d36b91 Bluetooth: Mesh: Avoid using 64-bit storage & math for beacons
It's in practice impossible for the time between two beacons to be
more than 50 hours (the approximate wrap-around time for a 32-bit
millisecond timer), so we can use a 32-bit timestamp instead of a
64-bit one for the beacon tracking.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 14:33:03 +02:00
Johan Hedberg 68f6b59e2d Bluetooth: Fix deadlock-risky HCI command buffer allocation
The LE scanning and advertising implementations were allocating and
holding buffers (the scan & advertising parameters respectively) while
at the same time potentially sending other commands (such as setting
the local private address). If these APIs would end up being called
simultaneously from different contexts, this could lead to a deadlock
in trying to allocate HCI command buffers, especially considering that
the default HCI command buffer count is 2.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 10:42:38 +02:00
Paul Sokolovsky b86b079f32 net: tcp: net_tcp_parse_opts: Convert MSS value to host byte order
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-09 17:00:26 +02:00
Tomasz Bursztyka 58bc383cfd net/ieee802154: Properly check the sequence when handling ACK frames
When sending a packet with AR flag set, the ACK frame that should be
replied to it must holp the same sequence number, so let's verify this
properly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-11-09 10:00:38 +02:00
Tomasz Bursztyka cf78219318 net/ieee802154: Make FC/Seq validation function public
There will be place where validating only this part of the frame will be
necessary. This will avoid to run the little bit heavier
ieee802154_validate_frame().

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-11-09 10:00:38 +02:00
Sebastian Bøe 5630ccfc23 cmake: Introduce a default VID and PID
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe dad876f837 cmake: Fixed subsys/net/lib/http
This fixes the CI failure of the sample lwm2m_client.

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Andrei Emeltchenko 6f52e2d911 usb: Allow to select Endpoint addresses for CDC ACM
Sometimes we need to select Endpoint addresses manually to get it
working with certain USB controllers having limit for endpoints. In
this case default values break endpoint limit check. The proper
solution would be automatic endpoint allocation.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-11-08 15:09:47 -05:00
David B. Kinder 7e3ed1465f doc: fix Kconfig misspellings
Kconfig files are processed to create configuration
option documentation.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-11-08 13:50:35 -05:00
Paul Sokolovsky cdea2bfab7 net: tcp: Add support for TCP options parsing
Add a generic function for TCP option parsing. So far we're
interested only in MSS option value, so that's what it handles.
Use it to parse MSS value in net_context incoming SYN packet
handler.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-08 16:19:57 +02:00
Paul Sokolovsky 3c652996ff net: tcp: Add NET_TCP_HDR_LEN(hdr) macro for reuse
Calculates full TCP header length (with options). Macro introduced
for reuse, to avoid "magic formula". (E.g., it would be needed to
parse TCP options).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-08 16:19:57 +02:00
Paul Sokolovsky bc88ad750b net: tcp: Handle storage of TCP send MSS
MSS is Maximum Segment Size (data payload) of TCP. In SYN packets,
each side of the connection shares an MSS it wants to use (receive)
via the corresponding TCP option. If the option is not available,
the RFC mandates use of the value 536.

This patch handles storage of the send MSS (in the TCP structure,
in TCP backlog), with follow up patch handling actual parsing it
from the SYN TCP options.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-08 16:19:57 +02:00
Johann Fischer 8ff9b6350f subsys: netusb: use usb_cdc.h header
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-11-07 15:31:02 -05:00
Andrei Emeltchenko 641f867adf usb: netusb: Allow to select Endpoint numbers
Add support for selecting Endpoint numbers and move it under USB
Device Networking menu.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-11-07 14:00:58 -05:00
Johan Hedberg 2a74be43ea Bluetooth: Mesh: Fix network decryption in case of multiple LPNs
If we are a Friend node with multiple LPNs, we need to iterate through
all available Friendship credentials to find the right keys.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg 1ecb486f17 Bluetooth: Mesh: Simplify & fix net credentials selection
The Mesh spec expects us to fall back to master credentials if
friendship ones are not available. Also remove an unnecessary branch
with the help of a new 'idx' variable.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg d118fff232 Bluetooth: Mesh: Remove unnecessary per-buffer segment context
The friend_cred and new_key information is common for all segments of
a segmented transaction, so it makes sense to store them as part of
struct seg_tx instead of each buffer's user data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg 9b2a6d4866 Bluetooth: Mesh: Fix friendship credential usage for segmented messages
The friend_cred hint needs to be set already at the point of
segmenting, i.e. doing it in bt_mesh_net_send() is too late. Move the
setting to bt_mesh_trans_send() and bt_mesh_ctl_send().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg ada5771d7c Bluetooth: Mesh: Fix ignoring invalid Transport OpCode as LPN
MESH/NODE/FRND/LPN/BI-02-C requires us to ignore unknown Transport
OpCodes instead of treating them as valid responses to a Friend Poll.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg f51797335d Bluetooth: Mesh: Fix retries when establishing Friendship as LPN
The Mesh Specification recommends retrying up to 6 times the Friend
Poll when establishing Friendship as LPN.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg b18f023e31 Bluetooth: Mesh: Improve debug logs for provisioning
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg f7e74dd5cb Bluetooth: Mesh: Fix provisioning with Key Refresh flag set
We should not have any valid key material in key slot 0 if the KR flag
is set, since then the new key/old key information will be incorrect
when network PDUs get decrypted.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg 4492c5d072 Bluetooth: Mesh: Improve acknowledgement timer calculation
According to the Mesh Profile Specification: "The acknowledgment timer
shall be set to a minimum of 150 + 50 * TTL milliseconds".

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg 8fe33607c6 Bluetooth: Mesh: Fix message replay protection
The Mesh Profile Specification states that replay protection must be
done for all control and access messages. Furthermore, the replay
protection list must be updated with the sequence from the last
segment of a segmented message (the code was only updating based on
SeqZero).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg cad1f4ce7b Bluetooth: Mesh: Fix transport layer heartbeat subscription matching
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg 95d34e0583 Bluetooth: Mesh: Cfg: Implement Low Power Node PollTimeout Get fully
Now that Friend support is complete we can create a full
implementation of the LPN PollTimeout Get message.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg 6abfab08d4 Bluetooth: Mesh: Fix not including RSSI into network RX context
The RSSI was supposed to be stored in the net_rx struct.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg 7248e4b7c3 Bluetooth: Mesh: Add complete Friend support
Add all the missing pieces of Friend node support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Jukka Rissanen 517caef5a4 net: pkt: Remove unnecessary error print in adjust_offset
The commit 971da9d0 ("net: pkt: adjust_offset: Simplify and optimize
code") changed the adjust_offset() function but left the error print
intact. This print is now invoked even if there is no error which
looks bad in debug prints.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-07 15:18:02 +02:00
Johan Hedberg 86c32aac1c Bluetooth: Kconfig: Introduce new BT_SCAN_WITH_IDENTITY option
Even with the privacy feature disabled, the stack has so far defaulted
to using an NRPA for active scanning, in order to protect privacy.
This is mainly because it is not always clear that scanning for other
devices may risk revealing the local identity.

There may however be use cases where such revealing is actively
desired, so introduce a new option for this (which defaults to
disabled).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 14:14:17 +03:00
Loic Poulain 35d0592a39 usb: netusb: Change 'conf' to 'configured'
conf member represents the configuration state of the device.
Change its type from u8 to bool and clean related functions.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 3fc83fd180 usb: netusb: ecm: Make in_pkt static
This reassembly buffer is local.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 41891849c9 usb: netusb: remove ecm struct
Remove unused iface member and move out skip variable.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain c82d1446bd usb: netusb: Remove ecm_register_function
The only access to the function is now the function interface.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 5f1c6d0999 usb: netusb: Move endpoint specific config to function interface
netusb endpoint config is specific to the function (ECM, RNDIS, EEM..).
Move this config to the function interface.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 3c47817a98 usb: netusb: Abstract netusb function specific methods
Move class_handler and send_pkt to netusb function interface.
This makes netusb 'function' agnostic.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 3870fc5928 usb: netusb: Remove multi-function array
Today, we support/use only one USB configuration descriptor.
Moreover I assume multi-config support should be managed at
usb core level and not by each class driver.
Let's track one netusb function per netusb instance for now.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 0188881599 usb: netusb: Add netusb_recv method
This method can be use by netusb functions on pkt reception.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 53d8389a6c usb: netusb: Remove eth_emu
Move network device creation/mgmt to netusb.
Add iface reference to netusb instance.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Tomasz Bursztyka c968e102e6 net/ieee802154: Add a choice on which packet to print-out
All, RX only or TX only

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-11-06 21:01:35 +02:00
Tomasz Bursztyka b181dc6791 net/ieee802154: Isolate packet display debugging option
Let's enable packet hex dump display without requiring the whole 15.4
stack debug option.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-11-06 21:01:35 +02:00
Aska Wu 62e5f8d7a1 net: socket: Handle the value-result argument
The addrlen of accept() and recvfrom() is a value-result argument. It
should be updated to the actual size of the source address after
calling accept() and recvfrom().

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-06 20:59:05 +02:00
Robert Chou 3ad6719fbf net: lwm2m: response to peer with correct error code when write fail
Update the firmware update_result accordingly by checking return
value of the firmware data write callback registered by application.
Also, set response code according.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-06 20:49:59 +02:00
Robert Chou d36b3251fa net: lwm2m: check engine context before accessing it
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-06 20:49:31 +02:00
Jukka Rissanen dd7b4bae28 net: tcp: Do not run expire function in ISR context
The expire function can call net_context_unref() which tries to
get a semaphore with K_FOREVER. This is not allowed in interrupt
context. To overcome this, run the expire functionality from
system work queue instead.

Fixes #4683

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-06 17:16:46 +02:00
Paul Sokolovsky 971da9d011 net: pkt: adjust_offset: Simplify and optimize code
An edge condition was handled in a special way, even though the main
condition covered it well. More code, more jumps == slower code,
bigger binaries.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-06 17:03:48 +02:00
Jukka Rissanen 2486694eb9 net: http: Create HTTP library that uses net-app
Create http library that uses net-app instead of net_context
directly. The old HTTP API is deprecated.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-06 09:33:00 -05:00
Johan Hedberg 018198cedc net: buf: Add slist helpers
Now that net_buf has "native" support for sys_slist_t in the form of
the sys_snode_t member, there's a danger people will forget to clear
out buf->frags when getting buffers from a list directly with
sys_slist_get(). This is analogous to the reason why we have
net_buf_get/put APIs instead of using k_fifo_get/put.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 14:20:40 +02:00
Aska Wu 1bdd80f8db net: context: Replace net pkt parsing by helper functions
The code parsing received net pkt to get source or destination
sockaddr repeats multiple times in net_context.c.

Eliminate the duplication by net_pkt_get_src_addr() and
net_pkt_get_dst_addr() which can handle different internet protocol
(i.e. ipv4 or ipv6) and transport protocol (i.e. tcp or udp)

Fixes: #4421

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-06 14:09:46 +02:00
Aska Wu 2d7ff75f60 net: pkt: Add net_pkt_get_dst_addr()
Rename net_pkt_get_src_addr() to net_pkt_get_addr() and make it able to
handle source or destination address.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-06 14:09:46 +02:00
Johan Hedberg e25d925242 Bluetooth: Defer RL update if there's an ongoing connection
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 12:50:40 +02:00
Johan Hedberg 56f79f817e Bluetooth: Add support for Link Layer Privacy
Add support for loading IRKs into the controller as well as the LE
Enhanced Connection Complete HCI event. To simplify things, the old LE
Connection Complete handler translates its event into the new enhanced
one which is then the single place of processing new connection
events.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 12:50:40 +02:00
Johan Hedberg a74feaaf55 Bluetooth: Add missing HCI defines for LL privacy
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 12:50:40 +02:00
Johan Hedberg 7762578de4 Bluetooth: Simplify and clean up LE scan handling
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 12:50:40 +02:00
Johan Hedberg 9a8316061d Bluetooth: Mesh: Fix HB Sub Status when disabling subscription
MESH/NODE/CFG/HBS/BV-02-C expects it to be possible to do a Set with
the existing src & dst addresses but with a zero period in order to
"cancel" the current subscription. In such a case the addresses should
remain set but the period be set to zero, similar to what would happen
if the period would expire.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg 33826b91bd Bluetooth: Mesh: Fix clearing HB state when disabling HB sub
The heartbeat subscription Count, MinHops & MaxHops should only be
reset when enabling heartbeat subscription. Any other actions should
keep it unchanged.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg bcc140dbe6 Bluetooth: Mesh: Fix sending heartbeat only when relay state changes
The heartbeat should only be sent in case the relay state actually
changes. This fixes MESH/NODE/CFG/HBP/BV-03-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg c44daebe97 Bluetooth: Mesh: Fix HB Pub Count Log calculation routine
"4.1.2 Log field transformation

In order to compress two-octet values into one-octet fields, the
following logarithmic transformation is used: any two-octet value is
mapped onto a one-octet field value representing the largest integer
n, where 2^(n-1) is less than or equal to the two-octet value."

Log field transformation table:

Log Field Value         2-octet Value
0x01                    0x0001
0x02                    0x0002 through 0x0003
0x03                    0x0004 through 0x0007
0x04                    0x0008 through 0x000F
0x05                    0x0010 through 0x001F
0x06                    0x0020 through 0x003F
0x07                    0x0040 through 0x007F
0x08                    0x0080 through 0x00FF
0x09                    0x0100 through 0x01FF
0x0A                    0x0200 through 0x03FF
0x0B                    0x0400 through 0x07FF
0x0C                    0x0800 through 0x0FFF
0x0D                    0x1000 through 0x1FFF
0x0E                    0x2000 through 0x3FFF
0x0F                    0x4000 through 0x7FFF
0x10                    0x8000 through 0xFFFF

"4.2.17.2 Heartbeat Publication Count Log

The Heartbeat Publication Count Log value between 0x01 and 0x11 shall
represent that smallest integer n where 2^(n-1) is greater than or
equal to the Heartbeat Publication Count value. For example, if the
Heartbeat Publication Count value is 0x0579, then the Heartbeat
Publication Count Log value would be 0x0C."

According to this definition 2^(n-1) is an upper bound for n log
value.

Proposed Publication Count Log transformation table:

Pub Count Log Value     2-octet Value
0x01                    0x0001
0x02                    0x0002
0x03                    0x0003 through 0x0004
0x04                    0x0005 through 0x0008
0x05                    0x0009 through 0x0010
0x06                    0x0011 through 0x0020
0x07                    0x0021 through 0x0040
0x08                    0x0041 through 0x0080
0x09                    0x0081 through 0x0100
0x0A                    0x0101 through 0x0200
0x0B                    0x0201 through 0x0400
0x0C                    0x0401 through 0x0800
0x0D                    0x0801 through 0x1000
0x0E                    0x1001 through 0x2000
0x0F                    0x2001 through 0x4000
0x10                    0x4001 through 0x8000
0x11                    0x8001 through 0x10000

According to Log field transformation table 0x0579 would be
transformed to 0x0B and should be to transformed to 0x0C.

This is required to pass MESH/NODE/CFG/HBP/BV-01-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg ebf1a3c661 Bluetooth: Mesh: Fix ignoring all prohibited sub_dst in HB Sub Set
Section 4.2.18.2 in the Mesh Profile Specification states:

"The Heartbeat Subscription Destination shall be the unassigned address,
the primary unicast address of the node, or a group address, all other
values are Prohibited."

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg 6047ccd2a1 Bluetooth: Mesh: Extend advertising API with helpers for Friend support
These extensions prepare the way of implementing full Friend support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg 91e75985bd Bluetooth: Mesh: Fix and clean up IV Update procedure
This patch fixes issue when receiving iv index greater than current
index + 42 in update mode. According to Specification when node is in
update state it should only accept iv index equal to the current iv
index. When node is in normal mode it should ignore index that is
greater than current index + 42.

This allows to pass MESH/NODE/IVU/BI-02-C.

Also this patch cleans up the iv update procedure, to make it easier
to read.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg b0a43b9d3c Bluetooth: Mesh: Return change information from bt_mesh_iv_update()
This will soon be useful to the callers of bt_mesh_iv_update(), in
particular Friend support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg e1b381c58f Bluetooth: Mesh: Export bt_mesh_friend_cred_get() for Friend usage
This function will soon be needed by the Friend support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg 020425f61a Bluetooth: Mesh: Remove redundant assignment
This value is assigned again a few lines later.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg a6ce33d7ea Bluetooth: Mesh: Cfg: Only update friend state if supported
If Friend support is not available we should not modify the value of
cfg->frnd.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg ab84517b45 Bluetooth: Mesh: Export some transport layer helpers
These will soon be needed by the Friend code to compose messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg ae714e4028 Bluetooth: Mesh: Add bt_mesh_net_flags() helper function
This reduces code in various places needed to construct a flags value
for a given subnet.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg b8e2c9a40f Bluetooth: Mesh: Fix TX segment context lookups
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg 2f9171c3ac Bluetooth: Mesh: Take advantage of BT_MESH_NET_HDR_LEN define
Avoid using hard-coded magic numbers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg 799ee46b5c Bluetooth: Mesh: Keep received buffer intact until transport layer
The lower transport layer is responsible e.g. for the Friend Queue, so
we need to have the buffer in its original parsing state there.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Jukka Rissanen 61fbc4d57d net: app: server: Allow IPv4 connections if IPv6 is enabled
A regression by commit 9728179757 ("Allow net_context re-connect").
The code did not create IPv4 listener if IPv6 listener was successfully
created.

Fixes #4697

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-03 16:09:08 +02:00
Savinay Dharmappa 0106059ff0 subsys: logging: event_logger: Fix CPU fault
A CPU fault occurs when sys_k_event_logger_get_wait()
api invoked with config KERNEL_EVENT_LOGGER_THREAD
enabled.

sys_k_event_logger_get_wait() supposed to pend  on a
semaphore when all the events from kernel event logger
are read.But when sys_k_event_logger_get_wait() inovked
with config KERNEL_EVENT_LOGGER_THREAD(i.e captures thread
events) subsquent call inside this function will write to
kernel event log buffer to capture pend event.This will
release the semaphore on which sys_k_event_logger_get_wait()
was pending hence thread gets unpend before swap gets called.

Which in other words a thread which is invoking
sys_k_event_logger_get_wait()(i. e sem_count = 0) get pends
and unpends in single function flow when KERNEL_EVENT_LOGGER_THREAD
enabled.

This would cause overlapping of the stack address where
return address of "_pend_current_thread" stored with esp of
callee saved(i. e thread->callee_saved.esp). Thus return adrress
of "_pend_current_thread" would be overwitten with zero. Which
in turn causes CPU fault.

The thread invoking sys_k_event_logger_get_wait() supposed
to only read the events of the threads which logged to kernel event
logger buffer. But it should not write to kernel event logger
buffer. Otherwise it would cause the race condition explained above.

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2017-11-02 22:22:54 -04:00
Szymon Janc 3b1cb4a309 Bluetooth: Mesh: Fail init on keys generation error
Fail on Mesh initialization if provisioning is enabled and keys were
not generated. This make it simpler to debug misconfigured devices.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-11-02 15:52:07 +02:00
Johan Hedberg 7166920a1d Bluetooth: Add option to use heuristics for VS HCI detection
On targets where non-Zephyr controllers are likely, such as qemu, it
may be harmful to try to issue any of the vendor HCI commands, since
non-Zephyr controllers may interpret them in completely different
ways.

Introduce a Kconfig option that, when enabled, uses some simple
heuristics (HCI version & lack of public address) to try to guess in
advance whether the Zephyr HCI vendor extensions are supported or not.
The new option is available for any host-only configuration and is
enabled by default for the qemu targets.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-02 14:51:42 +02:00
Vinayak Kariappa Chettimada 6016ccffe8 Bluetooth: controller: Fix diff proc collision with enc proc
Fixes the following conformance test regression failure
introduced in commit 7dd5fbee26 ("Bluetooth: controller:
Fix MIC error due to parallel Enc Proc")

TP/CON/MAS/BV-28-C [Initiating Connection Parameter Request
different procedure collision encryption]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-02 10:26:09 +01:00
Paul Sokolovsky 4641f88623 net: pkt: net_frag_read: Typo fix in comment
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-02 10:05:07 +02:00
Robert Chou 44995e2de0 net: lwm2m: replace coap_next_block() w/ coap_update_from_block()
We should call coap_update_from_block() which will determine the minimum
size of the BLOCK1 SIZE between server/client and update the current
offset and total size(if available) accordingly.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-02 10:02:45 +02:00
Robert Chou a37f049e6d net: lwm2m: break the opaque write loop early when fail
As title, check the return value from the write callback and break if
an error is returned

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-02 10:01:40 +02:00
Michael Scott 5876baa3be net: lwm2m: oma_tlv: fix typo in TLV length processing
This fixes writing to number / boolean values in LwM2M objects.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-11-02 10:01:05 +02:00
Michael Scott 77f18827d8 net: lwm2m: simplify oma_tlv get_bool()
Use existing get_number() function to reduce code size.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-11-02 10:01:05 +02:00
Vinayak Kariappa Chettimada 7dd5fbee26 Bluetooth: controller: Fix MIC error due to parallel Enc Proc
Fix to disallow initiating LE Start Encryption while another
procedure is in progress. Similarly, disallow initiating
another procedure while Encryption procedure is in progress.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-01 16:35:29 +01:00
Leandro Pereira 5a272b027a subsys/random: Add Xoroshiro128+ PRNG
This adds an implementation of Xoroshiro128+ PRNG, based on the
original implementation at [1].  This pseudorandom number generator
will use the entropy driver to obtain the seed.

While it uses only 128 bits of state, it's pretty robust for non-crypto
safe applications.

[1] http://vigna.di.unimi.it/xorshift/xoroshiro128plus.c

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-11-01 08:26:29 -04:00
Leandro Pereira 8b883a61a3 subsys/random: sys_rand32_get() implementation that uses entropy API
Instead of every hardware number generator driver providing an
implementation of this function, use the random device API to
centralize the implementation of this function.

This is a very simplistic function that can be seen as a stepping stone
to refactor the random number generation in Zephyr.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-11-01 08:26:29 -04:00
Leandro Pereira da9b0ddf5b drivers: Rename random to entropy
This should clear up some of the confusion with random number
generators and drivers that obtain entropy from the hardware.  Also,
many hardware number generators have limited bandwidth, so it's natural
for their output to be only used for seeding a random number generator.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-11-01 08:26:29 -04:00
Leandro Pereira adce1d1888 subsys: Add random subsystem
Some "random" drivers are not drivers at all: they just implement the
function `sys_rand32_get()`.  Move those to a random subsystem in
preparation for a reorganization.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-11-01 08:26:29 -04:00
Johan Hedberg f801c1ca8e net: buf: Add net_buf_id() API
Add a net_buf_id() API which translates a buffer into a zero-based
index, based on its placement in the buffer pool. This can be useful
if you want to associate an external array of meta-data contexts with
the buffers of a pool.

The added value of this API is slightly limited at the moment, since
the net_buf API allows custom user-data sizes for each pool (i.e. the
user data can be used instead of a separately allocated meta-data
array). However, there's some refactoring coming soon which will unify
all net_buf structs to have the same fixed (and typically small)
amount of user data. In such cases it may be desirable to have
external user data in order not to inflate all buffers in the system
because of a single pool needing the extra memory.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-01 12:08:27 +02:00
Andrei Emeltchenko 35a263374e usb: netusb: Fix handling no data case
In a case we get packet without fragments return -ENODATA.
The bug was discovered by Coverity.

Fixes #4637
Coverity-CID: 178334

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-11-01 10:00:02 +02:00
Andrei Emeltchenko 90721238c7 net: tcp: Print retry count in retransmission attempts
Print also retry count when retransmitting packets.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-11-01 10:00:02 +02:00
Ricardo Salveti 03b801321b net: increase retransmission timeout (RTO) config range
Previous max range value for RTO was 2 seconds, increase to 60 seconds
as setting larger values can be useful when debugging retransmission
issues on slow networks.

Signed-off-by: Ricardo Salveti <ricardo@opensourcefoundries.com>
2017-11-01 09:54:29 +02:00
Paul Sokolovsky 6f76a19f77 net: sockets: Fix Coverity false positive
Due to parameters used, net_context_recv() call cannot fail (it just
installs a callback, no I/O performed).

Coverity-CID: 178247
Fixes: #4581

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-01 09:47:40 +02:00
Andrei Emeltchenko 86272907d8 net: Add initial retransmission timeout config option
Add option to set initial Retransmission Timeout value. The value is
different from NET_TCP_ACK_TIMEOUT since latter affects TCP states
timeout when waiting for ACK for example.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-31 13:09:30 +02:00
Jukka Rissanen d525c41360 net: app: Allow TLS thread to run to handle the received data
If we receive lot of data fragments, then yield after initial
processing so that TLS thread can start to work on these.
If we do not yield here, we pile up data buffers and might run
out of memory more easily.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-31 09:54:39 +02:00
Jukka Rissanen afc0cdf7e4 net: app: Check if underlying net_context is freed
It might happen in TCP client, that the TCP connection is terminated
in which case net_context is freed. Check this and mark corresponding
net_context inside net_app to NULL. This way there will be no issue
to access already freed net_context.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-31 09:54:39 +02:00
Jukka Rissanen 5cc4ef78d3 net: app: TLS client handling issue when server closes connection
The client TLS code did not handle server issued close properly.
Now the connection is terminated properly and TLS thread is left up to
wait more requests from the user.

This commits adds new boolean field to net_app context. Because there
are already multiple boolean flags there, convert them all to bitfields
to save space.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-31 09:54:39 +02:00
Jukka Rissanen 882f476293 net: app: TLS handshake must be done before sending data
As the TLS handshake might take long time before connection is ready,
check this before trying to send user data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-31 09:54:39 +02:00
Jukka Rissanen 4743d89c9a net: app: Clarify the debug print in TX and RX
Print information that we are sending plain data and receiving
encrypted data, the code claimed that we are sending encrypted
data which is not the case here.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-31 09:54:39 +02:00
Jukka Rissanen 9728179757 net: app: client: Allow net_context re-connect
If user closes the client connection, then make sure that
user can just call net_app_connect() instead of calling the
client init. The client initializes everything in net_app but
for simple re-connect that is not necessary.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-31 09:54:39 +02:00
Michael Scott 353be4cd58 net: lwm2m: propagate errors from post_write callbacks
Now that objects and samples have their return values fixed, let's
propagate them back up to the user if there's an error.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott 98d8c6a665 net: lwm2m: fix all return values from resource callbacks
Previously, post_write and execute callbacks returned 1 when handled
and 0 for error condition.  However, this wasn't detailed enough and
the engine can't propagate any sort of error back to users -- so it
doesn't even check the return values in many cases!

Let's adjust the resource callback functions of all objects and the
lwm2m_client sample to return 0 for success or a valid error code.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott ccbd696706 net: lwm2m: remove predefined firmware buffer from firmware_pull
Now that we can access resource data in the lwm2m subsys, let's use
the user provided firmware push buffer (5/0/0) to also store the
firmware pull data.

This way the size of the firmware pull buffer is completely up to the
application.

NOTE: This patch adds a 64 byte firmware buffer to the lwm2m_client
sample for this purpose.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott febcf5317b net: lwm2m: fix OPAQUE handling in LwM2M engine
With the change to support multi-fragement buffers in the LwM2M subsys,
the OPAQUE data type was direct write methods were broken.

Let's fix OPAQUE handling by using the newly introduced getter methods
which can use multiple user callbacks (depending on the size of the
user provided buffer).  Let's also add public methods for users to set
/ get OPAQUE data in resources for future use with DTLS key data.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott f32815a8d5 net: lwm2m: expose lwm2m_engine_get_resource() for lwm2m subsys
The lwm2m_engine_get_resource() function needs to be made available to
other portions of the lwm2m subsys in order for firmware resource data
to be used in the future.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott 7fa099b67e net: lwm2m: remove unused len var from lwm2m_engine_get()
During conversion from the ZoAP to CoAP APIs the use for this variable
was removed, but the variable itself was left in place.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott 507bf72d10 net: lwm2m: consolidate URI_LEN define in firmware pull source
No need for 2 different defines to specify URI lengths in the source
for firmware pull method.  Let's combine them.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott dd95dbcd9e net: lwm2m: introduce getter/setter for OPAQUE data
Each content formatter should have a way of handling opaque data.

For instance TLV data will individually be able to specify a length
but plain text will take up the rest of the packet.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott b37a005d68 net: lwm2m: add multi fragment support to LwM2M library
The existing LwM2M framework expected contiguous buffers and this
was the reason for the 384 byte buffer sizes.  This was previously
a limitation of the ZoAP API. The new CoAP API doesn't have this
limitation and the LwM2M library has already been migrated to use
it.

Let's finish the process by replacing any contiguous buffer handling
with the correct net_pkt APIs to parse across multiple fragments.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott dd364efc58 net: lwm2m: share BUF_ALLOC_TIMEOUT setting w/ other lwm2m components
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Robert Chou be825dca1e net: lwm2m: handle format application/octet-stream w/ plain_text
application/octet-stream is used to indicate opaque payload format.
Use plain text handler to handle the opaque format.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-31 09:32:07 +02:00
Anas Nashif 780324b8ed cleanup: rename fiber/task -> thread
We still have many places talking about tasks and threads, replace those
with thread terminology.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-30 18:41:15 -04:00
Andrew Boie 74446381d1 sensors: move userspace handlers location
Place driver handlers with the drivers, not somewhere separate under
subsys/

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-30 13:20:19 -07:00
Andrei Emeltchenko f69b85e05c usb: netusb: Select NET_L2_ETHERNET when choosing Device Networking
Select automatically NET_L2_ETHERNET.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-30 11:50:42 -04:00
Jukka Rissanen 0e7c8edc92 net: context: Make sure we honor timeout when waiting data
The call to net_context_recv() with timeout returned -ETIMEDOUT
even when data was returned properly and there was no timeout.

Fixes #4565

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-30 17:18:11 +02:00
Vinayak Kariappa Chettimada 8edcbade9a Bluetooth: controller: Fix to enable Asym PHY on nRF52 Series
Fix the controller Kconfig to enable use of fast radio ramp
up by default, hence enabling support for Asym PHY updates
by default on nRF52 Series SoCs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-30 14:51:18 +01:00
Aska Wu 60a8e7843e net: context: Fix find_available_port()
In bind_default(), a local variable is passed to find_available_port().
However, the port number is unpredictable as it's not initialized and
will be used directly if not zero. This will lead to problems if the
port number is already used.

This patch makes find_available_port() always returns an available port
regardless of the port number in the sockaddr parameter.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-10-30 12:01:43 +02:00
Andrei Emeltchenko a226d58716 usb: Use RFC 7042 Documentation values for MAC strings
Use documentation defined values for virtual devices MAC addresses in
Zephyr and Host OS.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Andrei Emeltchenko c93578e608 usb: netusb: Add composite device with ECM function
Add composite device skeleton with ECM function implemented.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Andrei Emeltchenko 38e010136d usb: netusb: Add ethernet emulation device
Ethernet emulation device allows to use networking interface for
interaction with USB endpoints.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Andrei Emeltchenko bbd3b4d749 usb: Add CDC ECM composite configuration
Add USB device configuration for CDC ECM

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Andrei Emeltchenko 91a4397e16 usb: Add extra debug information
Add extra debug information to USB commands.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Tomasz Bursztyka 0d760d36e7 net/6lo: Enable it by default if IEEE 802.15.4 is enabled
This rework commit 77b8f5c1f6

Comparing it to BT IPSP is a the wrong comparison: BT IPSP does specify
6lo/ipv6 for it to work. Whereas 802.15.4 does not.

Instead of selecting 6lo from 802.15.4's Kconfig, let's do the reverse
way. If the user enabled 802.15.4 and IPv6 as well (to which 6lo
depends on), then 6lo is enabled by default as using IPv6 on 15.4
without it does not make much sense.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-28 14:28:02 -04:00
Sebastian Bøe b7eaeb9f0a cleanup: Use quote include instead of system include
When the header file is located in the same directory as the source
file it is better to use a relative quote-include, e.g.

than a system include like

Avoiding the use of system includes in these cases is beneficial
because;

* The source code will be easier to build because there will be fewer
system include paths.

* It is easier for a user to determine where a quote-include header
  file is located than where a system include is located.

* You are less likely to encounter aliasing issues if the list of
  system include paths is minimized.

Authors:
Anas Nashif
Sebastian Bøe

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-28 07:11:53 -04:00
Michael Scott 0bd961647a net: lib: http: fix check for invalid body_start pointer
Recent commit fb7f6cfa97 ("net: lib: http: Fix invalid pointer
body_start") introduced logic to reset the response body_start pointer
when the response buffer was reused.

This check needs to be fixed so that it doesn't arbitrarily change
body_start when not needed.

The problem with the current check can be demonstrated by not setting
a response callback for request which generates a large response
spanning multiple packets.

In this case body_start is still valid (not reusing the response buffer
because there is no callback set), but it will be changed when the 2nd
packet is received and the "at" marker is located at the head of the
new packet (!= response_buffer).

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-27 17:42:01 -04:00
Michael Scott 7aa06558e0 net: lwm2m: remove auto select of COAP_EXTENDED_OPTIONS_LEN config
When moving to the new CoAP API, I thought we would need to parse
incoming option values longer than 12 characters.

This hasn't proven to be true, so let's remove the auto-selection of
this config.  If needed user can set this option later.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-27 11:33:06 -04:00
Michael Scott 2567b9fb6a net: coap: Fix error handling for coap option length
Currently, we check the length of an option value in the
coap_packet_append_option() function.  This isn't required as
we're appending to a net_pkt and not using struct coap_option
where the limitation is imposed.

Instead, we should check the option value length in
parse_option() where we assign the value to a struct
coap_option.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-27 11:33:06 -04:00
Jukka Rissanen b68ee59335 net: app: Check that we could install recv_cb after connected
Inform user if we could not install receive callback after
a connection is created in net-app client.

Coverity-CID: 178246
Fixes #4582

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-27 15:35:59 +03:00
Jukka Rissanen 9a61384b86 net: http: Check that we could install recv_cb in accept
Inform user if we could not install receive callback after
a connection is accepted in http server.

Coverity-CID: 178244
Fixes #4584

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-27 15:35:59 +03:00
Jukka Rissanen de36f39dd6 net: mdns: Check net_pkt before accessing it
If we run out of memory, then net_pkt might be null and we must
not access it.

Coverity-CID: 178235
Fixes #4593

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-27 15:35:59 +03:00
Robert Chou e2024128e1 net: coap: check null pointer before assign value
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-26 12:43:34 +02:00
Ding Tao fb7f6cfa97 net: lib: http: Fix invalid pointer body_start
The body_start field at http_client_ctx.rsp is used to check if this
fragment contains (a part of) headers or not.

If the device recived more than one fragment in one http response,
may cause re-use of the result buffer in function on_body().

Once the device re-use the result buffer, the body_start that point
to this buffer address will no longer be valid.

Signed-off-by: Ding Tao <miyatsu@qq.com>
2017-10-26 09:40:05 +03:00
Paul Sokolovsky 87c4515f5c net: ieee802154_shell: get_pan_id: Print ID in hex too
Oftentimes, 15.4 PAN IDs are specified in hex. For example, that's
how Zephyr config specifies the default value. So, print them also
in hex, to avoid confusion.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-26 09:30:32 +03:00
Michael Scott f8ba4585c5 net: lwm2m: register the RD client with the engine periodic service
Remove the RD client's stack in favor of using the engine's periodic
service to trigger RD client events.  This saves 5K RAM of stack based
memory.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:29:42 +03:00
Michael Scott 1674a8c717 net: lwm2m: register device periodic service with engine
Remove the stack from the device object and instead make use of
the periodic engine service which will trigger the device service
when it's ready.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:29:42 +03:00
Michael Scott a4ab36bcbd net: lwm2m: add periodic service registration to engine
Stacks cost a lot of RAM in Zephyr.  We have 3 total stacks in
the LwM2M lib.  We can remove 2 of these if add a service handler
into the main LwM2M engine.  Each service can register with this
handler so that they can be called based on their own periodic
timer.  The handler itself will search through these registered
services and call them when they become due otherwise sleep
until another is ready.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:29:42 +03:00
Michael Scott 25ff4f0e6a net: lwm2m: reduce LwM2M footprint via lower defaults in Kconfig
Let's use conservative defaults for the LwM2M library to enable
hardware with constrained resources.  Users can increase where
necessary.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:25:56 +03:00
Michael Scott 022d805cc2 net: lwm2m: replace instances of s*printf with snprintk
Let's use snprintk for simple formatting to allow for possible disabling
of printf and protect calls to sprintf from string overruns.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:23:19 +03:00
Michael Scott ebe3660308 net: lwm2m: fix Leshan discover OP
When using Leshan REST API to perform a discover OP on a client, only an
accept field is sent with "application/link-format".  Current logic uses
the content-type to determine when a discover OP is indicated.  Let's
handle this case as well.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:20:40 +03:00
Vinayak Kariappa Chettimada 0328ecf6fc Bluetooth: controller: Fix Ctrl PDU Tx starvation assert
Replace all controller asserts in control procedure responses
that checked for buffer availability with an implementation
that nacks request PDUs if there are no buffer to prepare
response PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-25 16:16:47 +02:00
Vinayak Kariappa Chettimada 482771c497 Bluetooth: controller: Remove assert on invalid LL id
Remove an assert on receiving invalid LL id, drop these
invalid PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-25 14:54:17 +02:00
Paul Sokolovsky c469b7fc9f net: tcp: Avoid spurious seqno decrements
There were decrements of TCP sequence numbers, inherited from FNET
stack implementation, as was used as an initial base. RFC793 does
not specify conditions for decrementing sequence numbers, so such
decrements are an artifact of FNET implementation. In Zephyr code,
we had to compensate for these decrements by extra increments
(including an increment-by-2). So, remove decrements and associated
extra increments to simplify the code.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-25 14:19:04 +03:00
Michael Scott 1d05ba75d1 net: lwm2m: fix CREATED response code
Handle LwM2M CREATE op correctly and remove comments.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-25 13:39:55 +03:00
Michael Scott eb5ba43644 net: lwm2m: fix error handling in handle_request()
Let's reset the payload and return correct response error codes.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-25 13:39:55 +03:00
Michael Scott 1bca60d732 net: lwm2m: make release in lwm2m_release_message() optional
Let's rename lwm2m_release_message() to lwm2m_reset_message()
and add a parameter to let the function know whether or not to
release the lwm2m_message resource back to the pool.

By adding the optional release parameter, we can keep the
lwm2m_message but reset the underlying net_pkt / net_buf resources.
This allows us to regenerate the net_pkt after determining
an error has occured.  In this case, we don't want the previously
added net_pkt contents but we do want to maintain the message id,
token, etc.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-25 13:39:55 +03:00
Michael Scott fb734acc73 net: lwm2m: move to using the new multi-packet CoAP API
This patch moves from the ZoAP API in subsys/net/lib/zoap to
the CoAP API in subsys/net/lib/coap which handles multiple
fragments for sending / receiving data.

NOTE: This patch moves the LwM2M library over to the CoAP APIs
but there will be a follow-up patch which re-writes the content
formatter reader / writers to use net_pkt APIs for parsing
across multiple net buffers. The current implementation assumes
all of the data will land in 1 buffer.

Samples using the library still need a fairly large NET_BUF_DATA_SIZE
setting. (Example: CONFIG_NET_BUF_DATA_SIZE=384)

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-25 13:39:55 +03:00
Robert Chou 7aa223174a net: coap: empty payload with payload marker is malformed
From RFC 7252, section 3
"The absence of the Payload Marker denotes a zero-length payload.
The presence of a marker followed by a zero-length payload MUST
be processed as a message format error."

Check empty payload when COAP_MARKER is found and add a test case to
cover it

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-25 13:21:53 +03:00
Ravi kumar Veeramally 630fad3bbf net: coap: Improve options parsing helper functions
Options parsing helpers functions unable to handle the malformed
packets and dropping it. Improved parsing functionality to handle
malformed packets. Also payload marker is not mandatory in CoAP
packets when there is no payload. Exit gracefully when CoAP
packet contains only options.

Fixes #4396.

Coverity-ID: 178060

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-10-25 10:54:25 +03:00
Jukka Rissanen 29dd25afb4 net: app: Calculate TLS application data pointer correctly
We need to skip protocol headers when setting pointer to
application data when receiving TLS data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-24 12:18:50 -07:00
Jukka Rissanen 5eb8936b05 net: app: Fix compilation error if debugging is enabled
If user has enabled CONFIG_NET_DEBUG_APP, then the debugging
version of _net_app_select_net_ctx() was not properly declared
and it caused compile error.

Fixes #4481

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-24 11:40:55 -07:00
Johan Hedberg c2f0dad29d Bluetooth: Mesh: Improve Network Message Cache behavior
The implementation of the Network Message Cache has so far been
suboptimal, since it has treated the same packet with different TTL
values as different packets. Since one of the purposes of this cache
is to prevent unnecessary relaying, it's important that we don't let
the TTL value influence the "hash" that's used for matching messages.

This patch changes the hash to consist of most of the IV Index (three
least significant bytes of it), the sequence number and the source
address, which should give fairly optimal matching behavior.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-24 18:23:36 +03:00
Jukka Rissanen 5da4639067 net: ipv6: Remove invalid assert when receiving NS
If we receive a neighbor solicitation which does not have any
options, then there is no need to assert this condition as that
is a perfectly valid use case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-24 11:30:41 +03:00
Jukka Rissanen 41f44ad8e0 net: ieee802154: Check reassembly return value properly
If IEEE 802.15.4 reassembly function ieee802154_reassemble() returns
anything other than NET_CONTINUE, then drop that packet. Earlier
it only dropped the packet if NET_DROP was returned but the reassembly
might also return NET_OK. In that case the pkt is freed already and
pkt->frags pointer is NULL. This caused NULL pointer access in L2 when
packet was received.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-10-24 11:30:10 +03:00
Paul Sokolovsky 91ac13d87d net: shell: stacks: Print config option needed for full info
This is similar to how few commands already behave if they can
provide additional info to the user if particular config options
are enabled.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-23 15:13:35 +03:00
Aska Wu 311c5ea56a net: pkt: Fix net_pkt_get_src_addr()
net_pkt_tcp_data() and net_pkt_udp_data() simply returns the start
address of the header. However the header may span over multiple
fragments, unexpected data or memory corruption might happen when
reading or writing to the pointer directly.

Use net_tcp_get_hdr() and net_udp_get_hdr() instead.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-10-23 15:04:59 +03:00
Jukka Rissanen 363ccaf663 net: Clarify UDP and TCP header getter and setter documentation
The net_tcp_get/set_hdr() and net_udp_get/set_hdr() documentation
was not clear in corresponding header file. Clarify how the return
value of the function is supposed to be used.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-23 15:04:23 +03:00
Aska Wu 898036d892 net: udp: Remove subsys/net/ip/udp.h
udp.h is out-of-date as it accesses net buf directly. In 3604c391, it
has been replaced by net/udp.h and udp_internal.h

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-10-23 15:03:43 +03:00
Paul Sokolovsky 09b967366f net: pkt: Use standard macros to define system pkt slabs/pools
Previously net_pkt.h, defined macros NET_PKT_TX_SLAB_DEFINE,
NET_PKT_DATA_POOL_DEFINE, but advertised them as intended for
"user specified data". However, net_pkt.c effectively used the
same parameters for slabs/pools, but this wasn't obvious due
to extra config param redirection. So, make following changes:

1. Rename NET_PKT_TX_SLAB_DEFINE() to NET_PKT_SLAB_DEFINE()
as nothing in its definition is TX-specific.
2. Remove extra indirection for config params, and use
NET_PKT_SLAB_DEFINE and NET_PKT_DATA_POOL_DEFINE to define
system pools.
3. Update docstrings for NET_PKT_SLAB_DEFINE and
NET_PKT_DATA_POOL_DEFINE.

Overall, this change removes vail of magic in the definition of
system pkt slabs/pools, making obvious the fact that any packet
slabs/pools - whether default system or additional, custom - are
defined in exactly the same manner (and thus work in the same manner
too).

Fixes #4327

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-23 13:58:11 +03:00
Jukka Rissanen 4fe8d17bca net: ieee802154: Add more information when hexdumping the pkt
When hexdumping the packet, print also information if we
received / transmitted packet. Also print information if the
hexdump is before compression or not.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-21 18:14:56 -04:00
Johan Hedberg afc9b5098b Bluetooth: Mesh: Update TODO with current status
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-20 17:53:31 +03:00
Jukka Rissanen 2fba7024af net: app: Fix compilation if TCP is not enabled
If building a server that does not support TCP, then the
get_server_ctx() is not needed and thus needs to be compiled out.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-20 10:11:46 -04:00
Paul Sokolovsky a3eb4fcd3e net: pkt: net_pkt_tcp/udp_data: Better document caveats
Explicitly note that while these functions return pointers to
headers, the headers themselves may be fragmented into different
data fragments. 1a2f24f920 is an example where this might have
been overlooked.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-20 11:01:48 +03:00
Michael Scott 545db8b482 net: lwm2m: remove unused last_value_len from lwm2m_input_context
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott fcd37eb79d net: lwm2m: use isdigit in JSON formatter
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott 078288b2be net: lwm2m: move non-public data out of shared TLV include
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott 1fb61d21ac net: lwm2m: move non-public data out of shared JSON include
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott 7f7e203334 net: lwm2m: remove unused JSON parser types
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott 12072a378f net: lwm2m: cleanup function parameter naming
Don't use names like "strlen" for parameters.  Try and name buffer
parameters consistently.

NOTE: For several functions I removed "const" flag.  This is
intentional and will be needed in upcoming patches.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott 9b643e2be7 net: lwm2m: cleanup TODOs in firmware obj.
Remove some left over TODOs and also fix a TODO where we need to return
the appropriate error code to generate a 4.05 response.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:39:00 +03:00
Michael Scott 9a8597399d net: coap: fix coap packet length calculation
This calculation reads the length portion of the COAP header to determine
the length of the coap packet.  However, when encrypted via DTLS this
value seems to be getting corrupted.  Let's change this calculation so
that it will work for when DTLS is both enabled and disabled.  Use the
total length of the fragment data and substract back out the headers
to get a correct value.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:37:55 +03:00
Ravi kumar Veeramally 13480f3992 net: 6lo: Fix 6lo uncompression issue
When source address is unspecified then SAC is 1 and SAM is 00.
Uncompression does not process because context based compression
is not enabled.
Special case (SAC:1 and SAM:00) should be handled without context
based compression support.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-10-20 10:33:28 +03:00
Jukka Rissanen 73b0d2d084 net: shell: Print system workqueue information
Add system workqueue information prints to "net stacks" command.
This helps debugging when figuring out which stack is running out
of space.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-20 10:31:33 +03:00
Jukka Rissanen a499d9ffd1 net: shell: Add multi connection net-app monitoring support
Enhance existing "net app" command so that it can be
used to show information about multiple connections.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 4befa1316d net: app: Print info if address family is not set properly
If the IP address family is not set to correct value, then print
information about it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 9bff68fc2e net: app: Print more info for TLS MAC verification errors
If we get MAC verification error in handshake, it could be that
everything is fine but we ran out of heap memory in mbedtls.
In this happens, suggest the user to check amount of memory
in mbedtls as it might just fix the issue.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 28d0dffab2 net: app: Add more debugging when selecting net_ctx
As we select net_ctx, it is useful to see who actually called
the _net_app_select_net_ctx() when debugging the call flow.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 9051d462ca net: app: Select proper net_ctx when sending msg
Sometimes when sending network packet, the wrong net_context was
selected which prevented data to be sent.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 42808f4919 net: app: Print more info which interface we are using for pkt
Useful when debugging which network interface is used when sending
the packet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 9090bdfc10 net: app: Close TLS connection properly
We should not close the TLS connection immediately if the TLS
data is not yet sent. So if user calls net_app_close() and we
still have data pending, then send the TLS data and only after
that close the connection.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 1b1a3a6768 net: app: Close a specific network context
As there can be multiple listening network contexts, it should
be possible to close one of them.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 8c5f25d13b net: app: Add support for multiple listening connections
The server is able to listen and serve multiple incoming
connections. This commit does not add support for multiple
incoming TLS connections.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Andrei Emeltchenko 44a3cca2e2 usb: Remove default Vendor and Product ID
Vendor ID and Product ID should be assigned on build time by
respective process.

For sanity check we assign some random values which are only used for
build tests and should not be used for real products.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-19 09:30:58 -04:00
Robert Chou 19559ee41b net: lwm2m: increase rd client stack size when NET_LOG_GLOBAL=y
The stack of rd client is exhausted while running lwm2m client w/ IPv6
and network log global enabled. Increase the stack size to 1536 when
NET_LOG_GLOBAL is enabled.

Detail described at #4424

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:36:02 -04:00
Robert Chou 652cc727fe net: lwm2m: only method GET is allowed for .well-known/core
".well-known/core" is mainly used with method GET for performing the
resource discovery (RFC 6690). Since we are implementing a LwM2M client
and is not implement a resource directory which allow others to do the
resource registration (POST to .well-known/core). Only GET method is
allowed for the usage. Report 4.5 (Method Not Allowed) if other methods
are requested.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:34:10 -04:00
Robert Chou cfa9990c41 net: lwm2m: return 4.04 when URI is not composed by digits
Modify zoap_options_to_path() to return error when URI contains
character other than digits and return 4.04 NOT FOUND to caller.

PATH such as "/1a/2/3" was treated as "/1/2/3" after parsring
which is incorrect.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:34:10 -04:00
Robert Chou d5ab14697f net: lwm2m: fix empty path being treated as 0/0/0 issue
Return 4.05 Method Not Allowed when path is empty ('/') to the
caller for it's only use by bootstrap delete. This change also avoid the
empty path being treated as request targeted at 0/0/0.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:34:10 -04:00
Robert Chou ce5e0d7208 net: lwm2m: response nicely when obj not found or OP not handled
1) Respond NOT FOUND to caller when object doesn't exist
2) Report as internal server error when OP not handled

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:34:10 -04:00
Tomasz Bursztyka 8dd04742a0 ieee802154: Make packet display enablement via a Kconfig option
Such option should be use carefully. Printing out in/out packets is
extremely verbose.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-19 05:33:23 -04:00
Tomasz Bursztyka 70fb09548a net/ieee802154: Use common net_hexdump_frags instead of local function
Now that net_hexdump_frags can print out the link-layer reserve part,
let's use it.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-19 05:33:23 -04:00
Tomasz Bursztyka 81b9c8fcf6 net/utils: Make net_hexdump_frags being able to print ll reserve
If requested only and with colors with right SYS_LOG Kconfig options.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-19 05:33:23 -04:00
Jukka Rissanen 4463035c45 net: 6lo: Drop pkt if it is too short
If the pkt is corrupted and the offset would be larger than
the actual packet length, then print information about that and
drop the packet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 11:17:22 +03:00
Carles Cufi 493852bac3 Bluetooth: controller: Fix flow control packet drop
The main purpose of recv_thread is to process incoming events from the
radio and also any buffered items waiting to be dispatched to the Host
and that are pending because of lack of Host buffers.
When an iteration of the recv_thread obtains a element from the radio it
needs to process it immediately, either sending it straight away to the
Host or appending it to the queue. This was not the case before this
patch, where the concurrency of a buffered packet with one coming from
the radio would cause the latter to be "dropped", causing missing
packets.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-10-18 14:43:39 +02:00
Michael Scott 1965e5e9fc net: lwm2m: add RD client callbacks for app
Applications may want to be notified when various events
happen in the LwM2M rd client.  Let's implement an event
callback which sends: connect, disconnect and update events.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Ricardo Salveti 58d758bf90 net: lwm2m: firmware: add support for firmware pull over CoAP proxy
CoAP allows a proxy to be used when transferring data (CoAP-CoAP and/or
CoAP-HTTP) by creating request on a specific URI path and by using the
Proxy URI CoAP option. Create specific Kconfig options for the proxy
server address and port, until a parser gets implemented.

Code tested with Californium acting as CoAP proxy.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
[michael.scott@linaro.org: rebased on net_app + lwm2m_message
refactoring + firmware update changes.]
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 4a0986dc7a net: lwm2m: ignore duplicate/older block transfers
During firmware download via block-wise transfer, we can see
packets occaionally get re-transmitted (normal logic in the
pending / retry functions).  However, both of these packets
end up coming through the reply handler and we should ignore
any block-wise transfer that has a current value less than
where we expect to be.

NOTE: This fixes K64F ethernet transfers where we were getting
too many packets back in the handler.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott ed100e9c6a net: lwm2m: add full block-wise retries for firmware download
UDP packets can be lost in heavy traffic.  Normally we can handle this
with pending packet processing for packets which have not been responded
to with an ACK.  However, due to the time it takes for firmware to
download via CoAP, an extra level of retries should be added.

The process works like this:

Normal pending packets will try to send 3 times fairly quickly.
If that fails, then the timeout callback is called for the firmware
download process.  A retry counter is incremented and the timeout
callback perform a new packet send of the block-wise transfer
packet that is missing, until the retry counter hits a limit (3)
and then the transfer is aborted.

This allows for a longer "outage" to happen during firmware transfer
and the process can still succeed.

NOTE: This patch does not fix a current bug where the pending process
is not re-sending the packets correctly, it only makes the process
more stable with a better chance to work.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 0b0fd5515d net: lwm2m: fix packet leak in timeout work
When a packet expires after the pending retries we call
lwm2m_release_message() to free up resources.  This includes
cleanup of the pending structure which calls net_pkt_unref on
the pending packet.  This would normally free up the packet
memory.  However, earlier in the pending processing we add a ref
to the packet so that normal send processing doesn't free up
the memory.   This meant we were leaking packet memory every
time we had an expiration due to timeout.

Let's do an unref prior to calling lwm2m_release_message() to
make sure the packet memory is freed correctly.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott c9a80de76b net: lwm2m: setup lwm2m ctx for firmware download
Previously, firmware support wasn't initializing the retransmit work
or the extra network packet pools.  Let's fix that.

NOTE: While this fixes the setup of retransmit work, the actual
attempts to re-send packets which are pending is failing.  Needs
another follow-up fix.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 788c013d5b net: lwm2m: split out lwm2m context initialization
Create an internal function lwm2m_engine_context_init() which sets
the extra packet pools and initializes retransmit work internal to
the LwM2M engine.

This function will be used by firmware pull support which establishes
a new LwM2M context for downloading firmware.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott f630857e69 net: lwm2m: fix message release for separate reply
In the case of a proxy server translating HTTP -> COAP (known in
the code as "separate reply"), we were leaking lwm2m_message structures.
This was due to pending objects being cleared out during the first ACK,
and no other way of finding a matching message when the follow up packet
was received.  Let's add a second match for reply to make sure we can
find our matching message resources.

NOTE: This change renames find_msg_from_pending() to find_msg() and
makes it a static function as it's only used by the lwm2m_engine.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott edc32f4619 net: lwm2m: change registraion update messages to INFO
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 61fe1e17c3 net: lwm2m: RD client start message should be INFO not DEBUG
This is a useful message announcing that the RD client state machine
is starting for a particular connection.  If the log level is set
low so that DBG messages are hidden, then this message goes away.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 3f9c36301c net: lwm2m: fix compile w/o CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT
Fix wrong check of DELIVERY_METHOD_PUSH to DELIVERY_METHOD_PUSH_ONLY

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Robert Chou b93eb8dee1 net: lwm2m: add firmware push support
1. Add handling block1 option in handle_request(). The basic idea is
   to declare structure block_context at compiled time and use "token"
   as a key to pick up the on-going block cotext. It should be able to
   support multiple blockwise transfer concurrently
2. Use write callback implemented in lwm2m_obj_firmware to deal w/ the
   update state transition and than call the callback registered by the
   application
3. move default_block_size to lwm2m_engine.c to share between
   lwm2m_engine and lwm2m_obj_firmware_pull

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
[michael.scott@linaro.org: rebased on LwM2M net_app changes.]
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Robert Chou f6188fbce3 net: lwm2m: setup data_ptr/len for OPAQUE resource when none given
OPAQUE resource type might/might not have data_ptr/data_len setup
depending on the implementation. This introduce an issue that when
OPAQUE resource is written from the server side, the ones w/ none
setup will not be able to get the data at post_write_cb()

Modify to setup data_ptr/data_len as incoming buffer and buffer size

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-17 19:40:04 -04:00
Robert Chou d9f5fe7455 net: lwm2m: add state machine for firmware pull update
1. Parse firmware pull URI
2. Add lwm2m_firmware_get/set_update_cb() for application to register
   callback. This is because we want to check the update_state before
   we pass to the application
3. Add lwm2m_firmware_get/set_update_result() and
   lwm2m_firmware_get/set_update_stat() to manage the state transition
   as well as the sanity check

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
[michael.scott@linaro.org: rebased on net_app framework and
lwm2m_message refactoring.]
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott ba20b3a884 net: lib: lwm2m: use stand-alone URL parser
With future patches we will need to parse URLs in the registration
client and firmware object.  Enable it by default when LWM2M is
enabled.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Johan Hedberg 328f80fa07 Bluetooth: Fix memory leak of command response buffer
There was a missing net_buf_unref() for the response to reading the
controller static addresses.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-17 17:40:00 -04:00
David B. Kinder ee71332b99 doc: fix doc misspellings
Found some spelling issues missed during regular PR review

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-10-17 14:31:52 -04:00
Jukka Rissanen 9d1801d987 net: app: Close context even if there is no connection
If there is no connection to server, then _net_app_select_net_ctx()
will return NULL. This is perfectly fine and we can just continue.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-17 14:07:14 -04:00
Jukka Rissanen 2ab129fe8a net: app: Bind to correct address family
Use the remote address to determine what address family to bind.
This prevents extra context to be created. In order to avoid
parsing the peer address string multiple times, the client
init function is re-factored.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-17 14:07:14 -04:00
Andrew Boie c5c104f91e kernel: fix k_thread_stack_t definition
Currently this is defined as a k_thread_stack_t pointer.
However this isn't correct, stacks are defined as arrays. Extern
references to k_thread_stack_t doesn't work properly as the compiler
treats it as a pointer to the stack array and not the array itself.

Declaring as an unsized array of k_thread_stack_t doesn't work
well either. The least amount of confusion is to leave out the
pointer/array status completely, use pointers for function prototypes,
and define K_THREAD_STACK_EXTERN() to properly create an extern
reference.

The definitions for all functions and struct that use
k_thread_stack_t need to be updated, but code that uses them should
be unchanged.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-17 08:24:29 -07:00
Jukka Rissanen e2c5b07f90 net: ipv4: Accept multicast packets for processing
We dropped received IPv4 multicast packet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-17 08:36:39 -04:00