Commit graph

2736 commits

Author SHA1 Message Date
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Jim Luther ffd15131d2 bluetooth: host: fix unpacked l2cap struct
The bt_l2cap_le_conn_rsp struct in l2cap_internal.h has not been
declared __packed. This can cause alignment problems on some
platforms if the struct is placed on an unaligned address.

A __packed declaration solves this issue by forcing the compiler to
use store instructions that do not required alignment.

Signed-off-by: Jim Luther <jilu@oticon.com>
2020-05-29 17:43:32 +02:00
Vinayak Kariappa Chettimada ba487feb0f Bluetooth: controller: split: Workaround nRF52832 CCM overrun
Implemented an intermediate decrypt buffer to cover the CCM
overrun under CRC error conditions. The workaround is
applicable to nRF52832 SoC only, which is missing the
MAXPACKETSIZE register in the NRF_CCM peripheral.

Fixes #21107 for nRF52832 SoC.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-05-29 13:12:28 +02:00
Trond Einar Snekvik a385873336 Bluetooth: Mesh: Fail init on model init error
Adds propagation of error returns from the model init callbacks in
Access, and removing any other checks for successful init in the
foundation models.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-05-27 18:45:18 +02:00
Vinayak Kariappa Chettimada cd7a73c20a Bluetooth: controller: split: Fix NRF_CCM overrun
Fix missing assignment of NRF_CCM->MAXPACKETSIZE register
for PDU sizes smaller than 251 bytes. If there is CRC errors
causing PDU length fields to be higher than configured PDU
buffer sizes in the controller, without the MAXPACKETSIZE
register set to correct PDU size, CCM module could overrun
the PDU buffer and cause memory corruption. This fix is
applicable for all nRF52 Series SoCs except nRF52832 SoC.

Fixes #21107.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-05-27 18:06:17 +02:00
Andries Kruithof 3a91f35893 Bluetooth: controller: split: include proper header file
After removal of legacy controller ll_adv_aux.h does not exist anymore.
This is fixed in this PR by including ull_adv_aux.h instead.
The error only shows up when Advertisement Extensions are enabled
in the LL (CONFIG_BT_CTLR_ADV_EXT=y)

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-05-26 15:28:12 +02:00
chao an 2f15e3901a Bluetooth: Mesh: correct the return type
CC:  mesh/access.c
mesh/access.c: In function 'model_has_dst':
mesh/access.c:483:10:
	warning: returning 'u16_t *' {aka 'short unsigned int *'} from
	a function with return type '_Bool8' {aka 'unsigned char'} makes
	integer from pointer without a cast [-Wint-conversion]
  483 |   return bt_mesh_model_find_group(&mod, dst);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: chao an <anchao@xiaomi.com>
2020-05-26 14:36:40 +02:00
chao an bb5ce8ae30 Bluetooth: Mesh: fix shadow declare
CC:  mesh/adv.c
mesh/adv.c: In function 'bt_mesh_scan_cb':
mesh/adv.c:247:13: warning: declaration of 'adv_type'
                   shadows a global declaration [-Wshadow]
  247 |        u8_t adv_type, struct net_buf_simple *buf)
      |        ~~~~~^~~~~~~~
