Skip to content

Commit

Permalink
[hal] BLE: minors
Browse files Browse the repository at this point in the history
  • Loading branch information
XuGuohui committed Dec 22, 2020
1 parent 80966e5 commit fd950b8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
3 changes: 3 additions & 0 deletions hal/inc/ble_hal_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
* @{ */
#define BLE_SIG_ADDR_LEN (6)

// BLE authentication passkey length
#define BLE_PAIRING_PASSKEY_LEN (6)

// BLE device address type
typedef enum ble_sig_addr_type_t {
BLE_SIG_ADDR_TYPE_PUBLIC = 0x00, /**< Public (identity) address.*/
Expand Down
43 changes: 23 additions & 20 deletions hal/src/nRF52840/ble_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,23 @@ StaticRecursiveMutex s_bleMutex;

bool bleInLockedMode = false;

const auto BLE_CONN_CFG_TAG = 1;
constexpr auto BLE_CONN_CFG_TAG = 1;

// BLE service base start handle.
const hal_ble_attr_handle_t SERVICES_BASE_START_HANDLE = 0x0001;
// BLE service top end handle.
const hal_ble_attr_handle_t SERVICES_TOP_END_HANDLE = 0xFFFF;

// Pool for BLE event data.
const size_t BLE_EVT_DATA_POOL_SIZE = 2048;
constexpr size_t BLE_EVT_DATA_POOL_SIZE = 2048;

// Timeout for a BLE procedure.
const uint32_t BLE_OPERATION_TIMEOUT_MS = 30000;
constexpr uint32_t BLE_OPERATION_TIMEOUT_MS = 30000;
// Delay for GATT Client to send the ATT MTU exchanging request.
const uint32_t BLE_ATT_MTU_EXCHANGE_DELAY_MS = 800;
constexpr uint32_t BLE_ATT_MTU_EXCHANGE_DELAY_MS = 800;

constexpr uint8_t BLE_ENC_MIN_KEY_SIZE = 7;
constexpr uint8_t BLE_ENC_MAX_KEY_SIZE = 16;

static const uint8_t BleAdvEvtTypeMap[] = {
BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED,
Expand Down Expand Up @@ -1894,17 +1897,17 @@ int BleObject::ConnectionsManager::startPairing(hal_ble_conn_handle_t connHandle
connection->pairState == BLE_PAIRING_STATE_SEC_REQ_RECEIVED, SYSTEM_ERROR_INVALID_STATE);
ble_gap_sec_params_t secParams = {};
if (ioCaps_ != BLE_IO_CAPS_NONE) {
secParams.mitm = 1;
secParams.mitm = true;
}
if (connection->info.role == BLE_ROLE_CENTRAL) {
secParams.io_caps = toPlatformIoCaps(ioCaps_);
secParams.oob = 0;
secParams.min_key_size = 7;
secParams.max_key_size = 16;
secParams.kdist_own.enc = 1;
secParams.kdist_own.id = 1;
secParams.kdist_peer.enc = 1;
secParams.kdist_peer.id = 1;
secParams.oob = false;
secParams.min_key_size = BLE_ENC_MIN_KEY_SIZE;
secParams.max_key_size = BLE_ENC_MAX_KEY_SIZE;
secParams.kdist_own.enc = true;
secParams.kdist_own.id = true;
secParams.kdist_peer.enc = true;
secParams.kdist_peer.id = true;
}
LOG_DEBUG(TRACE, "Own security params: %d, %d, %d, %d, %d, %d", secParams.bond, secParams.mitm, secParams.lesc, secParams.io_caps, secParams.keypress, secParams.oob);
int ret = sd_ble_gap_authenticate(connection->info.conn_handle, &secParams);
Expand Down Expand Up @@ -2326,16 +2329,16 @@ int BleObject::ConnectionsManager::processSecurityEventFromThread(const ble_evt_
if (connection->pairState != BLE_PAIRING_STATE_REJECTED) {
ble_gap_sec_params_t secParams = {};
if (ioCaps_ != BLE_IO_CAPS_NONE) {
secParams.mitm = 1;
secParams.mitm = true;
}
secParams.io_caps = toPlatformIoCaps(ioCaps_);
secParams.oob = 0;
secParams.min_key_size = 7;
secParams.max_key_size = 16;
secParams.kdist_own.enc = 1;
secParams.kdist_own.id = 1;
secParams.kdist_peer.enc = 1;
secParams.kdist_peer.id = 1;
secParams.oob = false;
secParams.min_key_size = BLE_ENC_MIN_KEY_SIZE;
secParams.max_key_size = BLE_ENC_MAX_KEY_SIZE;
secParams.kdist_own.enc = true;
secParams.kdist_own.id = true;
secParams.kdist_peer.enc = true;
secParams.kdist_peer.id = true;
ret = sd_ble_gap_sec_params_reply(event->evt.gap_evt.conn_handle, BLE_GAP_SEC_STATUS_SUCCESS, &secParams, nullptr);
}
}
Expand Down
2 changes: 0 additions & 2 deletions hal/src/nRF52840/ble_hal_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@
#define BLE_MAX_PERIPHERAL_COUNT NRF_SDH_BLE_PERIPHERAL_LINK_COUNT
#define BLE_MAX_CENTRAL_COUNT NRF_SDH_BLE_CENTRAL_LINK_COUNT

#define BLE_PAIRING_PASSKEY_LEN 6


typedef uint16_t hal_ble_attr_handle_t;
typedef uint16_t hal_ble_conn_handle_t;
Expand Down

0 comments on commit fd950b8

Please sign in to comment.