Commit graph

1632 commits

Author SHA1 Message Date
lly 77fe2ced32 ble_mesh: stack: Move fast prov functions to a single file 2020-07-03 08:53:56 +08:00
lly c4794f761e ble_mesh: ci: Fix failing to compile when using make 2020-07-02 03:35:13 +00:00
lly 4d9af50eba ble_mesh: Mark platform related default RNG as 0 2020-07-02 03:35:13 +00:00
lly 0e028c044d ble_mesh: Remove the previously added redundant aes files 2020-07-02 03:35:13 +00:00
lly 813cf5cc00 ble_mesh: Update CMake and make files for tinycrypt 2020-07-02 03:35:13 +00:00
lly ac0746aba1 ble_mesh: Update tinycrypt header file include guards
Add BLE_MESH in the macro to make it specific for BLE Mesh.
2020-07-02 03:35:13 +00:00
lly e5f4ff2b1a ble_mesh: Format source and header files of tinycrypt 2020-07-02 03:35:13 +00:00
lly 4f37a08437 ble_mesh: Port full implementation of tinycrypt [Zephyr]
- Original code is here: https://github.com/zephyrproject-rtos/tinycrypt
- Also this fixes the compile error when NimBLE and ESP BLE Mesh
  both uses the tinycrypt.
2020-07-02 03:35:13 +00:00
Island c7acaf9b44 Merge branch 'bugfix/ble_mesh_compile_error_v4.0' into 'release/v4.0'
Bugfix/ble mesh compile error (v4.0)

See merge request espressif/esp-idf!9432
2020-07-02 11:29:06 +08:00
Jiang Jiang Jian 8309f06378 Merge branch 'bugfix/kconfig_vendor_specific_v4.0' into 'release/v4.0'
Bugfix: bt/Kconfig Vendor specific event data type and default value

See merge request espressif/esp-idf!9416
2020-07-01 13:49:53 +08:00
lly 3b6145dc46 ble_mesh: stack: Fix compile error when only proxy enabled
Also remove some redundant CONFIG_BLE_MESH_PROXY checks, because
when the following options are satisfied, the CONFIG_BLE_MESH_PROXY
option will be selected mandatorily.
2020-07-01 11:55:12 +08:00
Island b823a2a35f Merge branch 'bugfix/ble_mesh_check_subnet_before_update_beacon_sent_v4.0' into 'release/v4.0'
ble_mesh: Check if subnet exists before updating beacon_sent (v4.0)

See merge request espressif/esp-idf!9397
2020-07-01 11:16:39 +08:00
Island 4802585bfd Merge branch 'bugfix/ble_mesh_set_recv_rssi_v4.0' into 'release/v4.0'
Bugfix/ble mesh set recv rssi (v4.0)

See merge request espressif/esp-idf!9391
2020-07-01 11:15:20 +08:00
Chinmay Chhajed b9b31e3c85 bt/Kconfig: Update data type and default value of vendor specific event. 2020-06-30 15:02:22 +05:30
Jiang Jiang Jian d921a06c1f Merge branch 'feature/bt_secure_conn_downgrade_check_v4.0' into 'release/v4.0'
Bluedroid: Authentication fixes in Legacy and Secure Connection.

See merge request espressif/esp-idf!9338
2020-06-30 15:26:57 +08:00
lly dfcc8e77dc ble_mesh: Check if subnet exists before updating beacon_sent
- Before updating the "beacon_sent" of a subnet, we need to check
  if the subnet still exists, especially for a Provisioner.
- Fix a bug which will cause Provisioner failed to send Secure
  Network Beacon if no device is provisioned
2020-06-30 09:22:49 +08:00
lly 7f6735fd60 ble_mesh: stack: Copy recv_rssi for other received messages
Follow the commit: 2b80cb6883,
copy the recv_rssi for other mesh messages.
2020-06-30 09:05:51 +08:00
mbroek ca5ab9b607 When a generic mesh model message is received "bt_mesh_generic_server_cb_evt_to_btc" copies the
ctx values to cb_params for the mesh stack.

recv_rssi was not copied.

This means the rssi could not be read when receiving generic server messages using ble_mesh.
2020-06-30 09:05:50 +08:00
liminyang acb54059be docs:fix event typo
1.In the description of the ESP_API header file, it should be the event that the application layer needs to handle, not the BTA layer.
2.Fix name typo of BTA_GATTS_CREATE_SRVC_EVT event

