Commit graph

21541 commits

Author SHA1 Message Date
Joakim Andersson
75deefb1b2 Bluetooth: host: Fix indicate without user callback
Fix indicate without func not working properly, when sent as a
non-req by GATT this has two propblems:
 - The indicate would not be treated as a transaction, and back
   to back indicate would be sent without waiting for the confirm
 - The destroy callback would not be called on the indicate parameters
   since the indicate_rsp callback would not be called.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 12:59:01 -05:00
Luiz Augusto von Dentz
8df6124deb Bluetooth: ATT: Remove BT_ATT_TX_MAX
ATT channels do support queueing buffer so it no longer need to block
waiting the tx_sem besides the buffer allocation already serves the
same purpose as the application will not be able to have more requests
than there are buffers available.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-02-11 12:59:01 -05:00
Joakim Andersson
9752cee3d7 Bluetooth: host: Refactor smp handling of conn pointer
Refactor SMP to have a conn pointer where this pointer is used
multiple times.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 12:59:01 -05:00
Joakim Andersson
fcdb2eef25 Bluetooth: host: Allow requesting new security when security changed
Allow to request a higher security level during the key distribution
phase.

This is required by ATT and L2CAP since they only react to the encrypt
change event where they resend the current request.
The current request might require a higher security level still and
might have to request a higher security level before the pairing
procedure has been finished.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 12:59:01 -05:00
Joakim Andersson
301317e8fd Bluetooth: host: Handle multiple step security elevation
When ATT resends an ATT request it is sent as a "response" instead of
as a request. This causes the ATT request buffer to be released and
the ATT request cannot be resent one more time.

This causes a problem when the ATT request requires authentication
but the elevation of security is not enforcing MITM protection.
In this case the ATT will first require security level 2 and then resend
the request once this has been reached.
This will lead to a new ATT error response and ATT will require security
level L3.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 12:59:01 -05:00
Joakim Andersson
2f588f946f Bluetooth: host: Fix update keys when using debug public key check
Fix the update keys check allowing to overwrite the keys when using
debug keys. Instead the check disallowed overwriting keys made using
debug keys.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 12:59:01 -05:00
Joakim Andersson
abd470cbe6 Bluetooth: shell: Fix gatt write command not cleanup up on error
Fix gatt write command returned "write in progress" when either
hex2bin or bt_gatt_write returned an error.
The write_params.func should not be set if the write command was not
successful.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 12:59:01 -05:00
Anas Nashif
5d1c535fc8 license: add missing SPDX headers
Add SPDX header to files with existing license.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-02-11 08:05:16 -05:00
Flavio Ceolin
88725260e6 power: Fix power states length
The number of states was off by one.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-02-10 22:10:21 -05:00
Trond Einar Snekvik
512444d863 Bluetooth: Mesh: Update seqnum when re-encrypting for friend
Sets the sequence number when re-encrypting messages from the friend to
the lpn.

This is a regression from #28511.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-02-10 08:55:40 -05:00
Trond Einar Snekvik
48526b6925 Bluetooth: Mesh: Initialize msg_ctx when re-encrypting friend msg
Set app_idx and net_idx in the msg_ctx before calling
bt_mesh_keys_resolve when re-encrypting friend messages, as they'll be
referenced inside the function.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-02-10 08:55:40 -05:00
Jordan Yates
ddc595b662 lorawan: move public network request
Move the public network request command from the end of `lorawan_start`
to the start of `lorawan_join`. This MAC command interacts with the
radio driver, bringing it out of sleep mode, and doesn't put it back.

