make mtu private

This commit is contained in:
hathach committed 2019-01-18 12:52:22 +07:00
1 parent 4e5f419474
commit 317aee7d78
3 files changed
+74 -40

No files matched your search

+57 -1
View File
@@ -34,9 +34,65 @@
*/
/**************************************************************************/
#include "BLEConnection.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
//------------- IMPLEMENTATION -------------//
BLEConnection::BLEConnection(uint16_t conn_hdl, ble_gap_evt_connected_t const* evt_connected)
{
_conn_hdl = conn_hdl;
_addr = evt_connected->peer_addr;
_mtu = BLE_GATT_ATT_MTU_DEFAULT;
role = evt_connected->role;
}
uint16_t BLEConnection::handle (void)
{
return _conn_hdl;
}
bool BLEConnection::paired (void)
{
return _paired;
}
uint8_t BLEConnection::getRole (void)
{
}
uint16_t BLEConnection::getMTU (void)
{
return _mtu;
}
void BLEConnection::setMTU (uint16_t mtu)
{
_mtu = mtu;
}
ble_gap_addr_t BLEConnection::getPeerAddr (void)
{
return _addr;
}
uint8_t BLEConnection::getPeerAddr (uint8_t addr[6])
{
memcpy(addr, _addr.addr, BLE_GAP_ADDR_LEN);
return _addr.addr_type;
}
bool BLEConnection::getHvnPacket (void)
{
VERIFY(hvn_sem != NULL);
return xSemaphoreTake(hvn_sem, ms2tick(BLE_GENERIC_TIMEOUT));
}
bool BLEConnection::getWriteCmdPacket (void)
{
VERIFY(wrcmd_sem != NULL);
return xSemaphoreTake(wrcmd_sem, ms2tick(BLE_GENERIC_TIMEOUT));
}
+10 -29
View File
@@ -45,10 +45,10 @@ class BLEConnection
{
private:
uint16_t _conn_hdl;
uint16_t _mtu;
public:
ble_gap_addr_t _addr;
uint16_t att_mtu;
bool _paired;
uint8_t role;
@@ -64,40 +64,21 @@ class BLEConnection
uint16_t ediv;
bond_keys_t* bond_keys; // Shared keys with bonded device, size ~ 80 bytes
BLEConnection(uint16_t conn_hdl) { _conn_hdl = conn_hdl; }
BLEConnection(uint16_t conn_hdl, ble_gap_evt_connected_t const * evt_connected);
uint16_t handle(void) { return _conn_hdl; }
uint16_t handle(void);
bool connected(void);
bool paired(void) { return _paired; }
bool paired(void);
uint8_t getRole(void);
uint16_t getMTU (void)
{
return att_mtu;
}
uint16_t getMTU (void);
void setMTU (uint16_t mtu);
ble_gap_addr_t getPeerAddr(void)
{
return _addr;
}
ble_gap_addr_t getPeerAddr(void);
uint8_t getPeerAddr(uint8_t addr[6]);
uint8_t getPeerAddr(uint8_t addr[6])
{
memcpy(addr, _addr.addr, BLE_GAP_ADDR_LEN);
return _addr.addr_type;
}
bool getHvnPacket (void)
{
VERIFY(hvn_sem != NULL);
return xSemaphoreTake(hvn_sem, ms2tick(BLE_GENERIC_TIMEOUT));
}
bool getWriteCmdPacket(void)
{
VERIFY(wrcmd_sem != NULL);
return xSemaphoreTake(wrcmd_sem, ms2tick(BLE_GENERIC_TIMEOUT));
}
bool getHvnPacket (void);
bool getWriteCmdPacket(void);
};
+7 -10
View File
@@ -240,14 +240,9 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
_connection[conn_hdl] = NULL;
}
_connection[conn_hdl] = new BLEConnection(conn_hdl);
_connection[conn_hdl] = new BLEConnection(conn_hdl, para);
conn = _connection[conn_hdl];
varclr(conn);
conn->_addr = para->peer_addr;
conn->att_mtu = BLE_GATT_ATT_MTU_DEFAULT;
conn->role = para->role;
peer->role = para->role;
@@ -509,11 +504,13 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
{
uint16_t const mtu_max = (conn->role == BLE_GAP_ROLE_PERIPH) ? _prph.mtu_max : _central.mtu_max;
conn->att_mtu = minof(evt->evt.gatts_evt.params.exchange_mtu_request.client_rx_mtu, mtu_max);
VERIFY_STATUS( sd_ble_gatts_exchange_mtu_reply(conn_hdl, conn->att_mtu), );
uint16_t mtu = (conn->role == BLE_GAP_ROLE_PERIPH) ? _prph.mtu_max : _central.mtu_max;
mtu = minof(evt->evt.gatts_evt.params.exchange_mtu_request.client_rx_mtu, mtu);
LOG_LV1("GAP", "ATT MTU is changed to %d", conn->att_mtu);
conn->setMTU(mtu);
VERIFY_STATUS( sd_ble_gatts_exchange_mtu_reply(conn_hdl, mtu), );
LOG_LV1("GAP", "ATT MTU is changed to %d", mtu);
}
break;