Commit graph

9523 commits

Author SHA1 Message Date
Andrzej Kaczmarek
bef663d5c0 Bluetooth: controller: Require aux for connectable or scannable
Connectable and scannable instances always have AuxPtr so we can return
error immediately if controller is configured with no aux.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
0274a6b26b Bluetooth: controller: Disallow setting AD on scannable instance
Scannable instance can only have scan response data set.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Morten Priess
8682e47eb0 Bluetooth: controller: Prevent incorrect lazy_current increment
Prevent redundant collision resolves and potential incorrect and harmful
increment of lazy_current.

During collision scenarios with high CPU load, the ticker_worker may be
called a second time before the ticker_job gets to run. This will cause
ticker operations on the previosly expired node (expected), and in some
cases increment lazy_current, even though the node was not sceduled to
execute via the req/ack mechanism.

By moving the request check before collision resolve, CPU time is saved,
and lazy_current will not incorrectly be incremented if node is in
collision.

The problem may be seen as a connection suddenly not receiving packets,
or MIC error on master, because the event counter goes out of sync.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-09-04 14:14:23 +02:00
Rubin Gerritsen
69867a48db bluetooth: controller: BT_CTLR_CONN_RSSI as a shared controller opt
Use a helper config BT_CTLR_CONN_RSSI_SUPPORT so that it is only
enabled when supported by the controller.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-09-04 14:03:20 +02:00
Vinayak Kariappa Chettimada
42d59c95f2 Bluetooth: controller: Fix periodic advertising cond. compile
Fix missing conditional compilation around the periodic
advertising feature implementation.

Fixes #28017.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-04 11:59:23 +02:00
YanBiao Hao
e877ee6088 Bluetooth: Mesh: Adds three Config Client API.
Those APIs are used for deleting appkey, unbinding an application
from SIG model, unbinding an application from vendor model on the
target node, with matching shell command.

Signed-off-by: YanBiao Hao <haoyanbiao@126.com>
2020-09-04 11:47:52 +02:00
Joakim Andersson
e997c46e6d Bluetooth: GATT: Handle bt/ccc setting with CCC lazy loading
When lazy loading of CCCs are enabled there is no settings set handler
register for the 'bt/ccc' key, this means that the settings set handler
for 'bt' key is called instead. This handler does not know what to do
for the 'ccc' subkey, and returns -ENOENT for the entry.
This results in an error message logged by the settings subsystem.
  "E: set-value failure. key: bt/ccc/f8c39e2f98210 error(-2)"

Fix this by providing an empty handler for the 'bt/ccc' key when
Lazy Loading feature is enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-03 13:56:10 +02:00
Vinayak Kariappa Chettimada
eafb6aece1 Bluetooth: host: Fix periodic advertising delete
Fix periodic advertising delete implementation, to not
NULL the callback pointer when deleting the instance so
that the application's terminate callback can be called
thereafter.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-03 10:40:35 +02:00
Vinayak Kariappa Chettimada
c895e3650f Bluetooth: host: minor code style cleanup
Minor cleanup to use reverse christmas tree declarations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-03 10:40:35 +02:00
Tomasz Bursztyka
4dcfb5531c isr: Normalize usage of device instance through ISR
The goal of this patch is to replace the 'void *' parameter by 'struct
device *' if they use such variable or just 'const void *' on all
relevant ISRs

This will avoid not-so-nice const qualifier tweaks when device instances
will be constant.

Note that only the ISR passed to IRQ_CONNECT are of interest here.

In order to do so, the script fix_isr.py below is necessary:

from pathlib import Path
import subprocess
import pickle
import mmap
import sys
import re
import os

cocci_template = """
@r_fix_isr_0
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
 ...
(
 const struct device *D = (const struct device *)P;
|
 const struct device *D = P;
)
 ...
}

@r_fix_isr_1
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
 ...
 const struct device *D;
 ...
(
 D = (const struct device *)P;
|
 D = P;
)
 ...
}

@r_fix_isr_2
@
type ret_type;
identifier A;
@@
-ret_type <!fn!>(void *A)
+ret_type <!fn!>(const void *A)
{
 ...
}

@r_fix_isr_3
@
const struct device *D;
@@
-<!fn!>((void *)D);
+<!fn!>(D);

@r_fix_isr_4
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
 ...
(
-const struct device *D = (const struct device *)P;
|
-const struct device *D = P;
)
 ...
}

@r_fix_isr_5
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
 ...
-const struct device *D;
...
(
-D = (const struct device *)P;
|
-D = P;
)
 ...
}
"""

