Commit graph

1085 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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