The public network setting is only needed when joining a network, and
`lorawan_start` can be called well before `lorawan_join`. By moving the
command we save ~600uA before joining (for sx1262).

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-02-10 08:55:15 -05:00
Vinayak Kariappa Chettimada
b365ab06a7 Bluetooth: controller: Fix missing advertising PDU len initialization
Fix missing advertising PDU length initialization which
prevented advertising PDU to be transmitted by Radio. This
issue was reproduced when connectable undirected advertising
was enabled without setting an advertising data.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-10 07:17:48 -05:00
Eduardo Montoya
fb20d0022a net: openthread: add CoAP Block Kconfig option
Enable new feature from the upmerge:
- OPENTHREAD_COAP_BLOCK

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-02-08 11:36:45 -05:00
Peter Bigot
9519140270 fs: littlefs: fix mis-use of preprocessor
llvm 11 doesn't like having preprocessor directives in the expansion
of a macro used as a preprocessor conditional expression.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-08 11:36:24 -05:00
Trond Einar Snekvik
a281d10cff Bluetooth: Mesh: Store network at the end of provisioning
After #31176, the network would get stored immediately in
bt_mesh_net_create, causing the address and devicekey to get stored as
their zero-initialized version, as they're only being set in the
bt_mesh_comp_provision call, which fires after.

Fixes #32067.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-02-08 10:37:08 -05:00
Joel Westerberg
8b14b83940 Bluetooth: ISO: fix error value set but not returned
err was set to -EIO, but function still returned 0.

Fixes: #31847

Signed-off-by: Joel Westerberg <joel@teenage.engineering>
2021-02-05 08:13:14 -05:00
Andrzej Puzdrowski
6fb7ac233c fs: Fix fs_opendir resource leak when invoked on fs_dir_t object in use
Fixes problem when fs_opendir invoked on fs_dir_t object,
which is already holding information on opened directory,
overwrites references to other memory objects within
the fs_dir_t object causing resource leak.
If fs_opendir is invoked on already used fs_dir_t object,
it will return
-EBUSY.

Note: The change requires that all fs_dir_t objects should be
initialized to 0.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-02-05 07:32:20 -05:00
Andrzej Puzdrowski
7a4940d270 fs: Add fs_dir_t type variable initializations
The commit adds initializations of fs_dir_t variables in preparation
for fs_opendir function change that will require fs_dir_t object, passed
to the function, to be initialized before first usage.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-02-05 07:32:20 -05:00
Vinayak Kariappa Chettimada
a980012aa9 Bluetooth: controller: Fix build error with ISO support
Fix build error due to missing include file with ISO support
enabled.

Fixes #31996.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-05 06:36:52 -05:00
Emil Hammarstrom
3cf64b17c3 bluetooth: host: expand l2cap CID abbreviation
Reduces some user confusion regarding whether it is related
to "Connection ID", "Channel ID", or "Company ID" for the
uninitiated.

