Commit graph

2410 commits

Author SHA1 Message Date
Tomasz Bursztyka f8cf3b99d9 subsys/net/lib: Clear up CMakeLists.txt
Tiny cleanups to clarify, and 80 chars limit fix.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-12-11 09:34:16 -05:00
Tomasz Bursztyka 8d2c0b4707 subsys/net/ip: Clear up content in CMakeLists.txt
Empty CMakeLists.txt in l2 and l2/ieee802154 deserved to get filled-in
relevantly, instead of centralizing everything in ip/ location.
Also making sure lines don't get over 80 chars.
Also, no need of linking against mbetls unless net shell is enabled.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-12-11 09:34:16 -05:00
Paul Sokolovsky f161633109 net: if: Join solicited-node multicast addr for each unicast addr
https://tools.ietf.org/html/rfc4862#section-5.4.2 :

"""
Before sending a Neighbor Solicitation, an interface MUST join the
all-nodes multicast address and the solicited-node multicast address
of the tentative address.
"""

So, joining should happen before sending DAD packets, and it should
happen for each unicast address added. This is achieved by joining
from net_if_ipv6_addr_add() call. Note that we already leave
solicited-node group from net_if_ipv6_addr_rm(). In particular, we
leave it if DAD fails (as that function is called in this case).

Fixes #5282.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-12-11 09:09:48 -05:00
Aska Wu fa934009cb subsys: console: Fix the buffer size checking
Fix the problem that no compiler error even the buffer size is not power
of 2.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-12-10 19:49:02 -05:00
Anas Nashif f46c0c2472 kconfig: remove deprecated DEBUG_TRACING_KERNEL_OBJECTS
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-09 08:48:51 -06:00
Anas Nashif a254359c1a kconfig: stack_usage: remove extra space
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-09 08:48:51 -06:00
Vinayak Kariappa Chettimada ec5a787da2 Bluetooth: controller: Fix multiple master role event scheduling
When the controller is connecting to multiple connectable
advertisers, the events are scheduled consecutively avoiding
overlapping events. Calculation of the window offset did not
consider the preparation time before the event, causing the
new master role connection event to overlap with previous
event. This is now fixed by including the preparation time
in the used window offset from the end of connect_ind PDU
transmitted.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-09 09:24:37 +02:00
Michał Narajowski 06facdcad7 Bluetooth: Mesh: Fix typo in Kconfig help message
300 * 100 ms = 30000 ms = 30 s

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2017-12-07 17:15:47 +02:00
Vinayak Kariappa Chettimada ba13c99141 Bluetooth: controller: Fix conn param req initiation check
Fixed the check related to initiating connection parameter
request procedure. This will avoid sending invalid repeated
dispatch of connection parameter request PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-06 11:30:42 -06:00
Vinayak Kariappa Chettimada 73a493eae6 Bluetooth: controller: Fix missing CPR procedure reset
When connection parameter request procedure was responded
by master role with Unsupported Link Layer Parameter Value,
a missing reset of the connection parameter request
procedure state caused next connection parameter request to
be incorrectly responded with same procedure collision
extended reject ind PDU. This caused an eventual connection
disconnection with reason LMP response timeout. This is now
fixed by reseting the state correctly.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-06 10:24:26 -06:00
Johan Hedberg 8b51b60634 Bluetooth: Mesh: Proxy: Don't try to advertise when it's not possible
If we have the maximum number of supported connections, then it
doesn't make sense to try to do connectable advertising.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg e4cac812df Bluetooth: Mesh: Proxy: Fine-tune subnet advertising rotation
Create a slightly smarter algorithm for choosing how long to advertise
each subnet. This is particularly important for the mesh_shell app,
since it uses a 10 second NODE_ID_TIMEOUT, meaning starting Node ID
advertising through user interaction would only succeed in advertising
one subnet (due to this being configured to 10 seconds).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg 6e89138823 Bluetooth: Mesh: Suppport multiple subnets for app-triggered Node ID
Mesh Profile Specification 1.0 section 7.2.2.2.3:

"When the server starts advertising as a result of user interaction,
the server shall interleave the advertising of each subnet it is a
member of"

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg 174facc02a Bluetooth: Mesh: Prioritize subnets with Node ID
Node ID advertising is short lived, so it's important to make sure
that subnets that get it enabled are first in queue to start
advertising.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg 86ac86c6ca Bluetooth: Mesh: Add helpers for starting/stopping Node ID
We'll soon extend the start functionality with a bit more stuff
(prioritizing the started subnet), so in order to avoid excessive code
duplication, create helpers for these actions.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg 62777755f9 Bluetooth: Mesh: Add Proxy advertising support for multiple subnets
Until now the proxy server code would only advertise with the first
subnet. Introduce tracking of what the last advertised subnet was, and
give each subnet 10 seconds of advertising at a time.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg 364ce8801f Bluetooth: Mesh: Add support for sending NetKey Add message
Add configuration client model support for NetKey Add message, as well
as a mesh shell command for calling the new API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg 74e1f51350 Bluetooth: Mesh: Coding-style: Remove redundant whitespace
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Michael Scott 2386ce7af8 net: if: fix ND reachable calculation
The reachable calculation for ND is using fractions combined with
integers and getting rounded to very small results (1ms or 0ms).
Let's split up the fraction into it's numerator and denominator
and perform the math in a better way to get the correct results.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-12-05 07:51:59 -06:00
Johan Hedberg 22f3d36ba7 Bluetooth: Mesh: Fix relaying from GATT to Advertising
The logic for choosing to relay from the GATT bearer to the
advertising bearer was still buggy. This patch refactors the logic to
a separate helper function to make it clearer.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 13:52:10 +02:00
Johan Hedberg 7d7121b1ee Bluetooth: Mesh: Fix copy-paste mistake in log message
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 13:36:31 +02:00
Johan Hedberg dd839d90ac Bluetooth: Mesh: shell: Fix AppKey Add command handler
The command handler already has support for decoding from hex, however
it was not using the decoded value when calling the client API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 13:36:31 +02:00
Johan Hedberg 39298cf3c5 Bluetooth: Mesh: Fix format specifier for s32_t
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 13:36:31 +02:00
Johan Hedberg c0b5a91588 Bluetooth: Mesh: Fix using the correct transmit state
If relaying is not supported, or disabled, the Relay Transmit state
will normally be 0, which is not what we want to use when proxying out
packets from GATT clients. The bt_mesh_net_relay() function is also
used for sending out locally originated packets, in which case the
Relay Retransmit state is also the wrong one to use (the Network
Transmit state should be used instead).