Closes https://github.com/espressif/esp-idf/issues/5446
2020-06-29 20:59:14 +08:00
Island 8cb2ad1fe6 Merge branch 'bugfix/ble_mesh_get_node_with_name_v4.0' into 'release/v4.0'
ble_mesh: Get node info with pre-configured node name (v4.0)

See merge request espressif/esp-idf!9303
2020-06-28 20:25:24 +08:00
Island 304c40f3ef Merge branch 'bugfix/ble_mesh_bt_hex_v4.0' into 'release/v4.0'
ble_mesh: Fix wrong log output with bt_hex (v4.0)

See merge request espressif/esp-idf!9310
2020-06-28 20:24:12 +08:00
Island ef136a664c Merge branch 'bugfix/ble_mesh_not_define_bool_v4.0' into 'release/v4.0'
Bugfix/ble mesh not define bool (v4.0)

See merge request espressif/esp-idf!9317
2020-06-28 20:23:03 +08:00
Chinmay Chhajed a9d4ed4a55 Bluedroid: Authentication fixes in Legacy and Secure Connection.
Prevent a remote device from doing a Bluetooth Impersonation Attack
(BIAS) by:

- Preventing remote device to downgrade secure connection
feature mask. Secure connection feature mask should remain same or
increase to enabled in link key generation and authentication.

- Doing a mutual authentication during Legacy Authentication.

Signed-off-by: Chinmay Chhajed <chinmay.chhajed@espressif.com>
2020-06-24 22:25:20 +05:30
lly 939a3b78e2 ble_mesh: Fix wrong log output with bt_hex
- This issue was introduced in the commit: a788e7cd3d
  which updated the bt_hex() function incorrectly.
- And in bt_hex(), we use 2 for the two-dimensional array, because currently
  at most two bt_hex() will be used at the same time. Also this will save
  some DRAM compared with using 4.
2020-06-24 10:33:58 +00:00
lly f1c0fee05b ble_mesh: Get node info with pre-configured node name
Also add a function to get the entry of the nodes table.

Closes https://github.com/espressif/esp-idf/issues/5397
2020-06-24 10:31:25 +00:00
lly 268b0e5e3f ble_mesh: Remove boolean type definitions 2020-06-24 09:12:31 +00:00
Nikolaos Strikos 940fcf0ca9 ble_mesh: Do not #define bool when compiling in C++ 2020-06-24 09:12:31 +00:00
lly c6ce7d2866 ble_mesh: stack: Check model status with variable length 2020-06-24 09:10:32 +00:00
wangcheng b869e69c62 components/bt: Consider link_xmit_data_q in congest events to prevent excessive memory usage 2020-06-18 15:02:02 +08:00
wangcheng 12759b951c components/bt: Fixed the problem of incomplete data packets caused by disordered acl data packets 2020-06-18 15:01:24 +08:00
Wang Cheng d875485f89 components/bt: Add a detailed description for the user to distinguish the function of the query buffer api. 2020-06-18 15:01:18 +08:00
Geng Yu Chao ac2e34f611 Update the limited of function esp_ble_get_sendable_packets_num. 2020-06-18 15:01:13 +08:00
wangcheng 211e7bb4c2 components/bt: Add api to query the number of available buffers for the current connection 2020-06-18 15:01:05 +08:00
wangcheng e781279110 blufi: When the format of the received data packet is wrong, reply with an error response 2020-06-17 12:20:53 +08:00
Island 9718338984 Merge branch 'bugfix/ble_mesh_remove_relay_dependency_v4.0' into 'release/v4.0'
ble_mesh: Remove relay option dependency (v4.0)

See merge request espressif/esp-idf!9027
2020-06-03 15:20:51 +08:00
Island 5a61c4c24c Merge branch 'bugfix/ble_mesh_example_nvs_store_v4.0' into 'release/v4.0'
Bugfix/ble mesh example nvs store (v4.0)

See merge request espressif/esp-idf!9017
2020-06-03 15:12:17 +08:00
Island ceffc0837e Merge branch 'bugfix/ble_mesh_model_recv_fix_v4.0' into 'release/v4.0'
Bugfix/ble mesh model recv fix (v4.0)

