Commit graph

2878 commits

Author SHA1 Message Date
Asbjørn Sæbø 1886cb4b4e Bluetooth: Shell: Add shell command to output the ATT MTU size
It is sometimes useful to know what the ATT MTU size is.

Signed-off-by: Asbjørn Sæbø <asbjorn.sabo@nordicsemi.no>
2020-07-10 13:14:30 +02:00
Marek Pieta 4e43e00c4c Bluetooth: controller: Safe default value of BT_CTLR_LLCP_CONN
Change sets default value of Kconfig option BT_CTLR_LLCP_CONN to
BT_MAX_CONN. The default value should properly handle the worst case.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2020-07-09 19:08:50 +02:00
Vinayak Kariappa Chettimada dc55538645 Bluetooth: controller: Fix missing skip value calculation
Fix missing recalculation of skip value of the ticker being
inserted into ordered list, when it collides and is being
attempted to be inserted at next periodic interval.
This fix is for ticker compatibility mode which is used as
default for nRF51 series.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-09 19:08:35 +02:00
Trond Einar Snekvik cb7835d18f Bluetooth: Mesh: Wait for proxy on node reset
Adds idle wait callback to proxy by counting the number of pending
notifications.

Ensures that all connected nodes have received messages before resetting
the mesh stack.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-07-09 13:49:26 +02:00
Vinayak Kariappa Chettimada eb2a64989b drivers: flash: nrf: Fix flash operation timeout
Fix flash operation timeout due to incorrect use of
secondary ticker to abort any radio in use. Ticker id 0
is reserved for split controller's pipeline preempt timeout.
Using the same ticker id caused the secondary ticker to
not be started if controller is using the same ticker id
for pipeline preempt timeout.

Fixes #26333.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-09 07:17:41 -04:00
Michał Narajowski 67ab8a3173 Bluetooth: Mesh: Fix response to Provisioning PDU with invalid type
Reverse the order of these checks because invalid PDU type will
never be expected. If PDU type is invalid we should respond with
error 0x0002 - Invalid format.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-08 10:19:02 +02:00
Vinayak Kariappa Chettimada 2b45736f28 Bluetooth: controller: Add Periodic Advertising HCI integration
Add implementation to integrate the HCI Periodic Advertising
interface.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-07 15:04:51 +02:00
Joakim Andersson c3308275f6 Bluetooth: GATT: Turn GATT notify multiple feature default off
Turn the GATT notify multiple feature off as default value.
This feature changes the behavior of the bt_gatt_notify API in a way
that might not be backwards-compatible.
This is because the notify multiple header is larger, and therefore
limits the amount of bytes that could otherwise have been sent in a
normal notify PDU for a given ATT MTU.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 16:50:36 +02:00
Joakim Andersson 1d27450954 Bluetooth: host: Fix conn_handle in LE Advertising Set Terminated evt
Fix use of conn_handle in LE Advertising Set Terminated event not
converting from serial Little Endian to native CPU endianness.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 16:49:28 +02:00
Vinayak Kariappa Chettimada 6adfc9bfba Bluetooth: controller: Fix Periodic Adv Data Set parameter list
Fix the parameter list of Periodic Advertising Data Set
interface.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-06 16:49:19 +02:00
Joakim Andersson 4f7505cb10 Bluetooth: host: Unspecified disconnect reason for no pending conn
Use an unspecified reason when disconnecting a connection that did not
have a pending connection in the host.
We don't allocate connection objects in the connection complete anymore
so using memory-capacity-exceeded is misleading.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 14:39:30 +02:00
Joakim Andersson 52f9c0dd46 Bluetooth: host: Fix resume advertiser race condition
This patch fixes an issue with the advertiser not resuming connectable
advertiser if the last bt_conn_unref happens from something other
than the disconnected callback.
In this case this last bt_conn_unref was from gatt.c notify_cb called
from application main thread.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 11:15:39 +02:00
Joakim Andersson 4be66bd33d Bluetooth: Fix host RX thread deadlock
Fix host RX thread being deadlocked. The deadlock occurs because the
RX thread is stuck waiting in conn_tx_alloc with K_FOREVER but if the
connection is disconnected only the RX thread can unblock it in the
handling of the disconnect event.