This patch makes sure we only use the Relay Retransmit state for
packets originating from the advertising bearer, and for all other
packets use the Network Transmit state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 11:13:31 +02:00
Johan Hedberg 4871d8567b Bluetooth: Mesh: Fix relaying conditions for Adv & GATT bearers
The bt_mesh_net_relay() function was missing several important checks
for whether a PDU should be relayed or not. In particular, it would
relay a packet from adv to adv even if the Relay state was set to
disabled, as long as GATT Proxy was set to enabled. The code would
also relay packets to the GATT Proxy bearer if the Relay state was set
to enabled but GATT Proxy was set to disabled. This patch addresses
both of these issues.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 11:13:31 +02:00
Johan Hedberg ad6f9b15e6 Bluetooth: Mesh: Fix changing Relay state from Not Supported (0x02)
If the Relay state is set to Not Supported (0x02) the Config Relay Set
message should not change the state, rather just return its current
value.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 11:13:31 +02:00
Johan Hedberg 967d8b5b59 Bluetooth: Mesh: Fix beacon cache handling
The beacon cache handling was severely broken in the way that the
cache_add() function was incorrectly mapping net_idx to array index,
which could have lead to array overflows.

To fix this, while also cleaning things up, move the cache to the
actual bt_mesh_subnet struct. This e.g. lets us avoid having to track
the net_idx twice.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-01 12:28:56 +02:00
Johan Hedberg a3448aba9f Bluetooth: Mesh: Fix setting an upper limit on beacon interval
https://www.bluetooth.org/errata/errata_view.cfm?errata_id=9807

"If the computed Beacon Interval is less than 10 seconds, it should be
set to 10 seconds. If the computed Beacon Interval is greater than 600
seconds, it should be set to 600 seconds."

The lower limit is already covered by how frequently the delayed work
callback gets called, so we just need enforce the 600 second maximum.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-01 12:28:56 +02:00
Johan Hedberg 77ca943fd5 Bluetooth: Mesh: Fix sending beacons to Friend Queue & GATT clients
Whenever there's a security change (Key Refresh or IV Update) we
should immediately send beacons to any Friend Queues or connected GATT
clients. Introduce a helper function to do this, and make sure it's
called from all places that change the Key Refresh or IV Update
states.