See merge request espressif/esp-idf!9008
2020-06-03 15:11:32 +08:00
Island ece24128da Merge branch 'bugfix/ble_mesh_rework_prov_pdu_len_check_v4.0' into 'release/v4.0'
ble_mesh: Rework prov pdu length check (v4.0)

See merge request espressif/esp-idf!9004
2020-06-03 15:10:52 +08:00
lly 19f69333f7 ble_mesh: Remove relay option dependency
When the relay functionality of a node is not enabled, this
issue will cause the node failing to send messages to fixed
group.
2020-06-02 19:18:52 +08:00
lly b55020ad80 ble_mesh: Config and health client btc fixes
Fix an issue which may cause no error code is returned
when sending config client or health client messages
with invalid parameters.
2020-06-02 14:04:35 +08:00
lly 1ac6d48fcf ble_mesh: Add more checks of net_idx & app_idx 2020-06-02 14:04:35 +08:00
lly 268f5ad6c6 ble_mesh: Optimize some send & recv logs 2020-06-02 14:04:34 +08:00
lly 205425b86b ble_mesh: correct the return type [Zephyr] 2020-06-02 10:32:25 +08:00
lly c2589b0b57 ble_mesh: Add net_buf_simple_init_with_data [Zephyr] 2020-06-02 10:32:24 +08:00
lly f990d725f4 ble_mesh: Optimize model recv operations [Zephyr]
Previously the model recv operation is a littl fuzzy.
With the changes, the model recv operation is splitted into:
- find op
- check app_idx
- check dst
- check length
- update info & handle message
2020-06-02 10:32:23 +08:00
lly 073b8daa6e ble_mesh: Rework prov pdu length check 2020-06-02 10:14:50 +08:00
lly cd40f3ad52 ble_mesh: Local model (un)subscribes group address 2020-06-01 09:11:27 +08:00
lly 11cfb44e58 ble_mesh: Define a macro for invalid company id 2020-06-01 09:11:26 +08:00
Jiang Jiang Jian 6b5c89b684 Merge branch 'bugfix/ble_mesh_check_timer_init_v4.0' into 'release/v4.0'
ble_mesh: Check the result of creating timer (v4.0)

See merge request espressif/esp-idf!8959
2020-05-28 15:27:21 +08:00
Jiang Jiang Jian a5ffd527ab Merge branch 'nimble/update_nimble_submodule_v4.0' into 'release/v4.0'
NimBLE: Include upstream fixes and use macros for log level filtering (backport v4.0)

See merge request espressif/esp-idf!8795
2020-05-28 15:24:45 +08:00
lly 792605e8fd ble_mesh: Check the result of creating timer 2020-05-28 10:27:25 +08:00
Island 59e11421bf Merge branch 'bugfix/ble_mesh_sync_zephyr_fixes_v4.0' into 'release/v4.0'
Bugfix/ble mesh sync zephyr fixes (v4.0)

See merge request espressif/esp-idf!8949
2020-05-28 10:16:52 +08:00
Island a90e8d67e9 Merge branch 'bugfix/ble_mesh_not_use_same_private_key_v4.0' into 'release/v4.0'
ble_mesh: Not using pre-initialized private key (v4.0)

See merge request espressif/esp-idf!8946
2020-05-28 10:14:45 +08:00
lly 63c83730c2 ble_mesh: Transport tx fields overflow [Zephyr]
The transport segmented TX nack and seg_pending fields must be at least
6 bits to avoid overflow for 32 segment messages. This change rearranges
the seg_tx fields to gather all state flag fields in one byte, while
making the counter fields whole bytes.
2020-05-27 17:45:55 +08:00
lly f781c6edac ble_mesh: Friend with unknown appkey [Zephyr]
Ensures that friend messages are enqueued, even if the packet is
received with an appkey is unknown to the friend. Previously, sdu_recv
would return EINVAL if the appkey was unknown, which would prevent the
lower transport layer from adding the packet to the friend queue. This
is irrelevant for the logic in lower transport, and should not be
returned as an error.
2020-05-27 17:45:49 +08:00
lly 7078065980 ble_mesh: Not using pre-initialized private key 2020-05-27 17:39:35 +08:00
lly a8afd951dc ble_mesh: Same func for storing/restoring comp data 2020-05-27 17:31:01 +08:00
lly 9d5ea68c61 ble_mesh: Fix using old config for duplicate scan 2020-05-25 16:54:03 +08:00
Island 57932baef3 Merge branch 'bugfix/ble_mesh_provisioner_fail_to_pub_v4.0' into 'release/v4.0'
ble_mesh: Fix Provisioner failed to publish (v4.0)