This commit fixes this deadlock by splitting the processing of the
disconnected event into two parts.
The part needed to unblock the RX is to release resources held by
unack'ed TX packets and mark the connection state as not connected
anymore.
The RX thread waiting for free_tx fifo and the TX thread waiting for
the bt_dev.le.pkts semaphore will both check the connected state after
having acquired them and will abort if disconnected.
The rest of the processing will be handled at normal RX thread
priority like normal.

Move the bt_recv_prio handling to the Bluetooth host when the host
has defined its own RX thread (CONFIG_BT_RECV_IS_RX_THREAD=n).
If the HCI driver has the RX thread (CONFIG_BT_RECV_IS_RX_THREAD=y),
then the responsibility to call bt_recv and bt_recv_prio correctly
falls to the HCI driver.
The helper function bt_hci_evt_is_prio() is replaced with
bt_hci_evt_get_flags() so that the HCI driver can do this correctly.
This decision to replace was made so that existing HCI drivers
maintained out-of-tree will fail at compile time with the new system.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>

Bluetooth: host: Move bt_recv_prio to host when RX thread is defined

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 11:15:39 +02:00
ZhongYao Luo ddf5152bb8 Bluetooth: br/edr: store link key
Save link key to settings_subsys, no need to re-pair after restart.
Overwrite old pairing records with aging counts.

Signed-off-by: ZhongYao Luo <LuoZhongYao@gmail.com>
2020-07-02 16:32:41 +03:00
Andries Kruithof 2bfb128463 Bluetooth: shell: allow multiple parameters for bt hci-cmd
The hci-cmd currently accepts only a 1 byte parameter. This
disables use of commands that requires more than 1 byte,
for ex. the feature exchange that requires a 16 bit parameter.

This commit allows a datafield parameter up to 65 bytes long.
65 bytes comes from the nr. of parameters for the
HCI_LE_Generate_DHKey command

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-07-02 16:32:04 +03:00
Michał Narajowski 91761767dd mesh: Ignore Friend Request from local interface
Friend Request is also transmitted over local queue and
if both Friend and LPN features are enabled then we would
try to establish friendship with ourselves.

Fixes MESH/NODE/FRND/LPN testcases.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski 1e29b2dceb mesh: Replace hardcoded duplicate cache size
The hardcoded value was arbitrary and interfered with message cache
mechanism causing invalid behavior and PTS test to fail.

Fixes MESH/NODE/RLY/BV-02-C.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski cc6d9f1072 mesh: Do not ignore message with DST as RFU group address
According to Mesh Profile Test Specification we should still
relay messages with DST address that is RFU.

Fixes MESH/NODE/RLY/BV-01-C.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski 3e7c64dda9 mesh: Fix net_buf leak in advertising provisioning bearer
Unsegmented buffer in bearer_ctl_send was not unrefed causing
a memory leak.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski 73e1cccdbb mesh: Fix Vendor Model Subscription Get procedure
Invalid argument was passed to bt_mesh_model_tree_walk.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski addbdb0d00 mesh: Fix key refresh procedure
Key refresh procedure was ignored on non-primary subnet.

Mesh Profile Specification v1.0.1:
3.10.4 Key Refresh procedure
"This procedure is used when the security of one or more network
keys and/or one or more of the application keys has been compromised
or could be compromised."

"It is possible to update each NetKey independently of all other
NetKeys. A Key Refresh procedure for one NetKey can be in a different
phase to another Key Refresh procedure for other NetKeys."

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski 9a0602417a mesh: Add reset link functionality to provisioning bearers
Reset provisioning bearers when bt_mesh_reset() is called. Accept
another provisioning attempt after link close.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski 5e543a2366 mesh: Add a define representing max transaction id
This value was used quite often in the file so adding a
descriptive name should improve readability.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski ebabba3684 mesh: Start protocol timer on send message in advertising bearer
Protocol timer was not started when sending a control message
in advertising bearer.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski df426abe53 mesh: Fix resending provisioning link ack
The comparison of a current tx link transaction id caused
us to not send ack and in effect fail provisioning.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Joakim Andersson 16763ff9b6 Bluetooth: host: Fix adv object not released on directed adv timeout
Fix the advertise object not release when a high-duty cycle directed
advertiser timeout happens. If the extended advertising feature has been
enabled in the host, but not supported by the controller then the
advertising object must be released in the connection complete event
since there will not be a advertising set terminated event.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-06-25 19:34:16 +02:00
Joakim Andersson 0b1af81daa Bluetooth: controller: Fix non-privacy directed advertiser
Fix issue with directed advertiser not accepting connection request
from non-privacy enabled peer that has given us a non-zero IRK.
When device privacy is enabled then ull_filter_lll_rl_addr_allowed will
return true, and update the rl_idx to entry in the resolving list.
When the directed advertiser is not privacy enabled then lll->rl_idx is
set to FILTER_IDX_NONE and will not use RPA for the target address.
The check rl_idx != lll->rl_idx will then fail (0 != 0xff) and the
connect request is denied, even though all addresses matches on-air.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-06-25 12:11:02 +02:00
Trond Einar Snekvik 5ea787c794 Bluetooth: Mesh: Keep PB-GATT callback through disconnect
Removes the memset of the prov_bearer_cb in PB-GATT during resets. This
allows the provisioning link to disconnect and reconnect again without
having to call pb_gatt_open.

