2025-09-15 5:53 AM
Hi,
I need to implement the following behavior on a STM32WB55.
Upon a command, device must advertise in 2 different modes:
To acheive that, I followed scrupulously the ST wiki & configured the following:
I am able to have either one of the 2 scenarii, but I cannot switch dynamically from one another.
The key difference resides in the security permission of each characteristic.
Unfortunately, I cannot switch dynamically between the 2.
I tried the following:
Here are my questions:
Code snippet of the authentication requirements:
/**
* Configuration that differs upon advertizing mode
*/
switch (mode)
{
case ble_advertize_justworks:
io_capability = IO_CAP_NO_INPUT_NO_OUTPUT;
MITM_Mode = CFG_MITM_PROTECTION_NOT_REQUIRED;
break;
case ble_advertize_passkey:
io_capability = IO_CAP_DISPLAY_ONLY;
MITM_Mode = CFG_MITM_PROTECTION_REQUIRED;
break;
default:
assert(FALSE); // should not reach here
break;
}
/**
* Set I/O capability
*/
ret = aci_gap_set_io_capability(io_capability);
if (ret != BLE_STATUS_SUCCESS) {
APP_DBG_MSG("aci_gap_set_io_capability failed with status %x", ret);
return ret;
}
/**
* Configure authentication
*/
ret = aci_gap_set_authentication_requirement(0, // No bonding required
MITM_Mode,
CFG_SECURE_NOT_SUPPORTED,
CFG_KEYPRESS_NOT_SUPPORTED,
CFG_ENCRYPTION_KEY_SIZE_MIN,
CFG_ENCRYPTION_KEY_SIZE_MAX,
0, // use a fixed pin
passkey, // fixed pin value
GAP_PUBLIC_ADDR); // identity address type
if (ret != BLE_STATUS_SUCCESS)
{
APP_DBG_MSG("aci_gap_set_authentication_requirement failed with status %x", ret);
return ret;
}
/**
* Fill UUID with UUID
*/
memcpy(&(ble_adv_uuid[1]), ble_get_uuid(), sizeof(ble_uuid_t));
/**
* Start advertising
*/
ret = aci_gap_set_discoverable(
ADV_IND,
CFG_FAST_CONN_ADV_INTERVAL_MIN,
CFG_FAST_CONN_ADV_INTERVAL_MAX,
BLE_ADDR_TYPE,
NO_WHITE_LIST_USE,
sizeof(ble_local_name) - 1, /* Don't count the 0 byte at the end */
(uint8_t*) ble_local_name,
sizeof(ble_adv_uuid),
(uint8_t*) ble_adv_uuid,
0, /* No specific minimum connection interval */
0 /* No specific maximum connection interval */
);
if (ret != BLE_STATUS_SUCCESS) {
APP_DBG_MSG("aci_gap_set_discoverable failed with status %x", ret);
return ret;
}