2023-11-29 03:53 AM
I am working with nucleo l496zg development board and I have successfully interfaced x nucleo bluenrg shield and able to receive and send data. I want to implement passcode security to my BLE dev while making a connection and send the data in encrypted mode
I followed BlueNRG-2 BLE stack v2.x programming guidelines and used void aci_gap_pass_key_req_event() and ret=aci_gap_set_io_capability() functions to enable security but I am not able to implement it proprely i guess.
Can anyone take a look at my BLE Init and help me with a solution
hci_init(APP_UserEvtRx, NULL);
hci_reset();
HAL_Delay(100);
ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, bdaddr);
ret = aci_gatt_init();
if(ret != BLE_STATUS_SUCCESS)
{
printf("aci_gatt_init : FAILED!! \n\r");
}
ret = aci_gap_init(GAP_PERIPHERAL_ROLE, 0, 0x07, &service_handle, &dev_name_handle, &appearance_char_handle);
// ret = aci_gap_init(GAP_PERIPHERAL_ROLE, 0x02, sizeof (name), &service_handle, &dev_name_handle, &appearance_char_handle);
if(ret != BLE_STATUS_SUCCESS)
{
printf("aci_gap_init : FAILED!! \n\r");
}
ret = aci_gatt_update_char_value(service_handle, dev_name_handle, 0, strlen(name), (uint8_t *)name);
if(ret != BLE_STATUS_SUCCESS)
{
printf("aci_gatt_update_char_value : FAILED!! \n\r");
}
// ret = aci_gap_clear_security_db();
// if(ret != BLE_STATUS_SUCCESS)
// {
// printf("aci_gatt_update_char_value : FAILED!! \n\r");
// }
/*Update characteristics value*/
ret= aci_gap_set_io_capability(IO_CAP_DISPLAY_ONLY);
if (ret != BLE_STATUS_SUCCESS)
{printf("Failure.\n");}
/*Update characteristics value*/
ret=aci_gap_set_authentication_requirement(BONDING,/*bonding is enabled */
MITM_PROTECTION_REQUIRED,
SC_IS_SUPPORTED,/*Secure connection supported but optional */
KEYPRESS_IS_NOT_SUPPORTED,
7, /* Min encryption key size */
16, /* Max encryption key size */
USE_FIXED_PIN_FOR_PAIRING, /* fixed pin is not used*/
123456, /* fixed pin */
STATIC_RANDOM_ADDR /* Public Identity address type */);
if (ret != BLE_STATUS_SUCCESS)
{printf("Failure.\n");}
ret = add_service();