This commit is contained in:
hathach committed 2017-07-22 00:09:08 +07:00
1 parent 161e4d4de8
commit 25df80d805
4 files changed
+35 -20

No files matched your search

+1
View File
@@ -27,6 +27,7 @@
- Separated `BLEAdvertisingData` and `BLEAdvertising`
- Added `setStopCallback()` support to declare a callback when advertising stops
- Add the option to advertise for a specific time. There are multiple timeouts: initial fast advertising mode, slow advertising mode, and an optional delay to stop advertising entirely. Values can be set in multiple of timeout ticks (0.625ms per unit) or in ms (approximate since it gets converted to 0.625ms units). The optional timeout to stop advertising entire is set via the `.start(timeout)` parameter.
- Blue LED will blink 2x in fast mode than slow mode.
- Default timeout to slow mode = 30 seconds. Default adv intervals are fast mode = 20 ms, slow = 152.5 ms
- Add new example `advance_adv`
+26 -3
View File
@@ -630,7 +630,6 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
// return security information. Otherwise NULL
ble_gap_evt_sec_info_request_t* sec_request = (ble_gap_evt_sec_info_request_t*) &evt->evt.gap_evt.params.sec_info_request;
//if (_bond_data.own_enc.master_id.ediv == sec_request->master_id.ediv)
if ( _loadBondKeys(sec_request->master_id.ediv) )
{
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);
@@ -769,6 +768,7 @@ bool AdafruitBluefruit::_saveBondKeys(void)
sprintf(filename, BOND_FILENAME, _bond_data.own_enc.master_id.ediv);
VERIFY( Nffs.writeFile(filename, &_bond_data, sizeof(_bond_data)) );
LOG_LV1(BOND, "Keys is saved to Nffs");
printBondDir();
@@ -780,10 +780,14 @@ bool AdafruitBluefruit::_loadBondKeys(uint16_t ediv)
char filename[BOND_FILENAME_LEN];
sprintf(filename, BOND_FILENAME, ediv);
bool result = Nffs.readFile(filename, &_bond_data, sizeof(_bond_data)) > 0;
bool result = (Nffs.readFile(filename, &_bond_data, sizeof(_bond_data)) > 0);
if ( result ) {
if ( result )
{
LOG_LV1(BOND, "Load Keys from %s", filename);
}else
{
LOG_LV1(BOND, "Keys not found");
}
return result;
@@ -813,6 +817,9 @@ void AdafruitBluefruit::_loadBondedCCCD(uint16_t ediv)
loaded = true;
LOG_LV1(BOND, "Load CCCD from %s", filename);
}else
{
LOG_LV1(BOND, "CCCD setting not found");
}
}
@@ -845,9 +852,25 @@ void AdafruitBluefruit::_saveBondedCCCD(void)
sprintf(filename, BOND_FILENAME "_cccd", _bond_data.own_enc.master_id.ediv);
Nffs.writeFile(filename, sys_attr, len);
LOG_LV1(BOND, "CCCD setting is saved to Nffs");
}
printBondDir();
rtos_free(sys_attr);
}
void AdafruitBluefruit::_bledfu_get_bond_data(ble_gap_addr_t* addr, ble_gap_irk_t* irk, ble_gap_enc_key_t* enc_key)
{
if (!_bonded)
{
(*addr) = getPeerAddr();
}else
{
(*addr) = _bond_data.peer_id.id_addr_info;
(*irk) = _bond_data.peer_id.id_info;
(*enc_key) = _bond_data.own_enc;
}
}
+4 -8
View File
@@ -152,10 +152,10 @@ class AdafruitBluefruit
* Although declare as public, it is meant to be invoked by internal
* code. User should not call these directly
*------------------------------------------------------------------*/
void _startConnLed (void);
void _stopConnLed (void);
void _setConnLed (bool on_off);
void _startConnLed (void);
void _stopConnLed (void);
void _setConnLed (bool on_off);
void _bledfu_get_bond_data(ble_gap_addr_t* addr, ble_gap_irk_t* irk, ble_gap_enc_key_t* enc_key);
private:
/*------------- BLE para -------------*/
@@ -185,7 +185,6 @@ class AdafruitBluefruit
BLEGap::connect_callback_t _connect_cb;
BLEGap::disconnect_callback_t _disconnect_cb;
public: // TODO temporary for bledfu to load bonding data
struct
{
// Keys
@@ -194,7 +193,6 @@ public: // TODO temporary for bledfu to load bonding data
ble_gap_id_key_t peer_id;
} _bond_data;
private:
ble_gap_sec_params_t _sec_param;
COMMENT_OUT(
@@ -205,8 +203,6 @@ COMMENT_OUT(
/*------------------------------------------------------------------*/
/* INTERNAL USAGE ONLY
*------------------------------------------------------------------*/
bool _addToAdv(bool scan_resp, uint8_t type, const void* data, uint8_t len);
bool _saveBondKeys(void);
bool _loadBondKeys(uint16_t ediv);
@@ -126,19 +126,14 @@ static void bledfu_control_wr_authorize_cb(BLECharacteristic& chr, ble_gatts_evt
peer_data_t* peer_data = (peer_data_t*) (0x20007F80UL);
varclr(peer_data);
// Get CCCD
uint16_t sysattr_len = sizeof(peer_data->sys_attr);
sd_ble_gatts_sys_attr_get(Bluefruit.connHandle(), peer_data->sys_attr, &sysattr_len, BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS);
if ( !Bluefruit.connPaired() )
{
peer_data->addr = Bluefruit.getPeerAddr();
}else
{
peer_data->addr = Bluefruit._bond_data.peer_id.id_addr_info;
peer_data->irk = Bluefruit._bond_data.peer_id.id_info;
// Get Bond Data
Bluefruit._bledfu_get_bond_data(&peer_data->addr, &peer_data->irk, &peer_data->enc_key);
peer_data->enc_key = Bluefruit._bond_data.own_enc;
}
// Calculate crc
peer_data->crc16 = crc16((uint8_t*) peer_data, offsetof(peer_data_t, crc16));
// Initiate DFU Sequence and reboot into DFU OTA mode