@@ -106,10 +106,7 @@ AdafruitBluefruit::AdafruitBluefruit(void)
106
106
_chars_count = 0 ;
107
107
for (uint8_t i=0 ; i<BLE_MAX_CHARS; i++) _chars_list[i] = NULL ;
108
108
109
- varclr (&_bond);
110
-
111
- _sys_attr = NULL ;
112
- _sys_attr_len = 0 ;
109
+ varclr (&_bond_data);
113
110
114
111
_connect_cb = NULL ;
115
112
_discconnect_cb = NULL ;
@@ -481,6 +478,11 @@ uint16_t AdafruitBluefruit::connHandle(void)
481
478
return _conn_hdl;
482
479
}
483
480
481
+ bool AdafruitBluefruit::connBonded (void )
482
+ {
483
+ return _bonded;
484
+ }
485
+
484
486
ble_gap_addr_t AdafruitBluefruit::peerAddr (void )
485
487
{
486
488
return _peer_addr;
@@ -495,18 +497,17 @@ err_t AdafruitBluefruit::saveAllCCCD(void)
495
497
{
496
498
uint16_t len=0 ;
497
499
sd_ble_gatts_sys_attr_get (_conn_hdl, NULL , &len, SVC_CONTEXT_FLAG);
498
- // PRINT_INT(len);
499
500
500
501
// Free and re-malloc if not enough
501
- if ( _sys_attr_len < len )
502
+ if ( _bond_data. sys_attr_len < len )
502
503
{
503
- if (_sys_attr ) rtos_free (_sys_attr );
504
+ if (_bond_data. sys_attr ) rtos_free (_bond_data. sys_attr );
504
505
505
- _sys_attr = (uint8_t *) rtos_malloc ( len );
506
- _sys_attr_len = len;
506
+ _bond_data. sys_attr = (uint8_t *) rtos_malloc ( len );
507
+ _bond_data. sys_attr_len = len;
507
508
}
508
509
509
- return sd_ble_gatts_sys_attr_get (_conn_hdl, _sys_attr , &_sys_attr_len , SVC_CONTEXT_FLAG);
510
+ return sd_ble_gatts_sys_attr_get (_conn_hdl, _bond_data. sys_attr , &_bond_data. sys_attr_len , SVC_CONTEXT_FLAG);
510
511
}
511
512
512
513
/* ------------------------------------------------------------------*/
@@ -619,6 +620,8 @@ void AdafruitBluefruit::_poll(void)
619
620
_conn_hdl = evt->evt .gap_evt .conn_handle ;
620
621
_peer_addr = para->peer_addr ;
621
622
623
+ PRINT_HEX (_conn_hdl);
624
+
622
625
uint8_t txbuf_max;
623
626
(void ) sd_ble_tx_packet_count_get (_conn_hdl, &txbuf_max);
624
627
_txbuf_sem = xSemaphoreCreateCounting (txbuf_max, txbuf_max);
@@ -695,15 +698,15 @@ void AdafruitBluefruit::_poll(void)
695
698
ble_gap_sec_keyset_t keyset =
696
699
{
697
700
.keys_own = {
698
- .p_enc_key = &_bond .own_enc ,
701
+ .p_enc_key = &_bond_data .own_enc ,
699
702
.p_id_key = NULL ,
700
703
.p_sign_key = NULL ,
701
704
.p_pk = NULL
702
705
},
703
706
704
707
.keys_peer = {
705
- .p_enc_key = &_bond .peer_enc ,
706
- .p_id_key = &_bond .peer_id ,
708
+ .p_enc_key = &_bond_data .peer_enc ,
709
+ .p_id_key = &_bond_data .peer_id ,
707
710
.p_sign_key = NULL ,
708
711
.p_pk = NULL
709
712
}
@@ -720,10 +723,11 @@ void AdafruitBluefruit::_poll(void)
720
723
ble_gap_evt_sec_info_request_t * sec_request = (ble_gap_evt_sec_info_request_t *) &evt->evt .gap_evt .params .sec_info_request ;
721
724
722
725
PRINT_HEX (sec_request->master_id .ediv );
723
- if (_bond.own_enc .master_id .ediv == sec_request->master_id .ediv )
726
+ // EDIV_INIT_VAL
727
+ if (_bond_data.own_enc .master_id .ediv == sec_request->master_id .ediv )
724
728
{
725
729
PRINT_LOCATION ();
726
- sd_ble_gap_sec_info_reply (evt->evt .gap_evt .conn_handle , &_bond .own_enc .enc_info , &_bond .peer_id .id_info , NULL );
730
+ sd_ble_gap_sec_info_reply (evt->evt .gap_evt .conn_handle , &_bond_data .own_enc .enc_info , &_bond_data .peer_id .id_info , NULL );
727
731
} else
728
732
{
729
733
PRINT_LOCATION ();
@@ -745,7 +749,7 @@ void AdafruitBluefruit::_poll(void)
745
749
_bonded = true ;
746
750
747
751
// Connection is secured, Apply Service Context
748
- sd_ble_gatts_sys_attr_set (_conn_hdl, _sys_attr, _sys_attr_len , SVC_CONTEXT_FLAG);
752
+ sd_ble_gatts_sys_attr_set (_conn_hdl, _bond_data. sys_attr , _bond_data. sys_attr_len , SVC_CONTEXT_FLAG);
749
753
}
750
754
break ;
751
755
@@ -762,11 +766,12 @@ void AdafruitBluefruit::_poll(void)
762
766
break ;
763
767
764
768
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
765
- sd_ble_gatts_sys_attr_set (_conn_hdl, NULL , 0 , 0 );
769
+ // TODO Look up bonded information and apply application context
770
+ // sd_ble_gatts_sys_attr_set(_conn_hdl, NULL, 0, 0);
766
771
break ;
767
772
768
- // Save CCCD when enabled/disabled if bonded
769
773
case BLE_GATTS_EVT_WRITE:
774
+ // Auto Save when CCCD is enabled/disabled if bonded
770
775
if ( _bonded )
771
776
{
772
777
ble_gatts_evt_write_t * write = &evt->evt .gatts_evt .params .write ;
0 commit comments