make hvn_sem and wrcmd_sem private
This commit is contained in:
3 files changed
+59
-43
No files matched your search
@@ -41,13 +41,39 @@
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
|
||||
BLEConnection::BLEConnection(uint16_t conn_hdl, ble_gap_evt_connected_t const* evt_connected)
|
||||
BLEConnection::BLEConnection(uint16_t conn_hdl, ble_gap_evt_connected_t const* evt_connected, uint8_t hvn_qsize, uint8_t wrcmd_qsize)
|
||||
{
|
||||
_conn_hdl = conn_hdl;
|
||||
|
||||
_addr = evt_connected->peer_addr;
|
||||
_mtu = BLE_GATT_ATT_MTU_DEFAULT;
|
||||
_addr = evt_connected->peer_addr;
|
||||
_role = evt_connected->role;
|
||||
|
||||
_hvn_sem = xSemaphoreCreateCounting(hvn_qsize, hvn_qsize);
|
||||
_wrcmd_sem = xSemaphoreCreateCounting(wrcmd_qsize, wrcmd_qsize);
|
||||
|
||||
_paired = false;
|
||||
hvc_sem = NULL;
|
||||
hvc_received = false;
|
||||
pair_sem = NULL;
|
||||
ediv = 0xFFFF; // invalid ediv value
|
||||
bond_keys = NULL;
|
||||
}
|
||||
|
||||
BLEConnection::~BLEConnection()
|
||||
{
|
||||
vSemaphoreDelete( _hvn_sem );
|
||||
vSemaphoreDelete( _wrcmd_sem );
|
||||
}
|
||||
|
||||
void BLEConnection::giveHvnPacket(uint8_t count)
|
||||
{
|
||||
for(uint8_t i=0; i<count; i++) xSemaphoreGive(_hvn_sem);
|
||||
}
|
||||
|
||||
void BLEConnection::giveWriteCmdPacket(uint8_t count)
|
||||
{
|
||||
for(uint8_t i=0; i<count; i++) xSemaphoreGive(_wrcmd_sem);
|
||||
}
|
||||
|
||||
uint16_t BLEConnection::handle (void)
|
||||
@@ -59,9 +85,10 @@ bool BLEConnection::paired (void)
|
||||
{
|
||||
return _paired;
|
||||
}
|
||||
|
||||
uint8_t BLEConnection::getRole (void)
|
||||
{
|
||||
|
||||
return _role;
|
||||
}
|
||||
|
||||
uint16_t BLEConnection::getMTU (void)
|
||||
@@ -87,12 +114,10 @@ uint8_t BLEConnection::getPeerAddr (uint8_t addr[6])
|
||||
|
||||
bool BLEConnection::getHvnPacket (void)
|
||||
{
|
||||
VERIFY(hvn_sem != NULL);
|
||||
return xSemaphoreTake(hvn_sem, ms2tick(BLE_GENERIC_TIMEOUT));
|
||||
return xSemaphoreTake(_hvn_sem, ms2tick(BLE_GENERIC_TIMEOUT));
|
||||
}
|
||||
|
||||
bool BLEConnection::getWriteCmdPacket (void)
|
||||
{
|
||||
VERIFY(wrcmd_sem != NULL);
|
||||
return xSemaphoreTake(wrcmd_sem, ms2tick(BLE_GENERIC_TIMEOUT));
|
||||
return xSemaphoreTake(_wrcmd_sem, ms2tick(BLE_GENERIC_TIMEOUT));
|
||||
}
|
||||
@@ -46,14 +46,14 @@ class BLEConnection
|
||||
private:
|
||||
uint16_t _conn_hdl;
|
||||
uint16_t _mtu;
|
||||
ble_gap_addr_t _addr;
|
||||
uint8_t _role;
|
||||
|
||||
public:
|
||||
ble_gap_addr_t _addr;
|
||||
bool _paired;
|
||||
SemaphoreHandle_t _hvn_sem;
|
||||
SemaphoreHandle_t _wrcmd_sem;
|
||||
|
||||
SemaphoreHandle_t hvn_sem;
|
||||
SemaphoreHandle_t wrcmd_sem;
|
||||
public:
|
||||
bool _paired;
|
||||
|
||||
// On-demand semaphore that are created on the fly
|
||||
SemaphoreHandle_t hvc_sem;
|
||||
@@ -64,7 +64,8 @@ class BLEConnection
|
||||
uint16_t ediv;
|
||||
bond_keys_t* bond_keys; // Shared keys with bonded device, size ~ 80 bytes
|
||||
|
||||
BLEConnection(uint16_t conn_hdl, ble_gap_evt_connected_t const * evt_connected);
|
||||
BLEConnection(uint16_t conn_hdl, ble_gap_evt_connected_t const * evt_connected, uint8_t hvn_qsize, uint8_t wrcmd_qsize);
|
||||
virtual ~BLEConnection();
|
||||
|
||||
uint16_t handle(void);
|
||||
bool connected(void);
|
||||
@@ -77,8 +78,11 @@ class BLEConnection
|
||||
ble_gap_addr_t getPeerAddr(void);
|
||||
uint8_t getPeerAddr(uint8_t addr[6]);
|
||||
|
||||
bool getHvnPacket (void);
|
||||
bool getHvnPacket(void);
|
||||
void giveHvnPacket(uint8_t count);
|
||||
|
||||
bool getWriteCmdPacket(void);
|
||||
void giveWriteCmdPacket(uint8_t count);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -149,12 +149,11 @@ bool BLEGap::connected(uint16_t conn_hdl)
|
||||
|
||||
bool BLEGap::requestPairing(uint16_t conn_hdl)
|
||||
{
|
||||
gap_peer_t* peer = &_peers[conn_hdl];
|
||||
BLEConnection* conn = _connection[conn_hdl];
|
||||
VERIFY(conn);
|
||||
|
||||
// skip if already paired
|
||||
if ( conn->_paired ) return true;
|
||||
if ( conn->paired() ) return true;
|
||||
|
||||
uint16_t cntr_ediv = 0xFFFF;
|
||||
|
||||
@@ -162,8 +161,9 @@ bool BLEGap::requestPairing(uint16_t conn_hdl)
|
||||
{
|
||||
// Check to see if we did bonded with current prph previously
|
||||
bond_keys_t bkeys;
|
||||
ble_gap_addr_t peer_addr = conn->getPeerAddr();
|
||||
|
||||
if ( bond_find_cntr(&conn->_addr, &bkeys) )
|
||||
if ( bond_find_cntr(&peer_addr, &bkeys) )
|
||||
{
|
||||
cntr_ediv = bkeys.peer_enc.master_id.ediv;
|
||||
LOG_LV2("BOND", "Load Keys from file " BOND_FNAME_CNTR, cntr_ediv);
|
||||
@@ -185,7 +185,7 @@ bool BLEGap::requestPairing(uint16_t conn_hdl)
|
||||
|
||||
// Failed to pair using central stored keys, this happens when
|
||||
// Prph delete bonds while we did not --> let's remove the obsolete keyfile and move on
|
||||
if ( !conn->_paired && (cntr_ediv != 0xffff) )
|
||||
if ( !conn->paired() && (cntr_ediv != 0xffff) )
|
||||
{
|
||||
bond_remove_key(BLE_GAP_ROLE_CENTRAL, cntr_ediv);
|
||||
|
||||
@@ -198,7 +198,7 @@ bool BLEGap::requestPairing(uint16_t conn_hdl)
|
||||
vSemaphoreDelete(conn->pair_sem);
|
||||
conn->pair_sem = NULL;
|
||||
|
||||
return conn->_paired;
|
||||
return conn->paired();
|
||||
}
|
||||
|
||||
uint8_t BLEGap::getRole(uint16_t conn_hdl)
|
||||
@@ -240,21 +240,18 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
|
||||
_connection[conn_hdl] = NULL;
|
||||
}
|
||||
|
||||
_connection[conn_hdl] = new BLEConnection(conn_hdl, para);
|
||||
conn = _connection[conn_hdl];
|
||||
// Transmission buffer pool
|
||||
uint8_t const hvn_qsize = (para->role == BLE_GAP_ROLE_PERIPH) ? _prph.hvn_qsize : _central.hvn_qsize;
|
||||
uint8_t const wrcmd_qsize = (para->role == BLE_GAP_ROLE_PERIPH) ? _prph.wrcmd_qsize : _central.wrcmd_qsize;
|
||||
|
||||
_connection[conn_hdl] = new BLEConnection(conn_hdl, para, hvn_qsize, wrcmd_qsize);
|
||||
conn = _connection[conn_hdl];
|
||||
|
||||
peer->role = para->role;
|
||||
|
||||
// Transmission buffer sem pool
|
||||
uint8_t const hvn_qsize = (para->role == BLE_GAP_ROLE_PERIPH) ? _prph.hvn_qsize : _central.hvn_qsize;
|
||||
conn->hvn_sem = xSemaphoreCreateCounting(hvn_qsize, hvn_qsize);
|
||||
|
||||
uint8_t const wrcmd_qsize = (para->role == BLE_GAP_ROLE_PERIPH) ? _prph.wrcmd_qsize : _central.wrcmd_qsize;
|
||||
conn->wrcmd_sem = xSemaphoreCreateCounting(wrcmd_qsize, wrcmd_qsize);
|
||||
|
||||
LOG_LV2("GAP", "Conn Interval= %f", para->conn_params.min_conn_interval*1.25f);
|
||||
|
||||
// Invoke connect callback
|
||||
if ( conn->getRole() == BLE_GAP_ROLE_PERIPH )
|
||||
{
|
||||
if ( _prph.connect_cb ) ada_callback(NULL, _prph.connect_cb, conn_hdl);
|
||||
@@ -270,14 +267,10 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
|
||||
ble_gap_evt_disconnected_t const* para = &evt->evt.gap_evt.params.disconnected;
|
||||
|
||||
LOG_LV2("GAP", "Disconnect Reason 0x%02X", evt->evt.gap_evt.params.disconnected.reason);
|
||||
// mark as disconnected, but keep the role for sub sequence event handler
|
||||
|
||||
vSemaphoreDelete( conn->hvn_sem );
|
||||
conn->hvn_sem = NULL;
|
||||
|
||||
vSemaphoreDelete( conn->wrcmd_sem );
|
||||
conn->wrcmd_sem = NULL;
|
||||
// FIXME role is still required for sub sequence event handler such as Gatt
|
||||
|
||||
// Invoke disconnect callback
|
||||
if ( conn->getRole() == BLE_GAP_ROLE_PERIPH )
|
||||
{
|
||||
if ( _prph.disconnect_cb ) ada_callback(NULL, _prph.disconnect_cb, conn_hdl, para->reason);
|
||||
@@ -397,7 +390,7 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
|
||||
{
|
||||
sd_ble_gap_sec_info_reply(evt->evt.gap_evt.conn_handle, &bkeys.own_enc.enc_info, &bkeys.peer_id.id_info, NULL);
|
||||
|
||||
conn->ediv = bkeys.own_enc.master_id.ediv;
|
||||
conn->ediv = bkeys.own_enc.master_id.ediv;
|
||||
} else
|
||||
{
|
||||
sd_ble_gap_sec_info_reply(evt->evt.gap_evt.conn_handle, NULL, NULL, NULL);
|
||||
@@ -438,17 +431,11 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
|
||||
break;
|
||||
|
||||
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
|
||||
if ( conn->hvn_sem )
|
||||
{
|
||||
for(uint8_t i=0; i<evt->evt.gatts_evt.params.hvn_tx_complete.count; i++) xSemaphoreGive(conn->hvn_sem);
|
||||
}
|
||||
if ( conn ) conn->giveHvnPacket(evt->evt.gatts_evt.params.hvn_tx_complete.count);
|
||||
break;
|
||||
|
||||
case BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE:
|
||||
if ( conn->wrcmd_sem )
|
||||
{
|
||||
for(uint8_t i=0; i<evt->evt.gattc_evt.params.write_cmd_tx_complete.count; i++) xSemaphoreGive(conn->wrcmd_sem);
|
||||
}
|
||||
if ( conn ) conn->giveWriteCmdPacket(evt->evt.gattc_evt.params.write_cmd_tx_complete.count);
|
||||
break;
|
||||
|
||||
case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST:
|
||||
|
||||
Reference in new issue
Block a user