See merge request espressif/esp-idf!8874
2020-05-22 19:14:26 +08:00
Island 4c5fd2be70 Merge branch 'bugfix/ble_mesh_friend_init_flag_v4.0' into 'release/v4.0'
Bugfix/ble mesh friend init flag (v4.0)

See merge request espressif/esp-idf!8869
2020-05-22 19:13:42 +08:00
Island 7a60ae4bc8 Merge branch 'bugfix/ble_mesh_remove_patch_v4.0' into 'release/v4.0'
ble_mesh: Remove patch for the bug of an App (v4.0)

See merge request espressif/esp-idf!8868
2020-05-22 19:13:24 +08:00
lly 699270e09e ble_mesh: Fix Provisioner failed to publish 2020-05-22 15:48:49 +08:00
lly 13167a7579 ble_mesh: Clear two more vars during proxy server deinit 2020-05-22 11:39:51 +08:00
lly acf41f93a9 ble_mesh: Add missing sdkconfig.h 2020-05-22 11:39:51 +08:00
lly 470c959b04 ble_mesh: Init device name during proxy server init
Device name will be reset when deinit mesh stack. If not
initializing device name during the next mesh stack init,
it will fail to set the device name when using bluedroid.
2020-05-22 11:39:50 +08:00
lly dd7c98d6c2 ble_mesh: Add init flag for friend init/deinit
Since bt_mesh_friend_init() will only be invoked when
a device is provisioned or Provisioner is enabled, so
we add a flag to indicate if the friend functionality
is initialized in case deinit before initialization.
2020-05-22 11:39:49 +08:00
lly 90aa79fd2b ble_mesh: Remove patch for the bug of an App 2020-05-22 11:37:30 +08:00
lly 97c1a4b5c6 ble_mesh: Fix typos 2020-05-22 11:34:07 +08:00
Island 5897354d7f Merge branch 'bugfix/sync_zephyr_bt_mesh_bugfix_v4.0' into 'release/v4.0'
Bugfix/sync zephyr bt mesh bugfix (v4.0)