def find_isr(fn):
    db = []
    data = None
    start = 0

    try:
        with open(fn, 'r+') as f:
            data = str(mmap.mmap(f.fileno(), 0).read())
    except Exception as e:
        return db

    while True:
        isr = ""
        irq = data.find('IRQ_CONNECT', start)
        while irq > -1:
            p = 1
            arg = 1
            p_o = data.find('(', irq)
            if p_o < 0:
                irq = -1
                break;

            pos = p_o + 1

            while p > 0:
                if data[pos] == ')':
                    p -= 1
                elif data[pos] == '(':
                    p += 1
                elif data[pos] == ',' and p == 1:
                    arg += 1

                if arg == 3:
                    isr += data[pos]

                pos += 1

            isr = isr.strip(',\\n\\t ')
            if isr not in db and len(isr) > 0:
                db.append(isr)

            start = pos
            break

        if irq < 0:
            break

    return db

def patch_isr(fn, isr_list):
    if len(isr_list) <= 0:
        return

    for isr in isr_list:
        tmplt = cocci_template.replace('<!fn!>', isr)
        with open('/tmp/isr_fix.cocci', 'w') as f:
            f.write(tmplt)

        cmd = ['spatch', '--sp-file', '/tmp/isr_fix.cocci', '--in-place', fn]

        subprocess.run(cmd)

def process_files(path):
    if path.is_file() and path.suffix in ['.h', '.c']:
        p = str(path.parent) + '/' + path.name
        isr_list = find_isr(p)
        patch_isr(p, isr_list)
    elif path.is_dir():
        for p in path.iterdir():
            process_files(p)

if len(sys.argv) < 2:
    print("You need to provide a dir/file path")
    sys.exit(1)

process_files(Path(sys.argv[1]))

And is run: ./fix_isr.py <zephyr root directory>

Finally, some files needed manual fixes such.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka
e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Johan Hedberg
0aa5341ea5 Bluetooth: Mesh: Remove unnecessary #ifdefs from beacon code
Many #ifdefs can be removed, but the UNPROV_BEACON_INT Kconfig
variable needs to be also made available also. This is done by making
its prompt (user selectability) optional rather than the option
itself. This approach is fine for "parameter style" options, but
should probably not be used for feature enabling options.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-09-01 22:00:02 +03:00
Lingao Meng
23ddc90394 Bluetooth: Mesh:Move LPN_SUB_ALL to lpn subgroup
Move BT_MESH_LPN_SUB_ALL_NODES_ADDR to lpn subgroup

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-09-01 22:00:02 +03:00
Lingao Meng
f869e51c25 Bluetooth: Mesh: Add Option config unprov beacon interval
Add Option to specifies the second interval when device
send Unprovisioned Beacon.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-09-01 22:00:02 +03:00
Joakim Andersson
9ac8dcf5a7 Bluetooth: Call bt_recv from priority higher that TX thread.
A build assert in dummy.c lists the following requirement:
[...] receive thread priority shall be higher than the Bluetooth
Host's Tx and the Controller's receive thread priority.
This is required in order to dispatch Number of Completed Packets
event before any new data arrives on a connection to the Host threads.

The drivers uses a priority that is equal to the Host TX thread,
and since they don't use the CONFIG define that is only available
to the controller then this BUILD_ASSERT will not catch the
requirement.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-01 15:15:36 +03:00
Trond Einar Snekvik
18ace841d8 Bluetooth: Mesh: Config client net_key_del
Adds a Config Client API for deleting netkeys on the target node, with
matching shell command.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-09-01 14:49:20 +03:00
Emil Gydesen
9bf50ddb20 Bluetooth: Gatt: Added write callback for gatt (un)subscribe
Added a callback that lets an application get write error
(if any) when subscribing to a gatt characteristic.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-09-01 13:34:25 +02:00
Joakim Andersson
becd9cadfe Bluetooth: host: Fix option USE_IDENTITY for bt_le_ext_adv_* API
Fix option USE_IDENTITY for bt_le_ext_adv_* API.
The random static identity address that was set in bt_le_ext_adv_create
was overwritten in bt_le_ext_adv_start in the call to
le_adv_set_private_addr.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-01 13:28:56 +02:00
Andrzej Głąbek
8e5afef6da bluetooth: controller: nrf5: Add support for nRF52805
Add the nRF52805-specific file with radio related defintions.
Use also specific configurations for certain PPI channels used by
the controller, as this SoC has limited number of programmable PPI
channels.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2020-08-31 15:40:19 +02:00
Andrzej Głąbek
89c7588917 bluetooth: controller: nrf5: Refactor a bit radio_nrf5_ppi.h
Change hard-coded (D)PPI channel bitfield values to the BIT() macro
calls with the corresponding channel base value supplied as parameter,
to make it possible to actually change this base value if needed.
Remove unused *_EXCLUDE macros.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2020-08-31 15:40:19 +02:00
Vinayak Kariappa Chettimada
293aa54ef3 Bluetooth: controller: Revert back to using EGU in nRF5340PDK
Refer to nRF5340 Engineering A Errata 29.
[29] SWI: SWIRQ is not functional.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:49:35 +02:00
Vinayak Kariappa Chettimada
5a40aa073d Bluetooth: controller: nRF53: Use SWI instead of EGU
nRF5340 does have SWI peripheral, hence use it instead of
the single available EGU peripheral. Use of SWI will allow
controller's LLL, ULL_HIGH and ULL_LOW execution context to
be independently configured to different interrupt priority
levels.