Fixes #26343.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-06-23 19:22:58 +02:00
Vinayak Kariappa Chettimada 1af8c136a7 Bluetooth: controller: Add explicit opcode check in unknown rsp PDU
Add explicit opcode check when handling received unknown
response PDU.

Without this, for example, an in progress Data Length Update
procedure state was reset when receiving an unknown response
to slave initiated feature request.

Fixes #26252.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-22 12:33:22 +02:00
Joakim Andersson 0f67f6cb72 Bluetooth: shell: Add phy procedure options to the shell
Add command line options to set the PHY options coding schemed and
no preference.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-06-19 13:42:29 +02:00
Joakim Andersson 1d0b03bb37 Bluetooth: host: Add phy update procedure options
Add options for phy update procedure. User can now set no preference
option for a particular PHY as well as preference for LE Coded PHY
coding scheme.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-06-19 13:42:29 +02:00
Luiz Augusto von Dentz 0742a45ac9 Bluetooth: shell: Add support for printing the write rate
This makes the gatt metrics also available for
gatt write-without-rsp-cb so it now prints the rate of each write:

uart:~$ gatt write-without-response-cb 1e ff 10 10
Write #1: 16 bytes (0 bps)
Write #2: 32 bytes (3445948416 bps)
Write #3: 48 bytes (2596929536 bps)
Write #4: 64 bytes (6400 bps)
Write #5: 80 bytes (8533 bps)
Write #6: 96 bytes (10666 bps)
Write #7: 112 bytes (8533 bps)
Write #8: 128 bytes (9955 bps)
Write #9: 144 bytes (11377 bps)
Write #10: 160 bytes (7680 bps)
Write #11: 176 bytes (8533 bps)
Write #12: 192 bytes (9386 bps)
Write Complete (err 0)
Write #13: 208 bytes (8533 bps)
Write #14: 224 bytes (9244 bps)
Write #15: 240 bytes (9955 bps)
Write #16: 256 bytes (8000 bps)

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Luiz Augusto von Dentz 0028559860 Bluetooth: ATT: Fix using of k_fifo_{put,get}
These functions don't work with buffers that do have fragments, instead
this replaces their usage with net_buf_{put,get}.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Luiz Augusto von Dentz 5aac983419 Bluetooth: ATT: Fix low throughput
ATT_PENDING_SENT does severely impact the throughput since multiple
packets no longer can be scheduled at same time, so instead of always
setting it regardless of the bearer/channel it is now only used for
EATT since that cannot set its own callbacks.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Luiz Augusto von Dentz 3ae926c0f1 Bluetooth: ATT: Fix not returning error
bt_l2cap_send_cb may fail if there are no context available which means
that the request would not be sent, also due to the use of custom
callback it cannot be queued either so the only option is to return the
error and let the application handle it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Luiz Augusto von Dentz bc7ce86ac5 Bluetooth: ATT: Fix not processing pending requests
Since the TX semaphore is used for all types of PDUs a request may have
to be put on the request list while there is no pending request pending
which means no response will be generated to trigger att_process,
previously this condition was handled by setting the request as
currently pending and append its buffer to tx_queue but this is no
longer efficient since there could be more than one channel active the
code should try all of them before queueing back to request list.

To fix this the request list will now be processed each time a PDU has
been sent.

Fixes #26070

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Luiz Augusto von Dentz 4418ba76a5 Bluetooth: ATT: Fix overwritting sent callback
ATT channel sent callback shall not be overwritting until the
operation completes as it can result in breaking flow control when
CONFIG_BT_ATT_ENFORCE_FLOW is enabled.

