Part Number: CC2640R2F
Other Parts Discussed in Thread: CC2640
Hi there,
I am making a POC with CC2640R2 chip with simplelink_cc2640r2_sdk_1_40_00_45 stack. My code is running on a custom designed board and everything related with HW looks fine. Before I start I wanted to mention that, I am following following page: file:///C:/ti/simplelink_cc2640r2_sdk_1_40_00_45/docs/ble5stack/ble_user_guide/html/ble-stack-5.x/gapbondmngr.html
I would like to use pair with my peripheral device with central device (PC/Mobile Phone) where Initiator (Central Device) has Keyboard and Display and Responder - My Device - (Peripheral Device) has Display YESNO. I would like to use PassKey Entry for LE Legacy and Numaric Comparison for Secure Connection.
I use the SimplePeripheral Project as base and wrote my code on top of that. Here is the build_config.opt on my Stack Project.
-DHOST_CONFIG=PERIPHERAL_CFG -DGAP_BOND_MGR -DBLE_V41_FEATURES=L2CAP_COC_CFG -DBLE_V42_FEATURES=SECURE_CONNS_CFG+PRIVACY_1_2_CFG -DHCI_TL_NONE
My Stack project has "OSAL_SNV=1" Preprocessor define
On the application project, I defined "MAX_PDU_SIZE=135" and my minimum heap size is set to 4500 on app_ble.cfg file as following:
var Memory = xdc.useModule('xdc.runtime.Memory');
var HEAPMGR_CONFIG = 1;
var HEAPMGR_SIZE = 4500;
Here are my gap parameters configured as:
// Setup Antenna Power
{
HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_0_DBM);
}
// Advertisement Parameters
{
uint8_t initialAdvertEnable = TRUE; // Device starts advertising upon initialization of GAP
uint16_t advertOffTime = DEFAULT_ADVERTISE_OFF_TIME;
uint8_t enableUpdateRequest = DEFAULT_ENABLE_UPDATE_REQUEST;
uint16_t desiredMinInterval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
uint16_t desiredMaxInterval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
uint16_t desiredSlaveLatency = DEFAULT_DESIRED_SLAVE_LATENCY;
uint16_t desiredConnTimeout = DEFAULT_DESIRED_CONN_TIMEOUT;
uint16_t advInt = DEFAULT_ADVERTISING_INTERVAL;
// Set the Peripheral GAPRole Parameters
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),&initialAdvertEnable);
GAPRole_SetParameter(GAPROLE_ADVERT_OFF_TIME, sizeof(uint16_t),&advertOffTime);
GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData),scanRspData);
GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData);
GAPRole_SetParameter(GAPROLE_PARAM_UPDATE_ENABLE, sizeof(uint8_t),&enableUpdateRequest);
GAPRole_SetParameter(GAPROLE_MIN_CONN_INTERVAL, sizeof(uint16_t),&desiredMinInterval);
GAPRole_SetParameter(GAPROLE_MAX_CONN_INTERVAL, sizeof(uint16_t),&desiredMaxInterval);
GAPRole_SetParameter(GAPROLE_SLAVE_LATENCY, sizeof(uint16_t),&desiredSlaveLatency);
GAPRole_SetParameter(GAPROLE_TIMEOUT_MULTIPLIER, sizeof(uint16_t),&desiredConnTimeout);
GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MIN, advInt);
GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MAX, advInt);
GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MIN, advInt);
GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MAX, advInt);
}
// Set the GAP Characteristics
{
uint8_t gapPeripheralPrivacyFlag = GAP_PERIPHERAL_PRIVACY_FLAG;
uint8_t gapPeripheralConnectionParam[8] = GAP_PERIPHERAL_CONNECTION_PARAM;
GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, (void *) attDeviceName);
GGS_SetParameter(GGS_PERI_PRIVACY_FLAG_ATT, sizeof(uint8), &gapPeripheralPrivacyFlag);
GGS_SetParameter(GGS_PERI_CONN_PARAM_ATT, 8, &gapPeripheralConnectionParam);
GAP_SetParamValue(TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL);
}
// Bonding Parameters
{
uint32_t passkey = DEFAULT_PAIRING_PIN_CODE;
uint8_t pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ; // Don't send a pairing request after connecting; the peer device must initiate pairing
uint8_t mitm = TRUE; // Use authenticated pairing: require passcode.
uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_YES_NO;
uint8_t bonding = TRUE;
uint8_t gapbondSecure = GAPBOND_SECURE_CONNECTION_ALLOW;
GAPBondMgr_SetParameter(GAPBOND_DEFAULT_PASSCODE, sizeof(uint32_t),&passkey);
GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);
GAPBondMgr_SetParameter(GAPBOND_SECURE_CONNECTION, sizeof(uint8_t), &gapbondSecure);
// Disable Advertisement Timeout
GAP_SetParamValue(TGAP_GEN_DISC_ADV_MIN, 0);
GAP_SetParamValue(TGAP_LIM_ADV_TIMEOUT, 0);
uint8_t u8VarWithNumber = 15; // 15*18=270 byte buffer size
GATTServApp_SetParameter(GATT_PARAM_NUM_PREPARE_WRITES, 1, &u8VarWithNumber);
}
.....
#if defined (BLE_V42_FEATURES) && (BLE_V42_FEATURES & PRIVACY_1_2_CFG)
// Initialize GATT Client
GATT_InitClient();
// This line masks the Resolvable Private Address Only (RPAO) Characteristic
// in the GAP GATT Server from being detected by remote devices. This value
// cannot be toggled without power cycling but should remain consistent across
// power-cycles. Removing this command when Privacy is used will cause this
// device to be treated in Network Privacy Mode by bonded devices - this means
// that after disconnecting they will not respond to this device's PDUs which
// contain its Identity Address.
// Devices wanting to use Network Privacy Mode with other BT5 devices, this
// line should be commented out.
// GGS_SetParamValue(GGS_DISABLE_RPAO_CHARACTERISTIC); // ----- Not interested in RPA for now.
#endif // BLE_V42_FEATURES & PRIVACY_1_2_CFG
#if !defined (USE_LL_CONN_PARAM_UPDATE)
// Get the currently set local supported LE features
// The will result in a HCI_LE_READ_LOCAL_SUPPORTED_FEATURES event that
// will get received in the main task processing loop. At this point,
// feature bits can be set / cleared and the features can be updated.
HCI_LE_ReadLocalSupportedFeaturesCmd();
#endif // !defined (USE_LL_CONN_PARAM_UPDATE)
......
I also registered the gapBondCBs
static gapBondCBs_t XXX_BondMgrCBs =
{
(pfnPasscodeCB_t)XXX_passcodeCB, // Passcode callback
XXX_pairStateCB // Pairing / Bonding state Callback
};
where;
static void XXX_passcodeCB(uint8_t *deviceAddr, uint16_t connHandle,
uint8_t uiInputs, uint8_t uiOutputs, uint32_t numComparison)
{
gapPasskeyNeededEvent_t *pData;
// Allocate space for the passcode event.
if ((pData = ICall_malloc(sizeof(gapPasskeyNeededEvent_t))))
{
memcpy(pData->deviceAddr, deviceAddr, B_ADDR_LEN);
pData->connectionHandle = connHandle;
pData->uiOutputs = uiOutputs;
pData->uiInputs = uiInputs;
pData->numComparison = numComparison;
pData->opcode = GAP_PASSKEY_NEEDED_EVENT;
// Enqueue the event.
XXX_enqueueMsg(XXX_PASSCODE_NEEDED_EVT, NULL, (uint8_t *) pData);
}
}
static void XXX_processPasscode(gapPasskeyNeededEvent_t *pData)
{
// Use static passcode
uint32_t passcode = DEFAULT_PAIRING_PIN_CODE;
//Display_print1(dispHandle, MR_ROW_SECURITY, 0, "Passcode: %d", passcode);
// Send passcode to GAPBondMgr
GAPBondMgr_PasscodeRsp(pData->connectionHandle, SUCCESS, passcode);
}
However, I never receive a PIN Entry on my central device. Can you tell me a little bit about what can be wrong. I spent a lot of time and played with different parameters for Bonding Parameters. However, still there is no result yet.
I thank you in advance!