Commit graph

9523 commits

Author SHA1 Message Date
Joakim Andersson
2cb4548a42 Bluetooth: host: Fix not setting NRPA before starting scanner
Fix not setting NRPA before starting scanner.
Occurs with BT_PRIVACY=n and BT_EXT_ADV=y

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-19 10:19:03 +02:00
Thomas Stenersen
b7336616b2 Bluetooh: Host: Fix wrong buffer in acl_total_len calc
To be squashed.

Co-authored-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2020-09-18 20:24:46 +03:00
Thomas Stenersen
3d57cdb7c3 Bluetooth: host: Use C89-style
To be squashed after review.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2020-09-18 20:24:46 +03:00
Thomas Stenersen
e28fdbb9df Bluetooth: host: Fetch L2CAP length directly
This commit will be squashed after review.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2020-09-18 20:24:46 +03:00
Thomas Stenersen
8bc00f5ead Bluetooth: host: Refactor bt_conn_recv
Re-structures the `bt_conn_recv()` to support more generic appending of
new ACL data. This also handles the possibility of receiving 0-length
ACL_START and ACL_CONT fragments, whilst maintaining existing
error-checking functionality.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2020-09-18 20:24:46 +03:00
Thomas Stenersen
a8f47a1110 Bluetooth: host: Support fragmented L2CAP header
Fixes issue #26900.

A controller may fragment an L2CAP SDUs in any way it sees fit,
including fragmenting the L2CAP header. Likewise, the receiving
controller may send the fragmented header as ACL data to the host.

The Zephyr host assumed that a `BT_ACL_START` was at least 2 bytes long,
and consequently read the two-byte length field from the buffer without
length checks.

This commit allows the `BT_ACL_START` to be less than two bytes,
updating the `conn->rx_len` onces the `BT_ACL_CONT` with the remaining
part of the length field has been received.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2020-09-18 20:24:46 +03:00
Joakim Andersson
cccfea24c1 Bluetooth: controller: Fix Kconfig dependencies for PHY options
Fix Kconfig dependencies for enabling the controller PHY options
for LE 2M Phy  and LE Coded Phy. These options should be selectable
without connections enabled when extended advertising has been enabled.

The issue affects out-of-tree controllers that wish to use the
BT_CTLR_PHY_CODED and BT_CTLR_PHY_2M options.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-18 18:11:35 +02:00
Joakim Andersson
4cc6098af8 Bluetooth: controller: Select controller features from SoC capabilities
Select the controller feature support for data length and LE 2M PHY
based on the SoC hardware capabilities instead of relying on SoC
family.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-18 18:11:35 +02:00
Luiz Augusto von Dentz
6f20e072f1 Bluetooth: ISO: Fix unbalanced reference count
When disconnecting chan->conn is set to NULL without unrefing.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-18 15:24:17 +02:00
Luiz Augusto von Dentz
a76c804d07 Bluetooth: ISO: Fix crash when bt_iso_chan_bind fails
When attempting to bind a channel if it fails the code will attempt to
cleanup calling bt_iso_cleanup which expects connections of
BT_CONN_TYPE_ISO.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-18 15:24:17 +02:00
Luiz Augusto von Dentz
a177dfdd93 Bluetooth: ISO: Fix missing break after bt_iso_cleanup
ISO connection does not initialize its tx_complete_work nor it uses for
anything so calling into tx_notify will likely cause a crash.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-18 15:24:17 +02:00
Lingao Meng
b667ba997f Bluetooth: Mesh: Fix RPL not check by proxy configuration
Fixes proxy configuration not check by replay.
Fixes secure beacon iv update not store new RPL.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-09-18 15:18:18 +02:00
Vinayak Kariappa Chettimada
17c4396ed4 Bluetooth: controller: Fix cond. compilation for broadcaster
Fix conditional compilation for extended advertising
without peripheral support.

This fixes missing initialization of buffer for generating
advertising terminate event.

