Skip to content

Commit e53bbf9

Browse files
committed
Update core to esp-nimble commit 95bd864.
1 parent d8a535d commit e53bbf9

File tree

6 files changed

+94
-22
lines changed

6 files changed

+94
-22
lines changed

README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# NimBLE-Arduino
22
A fork of the NimBLE stack restructured for compilation in the Ardruino IDE with a CPP library for use with ESP32.
33

4-
**Note for IDF users: An ESP-IDF component version of this library can be [found here](https://github.com/h2zero/esp-nimble-cpp), this will not compile correctly in ESP-IDF**.
4+
**Note for IDF users: This repo will not compile correctly in ESP-IDF. An ESP-IDF component version of this library can be [found here.](https://github.com/h2zero/esp-nimble-cpp)**
55

66
This library **significantly** reduces resource usage and improves performance for ESP32 BLE applications as compared
77
with the bluedroid based library. The goal is to maintain, as much as reasonable, compatibility with the original
@@ -53,10 +53,25 @@ More advanced examples highlighting many available features are in examples/ Nim
5353
Beacon examples provided by @beegee-tokyo are in examples/ BLE_Beacon_Scanner, BLE_EddystoneTLM_Beacon, BLE_EddystoneURL_Beacon.
5454

5555
Change the settings in the `nimconfig.h` file to customize NimBLE to your project, such as increasing max connections, default is 3.
56+
57+
**Note To increase max connections in Arduino it is also required to change the controller max connections defined in sdkconfig.h.**
58+
59+
This is located in your Arduino/hardware/espressif/esp32/tools/sdk/include/config folder.
60+
61+
The values in `sdkconfig.h` you will need to change are:
62+
```
63+
#define CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN 3
64+
#define CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF 3
65+
```
66+
In `nimconfig.h` the value is:
67+
```
68+
#define CONFIG_BT_NIMBLE_MAX_CONNECTIONS 3
69+
```
70+
Espressif has stated the hard maximum connections is 9.
5671
<br/>
5772

5873
# Continuing development
59-
This Library is tracking the esp-nimble repo, nimble-1.2.0-idf master branch, currently [@46c1d9f.](https://github.com/espressif/esp-nimble)
74+
This Library is tracking the esp-nimble repo, nimble-1.2.0-idf master branch, currently [@95bd864.](https://github.com/espressif/esp-nimble)
6075

6176
Also tracking the NimBLE related changes in ESP-IDF, master branch, currently [@2ef4890.](https://github.com/espressif/esp-idf/tree/master/components/bt/host/nimble)
6277
<br/>
@@ -68,9 +83,7 @@ Also tracking the NimBLE related changes in ESP-IDF, master branch, currently [@
6883
<br/>
6984

7085
# Todo
71-
1. Implement random addresses.
72-
2. Implement NimBLEServer::removeService
73-
3. Implement extra fields in NimBLEAdvertisedDevice.
74-
4. Document nimconfig.
75-
5. Add BLE Mesh code.
86+
1. Document nimconfig.
87+
2. Examples.
88+
3. Improve documentation.
7689
<br/>

docs/index.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,29 @@ See: [Breaking API Changes vs Original](docs/BREAKING_API_CHANGES.md) for detail
4848

4949
Also see [Improvements_and_updates](docs/Improvements_and_updates.md) for information about non-breaking changes.
5050

51-
### Arduino
52-
    See the Refactored_original_examples in the examples folder for highlights of the differences with the original library.
51+
### Arduino specific:
52+
See the Refactored_original_examples in the examples folder for highlights of the differences with the original library.
5353

54-
    More advanced examples highlighting many available features are in examples/NimBLE_Server, NimBLE_Client.
54+
More advanced examples highlighting many available features are in examples/NimBLE_Server, NimBLE_Client.
5555

56-
    Beacon examples provided by [beegee-tokyo](https://github.com/beegee-tokyo) are in examples/BLE_Beacon_Scanner, BLE_EddystoneTLM_Beacon, BLE_EddystoneURL_Beacon.
56+
Beacon examples provided by [beegee-tokyo](https://github.com/beegee-tokyo) are in examples/BLE_Beacon_Scanner, BLE_EddystoneTLM_Beacon, BLE_EddystoneURL_Beacon.
5757

58-
    Change the settings in the nimconfig.h file to customize NimBLE to your project, such as increasing max connections (default == 3).
58+
Change the settings in the nimconfig.h file to customize NimBLE to your project, such as increasing max connections (default == 3).
59+
60+
**Note To increase max connections in Arduino it is also required to change the controller max connections defined in sdkconfig.h.**
61+
62+
This is located in your Arduino/hardware/espressif/esp32/tools/sdk/include/config folder.
63+
64+
The values in `sdkconfig.h` you will need to change are:
65+
```
66+
#define CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN 3
67+
#define CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF 3
68+
```
69+
In `nimconfig.h` the value is:
70+
```
71+
#define CONFIG_BT_NIMBLE_MAX_CONNECTIONS 3
72+
```
73+
Espressif has stated the hard maximum connections is 9.
5974
<br/>
6075

6176
# Acknowledgments

src/nimble/host/mesh/src/src/ble_hs_resolv_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct ble_hs_peer_sec {
5353
*/
5454
struct ble_hs_dev_records {
5555
bool rec_used;
56+
uint8_t rand_addr_type;
5657
uint8_t pseudo_addr[BLE_DEV_ADDR_LEN];
5758
uint8_t rand_addr[BLE_DEV_ADDR_LEN];
5859
uint8_t identity_addr[BLE_DEV_ADDR_LEN];

src/nimble/host/src/ble_hs_resolv.c

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,44 @@ is_rpa_resolvable_by_peer_rec(struct ble_hs_dev_records *p_dev_rec, uint8_t *pee
181181
return false;
182182
}
183183

184+
static void
185+
ble_rpa_replace_id_with_rand_addr(uint8_t *addr_type, uint8_t *peer_addr)
186+
{
187+
struct ble_hs_dev_records *p_dev_rec;
188+
ble_addr_t p_addr = {0};
189+
struct ble_hs_conn *conn = NULL;
190+
191+
p_dev_rec = ble_rpa_find_peer_dev_rec(peer_addr);
192+
193+
if (p_dev_rec != NULL) {
194+
if (memcmp(p_dev_rec->rand_addr, p_dev_rec->identity_addr, BLE_DEV_ADDR_LEN)) {
195+
/* OTA address (before resolving) gets saved in RAND_ADDR when the peer
196+
* record is fetched from resolving list. Replace peer address
197+
* with rand_addr to maintain status quo for new pairing/encryption request. */
198+
p_addr.type = *addr_type;
199+
memcpy(&p_addr.val[0], peer_addr, BLE_DEV_ADDR_LEN);
200+
201+
ble_hs_lock();
202+
203+
conn = ble_hs_conn_find_by_addr(&p_addr);
204+
/* Rewrite the peer address history in ble_hs_conn. Need to take
205+
* this step to avoid taking wrong address during re-pairing
206+
* process */
207+
if (conn != NULL) {
208+
conn->bhc_peer_rpa_addr.type = p_dev_rec->rand_addr_type;
209+
memcpy(&conn->bhc_peer_rpa_addr.val[0], p_dev_rec->rand_addr, BLE_DEV_ADDR_LEN);
210+
conn->bhc_peer_addr.type = p_dev_rec->rand_addr_type;
211+
memcpy(&conn->bhc_peer_addr.val[0], p_dev_rec->rand_addr, BLE_DEV_ADDR_LEN);
212+
BLE_HS_LOG(DEBUG, "\n Replace Identity addr with random addr received at"
213+
" start of the connection\n");
214+
}
215+
216+
ble_hs_unlock();
217+
}
218+
}
219+
return;
220+
}
221+
184222
/* Add peer to peer device records.
185223
*
186224
* @return 0 if added successfully,
@@ -227,6 +265,7 @@ ble_rpa_find_rl_from_peer_records(uint8_t *peer_addr, uint8_t *peer_addr_type)
227265

228266
if (is_rpa_resolvable_by_peer_rec(p_dev_rec, peer_addr)) {
229267
memcpy(p_dev_rec->rand_addr, peer_addr, BLE_DEV_ADDR_LEN);
268+
p_dev_rec->rand_addr_type = *peer_addr_type;
230269
rl = ble_hs_resolv_list_find(p_dev_rec->identity_addr);
231270
if (rl) {
232271
memcpy(peer_addr, p_dev_rec->identity_addr, BLE_DEV_ADDR_LEN);
@@ -277,13 +316,10 @@ ble_rpa_replace_peer_params_with_rl(uint8_t *peer_addr, uint8_t *addr_type,
277316

278317
if (is_rpa) {
279318
ble_hs_log_flat_buf(peer_addr, BLE_DEV_ADDR_LEN);
280-
rl_tmp = ble_hs_resolv_list_find(peer_addr);
319+
BLE_HS_LOG(DEBUG, "\n");
281320

282-
/* Try to find from your peer_device records, if RL doesn't
283-
* exist */
284-
if (rl_tmp == NULL) {
285-
rl_tmp = ble_rpa_find_rl_from_peer_records(peer_addr, addr_type);
286-
}
321+
/* Try to find RL from your peer_device records */
322+
rl_tmp = ble_rpa_find_rl_from_peer_records(peer_addr, addr_type);
287323
}
288324

289325
if (rl != NULL) {
@@ -571,7 +607,7 @@ ble_hs_resolv_list_add(uint8_t *cmdbuf)
571607
int
572608
ble_hs_resolv_list_rmv(uint8_t addr_type, uint8_t *ident_addr)
573609
{
574-
int position;
610+
int position, rc = BLE_HS_ENOENT;
575611

576612
/* Remove from IRK records */
577613
position = ble_hs_is_on_resolv_list(ident_addr, addr_type);
@@ -583,10 +619,15 @@ ble_hs_resolv_list_rmv(uint8_t addr_type, uint8_t *ident_addr)
583619
ble_hs_resolv_entry));
584620
--g_ble_hs_resolv_data.rl_cnt;
585621

586-
return 0;
622+
rc = 0;
587623
}
588624

589-
return BLE_HS_ENOENT;
625+
/* As we are removing the RL record, it is needed to change
626+
* peer_address to its latest received OTA address, this helps when existing bond at
627+
* peer side is removed */
628+
ble_rpa_replace_id_with_rand_addr(&addr_type, ident_addr);
629+
630+
return rc;
590631
}
591632

592633
/**

src/nimble/host/src/ble_hs_resolv_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct ble_hs_peer_sec {
5353
*/
5454
struct ble_hs_dev_records {
5555
bool rec_used;
56+
uint8_t rand_addr_type;
5657
uint8_t pseudo_addr[BLE_DEV_ADDR_LEN];
5758
uint8_t rand_addr[BLE_DEV_ADDR_LEN];
5859
uint8_t identity_addr[BLE_DEV_ADDR_LEN];

src/porting/nimble/src/os_mempool.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ os_mempool_info_get_next(struct os_mempool *mp, struct os_mempool_info *omi)
346346
omi->omi_num_blocks = cur->mp_num_blocks;
347347
omi->omi_num_free = cur->mp_num_free;
348348
omi->omi_min_free = cur->mp_min_free;
349-
strncpy(omi->omi_name, cur->name, sizeof(omi->omi_name));
349+
strncpy(omi->omi_name, cur->name, sizeof(omi->omi_name) - 1);
350+
omi->omi_name[sizeof(omi->omi_name) - 1] = '\0';
350351

351352
return (cur);
352353
}

0 commit comments

Comments
 (0)