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

Return error code at connection

Hello,

I would like to return a specific error when a device connects to my NRF52 (by bluetooth) when for example the range of mac address is wrong to me... (or something else).

Do you know if it is technically possible to return an error (BLE_GATT_STATUS_UNKNOWN or even a specific error different from BLE_GATT_STATUS_SUCCESS) at connection ?

Thank you for your help

Parents
  • There is no MAC black-list feature, nor is it possible to whitelist a range of MAC addresses.

    If I understand correctly, and you want to allow or disallow connection from a range of MAC addresses, this is not something you can do directly. However, once a device connect and you get the BLE_GAP_EVT_CONNECTED, you get access to the peers MAC address (from p_ble_evt->evt.gap_evt.connected.peer_addr). If this is a device which should not be allowed to stay connected, you can close it immediately by a call to sd_ble_gap_disconnect(), using the connection handle from the event, p_ble_evt->evt.gap_evt.conn_handle.

Reply
  • There is no MAC black-list feature, nor is it possible to whitelist a range of MAC addresses.

    If I understand correctly, and you want to allow or disallow connection from a range of MAC addresses, this is not something you can do directly. However, once a device connect and you get the BLE_GAP_EVT_CONNECTED, you get access to the peers MAC address (from p_ble_evt->evt.gap_evt.connected.peer_addr). If this is a device which should not be allowed to stay connected, you can close it immediately by a call to sd_ble_gap_disconnect(), using the connection handle from the event, p_ble_evt->evt.gap_evt.conn_handle.

Children
  • Well Thank you Einar. Mac address was just an example, it could be something else.

    The point is: is it possible to catch event when the device just connects (before BLE_GAP_EVT_CONNECTED) and cancel connexion plus return an error if I don't want it to connect ?

    Maybe this is too low-level programming...

    Well if my request is impossible, is it possible when I call sd_ble_gap_disconnect() to "tell the device" the reason why I disconnect it ? ... an error like "unauthorized" or something else ?

  • The SoftDevice (which is our closed source BLE stack) will not let the application know about the connection attempt before you get the BLE_GAP_EVT_CONNECTED upon a successful connection, so the answer is no. You cannot get any event about the connection or connection attempt before you get the BLE_GAP_EVT_CONNECTED event.

    They only standard way I could think of to convey something like "unauthorized" is using the HCI status code, which is the second parameter of sd_ble_gap_disconnect(). However, that also may not really be that useful, as you only have two legal values in this case, and the only one that makes sense is BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION.

Related