Fixes #28325.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-18 10:28:57 +02:00
Carles Cufi
121937e071 Bluetooth: controller: Make RX prio thread stack configurable
Now that CONFIG_BT_CTLR_RX_PRIO_STACK_SIZE defines a stack size, allow
for it to be configurable from a .conf file just like the rest of the
threads in Bluetooth.

Fixes #27768.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-09-17 18:08:21 +02:00
Trond Einar Snekvik
d7e0d8135f Bluetooth: Mesh: Use #ifdef for provisioner build
Replaces the current zero length array for provisioner data with
ifdefs, to silence new gcc 10 warnings about array element access.

Fixes #28371.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-09-17 11:51:13 +03:00
chao an
e611b10fde Bluetooth: host: free the adv instance if start legacy advertise fail
the adv instance should be delete correctly if advertise fail,
Otherwise the instance will unable to allocate if start the legacy again

Signed-off-by: chao an <anchao@xiaomi.com>
2020-09-16 11:29:09 +03:00
Trond Einar Snekvik
61819f23f9 Bluetooth: Mesh: Virtual address memory leak
Fixes a memory leak when a virtual address subscription is added for a
model that either has this VA already, or the model has no more space
for subscription addresses.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-09-12 22:48:20 +03:00
Vinayak Kariappa Chettimada
c8e23139c1 Bluetooth: controller: Fix addr type in auxiliary PDU
Fix uninitialized transmitter address type being set in the
auxiliary PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-10 12:07:57 -05:00
Lingao Meng
0023d3f364 Bluetooth: Mesh: Store Krp phase after krp value changed
Store krp phase persistently when this value has been changed.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-09-10 14:12:49 +03:00
Vinayak Kariappa Chettimada
48e791a625 Bluetooth: host: Fix Suggested Default Data Len for QUIRK_NO_AUTO_DLE
Add back call to LE Write Suggested Default Data Length
command so that new connections, receiving Data Length
Update procedure before local device can auto initiate, can
respond with the suggested default data length Tx octets
and Tx time.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-10 12:51:27 +02:00
Andrzej Kaczmarek
7a113ea657 Bluetooth: controller: Fix TxAdd setting in auxiliary PDU
When controller is built with extended advertising support but without
LL Privacy build fails due to issue with code that sets TxAdd in aux
PDU:

.../ll_sw/ull_adv_aux.c: In function 'ull_adv_aux_hdr_set_clear':
.../ll_sw/ull_adv_aux.c:502:25: error: 'struct ll_adv_set' has no
                                member named 'own_addr_type'
  502 |   sec_pdu->tx_addr = adv->own_addr_type & 0x1;
      |

We need own_addr_type value if an advertising set with aux but without
AD is created since we cannot get TxAdd value from other PDU.

ull_adv_aux_hdr_set_clear() can now be called with a flag to explicitly
set AdvA field and pass own_addr_type in 'value' parameter. This allows
to set proper TxAdd when creating new advertising set.

On aux updates, we use TxAdd from other PDU:
- if primary PDU has AdvA, we use TxAdd from that PDU
- if previous secundary PDU has AdvA, we use TxAdd from that PDU
In other case we just return an unpsecified error since this should not
happen in any valid scenario.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-10 12:40:29 +02:00
Vinayak Kariappa Chettimada
61b6534727 Bluetooth: controller: Scanning with unreserved window
Added a Kconfig option to enable scanner with unreserved
scan window when in continuous scan mode. This will permit
scanner to be always pre-empted by other roles, making it
the lowest in priority when it comes to using the radio.

Fixes #27414.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-07 15:11:33 +02:00
Luiz Augusto von Dentz
95cec8354c Bluetooth: GATT: Introduce bt_gatt_attr_get_handle
This introduces bt_gatt_attr_get_handle which can be used to resolve
handles of static attributes.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-05 11:06:21 +02:00
Luiz Augusto von Dentz
5c4bde55d0 Bluetooth: GATT: Rework bt_gatt_attr_func_t
Make it actually give the original pointer to the attribute and its
resolved handle so static attributes don't need an extra lookup.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-05 11:06:21 +02:00
Luiz Augusto von Dentz
dde25a3d44 Bluetooth: GATT: Optimize static service handle resolution
This optimizes the lookups to skip ahead when attribute pointer is not
located within service array.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-05 11:06:21 +02:00
Luiz Augusto von Dentz
b8e9b6f88a Bluetooth: shell: Add iso module
This adds iso shell module which we can be used to exercise ISO related
APIs:

