Hi,
I am working on nRF52832 with SDK 15.3.0 with SoftDevice s112.
I am actually shifting from nRF51 to nRF52.
I have merged nrf51 custom code to nrf52, and able to advertise without bonding but not able to advertise with whitelist.
Adding advertising part of code.
i got error value to "sd_ble_gap_adv_set_configure" API NRF_ERROR_INVALID_PARAM, i think the issue with Use of whitelist requested but whitelist has not been set,
* see @ref sd_ble_gap_whitelist_set.
So i think i have to add sd_ble_gap_whitelist_set() API.
1. Where to add this API?
2. Is this sd_ble_gap_whitelist_set() API saves peer address.
3. How sd_ble_gap_whitelist_set() will react on power-on reset, this address need to set again?
4. Is anything needed after or before sd_ble_gap_whitelist_set() API.
5. Please check the code and tell me what is the reason of NRF_ERROR_INVALID_PARAM.
I dont want to use peer manager, is there is any example for bonding/whitelist without peer manager which i can refer.
Please help me on this.
void LDNVM::GetWhitelist(UINT8 &count, ble_whitelist_t &whiteList)
{
static ble_gap_addr_t* s_whiteListAddr[LDBONDNVM_MAX_BONDED_MASTERS];
static ble_gap_irk_t* s_whiteListIrk[LDBONDNVM_MAX_BONDED_MASTERS];
count = 0;
MasterBond* p = &s_bondDB[0];
if ((p->header != 0) && (IsValidBond((MasterBond*) p)))
{
count = 1;
s_whiteListAddr[0] = &p->keys_set.keys_peer.p_id_key->id_addr_info;
s_whiteListIrk[0] = &p->keys_set.keys_peer.p_id_key->id_info;
whiteList.addr_count = 1;
whiteList.irk_count = 1;
whiteList.pp_addrs = s_whiteListAddr;
whiteList.pp_irks = s_whiteListIrk;
}
}
/**@brief Whitelist structure. */
typedef struct
{
ble_gap_addr_t ** pp_addrs; /**< Pointer to array of device address pointers, pointing to addresses to be used in whitelist. NULL if none are given. */
uint8_t addr_count; /**< Count of device addresses in array, up to @ref BLE_GAP_WHITELIST_ADDR_MAX_COUNT. */
ble_gap_irk_t ** pp_irks; /**< Pointer to array of Identity Resolving Key (IRK) pointers, each pointing to an IRK in the whitelist. NULL if none are given. */
uint8_t irk_count; /**< Count of IRKs in array, up to @ref BLE_GAP_WHITELIST_IRK_MAX_COUNT. */
} ble_whitelist_t;
bool LDSoftDevice::GapSetAdvertisingData( UINT16 advInterval, UINT16 advTimeout,INT8 txPowerLevel, UINT32* status1, UINT32* status2, UINT32* status3)
{
bool retVal = false;
ble_whitelist_t whiteList;
UINT8 whiteListCount;
GetWhitelist(whiteListCount, whiteList);
if (GapAddVendorUUID(status1))
{
ble_advdata_t advdata;
ble_advdata_t srdata;
ble_uuid_t adv_uuids[] = { { PR_SERVICE_UUID, m_uuidBaseHandle } };
// Build and set advertising data
memset(&advdata, 0, sizeof(advdata));
// Build and set scan response data
memset(&srdata, 0, sizeof(srdata));
// advertising indication
advdata.name_type = BLE_ADVDATA_NO_NAME;
advdata.include_appearance = false;
advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
advdata.uuids_complete.p_uuids = adv_uuids;
// Flag to bonded device
if (whiteListCount == 1)
{
advdata.flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED ;
}
else
{
advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
}
// scan response data
srdata.name_type = BLE_ADVDATA_FULL_NAME;
// Variables used for manufacturer specific data
ble_advdata_manuf_data_t adv_manuf_data;
uint8_array_t adv_manuf_data_array;
uint8_t adv_manuf_data_data[3]; // up to 6 bytes
// Configuration of manufacturer specific data
adv_manuf_data_data[PAIRING_STATUS_INDEX] = 0x00; //Zero initialization
bool bonded = LDNVM::GetInstance()->IsBonded();
adv_manuf_data_data[PAIRING_STATUS_INDEX] = (bonded) ? (adv_manuf_data_data[PAIRING_STATUS_INDEX] | PAIRED) : (adv_manuf_data_data[PAIRING_STATUS_INDEX] & ~(PAIRED));
adv_manuf_data_data[DEVICE_TYPE_INDEX] = PPM_WE;
adv_manuf_data_array.p_data = adv_manuf_data_data;
adv_manuf_data_array.size = sizeof(adv_manuf_data_data);
adv_manuf_data.company_identifier = MFG_ID;
adv_manuf_data.data = adv_manuf_data_array;
advdata.p_manuf_specific_data = &adv_manuf_data;
ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
ble_advdata_encode(&srdata, m_adv_data.scan_rsp_data.p_data, &m_adv_data.scan_rsp_data.len);
ble_gap_adv_params_t adv_params;
// Set advertising parameters.
memset(&adv_params, 0, sizeof(adv_params));
adv_params.primary_phy = BLE_GAP_PHY_1MBPS;
adv_params.duration = advTimeout * CENTISEC_TO_SEC;
adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
adv_params.interval = advInterval;
// filter to bonded device
if (whiteListCount == 1)
{
adv_params.filter_policy = BLE_GAP_ADV_FP_FILTER_CONNREQ;
adv_params.p_peer_addr = *whiteList.pp_addrs;
}
else
{
adv_params.filter_policy = BLE_GAP_ADV_FP_ANY;
adv_params.p_peer_addr = NULL;
}
*status2 = sd_ble_gap_adv_set_configure(&m_AdvHandle, &m_adv_data, &adv_params);
if (*status2 == NRF_SUCCESS)
{
retVal = true;
}
// Set BLE TX Power level
*status3 = GapSetTxPowerLevel(txPowerLevel);
if(*status3 == NRF_SUCCESS)
{
retVal = true;
}
}
return retVal;
}