See merge request espressif/esp-idf!8853
2020-05-22 10:50:39 +08:00
lly d2bcb5c7ff ble_mesh: A specific fix for compile warning in idf4.0
Compared with the latest idf, idf4.0 defines BIT(nr) in
the "esp_bit_defs.h" without the pre-condition "#ifndef BIT",
which will cause compile warning when using mesh. So we
include the header file "soc/soc.h" in "mesh_util.h",
which can bypass the definition of "BIT" in "mesh_util.h"
when compiling.
2020-05-21 16:50:09 +08:00
lly 2ea69e6df5 ble_mesh: Fix mesh node device role restore
Old version of BLE Mesh has no device role storage, because
previously we only support storing mesh node info.
If the binary of the node is upgraded from old version to a
new version (support storing provisioner info), the mesh info
of the node will not be restored because mesh role does not
exist in the flash.
2020-05-21 15:26:50 +08:00
lly b5bd1bf67e ble_mesh: Fix not update prov addr in fast prov
When using fast provisioning, the Provisioner functionality
will be enabled. Unicast addresses within the pre-allocated
range will be used for provisioning nodes. And during the
address assignment, the allocated unicast address will be
checked that if it's duplicated with other nodes addresses
and the Provisioner's own addresses.
So before starting using fast provisioning, we need to update
the Provisioner address.
2020-05-21 15:22:21 +08:00
lly 8294055c65 ble_mesh: net_key_status only pull one key idx [Zephyr]
Fixes bug where the config client's net_key_status handler would attempt
to pull two key indexes from a message which only holds one.
2020-05-21 15:22:21 +08:00
lly 11286e35a2 ble_mesh: Update client message timeout calculation
Since the behavior of sending segmented messages has been
changed properly, the calculation of timeout value which
will be used when sending an acknowledged message by a
client model also needs to be updated.
2020-05-21 15:22:20 +08:00
lly 2c5b0a523a ble_mesh: Add lock for segmented msg operations
Add mutex to protect some variables of the mesh segmented
messages.
Currently the timeout handler of mesh will be executed in
the btc task, while the received mesh messages will be
handled in the btu task. In case some variables are set to
NULL when handled in the btu task, meanwhile these variables
are also accessed in the timeout handler, so we add mutex to
protect these variables and related operations.
2020-05-21 15:22:19 +08:00
lly 8c6f6318c0 ble_mesh: Fix dereferencing pointer before checking for NULL [Zephyr]
The publication context is checked for NULL in bt_mesh_model_publish()
however it was dereferenced before that. Move the assignment to
ctx.send_rel to the same place where other ctx members are set.
2020-05-21 15:22:18 +08:00
lly 632d9739b5 ble_mesh: Optimize some mesh log output 2020-05-21 15:22:18 +08:00
lly 34cb56b7aa ble_mesh: Fix restore when revoke keys [Zephyr]
Store keys (NetKey and AppKey) again after revoking.
2020-05-21 15:22:17 +08:00
lly 7c12074801 ble_mesh: Spit mesh_util.h into different header files
Split mesh_util.h into mesh_byteorder.h, mesh_compiler.h,
mesh_ffs.h and mesh_util.h based on the classification of
Zephyr, which will make further porting more clear.
2020-05-21 15:22:16 +08:00
lly 4b21a34675 ble_mesh: Split mesh os related into a separate file 2020-05-21 15:22:13 +08:00
lly ac51ec11ec ble_mesh: Split mesh mutex into a separate file 2020-05-21 15:19:52 +08:00
lly 7db10be193 ble_mesh: Rename mesh_kernel.* to mesh_timer.* 2020-05-21 15:19:51 +08:00
lly fde075aec2 ble_mesh: Add and use transport macro definitions [Zephyr] 2020-05-21 15:19:51 +08:00
lly cbd2bcfbd2 ble_mesh: Friend SeqAuth cleanup [Zephyr]
The Friend queue uses the message SeqAuth to determine whether the
message is already in the queue. To facilitate this, the SeqAuth is
passed around as a pointer throughout the transport modules. In the
bt_mesh_ctl_send functions, this parameter is also exposed in the API,
but the internal usage is inconsistent and buggy. Also, no one actually
uses this parameter.

- Removes seq_auth param from bt_mesh_ctl_send, instead passing NULL
  directly to the friend module, to enforce its addition to the queue.
- Makes the seq_auth pointer const throughout the friend module.
2020-05-21 15:19:50 +08:00
lly 5c5621790a ble_mesh: Rework msg_cache [Zephyr]
Changes the behavior of the message cache to optimize for cache
capacity. Previously, the message cache's primary function was to avoid
decrypting messages multiple times, although the cache's main function
in the spec is to avoid message rebroadcasting. Optimizing for minimal
decryption causes us to fill the network cache faster, which in turn
causes more cache misses, potentially outweighing the advantage.

Now stores src + seq in message cache instead of field hash value. This
cuts cache size in two, while including more of the sequence number than
before.

Adds messages to the cache only after the packet is successfully
decrypted. This reduces noise in the cache, and ensures that no
invalid deobfuscations are added.

Additionally, this fixes a bug where multiple calls to net_decrypt with
the same packet failed, as the message cache found its own entry from
the previous call.
2020-05-21 15:19:49 +08:00
lly fbdb7ff665 ble_mesh: Segmented TX to groups [Zephyr]
Implements several changes to the transport layer segmented tx to
improve group message performance:
- Moves retransmit counter to tx context instead of per packet. As every
  unacked packet is sent every retransmit, the retransmit counters would
  be the same in each segment. This makes it easier to control progress.
- Delays the scheduling of the retransmit until the completion of the
  last segment by adding a seg_pending counter. This is essentially the
  same as the old behavior, except that the old behavior might retrigger
  the sending before all segments are finished if the advertising is
  slow.
- Allows the group transmits to stop as soon as all retransmits have
  been exhausted, instead of timing out waiting for acks that won't
  come. This allows group tx to finish without error.
- Fixes a bug where a failed TX would block IV update.
- Cancels any pending transmissions of acked segments.
- Reduces log level for several common group tx scenarios that aren't
  erronous.