iso - Bluetooth ISO shell commands
Subcommands:
  bind        :[dir] [interval] [packing] [framing] [latency] [sdu]
  [phy] [rtn]
  connect     :Connect ISO Channel
  listen      :[security level]
  send        :Send to ISO Channel
  disconnect  :Disconnect ISO Channel

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-04 21:03:13 +02:00
Luiz Augusto von Dentz
d85d40c58e Bluetooth: hci_raw: Add support for ISO packets
This adds supports for ISO packets so then can be transmitted and
received with hci_raw driver.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-04 21:03:13 +02:00
Luiz Augusto von Dentz
c29e6ffa73 Bluetooth: monitor: Add support for ISO packets
This adds types for TX/RX ISO packets so the likes of btmon can decode
them properly.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-04 21:03:13 +02:00
Luiz Augusto von Dentz
81d34ecd19 Bluetooth: Audio: Initial ISO channel support
This adds initial code for handling ISO channels.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-04 21:03:13 +02:00
Guillaume Lager
f5cb887a79 bluetooth: Allow immediate logging with software-based LL
Some logging configuration are compatible with software-base Link
Layer. Currently only one configuration is supported:
RTT back-end in drop mode and no clean output

Signed-off-by: Guillaume Lager <guillaume.lager@gmail.com>
2020-09-04 18:48:32 +02:00
Kamil Piszczek
be7e2fc5ab bluetooth: services: ots: use multi-instance macro from gatt.h
Used multi-instance macro defined in gatt.h for OTS instance
definitions.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2020-09-04 18:37:27 +02:00
Joakim Andersson
48606a2dcd Bluetooth: shell: Add "add-subscription" command
Add the command add-subscription to the shell to test the
bt_gatt_add_subscription API.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-04 18:34:18 +02:00
Joakim Andersson
76119c526e Bluetooth: GATT: Allow application to add subscription.
Allow the application to add subscription without resubscribing.
This is needed for persistent bonds that can go to deep sleep and
turn of the RAM or power-cycle.
In this case the application as a GATT client must have a way to add
the subscription callbacks back to the stack before the GATT server
sends notifications.
This should preferable be able to be done before even connecting
since the notifications can arrive immediately after connecting to
the peer.
The stack cannot persist this on it's own since it must remember the
function pointers for the callback functions. Storing these in
persistent storage would not be compatible with a Device Firmware
Upgrade (DFU) solution.

