Commit graph

1495 commits

Author SHA1 Message Date
Mariusz Skamra 74dbd835c3 Bluetooth: Add BT_SMP_ENFORCE_MITM option
Having this option disabled, MITM flag state can be controlled by
bt_conn_security state. This option is enabled by default to not
change the current implementation behavior.
Related to SM/MAS/SCPK/BV-01-C.

Fixes #17463

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2019-07-11 15:54:17 +03:00
Joakim Andersson 3bddc20f87 Bluetooth: GATT: Fix segfault discover descriptors all UUIDs
Handle optional argument UUID in bt_gatt_discover with type
DISCOVER_DESCRIPTOR, bt_uuid_cmp doesn't check for NULL pointer.
On system with MMU (nrf52_bsim) this can result in segfault.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-10 18:57:37 +03:00
Johan Hedberg 408703e8dd Bluetooth: Mesh: Move under subsys/bluetooth/mesh
We've already got GATT services in subsys/bluetooth/services so
subsys/bluetooth/mesh is a more natural place. Aditionally this aims
to fix the Kconfig dependencies to be able to use mesh together with
BT_CUSTOM (i.e. a custom, potentially non-HCI, host stack).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-07-10 09:41:57 +03:00
Nicolas Pitre 6ce89204e6 Bluetooth: L2CAP: fix use of Z_STRUCT_SECTION_ITERABLE
Two sections are needed: bt_l2cap_fixed_chan and bt_l2cap_br_fixed_chan.
However the second one cannot be created using #define as the
preprocessor will expand it to the first before compilation happens,
sending bt_l2cap_br_fixed_chan instances in the wrong section.