This fixes test case MESH/SR/PROX/PB-12-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-30 19:29:15 +02:00
Johan Hedberg 8f2a7f2d46 Bluetooth: Mesh: Fix logging mesh addresses
Addresses are 16-bit and not 8-bit.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-30 19:29:15 +02:00
Johan Hedberg 1210258603 Bluetooth: Mesh: Clearly document the magic 18 byte minimum length
This makes it clear why 18 is a valid minimum network PDU length to
enforce. This is particularly important since as of writing this patch
there's at least one PTS test case which sends too small PDUs, which
could potentially lead to people thinking the implementation is at
fault (it's not).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-30 14:58:09 +02:00
Johan Hedberg 6078f8acc2 Bluetooth: Mesh: Introduce API for clearing the RPL
Some Transport Layer tests (MESH/NODE/TNPT/BV-13-C in particular)
require manual clearing of the RPL. Introduce an API for it as well as
a command to the mesh shell to call the API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:49:45 +02:00
Johan Hedberg 3222662553 Bluetooth: Mesh: Fix Replay Protection List checking
If we the stored RPL entry was for an old IV Index, and the received
PDU is for a new IV Index we should not be comparing the sequence
number (as it's by definition always greater than the old one).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:49:45 +02:00
Johan Hedberg 859afbf39b Bluetooth: Mesh: Fix disconnecting clients when disabling GATT Proxy
Section 4.2.11 of the Mesh Profile Specification 1.0 states:

"Upon transition from GATT Proxy state 0x01 to GATT Proxy state 0x00
the GATT Bearer Server shall disconnect all GATT Bearer Clients."

This also makes test case MESH/SR/MPXS/BV-08-C pass.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg 90ea44cc4b Bluetooth: Mesh: Fix initializing Node ID start time
The bt_mesh_proxy_identity_enable() function was missing a line to
properly initialize the start time for Node Identity advertising.
Without it this public function wouldn't work as intended.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg 012e763311 Bluetooth: Mesh: Fix GATT Proxy Service CCC read permissions
Test case MESH/SR/MPXS/BV-04-C requires the Proxy Service CCC to have
read permissions in order to pass.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg ff7d5ca910 Bluetooth: Mesh: Fix GATT Proxy & Node Identity state binding
Section 4.2.11.1 of the Mesh Profile specification 1.0 states:

"When the GATT Proxy state is set to 0x00, the Node Identity state for
all subnets shall be set to 0x00 and shall not be changed."

When the proxy state has been changed we also need to wake up the
advertising module to make sure we do the right kind of advertising.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg 84409d0161 Bluetooth: Mesh: Deliver TTL=1 PDUs only to the local net interface
Section 3.4.5.2 in the Mesh Profile Specification (1.0) states:

"The output filter of the interface connected to advertising or GATT
bearers shall drop all messages with TTL value set to 1."

Also: https://www.bluetooth.org/errata/errata_view.cfm?errata_id=9811

Note that this is specifically 1 and not 0, since e.g. Friend PDUs
always go out with TTL 0.

Another noteworthy thing is that the way this has to be implemented is
slightly contrary to how it's presented in the specification (both in
the text as well as the Message processing flow diagram in section
3.11. If this was implemented following the spec to its word, then any
PDU received over GATT or Advertising with TTL 2 would never be
relayed (since the TTL would be 1 when the PDU gets rerouted back to
the bearer). This would be both counterintuitive to the intended
purpose of the TTL, and would also be contrary to the test
specification (see Test Procedure step 1 in MESH/NODE/RLY/BV-01-C).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg bed5472cab Bluetooth: Mesh: Remove unnecessary variable
Most places in bt_mesh_friend_req() used rx->sub (which is already
quite short in itself), so just remove the only remaining user and the
helper variable itself.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Vakul Garg 26f43950f2 net: pkt: Corrected data length appended in net_pkt_append()
The maximum data length that can be appended using net_pkt_append()
should be set to TCP send_mss only if it is smaller than allowed
payload length in net_pkt.

Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
2017-11-28 12:30:01 -05:00
Vakul Garg 687bd0d710 net: pkt: Account for IP header length for allowable payload data
For calculating amount of payload data that can be added in a packet,
we need to subtract IPv6 or IPv4 header lengths from MTU.

Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
2017-11-28 12:30:01 -05:00
Ding Tao 6caf6964cd net: pkt: Fix possible division by zero
When net debugging is enabled, the count variable is initialized to -1.
This may cause division by zero if there is only one fragment in pkt.
Solve this by setting the count to 0 and checking the value before the
print at the end of the function.

Successfully tested on STM32F407 SoC.

Signed-off-by: Ding Tao <miyatsu@qq.com>
2017-11-28 12:28:10 -05:00
Johan Hedberg c393bfd8e3 Bluetooth: Mesh: Fix Friend messaging state tracking
There were several issues with the code:

 - queue_size wasn't properly kept up to date, leading to erroneous
   buffer discarding logic.

 - Poll timeout when there were buffers in the Friend Queue didn't
   work because we didn't track if there'd been a preceding request
   for messages or not (hence the added pending_req variable).

 - We would overwrite the recv_delay timer if there was another
   request while the previous one was still sending (a likely scenario
   if we send out multiple advertising events per packet).

 - We weren't canceling the sending of a buffer if the Friendship was
   suddenly cleared.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg 49c5e5546a Bluetooth: Mesh: Log information about the on-behalf-of flag
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg b123799ebe Bluetooth: Mesh: Reduce logging clutter for LPN lookups
The logs for looking up LPNs were spamming the console a bit too much.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg c65d04655d Bluetooth: Mesh: Fix looking up existing friendship contexts
When receiving Friend Offers we should also consider unestablished
contexts, and simply start from the beginning if that happens.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg a9a18cec7b Bluetooth: Mesh: Fix clearing Friend state upon reset
Not clearing the Friend state could risk invalid timers staying
active, etc.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg 2d63f5e480 Bluetooth: Mesh: Fix & clean up Friendship Credential handling
Pass the subnet to some friend_cred_* APIs since it contains all
necessary information for choosing the right keys to generate them
from. Also shorten the API names to avoid awkward line splitting -
these are internal APIs so it's an acceptable compromise. One bug that
this fixes as part of the cleanup is using the right NetKey Index when
clearing Friendship: previously the code was always using the index of
the first subnet, regardless of which subnet the Friendship was based
on.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg e7199060c6 Bluetooth: Mesh: Remove unnecessary logic for key selection
Key Refresh Phase 2 is analogous to the Key Refresh flag being set.
This means that the flag can directly be used as the index to the
new/old key two-element array.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg 46f8c7fb44 Bluetooth: Mesh: Fix clearing network message cache
Since the stack supports runtime reset and reprovisioning, we need to
clear the network message cache whenever creating a new mesh network.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg 48e6bfaaa7 Bluetooth: Mesh: Fix proxy advertising handling
Remove inconsistent and sometimes unreliable tracking of what
advertising parameters should be used and when the Node Identity
advertising started. The main change that facilitates this is to have
the Node ID start timestamp as part of the mesh subnet context.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg bdcf8c3692 Bluetooth: Mesh: Use 32-bit math for Node ID duration
The Node Identity duration is at most 60 seconds, so it's safe to use
32-bit timestamps.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg 7909c3d3fa Bluetooth: Mesh: Introduce option for Node ID timeout
Some PTS test cases only work when we're advertising using Network
Identity. Using the default timeout of 60 seconds for Node Identity
will cause this test cases to fail (i.e. the PTS gives up before
Zephyr transitions to advertising from Node Identity to Network
Identity).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg 699a7c9e85 Bluetooth: Mesh: shell: Fix parsing "boolean" parameters
The shell was being inconsistent in its parsing of boolean parameters.
Some commands were documented as accepting "on" but were actually
parsing the parameter with strtoul() which would result in 0.
Introduce a new helper to convert a string to a u8_t which still
accepts "on" or "enable". This gives us full flexibility of having a
simple interface to the user, but still allowing non-boolean values to
be tested (since on-air the value is a full octet).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg f81b23a624 Bluetooth: Mesh: shell: Add command for setting the UUID
Instead of having a hard-coded UUID, introduce a command to change it.
This is particularly useful if there are many unprovisioned nodes
around.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg 4c180d6fbf Bluetooth: Mesh: shell: Make Static OOB optional
Having the Static OOB value set up-front can be confusing to the user
since they will not know what the value is. Start off by having it
unset, but introduce a new command using which the user can either set
or clear it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Anas Nashif 1092a25978 kconfig: move GDB_INFO kconfig to subsys/debug
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-11-27 22:15:30 -05:00
Vinayak Kariappa Chettimada b022f72cf4 Bluetooth: shell: Fix compile error due to missing memq.h include
Fixes the following compile error when building
tests/bluetooth/shell application:

In file included from subsys/bluetooth/shell/ticker.c:16:0:
subsys/bluetooth/shell/../controller/util/mayfly.h:21:2:
error: unknown type name 'memq_link_t'
  memq_link_t *_link;
  ^~~~~~~~~~~

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-27 13:48:24 -08:00
Johan Hedberg f20afb7473 Bluetooth: Mesh: Restrict scope of variables in health_get_registered()
Don't declare the variables in a wider scope than what they're needed
for.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 12:10:49 +02:00
Johan Hedberg c2fd67699d Bluetooth: Mesh: shell: Fix sending health publication
We need to send out a Health Fault Current Status (the Health Model's
publication message) when all faults are cleared. The logic for
calculating number of faults was also wrong after the updated model
publication API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 12:10:49 +02:00
Johan Hedberg 8a13066a4e Bluetooth: Mesh: shell: Fix health publication message size
The Health Current Fault message size was being set too small to fit
any faults. Use a macro to make sure the size gets applied in both
places where appropriate.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 12:10:49 +02:00
Vakul Garg d5134d9bf3 Bluetooth: Added missing checks for whether CONFIG_BT_PRIVACY is enabled
Fixes error encountered during connecting BLE endpoint.
[bt] [ERR] le_remote_feat_complete: Unable to lookup conn for handle 32

This is to work around a buggy controller that states support for
enhanced privacy, but misbehaves when it's enabled. This change
makes it possible to ensure the host doesn't try to enable the enhanced
event by simply disabling the privacy feature in Kconfig.

Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
2017-11-27 11:30:00 +02:00
Johan Hedberg d0826f3392 Bluetooth: Mesh: Fix NetKey Update behavior in Phase 1
If we get a different key value in Phase 1 we should return the same
"Cannot Update" error as in phases 2 and 3. This fixes test case
MESH/NODE/KR/BI-02-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 10:17:54 +02:00
Johan Hedberg 48aecd1513 Bluetooth: Mesh: Add IV Update test mode API
This makes it possible to pass all IV Update tests without having to
build a custom configuration for some of the tests. We also disable
the feature in all sample configurations, but leave it on in the
tests.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 10:17:54 +02:00
Johan Hedberg a41449ef2a Bluetooth: Mesh: shell: Add iv-update command
This command is needed to pass some IV Update-related PTS tests.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 10:17:54 +02:00
Johan Hedberg 6e2a3863ac Bluetooth: Mesh: Fix creating initial beacon data
There was a chance that initial beacons for subnets would be sent with
uninitialized data. Make sure we initialize the beacon data each time
when we create a new subnet.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 10:17:42 +02:00
Johan Hedberg a48724fd0f Bluetooth: Mesh: shell: Fix & clean up command help
Use NULL instead of "", fix typos, and indicate app-key-add last
parameter as optional (to match the command implementation).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg 35fd523b03 Bluetooth: Mesh: Add support for manipulating Label UUIDs
Add support for sending messages that add, delete or overwrite Label
UUIDs, and add commands for these to the shell. With the help of these
commands it's possible to pass Transport Layer PTS tests (in
particular TNPT/BV-05-C) by manually adding a Label UUID through
module subscription, since the test case itself does not do this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg 23ffed0511 Bluetooth: Mesh: Improve logging related to Label UUID lookups
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg e80881d0b9 Bluetooth: Mesh: shell: Add raw network PDU sending support
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg b0393caeb5 Bluetooth: Mesh: shell: Add support for decoding hex strings
Add helper to decode arbitrary-length hex strings. The first user is
the AppKeyAdd handler.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg 561b458011 Bluetooth: Mesh: shell: Fix decoding vendor model IDs
The code was accessing the wrong parameter.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Aska Wu 8a20c4add7 net: context: Make sure contexts lock is released when error
Also, set the in-use flag after it is allocated successfully.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-24 08:30:00 -05:00
Patrik Flykt 753daa65f9 net: pkt: Compute TX payload data length
Compute the length of the TX payload that is transported in one
IPv4 or IPv6 datagram taking into account UDP, ICMP or TCP
headers in addition to any IPv6 extension headers added by RPL.
The TCP implementation in Zephyr is known to currently carry at
maximum 8 bytes of options. If the protocol is not known to the
stack, assume that the application handles any protocol headers
as well as the data. Also, if the net_pkt does not have a
context associated, length check on the data is omitted when
appending.

Although payload length is calculated also for TCP, the TCP MSS
value is used as before.

Define IPv4 minimum MTU as 576 octets, See RFC 791, Sections 3.1.
and 3.2.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2017-11-24 08:27:39 -05:00
Johan Hedberg 9097a66460 Bluetooth: Mesh: LPN: Fix clearing group status
When the Friendship is lost the group status tracking needs to be
cleared.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 11:37:09 +02:00
Johan Hedberg 9859146722 Bluetooth: Mesh: LPN: Fix clearing pending request
The code would unconditionally clear sent_req in update_timeout(),
which would e.g. cause us to switch to Friend Polls if the Friend
didn't respond to a Subscription List Add/Remove on the first attempt.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 11:37:09 +02:00
Johan Hedberg 4cc6a4fcbb Bluetooth: Mesh: Increase initial poll timeout
The purpose of using something less than the configured poll timeout
was to cover the case where the LPN establishes Friendship before the
provisioner has completely configured it. However, there's the "more
data" flag in the initial Friend Response, and we now also have a
public API to request for more messages. Both of these features
diminish the value of having a reduced initial timeout. Also, some LPN
test cases do not expect us to send frequent polls initially, causing
failures with the PTS.

Therefore, introduce a Kconfig option to set the initial timeout, and
make it default to the actual poll timeout.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 11:37:09 +02:00
Johan Hedberg 89030f0906 Bluetooth: Mesh: Introduce public LPN APIs for better control
Many apps, the mesh shell included (due to PTS test requirements)
benefit from exposing LPN state and polling outside of the stack.
Introduce new APIs for these, and add code to the mesh shell module to
take advantage of them.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 11:37:09 +02:00
Johan Hedberg 46e0afdf82 Bluetooth: Mesh: Health: Fix requiring specific Company ID
The Health Fault Test & Test Unacknowledged messages are supposed to
be sent for more than the Node Composition Data Company ID. It's true
that some PTS tests require the message to be ignored for
non-composition data ID, however that's something that should be
covered by the application that's used for testing, and not the
generic Health Server Code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg d588850c0c Bluetooth: Mesh: Add support for Health Attention messages
Add support for sending Health Attention messages, as well as commands
to use these new APIs from the shell.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 30d6761396 Bluetooth: Mesh: Introduce helpers to wait for a status message
There was a lot of code duplicated in the Foundation Client Models for
waiting on a specific status message. Refactor this into helper
functions (one per client model).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 7e8f9afee5 Bluetooth: Mesh: Add support for Health Period messages
Add support for sending Health Period messages, as well as commands to
use these new APIs from the shell.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg ce10be3a2a Bluetooth: Mesh: Add support for Health Fault Test messages
Add support for sending Test and Test Unacknowledged messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 987c68b7aa Bluetooth: Mesh: Add support for Health Fault Clear messages
Add support for sending Clear and Clear Unacknowledged messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 9e3ebf19d9 Bluetooth: Mesh: shell: Add Health Fault support to the server
Add commands and callbacks to manage the Registered Fault state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 1699d045f8 Bluetooth: Mesh: shell: Use a valid Company ID
The Company ID 0xffff is treated as invalid in some contexts, so use a
valid one. Also, the Health tests require the Health Fault Company ID
to match that found in the Composition Data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 2eda34cf3f Bluetooth: Mesh: Add support for receiving Health Current Status
Add a callback to the Health Client Model context, so that the
application is able to receive Health Current Status messages that
some Health Server Model publishes.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg b26231d770 Bluetooth: Mesh: Add support for sending Health Fault Get message
Add the needed Health Client API for sending Health Fault Get, and add
a command to the shell to utilize it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 7ef5e53e28 Bluetooth: Mesh: Add skeleton for Health Client model
Add a skeleton for the Health Client model.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 2a6010f1b3 Bluetooth: Mesh: shell: Add appidx command for setting the AppIndex
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Vinayak Kariappa Chettimada f9cd9d4a7b Bluetooth: controller: Fix compile error when LE_ENC is disabled
Fixes the following compile error when CONFIG_BT_CTLR_LE_ENC
is disabled:
subsys/bluetooth/controller/ll_sw/ctrl.c: In function
'isr_rx_conn_pkt_ctrl':
subsys/bluetooth/controller/ll_sw/ctrl.c:2613:29: error:
'LLCP_ENCRYPTION' undeclared (first use in this function)
         (conn->llcp_type != LLCP_ENCRYPTION)) ||
                             ^~~~~~~~~~~~~~~
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-22 18:48:05 -05:00
Johan Hedberg ea68c3aa22 Bluetooth: Fix compiler warning when VS HCI is unset
Fixes:

subsys/bluetooth/host/hci_core.c: In function ‘set_static_addr’:
subsys/bluetooth/host/hci_core.c:4043:1: error: label ‘generate’ defined
but not used [-Werror=unused-label]
 generate:
 ^~~~~~~~

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 18:48:05 -05:00
Vinayak Kariappa Chettimada 9fd502f956 Bluetooth: controller: Use PPI indices 14/15 for PA/LNA
PA/LNA feature being not default enabled, keeping the PPI
indices used for this feature at the higher indices would
allow use of these PPI indices by other drivers, for
instance the nRF5 software PWM driver.

Software PWM driver provides 3 PWM pins/channels using upto
6 PPI channels. If BLE controler where to use 0-13, then
14-19 PPI indices can be used by the PWM driver.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-22 18:46:20 -05:00
Jukka Rissanen 1789a9356b net: app: Honor MTU when sending TLS/DTLS data
Make sure we send all the data that is needed to be sent and in
proper MTU size chunks.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-22 10:10:31 -05:00
Tomasz Bursztyka b52c0f24a6 net/ieee802154: Make RAW mode generic
- Renaming NET_L2_RAW_CHANNEL to NET_RAW_MODE
- Create a generic IEEE 802.15.4 raw mode for drivers
- Modify the IEEE 802.15.4 drivers so it passes the packet unmodified,
up to code using that mode to apply the necessary changes on the
received net_pkt according to their needs
- Modify wpanusb/wpan_serial relevantly