When ULL_HIGH priority equals ULL_LOW priority, only SWI2
is used by controller. Otherwise, SWI3 is used for ULL_LOW.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:49:35 +02:00
Vinayak Kariappa Chettimada
13bbfc8172 Bluetooth: controller: Handle AD data set race condition
Detect and handle AD data set race condition between thread
and ISR context.

Fixes #27637.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:49:13 +02:00
Vinayak Kariappa Chettimada
530c090cba Bluetooth: controller: Add cpu_dsb hal interface
Add cpu_dsb() hal interface so that data synchronization
barrier be used in ARM Cortex M4 and M33 architecture
implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:49:13 +02:00
Vinayak Kariappa Chettimada
c0950dc35d Bluetooth: controller: Add volatile to AD data double buffer index
Set the AD data double buffer first index as volatile
because it is modified in LLL ISR context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:49:13 +02:00
Vinayak Kariappa Chettimada
8b2024e26c Bluetooth: controller: Add code to detect AD data set race
Added code to detect AD data set race condition.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:49:13 +02:00
Vinayak Kariappa Chettimada
58620ec5a7 Bluetooth: controller: Review rework use HCI defines
Use HCI error and command parameter defines.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:47:36 +02:00
Vinayak Kariappa Chettimada
139fbb0f4d Bluetooth: controller: Add sync info structure fill function
Refactor out into function the filling of sync info
structure in the common extended advertising payload format
header.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:47:36 +02:00
Vinayak Kariappa Chettimada
c85786ff6f Bluetooth: controller: Add aux ptr fill function
Refactor out into function the filling of aux ptr structure
in the common extended advertising payload format header.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:47:36 +02:00
Vinayak Kariappa Chettimada
4a2300d2da Bluetooth: controller: Add common header len get/fill function
Refactor out into functions the calculation of common
extended advertising payload format header length.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:47:36 +02:00
Vinayak Kariappa Chettimada
3abe58e7f1 Bluetooth: controller: Refactor to allow code reuse
Moved the assignment of PDU length out side of a conditional
so that code to calculate PDU length can be reused.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:47:36 +02:00
Vinayak Kariappa Chettimada
3120cddb47 Bluetooth: controller: Refactor out AD data population
Refactor out AD data population to use the common function
ull_adv_aux_hdr_set_clear.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:47:36 +02:00
Vinayak Kariappa Chettimada
f69d9ed515 Bluetooth: controller: Refactor sync info population
Refactor out sync info field population into a utility
function with set and clear interface to add or remove
the common extended advertising header format fields.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:47:36 +02:00
Trond Einar Snekvik
3c8e5b0e1c Bluetooth: Mesh: Network loopback
Changes the local network interface to exclusively handle packets for
the local interface, duplicating the buffers in the process.

The loopback mechanism now operates its own packet pool for the local
interface queue. The loopback is moved ahead of encryption, allowing the
local interface packets to go back up the stack without network crypto,
saving a full round of encrypt/decrypt for self-send.

Packets for group addresses the local node subscribes to are now
duplicated, with one unencrypted variant going into the network
queue, and the network bound packets following the regular path to the
advertiser.

Introduces one new configuration for setting the number of loopback
buffers.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-08-30 17:09:59 +03:00
chao an
00d1408a14 Bluetooth: host: fix build break if enable oob legacy pair only
enable CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY:

In function `bt_le_oob_get_local':
subsys/bluetooth/host/hci_core.c:8878:
		undefined reference to `bt_smp_le_oob_generate_sc_data'

Signed-off-by: chao an <anchao@xiaomi.com>
2020-08-28 12:23:56 +03:00
Flavio Ceolin
9337b782d1 bluetooth: Fix a fallthrough warning
It fixes:

../../../../include/toolchain/gcc.h:169:30: warning: statement will
never be executed [-Wswitch-unreachable]

  169 | #define __fallthrough        __attribute__((fallthrough))

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-08-27 07:02:40 -04:00
Emil Gydesen
c5636508d4 Bluetooth: host: Deleting PA sync before term callback
The PA sync is now "deleted" (i.e. flags reset) before
the terminated callback is called, so that is
possible to create PA sync in the callback. One flag
was already cleared before for this reason, but one
other flag is also required, so we just clear
everything now.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-08-26 12:31:59 +02:00
Emil Gydesen
4ee327461f Bluetooth: host: PA sync while explicitely scanning
Removed the check for explicit scanning, such that
an application may create a PA sync while explicitely
scanning.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-08-26 12:31:59 +02:00
Vinayak Kariappa Chettimada
b5dba35727 tests: Bluetooth: shell: Fix conditional compilations
Fix conditional compilations that fail when combinations
of Broadcaster, Observer, Peripheral and/or Central are
selected to build an application.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-25 16:38:12 +03:00
Vinayak Kariappa Chettimada
2a3e86a2fd Bluetooth: controller: Fix conditional compilations
Fix conditional compilations that fail when combinations
of Broadcaster, Observer, Peripheral and/or Central are
selected to build an application.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-25 16:38:12 +03:00
Vinayak Kariappa Chettimada
be1b634193 Bluetooth: controller: Fix BT_CTLR_SCAN_REQ_NOTIFY dependency
Fix BT_CTLR_SCAN_REQ_NOTIFY as depends on BT_BROADCASTER.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-25 16:38:12 +03:00
Vinayak Kariappa Chettimada
e8e7ccb448 Bluetooth: controller: Fix Adv Set Terminated event cond. compile
Fix the conditional compilation of Advertising Set Terminated
event implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-25 16:38:12 +03:00
Joakim Andersson
5880f3d74f Bluetooth: UUID: Use BT_UUID_16_ENCODE to set UUIDs in adv data
Use BT_UUID_16_ENCODE to set UUIDs in advertising data.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-25 16:09:22 +03:00
Emil Gydesen
689f3b2bc8 Bluetooth: host: per_adv_sync auto scan fixed for central role
If `CONFIG_BT_CENTRAL` was enabled and the device was not scanning
or connected, then `bt_le_per_adv_sync_create` would not start
scanning for periodic advertisers.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-08-25 15:50:32 +03:00
Lingao Meng
a574d4c840 Bluetooth: Mesh: Enhancement prov segment received
Optimize provisioning segment package received, and
not ignore non-begin segment.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-08-25 15:48:56 +03:00
Kim Sekkelund
41842dd174 Bluetooth: host: GATT Lazyloading cleanup at disconnect
Mark the ram version of the ccc_cfg as free after ccc has been
stored when a bonded device disconnects.
If the device use lazy loading of settings then ccc_cfg was not
cleaned up properly when a bonded device disconnects. This
resulted in the ccc system ran out of ccc_cfg resources after
having disconnected CONFIG_BT_MAX_CONN times.

Signed-off-by: Kim Sekkelund <ksek@oticon.com>
2020-08-25 15:40:31 +03:00
Kim Sekkelund
29b42c5a2f Bluetooth: host: GATT Relocate bt_gatt_disconnected
Step1: Move bt_gatt_disconnected() to avoid forward declarations which
otherwise would be needed by a fix to lazy loading cleanup on
disconnect in step 2.

Signed-off-by: Kim Sekkelund <ksek@oticon.com>
2020-08-25 15:40:31 +03:00
Luiz Augusto von Dentz
426fb82bd8 Bluetooth: ATT: Fix not restoring buffer state when send fails
Since bt_l2cap_send_cb can fail returning its error is not enough as
the buffer has been modified to add the headers, so this save the state
before calling bt_conn_send_cb and takes a reference so it can be
restored its original state in case of error.

Fixes #27434

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-08-25 15:22:07 +03:00
Flavio Ceolin
0aaae4a039 guideline: Make explicit fallthrough cases
-Wimplicit-fallthrough=2 requires a fallthrough comment or a compiler
to tells gcc that this happens intentionally.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-08-24 20:28:47 -04:00
Andrzej Kaczmarek
3006dac9ae Bluetooth: controller: Add privacy handling for LE Scan Request Recv
Scanner address returned in event should be resolved, if possible.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-08-24 13:28:31 +02:00