When optimizations are disabled more RAM is used and we get a stack
overflow on BT_HCI_TX_STACK_SIZE. To rectify this, increase the stack
size when CONFIG_NO_OPTIMIZATIONS.
This does not scale well, and will have to be replaced by a a more
general solution eventually, but in the mean time it follows the
existing best practice established by the GCOV infrastructure in
commit e908ea9aa5
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Translate HCI error codes to POSIX error codes in order to be able to
distinguish reason of connectable advertising start failure.
Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
The Bluetooth 5.1 specification was recently released, and has a new
version identifier (10) assigned to it in the Bluetooth Assigned
Numbers.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Convert the remaining places of the host stack where
net_buf_pull_mem() makes more sense than net_buf_pull().
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Take advantage of the new net_buf_pull_mem() API, and refactor the
events from long switch statements into (const) handler tables. This
helps reduce code size and makes it cheap to add proper checks/asserts
for having sufficient data in the buffers coming from the controller.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Sending a model publication message could fail e.g. if there are no
buffers available, however this doesn't mean that we should stop doing
periodic publishing indefinitely. When an error occurs, make sure to
call the publish_sent() function so that the periodic publishing timer
gets resubmitted if necessary.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
In some cases the Friendship & Low Power Node features aren't
available or feasible, however power saving is nevertheless required.
This patch introduces two new APIs to suspend and resume the Mesh
network. Currently, what this impacts is the LE scanning, the
ability to allocate new outgoing buffers, as well as the model
publishing, beacon and heartbeat timers.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Tracking of the BT_MESH_VALID flag and the PB-GATT state was rather
fragile. Add proper error returns to the various GATT service enable &
disable handlers, and toggle the BT_MESH_VALID flag in a single file
(main.c). Use the newly added error returns to ensure that we don't
re-enable PB-GATT if it wasn't already enabled from before.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
There's already a flags member in the bt_mesh context, so take
advantage of that for any boolean members that have so far been
bit-fields. This should produce more efficient code, also for the
sequence number that's now its own u32_t.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Build fails in smp.c:3942 if BT_SMP_SELFTEST is enabled,
sign_test uses smp_sign_buf which only available for BT_SIGNING.
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
This adds bt_gatt_write_response_cb works similarly to
bt_gatt_notify_cb which can take a callback to be called when the PDU
is considered transmitted over the air.
Note: This can also be used to disable the ATT flow control which would
blocks sending multiple commands without wainting their transmissions.
Fixes#11558
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
The current stack consumption with the H4 driver on qemu_x86 is as
follows with a change from 256 to 512:
usage 396 / 512 (77 %)
Increase the default for this configuration, as well as other similar
configurations. Set the fallback default to a higher value as well.
Fixes#12429
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
The msg->prev_addr is already stored in frnd->clear.frnd, so there's
no need to have an extra stack variable for this (in the form of
prev_addr).
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Currently, when handling a Friend Request message with `prev_addr` set,
we look up existing friend entry using `prev_addr` as the address.
However, `prev_addr` is the address of the requesting node's previous
friend, NOT the address of the requesting node itself. Therefore, we
should always look up existing friend entry using `rx->ctx.addr` as the
address.
Signed-off-by: Jiahao Li <reg@ljh.me>
This fixes usage of an uninitialized variable (to_store) as introduced
by commit bfad2a0.
Fixes#12314
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
When using bt_gatt_discover with BT_GATT_DISCOVER_CHARACTERISTIC the
read callback would be set to bt_gatt_attr_read_chrc which would attempt
to access the next attribute which in this case would not be set since
the value attribute is no fetched by the discovery, the spec actually
omit the value handle saying it should always be the first attribute to
appear after the characteristic thus we can assume it to be handle + 1.
Fixes#12159
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Both "store" and "clear" are verbs, so putting them after each other
is just confusing. Use "clean" consistently when clearing settings
entries.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
The code need to be align after introduction of stream codec to
setting serialization subsystem.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
The Code need to be align after introduction of stream codec to
setting serialization subsystem.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
1. Created new shell module: shell_help.
2. Simplified command handlers with new shell print macros.
3. Removed help functions from command handlers.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Removing help "options" from shell API.
Currently SHELL_OPT macro is not used by users. What is more
commit: a89690d10f ignores possible options created in
command handler by the user. As a result they are not printed
in help message.
Second, currntly implemented "options" in command handlers options are
implemented without SHELL_OPT macro.
And last but not least this change will allow to implement
help handler in a way that user will not need to think about calling
functions printing help in a command handler.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
When we're acting as a Friend for an LPN, we need to consider all
elements of the LPN. The information of how many elements the LPN has
is provided in the Friend Request message, however until now the code
did not do anything with this information.
Fix the issue by tracking the number of elements for each LPN and
update the unicast address matching code to take this into account.
Fixes#11731
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
There is not an easy way to relate an application's user_data to a
connection. One way is to save a pointer to bt_conn in the
application's user_data array upon connection establishment.
Each connection related callback function will have to loop for all
user_data and compare the saved pointer to the passed bt_conn
pointer. This is inefficient if there are many callback activations
during the connection.
This change makes the internal bt_conn mapping function accessible to
applications in conn.h. The function name is changed to
bt_conn_index() to clearly indicate that the function returns an
index of an array.
Add an ASSERT to catch illegal parameter.
Signed-off-by: Kim Sekkelund <ksek@oticon.com>
When removing a peer from a CCC, it also needs to be removed from
the attribute `cfg`.
Not removing it would create a shortage of `cfg` that could
prevent new host to pair to the BLE device.
Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
CCC settings was not removed when unpairing all keys.
It means CCC settings were still present in flash and were
loading at bluetooth initialization time.
Loading these orphan CCC settings would fill `bt_gatt_ccc_cfg`
configurations and would prevent to add new CCC when pairing
with a new device.
Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
Accourding to Bluetooth specification the Service Changed
Characteristic shall not have its handle changed once it has been
bonded, so this moves the GATT service to be the very first service
registered that way it is guaranteed that it won't change even if
device is flashed with a different configuration which end up changing
the handles after it.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
It is related to b904ad387f.
This fixes checking ECDH related events in event mask.
If ECDH support is disabled in host, there is no need to check
if those are supported in the controller.
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
Some backends may actually contain the same key multiple times so the
code needs to check if there is already a ccc_cfg for an address before
attempting to use one that is unallocated.
Fixes#11409
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
If there are no CCC to be stored the value should be set to NULL so it
is properly cleared otherwise calling settings_str_from_bytes will leave
str uninitialized which may cause a crash when attempting to load the
value.
Fixes#11564
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds Kconfig option to disable HCI ECDH support.
It will compile out ECDH related code, especially HCI event handlers.
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
This adds common option to disable support for LE Data Length Update
procedure in controller and host.
This will reduce flash usage by compiling out le_data_len_change
event handler that will never be called if controller has been
compiled with BT_CTLR_DATA_LENGTH option disabled.
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
This adds common option to disable support for PHY Update
procedure in controller and host.
This will reduce flash usage by compiling out le_phy_update_complete
event handler that will never be called if controller has been
compiled with BT_CTLR_PHY option disabled.
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
Logging subsystem could take few extra bytes when enabled.
ECC thread stack has been unconditionally increased to
support it.
During my test, I noticed a usage of 1052 bytes when logging
subsystem is enabled.
Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
This makes it clear that only request need to set an opcode since they
require a error response in case it fails.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
The comment was suggesting that write callback was reading and storing
buffer when in fact it should write to the attribute value.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Application may need to handle the write differently depending on the
write operation so this adds a flag called BT_GATT_WRITE_FLAG_CMD which
can then be checked by the callback, for instance one can respond with
BT_ATT_ERR_WRITE_REQ_REJECTED when that flag is not set which should
indicate to the client to use write command instead.
Fixes#11206
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Consider invalid if the request pointer is NULL or the callback is NULL
or there is a request ongoing. This conditions would likely lead to a
crash and most likely there is some other bug involved like for example
the application queueing the same request multiple times.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
When issuing LE Set Data Length Command host should not assume that
LE Data Length Change Event will be generated. From Core Spec 5.0:
"If the command causes the maximum transmission packet size or maximum
packet transmission time to change, an LE Data Length Change Event
shall be generated."
Change-Id: I17723b58ed4f390aa465db3f69126ee229871123
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
If master or application decided to switch connection parameters to
ones that meet pending parameters don't bother sending request
after 5 seconds timeout.
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
Experiments have shown that the probability of missing advertising
packets is significantly lower with 30ms scan window compared to 10ms
scan window. This is especially the case with advertisers using a 20ms
advertising interval, which in turn is perhaps the most common one
since it's the smallest allowed by the Bluetooth 5.0 specification.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
By default, CCC value is only stored to persistent memory during
BT disconnection. This commit adds an optional storing of CCC right
after it has been updated. This results in better robustness of
peripheral but increases system workqueue stack usage.
Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
Couple of findings which were revealed after changing
LOG_MODULE_REGISTER macro:
- missing semicolons after LOG_MODULE_REGISTER()
- missing LOG_LEVEL defines
- other
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>