Fixes #5004

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-11-22 10:10:09 -05:00
Vinayak Kariappa Chettimada f44efd12fa Bluetooth: controller: Replace void * with memq_link_t
Replace use if void * declaration related to memq links with
more readable memq_link_t.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-22 15:28:49 +01:00
Johan Hedberg 6fda8b2b4d Bluetooth: Mesh: Friend: Fix poll timeout type
The Poll Timeout needs to be at least 24 bits, so u16_t doesn't
suffice and will potentially result in truncation. Use u32_t, thereby
also fixing a coverity warning.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg 9b87e0f2cc Bluetooth: Mesh: Fix coverity warning of unchecked return
Most places check the return value of bt_mesh_model_send(), so check
for it in all places.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg 2849662aa8 Bluetooth: Mesh: Fix dereferencing mod->pub too early
The bt_mesh_model_publish() is supposed to return a "not supported"
error if the publish context doesn't exist. Fixing the premature
dereferencing also fixes coverity warnings.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg 7c53d31ed2 Bluetooth: Mesh: remove redundant 32-bit wrap-around code
The separate checking for "now < reftime" is unnecessary, since the
integer over/under-flow for unsigned 32-bit values resulting from
subtraction will give the right delta even if 'now' is less than the
reference.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg 15fe221f13 Bluetooth: Mesh: Fix accuracy of Publish Period
After the Publish Retransmit state was introduced the Publish Period
measurement would begin once the previous Publish message has finished
transmitting. This will however cause inaccurate periods, which is
particularly an issue with the PTS that expects accuracy of less than
0.5 seconds (apparently).

