This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Missing write event on pairing

I'm using SDKv12 S132v3 on nRF52 peripheral device. I have characteristic with following security setup:

char_add_params.read_access=SEC_JUST_WORKS;
char_add_params.write_access=SEC_JUST_WORKS;
char_add_params.cccd_write_access=SEC_JUST_WORKS;

Peer manager is configured to support 'Just works' pairing. Everything works ok as long as central requests encryption before attempting to interact with the characteristic.

If I try to for example write the cccd just after connect automatic pairing procedure is triggered and it completes ok but the event which triggered it (in this case cccd write) isn't passed to application code. If I add something like NRF_LOG_DEBUG("EVT: 0x%X\r\n",p_ble_evt->header.evt_id); to my main on_ble_evt() handler I see following list of event codes:

btle\btle.c:DEBUG:EVT: 0x10 BLE_GAP_EVT_CONNECTED
btle\btle.c:DEBUG:on_ble_evt() BLE_GAP_EVT_CONNECTED
btle\btle.c:DEBUG:EVT: 0x12 BLE_GAP_EVT_CONN_PARAM_UPDATE
btle\btle.c:DEBUG:EVT: 0x12 BLE_GAP_EVT_CONN_PARAM_UPDATE
btle\btle.c:DEBUG:EVT: 0x13 BLE_GAP_EVT_SEC_PARAMS_REQUEST
btle\btle.c:DEBUG:EVT: 0x12 BLE_GAP_EVT_CONN_PARAM_UPDATE
btle\btle.c:DEBUG:EVT: 0x1A BLE_GAP_EVT_AUTH_STATUS
btle\btle.c:DEBUG:EVT: 0x19 BLE_GAP_EVT_CONN_SEC_UPDATE
btle\peer_manager_handler.c:DEBUG:Link secured. Role: 1. conn_handle: 0, Procedure: 1
btle\btle.c:DEBUG:EVT: 0x12 BLE_GAP_EVT_CONN_PARAM_UPDATE
btle\btle.c:DEBUG:EVT: 0x12 BLE_GAP_EVT_CONN_PARAM_UPDATE
btle\btle.c:DEBUG:EVT: 0x12 BLE_GAP_EVT_CONN_PARAM_UPDATE

As you can see event 0x50 BLE_GATTS_EVT_WRITE which triggered the data exchange is missing

Same is true for characteristic value read/write. Operations following the missing event are processed fine. Please advise me what I'm doing wrong.

Parents
  • You are not doing anything wrong.

    If a client tries to write to an attribute value that requires the link to be in a certain security level, and the link is not in this level, it will receive an error response, and the attribute value will not be written (and the application will not get the write event). This error response is in your case most likely "Insufficient Authentication", and this error response is used to trigger initiation of pairing by the central device.

    After pairing is complete the client can try to write again.

    (Only write requests will get error responses, not write commands)

Reply
  • You are not doing anything wrong.

    If a client tries to write to an attribute value that requires the link to be in a certain security level, and the link is not in this level, it will receive an error response, and the attribute value will not be written (and the application will not get the write event). This error response is in your case most likely "Insufficient Authentication", and this error response is used to trigger initiation of pairing by the central device.

    After pairing is complete the client can try to write again.

    (Only write requests will get error responses, not write commands)

Children
Related