This fixes commit 4e8ddfd640 ("Bluetooth: L2CAP: Make use of
Z_STRUCT_SECTION_ITERABLE").

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-04 20:42:02 +03:00
Luiz Augusto von Dentz 4e8ddfd640 Bluetooth: L2CAP: Make use of Z_STRUCT_SECTION_ITERABLE
This makes use of Z_STRUCT_SECTION_ITERABLE to define fixed channel
sections.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-07-04 17:00:09 +03:00
Luiz Augusto von Dentz 8b9920fd77 Bluetooth: GATT: Make use of Z_STRUCT_SECTION_ITERABLE
This makes use of Z_STRUCT_SECTION_ITERABLE to define static service
sections.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-07-04 17:00:09 +03:00
Luiz Augusto von Dentz dbe80fd987 Bluetooth: GATT: Fix registering on static service area
When registering a new service it has to account the area used by static
services.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-07-02 15:49:58 -04:00
Arthur Crepin-Leblond ba894d8b0a Bluetooth: gatt: Fix DB corruption when adding/removing service
Fix an issue in the gatt_register routine where removing a service and
adding it again would cause the database to have non-ascending
orderdered handles numbers and lead to an incomplete service discovery.

Fix: Go through the database and look for a place where to insert
the new service.

Signed-off-by: Arthur Crepin-Leblond <arthur.crepin@proglove.de>
2019-07-02 17:34:57 +03:00
Johan Hedberg 0d9dab300e Bluetooth: Introduce separate pool for discardable events
Introduce a separate buffer pool for events which the HCI driver
considers discardable. Examples of such events could be e.g.
Advertising Reports. The benefit of having such a pool means that the
if there is a heavy inflow of such events it will not cause the
allocation for other critical events to block and may even eliminate
deadlocks in some cases.

Also update all mesh samples not to specify explicit RX buffer counts
anymore. Instead, create appropriate defaults in Kconfig so that we
only need to override this in the app for cases like the bbc:microbit
with limited memory.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-07-01 16:36:15 +03:00
Johan Hedberg fc2fcd10cf Bluetooth: Add dedicated pool for HCI_Num_Completed_Packets HCI event
This event is a priority one, so it's not safe to have it use the RX
buffer pool which may be depleted due to non-priority events (e.g.
advertising events). Since the event is consumed synchronously it's
safe to have a single-buffer pool for it. Also introduce a new
bt_buf_get_evt() API for HCI drivers to simplify the driver-side code,
this effectively also deprecates bt_buf_get_cmd_complete() which now
has no in-tree HCI driver users anymore.

Fixes #16864

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-07-01 16:36:15 +03:00
Anas Nashif efb8df5366 cleanup: include/: move misc/stack.h to debug/stack.h
move misc/stack.h to debug/stack.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 536dd5a71f cleanup: include/: move misc/slist.h to sys/slist.h
move misc/slist.h to sys/slist.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5d001f3e41 cleanup: include/: move misc/byteorder.h to sys/byteorder.h
move misc/byteorder.h to sys/byteorder.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5eb90ec169 cleanup: include/: move misc/__assert.h to sys/__assert.h
move misc/__assert.h to sys/__assert.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif d1b2718687 cleanup: include/: move uart.h to drivers/uart.h
move uart.h to drivers/uart.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif e1e05a2eac cleanup: include/: move atomic.h to sys/atomic.h
move atomic.h to sys/atomic.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Johan Hedberg d57a7b5138 Bluetooth: Mesh: Fix provisioning send error handling
Log all send errors, but don't try to call e.g. prov_send_fail_msg()
since that'll almost certainly fail as well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Johan Hedberg c4e225109e Bluetooth: Mesh: Fix rejecting invalid remote public key
Mesh Profile Spec v1.0.1 | Section 5.4.2.3:
"The Provisioner and the device shall check whether the public key
provided by the peer device or obtained OOB is valid (see Section
5.4.3.1).

When the Provisioner receives an invalid public key, then provisioning
fails, and the Provisioner shall act as described in Section 5.4.4.
When the device receives an invalid public key, then provisioning
fails, and the device shall act as described in Section 5.4.4."

This is also in Erratum 10395 which is Mandatory for Mesh v1.0.

The code was already rejecting the key, however that rejection
happened only after we had already sent our public key as response,
which got interpreted as acceptance by the tester (PTS).

Fixes MESH/NODE/PROV/BI-13-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Johan Hedberg 10274718bb Bluetooth: Mesh: Generate new public key for each provisioning session
Mesh Profile Spec v1.0.1 Section 5.4.2.3: "If the public key was not
available using an OOB technology, then the public keys are exchanged
between the Provisioner and the unprovisioned device. For each
exchange, a new key pair shall be generated by the Provisioner and the
unprovisioned device."

This allows passing MESH/NODE/PROV/BV-12-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Johan Hedberg d6c34c4644 Bluetooth: Fix public key callback management
Clear the callback list once generation is complete and we've done
calling all callbacks. This lets us use bt_pub_key_gen() multiple
times, which before this patch could have resulted in a corrupt linked
list.

Also remove redundant callback dispatching from bt_pub_key_gen() since
the function checks for the PUB_KEY_BUSY flag in the beginning, i.e.
there cannot be other pending generation actions at this point in the
code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Johan Hedberg 60f47c2d7e Bluetooth: SMP: Make public key handling more robust
Update code to handle other users of the public key generation APIs
by fetching the current public key at the beginning of each SMP
session. This is particularly important if someone creates the (rather
odd) combination of Mesh and SMP where Mesh will regenerate a new
key pair after provisioning.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Johan Hedberg 8d9a65c2c8 Bluetooth: Mesh: Rename reset_link() to reset_adv_link()
This is a PB-ADV specific internal helper, so rename it appropriately
to avoid any confusion.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Johan Hedberg d39fbf5e9c Bluetooth: Mesh: Fix Public Key mismatch error handling
Mismatch in Public Key type will cause device to send Invalid Format
error, and treat any further PDU's as unexpected.

This affects MESH/NODE/PROV/BI-03-C test case.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Johan Hedberg 8de784a09d Bluetooth: Mesh: Fix missing protocol error timeout
Provisioning errors shouldn't cause device to close link. Upon error,
device will send Provisioning Failed PDU, and any further PDU's will
be considered as unexpected as per Mesh Profile section 5.4.4.

Also a timer is started every time device sends or receives a PDU.
This affects MESH/NODE/PROV/BV-10-C test case.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Laczen JMS 5f19c8160a subsys/settings: Update bluetooth module
Updated the bluetooth module to use static handlers. Removed the
old bt specific static registration.

The routine bt_settings_init() is still calling settings_init() which
IMO is not needed anymore.

Updates:

changed SETTINGS_REGISTER_STATIC() to SETTINGS_STATIC_HANDLER_DEFINE()
changed settings_handler_stat type to settings_handler_static type
removed NULL declarations
renamed bt_handler to bt_settingshandler, as bt_handler already exists.
renamed all bt_XXX_handler to bt_xxx_settingshandler to avoid any
overlap.
changed SETTINGS_STATIC_HANDLER_DEFINE() to create variable names from
_hname by just prepending them with settings_handler_.
updated all bt_xxx_settings_handler to just bt_xxx.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-26 16:31:01 +02:00
Johan Hedberg 46ea1df2ec Bluetooth: Fix not using log_strdup() for bt_uuid_str()
The string returned by bt_uuid_str() is not in ROM so log_strdup()
must be used on it. This also eliminates the following kind of warning
messages: "<err> log: argument 3 in log message "%s: start_handle
0x%04x end_handle 0x%04x type %s" missing log_strdup()."

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-26 13:37:44 +02:00
Peter A. Bigot 587c35fa64 Bluetooth: gatt: avoid assumptions about characteristic handles
Although the Characteristic Value descriptor is required to be
immediately after the characteristic descriptor, the specification
allows for gaps in the corresponding Attribute handles.  Use the value
handle from the characteristic descriptor for value reads.

See BLUETOOTH CORE SPECIFICATION Version 5.1 Vol 3, Part G section 2.5.1
(p. 2345), first paragraph.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-06-25 18:24:32 +02:00
Johan Hedberg 4857cb852c Bluetooth: Mesh: Fix segmented message RPL behavior
Update the Replay Protection List handling for segmented messages to
be more in line with Figure 3.43 in Mesh Profile Specification 1.0.
This means that the RPL check and update need to be split into two
independent steps rather than always doing these together.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-25 11:35:08 +02:00
Luiz Augusto von Dentz eb8abda6b0 Bluetooth: GATT: Fix bt_gatt_discovery with BT_GATT_DISCOVER_DESCRIPTOR
Fix iterating past the response which causes an invalid memory to be
accessed and passed over to the callback as if there were more
attributes found.

Fixes #16602

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-24 12:16:49 +02:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
Johan Hedberg 4e89d29416 Bluetooth: Fix expiring RPA when different local identities are used
When advertising with different identities we need to flag any
programmed RPA as invalid if it was generated using a different
identity.

Fixes #16893

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-19 11:07:52 +03:00
Johan Hedberg 72e80104c1 Bluetooth: Remove unused bt_hci_get_cmd_opcode() function
This function has no users in the tree.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-19 11:07:27 +03:00
Johan Hedberg a16d513162 Bluetooth: Remove unnecessary HCI command data array
This array was created because more than 4 bytes were needed, however
now the minimum is 8 bytes, so we can use the net_buf user data
directly.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-19 11:07:27 +03:00
Laczen JMS 8ca8708224 subsys/settings: Update client modules
This updates all client modules to const char processing of
setting names.

Update of peripheral_dis sample

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-18 17:57:08 +02:00
Luiz Augusto von Dentz db7b9a988b Bluetooth: Make it safe to allocate buffers from TX callback
This makes it safe to allocate buffer from the TX callback by freeing
the context before calling the callback which should wake up the TX
thread had it be pending on add_pending_tx.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-17 15:53:06 +03:00
Johan Hedberg 4396dc9c71 Bluetooth: Simplify bt_gatt_notify_cb() API
This API had several issues:

 - The parameter types and order were inconsistent with e.g.
   bt_le_adv_start()
 - There were no real users of num_params, which just caused increased
   code size and memory consumption for no good reason.
 - The error handling policy was arbitrary: if one of the
   notifications would fail it would be impossible for the caller to
   know if some notifications succeeded, i.e. at what point the
   failure happened. Some callers might also want to make note of the
   failure but continue trying to notify for the remaining parameters.

The first issue is easily fixable, but because of the other two I
think it's best we don't have this code as part of the stack, rather
require whoever needs it to do the for loop themselves. It's just a
few lines of code, so the benefit of having this in the stack was
anyway quite minimal.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-15 10:37:19 +03:00
Luiz Augusto von Dentz a788ce23da Bluetooth: ATT: Fix unbalanced use of k_sem_give
k_sem_give shall only be used if no callback has been set otherwise
k_sem_take was not called which can break the flow control.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-14 15:55:07 +03:00
Luiz Augusto von Dentz ec89ae6ff4 Bluetooth: ATT: Queue buffers on bt_att_send
This prevents threads to block which may deadlock when system wq is
used.

Fixes #16803

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-14 15:55:07 +03:00
Luiz Augusto von Dentz e61c5b3630 Bluetooth: L2CAP: Fix inverting of SCID and DCID on disconnect
For the request:

DCID shall map to rx.cid:
  'This field specifies the endpoint of the channel to be disconnected
  on the device receiving this request.'

SCID shall map to tx.cid:
  'This field specifies the endpoint of the channel to be disconnected
  on the device sending this request.'

For the response when receiving the roles are inverted.

Fixes #16799

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-13 14:33:27 +03:00
Luiz Augusto von Dentz e8d9609c36 Bluetooth: GATT: Fix bt_gatt_foreach_attr_type
Number of matches was not being properly handled causing the callback to
be called more than specified by the caller.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-12 20:09:29 +03:00
Tobias Svehagen 1c84d7c5eb Bluetooth: Change from bitfields to normal types
Since the bt_mesh_msg_ctx struct no longer has a size that is a
multiple of 2, the bitfields might as well be made to normal types
as this will minimize the code generated to access them.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2019-06-12 15:51:04 +03:00
Tobias Svehagen 4866fa9e58 Bluetooth: Make RSSI value available to mesh applications
By moving the rssi value from the bt_mesh_net_rx struct to the
bt_mesh_msg_ctx struct, it will be available to applications via
the mesh op callbacks.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2019-06-12 15:51:04 +03:00
Mariusz Skamra f6665c812e Bluetooth: gatt: Fix infinite read_by_uuid procedure
The attribute handle used to read next attribute has to be incremented
to not loop reading the same attribute.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2019-06-12 12:57:43 +03:00
Rich Barlow 5c6e09b10a Bluetooth: Mesh: LPN: Clear sent_req on failure
When trying to establish friendship the Friend must respond to the
initial Friend Poll with a Friend Update. If this initial Friend Update
response is not received the Friendship establishment process must start
again.

When starting a second Friendship establishment processes the `sent_req`
field of the `lpn` struct was left set to `TRANS_CTL_OP_FRIEND_POLL`.
This prevented the initial Friend Poll being sent out on the second
attempt. Since the Friend Poll was not sent, no timeout is set and
nothing happens ever again. No more Friendship Requests are sent.

This commit clears `sent_req` back to zero when no Friend Update
response has been received after the initial Friend Poll.

Fixes #16678

Signed-off-by: Rich Barlow <rich@bennellick.com>
2019-06-12 11:44:41 +03:00
Luiz Augusto von Dentz 8ba5b73e8e Bluetooth: GATT: Fix assuming writes to CCC will always contain 2 bytes
Although unlikely it is possible that a remote may attempt to send just
1 byte as the write request allows to do that:

BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part F
page 2320:

  'If the attribute value has a fixed length and the Attribute Value
  parameter length is less than or equal to the length of the attribute
  value, the octets of the attribute value parameter length shall be
  written; all other octets in this attribute value shall be
  unchanged.'

Fixes #16734

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-11 15:47:06 +03:00
Nicolas Pitre b1d3742ce2 linker generated list: introduce Z_STRUCT_SECTION_ITERABLE()
This convenience macro wraps Z_DECL_ALIGN() and __in_section() to
simplify static definitions of structure instances gathered in dedicated
sections. Most of the time those go together, and the section name is
already closely related to the struct type, so abstracting things behind
a simpler interface reduces probability of mistakes and makes the code
clearer. A few input section names have been adjusted accordingly.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-06 14:21:32 -07:00
Nicolas Pitre 8bb1f2a947 linker generated list: explicit alignment on data definitions
The alignment fix on struct device definitions should be done to all
such linker list tricks. Let's abstract the declaration plus alignment
with a macro and apply it to all concerned cases.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-06 14:21:32 -07:00
Anas Nashif 4c32258606 style: add braces around if/while statements
Per guidelines, all statements should have braces around them. We do not
have a CI check for this, so a few went in unnoticed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-06 15:20:21 +02:00
Luiz Augusto von Dentz aec04a02ed Bluetooth: GATT: Fix using invalid handle
When reading attributes from static services their handles will not be
set and must be resolved at runtime.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-06 13:32:17 +03:00
Joakim Andersson e182d75ef7 Bluetooth: host: Fix gatt indicate when conn is NULL
Fix gatt indicate when conn is NULL and called with characteristic
declaration as the attribute argument. In this case the handle was not
advanced to the characteristic value. This is inconsistent with the rest
of the notify and indicate API

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-06-05 17:24:36 +03:00
Johan Hedberg 82497eca2b Bluetooth: Mesh: Fix missing implementation of Proxy SAR timeout
Mesh Profile 1.0 Section 6.6:
"The timeout for the SAR transfer is 20 seconds. When the timeout
expires, the Proxy Server shall disconnect."

This will let qualification test case MESH/SR/PROX/BV-05-C pass
without requiring an explicit disconnect.

Fixes #16600

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-05 17:13:56 +03:00
Luiz Augusto von Dentz 2699d05e45 Bluetooth: Fix BT_ATT_ENFORCE_FLOW
This moves the processing packets of upper layers from RX thread to the
system workqueue so they have the same priority as the TX callbacks
which has the added benefit of making any protocol on top of L2CAP to
be executed using system wq stack.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-05 16:45:57 +03:00
Vinayak Kariappa Chettimada a2c84ecf9e Bluetooth: Fix building of broadcaster or observer only
Fix conditional compilations to allow building broadcaster
and/or observer only applications.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-04 14:08:59 +02:00
Luiz Augusto von Dentz 362497235d Bluetooth: GATT: Disable flow control if running with POSIX_ARCH
Disable flow control with POSIX_ARCH since these boards tend to run
faster than normal defering the TX callback to system wq may not be
able to run before another packet is received.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-04 09:52:47 +03:00
Luiz Augusto von Dentz 8a7615f4a3 Bluetooth: conn: Defer bt_conn_tx callback to system wq
This makes the transmission complete callbacks to run on system wq
context so they are not executed in TX thread which usually has a much
smaller, and non-configurable, stack size.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-04 09:52:47 +03:00
Luiz Augusto von Dentz 648a53d50f Bluetooth: GATT: Add support to notify by UUID
This reworks bt_gatt_notify_cb to allow passing an UUID, in addition to
that it can now accept multiple notification at once as there could be
multiple instance of the same UUID the user can set multiple set of
parameters.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-04 09:52:47 +03:00
Luiz Augusto von Dentz e6ef539667 Bluetooth: GATT: Make use of bt_gatt_foreach_attr_type on bt_gatt_notify
This make use of bt_gatt_foreach_attr_type to match the CCC UUID which
previously was not possible with bt_gatt_foreach_attr.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-04 09:52:47 +03:00
Luiz Augusto von Dentz a5c07aa7fb Bluetooth: GATT: Add bt_gatt_foreach_attr_type
This adds bt_gatt_foreach_attr_type which can match attribute by UUID
and/or attribute user_data, in addition of that the user can also limit
the number of matches.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-04 09:52:47 +03:00
Erwan Gouriou 3d9416bfed drivers/bluetooth/hci: Implement HCI driver for stm32wb
Implement HCI driver for STM32WB. It allows host to controller.
It is based on ST library allowing communication over RAM shared
bewteen chip's C-M4 and C-M0 cores.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-06-03 09:38:19 -04:00
Arthur Crepin-Leblond 1d36734799 Bluetooth: gatt: Reuse existing handles from a previously added service
When removing a service using bt_gatt_service_unregister, its attributes
handles will keep their value which can cause a problem when adding the
service again to the GATT database.
When re-adding, the gatt_register routine is taking the last handle of
the GATT database to compare it with the handles of the service to be
added.
If a service has handles with a lower value than the last handle of
the database an error will occur.
If we add/remove/add the last service, no error will occur as its
handles are always greater than the last one of the database.

Instead of resetting the handles when unregistering a service and
reassign new ones we make sure that the handles of the services are
not in use in the GATT database in order to place the service back
where it used to be.

Signed-off-by: Arthur Crepin-Leblond <arthur.crepin@proglove.de>
2019-05-30 17:17:30 -04:00
Marek Pieta c8be3e81d3 Bluetooth: host: Fix bt_keys_get_addr()
Change fixes issue causing multiple keys creation for given address
and identity.

Fixes: #16478

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2019-05-30 13:21:16 +02:00
Radoslaw Koppel 974231ee6e subsys/settings: Add const modifier to the value pointer
This commit adds const modifier for value pointer in
settings_save_one function.

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2019-05-29 10:11:12 -04:00
Luiz Augusto von Dentz c904a45d8f Bluetooth: L2CAP: Add callback to notify status
This adds a new callback for L2CAP channels which notities whenever
status has changed so the channel user can can for example resume or
suspend sending depending on the status.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-29 16:31:03 +03:00
Luiz Augusto von Dentz 270e8342f5 Bluetooth: L2CAP: Move Kconfig option to its own it own file
The Bluetooth menu has way too many option so this move the L2CAP
specific option to its own menu.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-29 16:31:03 +03:00
Luiz Augusto von Dentz d8f20fe1e0 Bluetooth: L2CAP: Add sent callback
This adds a new callback to bt_l2cap_chan_ops which is called whenever a
SDU is completely sent.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-29 16:31:03 +03:00
Luiz Augusto von Dentz b65fe62719 Bluetooth: Add possibility to pass a user_data to conn_tx_cb_t
This allows setting a custom pointer to be passed back to the complete
callback at expense of increasing the buffers in 4 bytes.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-29 16:31:03 +03:00
Luiz Augusto von Dentz a3bea8872b Bluetooth: L2CAP: Move fixed channels to its own section in ROM
This changes the declaration of fixed channels to be statically defined
with use of BT_L2CAP_CHANNEL_DEFINE since fixed channels are never
unregistered.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-29 16:31:03 +03:00
Kamil Piszczek e4409d5d7d Bluetooth: smp: adding LE SC OOB support for peripheral side
Added support for the LE SC pairing with the OOB data. The peripheral
side is only supported for now.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-05-27 13:50:46 +02:00
Tedd Ho-Jeong An fccb2e1ffc Bluetooth: GATT: Fix using a wrong handle
This patch fixes to use the right handle value.

Fixes #16341

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
2019-05-23 12:31:35 +03:00
Thomas Ebert Hansen 5e1de1a983 Bluetooth: Add support for vendor-specific events
Add an event handler for HCI vendor-specific events with the
event code BT_HCI_EVT_VENDOR.

A vendor defined callback can be registered to be called when
vendor-Specific events are received in the stack. The callback can then
decode and handle the event; if not the stack will decode and handle
the event.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2019-05-20 13:33:36 +02:00
Luiz Augusto von Dentz 852b1dca55 Bluetooth: GATT: Fix not parsing result of Read by Type
When using the procedure Read By Type the response may contain multiple
instances so it needs to be parsed properly. When dealing with long
values only the beggining will be read, for the remaining bytes the
application should issue another bt_gatt_read with offset so Read Blob
procedure is used as recommended by the spec:

BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part F page 2312:

The Read Blob Request would be used to read the remaining octets of a
long attribute value.

Fixes #16107

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-17 15:29:37 +03:00
Peter Herager 4678447d45 Bluetooth: Add debug kconfig for bluetooth services
Add kconfig to enable debug output for bluetoth services

Signed-off-by: Peter Herager <pehe@oticon.com>
2019-05-08 20:17:07 +03:00
Johan Hedberg e9ed634654 Bluetooth: Mesh: Fix postponing storage deadline indefinitely
If the local node keeps getting bombarded with messages, it's possible
that the storage timer gets rescheduled over and over again and never
expires. Add the necessary code to only reschedule the timer if the
new deadline is earlier than an existing one.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-05-07 19:15:22 +03:00
Johan Hedberg c0a7e4d778 Bluetooth: Mesh: Fix RPL storage timeout handling
The default values for the timeouts, as well as non-defaults in most
Mesh samples, use a higher value for the RPL than then generic mesh
storage timeout. This hasn't had any effect in practice since the code
only uses the RPL timeout if it is *smaller* than the generic one.

The original intention of the code was to use the RPL timeout,
regardless of what the generic one is, whenever the RPL is the only
thing that needs updating. Add some helper macros to track the various
groups of pending flags, and perform the appropriate checks to apply
the RPL timeout whenever it's smaller than the generic timeout, or if
there are no other items to store besides the RPL.

Fixes #15904

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-05-07 19:15:22 +03:00
Mariusz Skamra 909f5a8a67 Bluetooth: gatt: Fix foreach iteration of static attributes
Fix calling bt_gatt_foreach_attr with start handle parameter set
to last static attribute handle.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2019-05-07 08:06:09 +03:00
Johan Hedberg e69b4be2af Bluetooth: Fix return type for settings read callback
settings_read_cb is defined to return ssize_t and not size_t. This
also eliminates several Coverity warnings.

Fixes #15765
Fixes #15768
Fixes #15771
Fixes #15774
Fixes #15778

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-05-02 11:18:30 +03:00
Luiz Augusto von Dentz bd007141fd Bluetooth: GATT: Rename BT_GATT_DB to BT_GATT_DYNAMIC_DB
This should be clearer about the intent of the option.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Luiz Augusto von Dentz 45e1ce8b52 Bluetooth: GATT: Move GATT/ATT option to Kconfig.gatt
This makes the host Kconfig a little less cluttered.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Luiz Augusto von Dentz d7d64032f6 Bluetooth: GATT: Fix typo in commments
COFNIG_BT_GATT_CACHING when it should be CONFIG_BT_GATT_CACHING

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Luiz Augusto von Dentz 2c4e5d5f16 Bluetooth: GATT: Disable dynamic database by default
This makes BT_GATT_DB default to n which reduces the ram required for
many samples.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Luiz Augusto von Dentz b3a6da671f Bluetooth: GATT: Add option to enable/disable database
This adds BT_GATT_DB option which can be used to enable/disable
registering/unregistering services dynamically:

with BT_GATT_DB=y (make ram_report):
      gatt.c                                    206     1.14%
        cf_cfg                                   32     0.18%
        db                                        8     0.04%
        db_hash                                  16     0.09%
        db_hash_work                             32     0.18%
        gatt_sc                                  80     0.44%
        init                                      4     0.02%
        last_static_handle                        2     0.01%
        sc_ccc_cfg                               32     0.18%

with BT_GATT_DB=n (make ram_report):
      gatt.c                                      6     0.03%
        init                                      4     0.02%
        last_static_handle                        2     0.01%

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Luiz Augusto von Dentz e0f3ab6bf2 Bluetooth: GATT: Add support for static services
This reintroduces support for static service in the form of a new API,
BT_GATT_SERVICE_DEFINE, and changes the internal services (GAP/GATT)
to be defined as const as they are never register/unregistered.

Internal service needed to be renamed in order to keep the same order
as before since the section elements are sorted by name.

The result is the following (make ram_report):

before:
      gatt.c                                    572     0.66%
        cf_cfg                                   32     0.04%
        db                                        8     0.01%
        db_hash                                  16     0.02%
        db_hash_work                             32     0.04%
        gap_attrs				180     0.21%
        gap_svc                                  12     0.01%
        gatt_attrs                              160     0.18%
        gatt_sc                                  80     0.09%
        gatt_svc                                 12     0.01%
        sc_ccc_cfg                               32     0.04%
        subscriptions                             8     0.01%

after:
      gatt.c                                    210     0.24%
        cf_cfg                                   32     0.04%
        db                                        8     0.01%
        db_hash                                  16     0.02%
        db_hash_work                             32     0.04%
        gatt_sc                                  80     0.09%
        last_static_handle                        2     0.00%
        sc_ccc_cfg                               32     0.04%
        subscriptions                             8     0.01%

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Luiz Augusto von Dentz 0392ad0dc8 Bluetooth: GATT: Fix usage of uint16_t instead of u16_t
This fixes checkpatch complaning about usage of uint16_t.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Marek Pieta 0654c33229 bluetooth: Fix bt_conn->id handling
Fixed bt_conn->id handling in bt_conn_create_slave_le function.

Fixes: #15698

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2019-04-29 11:34:08 +03:00
François Delawarde 94451b22fc subsys/settings: Allow to register custom backends in settings subsystem
Major changes are:
- Expose settings backend API to enable custom backend support.
- Add a new CONFIG_SETTINGS_CUSTOM backend to allow registering a custom
backend.
- Change api of the handlers h_set() routines to allow for
backend-specific read callbacks.
- Provide a customizable settings_backend_init() routine for custom
backends.
- Move runtime settings support to be its own backend.

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-04-26 11:24:31 +03:00
Kamil Piszczek c5f6e8bed4 bluetooth: host: format specifier alignment
Aligned format specifiers for the Bluetooth Host. Now, the format
specifier matches the variable type.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-04-24 13:05:11 -07:00
Tedd Ho-Jeong An 100f671bca Bluetooth: GATT: Add support for Read Using Characteristic UUID
This patch adds support for Read Using Characteristic UUID which is one
of the procedure to read the characteristic value especially when the
client only knows the characteristic UUID and does not know the handle
of the characteristic.

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
2019-04-24 09:39:53 -07:00
Pawel Dunaj 56a2691e1c bluetooth: host: Unref conn on direct adv start error
Unref conn when direct adv start exits with an error.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-04-18 11:59:12 +02:00
Pawel Dunaj d4dbab9f83 bluetooth: host: Use correct identity when direct advertising
When starting direct advertising use correct identity during
connection lookup.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-04-18 11:59:12 +02:00
Pawel Dunaj 26cfbf81db bluetooth: host: Save id when allocating CCC cfg slot
Make sure that along with address identity is saved too.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-04-18 11:58:27 +02:00
Reham Tarek a1d69fb725 Bluetooth: Mesh: AES-CCM: Fix output MIC with additional data
General MIC fix for AAD lengths up to 14 bytes.
This case doesn't concern the mesh stack because it uses 16 bytes.

Signed-off-by: Reham Tarek <reham.tarek@si-vision.com>
2019-04-17 10:08:03 +03:00
Marek Pieta 321fec4a38 bluetooth: hci_core: Remove misleading log
Changed misleading log of all stack sizes.
Only leaving stacks from hci_core.c file.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2019-04-17 10:06:04 +03:00
Luiz Augusto von Dentz 951822391d Bluetooth: GATT: Store database hash
This stores the database hash and check if it has changed on commit
skipping service changed if hash matches.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-17 10:05:19 +03:00
Luiz Augusto von Dentz f7b4069ac2 Bluetooth: Settings: Fix not allowing custom handlers without arguments
Custom handlers without any arguments don't since there is a check for
argc > 1, to fix this behavior removing the check.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-17 10:05:19 +03:00
Luiz Augusto von Dentz 755a6e503e Bluetooth: GATT: Fix iterating over requested handle range
If handle is over the range end return since handles are always placed
in ascending order.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-17 10:05:19 +03:00
Luiz Augusto von Dentz 4154f27ab5 Bluetooth: GATT: Skip ahead if handle is not within service handles
This reduces bt_gatt_foreach_attr complexity (O(n)) so it can skip
ahead when the start handle is not within its service handles.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-17 10:05:19 +03:00
Johan Hedberg 1a3d9fa0ba Bluetooth: Mesh: Add error checks for scan start/stop
It may be very important information for the developer if scanning
fails to start or stop, so add proper logs. There's no need to log
EALREADY errors, since the mesh stack doesn't track the current scan
state and simply relies on the under lying GAP layer to return this
error if the desired state is already set.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-04-17 09:59:04 +03:00
Marek Pieta 51b45f0df6 bluetooth: conn: Fix bt_gatt_connected call
bt_gatt_connected should be only called, when there is no
connection error. Change fixes problem with receiving notifications
before connection.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2019-04-16 17:43:55 +02:00
Johan Hedberg 42d330406e Bluetooth: Mesh: Fix qualification test MESH/SR/HM/CFS/BV-02-C
The commit 8d0ef1eb85 attempted to fix
test case MESH/SR/HM/CFS/BV-02-C, however inadvertently ended up
introducing a hidden bug. This bug was unearthed thanks to commit
686f5c79cf. We have to keep always track
of the FastPeriodDivisor state whether we're using it (faults > 0) or
not (faults == 0). Introduce a boolean field to the model publication
that's used to indicate whether the FastPeriodDivisor should be
applied or not, instead of zeroing the divisor when there are no
faults (this would cause wrong behavior when faults appear again).

Additionally, the PTS seems to require that we wait until the end of
the existing period before sending the next Health Current Status,
rather than sending it immediately when the fault count changes.

Fixes #15365

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-04-11 21:24:55 +03:00
Carles Cufi bae9f1967b samples: Bluetooth: hci_uart: Implement NOP Command Complete
Implement the Controller counterpart to CONFIG_BT_WAIT_NOP so that it
issues a NOP Command Complete event after booting up, to signal to the
Host that it is ready to receive HCI traffic.

Fixes #15333

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-04-11 14:54:37 +02:00
Luiz Augusto von Dentz f2a34a6106 Bluetooth: GATT: Fix not clearing Client Features
When a device is considered unpaired any configuration set in Client
Features shall also be removed.

Fixes #15329

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-11 12:04:53 +03:00
Johan Hedberg 63955e5f70 Bluetooth: Fix clearing conn->le.keys when unpairing
When calling bt_unpair() the keys were removed from flash, however a
pointer was left to the invalidated keys in case there was an existing
connection. This would then lead to a bogus entry being stored in
flash for a zero-address peer device. Fix this issue by clearing the
conn->le.keys pointer in the bt_unpair() function.

Fixes #15325

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-04-10 14:47:29 +03:00
Johan Hedberg 686f5c79cf Bluetooth: Mesh: Fix not updating health publication message
The bt_mesh_fault_update() API is meant for updating the publication
message and sending it out to the network, however it was missing the
necessary call to health_pub_update() which is responsible for
updating the publication message.

Fixes #15300

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-04-10 10:56:27 +03:00
Johan Hedberg 309b7ff3b4 Bluetooth: Mesh: Update TODO to match current situation
Persistent storage is done. So are the configuration and health
clients. We're also not actively looking to optimize the provisioning
protocol & mesh networking memory usage anymore.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-04-07 09:39:30 -04:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Patrik Flykt 4aa48833d8 subsystems: Rename reserved function names
Rename reserved function names in the subsys/ subdirectory except
for static _mod_pub_set and _mod_unbind functions in bluetooth mesh
cfg_srv.c which clash with the similarly named global functions.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Patrik Flykt 97b3bd11a7 drivers: Rename reserved function names
Rename reserved function names in drivers/ subdirectory. Update
function macros concatenatenating function names with '##'. As
there is a conflict between the existing gpio_sch_manage_callback()
and _gpio_sch_manage_callback() names, leave the latter unmodified.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Luiz Augusto von Dentz 593d8561c9 Bluetooth: PPCP: Fix not being able to disable configurations
The spec allows to set to no specific value with use of 0xffff.

As this still enables entering values in the invalid range, 3200-65535
for min/max interval, this adds the necessary build checks to prevent
values within this range to be used and at same time check if min
interval is not bigger that max interval.

Fixes #15017

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-02 12:13:22 -04:00
Joakim Andersson 710adac50d Bluetooth: host: Add RPA in directed advertisement support
In order to advertise directed to a privacy enabled central the
initiator field of the directed adv packet needs to set to an RPA.
To instruct the controller to use an RPA in the initiator field own
address type should be set to either 0x02 or 0x03.
Since it is not certain that a remote device supports address resolution
of the initiator address we add an option to turn this on and give the
application the responsibility to check if peer supports this.

Fixes #14743

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-04-02 13:19:00 +02:00
Luiz Augusto von Dentz c581163dcf Bluetooth: Fix not accepting string equal to CONFIG_BT_DEVICE_NAME_MAX
In order to accept string of the same size entered in
CONFIG_BT_DEVICE_NAME_MAX an extra byte must be allocated to guarantee
it will always be NULL terminated.

Fixes #15067

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-01 17:51:41 +03:00
Patrik Flykt 21358baa72 all: Update unsigend 'U' suffix due to multiplication
As the multiplication rule is updated, new unsigned suffixes
are added in the code.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Johan Hedberg 49a34244be Bluetooth: Mesh: Remove redundant LOCAL_PUB_KEY flag
There's no need to track this info in prov.c since hci_core.c is
already doing it. Just query hci_core.c always using the
bt_pub_key_get() API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:39:59 +01:00
Johan Hedberg c6fa295e6a Bluetooth: Mesh: Fix disconnecting existing provisioning bearers
If PB-GATT is disabled while there are connected clients, those
clients must be disconnected. Add a 'disconnect` parameter to
bt_mesh_proxy_prov_disable() to handle scenarios when we don't want to
disconnect (e.g. right after successfully finishing provisioning) and
tose where we do want to disconnect (e.g. user requesting to disable
the provisioning bearer).

Also make sure that we always update advertising, so that a stale
advertising set isn't left in the controller.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:39:59 +01:00
Johan Hedberg 7d3b627e19 Bluetooth: Mesh: Fix re-initializing provisioning state upon reset
If both PB-ADV and PB-GATT are supported, we need to properly
re-initialize variables such as link.rx.prev_id and (particularly
importantly) link.rx.buf. If we don't do this it may lead to the
following fault when trying to reprovision again:

***** USAGE FAULT *****
  Illegal use of the EPSR
***** Hardware exception *****
Current thread ID = 0x20001f10
Faulting instruction address = 0x0
Fatal fault in thread 0x20001f10! Aborting.

Fixes #14928

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:39:59 +01:00
Johan Hedberg 87fe134e65 Bluetooth: Mesh: Fix gen_prov struct definition
Remove unnecessary const keywords (the entire struct is const) and use
bool instead of u8_t for the require_link member.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:39:59 +01:00
Johan Hedberg b40235b3e0 Bluetooth: Mesh: Take advantage of settings_delete() when possible
Using settings_delete() makes it much easier to understand what the
code is doing, and actually also reduces the amount of code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:23:46 +01:00
Johan Hedberg 35ebacbe06 Bluetooth: Clean up settings related code
Add error checking, remove redundant code, and improve the logging for
settings related functionality.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:23:46 +01:00
Johan Hedberg f9450f072f Bluetooth: Remove unused ID_SIZE_MAX macro
There are no more user for this macro - just remove it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:23:46 +01:00
Johan Hedberg bcc2d8f0a9 Bluetooth: GATT: Fix attribute read return parameter type
The read() callback of attributes returns ssize_t and not size_t. Fix
this, which also fixes a Coverity warning.

Fixes Coverity CID 197457
Fixes #14958

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:22:22 +01:00
Johan Hedberg 12bf7e6ead Bluetooth: Use bt_addr_le_copy() instead of direct assignment
The convention in the code is to use the appropriate address copying
functions instead of direct assignments. Even when a specific copying
function doesn't exist the convention is to use memcpy.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 09:02:00 -05:00
Vinayak Kariappa Chettimada 3353c9f3c8 Bluetooth: Fix scan failed to start due to RPA timeout
Updating the Resolvable Private Address when advertising and
active scanning in progress fails and clears the RPA_VALID
flag; making the next bt_le_scan_start while continuing to
advertise to fail.

This is fixed by keeping the RPA_VALID flag remain set.
Stopping and starting active scanning to update RPA can be
implemented in a separate commit.

Fixes #9463.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-03-28 14:37:58 +01:00
Erwan Gouriou 7d81a099e6 Bluetooth: Mesh: Increase advertising thread stack size
With BT_HOST_CRYPTO, advertising stack size could be overflowed,
increase size to 1024 when BT_HOST_CRYPTO is enabled.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-03-25 22:51:18 -04:00
Johan Hedberg f811e5446a Bluetooth: Fix missing checks for the BT_DEV_READY flag
Several public APIs were not checking the BT_DEV_READY flag, which
could lead to hard-to-debug behavior, particularly when the stack
lacks an identity address. Add the appropriate checks to these APIs.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-25 10:04:45 +02:00
Johan Hedberg 12a413779d Bluetooth: Fix init procedure handling with BT_SETTINGS
The treatment of the BT_DEV_READY flag was broken when used together
with BT_SETTINGS. The flag would get set even though the stack was
still in a partially initialized state. Even worse, for central role
the stack would potentially try to initiate passive scanning without
having an identity address.

Refactor the code that sets the BT_DEV_READY flag (among other
initialization) into a separate bt_finalize_init() helper function and
call it when the settings have been loaded. Also clarify the warning
message given to the user in case settings_load() needs to be called.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-25 10:04:45 +02:00
Johan Hedberg 3ebd9b4a09 Bluetooth: Mesh: Fix clearing model binding and subscriptions
The code for clearing model bindings and subscriptions was flawed in
that proper "cleared" entries were never stored in settings. The code
must pass 0 and NULL to settings_save_one() in case the entry is
desired to be cleared.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-21 10:10:52 +02:00
Johan Hedberg dac335c238 Bluetooth: Mesh: Fix clearing model subscription list
The code was storing a "cleared" entry in storage for every model,
regardless of them having any subscriptions or not. Update hte
mod_sub_list_clear() function to return a "cleared entries" count so
that the calling code can decide whether any action is needed or not.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-21 10:10:52 +02:00
Johan Hedberg a0d762999d Bluetooth: Mesh: Clean up logging related to settings storage
Remove redundant "val (null)" logs and add a few missing BT_DBG()
calls to make the tracing of storage handling easier.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-21 10:10:52 +02:00
Johan Hedberg 4cac39e14a Bluetooth: Fix missing return statement in le_conn_param_req()
The le_conn_param_req() function was missing a return statement in
case of a failed connection lookup. This could lead to replying to the
connection parameter request twice as well as passing NULL to
bt_conn_unref(). The latter issue also triggered a Coverity warning.

Fixes CID 196638

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-21 10:05:47 +02:00
Mariusz Skamra 3ab275f3e1 Bluetooth: mesh: Fix net_id net_buf_pull in secure_beacon_recv
This fixes usage of net_buf_simple_pull_mem to pull the net_id
from network buffer.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2019-03-19 06:54:26 +02:00
Kumar Gala fdc59d7c2b Bluetooth: Mesh: Fix clang uninitialized var warning
There's a BT_DBG that will output the value of pub_addr before its ever
set to anything.  Remove output of pub_addr from BT_DBG().

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-14 14:31:57 -05:00
Luiz Augusto von Dentz bcf3d8e16b Bluetooth: GATT: Add BT_GATT_DISCOVER_ATTRIBUTE type
This adds BT_GATT_DISCOVER_ATTRIBUTE which can be used to discover any
type of attribute in a given range.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-03-13 17:48:37 +02:00
Luiz Augusto von Dentz af61102ae1 Bluetooth: GATT: Skip Characteristic Value when discovering Descriptors
Those are not considered Descriptors and shall be discovered with
use of BT_GATT_DISCOVER_CHARACTERISTIC.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-03-13 17:48:37 +02:00
Luiz Augusto von Dentz 76deb657d7 Bluetooth: GATT: Skip certain attributes when discovering descriptors
When discovering descriptor Find Information procedure is used which
does not allow any filtering by the server so it will return all
attributes in the given range including services and characteristics.

Fixes #14265

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-03-13 17:48:37 +02:00
Johan Hedberg 0299db7303 Bluetooth: Mesh: Fix checking for bt_mesh_provision() error
There isn't much we can do if this fails, but at least log an error
about it.

Fixes #13855

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-13 05:35:58 -05:00
Thomas Stenersen c1a18fb514 bluetooth: host: Specify controller in BT_HCI_TX_STACK_SIZE defaults
By specifying the controller directly when selecting the default
BT_HCI_TX_STACK_SIZE, an external controller may rely on the final
default value when none of the in-tree controllers are used.

The value is increased to 1024 to accomodate the current worst-case
stack size.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2019-03-12 19:42:40 +01:00
Patrik Flykt 4344e27c26 all: Update reserved function names
Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-11 13:48:42 -04:00
Ulf Magnusson b34b2c5a94 Bluetooth: kconfig: Remove redundant dependencies
subsys/bluetooth/common/Kconfig and subsys/bluetooth/host/Kconfig are
'source'd within 'if BT' and 'if BT_HCI', in subsys/bluetooth/Kconfig,
so there's no need to add those dependencies within them.

'if FOO' is just shorthand for adding 'depends on FOO' to each item
within the 'if'. Dependencies on menus work similarly. There are no
"conditional includes" in Kconfig, so 'if FOO' has no special meaning
around a source. Conditional includes wouldn't be possible, because an
if condition could include (directly or indirectly) forward references
to symbols not defined yet.

Tip: When adding a symbol, check its dependencies in the menuconfig
('ninja menuconfig', then / to jump to the symbol). The menuconfig also
shows how the file with the symbol got included, so if you see
duplicated dependencies, it's easy to hunt down where they come from.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-09 10:03:06 -05:00
Pawel Dunaj 4858a868e6 bluetooth: host: Expand TX thread stack for BT_CENTRAL
Expand TX stack size as more RAM is needed when keys are
stored.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-03-05 11:22:39 +01:00
Nick Ward b17d9eefc5 Bluetooth: GATT: Remove ccc cfg value
CCC cfg value was not being cleared on disconnection of a non bonded
peer if another peer was connected, had non zero value and occurred
earlier in the ccc cfg array.

Signed-off-by: Nick Ward <nick.ward@setec.com.au>
2019-03-01 12:50:43 +01:00
Filip Kubicz 5415f67475 bluetooth: settings: Clean up storing Bluetooth host values
Add missing log_strdup and remove usage of goto where not needed.

Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
2019-03-01 12:49:28 +01:00
Pawel Dunaj aab77ea10f bluetooth: Fix broken directed advertising
This code probably got broken during some merge.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-02-27 11:49:48 +02:00
Luiz Augusto von Dentz 46298da104 Bluetooth: Mesh: Use BT_GATT_CCC_MANAGED
This makes use of BT_GATT_CCC_MANAGED so instead of having a custom
attribute which is not managed by stack.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-27 10:30:50 +01:00
Luiz Augusto von Dentz efb064ab9b Bluetooth; GATT: Consolidate code for finding a CCC config
This consolidates code for finding a CCC config in a helper function
thus reducing the amount of duplicated code.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-27 10:30:50 +01:00
Luiz Augusto von Dentz da163794d0 Bluetooth: GATT: Add BT_GATT_CCC_MANAGED
This adds another helper macro called BT_GATT_CCC_MANAGED which can be
used to set 2 new callbacks:

 - cfg_write: Which application can set if it wants to manage writes to
 CCC configuration.
 - cfg_match: Which application can set if it wants to manage matching
 CCC configuration when notifying/indicating.

BT_GATT_CCC_MANAGED retains the ability of saving peer configuration
on storage making it useful for clients which are only interrested in
managing the CCC configuration but not the storage itself.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-27 10:30:50 +01:00
Ulf Magnusson 9aab5cef96 kconfig: Remove redundant 'default n' properties
Some more were added since the cleanup pass in June 2018. See e.g.
commit 2d50da70a1 ("drivers: ipm: Kconfig: Remove redundant 'default n'
properties") for a motivation. It also avoids people wondering whether
or not they need to put in 'default n'.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 09:25:22 +01:00
Filip Kubicz e44011b6e3 Bluetooth: host: Use log_strdup() for stack strings
Prevent temporary strings from being printed incorrectly if they go out
of scope before being processed by logger.

Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
2019-02-21 09:25:50 -05:00
Filip Kubicz f1a2295088 Bluetooth: settings: Always initialize key when storing Client Features
Fixes #13572.

Initialize key used to store Client Features even when config was not
found.

Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
2019-02-21 09:25:50 -05:00
Johan Hedberg 16311e2285 Bluetooth: settings: Fix missing log_strdup() call
The bt_settings_encode_key() cannot know if the given path pointer is
on the stack or not, so the only safe way to pass it to the logger is
by using a log_strdup() call. Not doing this will likely cause
corrupted strings to show up in the log output.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-02-21 13:25:06 +02:00
Krzysztof Chruscinski 3605e48c44 shell: Modify subcommands to use SHELL_STATIC_SUBCMD_SET_CREATE
It is planned to deprecate SHELL_CREATE_STATIC_SUBCMD_SET macro
which is replaced by SHELL_STATIC_SUBCMD_SET_CREATE.

Additionally, removed irrelevant comments about alphabetical
ordering which is no longer needed.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-20 07:31:35 -05:00
Kamil Piszczek 6bb75a53d1 Bluetooth: gatt: ccc changed cb after connection cb
Changed the order of Bluetooth callbacks. Now the connected callback is
received before CCC changed callbacks.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-02-18 15:13:25 -05:00
Johan Hedberg 1cfa12276c Bluetooth: Mesh: Increase advertising thread size
In certain configurations, such as with MPU support enabled, the
consumption of the advertising thread has gone slightly up. In some
case it was seen to overflow by some 48 bytes. Let it always be 786,
like it was so far with CONFIG_BT_HOST_CRYPTO.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-02-15 18:49:14 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Luiz Augusto von Dentz e919054155 Bluetooth: GATT: Add option to enforce client change-unware state
This adds BT_GATT_ENFORCE_CHANGE_UNAWARE option which when enable
returns -EAGAIN when notifying or indicating if the client is
change-unware to conform with following statement on the spec:

  'BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part G page 2350:
   Except for the Handle Value indication, the  server shall not send
   notifications and indications to such a client until it becomes
   change-aware.'

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Luiz Augusto von Dentz aecf7c7076 Bluetooth: GATT: Store Client features
Client features shall be persisted across connections.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Luiz Augusto von Dentz 3cccf27b2d Bluetooth: GATT: Persist Client Features config only when paired
BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part G page 2405:

  'For clients with a trusted relationship, the characteristic value
  shall be persistent across connections. For clients without a
  trusted relationship the characteristic value shall be set to the
  default value at each connection.'

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Luiz Augusto von Dentz daac1fa77a Bluetooth: GATT: Implement Robust Caching
This implement Robust Caching which is mandatory when Database Hash and
Service changed Characteristics are supported.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Luiz Augusto von Dentz a3bca71a5e Bluetooth: GATT: Implement Database Hash
This implements the Database Hash characteristic which generates a hash
with the contents of certain attributes. The generation of hash is
usually offloaded to the systemwq using a delayed work so that when
application register multiple services only one hash needs to be
calculated.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Luiz Augusto von Dentz ad9846b928 Bluetooth: GATT: Implement Client Supported Features
The Client Supported Features characteristic is used by the client to
inform the server which features are supported by the client.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Luiz Augusto von Dentz 408edcfcdb Bluetooth: Kconfig: Add menu for ATT and GATT options
This move Kconfig options for ATT and GATT to a dedicated menu.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Luiz Augusto von Dentz 753a6d4f20 Bluetooth: Kconfig: Add BT_GATT_CACHING
This adds BT_GATT_CACHING option which can be used to enable support
for Client Supported Features and Database Hash characteristics.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Wolfgang Puffitsch aed74024b5 bluetooth: host: Fix endianness issue for group end_handle.
Convert end_handle to native endianness before comparison.

Signed-off-by: Wolfgang Puffitsch <wopu@oticon.com>
2019-02-07 21:00:42 +02:00
Sebastian Bøe 7644d02598 Bluetooth: Increase hci_tx stack size when CONFIG_NO_OPTIMIZATIONS
When optimizations are disabled more RAM is used and we get a stack
overflow on BT_HCI_TX_STACK_SIZE. To rectify this, increase the stack
size when CONFIG_NO_OPTIMIZATIONS.

This does not scale well, and will have to be replaced by a a more
general solution eventually, but in the mean time it follows the
existing best practice established by the GCOV infrastructure in
commit e908ea9aa5

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-02-07 11:16:59 -06:00
Filip Kubicz 1d199181ac Bluetooth: host: Meaningful error codes on advertising start
Translate HCI error codes to POSIX error codes in order to be able to
distinguish reason of connectable advertising start failure.

Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
2019-02-07 12:56:26 +02:00
Johan Hedberg 1c171ec283 Bluetooth: Add identifiers for Bluetooth 5.1
The Bluetooth 5.1 specification was recently released, and has a new
version identifier (10) assigned to it in the Bluetooth Assigned
Numbers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-29 16:00:57 +02:00
Johan Hedberg fe7f1e17de Bluetooth: Take advantage of net_buf_pull_mem()
Convert the remaining places of the host stack where
net_buf_pull_mem() makes more sense than net_buf_pull().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Johan Hedberg c10b9ac228 Bluetooth: Redesign HCI event handling
Take advantage of the new net_buf_pull_mem() API, and refactor the
events from long switch statements into (const) handler tables. This
helps reduce code size and makes it cheap to add proper checks/asserts
for having sufficient data in the buffers coming from the controller.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Johan Hedberg e399399a99 Bluetooth: Mesh: Take advantage of net_buf_simple_pull_mem()
Use net_buf_simple_pull_mem() instead of net_buf_simple_pull() where
it makes sense.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Johan Hedberg 9abce3ec58 Bluetooth: Mesh: Fix publish timer handling when sending fails
Sending a model publication message could fail e.g. if there are no
buffers available, however this doesn't mean that we should stop doing
periodic publishing indefinitely. When an error occurs, make sure to
call the publish_sent() function so that the periodic publishing timer
gets resubmitted if necessary.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 14:10:58 +02:00
Johan Hedberg e5b8f60bb6 Bluetooth: Mesh: Add support for suspend/resume
In some cases the Friendship & Low Power Node features aren't
available or feasible, however power saving is nevertheless required.
This patch introduces two new APIs to suspend and resume the Mesh
network. Currently, what this impacts is the LE scanning, the
ability to allocate new outgoing buffers, as well as the model
publishing, beacon and heartbeat timers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 14:10:58 +02:00
Johan Hedberg 3e11177a06 Bluetooth: Mesh: Clean up net validity & provisioning state handling
Tracking of the BT_MESH_VALID flag and the PB-GATT state was rather
fragile. Add proper error returns to the various GATT service enable &
disable handlers, and toggle the BT_MESH_VALID flag in a single file
(main.c). Use the newly added error returns to ensure that we don't
re-enable PB-GATT if it wasn't already enabled from before.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 14:10:58 +02:00
Johan Hedberg fbe661fd3b Bluetooth: Mesh: Convert bit-fields into flags
There's already a flags member in the bt_mesh context, so take
advantage of that for any boolean members that have so far been
bit-fields. This should produce more efficient code, also for the
sequence number that's now its own u32_t.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 14:10:58 +02:00
Johan Hedberg f18e978837 Bluetooth: Take advantage of atomic_set_bit_to() API
Use the atomic_set_bit_to() API to simplify code where possible.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-25 17:35:44 -05:00
Johann Fischer 5c23843e65 bluetooth: smp: fix build if BT_SMP_SELFTEST is enabled
Build fails in smp.c:3942 if BT_SMP_SELFTEST is enabled,
sign_test uses smp_sign_buf which only available for BT_SIGNING.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-01-25 13:47:24 +02:00
Luiz Augusto von Dentz a779705f16 Bluetooth: GATT: Add bt_gatt_write_response_cb
This adds bt_gatt_write_response_cb works similarly to
bt_gatt_notify_cb which can take a callback to be called when the PDU
is considered transmitted over the air.

Note: This can also be used to disable the ATT flow control which would
blocks sending multiple commands without wainting their transmissions.

Fixes #11558

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-01-16 21:43:53 -05:00
Johan Hedberg a7a0d27ae2 Bluetooth: Give proper names to Bluetooth threads
Provide names for all Bluetooth threads so that they don't show up as
"NA" when issuing the "kernel stacks" command in the shell.

To get this info the following Kconfig options need to be enabled:

CONFIG_THREAD_STACK_INFO=y
CONFIG_THREAD_MONITOR=y
CONFIG_KERNEL_SHELL=y
CONFIG_INIT_STACKS=y
CONFIG_THREAD_NAME=y

After issuing the "kernel stacks" command the output should look
something like this:

uart:~$ kernel stacks
0x200011D0 BT RX      (real size 1024): unused 760      usage 264 / 1024 (25 %)
0x20001148 BT RX pri  (real size 448):  unused 280      usage 168 / 448 (37 %)
0x20000654 BT ECC     (real size 1100): unused 168      usage 932 / 1100 (84 %)
0x20000764 BT TX      (real size 640):  unused 280      usage 360 / 640 (56 %)
0x20001ED8 sysworkq   (real size 1024): unused 592      usage 432 / 1024 (42 %)
0x200004C4 shell_uart (real size 2048): unused 904      usage 1144 / 2048 (55 %)
0x20000058 logging    (real size 768):  unused 584      usage 184 / 768 (23 %)
0x20001D84 idle       (real size 256):  unused 184      usage 72 / 256 (28 %)
0x20001E08 main       (real size 1024): unused 768      usage 256 / 1024 (25 %)

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-15 17:39:54 +01:00
Johan Hedberg eba16555ce Bluetooth: Increase default TX stack size
The current stack consumption with the H4 driver on qemu_x86 is as
follows with a change from 256 to 512:

	usage 396 / 512 (77 %)

Increase the default for this configuration, as well as other similar
configurations. Set the fallback default to a higher value as well.

Fixes #12429

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-15 10:31:55 +02:00
Johan Hedberg 61ff1bda2f Bluetooth: Mesh: Remove redundant stack variable
The msg->prev_addr is already stored in frnd->clear.frnd, so there's
no need to have an extra stack variable for this (in the form of
prev_addr).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-14 11:38:51 +02:00
Jiahao Li 6a5623566e Bluetooth: Mesh: Fixes existing friend lookup in Friend Request handling
Currently, when handling a Friend Request message with `prev_addr` set,
we look up existing friend entry using `prev_addr` as the address.
However, `prev_addr` is the address of the requesting node's previous
friend, NOT the address of the requesting node itself. Therefore, we
should always look up existing friend entry using `rx->ctx.addr` as the
address.

Signed-off-by: Jiahao Li <reg@ljh.me>
2019-01-12 22:07:41 +02:00
Johan Hedberg d57a9a648b Bluetooth: Mesh: Fix heartbeat publication storing
This fixes usage of an uninitialized variable (to_store) as introduced
by commit bfad2a0.

Fixes #12314

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-07 12:49:36 +02:00
Johan Hedberg 3d0950e59a Bluetooth: Mesh: Fix typo leading to incorrect settings storage
This was intended to be an equality comparison and not an assignment.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-07 12:49:36 +02:00
Luiz Augusto von Dentz 80bc21e03c Bluetooth: GATT: Fix warning when attempting to use read callback
When using bt_gatt_discover with BT_GATT_DISCOVER_CHARACTERISTIC the
read callback would be set to bt_gatt_attr_read_chrc which would attempt
to access the next attribute which in this case would not be set since
the value attribute is no fetched by the discovery, the spec actually
omit the value handle saying it should always be the first attribute to
appear after the characteristic thus we can assume it to be handle + 1.

Fixes #12159

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-01-03 12:12:10 +01:00
Johan Hedberg fc29dd8c8f Bluetooth: Mesh: Fix confusing language in log messages
Both "store" and "clear" are verbs, so putting them after each other
is just confusing. Use "clean" consistently when clearing settings
entries.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-12-11 16:58:36 +02:00
Johan Hedberg ed3c2cd38a Bluetooth: Mesh: Fix missing log_strdup() for logging
Several non-persistent strings were being logged without log_strdup().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-12-11 16:58:36 +02:00
Andrzej Puzdrowski bfad2a0cbf bluetooth: host: mesh: align code to reworked settings
The code need to be align after introduction of stream codec to
setting serialization subsystem.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Andrzej Puzdrowski bfb60743d5 bluetooth: host: align code to reworked settings
The Code need to be align after introduction of stream codec to
setting serialization subsystem.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Jakub Rzeszutko b928b71756 shell: rename shell_help_print function
Function printing help has been renamed to shell_help.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Jakub Rzeszutko 3064ca4f2f shell: creating new module for help functionality
1. Created new shell module: shell_help.
2. Simplified command handlers with new shell print macros.
3. Removed help functions from command handlers.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Jakub Rzeszutko 5451ff2848 shell: remove "options" concept
Removing help "options" from shell API.

Currently SHELL_OPT macro is not used by users. What is more
commit: a89690d10f ignores possible options created in
command handler by the user. As a result they are not printed
in help message.

Second, currntly implemented "options" in command handlers options are
implemented without SHELL_OPT macro.

And last but not least this change will allow to implement
help handler in a way that user will not need to think about calling
functions printing help in a command handler.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Johan Hedberg bec74121f6 Bluetooth: Mesh: Fix matching for all elements of an LPN
When we're acting as a Friend for an LPN, we need to consider all
elements of the LPN. The information of how many elements the LPN has
is provided in the Friend Request message, however until now the code
did not do anything with this information.

Fix the issue by tracking the number of elements for each LPN and
update the unicast address matching code to take this into account.

Fixes #11731

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-11-29 17:55:23 +02:00
Kim Sekkelund bf11698ed9 bluetooth: host: Rename bt_conn_get_id and make it public.
There is not an easy way to relate an application's user_data to a
connection. One way is to save a pointer to bt_conn in the
application's user_data array upon connection establishment.
Each connection related callback function will have to loop for all
user_data and compare the saved pointer to the passed bt_conn
pointer. This is inefficient if there are many callback activations
during the connection.

This change makes the internal bt_conn mapping function accessible to
applications in conn.h. The function name is changed to
bt_conn_index() to clearly indicate that the function returns an
index of an array.
Add an ASSERT to catch illegal parameter.

Signed-off-by: Kim Sekkelund <ksek@oticon.com>
2018-11-28 18:20:38 +02:00
Olivier Martin ff66b4b09a Bluetooth: host: Remove peer from CCC cfg
When removing a peer from a CCC, it also needs to be removed from
the attribute `cfg`.

Not removing it would create a shortage of `cfg` that could
prevent new host to pair to the BLE device.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-11-27 13:58:21 +02:00
Olivier Martin 6c3aefa0b6 Bluetooth: host: Clear CCC when clearing all keys
CCC settings was not removed when unpairing all keys.
It means CCC settings were still present in flash and were
loading at bluetooth initialization time.

Loading these orphan CCC settings would fill `bt_gatt_ccc_cfg`
configurations and would prevent to add new CCC when pairing
with a new device.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-11-26 18:34:41 +02:00
Luiz Augusto von Dentz 6798a421e1 Bluetooth: GATT: Ensure GATT service is registered first
Accourding to Bluetooth specification the Service Changed
Characteristic shall not have its handle changed once it has been
bonded, so this moves the GATT service to be the very first service
registered that way it is guaranteed that it won't change even if
device is flashed with a different configuration which end up changing
the handles after it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-22 17:27:48 +02:00
Mariusz Skamra 474b2b3e94 Bluetooth: Don't mask ECDH related events if CONFIG_BT_ECC disabled
It is related to b904ad387f.
This fixes checking ECDH related events in event mask.
If ECDH support is disabled in host, there is no need to check
if those are supported in the controller.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-22 12:54:57 +02:00
Luiz Augusto von Dentz a618ea2a5a Bluetooth: GATT: Fix not handling duplicated CCC storage
Some backends may actually contain the same key multiple times so the
code needs to check if there is already a ccc_cfg for an address before
attempting to use one that is unallocated.

Fixes #11409

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-21 19:48:16 +02:00
Luiz Augusto von Dentz 046e1ab94a Bluetooth: GATT: Fix not resetting CCC storage
If there are no CCC to be stored the value should be set to NULL so it
is properly cleared otherwise calling settings_str_from_bytes will leave
str uninitialized which may cause a crash when attempting to load the
value.

Fixes #11564

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-21 19:32:16 +02:00
Mariusz Skamra b904ad387f Bluetooth: Add Kconfig option to disable HCI ECDH support
This adds Kconfig option to disable HCI ECDH support.
It will compile out ECDH related code, especially HCI event handlers.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-21 12:26:27 -05:00
Mariusz Skamra 8f5ba0be88 Bluetooth: Add common Kconfig option to disable LE Data Length Update
This adds common option to disable support for LE Data Length Update
procedure in controller and host.
This will reduce flash usage by compiling out le_data_len_change
event handler that will never be called if controller has been
compiled with BT_CTLR_DATA_LENGTH option disabled.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-21 12:26:27 -05:00
Mariusz Skamra be314d3af5 Bluetooth: Add common Kconfig option to disable PHY Update
This adds common option to disable support for PHY Update
procedure in controller and host.
This will reduce flash usage by compiling out le_phy_update_complete
event handler that will never be called if controller has been
compiled with BT_CTLR_PHY option disabled.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-21 12:26:27 -05:00
Olivier Martin 1d9fb2b2b3 Bluetooth: host: Increase ECC thread stack
Logging subsystem could take few extra bytes when enabled.
ECC thread stack has been unconditionally increased to
support it.

During my test, I noticed a usage of 1052 bytes when logging
subsystem is enabled.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-11-21 14:39:36 +02:00
Luiz Augusto von Dentz 57a6858278 Bluetooth: ATT: Rename op parameter of att_write_rsp
This makes it clear that only request need to set an opcode since they
require a error response in case it fails.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-20 13:14:58 +02:00
Luiz Augusto von Dentz 8f812f30a1 Bluetooth: GATT: Fix comment related to write attribute
The comment was suggesting that write callback was reading and storing
buffer when in fact it should write to the attribute value.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-20 13:14:58 +02:00
Luiz Augusto von Dentz ae05089946 Bluetooth: GATT: Add flag to indicate write command
Application may need to handle the write differently depending on the
write operation so this adds a flag called BT_GATT_WRITE_FLAG_CMD which
can then be checked by the callback, for instance one can respond with
BT_ATT_ERR_WRITE_REQ_REJECTED when that flag is not set which should
indicate to the client to use write command instead.

Fixes #11206

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-20 13:14:58 +02:00
Luiz Augusto von Dentz 3fdedde967 Bluetooth: ATT: Assert if request is invalid
Consider invalid if the request pointer is NULL or the callback is NULL
or there is a request ongoing. This conditions would likely lead to a
crash and most likely there is some other bug involved like for example
the application queueing the same request multiple times.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-20 11:15:33 +01:00
Szymon Janc e693997c29 Bluetooth: host: Fix not starting slave conn param update timer
When issuing LE Set Data Length Command host should not assume that
LE Data Length Change Event will be generated. From Core Spec 5.0:
"If the command causes the maximum transmission packet size or maximum
packet transmission time to change, an LE Data Length Change Event
shall be generated."

Change-Id: I17723b58ed4f390aa465db3f69126ee229871123
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-19 13:40:13 +02:00
Szymon Janc bf71fa1aeb Bluetooth: host: Don't send slave conn param request if not needed
If master or application decided to switch connection parameters to
ones that meet pending parameters don't bother sending request
after 5 seconds timeout.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-19 13:22:43 +02:00
Johan Hedberg 296dab3fe2 Bluetooth: Mesh: Increase scan window from 10ms to 30ms
Experiments have shown that the probability of missing advertising
packets is significantly lower with 30ms scan window compared to 10ms
scan window. This is especially the case with advertisers using a 20ms
advertising interval, which in turn is perhaps the most common one
since it's the smallest allowed by the Bluetooth 5.0 specification.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-11-16 09:36:20 +02:00
Filip Kubicz 7c290b053d Bluetooth: settings: store CCC on write
By default, CCC value is only stored to persistent memory during
BT disconnection. This commit adds an optional storing of CCC right
after it has been updated. This results in better robustness of
peripheral but increases system workqueue stack usage.

Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
2018-11-13 16:36:49 +02:00
Krzysztof Chruscinski 97345dbb1b logging: Fix errors in log usage
Couple of findings which were revealed after changing
LOG_MODULE_REGISTER macro:
- missing semicolons after LOG_MODULE_REGISTER()
- missing LOG_LEVEL defines
- other

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-10 12:38:29 -05:00
Kumar Gala 701a574c03 Bluetooth: host: Fix trivial comment mismatch
The endif comment block is for CONFIG_BT_FIXED_PASSKEY not
CONFIG_SMP_FIXED_PASSKEY.  Fix the comment to match.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-09 16:20:19 +02:00
Luiz Augusto von Dentz 7aa58ff91d mesh: Port shell module to the new shell
This makes mesh shell to register commands with the new shell subsystem
and stop using the legacy shell.

Fixes #11056

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-09 11:19:49 +01:00
Szymon Janc 602e08c69a Bluetooth: host: Don't restart scan if connection is pending
With multiple devices on auto-connect list it is possible that while
having pending connection to device A, device B disconnects. In that
case host should not try to start scan (currently controller doesn't
support concurrent scanning and initiating).

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-08 14:21:21 +02:00
Szymon Janc 16fe6c5473 Bluetooth: host: Add comment clarifying L2CAP fallback for CPUP
Makes it easier to understand reason for else branch.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-07 13:01:01 +02:00
Szymon Janc b6979010c6 Bluetooth: host: Fallback to L2CAP for CPUP if rejected by master on LL
Fallback to L2CAP Connection Parameters Update Request if LL Connection
Update Request was rejected by remote device that has this marked as
supported in features. This can happen if procedure is supported only
by remote controller, but not enabled by host. This is connection
parameters update with iOS devices.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-06 16:30:15 -05:00
Mariusz Skamra 50768a6bba Bluetooth: Do not compile GATT response handlers if Client is disabled
This will exclude GATT Client response handlers from compilation
if GATT Client support is disabled.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-06 09:33:19 +02:00
Flavio Ceolin aecd4ecb8d kernel: Change k_poll_signal api
k_poll_signal was being used by both, struct and function. Besides
this being extremely error prone it is also a MISRA-C violation.
Changing the function to contain a verb, since it performs an action
and the struct will be a noun. This pattern must be formalized and
followed and across the project.

MISRA-C rules 5.7 and 5.9

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-04 11:37:24 -05:00
David B. Kinder ee47f7fb7a doc: fix kconfig misspellings
Fix misspellings in Kconfig files that show up in the configuration
documentation (and make menuconfig screens).

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-11-02 17:58:16 -04:00
Joakim Andersson 2487d55403 Bluetooth: host: Fix identation of struct members
Fix identation of struct members so that all are aligned.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-10-29 14:10:26 +02:00
Joakim Andersson c2d62a29f0 Bluetooth: host: Require 128-bit encryption key for security level 4.
In Bluetooth 5 the definition of LE security mode 1, has changed.
LE Security Mode 1 level 4 requires authenticated LE Secure Connections
pairing with encryption using a 128-bit strength encryption key.
This also changes the behaviour when a security request and response
would end up with a security level that is lower than the one requested.
Before pairing would complete, and the link would disconnect with error
authentication failure. Instead a SMP will abort pairing with error code
authentication requirement, or encryption key size.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-10-29 14:10:26 +02:00
Mariusz Skamra 45411bc08d Bluetooth: Update advertising data without advertising restart
This adds new API fuction to update running advertising data.
It will remove the need of advertising restarting.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-10-29 12:30:34 +02:00
Mariusz Skamra 74318e61ca Bluetooth: Change l2cap accept callback return error
This changes EKEYREJECTED to EPERM due to newlib dependencies
errors.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-10-26 16:56:01 +01:00
Szymon Janc b732a9a69b Bluetooth: host: Compile master role conn complete conditionally
Connection complete event with error code can be received only for
central role and can be compiled conditionally.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-10-25 17:03:59 +01:00
Mariusz Skamra e82ebb2c84 Bluetooth: L2CAP: Extend available return codes from accept cb
This adds support for returning various return codes from
the channel accept callback.
This is needed for implementation of incoming connection
authorization for certification purposes.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-10-25 08:02:54 +01:00
Mariusz Skamra 2c6065c2d1 Bluetooth: L2CAP: Rename LE Connection Response Results
Rename connection response results to map those that are defined
for BR.
BR: BT_L2CAP_BR_*
LE: BT_L2CAP_LE_*

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-10-25 08:02:54 +01:00
Johan Hedberg 9f18ff9baf Bluetooth: Convert monitor protocol to a logger backend
Convert the monitor protocol to a proper logger backend. This also
means that our log.h headerfile gets greatly simplified.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Johan Hedberg 251d99132d Bluetooth: Remove custom stack macros
Now that log processing happens in a separate thread, the
BT_STACK_EXTRA macro is not needed (since there's no significant
overhead), and therefore the BT_STACK macros become unnecessary as
well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Johan Hedberg 343c53e841 Bluetooth: Switch from SYS_LOG to logger-based logging
Initial conversion to use syslog instead of logger.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Szymon Janc 30ce313482 Bluetooth: host: Avoid using out-of-scope pointer
Mkae sure that variable pointed by params is valid when passing it
as function argument.

Fixes #10587

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-10-18 21:22:33 +03:00
Sebastian Bøe 2aea475846 Bluetooth: host: Improve error feedback on invalid input
Improve the error feedback when calling bt_le_adv_start and inputting
too much data in the advertisement.

Error feedback before:

Bluetooth initialized
Advertising failed to start (err -22)

Error feedback after:

Bluetooth initialized
[bt] [ERR] set_ad: Advertising data does not fit in buffer
Advertising failed to start (err -22)

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-10-17 13:37:24 +03:00
Joakim Andersson 912cdc0b8e Bluetooth: host: Allow to disable legacy pairing.
Add option to disable legacy pairing and only use secure connection.
If legacy pairing was requested pairing will be denied with status
insufficient authenticated

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-10-16 14:25:56 +03:00
Radoslaw Koppel 4db9731451 bluetooth: host: conn: Add const to addr in bt_le_set_auto_conn
This commit adds missed const modifier for addr pointer for
bt_le_set_auto_conn function

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2018-10-08 20:31:39 -04:00
Szymon Janc 861bae22b8 Bluetooth: Fix autoconnect if cancelled pending connection
bt_conn_disconnect removes device from autoconnect list and thus
should not be called from le_conn_update when timeouting pending
connection. Also auto connect flag needs to be check on connection
failure to make sure scan is restarted.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-10-05 13:43:49 +02:00
Szymon Janc a7bf9de0ee Bluetooth: Use BT_CMD_TEST macro for testing supported commands
Make code easier to read and more consistent.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-28 13:43:39 +03:00
Szymon Janc 9c5c2f8baf Bluetooth: Fix incorrectly reporting connection as failure
Auto connect code reuses bt_conn object and connection code was assuming
object was cleared which resulted in invalid code being provided to
application. Fix that by explicitly setting error code to 0 on
successful connection.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-28 13:43:00 +03:00
Szymon Janc f0f4147a57 Bluetooth: Allow to configure LE Create Connection timeout
Depending on perhiperal advertising interval 3 seconds might not be
enough and would result in cancelling pending connection. Make this
Kconfig configurable and let application to decide.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-28 13:42:26 +03:00
Mark Ruvald Pedersen d67096da05 portability: Avoid void* arithmetics which is a GNU extension
Under GNU C, sizeof(void) = 1. This commit merely makes it explicit u8.

Pointer arithmetics over void types is:
 * A GNU C extension
 * Not supported by Clang
 * Illegal across all ISO C standards

See also: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-09-28 07:57:28 +05:30
Szymon Janc 063123f35a Bluetooth: Allow to configure background scan window and interval
Applications may require different scan windows and interval depending
on expected re-connection time or peer devices advertising parameters.
Default to GAP recommended slow values.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-26 22:45:37 +02:00
Kamil Piszczek 868a3bff0d Bluetooth: host: always set address via HCI before scanning
The address of the device is also set via HCI interface when passive
scanning is used. As a result, LL does not filter out directed
advertising packets that are targeted at this device.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2018-09-25 14:25:17 +03:00
Szymon Janc bb271a6d98 Bluetooth: Add option to configure peripheral connection parameters
This allows to configure desired parameters for peripheral. When set
PPCP characteristic is also added to GAP service. If disabled it is
up to application to controll connection parameters and stack will
only enforce 5 seconds delay before update.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-25 13:31:10 +03:00
Szymon Janc 75405f5613 Bluetooth: Fix connection parameters update
This fixes a few issues with the handling of Connection Parameter
update in the Host:
 - starting conn param update timer as master
 - ignoring 5 seconds slave timer when calling bt_conn_le_param_update
 - starting conn param update timer on every PHY update

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-25 13:31:10 +03:00
Johan Hedberg 559578c09a Bluetooth: Add API to iterate through existing bonds
So far the stack hasn't provided any way for the application to access
the existing bonds. This patch adds such an API.

Fixes #10122

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-24 13:27:26 +03:00
Luiz Augusto von Dentz 16fdd74908 Bluetooth: L2CAP: Make use of net_buf_append_bytes
This uses net_buf_append_bytes to reassemble the SDU segments instead of
doing it manually.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Luiz Augusto von Dentz 62f41df283 Bluetooth: L2CAP: Prevent the channel to stall
If the remote stack is not able to fully utilize each segment it is
possible it would run out of credits before completing the SDU, these
changes detects if that would happen and attempt to restore enough
credits for the SDU to be received.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Luiz Augusto von Dentz 8af4786e9f Bluetooth: L2CAP: Restore credits after receiving an SDU
This simplify the logic of restoring the credits after each SDU instead
of using an arbitrary threshold which was not configurable per channel.

Because the credits are restored only when the full SDU has been
reassembled it means the channels needs to be set up with enough for
the configured MTU otherwise there is a risk of the channel to run out
of RX credits before the packet is fully reassembled, because of such
corner case the code will now warn if a channel is setup with not enough
init_credits.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Luiz Augusto von Dentz 3151d26572 Bluetooth: L2CAP: Add return to recv
This adds a int return to recv callback which can be used to notify the
stack about errors when receiving a packet. In addition to that the user
can return -EINPROGRESS to inform the stack the data will be processed
asynchronously which can be complete by calling
bt_l2cap_chan_recv_complete.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Joakim Andersson 0287a04340 Bluetooth: host: Fix name conflict with kernel smp_init in smp.c
When activating SystemView internal kernel header files will be
included. This causes a name conflict with smp_init in smp.c
and smp_init in kernel_internal.h

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-09-24 10:53:20 +03:00
Kamil Piszczek e48434bc71 Bluetooth: gatt: gatt_discover_next with inclusive handle range
This fix ensures that the handle range used for next GATT discovery is
always inclusive. Previously, the discovery procedure could not be
started with equal value of start and end handle.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2018-09-21 18:52:52 -04:00
Luiz Augusto von Dentz 0a23067540 Bluetooth: GATT: Remove BT_GATT_WRITE_FLAG_PREPARE check in GAP
This check is only required when BT_GATT_WRITE_FLAG_PREPARE is set.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-21 12:27:50 +03:00
Adithya Baglody 9fe378b7e7 Bluetooth: Mesh: Enforce proper compilation.
The current method relies heavily on the linker/compiler to
do the correct operation. Which is to eliminate the code that will
never get called. This posses a problem if the build even changes
by a smallest fraction.
The current patch will enforce proper inclusion of the code at the
pre-processing stage. Thereby not relying on the compiler/linker to
do the right thing.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-20 11:14:03 +03:00
Krzysztof Chruscinski 527256501f shell: Rename shell to legacy_shell
New shell implementation is on the way. For now old one and all
references are kept to be gradually replaced by new shell.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Joakim Andersson 139beac5cf Bluetooth: host: Add set channel map command
Add functionality for setting the host channel classification in
the controller using the HCI command.
This closes issue #9851

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-09-19 15:51:57 +03:00
Szymon Janc 732b45cff3 Bluetooth: Read static address from FICR on nRF5 if no VS enabled
When running combined build on nRF5 with disabled VS command it is
possible to simply read static random address from FICR in host.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-19 13:03:56 +02:00
Szymon Janc f93eef17a5 Bluetooth: Fix security level checking with LE SC and no-bonding
This was affecting SM/MAS/SCPK/BV-01-C qualification test case.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-19 13:34:29 +03:00
Mariusz Skamra 4f74f69814 Bluetooth: Add run-time option to disable SMP bondable mode
This adds a function that will disable Bonding flag in
Authentication Requirements flag in SMP Pairing Request/Response.
This is needed for qualification purposes.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-09-19 10:48:39 +03:00
Mariusz Skamra 7ff9eeea0e Bluetooth: Add Kconfig option to disable bondable mode
This adds Kconfig option to allow disable bondable mode in compile
time.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-09-19 10:48:39 +03:00
Mariusz Skamra 64e608be8b Bluetooth: testing: Exclude Mesh related code if BT_MESH not set
This will exclude testing Mesh related code from build if BT_MESH
option in Kconfig is not set.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-09-19 10:48:39 +03:00
Luiz Augusto von Dentz e2362e1d00 Bluetooth: GATT: Make bt_gatt_discover perform discover all procedure
This makes bt_gatt_discover perform discover all proceduce if no UUID
is given in the parameters.

Fixes #9713

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-19 09:23:08 +03:00
Luiz Augusto von Dentz 0d1724b069 Bluetooth: GATT: Fix long write procedure
Long write procedure currently requires BT_GATT_PERM_PREPARE_WRITE to
be set otherwise the prepares would fail. This changes the behavior so
that BT_GATT_PERM_PREPARE_WRITE enables checking each prepare chunk
skipping it otherwise.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-19 09:22:31 +03:00
Matias Karhumaa 22a27fa0e2 Bluetooth: hci_ecc: Fix byte order of dbg keys
Pass Bluetooth SMP debug keys to crypto API in correct byte order.

Fixes #9867

Signed-off-by: Matias Karhumaa <matias.karhumaa@gmail.com>
2018-09-18 14:23:15 +03:00
Johan Hedberg 366378f8ac Bluetooth: GATT: Fix const'ness of characteristic descriptor data
None of the data for the CEP, CUD and CPF descriptors needs to be
modified by the stack at runtime. Make it possible to pass constant
data to the descriptor macros, and make sure the descriptor handlers
cast the data back to be a constant.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-18 10:19:08 +03:00
Johan Hedberg 3c1dab005f Bluetooth: SMP: Remove bogus ARG_UNUSED() macro
The req variable in smp_pairing_failed() does get used, so
ARG_UNUSED() is inappropriate for it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-17 14:46:10 -04:00
Johan Hedberg b4d7c2906b Bluetooth: Remove bogus condition for setting IRK for an identity
Just like we set the address for an identity without depending on the
BT_DEV_READY flag, we should do the same for the IRK. Otherwise we
risk getting an all-zeroes IRK. Remove the condition and always set
the IRK value whenever CONFIG_BT_PRIVACY is enabled.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-17 19:50:49 +03:00
Johan Hedberg cb08963fac Bluetooth: Fix identity creation through vendor HCI
The code creating identities from the Read_Static_Addresses vendor
command was failing to create matching IRKs, resulting in an
all-zeroes IRK to be used. Fix this by using the existing id_create()
function which takes care of generaing an IRK when necessary.

Fixes #10003

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-17 19:50:49 +03:00
Johan Hedberg a8f4370966 Bluetooth: Move bt_setup_id_addr() to avoid forward declaration
A subsequent patch will make bt_setup_id_addr() depend on id_create()
which was so far lower down in the hci_core.c c-file. Move
bt_setup_id_addr() further down to avoid a forward declaration.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-17 19:50:49 +03:00
Flavio Ceolin abffd83d26 kernel: atomic: Ignore atomic_and/or return when not used
There are some cases where atomic_and/or don't need to be
checked. Actively acknowledge these cases.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Kamil Gawor 8853cb3d06 subsys: bluetooth: Add notification TX complete callback
This changed added notification complete callback which
gives information if a given notification has been sent.

Signed-off-by: Kamil Gawor <Kamil.Gawor@nordicsemi.no>
2018-09-14 14:39:01 +02:00
Kamil Piszczek 9af28ddc09 Bluetooth: host: directed advertising support
Added implementation to the directed advertising API in the Connection
Management module. Introduced a new connection state for this type of
advertising. The new state is symmetric to the connection state used for
scanning.

Added a new advertising option that can be used to trigger low and high
duty directed advertising. Added macros for default values of
Advertising Parameters, which are used to trigger directed advertising.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2018-09-13 14:21:21 +02:00
Mariusz Skamra 02d980add3 bluetooth: gatt: Add GAP Central Address Resolution characteristic
This adds Central Address Resolution characteristic that is required
to check by peer if it's about to send directed advertisements where
initiator address is set to RPA.
Zephyr supports the Address Resolution, so the characteristic value
is hard-coded.
Please check Core 5.0 Vol 3 Part C 12.4 CENTRAL ADDRESS RESOLUTION
Related PTS test case: GAP/CONN/ACEP/BV-03-C

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-09-10 17:47:15 -04:00
Luiz Augusto von Dentz 148c7dd8a3 Bluetooth: GATT: Auto init if bt_gatt_service_register is called
This ensures the core services are always registered first and the
gatt_sc work is initialized.

Fixes #9785

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-10 12:07:08 -04:00
David Leach c2d980798a Bluetooth: Mesh: Fix incorrect reference to BT_SETTINGS
The test for IS_ENABLED(BT_SETTINGS) in mod_reset()
should be IS_ENABLED(CONFIG_BT_SETTINGS).

Signed-off-by: David Leach <david.leach@nxp.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-10 10:46:23 -04:00
Carles Cufi 022f9157e8 Bluetooth: mesh: Fix missing semicolon
Fix a missing semicolon at the end of a statement.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-09-05 10:45:19 -04:00
Johan Hedberg 697919c5ba Bluetooth: Mesh: Fix checking for subnet when recovering App Key
The ordering of items in flash is not guaranteed, so it's possible we
get an App Key before the corresponding Net Key. Remove the check for
a Net Key, since the storing code should never store an App Key if
there is no corresponding Net Key.

Fixes #9670

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-02 21:44:54 -04:00
Johan Hedberg 643c8abea3 Bluetooth: Fix using correct IRK when generating RPA
The code in le_set_private_addr() was hardcoding identity 0, even
though it is given a specific identity as an input parameter.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-30 13:49:59 +03:00
David B. Kinder 1c29bff055 doc: fix kconfig misspellings
Fix misspellings in kconfig files missed during regular reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-08-28 13:58:46 -04:00
Olivier Martin c3118e66ee subsys: bluetooth: host: Ensure PDUs are not allocated in ISR
`bt_conn_create_pdu()` must not be called in ISR has the call
might be blocking.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-08-27 12:52:11 -04:00
Vinayak Kariappa Chettimada 021b12328a Bluetooth: Kconfig the Auto PHY Update Procedure initiation
Added Kconfig option to select Auto-initiation of PHY update
procedure on connection establishment.

Relates to #9608.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-27 12:47:34 -04:00
Luiz Augusto von Dentz 871859a07e Bluetooth: GATT: Make CCC cfg_changed optional
If cfg_changed has not been set consider that the application don't
care and just skip it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-08-21 21:57:00 +03:00
Johan Hedberg bf023d6210 Bluetooth: Mesh: Fix heartbeat subscription state handling
PTS version 7.3.0 incorporates some errata which change the expected
behavior of the heartbeat subscription state. Update the code so that
the following tests pass successfully:

MESH/NODE/CFG/HBS/BV-01
MESH/NODE/CFG/HBS/BV-02
MESH/NODE/CFG/HBS/BV-03
MESH/NODE/CFG/HBS/BV-04

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-16 22:40:02 +03:00
Johan Hedberg c037127754 Bluetooth: Mesh: Initialize PB-GATT advertising data at the right time
Some things, such as UUID, URI or even the local name may be different
when bt_mesh_prov_enable() is called compared to when bt_mesh_init()
was called. Create the advertising data on-demand each time when
enabling PB-GATT.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-16 22:39:36 +03:00
Johan Hedberg bb576f61b6 Bluetooth: Mesh: Move Device UUID log to bt_mesh_prov_enable()
In some cases the application might only initialize its UUID after
calling bt_mesh_init(), e.g. in the case of deriving the UUID from the
identity address. To avoid confusing logs, only print the UUID when
actually enabling one of the provisioing bearers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-16 22:39:36 +03:00
Johan Hedberg e4908119f1 Bluetooth: Mesh: Transport: Fix calculating SeqAuth
This patch fixes case where Mesh is receiving segmented data with
SEQ and SeqZero as in logs below:

bt_mesh_trans_recv: src 0x07FF dst 0x0001 seq 0x00031FFF friend_match 0
bt_mesh_trans_recv: Payload dd7ffc016e5c7f861272e5f7577a6644
trans_seg: ASZMIC 0 AKF 1 AID 0x1D
trans_seg: SeqZero 0x1FFF SegO 0 SegN 1
trans_seg: ######## seq_auth=204799

bt_mesh_trans_recv: src 0x07FF dst 0x0001 seq 0x00032000 friend_match 0
bt_mesh_trans_recv: Payload dd7ffc21abb5a7
trans_seg: ASZMIC 0 AKF 1 AID 0x1D
trans_seg: SeqZero 0x1FFF SegO 1 SegN 1
trans_seg: ######## seq_auth=212991

Original-patch-by: Łukasz Rymanowski <lukasz.rymanowski@codecoup.pl>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-16 17:36:27 +03:00
Johan Hedberg 346f815d9e Bluetooth: Introduce bt_id_delete() API
This API makes it possible to delete an existing identity and to flag
its storage slot as unused.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 47291330b2 Bluetooth: Add safe-guards for creating duplicate identities
Make sure the application doesn't pass existing identity addresses to
bt_id_create() and bt_id_reset(). Also make sure we don't accidentally
create a duplicate when generating random identity addresses.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 7dba2512e3 Bluetooth: Introduce bt_id_reset() API
Add a new API which can be used to reclaim an identity slot for a new
identity. When called, any previous pairings, connections, or other
data will be cleared, and then a new identity will be generated in the
place of the old one.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 3d3888c094 Bluetooth: Remove return parameter from bt_id_add/del
None of the callers of these APIs do anything with the return value,
so just remove it to produce more efficient code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 9336049725 Bluetooth: Remove bogus bt_keys_func_t typedef
This wasn't used anywhere and was typed incorrectly (the foreach
callback takes two parameters). There was also one user of this which
was triggering compiler warnings of mismatched callback type.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg cbb1b84f91 Bluetooth: Pass identity to connection and pairing clearing functions
When doing bt_unpair() we need to pass the given identity when
disconnecting and clearing keys, in case all associated pairings were
requested to be cleared.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg e70c556dcc Bluetooth: Add full storage support for multiple identities
Update the storage handling to take into account multiple identities.
We can save a bit of code by using the new bt_id_create() API from
within settings.c.

Also make the treatment of addr & irk parameters to bt_id_create()
consistent, in that NULL is acceptable for both of them.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 3ed01b48b9 Bluetooth: Remove redundant BT_DEV_ID_STATIC_RANDOM flag
This flag was both redundant and creates confusion with potentially
multiple identity addresses (it was only referring to the first
identity address). We can simply just look at the type of the identity
address wanting to be used.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 1d8dab811e Bluetooth: Add initial APIs for identity manipulation
Add APIs for getting current identities as well as for creating new
ones.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 5708f1e8b1 Bluetooth: Add infrastructure to handle multiple identities
Make it possible to have multiple identity addresses as an LE
peripheral. For central role only the default identity is supported
for now. This also extends the flash storage in a backward compatible
way.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 6b8af4f0b2 Bluetooth: Minor whitespace fixes
Remove redundant whitespace.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Ulf Magnusson ec3eff57e0 Kconfig: Use the first default with a satisfied condition
Up until now, Zephyr has patched Kconfig to use the last 'default' with
a satisfied condition, instead of the first one. I'm not sure why the
patch was added (it predates Kconfiglib), but I suspect it's related to
Kconfig.defconfig files.

There are at least three problems with the patch:

  1. It's inconsistent with how Kconfig works in other projects, which
     might confuse newcomers.

  2. Due to oversights, earlier 'range' properties are still preferred,
     as well as earlier 'default' properties on choices.

     In addition to being inconsistent, this makes it impossible to
     override 'range' properties and choice 'default' properties if the
     base definition of the symbol/choice already has 'range'/'default'
     properties.

     I've seen errors caused by the inconsistency, and I suspect there
     are more.

  3. A fork of Kconfiglib that adds the patch needs to be maintained.

Get rid of the patch and go back to standard Kconfig behavior, as
follows:

  1. Include the Kconfig.defconfig files first instead of last in
     Kconfig.zephyr.

  2. Include boards/Kconfig and arch/<arch>/Kconfig first instead of
     last in arch/Kconfig.

  3. Include arch/<arch>/soc/*/Kconfig first instead of last in
     arch/<arch>/Kconfig.

  4. Swap a few other 'source's to preserve behavior for some scattered
     symbols with multiple definitions.

     Swap 'source's in some no-op cases too, where it might match the
     intent.

  5. Reverse the defaults on symbol definitions that have more than one
     default.

     Skip defaults that are mutually exclusive, e.g. where each default
     has an 'if <some board>' condition. They are already safe.

  6. Remove the prefer-later-defaults patch from Kconfiglib.

Testing was done with a Python script that lists all Kconfig
symbols/choices with multiple defaults, along with a whitelist of fixed
symbols. The script also verifies that there are no "unreachable"
defaults hidden by defaults without conditions

As an additional test, zephyr/.config was generated before and after the
change for several samples and checked to be identical (after sorting).

This commit includes some default-related cleanups as well:

  - Simplify some symbol definitions, e.g. where a default has 'if FOO'
    when the symbol already has 'depends on FOO'.

  - Remove some redundant 'default ""' for string symbols. This is the
    implicit default.

Piggyback fixes for swapped ranges on BT_L2CAP_RX_MTU and
BT_L2CAP_TX_MTU (caused by confusing inconsistency).

Piggyback some fixes for style nits too, e.g. unindented help texts.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-10 12:38:28 -07:00
David B. Kinder 7c89b63b7c doc: fix kconfig misspellings
Fix misspellings in Kconfig files missed during normal reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-08-08 01:48:24 -05:00
Szymon Janc 504584a998 Bluetooth: att: Add option to disable GATT writable name
This allow to set name at runtime while leaving GAP name characteristic
read only.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-08-03 10:41:01 +02:00
Luiz Augusto von Dentz 1329763a14 Bluetooth: Fix storing name in plain text
Settings consider the character space the end of the value, so instead
encode the name using settings_str_from_bytes and restore it with
settings_bytes_from_str.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-08-02 19:16:58 +02:00
Johan Hedberg 6ee8e41915 Bluetooth: Mesh: Clarify confusing log message
Normally App Keys are identified using the AppKey Index value (a 12
bit value in practice), whereas the stack-internal array index has
very little relevance.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-02 01:06:29 +02:00
Johan Hedberg 28d5a65a94 Bluetooth: SMP: Don't try to encrypt with a non-existing LTK
When we receive a security request we need to make sure that any
existing keys contain an LTK to encrypt with. Otherwise there's a risk
of trying to encrypt with an all-zeroes LTK.

Fixes #3221

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-02 01:05:49 +02:00
Johan Hedberg c446c8267b Bluetooth: Add support for fixed passkeys
Add a new bt_passkey_set() API that can be used to set a fixed passkey
to be used for pairing. The new API also requires a new Kconfig option
to be enabled first (CONFIG_BT_FIXED_PASSKEY).

Fixes #8350

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg ef70fc85a9 Bluetooth: SMP: Fix SMP context init when sending security request
The code was not doing the right thing when we as peripheral would
send a security request to the central. First of all, the SEQ_REQ flag
was getting cleared by the pairing request handler, resulting in
pairing_confirm() callbacks for no reason. Secondly, the behavior in
encrypt_change() was not utilizing the smp_reset() helper as it should
have done.

Fix the situation by calling smp_init() when sending a security
request, and detect that this has been done when receiving a pairing
request. Also do the appropriate cleanup if the result is an encrypt
change instead of a pairing request (in case we were already paired
with the peer).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg da8f62de3a Bluetooth: SMP: Remove redundant check for smp pointer
The smp pointer is the return value of CONTAINER_OF() which is
guaranteed to always be non-NULL.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg 4752788c81 Bluetooth: Fix documentation and other issues with auth callbacks
Provide proper documentation for all of the authentication callbacks,
and clarify the usage of the cancel callback. Previously the cancel
callback was always required, even though that doesn't necessarily
make sense now that the pairing_complete/failed callbacks exist.

Fixes #8385

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Ulf Magnusson 642db77591 bluetooth: kconfig: Fix swapped 'range's on BT_RFCOMM_L2CAP_MTU
Whoever added Zephyr's prefer-later-defaults Kconfig patch originally
didn't do the same for 'range's. Earlier ranges are still preferred.
Swap the ranges on BT_RFCOMM_L2CAP_MTU to give the intended behavior.

Fixes the following warning for tests/bluetooth/shell/prj_br.conf:

  warning: default value 200 on BT_RFCOMM_L2CAP_MTU (defined at
  subsys/bluetooth/host/Kconfig:508) clamped to 264 due to being outside
  the active range ([264, 32767])

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-31 08:26:28 -04:00
Johan Hedberg db0e4d5267 Bluetooth: Kconfig: Enable TINYCRYPT_ECC for combined builds
Essentially all products that support pairing or Mesh need to be able
to support ECC. This is particularly important for traditional
peripheral/central use cases where legacy pairing is considered
insecure. With split builds we don't know if the controller supports
ECC HCI commands or not, however with a combined build we know that
the current controller lacks any special ECC support, so enable
TINYCRYPT_ECC by default for such a configuration.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-31 13:55:40 +03:00
Johan Hedberg 4fe8eddd27 Bluetooth: SMP: Don't return STK if it hasn't been generated yet
The SMP_FLAG_ENC_PENDING flag indicates that we've generated an STK
and are waiting for encryption to happen. In case the remote enables
encryption prematurely we should not try to encrypt with whatever is
stored in smp->tk, rather reject the pairing attempt.

Fixes #3222

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-30 13:02:34 +03:00
Johan Hedberg 4d10b04aa1 Bluetooth: SMP: Fix missing NULL-checks for bt_auth
The recently added pairing_complete & pairing_failed callbacks
were missing a NULL-check for bt_auth, since it is possible that
there's no authentication callback structure registered at all.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-30 12:42:45 +03:00
Johan Hedberg e2e0202995 Bluetooth: SMP: Fix minor coding style issues
commit 9b6ad4067b introduced some minor
coding style issues related to line splitting. Fix these.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-27 19:34:34 +03:00
Jun Li 9b6ad4067b bluetooth: add callback to notify pairing is complete
Added two new callbacks for Bluetooth stack to notify
the application that pairing has been completed or failed.

fixes: #8390

Signed-off-by: Jun Li <jun.r.li@intel.com>
2018-07-27 16:16:52 +03:00
Johan Hedberg c384631dac Bluetooth: Mesh: Kconfig: Tweak RX SDU value
Update the RX SDU Kconfig value to something that reflects better
current use cases and doesn't waste memory needlessly. Also lower the
minimum to two segments, since while many samples need three for their
composition data (typically the biggest transferred payload), it's
possible to have a very simple node whose composition fits in two
segments.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-25 18:16:45 +03:00
Johan Hedberg 8c1c1641fe Bluetooth: Mesh: Improve outgoing segment count configuration
The Mesh specification doesn't support more than 32 transport layer
segments, the way the number was so far derived from the advertising
buffer count could result in a highre numbe than 32, thereby wasting
memory. Make the number of supported segments build-time configurable
through a new BT_MESH_TX_SEG_MAX configuration option.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-25 18:16:45 +03:00
Johan Hedberg 99a91c9459 Bluetooth: Kconfig: Lower minimum required ACL buffer count
The controller already has a minimum of 1, and the host should mirror
that (in particular to avoid Kconfig warnings). A single buffer is
unsafe in some scenarios (such as with LE SC enabled) however there
are valid scenarios where a single buffer makes sense, so leave it up
to the developer to choose this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-24 14:14:49 +03:00
Luiz Augusto von Dentz 4052ca6d17 Bluetooth: Use shortened name if complete doesn't fit
If the complete name doesn't fit try shortening the name.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz 18df11646f Bluetooth: Allow use of ScanData with BT_LE_ADV_OPT_USE_NAME
This enables the user to provide a ScanData, as long as it contain
names, and set BT_LE_ADV_OPT_USE_NAME.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz acc3e5129e Bluetooth: Add BT_LE_ADV_OPT_USE_NAME
This introduces a new advertising flag BT_LE_ADV_OPT_USE_NAME which can
be used by applications to make the stack automatically include the
Bluetooth Device Name in the Scan Response.

The name is also updated in case there is already an advertising
instance using it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz aa339ed0f2 Bluetooth: GATT: Make GAP name writable
This makes GAP name writable if CONFIG_BT_DEVICE_NAME_STORAGE is > 0
which means the name can be persisted.

Fixes #8357

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz 2637c978fe Bluetooth: Store device name
This uses bt_dev to store the name and allow changing it at runtime, in
addtion to that if CONFIG_BT_SETTINGS is defined make the name
persistent.

Fixes #8357

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Johan Hedberg be9966f3ae Bluetooth: Mesh: Fix missing semicolon for debug log
Without this it's not possible to build cfg_srv.c with debug logs
enabled.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-20 14:15:49 +03:00
Anas Nashif e29acf0015 Bluetooth: shell: fix type usage
We have been mixing u32_t and uint32_t. Using u32_t when the API expects
something else.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-07-18 12:32:23 -04:00
Kumar Gala f035395ed0 bluetooth: at: Fix warning when building with newlib
If we use newlib the isdigit (and other similar functions) return an
error as char can possibly be viewed as signed:

usr/include/ctype.h:57:54: error: array subscript has type ‘char’ [-Werror=char-subscripts]
 #define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])

Explicity cast to unsigned char so we deal with both this warning and
possible warning when -Wpointer-sign is enabled.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-16 11:06:20 -04:00
Kumar Gala c2862eda4d bluetooth: mesh: shell: Fix warning when building with newlib
If we use newlib the isdigit (and other similar functions) return an
error as char can possibly be viewed as signed:

usr/include/ctype.h:57:54: error: array subscript has type ‘char’ [-Werror=char-subscripts]
 #define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])

Explicity cast to unsigned char so we deal with both this warning and
possible warning when -Wpointer-sign is enabled.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-16 11:06:20 -04:00
Ulf Magnusson 1073882998 subsys: kconfig: Remove 'default n' properties and clean up a bit
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.

Remove some 'default ""' properties on string symbols too.

Also make definitions more consistent by converting some

  config FOO
  	<type>
  	prompt "foo"

definitions to a shorter form:

  config FOO
  	<type> "foo"

This shorthand works for int/hex/string symbols too, not just for bool
symbols.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-12 23:13:22 -04:00
Johan Hedberg 387e91a76b Bluetooth: Mesh: cfg_srv: Ignore Prohibited element addresses
The Configuration Model specification states that all non-unicast
addresses given as the address of an element are Prohibited. The
correct action for Prohibited parameter values is to ignore the
message. As of writing this patch the PTS does not enforce this, but
it might in the future (as it does for many other Prohibited values).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-28 10:48:18 +03:00
Johan Hedberg e69b735a5a Bluetooth: Mesh: Fix checking for model subscription address
Previously the code only checked if any of the models within an
element had the destination address in their subscription list. After
that check the specific model that the message was addressed to was
not verified to have that address in it's subscription list. This
patch fixes the problem.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-28 10:48:18 +03:00
Johan Hedberg 59bbab99a8 Bluetooth: Mesh: Fix cyclic rewriting to flash when restoring state
When we're reading the initial state from flash, calling the various
internal functions was leading to scheduling a rewrite to flash. Add
an extra parameter to the appropriate functions so they know when
they're called due to active configuration by a configuration client,
and when they're called due to restoring the state from flash.

This was not only wasting flash space, but also causing erroneous
behavior with the FCB settings backend if there was an intermediate
node reset operation stored, followed by a reprovisioning. The node
reset entries would cause them to be re-appened after the second valid
provisioning, leading to an incomplete node state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-27 15:54:40 +03:00
Johan Hedberg f23e808ed0 Bluetooth: Mesh: Fix redundant model publication clearing
If the model publication is not enabled, we should return success,
however no other steps need to be done. This also helps avoid writing
redundant entries to flash when resetting a node that never had model
publication enabled.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-27 15:54:40 +03:00
Johan Hedberg 310320c4d1 Bluetooth: Mesh: Fix initialization order during node reset
There were several things broken with the initialization order during
node reset:

 - The model->flags should not be touched since the writing to
   persistent storage happends through delayed work, and the flags
   need to be kept until that.

 - The unprovision() function should only be called at the very end of
   the reset procedure, since it calls model-specific init functions
   which may clear things which the earlier reset routines depend on.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-27 15:54:40 +03:00
Joakim Andersson 5e3c48f43c bluetooth: Make controller crypto functions optional
Provide flexibility in choosing to use the host defined crypto
functions or the ones provided by the controller

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-06-27 12:12:45 +02:00
Mariusz Skamra 698311d220 Bluetooth: att: Add Kconfig option to disable Multiple Read operation
This adds an Kconfig option to disable GATT Multiple Read support.
This GATT sub-procedure is optional and does not have to be supported.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Mariusz Skamra becbfa2243 Bluetooth: att: Do not build Signed Write cmd handler if SMP disabled
This function does nothing actually if SMP is disabled.
This excludes att_signed_write_cmd handler from build if BT_SMP
is disabled or BT_SIGNING is disabled.

Note:
BT_SIGNING depends on BT_SMP

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Mariusz Skamra 76d0dd41f9 Bluetooth: hci_core: Exclude scan related code if non-observer
This chunks should be excluded from build if the target application
does not support neither observer not central role.
This helps to reduce the application image size that implement
Peripheral or Broadcaster role.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Mariusz Skamra 8a50160198 Bluetooth: Mesh: Depend Mesh upon Observer and Broadcaster roles
This adds dependency upon BT_BROADCASTER and BT_OBSERVER roles.
Those are necessary to implement Mesh device.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Mariusz Skamra f3ba6e3806 Bluetooth: hci_core: Exclude conn creation related code for non-central
Don't build the code that is related to central role if the target
does not support connection creation.
This helps to reduce the application image size that implement
either Observer, Peripheral or Broadcaster role.

Note:
BT_CENTRAL implies BT_CONN and BT_OBSERVER

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Johan Hedberg 8818244959 Bluetooth: Add helper for parsing advertising data
It is quite easy to implement a buggy or security vulnerable
advertising data parser. Provide a helper for this purpose, which uses
the existing bt_data struct which is used for programming the local
advertising data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-26 19:34:57 +03:00
Vinayak Kariappa Chettimada b35ed7e79c Bluetooth: Fix central from failing to start encryption
This fixes a regression introduced in commit 6af5d1cd1f
("Bluetooth: Compress bt_keys struct").

Instead of passing a value zero as the random number, the
value at the RAM address zero was being used by the start
encryption function call. It is now fixed by consistently
using byte-array to store EDiv and Rand values.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-22 18:03:43 +02:00
Mariusz Skamra 48b7f236fa Bluetooth: Fix assertion condition in bt_gatt_discover
This fixes invalid assert condition.

As stated in Bluetooth Core v5.0 Vol 3 Part F
3.4.4.1 Read By Type Request &&
3.4.4.9 Read by Group Type Request
"The starting handle shall be less than or equal to the
ending handle."

3.4.3.1 Find Information Request &&
3.4.3.3 Find By Type Value Request
"Only attributes with attribute handles between and
including the Starting Handle parameter and the Ending
Handle parameter that match the requested attribute type
and the attribute value that have sufficient permissions
to allow reading will be returned."

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-15 15:47:04 +02:00
Johan Hedberg b20aff2f80 Bluetooth: Introduce HCI driver quirks
Introduce a quirks field to the HCI driver struct, which can be used
to create exceptions in host behavior for non-standard or unusual
controller behavior. An initial quirk is added to prevent the host
from sending the HCI_Reset command (in which case the controller is
responsible for performing the reset).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-13 21:04:27 +02:00
Johan Hedberg b1b1017178 Bluetooth: Export HCI command APIs through public hci.h header file
This is the simplest & cleanest way to make these APIs available for
drivers. We already have a public hci.h header file, so using it seems
most natural.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-13 21:04:27 +02:00
Johan Hedberg e1b772479b Bluetooth: GATT: Fix notifications
Recent commits which made the choice of attribute to pass to
bt_gatt_notify() more flexible contained some unfortunate bugs in
handling the attributes and their values. In particular, both calls to
gatt_notify() would in certain circumstances pass the wrong handle
value. This should now be fixed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-12 17:54:59 +02:00
Johan Hedberg 7d9896575b Bluetooth: Add HCI User Channel driver for native POSIX port
Introduce a custom HCI driver for the native POSIX port, which opens a
HCI User Channel socket to the Linux kernel to gain access to a local
Bluetooth controller.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-11 17:14:43 -04:00
Luiz Augusto von Dentz 68de9d5d66 Bluetooth: Use Characteristic attribute whenever possible
With updates to bt_gatt_notify and bt_gatt_indicate it is now possible
to pass the Characteristic attribute instead of its value which makes
the code able to verify if attribute properties are set correctly.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-06-11 14:41:19 -04:00
Luiz Augusto von Dentz 679a0b395f Bluetooth: GATT: Allow Characterist to be used with bt_gatt_indicate
Since BT_GATT_CHARACTERISTIC now expands to 2 attributes it may be
confusing to use bt_gatt_indicate as that expects the Value attribute to
be given which is no longer visible, so this enables the user to use
the Characteristic attribute in addition to its value.

Fixes #8231

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-06-11 14:41:19 -04:00
Luiz Augusto von Dentz c3edc82fe7 Bluetooth: GATT: Allow Characterist to be used with bt_gatt_notify
Since BT_GATT_CHARACTERISTIC now expands to 2 attributes it may be
confusing to use bt_gatt_notify as that expects the Value attribute to
be given which is no longer visible, so this enables the user to use
the Characteristic attribute in addition to its value.

Fixes #8231

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-06-11 14:41:19 -04:00
Luiz Augusto von Dentz 1218648ed1 Bluetooth: ATT: Fix clearing context at disconnect
When att_disconnected is called a thread may be waiting for the tx_sem
but that is memset to 0, furthermore there exists a flag
ATT_DISCONNECTED to indicate the context is no longer valid so instead
move memset to bt_att_accept so it is cleared when it is about to be
reused.

Fixes #8083

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-06-06 09:38:37 -04:00
Johan Hedberg ed5fb3ff37 Bluetooth: Mesh: Fix (re)transmit interval handling
The adv_send() function was incorrectly decoding the 5-bit value (it
was using it directly as milliseconds), which effectively lead to the
code always picking the controller's minimum supported interval.

Fix this issue, but do it by simplifying the (re)transmission state
tracking so that the state is always stored in the original "packed"
8-bit value, where 5 bits are reserved for the interval, and 3 for the
count.

Fixes #7972

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-05 19:15:14 +02:00
Johan Hedberg ae829b269d Bluetooth: Fix unchecked settings value lengths
We should check for valid lengths, not just because flash may have
become corrupted, but also because this fixes coverity errors, such as
CID 186030.

Fixes #7739

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-04 17:05:07 -04:00
Johan Hedberg c4b0f1c5b4 Bluetooth: Mesh: Fix build error when LPN is not enabled
Some versions of gcc do not seem to compile out the inaccessible code
in this case and instead give the following error:

subsys/bluetooth/host/mesh/transport.c:419: undefined reference to
`bt_mesh_lpn_poll'

This happens at least when building samples/bluetooth/mesh for
native_posix on Fedora 28.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-25 10:53:46 +03:00
Johan Hedberg 8d1f67c605 Bluetooth: Remove references to non-existing Kconfig symbols
Remove non-existent Kconfig symbol references. An additional (but
related) change is the removal of all persistent storage symbols from
the Arduino 101 Bluetooth shell app, since BT_STORAGE no longer
exists.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-23 16:57:59 -04:00
Johan Hedberg 20a2b7a79d Bluetooth: Mesh: Fix reference to CONFIG_BT_MESH_FRIEND
The Kconfig symbols use BT_* and not BLUETOOTH_*.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-23 16:57:59 -04:00
David B. Kinder 44383a394b doc: fix misspellings in Kconfig files
Found some misspellings missed during normal reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-05-23 16:57:20 -04:00
Joakim Andersson 81b964b619 doc: Update description of BT_RECV_IS_RX_THREAD.
Clarify why this option is needed and which restrictions it has if
disabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-05-22 13:30:45 -04:00
Johan Hedberg df4220b213 Bluetooth: L2CAP: Add support for dynamically allocated PSM values
The Bluetooth core specification splits the valid LE L2CAP PSM range
into two subranges:

 - Standard, SIG-assigned fixed PSM values in the range 0x0001-0x007f
 - Dynamic, allocated at runtime in the range 0x0080-0x00ff

Previously the bt_l2cap_server_register() API was assuming that the
app would always decide the PSM, which effectively made it impossible
to have collision-free dynamic PSMs. This patch extends the
implementation so that if server->psm is 0, then the stack will look
for a free PSM from the dynamic range and take it into use.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-18 12:39:58 +03:00
Johan Hedberg 20ea1b86b9 Bluetooth: Mesh: Remove redundant ivu_unknown variable
Instead of having an ivu_unknown variable to track when we can ignore
the 96-hour minimum duration requirement, simply set the duration to
the minimum (96 hours) in the places where ivu_unknown would have been
1.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-18 12:39:41 +03:00
Johan Hedberg 2b73c97d68 Bluetooth: Mesh: Fix IV Update duration tracking
When the IV Update state enters Normal operation or IV Update in
Progress, we need to keep track of how many hours has passed in the
state, since the specification requires us to remain in the state at
least for 96 hours (Update in Progress has an additional upper limit
of 144 hours).

In order to fulfil the above requirement, even if the node might be
powered off once in a while, we need to store persistently how many
hours the node has been in the state. This doesn't necessarily need to
happen every hour (thanks to the flexible duration range). The exact
cadence will depend a lot on the ways that the node will be used and
what kind of power source it has.

Since there is no single optimal answer, this patch adds a new
configuration option, which allows specifying a divider, i.e. how many
intervals the 96 hour minimum gets split into. After each interval the
duration that the node has been in the current state gets stored to
flash. E.g. the default value of 4 means that the state is saved every
24 hours (96 / 4).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-17 17:30:03 +03:00
Johan Hedberg cfb34d2b80 Bluetooth: Mesh: shell: Add persistent storage support
Add persistent storage support to the mesh shell module and app.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-16 18:41:23 +03:00
Johan Hedberg a3c1b3dbcc Bluetooth: Mesh: Expose bt_mesh_is_provisioned() publicly
After introducing persistent storage, it's useful for an app to check
if the node has been provisioned or not.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-16 18:00:19 +03:00
Ramakrishna Pallala 0fb9ea0304 subsys: bluetooth: Remove deprcated k_call_stacks_analyze API
Replace deprecated k_call_stacks_analyze() API with
k_thread_foreach() API.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-05-15 13:43:00 +03:00
Luiz Augusto von Dentz 1b038f2941 Bluetooth: GATT: Make BT_GATT_CHARACTERISTIC declare its value
This ensures the every characteristic has a value attribute declared
with the same UUID since the old macro did not declare the value the
application would normally have to declare one itself using a different
UUID which is not allowed.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-05-14 18:51:22 +03:00
Johan Hedberg 4f4afce5b0 Bluetooth: Remove unused rx_prio_queue
The rx_prio_queue k_fifo object has not been used for anything for a
really long time. The use for it was originally removed by the following
commit:

commit ad475d863a
Author: Szymon Janc <ext.szymon.janc@tieto.com>
Date:   Fri Apr 22 11:36:04 2016 +0200

    Bluetooth: Remove RX priority fiber

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-12 21:28:09 +03:00
Johan Hedberg 88dfd399f4 Bluetooth: Mesh: Remove sequence number from bt_mesh_provision()
The sequence number was acting as a stop-gap for missing persistent
storage. Now that we have the settings support in place it's no longer
needed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg e240421496 Bluetooth: Mesh: Fix sequence number restoring
The logic for restoring the sequence number was flawed in that it
would not always cause an incremented sequence write upon the
transmission of the first packet. The reason the code didn't work is
that it assumed the stored value was a multiple of SEQ_STORE_RATE,
however since the sequence number is stored in a deferred fashion
that's not always true.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg 53c85cf8bf Bluetooth: Mesh: Fix updating RPL for locally originated messages
We can implicitly trust locally originated messages, so there's no
need to burden the RPL with them.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg 59239032f6 Bluetooth: Mesh: Support for storing common configuration states
Add support for storing the remaining configuration server model
states (all of which are one byte values). The states are stored under
a single settings key bt/mesh/Cfg.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg 44bd56877b Bluetooth: Mesh: Support for storing heartbeat publication persistently
Add support for storing the heartbeat publication persistently. The
information is only stored as "publish indefinitely" or as "periodic
publishing disabled" since we can't know for how long the node is
powered off. The information is stored under the settings key
bt/mesh/HBPub.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg efb68ca2da Bluetooth: Mesh: Support for storing model publication persistently
Add support for storing the model publication information
persistently. The addresses are stored under the settings key
bt/mesh/s/<mod id>/pub for SIG models and bt/mesh/v/<mod id>/pub for
vendor models.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg dde2db5626 Bluetooth: Mesh: Support for storing model subscriptions persistently
Add support for storing the subscribed group addresses for each model
persistently. The addresses are stored under the settings key
bt/mesh/s/<mod id>/sub for SIG models and bt/mesh/v/<mod id>/sub for
vendor models.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg c3d5a0da62 Bluetooth: Mesh: Support for storing model bindings persistently
Add support for storing the bound App Keys for each model
persistently. The bindings are stored under the settings key
bt/mesh/s/<mod id>/bind for SIG models and bt/mesh/v/<mod id>/bind for
vendor models.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg 8703ffad23 Bluetooth: Mesh: Redesign element and storage info for models
Keeping the model struct same sized, change the element pointer to two
indexes, and add a flags member that will be used to track pending
storage actions.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg b7078e1487 Bluetooth: Mesh: Perform storage clearing also through delayed work
In order not to have a Node Reset consume more stack than other
operations, also perform the related storage writes through the same
delayed work as all other storage updates.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg 9e2189c4c1 Bluetooth: Mesh: Introduce generic storage timer
Instead of having an RPL-specific storage timer, introduce a generic
one that'll eventually be used for all persistent storage.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg ace198142e Bluetooth: Mesh: Convert RPL storage timer into a generic one
To reduce stack consumption, and to avoid blocking the CPU during
network activity, prepare for a generic timer that can be used for
most (possibly all) mesh storage values.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Luiz Augusto von Dentz f6a687c0ce Bluetooth: GATT: Add support to persistent CCC config
This makes use of bt_settings to store CCC configs for bonded devices.

Fixes #7073

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-05-11 14:55:42 +03:00
Johan Hedberg c1c5f3d9a3 Bluetooth: Mesh: Expose destination address in bt_mesh_msg_ctx
There are valid use cases where the model layer must know the true
destination address. So far only the fact that it was one of the
addresses that the model subscribes to (its element's unicast
included) has been knowable.

Solve the issue by moving the destination address from the internal
net_rx context to the public bt_mesh_msg_ctx struct.

Fixes #7453

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 13:57:43 +03:00
Johan Hedberg 5b01cb1a46 Bluetooth: Introduce new bt_set_id_addr() API
There are certain use cases where the application needs to be able to
explicitly set a specific identity address. This was previously
possible using the bt_storage API, however now that it's gone another
solution is needed.

This patch adds a ne bt_set_id_addr() API which the application can
use to set a specific identity address before calling bt_enable().

Fixes #7434

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-10 22:39:04 +02:00
Johan Hedberg 31afd18977 Bluetooth: Mesh: Add support for clearing persistent network storage
Add support for clearing all data that's currently supported to be
persistently stored.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg cc3830f8ed Bluetooth: Mesh: Fix resetting configuration model state
Instead of manually iterating all app keys and net keys, use the
bt_mesh_subnet_del() helper on all subnets. This will also clear any
app keys, and ensures that persistent storage is cleared as well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg be7fe55b82 Bluetooth: Mesh: Introduce measures to avoid too frequent flash writes
Both the local sequence number as well as the Replay Protection List
(RPL) are states that may potentially change very often. In order not
to wear out the flash with these updates it makes sense to try to
avoid too frequent writes.

For the local sequence number a simple solution is not to write the
number on every increment. This patch introduces a new Kconfig option
to define after how many increments the sequence number gets written.
When the stack gets initialized it automatically adds the configured
number to the last stored one, thereby guaranteeing that the node
starts off with a number that's larger than the last used one.

The RPL is more problematic, since in principle it needs to be updated
every single time that we receive and process a message. Especially
security sentitive nodes will want this stored immediately to flash.
To give some use-case dependent flexibility, this patch introduces a
new Kconfig option to specify a timeout after which the RPL gets
written to flash.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg 43c7ef3959 Bluetooth: Mesh: Move network startup operations to common function
These are needed both for bt_mesh_provision() as well as persistent
storage-based network creation.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg 3f30d12ce5 Bluetooth: Mesh: Remove redundant 'provisioned' variable
This variable is both redundant as well as problematic when it comes
to adding persistent-storage-based provisioning information, which
will not come through main.c or the bt_mesh_provision() API. Just
remove it and use bt_mesh.valid which serves the same purpose in
practice.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg 1c846651db Bluetooth: Mesh: Add storage APIs for core network values
Add APIs for storing core network values, such as Net and App Keys, IV
Index, Sequence number, RPL, etc.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg 9540f7d52d Bluetooth: Mesh: Add skeleton for persistent storage
Add initial skeleton for doing settings-based persistent storage for
the mesh network state. This patch only includes restoring some core
network state such as IV Index, Sequence number, Net Keys, App Keys
and the Replay Protection list. The remaining state, and actually
storing the state, is left for follow-up patches.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg 2be496a03b Bluetooth: Mesh: Create dedicated helper for incrementing seq
The sequence number is incremented from several different places in
the stack. The way it was done was potentially race condition prone,
and was also problematic from the perspective of updating the
sequence number in persistent storage. Create a dedicated helper for
incrementing the sequence number (solves the race) which can in later
patches be used to add the persistent storage support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg ca10b6bc94 Bluetooth: Mesh: Remove redundant initialization
This for loop runs inside an "if (!sub)" branch, so explicitly setting
sub to NULL in the loop is redundant.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg f7e780a719 Bluetooth: Mesh: Increase visibility of net & app key helpers
These app key and net key (subnet) helpers will soon be needed to be
called from the persistent storage code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg 10fabcd04f Bluetooth: Mesh: Move IV Update defines to net.h
These will soon be needed from other places, e.g. the persistent
storage support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg 6af5d1cd1f Bluetooth: Compress bt_keys struct
There's a bit of unnecessary space in the bt_keys struct. Re-design
some fields for a more compact format, which is particularly helpful
now that the struct gets stored as-is to flash through the settings
API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg f36ea83628 Bluetooth: Add support for persistent pairing keys storage
Integrate the bt_keys submodule with bt_settings. Add a new
bt_keys_store() API to write keys to flash, and extend the existing
bt_keys_clear() to remove the keys from flash.

Along with this, add some helpers for genrating settings key values
containing a bluetooth address, as well as for decoding them to get
the binary bt_addr_le_t.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg 470349c25a Bluetooth: settings: Add support for per-submodule handlers
Add a new linker section for a list of submodule settings handlers,
and iterate the list from the various settings callbacks.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg d22b7c9f2d Bluetooth: Remove bt_storage API
The same functionality is now supported by the settings-based
solution, so remove bt_storage out of the way. There were stubs in
bt_storage to handle per-peer information (e.g. pairing keys) but this
was never actually implemented in full. The next step is to add this
support to the settings-based solution.

Leave the code for generating temporary IRK and identity address in
case BT_SETTINGS is not enabled. Also leave the code for using vendor
HCI to read the identity address, in which case the settings
implementation will not touch it.

Introduce a new bt_unpair() API to replace the removed
bt_storage_clear(), since the latter was actually doing more than just
storage management: it was also handling runtime storage of pairing
information. Later, the bt_unpair() implementation will be extended to
clear settings-based pairing storage.

There is one feature that the bt shell module looses: the ability to
give a specific identity address to the "init" command as a parameter.
We might look later in the future if this is really needed, and add a
separate API for this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg b997a283f7 Bluetooth: Introduce skeleton for settings-based storage
Introduce a basic skeleton for peristent storage based on the settings
subsystem. Also enable support for this to the peripheral sample
application, so the new code gets exersized by CI. For now, the
implementation provides the same level support as the bt_storage API
ever did, i.e. for the identity address and the IRK.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg 8dd37fa79a Bluetooth: Mesh: Fix sequence number in Friend queue
The code was updating net_rx->seq to make sure sdu_recv() gets the
right sequence number (seq_auth for segmented messages), however later
net_rx->seq was also used for enqueuing to the Friend Queue, causing
the queued messages to have the wrong value.

To fix this, don't update net_rx->seq, rather pass an explicit
sequence number value to sdu_recv(), which is just net_rx->seq for
unsegmented messages, and seq_auth for segmented messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-03 10:01:00 +01:00
Johan Hedberg 6a71a69f8d Bluetooth: GATT: Fix CCC handling
The 'valid' member of struct bt_gatt_ccc_cfg was redundant, since
setting 'peer' to BT_ADDR_LE_ANY does the same job. What's worse, the
handling of 'valid' was also buggy in that some places looking for
valid CCC structs only matched the address, meaning it might yield a
positive match for invalid entries.

Fix these issues by removing the 'valid' struct member, and solely
using the 'peer' member to identify valid entries. Also simplify the
code by acknowledging that no CCC entry is essentially the same as the
value '0' written to CCC.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-03 09:53:16 +01:00
Johan Hedberg 6b11106440 Bluetooth: Mesh: Fix enabling Node Identity advertising
The bt_mesh_provision() call results in the provisioning link state
being cleared, so link.conn will become NULL. Add code to store the
information of whether PB-GATT was used and use this information after
the call instead of relying on link.conn anymore at this point.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-02 15:45:16 +01:00
Johan Hedberg aa67a4c55a Bluetooth: Mesh: Remove redundant branch for IV Update
The condition 'iv_index != bt_mesh.iv_index + 1' is already caught by
the earlier conditions in this branch.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-26 12:18:31 +03:00
Johan Hedberg c7c5829ba6 Bluetooth: Mesh: Fix missing IVU normal mode timer when provisioning
If the network is in IV Update In Progress state when we get
provisioned we should set a timer so we eventually transition back to
Normal mode (otherwise we may end up in IVU In Progress indefinitely).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-26 12:18:31 +03:00
Johan Hedberg 2a896cc6c4 Bluetooth: Mesh: Fix IV Update tests when duration is unknown
When we get provisioned we can't know how long the network has been in
the current IV Update state. Introduce a special value for
bt_mesh.last_update to indicate that we don't know the duration.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-26 12:18:31 +03:00