Since the publication timer is also used for the retransmissions we
can't simultaneously use if for the period as well. Therefore, we
introduce a new variable called period_start which makes a note of
when the period was supposed to start, and then once all
retransmissoins are done initializes the timer with the send duration
taken into account.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg 8f1541184f Bluetooth: Mesh: Fix non-periodic Model Publication
The only generally available model supporting publication that's
convenient to be used for testing is the Health Server Model.
Unfortunately since this model supports period publication, the
non-periodic side got less attention and had some bugs.

The first thing that needs to be done is to verify that the period
returned by bt_mesh_model_pub_period_get() is positive. If it's zero
then no periodic publication should take place.

Another thing that this patch cleans up is the naming of the callback
used for periodic publishing. There's no need do require the callback
to call bt_mesh_model_publish() since this must happen no matter what,
so instead rename the callback from 'func' to 'update' and have the
access layer call bt_mesh_model_publish() if the callback was
successful.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Robert Chou b678895a6d net: lwm2m: POST with <obj>/<obj instance> is a WRITE op
Per LwM2M specification V1_0_1-20170704-A, table 25.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-21 09:28:12 -05:00
Johan Hedberg 03151fc8d7 Bluetooth: Mesh: Proxy: Downgrade advertising errors to warnings
When a small amount of supported connections is configured (especially
the default number of 1), connectable advertising may fail. This is
perfectly fine since as soon as a disconnection event happens the
advertising will be successfully restarted. To avoid causing
unnecessary user worries, downgrade the resulting errors to warnings.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-21 15:02:25 +02:00
Johan Hedberg 95bef3694e Bluetooth: Mesh: Fix node reset
There were some things that were working only when receiving a Node
Reset message from someone else, but not when the app called
bt_mesh_reset() directly. There was also some state cleanup missing
for the transport layer. This patch addresses all of these issues.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-21 15:02:25 +02:00
Paul Sokolovsky 21f31e90ec net: sockets: Handle EINTR return from k_poll()
In 90b471fe4, there was a change to make k_poll() return EINTR error
if it was cancelled with k_fifo_cancel_wait(). Handle this change, or
otherwise sockets EOF handling was broken.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-21 07:01:49 -05:00
Aska Wu 3689107b59 net: tcp: First check sequence number
Previously, the connection will be reset easily due to a forged TCP
reset with a random sequence number.

