Skip to content

Commit 5c73ce7

Browse files
committed
small changes from the esp-arduino library
1 parent 1c32e6a commit 5c73ce7

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

docs/todo

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
- Update connection parameter wieder hinzufügen (bleprh anschauen)
2+
- Update connection parameters are not allowed during iPhone HID encryption, slave turns off the ability to automatically update connection parameters during encryption.
23
- Bei einem erneuten verbindungsaufbau wird das gestoppte updaten der daten nicht wieder gestartet
3-
- IOS kann den bond nicht wiederherstellen, wenn ESP neugestartet wird (muss neu hinzugefügt werden)
4-
- Android kann schon beim enkoppeln und erneuten koppeln nicht mehr bonden ohne nachfrage
5-
- Linux geht immer
4+
65
- Code cleanup
76
- Kommentare von main nehmen und in diesen branch hinzufügen
87
- Mergen in main
98

109

11-
Update connection parameters are not allowed during iPhone HID encryption, slave turns off the ability to automatically update connection parameters during encryption.
1210

13-
https://github.com/espressif/esp-idf/issues/3532
11+
12+
13+
Kann ich nicht ändern --> wie https://github.com/h2zero/NimBLE-Arduino/blob/release/1.4/src/NimBLEDevice.cpp alles gemacht:
14+
- IOS kann den bond nicht wiederherstellen, wenn ESP neugestartet wird (muss neu hinzugefügt werden)
15+
- Android kann schon beim enkoppeln und erneuten koppeln nicht mehr bonden ohne nachfrage
16+
- Linux geht immer

main/main.c

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,20 @@ blehr_gap_event(struct ble_gap_event *event, void *arg)
207207
if (event->connect.status != 0) {
208208
/* Connection failed; resume advertising */
209209
blehr_advertise();
210+
} else {
211+
struct ble_gap_upd_params connectionParameters = {
212+
//itvl: These determine how often the devices will "ping-pong" each other and also when they will send any data required. So if you set the value to something like 20, that would mean packets are sent every 25ms, which will obviously consume more power than say a value of 80 (100ms). The reason for the min max values is so the devices can negotiate a compromise for the best possible communication, you can set these to the same value if you prefer.
213+
.itvl_min = (int)(11.25/1.25), //1.25ms units; laut apple 11.25 minimum fuer hid
214+
.itvl_max = (int)(20/1.25), //minimum ist laut apple eigentlich 15ms deswegen etwas höher setzen
215+
//latency: This is how many "ping-pong" (connection interval) events the slave(server) device is allowed to skip without the client device considering the connection terminated. So if you had a 25ms connection interval and you wanted to sleep for 1 second you could set this value to 40 and the client would consider the connection active for up to 40 skipped intervals.
216+
.latency = 30, //up to 30 connection intervals
217+
//timeout: This is the absolute (disconnection) timeout, if no packets are received by either device within this time the connection is considered terminated.
218+
.supervision_timeout = 1860/10 //10ms units, laut apple größer als itvl_max * (latency + 1) * 3
219+
};
220+
221+
//ESP_ERROR_CHECK(ble_gap_update_params(event->connect.conn_handle, &connectionParameters));
210222
}
211223

212-
struct ble_gap_upd_params connectionParameters = {
213-
//itvl: These determine how often the devices will "ping-pong" each other and also when they will send any data required. So if you set the value to something like 20, that would mean packets are sent every 25ms, which will obviously consume more power than say a value of 80 (100ms). The reason for the min max values is so the devices can negotiate a compromise for the best possible communication, you can set these to the same value if you prefer.
214-
.itvl_min = (int)(11.25/1.25), //1.25ms units; laut apple 11.25 minimum fuer hid
215-
.itvl_max = (int)(20/1.25), //minimum ist laut apple eigentlich 15ms deswegen etwas höher setzen
216-
//latency: This is how many "ping-pong" (connection interval) events the slave(server) device is allowed to skip without the client device considering the connection terminated. So if you had a 25ms connection interval and you wanted to sleep for 1 second you could set this value to 40 and the client would consider the connection active for up to 40 skipped intervals.
217-
.latency = 30, //up to 30 connection intervals
218-
//timeout: This is the absolute (disconnection) timeout, if no packets are received by either device within this time the connection is considered terminated.
219-
.supervision_timeout = 1860/10 //10ms units, laut apple größer als itvl_max * (latency + 1) * 3
220-
};
221-
222-
//ESP_ERROR_CHECK(ble_gap_update_params(event->connect.conn_handle, &connectionParameters));
223-
224-
conn_handle = event->connect.conn_handle;
225-
ble_gap_security_initiate(conn_handle);
226224
break;
227225

228226
case BLE_GAP_EVENT_DISCONNECT:
@@ -240,6 +238,17 @@ blehr_gap_event(struct ble_gap_event *event, void *arg)
240238

241239
case BLE_GAP_EVENT_SUBSCRIBE:
242240
ESP_LOGI("ASDF", "subscribe event; cur_notify=%d\n value handle; val_handle=%d\n", event->subscribe.cur_notify, report_data_handle);
241+
242+
rc = ble_gap_conn_find(event->subscribe.conn_handle, &desc);
243+
if (rc != 0) {
244+
break;
245+
}
246+
247+
//muss eigentlich nur gemacht werden bei den attr_handle wo es auf encrypted nur gelesen wird --> input report
248+
if(!desc.sec_state.encrypted) {
249+
ble_gap_security_initiate(event->subscribe.conn_handle);
250+
}
251+
243252
if (event->subscribe.attr_handle == report_data_handle) {
244253
notify_state = event->subscribe.cur_notify;
245254
blehr_tx_hrate_reset();
@@ -345,10 +354,10 @@ blehr_on_sync(void)
345354
ble_hs_pvcy_rpa_config(1);
346355

347356
/* Make sure we have proper identity address set (public preferred) */
348-
//rc = ble_hs_util_ensure_addr(1);
357+
rc = ble_hs_util_ensure_addr(0);
349358

350359

351-
rc = ble_hs_id_infer_auto(0, &blehr_addr_type);
360+
rc = ble_hs_id_infer_auto(blehr_addr_type, &blehr_addr_type);
352361
assert(rc == 0);
353362

354363
uint8_t addr_val[6] = {0};
@@ -358,6 +367,8 @@ blehr_on_sync(void)
358367
print_addr(addr_val);
359368
ESP_LOGI("ASDF", "\n");
360369

370+
taskYIELD();
371+
361372
/* Begin advertising */
362373
blehr_advertise();
363374
}
@@ -415,8 +426,10 @@ void app_main(void)
415426
//BLE_SM_IO_CAP_NO_IO = just work
416427
//BLE_SM_IO_CAP_KEYBOARD_DISP = Keyboard and display
417428
ble_hs_cfg.sm_io_cap = BLE_SM_IO_CAP_NO_IO;
429+
//perform secure connection pairing, false we will use legacy pairing.
418430
ble_hs_cfg.sm_sc = 1;
419431
ble_hs_cfg.sm_bonding = 1;
432+
//man in the middle protection
420433
ble_hs_cfg.sm_mitm = 1;
421434
ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID;
422435
/* Refer components/nimble/nimble/nimble/host/include/host/ble_sm.h for

0 commit comments

Comments
 (0)