2020-05-21 15:19:49 +08:00
lly bbfaaa2044 ble_mesh: Add comment explaining use of byte order [Zephyr]
Add comment that explains why a different byte order is used for the
3-byte opcode on the CID part of the opcode.
2020-05-21 15:19:48 +08:00
lly ad14507e3f ble_mesh: Use 24-bit functions [Zephyr]
Use 24-bit functions for byteorder and net_buf in order to make the
byteorder used more readable.
2020-05-21 15:19:47 +08:00
lly c9d1255ce4 ble_mesh: Optimize net_buf_simple routines [Zephyr]
Use sys_put_xyz() helpers instead of memcpy() whenever possible. This
brings in straight-line inline code for pushes and adds of known,
small sizes.
2020-05-21 15:19:46 +08:00
lly 25569cd9de ble_mesh: Add PRIu64 & PRIx64 in mesh_types.h 2020-05-21 15:19:46 +08:00
lly 416e8958fa ble_mesh: Add push functions for supported bit-variants [Zephyr]
Add push functions for bit-widths supported by add and pull functions.
2020-05-21 15:19:45 +08:00
lly cde1592bf3 ble_mesh: Add support for 64 bit data type [Zephyr]
This enables pulling and pushing values in 64 bit format.
2020-05-21 15:19:44 +08:00
lly 0af05fdee1 ble_mesh: Add support for 48 bit data type [Zephyr]
This enables pulling and pushing values in 48 bit format.
2020-05-21 15:19:44 +08:00
lly 4536a485be ble_mesh: Add 48 bit variants [Zephyr]
This adds sys_*_*48 functions that operation on a 48 bits values.
2020-05-21 15:19:43 +08:00
lly e7d37f2d1a ble_mesh: Add support for 24 bit data type [Zephyr]
This enables pulling and pushing values in 24 bit format.
2020-05-21 15:19:42 +08:00
lly fd17ff2f0b ble_mesh: Add 24 bit variants [Zephyr]
This adds sys_*_*24 functions that operation on a 24 bits values.
2020-05-21 15:19:41 +08:00
lly e322c5950b ble_mesh: Group resends in proxy nodes [Zephyr]
Resend transport segments for groups on the advertiser interface, even
if a connected proxy node holds the group.
2020-05-21 15:19:41 +08:00
lly 1f96a6f35d ble_mesh: Typo in condition in comp_add_elem of cfg_srv [Zephyr]
Vendor model IDs take up four (not two) bytes in the composition
2020-05-21 15:19:40 +08:00
lly 4fddf1156b ble_mesh: GATT Proxy Spec 1.0.1 changes [Zephyr]
Backport of https://github.com/apache/mynewt-nimble/pull/724

Mesh spec 1.0.1 changes proxy disabling behavior to only affect the
relaying from proxy nodes. Previously, disabling proxy would shut down
all proxy and node activity.

Tweaks from the original commit:
- Removed redundant call to bt_mesh_adv_update() in gatt_proxy_set()
- Removed invalid ref to 4.2.11.1 in node_identity_set()

---

According to Mesh Profile Spec 1.0.1, Section 4.2.11:
"If the Proxy feature is disabled, a GATT client device can connect
over GATT to that node for configuration and control. Messages from
the GATT bearer are not relayed to the advertising bearer."

Moreover some notes have been removed from the spec compared to
version 1.0:

Mesh Profile Spec 1.0, Section 4.2.11:

"Upon transition from GATT Proxy state 0x01 to GATT Proxy state 0x00
the GATT Bearer Server shall disconnect all GATT Bearer Clients."

"The Configuration Client should turn off the Proxy state as the last
step in the configuration process."

Mesh Profile Spec 1.0, Section 4.2.11.1:

"When the GATT Proxy state is set to 0x00, the Node Identity state
for all subnets shall be set to 0x00 and shall not be changed."
2020-05-21 15:19:39 +08:00
lly 833483bb22 ble_mesh: Support reliable sending when publishing [Zephyr]
Until now the choice of reliable sending (segmented messages with
acks) was implicitly dependent on the size of the payload. Add a new
member to the bt_mesh_model_pub to force using segment acks even when
the payload would fit a single unsegmented message.
2020-05-21 15:19:39 +08:00