As described in RFC793 p.69, we should check if the sequence number
falls into the receiver window at first.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-21 07:00:20 -05:00
Johan Hedberg 3a072f07a1 Bluetooth: Mesh: shell: Declare mandatory dependency on BT_MESH_CFG_CLI
The Configuration Client is such a generally useful feature for the
shell that it makes sense to have it as a mandatory dependency (the
shell wasn't anyway compiling at the moment without it).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-21 13:32:53 +02:00
Johan Hedberg 5a3a9aed49 Bluetooth: Mesh: Update TODO file
Update the TODO file with the latest status.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-21 12:19:41 +02:00
Vinayak Kariappa Chettimada 25737d9963 Bluetooth: controller: Optimise memq interface
Optimised the parameter passing order of memq interface such
that the compiled code uses less space and execution time.

Having a parameter that gets returned as the first parameter
passed to a function avoids instructions required to have
the result in the return register.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-21 09:11:34 +02:00
Johan Hedberg 47756c8364 Bluetooth: Mesh: shell: Add mod-sub-del command
Add command to delete model subscriptions.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg 324336167e Bluetooth: Mesh: Add Model Subscription Del & Overwrite support
The Del and Overwrite operations have the exact same parameters and
expected status response as the Add operation, so we can reuse most of
the code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg a5340e72a3 Bluetooth: Mesh: Fix ignoring all messages in LPN mode
Even though we have LPN enabled, we might still receive messages
through other network interfaces than the advertising one (e.g. the
local network interface).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg ec9aaaed23 Bluetooth: Mesh: Fix calling send start for multi-segmented messages
Using the start callback, especially with multi-segment messages, may
not be super useful for applications, but we should support if if they
do provide it. One application could e.g. be to calculate the duration
it takes for a multi-segment message to be completely received by the
remote end.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg e7bb76e2b6 Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:

 - The Publish Retransmit State was not taken into account at all
 - Health Server used a single publish state for all elements

To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.

Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.

To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.

The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.

The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg f9fad553ac Bluetooth: Mesh: Fix encoding/decoding Publish Retransmit value
The Model Publish Retransmit Interval is in units of 50ms and not 10ms
like the other transmit/retransmit states. Create dedicated macros for
the Publish Retransmit State and use them where appropriate.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg 4bf045e282 Bluetooth: Mesh: Use a unified send callback also for public API
There's no need for callback exposed in the public API to be something
different than what's used internally. In fact this would just
complicate things. This patch exposes the internal callback under a
bt_mesh_adv_cb name and uses it throughout the mesh stack.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg 224506c78c Bluetooth: Mesh: Fix notifying message send completion for GATT proxy
In case an outgoing message gets only delivered to the proxy interface
we should not forget to notify the send callbacks of this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg c3ad883872 Bluetooth: Mesh: Introduce a second advertising callback
Some places of the code are interested in when the first advertising
event goes out. Others, on the other hand, are interested when the
last advertising event goes out. Some are even interested in both of
these. Instead of providing a single callback, provide a struct with
two possible callbacks for sending advertising PDUs.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg 8beb6784d3 Bluetooth: Mesh: Introduce user data for the advertising callback
This simplifies the callback implementations since they no-longer need
to do their own look-ups of the needed context.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg ad7afa0c7c Bluetooth: Mesh: Move per-buffer mesh meta-data to external struct
We've so far been trying to keep the per-buffer mesh meta-data to
a maximum of 8 bytes in anticipation of upcoming net_buf refactoring
that'll have all net_bufs in the system with the same sized user data.

It's however slowly becoming unfeasible to do this - e.g. simply
adding user data to the sending callback would already fill up the
full 8 bytes.

To solve this issue, treat the net_buf user data as just a pointer to
the actual user data, and keep the actual user data in a separate
array. We still keep taking advantage of net_buf_id() however, so
buffers can cheaply be mapped to their meta-data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Aska Wu 718b3cd7d0 net: sockets: Support ipv6 wildcard and loopback address
Add in6addr_any and in6addr_loopback which are defined in RFC2553 Basic
Socket Interface Extensions for IPv6.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-20 13:42:38 +02:00
Aska Wu b6c8c2d749 net: tcp: Fix tcp passive close
Previously, if passive close is peformed, the net context is released
after FIN is received and FIN,ACK is sent. The following last ack from
the peer will be treated as an improper packet, RST is sent to the peer.

This patch refines tcp_established() by centralizing the tcp state
transition and releases the net context only if NET_TCP_CLOSED is
reached.

Besides, the logic that releases the net pkt without appdata (i.e. ACK
or FIN) is moved from packet_received() to tcp_established(). This makes
packet_received() less dependent on the protocol and make the usage of
net pkt more clear in tcp_established().

Fixes: #4901

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-20 13:42:10 +02:00
Vinayak Kariappa Chettimada 9746b2a75d Bluetooth: controller: Fix memq_dequeue function
When testing memq implementation used by controller, a
missing check on NULL pointer return could lead to NULL
pointer deferencing.

Current implementation of controller and mayfly do not
by design lead to NULL pointer dereferencing, this fix
is only for correct-ness and complete-ness.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-20 10:42:53 +02:00
Jukka Rissanen c0fc269edf net: app: Do not allow local unspecified address in client
Do not allow :: or ANY address in client when sending data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-18 08:52:40 -05:00
Johan Hedberg 6d7f171549 Bluetooth: Mesh: Fix clearing incomplete Friendship upon reset
When resetting there is no point trying to start clearing the
Friendship since there will not be any security material left to send
out PDUs.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-17 14:44:19 +02:00
Johan Hedberg 62f2475e3e Bluetooth: Mesh: Fix compiler warning for access.c
This fixes a warning for duplicate const declaration specifier.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-17 14:44:19 +02:00
Johan Hedberg 1edb69e4b6 Bluetooth: Mesh: Make AppKey binding implicit for Model Publication
The common interpretation (among other implementations) seems to be
that Model Publication for a given AppKey Index implies a binding for
that AppKey. This isn't currently explicitly stated in the spec, but
in order to improve interoperability go with this interpretation as
well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-17 13:24:30 +02:00
Johan Hedberg 1c825c825f Bluetooth: Mesh: Friend: Fix setting pending_buf variable
The variable for tracking that a buffer from the Friend Queue hasn't
been sent yet was not being properly set.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-17 13:09:45 +02:00
Aska Wu 7e58c5609a net: sockets: Fix net pkt leak
If net_context_recv() returns a error, net pkt will not be released. For
example, net_context_recv() returns -EBADF because the TCP connection is
closed by the peer.

Handle the return value instead of using SET_ERRNO().

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-17 12:58:32 +02:00
june li 486e156827 net: dhcpv4: Unref net_pkt if message sending fails
If we cannot send a DHCP message, then unref the net_pkt
in order to avoid a buffer leak. Earlier we tried to
unref NULL net_pkt which is not correct.

Signed-off-by: june li <junelizh@foxmail.com>
2017-11-17 11:16:04 +02:00
Johan Hedberg bd69b2127e Bluetooth: Mesh: Use dedicated struct for heartbeat subscription
This simplifies the API since there is no-longer a need to pass a huge
number of function arguments around.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Johan Hedberg d4365e16f9 Bluetooth: Mesh: Use dedicated struct for heartbeat publication
This simplifies the API since there is no-longer a need to pass a huge
number of function arguments around.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Johan Hedberg a18a22524f Bluetooth: Mesh: shell: Add mod-pub command
Add a command for getting and setting the model publication. We also
have to adjust the app's configuration, since both the Model
Publication Set and Status messages are segmented messages, meaning we
need two TX and RX segment contexts.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Johan Hedberg 05be6b8033 Bluetooth: Mesh: Add support for sending Model Publication messages
Add support for Model Publication Set/Get and their vendor model
variants.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Johan Hedberg 2e50ba9847 Bluetooth: Mesh: Use invalid CID instead of bool for non-vendor models
The value 0xffff is reserved, so we can use that to indicate whether
there's a vendor model in question or not. Simplifies things over the
previously used separate boolean value.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Robert Chou 9dcbbdb3e2 net: lwm2m: fix sending packet w/o token setup when error
Token is missing when we jump to the error and token is not yet setup.
To correct it, we grab the token from the input packet at the beginning
of the handle_request()

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-16 10:21:14 +02:00
Johan Hedberg bde9dcd3bc Bluetooth: Mesh: Fix enabling scanning after provisioning
There were some needed changes missing after the update to have manual
control of PB-ADV & PB-GATT provisioning bearers. E.g. the test for
CONFIG_BT_MESH_LOW_POWER in net.c was no-longer indicative of scanning
being on or not.

Do the scan enabling selection within the LPN module if LPN is
supported, or otherwise enable scanning unconditionally in
bt_mesh_provision().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 08:39:00 +02:00
Ramakrishna Pallala a895d21d63 subsys: random: Fix semaphore initial count of xoroshiro128
Semaphore state_sem initial count is set to 0 but k_sem_give()
is invoked first in sys_rand32_get() which will block the caller
forever.

Fix the issue by setting the initail count to count_limit.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2017-11-15 15:47:10 -06:00
Johan Hedberg 45f258686b shell: Fix looking up help for the current module
The code was not properly handling "help <cmd>" for the currently
selected module.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 7318904ae1 shell: Use struct shell_module instead of integer to refer to modules
It's much more intuitive to read "if (module)" instead of
"if (module != -1)" when checking for a valid module. Update the code
to use struct shell_module pointers instead of integers for tracking
modules.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 22b5ff9b29 shell: Redesign internal command handling
Make the internal commands (exit, select & help) as any other
commands, so that e.g. "help help" works as expected. Also redesign
the way commands are looked up to avoid duplicate lookups.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 329a6628e4 shell: Remove unnecessary function
The print_cmd_unknown() is just a two-liner and only called from a
single place, so just do the printk calls inline.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg f9e30ed582 shell: Fix command lookup for non-default modules
The code was completely broken wrt command lookups when the command is
given in the format "<module> <cmd> <args...>". It would only work if
the default module is not set, which is almost never the case (as most
apps set it explicitly).

Refactor the command handling by moving more logic up to shell_exec(),
so that get_cb() does a lookup for a single module

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg fe20f55d03 shell: Remove redundant checking for argv[0]
The way get_command_and_module() is used it's impossible for it to be
given an argv where argv[0] is NULL.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 74556b7abb shell: Fix unnecessary passing by reference of argc
The get_cb() function does not modify argc, so there's no point in
passing it by reference.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 39a733151d shell: Remove unnecessary first_string variable
This variable adds no value, and is in fact longer to spell out than
simply argv[0].

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 76fb522993 shell: Remove redundant checking for first parameter
The way the command line parsing works, argv[0] is always guaranteed
to be non-NULL as well as a non-empty string, so doing checks for this
in get_cb() is redundant.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 04fbb80adb shell: Remove unnecessary initialization of err
All code paths in shell_exec() are guaranteed to set err before
returning it, so doing this (rather curious) initialization is
completely unnecessary.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Michael Scott 6a5da2c574 net: lwm2m: fix max measurement checks
Copy/paste error was checking minimum measurements where it
should have been checking maximum measurements.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-11-15 15:31:45 +02:00