Fixes: #21798

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-04 18:34:18 +02:00
Joakim Andersson
ae5489085f Bluetooth: GATT: Refactor gatt_sub_add to add withouth conn object
Refactor the gatt_sub_add function to be similar in structure to how
find_cf_cfg is implemented. This is so that a subscription can be added
without an active connection.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-04 18:34:18 +02:00
Vinayak Kariappa Chettimada
94d7469172 Bluetooth: controller: Add DEBUG_PINS support in nRF5340DK
Add support for BT_CTLR_DEBUG_PINS for nRF5340DK board.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-04 17:17:07 +02:00
Vinayak Kariappa Chettimada
03852a5f02 Bluetooth: controller: Fix DEBUG_PINS_CPUAPP dependency
Remove the BT_LL_SW_SPLIT dependency for
BT_CTLR_DEBUG_PINS_CPUAPP when building CPUAPP application
that is using Zephyr BLE HCI controller on the CPUNET core.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-04 17:17:07 +02:00
Kamil Piszczek
0a7a8fd137 bluetooth: services: add Object Transfer service
Added GATT Object Transfer Service implementation.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2020-09-04 17:06:17 +02:00
Emil Gydesen
9c5db74a6e Bluetooth: Remove _gatt_ infix for Device Information Service (DIS)
The _gatt_ infix was determined to be unnecessary as
GATT is implied by it being a Bluetooth service.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-09-04 15:38:44 +02:00
Emil Gydesen
8d7b5ebd7a Bluetooth: Remove _gatt_ infix for Heart Rate Service (HRS)
The _gatt_ infix was determined to be unnecessary as
GATT is implied by it being a Bluetooth service.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-09-04 15:38:44 +02:00
Emil Gydesen
b4a8229db6 Bluetooth: Remove _gatt_ infix for Battery Service (BAS)
The _gatt_ infix was determined to be unnecessary as
GATT is implied by it being a Bluetooth service.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-09-04 15:38:44 +02:00
Joakim Andersson
7ab35145fb Bluetooth: host: Add hardware error event handling
Add handling of the HCI_Hardware_Error event to log the hardware code.
This event was unmasked in set_event_mask.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-04 14:46:54 +02:00
Jordan Yates
4f54b4176d bluetooth: controller: add name to TX power choice
Add a name to the Kconfig choice that selects the controller TX power.
This allows board `*.defconfig` files to change the default TX power
as their certifications warrant. For example:

```
choice BT_CTLR_TX_PWR
	default BT_CTLR_TX_PWR_PLUS_4
endchoice
```

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2020-09-04 14:46:05 +02:00
Jordan Yates
1723e479ab Bluetooth: controller: preserve TX power
Preserve the TX power set with the `BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL`
command for advertising and scanning procedures. As the TX power is no
longer overwritten on procedure start, the TX powers can now be set
before starting the procedure. This eliminates the chance for the first
transmissions to use the default TX power instead of the request TX
power.

Similar changes are not made to the connection advertising powers as
changing the TX power for a connection to device A should not change
the TX power for a future connection to device B using the same
`struct lll_adv` instance.

Fixes #27921.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2020-09-04 14:37:57 +02:00
Andrzej Kaczmarek
d8864d44f4 Bluetooth: controller: Add ADI support in AUX_SCAN_RSP
ADI field is optional in AUX_SCAN_RSP so by default it's disabled, but
now we'll have an option to include it.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
1b1ab16a64 Bluetooth: controller: Return current ADI when updating aux
When aux is upated, DID is changed and unlike SID it's only stored in
aux PDU. To allow quick access to new DID value, let's just optionally
return current ADI value after aux was updated. It will be useful e.g.
when updating scan response data if we want to put ADI there.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
09115429a1 Bluetooth: controller: Add non-connectable scannable
This enables processing of AUX_SCAN_REQ and sending back AUX_SCAN_RSP
on non-connectabe scannable advertising instances. Similar path will
be used for AUX_CONNECT_REQ so there are few references for connectable
as well, but this is not supported as for now.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
b47df3cc21 Bluetooth: controller: Add scan response data setting restrictions
This adds restrictions for setting scan response data as specified by
Core spec:
* on legacy, only complete data can be set
* on legacy, data cannot be longer than 31 octets
* on ext, if non-scannable, data can only be discarded
* if ext enabled, only complete data can be set
* if ext enabled, data cannot be discarded

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
60b8df94e1 Bluetooth: controller: Add support to set scan response data on ext
This allows to set scan response data using ext adv commands.

New AUX_SCAN_RSP can be created without analyzing previous PDU since
the only value that need to be copied from previous PDU is AdvA which
is placed at fixed location. TxPower is omitted since, if enabled, it
is already present in AUX_ADV_IND and does not need to be presed in
other PDUs. ADI support is to be added later.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
e49ef46677 Bluetooth: controller: Add AdvA to connectable and scannable aux
AdvA in aux is mandatory for any connectable and scannable set so make
sure it's always added.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
c34bd1c2c4 Bluetooth: controller: Add aux for connectable and scannable
Connectable and scannable instances always have aux so we need to force
AuxPtr to be included in primary PDU and have aux allocated even if no
data are set.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00