@@ -51,6 +51,9 @@ static EventGroupHandle_t _spp_event_group = NULL;
51
51
static boolean secondConnectionAttempt;
52
52
static esp_spp_cb_t * custom_spp_callback = NULL ;
53
53
static BluetoothSerialDataCb custom_data_callback = NULL ;
54
+ static esp_bd_addr_t current_bd_addr;
55
+ static ConfirmRequestCb confirm_request_callback = NULL ;
56
+ static AuthCompleteCb auth_complete_callback = NULL ;
54
57
55
58
#define INQ_LEN 0x10
56
59
#define INQ_NUM_RSPS 20
@@ -398,8 +401,14 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
398
401
case ESP_BT_GAP_AUTH_CMPL_EVT:
399
402
if (param->auth_cmpl .stat == ESP_BT_STATUS_SUCCESS) {
400
403
log_v (" authentication success: %s" , param->auth_cmpl .device_name );
404
+ if (auth_complete_callback) {
405
+ auth_complete_callback (true );
406
+ }
401
407
} else {
402
408
log_e (" authentication failed, status:%d" , param->auth_cmpl .stat );
409
+ if (auth_complete_callback) {
410
+ auth_complete_callback (false );
411
+ }
403
412
}
404
413
break ;
405
414
@@ -421,7 +430,13 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
421
430
422
431
case ESP_BT_GAP_CFM_REQ_EVT:
423
432
log_i (" ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d" , param->cfm_req .num_val );
424
- esp_bt_gap_ssp_confirm_reply (param->cfm_req .bda , true );
433
+ if (confirm_request_callback) {
434
+ memcpy (current_bd_addr, param->cfm_req .bda , sizeof (esp_bd_addr_t ));
435
+ confirm_request_callback (param->cfm_req .num_val );
436
+ }
437
+ else {
438
+ esp_bt_gap_ssp_confirm_reply (param->cfm_req .bda , true );
439
+ }
425
440
break ;
426
441
427
442
case ESP_BT_GAP_KEY_NOTIF_EVT:
@@ -500,7 +515,9 @@ static bool _init_bt(const char *deviceName)
500
515
}
501
516
}
502
517
503
- if (_isMaster && esp_bt_gap_register_callback (esp_bt_gap_cb) != ESP_OK) {
518
+ // Why only master need this? Slave need this during pairing as well
519
+ // if (_isMaster && esp_bt_gap_register_callback(esp_bt_gap_cb) != ESP_OK) {
520
+ if (esp_bt_gap_register_callback (esp_bt_gap_cb) != ESP_OK) {
504
521
log_e (" gap register failed" );
505
522
return false ;
506
523
}
@@ -672,6 +689,22 @@ void BluetoothSerial::end()
672
689
_stop_bt ();
673
690
}
674
691
692
+ void BluetoothSerial::onConfirmRequest (ConfirmRequestCb cb)
693
+ {
694
+ confirm_request_callback = cb;
695
+ }
696
+
697
+ void BluetoothSerial::onAuthComplete (AuthCompleteCb cb)
698
+ {
699
+ auth_complete_callback = cb;
700
+ }
701
+
702
+ void BluetoothSerial::confirmReply (boolean confirm)
703
+ {
704
+ esp_bt_gap_ssp_confirm_reply (current_bd_addr, confirm);
705
+ }
706
+
707
+
675
708
esp_err_t BluetoothSerial::register_callback (esp_spp_cb_t * callback)
676
709
{
677
710
custom_spp_callback = callback;
0 commit comments