mesh/adv.c:58:19: note: shadowed declaration is here
   58 | static const u8_t adv_type[] = {
      |                   ^~~~~~~~

CC:  mesh/prov.c
mesh/prov.c: In function 'bt_mesh_prov_enable':
mesh/prov.c:1203:30: warning: declaration of 'prov'
                     shadows a global declaration [-Wshadow]
 1203 |   const struct bt_mesh_prov *prov = bt_mesh_prov_get();
      |                              ^~~~
mesh/prov.c:129:35: note: shadowed declaration is here
  129 | static const struct bt_mesh_prov *prov;
      |                                   ^~~~

Signed-off-by: chao an <anchao@xiaomi.com>
2020-05-26 14:36:40 +02:00
Andries Kruithof 6a2f50aba2 Bluetooth: controller: split: Update feature exchange to BTCore V5.0
The existing feature exchange procedure does not give the proper
response as specified in the BT core spec 5.0.
The old behaviour is that the feature-response returns the logical and
of the features for both peers.
The behaviour implemented here is that the feature-response returns the
featureset of the peer, except for octet 0 which is the logical and of
the supported features.
Tested by using the bt shell, and having different featuresets
on the 2 peers.

This fixes #25483

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-05-26 14:34:39 +02:00
Erwan Gouriou 2716cbcaa6 drivers: susbsys: Check errors on devices selected using dt macro
Some Kconfig defined devices may be defined using dt_chosen_label
function. Since there is no way to ensure a device enabled in dts
is also defined in Kconfig, it may happen that instance is not
actually defined.
In this case device_get_binding might return 0, leading to undefined
behavior in the function that calls it.
When not already done, systematically check return of function
device_get_binding on devices defined through dt_chosen_label macro.
Trigger ASSERT when required and return error when possible.

Fixes #20068

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-05-25 11:43:14 +02:00
François Delawarde 24729bb7c6 bluetooth: host: fix wrong bt/cf settings loading
This commits fixes the loading of bt/cf settings into memory. Only data
was loaded and not the address.

Signed-off-by: François Delawarde <fnde@demant.com>
2020-05-23 22:42:25 +02:00
chao an 32e6347f42 Bluetooth: host: foreach bond only SMP is enabled
build breakage if SMP is disabled

In function `bt_unpair':
bluetooth/host/hci_core.c:2640: undefined reference to `bt_foreach_bond'

Signed-off-by: chao an <anchao@xiaomi.com>
2020-05-20 15:36:10 +02:00
Trond Einar Snekvik 4a2e56d42a Bluetooth: Mesh: Transport tx fields overflow
The transport segmented TX nack and seg_pending fields must be at least
6 bits to avoid overflow for 32 segment messages. This change rearranges
the seg_tx fields to gather all state flag fields in one byte, while
making the counter fields whole bytes.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-05-19 14:44:51 +02:00
Vinayak Kariappa Chettimada 122c43562e Bluetooth: controller: split: Fix slave latency cancel race
Fix missing transmit buffer demutiplexing before checking if
slave latency needs to be maintained or cancelled.

This bug was detected when new transmit buffer was enqueued
overlapping with on-air radio transmission of empty PDU
preceding the handling of radio event done.

Symptoms of this bug being data transmission latency of upto
slave latency plus one times connection interval.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-05-15 17:07:33 +02:00
Trond Einar Snekvik e1c6ea9241 Bluetooth: Mesh: Transport tx seg_o overflow
Increases the transport segmentented tx seg_o counter to 6 bits to avoid
overflow when sending 32 segments. The check in the send loop would
previously never be false, which causes segments to repeat
unnecessarily.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-05-15 17:04:45 +02:00
Trond Einar Snekvik 0aeba0eb12 Bluetooth: Mesh: Transport seg with few adv bufs
Fixes bug where the transport segmented tx would decrement the attempt
counter every time it ran out of buffers. If transport ran out of
buffers 4 times before the sending could complete, the transfer would
end prematurely.

Moves the attempt decrement to only execute when all segments have been
sent.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-05-15 17:04:24 +02:00
Trond Einar Snekvik 266e3f27da Bluetooth: Mesh: Friend with unknown appkey
Ensures that friend messages are enqueued, even if the packet is
received with an appkey is unknown to the friend. Previously, sdu_recv
would return EINVAL if the appkey was unknown, which would prevent the
lower transport layer from adding the packet to the friend queue. This
is irrelevant for the logic in lower transport, and should not be
returned as an error.

Fixes #24014.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-05-15 17:04:07 +02:00
Luiz Augusto von Dentz ef25b864e2 Bluetooth: hci_core: Fix invalid if LE Read PHY
If LE Read PHY fails the code was still trying to parse the buffer as a
valid response.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-15 11:29:41 +03:00
Joakim Andersson a1b8cc2671 Bluetooth: host: Fix extended advertiser address with privacy disabled
Fix extended advertiser not using correct set random address command
to set private (NRPA) address when privacy feature has been disabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-13 21:23:20 +02:00
Joakim Andersson 831ffcd4c2 Bluetooth: host: Fix Service Changed not cleared from flash
Fix Service Changed configuration stored in flash not deleted in flash
when calling bt_gatt_clear from bt_unpair.
When clearing the check for "is bonded" should not be made. If the
bond information is already removed this check will fail.
When clearing the check for "modified" should not be made, clearing
is in itself a modification, and should always be made.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-12 21:00:58 +03:00
Joakim Andersson 6de4294aed Bluetooth: host: Fix CCC cfg not cleared when overwriting oldest bond
Fix CCC cfg not cleared when overwriting oldest bond. Calling
bt_unpair with a pointer to the key will result in the key addr being
memset to zero and bt_gatt_clear is called with an zero-set address.
This happens because unpair (hci_core.c) calls bt_keys_clear before
calling bt_gatt_clear.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-12 21:00:58 +03:00
Peter A. Bigot cca0b79c27 Bluetooth: host: fix warning on unused function
get_phy is referenced by BT_EXT_ADV only when BT_OBSERVER is also
selected.  Avoid defined-but-not-used warnings in that situation.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2020-05-10 11:07:35 +03:00
Carles Cufi b67a31e411 Bluetooth: controller: Remove legacy LL
Remove the legacy Link Layer implementation.

Closes #24187.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-05-08 15:07:00 +02:00
Mieszko Mierunski f93924c689 bluetooth: Add bluetooth support for nRF52820
This commit adds support for bluetooth in nRF52820 SoC.
Bluetooth radio related files created and added to Zephyr.

Signed-off-by: Mieszko Mierunski <mieszko.mierunski@nordicsemi.no>
2020-05-08 15:00:41 +02:00
Joakim Andersson 21a42f3b67 Bluetooth: shell: Add phy handling to the shell
Add phy update callback and command to the shell.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson 322f70243e Bluetooth: shell: Add data length handling in the shell
Add data length callback and command to the shell.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson 0ccee9ba60 Bluetooth: host: Read current PHY when using extended advertising
When using extended advertising the connection can be established on
different PHY. In order to have an updated value of the current PHY
we need to read the PHY of the connection in the connection complete
event.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson 6f0b8c1421 Bluetooth: host: Add application control of PHY change procedure
Add application control of initiating phy change procedure and it's
parameters.
The reasons for allowing the application control over the PHY:
 - Allow changing to Coded PHY.
 - Application may change PHY to react to changes in environment
   to balance throughput and range.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson d9e228a4b0 Bluetooth: host: Add application control of data length procedure
Add application control of initiating data length procedure and it's
parameters.
The reasons for allowing the application control over the data length:
 - Bandwidth control adjusted based on number of active connections.
 - Changing data length before switching to coded phy.
 - Applying workarounds for interoperability problems.
 - Controlling order of ATT MTU and data length procedures.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson 69dfcc6fca Bluetooth: host: Add Kconfig option for auto data length procedure
Add Kconfig option so that the application can disable automatic
initiation of the data length procedure. This is symmetric with the
PHY auto initiation kconfig option.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson f85433c4a9 Bluetooth: host: Refactor setting maximum data length
Refactor setting the maximum data length parameters supported on in
auto data length procedure. This makes setting the data length of the
connection a re-usable function.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Vinayak Kariappa Chettimada aa60a51a66 Bluetooth: controller: Update Bluetooth version to 5.2
Update the Bluetooth HCI Version to 5.2.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-05-07 19:26:13 +03:00
Morten Priess 3ed658e9ed Bluetooth: controller: Added support for vendor ticker nodes
With BT_CTLR_USER_TICKER_ID_RANGE it is possible for vendors to add a
number of ticker nodes for proprietary purposes. The feature depends on
BT_CTLR_USER_EXT.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-05-07 17:34:21 +02:00
Luiz Augusto von Dentz 1c35cc18fe Bluetooth: hci_raw: Split TX into ACL and CMD pools
This might reduce the footprint if the supported sizes are different.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-07 10:31:36 +03:00
Luiz Augusto von Dentz f9d1b7ed63 Bluetooth: hci_raw: Fix number of TX buffers
The numbers should have been the sum of HCI commands count and ACL TX
buffers but instead the buffer size was used which makes the pool holds
substatially more buffer than necessary.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-07 10:31:36 +03:00
Joakim Andersson c6edfa0971 Bluetooth: shell: Add name option control to advertise parameters.
Add control over the use name option to advertise shell parameters as
an optional argument.
The argument count for extended advertise parameters had not been
updated for the maximum directed advertise parameter count.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-06 17:08:49 +03:00
Joakim Andersson 4592cb64ea Bluetooth: host: Add BT_LE_ADV_OPT_USE_NAME for new advertising API
Implement the BT_LE_ADV_OPT_USE_NAME when using bt_le_ext_adv_* APIs
to start the advertiser.
When starting an extended connectable advertiser the name must be
included in the advertising data, since scan response data is
not allowed in this configuration.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-06 17:08:49 +03:00
Joakim Andersson e9002a4fb4 Bluetooth: host: remove duplicate flags set.
Remove setting state flags in bt_le_adv_start_ext since they are set
by le_ext_adv_param_set, except for BT_ADV_PERSIST flag.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-06 17:08:49 +03:00
Joakim Andersson a2a7cc9fe6 Bluetooth: host: Only persist advertising with bt_le_adv_start API
Only persist advertising when the bt_le_adv_start API is used to start
the advertiser. For multiple advertising set a connectable advertiser
can only be started if there is a connection object available for the
advertiser. Leave the decision on which advertising set should be
advertising up to the application instead of suspending advertising
when no connection object is available.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-06 17:08:49 +03:00
Joakim Andersson fdb3da8aff Bluetooth: host: Rename BT_LE_CONN_OPT to BT_CONN_LE_OPT
Rename connection options to be consistent with the rest of the API
names in conn.h

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-04 17:48:22 +03:00
Joakim Andersson 8b70079ebe Bluetooth: host: Remove BT_LE_CONN_OPT_2M option
Remove the BT_LE_CONN_OPT_2M option and update documentation.
This was a misunderstand about the init PHY HCI parameter.
The init PHY in the extended connection create command does not
determine which PHYs are accepted as the initial PHY of the
connection. This is instead determined by the secondary PHY of the
extended advertiser.
The init PHY parameter only specifies which conn parameters are
provided, and since we only provide one conn parameter this option
has no effect.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-04 17:48:22 +03:00
Johan Hedberg e1dddf7bef Bluetooth: Fix NULL pointer dereference when bt_send() fails
The last parameter to hci_cmd_done() is expected to be a valid net_buf
since the function immediately tries to dereference it. Fix this by
passing the appropriate buffer reference to the function.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-05-04 10:59:39 +03:00
Luiz Augusto von Dentz ec5603da8d Bluetooth: L2CAP: Add status flag to track encrypt pending
This adds a new flag to track if the L2CAP channel is pending waiting
for encryption to be changed to resume connecting.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz e0cbdf3b87 Bluetooth: GATT: Add support for new PDUs
This adds support for ATT_MULTIPLE_HANDLE_VALUE_NTF,
ATT_READ_MULTIPLE_VARIABLE_REQ and ATT_READ_MULTIPLE_VARIABLE_RSP.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz f4192bda26 Bluetooth: ATT: Add support EATT bearer
This adds support for EATT bearer which was introduced in 5.2, they work
as extra channels to have GATT traffic, at the moment it is completely
transparent to application when they are in use since the allocation
happens automatically.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz d148f8648b Bluetooth: ATT: Add definitions from 5.2
This adds the definitions for Enhanced ATT along with new PDUs and UUIDs
introduced in 5.2.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz 14d6c00b9b Bluetooth: L2CAP: Add released callback
This adds a callback to indicate when the stack has released all
references to a given channel so the owner free up any resources
associated with that.

This is requires since EATT channels cannot rely on the destroy callback
as it does not use a fixed channel like ATT.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz 0473b436b5 Bluetooth: L2CAP: Process channel with fixed PSM on RX thread
This leaves only channels on the dynamic range to be offloaded to the
system queue so ATT and EATT handling are handling in the same context.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz f7586b0b04 Bluetooth: L2CAP: Add initial implementation of ECRED mode
This adds the initial implementation of ECRED mode which can connect up
to 5 channels simultaneously and is required by EATT.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz 72d4f06bf0 Bluetooth: L2CAP: Use spaces to align defines
This replaces the use of tabs with spaces to align defines.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00