Bluetooth authentication by MAC in HID mouse example

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Bartek
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

Hello,

I try to get MAC adres of device ( example laptop)  that want connect to Bluetooth mouse that is implemented from cypress example on CYPROTO-06-BLE kit. When I get MAC I would like compare it form one that is in memory and if its match allow to connect. I think some code should be add in event:

case CY_BLE_EVT_GAP_AUTH_REQ:

But I don't know how to read MAC of device that want to connect and how to allow or disallow for connection.

Does anyone know how to do it ? I will be very thankful.

Regards,

Bartek

0 Likes
1 Solution
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi Bartek,

You can find the MAC address of the peer device in the CY_BLE_EVT_GAP_DEVICE_CONNECTED event itself. The event parameter for the CY_BLE_EVT_GAP_DEVICE_CONNECTED event is of type cy_stc_ble_gap_connected_param_t which has the peer device's address. So you can use some local flag to identify if the connected device is unwanted and then reject the authentication.

Hope this information helps. Please update if you need more information.

Thanks

Ganesh

View solution in original post

0 Likes
6 Replies
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi Bartek,

On the peripheral side, you can set the Filter policy as Scan request: Any, Connect Request: Whitelist

Once this setting is set, you can add the Laptop address to Whitelist using the API Cy_BLE_AddDeviceToWhiteList () so that the peripheral accepts connection only from those devices added to the whitelist. Please refer to peripheral driver library BLE API documentation for more information.

Thanks and regards

Ganesh

0 Likes
Bartek
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

Thank you. It is very helpful.

Do you know if there is possibility to have "black list". It means to allow to connect every one, but only reject connection from some devices ?

0 Likes
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi,

Sorry. The blacklist is not directly possible to implement in the BLE application. You need to manually create it. Also, you do not have any control over the connection with "blacklisted" devices. You can only reject the authentication by not calling the API CyBle_AuthReqReply() when the event CY_BLE_EVT_GAP_AUTH_REQ triggers.

Thanks and regards

Ganesh

0 Likes
Bartek
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

Hello,

Do you know if it is possible and how to check peer device mac adres or name in  event  CY_BLE_EVT_GAP_AUTH_REQ in order to compare with ma custom black list ?

Regards,

Bartek 

0 Likes
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi Bartek,

You can find the MAC address of the peer device in the CY_BLE_EVT_GAP_DEVICE_CONNECTED event itself. The event parameter for the CY_BLE_EVT_GAP_DEVICE_CONNECTED event is of type cy_stc_ble_gap_connected_param_t which has the peer device's address. So you can use some local flag to identify if the connected device is unwanted and then reject the authentication.

Hope this information helps. Please update if you need more information.

Thanks

Ganesh

0 Likes

It works ! Thank you 🙂 You help me a lot.

I add lines in event to check :

.......

case CY_BLE_EVT_GAP_DEVICE_CONNECTED:
DBG_PRINTF("MAC = %d %d %d %d %d %d\r\n",
(*(cy_stc_ble_gap_connected_param_t *)eventParam).peerAddr[0],
(*(cy_stc_ble_gap_connected_param_t *)eventParam).peerAddr[1],
(*(cy_stc_ble_gap_connected_param_t *)eventParam).peerAddr[2],
(*(cy_stc_ble_gap_connected_param_t *)eventParam).peerAddr[3],
(*(cy_stc_ble_gap_connected_param_t *)eventParam).peerAddr[4],
(*(cy_stc_ble_gap_connected_param_t *)eventParam).peerAddr[5]);

......

0 Likes