Fixes #25964
Fixes #26071

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
chao an 95e4eb8867 Bluetooth: Mesh: fix different signedness
CC:  subsys/bluetooth/mesh/prov.c
subsys/bluetooth/mesh/prov.c: In function 'bt_mesh_input_string':
subsys/bluetooth/mesh/prov.c:616:14:
        warning: pointer targets in passing argument 1 of
        'strncpy' differ in signedness [-Wpointer-sign]
  616 |  strncpy(link.auth, str, prov->input_size);
      |          ~~~~^~~~~
      |              |
      |              uint8_t * {aka unsigned char *}

Signed-off-by: chao an <anchao@xiaomi.com>
2020-06-18 13:17:24 +02:00
Joakim Andersson e4af41acc2 Bluetooth: kconfig: Disable advertising extension until feature complete
Disable the controller advertising extension feature default setting
until the feature is complete. The zephyr host requires the
LE Advertising Set Terminated event to function.
Without this event a peripheral connection cannot pair because the
local on-air address is not set, and the advertising state will not be
cleaned up, so advertising cannot be started again.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-06-17 17:09:59 +02:00
Trond Einar Snekvik ca901c2149 Bluetooth: Mesh: Null check buf before unref
The frnd->last buffer can potentially be NULL if friend_clear is called
after the adv.c buf->busy check, but before the adv_start callback.
The current design is based on the adv.c thread being cooperative, and
therefore not yielding between the busy check and the adv_start
callback, but as the bt_le_adv_start call has to acquire a semaphore,
there's a possibility for friend_clear being called inbetween.

Fixes #26177.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-06-17 17:09:36 +02:00
Carles Cufi 88f25df9ac Bluetooth: smp: Warn on enabling several Bluetooth options
Add warning about enabling the options below so that users are
aware that this is a security risk.

- CONFIG_BT_DEBUG_SMP
- CONFIG_BT_DEBUG_KEYS
- CONFIG_BT_OOB_DATA_FIXED
- CONFIG_BT_USE_DEBUG_KEYS
- CONFIG_BT_STORE_DEBUG_KEYS

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-06-17 17:14:33 +03:00
Joakim Andersson f756b79124 Bluetooth: controller: Use NRF RNG entropy device
Use the NRF RNG entropy device as the entropy device for bt_rand and
controller internal functions when LLL is Nordic.
Using an entropy source with a significant increase in stack usage
will invalidate all stack size configurations in the system and lead
to stack overflow issues.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-06-16 19:09:55 +02:00
Vinayak Kariappa Chettimada 69ef82f22f Bluetooth: controller: Fix missing RADIO_TXP_DEFAULT define
Fix compile error due to missing include file that defined
RADIO_TXP_DEFAULT.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-16 17:48:59 +02:00
Vinayak Kariappa Chettimada a20ecb6722 Bluetooth: controller: Fix compilation regression
Fix compilation regression due to addition of const
qualifier to tx_pwr_lvl parameter of ll_tx_pwr_lvl_set
function. Support for BT_CTLR_TX_PWR_DYNAMIC_CONTROL
needs the tx_pwr_lvl to be updated and returned.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-16 17:48:59 +02:00
Carles Cufi 8617e93b84 Bluetooth: controller: Work around compiler silliness
For some reason GCC 9.x doesn't seem to be able to realize that set_num
will always be > 0 and so the local variable status will always be
initialized. Use a do {} while instead to keep it happy.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-06-12 22:58:05 +02:00
Vinayak Kariappa Chettimada d048570ec5 Bluetooth: controller: Re-arrange Kconfig options
Re-arrange and have conditional prompt for BT_CTLR_ADV_EXT.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada 3d78a16d81 Bluetooth: controller: split: Fix initialization of new aux header
Fix missing implementation of initialization of common
advertising header bit fields when new auxiliary channel PDU
is instantiated. This caused corrupt invalid Bluetooth
Device address being copied from uninitialised previous
auxiliary PDU instead of copying from primary channel PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada 205fe1825e Bluetooth: controller: split: Refactor auto variable names
Review rework updates, refactor auto variable names.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada 130d63a1c2 Bluetooth: controller: split: Review rework use defines
Review rework updates, use defines in place of magic values.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada 5d13bf4e98 Bluetooth: controller: split: Fix endianness in filling DID
Handle endianness when filling the DID value in advertising
PDU extended header.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00