Signed-off-by: Emil Hammarstrom <emil.hammarstrom@assaabloy.com>
2021-02-04 08:31:20 -05:00
Tomasz Bursztyka
f729f82171 net/6lo: First buffer fragment should hold the full compressed header
Current 6lo implementation is unable to deal with scattered headers
(which should not happen usually, though it's a valid use case), so
let's just fail uncompressing such packet then.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-02-04 07:36:16 -05:00
Tomasz Bursztyka
a980762f70 net/ieee802154: Drop fragmented packet if first frag is not present
Bogus fragmented packet could be sent without a FRAG1 fragment and hit
reassembly. Let's make sure this does not happen.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-02-03 17:39:26 -05:00
Tomasz Bursztyka
2a423bc6d3 net/ieee802154: Do not unreference one time too many a fragmented packet
In case the current packet is the same as the cached one, let's not
unreference it while clearing the cache.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-02-03 17:39:26 -05:00
Tomasz Bursztyka
0ebd300001 net/ieee802154: Make sure L2 drop any ACK frames
Though ACK frames are not meant to reach L2 (drivers must ensure this
never happens), let's "re-enforce" the L2 by dropping them.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-02-03 17:39:26 -05:00
Tomasz Bursztyka
6917d26848 net/ieee802154: Avoid NULL pointer de-reference in packet reassembly
In case the very first fragment holds all the data already.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-02-03 17:39:26 -05:00
Tomasz Bursztyka
606807940c net/ieee802154: Each fragment should be at least of its header's length
Not validating this length could lead to integer underflow and memory
corruption.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-02-03 17:39:26 -05:00
Tomasz Bursztyka
6f1ab93c66 net/ieee802154: Invalidate frame in case of no address in relevant modes
All addressing mode but IEEE802154_ADDR_MODE_NONE should have a valid
address. If not, the frame is invalid.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-02-03 17:39:26 -05:00
Vinayak Kariappa Chettimada
b7acb6bf55 Bluetooth: controller: openisa: Fix to use compiler memory barrier
Fix OpenISA port to include compiler memory barrier as in
commit 1a14f8b3a6 ("Bluetooth: controller: Use DMB instead
of DSB").

Relates to commit 1af2b91c23 ("Bluetooth: controller: Fix
Tx Buffer Overflow") and to commit ef2ece82c0 ("Bluetooth:
controller: openisa: Fix sanitycheck failures") and to
commit c2fc629dd2 ("Bluetooth: controller: 255 byte AD
payload support").

Fixes #31937.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-03 14:16:12 -05:00
Vinayak Kariappa Chettimada
59616c0b03 Bluetooth: controller: openisa: Fix unsupported ULL LLL Prio config
Fix for OpenISA rv32m1_vega_ri5cy board not supporting
different IRQ Priority levels for LLL, ULL_HIGH and ULL_LOW
execution contexts.

Fixes #31937.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-03 14:16:12 -05:00
Vinayak Kariappa Chettimada
3664cb9f62 Bluetooth: controller: Fix BT_CTLR_ULL_HIGH_PRIO default value
Fix BT_CTLR_ULL_HIGH_PRIO default value to equal
BT_CTLR_LLL_PRIO value if BT_CTLR_LOW_LAT is enabled, else
default ULL_HIGH to lower IRQ priority level in comparison
to LLL IRQ priority level. If BT_CTLR_ZLI is enabled,
BT_CTLR_ULL_HIGH_PRIO can default to a priority level value
of 0 and still be lower priority level than the LLL which
is placed at Zero Latency IRQ priority level (highest
priority in the CPU).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-03 14:16:12 -05:00
Trond Einar Snekvik
2bd5b63dfd Bluetooth: Mesh: Verify network buffer max len
As network_decode needs a target buffer for decoding, the max PDU length
must be checked to prevent overflow on the target buffer. When receiving
a proxy configuration message with excessive length, there's no previous
check for this.

Also pulls the NET PDU length defines out into net.h, so they can be
used when defining the target buffers.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-02-03 13:12:09 -05:00
Jordan Yates
b5b9f2c458 lorawan: restore datarate after join
Restore the user requested datarate upon a successful join. Several
regions overwrite the configured datarate through `RegionAlternateDr`,
which means that for these regions, `LoRaMacQueryTxPossible` will not
be evaluating the requested datarate for the first transmission after
joining.

Fixes #31551.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-02-03 10:45:41 -05:00
Jordan Yates
f553007e06 lorawan: validate requested datarates
Validate datarates requested by users. As a side effect of this change
the MAC layer is immediately aware of updated datarates. Therefore
`LoRaMacQueryTxPossible` in `lorawan_send` will be using the same
datarate to evaluate the payload length as `LoRaMacMcpsRequest` is
requesting.

Fixes #31551.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-02-03 10:45:41 -05:00
Jordan Yates
83f43c727f lorawan: query default region datarate
Query the default datarate for the configured region, instead of
assuming that the default is DR_0.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-02-03 10:45:41 -05:00
Lukasz Maciejonczyk
563c24fb78 settings: Handle unhandled error
There was a case when the return code was ignored. This commit
fixes it.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-02-03 08:37:11 -05:00
Johann Fischer
de6c583eee usb: fix BOS descriptor registration
Use BOS header structure directly we have access to
instead of casting extern const pointers.

Fixes: #30330

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-02-02 21:29:23 -05:00
Peter Bigot
96dfed029d power: fix bound on state array
Attempts to disable PM_STATE_SOFT_OFF would index past the end of the
count array.  Increase the array length to allow operations on
PM_STATE_SOFT_OFF.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-02 16:43:55 -05:00
Hubert Miś
77c68aa070 net: coap: clean up token usage in samples and tests
This patch replaces magic numbers with COAP_TOKEN_MAX_LEN value and
removes unnecessary castings of token buffer type.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-02 14:03:01 -05:00
Hubert Miś
22687c34e3 net: coap: define default CoAP version
RFC 7252 (CoAP) specifies value of the Version (Ver) field in the
protocol header to value 1. This patch defines value of the Version
field to make packet initialization easier. All samples and tests
are updated to use the new COAP_VERSION_1 field when initializing
a CoAP packet.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-02 14:03:01 -05:00
Vinayak Kariappa Chettimada
1af2b91c23 Bluetooth: controller: Fix Tx Buffer Overflow
Fix Tx Buffer Overflow caused by uninitialized node_tx
memory being used by ULL ISR context due to Compiler
Instructions Reordering in the use of MFIFO_ENQUEUE.

The MFIFO last index was committed before the data element
was stored in the MFIFO due to Compiler Instructions
Reordering.

This is fixed now by adding a Data Memory Barrier
instruction alongwith a compiler memory clobber.

Fixes #30378.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-02 14:00:57 -05:00
Vinayak Kariappa Chettimada
1a14f8b3a6 Bluetooth: controller: Use DMB instead of DSB
Use of Data Memory Barrier instruction with memory clobber
in ARM Cortex M architectures is sufficient in the
controller implementation to keep compiler data access
instructions in order so that an ISR vectoring has memory
accesses in the correct order as intented by design.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-02 14:00:57 -05:00
Joakim Andersson
97d59a7c6d Bluetooth: host: Mark the option BT_FIXED_PASSKEY as insecure
Mark the option BT_FIXED_PASSKEY as an insecure option.
During Legacy pairing the passkey is used as encryption key, and
brute-forcing this is easy.
During LE Secure Connections the passkey is checked one bit at a time,
so when it is fixed the passkey can be deduced with series of pairing
attempts.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-02 11:09:05 -05:00
Joakim Andersson
b9695c07cd Bluetooth: kconfig: Fix SMP dependency on BT_ECC
The Bluetooth SMP protocol depends on the BT_ECC for the LE Secure
Connections pairing. Since this feature cannot be disabled we must
select this dependency.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-02 11:09:05 -05:00
Joakim Andersson
971404eee9 Bluetooth: host: Fix fixed passkey for legacy pairing
Fix fixed passkey for legacy pairing. The pairing procedure fails
because the temporary key (TK) has not been set for this pairing
procedure.

Fix this by always requesting the legacy TK.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-02 11:09:05 -05:00
Joakim Andersson
2d50761c3e Bluetooth: shell: Fix misleading shell message id-create failed
Fix misleading message in the bluetooth shell when the id-create
command returns en error code. In this case both failure and success
messages are printed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-02 08:46:17 -05:00
Joakim Andersson
e800ec1cf3 Bluetooth: host: Add options to control behavior of the init command
Add options to control the behavior of the init command.
Option no-settings-load allows the user to create identities
with the id-create command after bt_enable() but before settings_load().
Option no-ready-cb allows the user to test using synchronous enable,
since this sometimes leads to different behavior of the stack.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-02 08:46:17 -05:00
Joakim Andersson
8a55e04e23 Bluetooth: host: Prevent bt_rand calls before bt_enable
Prevent the bt_rand function from being called before bt_enable.
Depending on the implementation of bt_rand this function cannot
be called before bluetooth has been initialized. With host supplied
crypto functions the HCI LE rand command is used for example.

The use case for calling bt_id_create before bt_enable is meant for
when the application has storage for the identity instead of the stack.
So we add the requirement that the application has to have storage
for the identity resolving key (IRK) in addition when the local
device is privacy-enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-02 08:46:17 -05:00
Vinayak Kariappa Chettimada
30634334a8 Bluetooth: controller: Fix ULL_HIGH priority to be lower than LLL
Fix the default ULL_HIGH execution priority to be lower than
LLL execution priority to reduce Radio ISR service latency.

Also, default to Zero Latency IRQ for Radio ISR if enabled
in the kernel.

Fixes #29994.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-02 08:09:29 -05:00
Vinayak Kariappa Chettimada
929dae8cad Bluetooth: controller: Add ISR cputime measurement
Adding ISR cputime measurement for Radio, LLL, ULL_HIGH and
ULL_LOW execution contexts.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-02 08:09:29 -05:00