CyBle_GapGetPeerBdAddr Is not returning the correct BLE ID

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

cross mob
Anonymous
Not applicable

For some reason the following code does not return the expected BLE ID from a specific android device.  I've checked in the android "status" screen to find out what the ID should be: A0:CB:FD:7B:CA:67  I'm receiving 65:67:09:96:b4:95  though it seems that between compiles sometimes the value it returns changes I just got 63:c9:63:01:ee:5d for the same device.  It does provide different BLE IDs for different devices and it does seem to be static per device for some set of time.  It's just unreliable.

Following code is used:

        case CYBLE_EVT_GAP_DEVICE_CONNECTED:/*Device connected*/

                /* Enable notifications on the server side */

                {

                    volatile uint8_t addr[CYBLE_GAP_BD_ADDR_SIZE];

                   CYBLE_GATTC_WRITE_CMD_REQ_T write_server;

                    CYBLE_GATT_ERR_CODE_T gattErrCode;

                    uint32_t connected_ble_addr[2];

                    if(CYBLE_ERROR_OK != CyBle_GapGetPeerBdAddr(connHandle.bdHandle, &connected_addr))

                    {

                        printf("Couldn't retrieve peer address.\r\n"); 

                    }

                    addr[0] = connected_addr.bdAddr[0];

                    addr[1] = connected_addr.bdAddr[1];

                    addr[2] = connected_addr.bdAddr[2];

                    addr[3] = connected_addr.bdAddr[3];

                    addr[4] = connected_addr.bdAddr[4];

                    addr[5] = connected_addr.bdAddr[5];

                  

                    connected_ble_addr[0] = addr[5] << 8 | addr[4];

                    connected_ble_addr[1] = addr[3] << 24 | addr[2] << 16 | addr[1] << 8 | addr[0];

                    printf("peer address - %02x:%02x:%02x:%02x:%02x:%02x \r\n",

                            addr[5], addr[4],

                            addr[3], addr[2],

                            addr[1], addr[0]);

               }

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
GyanC_36
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

Hello,

    Please find a sample code example to get the Android/iOS ID address.

-Gyan

View solution in original post

0 Likes
4 Replies
Anonymous
Not applicable

Is "connected_addr" declared somewhere in code? (I will assume yes)

Why not pass the "addr" array pointer instead for debug purposes to ensure the value is being copied to the passed array?

Otherwise, the only thing I can think of without seeing the whole project is that you are passing a pointer to a pointer to the address array where you want the address stored rather than passing the pointer to the array. (mismatch in the number of pointer abstraction levels to the address memory location)

0 Likes
manusharian
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

Hello,

I think the "problem" is the fact that newest Android versions and all iOS devices use a random resolvable address when they connect to a peripheral device and that is why you receive different addresses between connections. I myself have some problems with this but the other way around, when I try to use for my PSoC a private random resolvable address.

Hope this is helpful.

0 Likes
Anonymous
Not applicable

The "random" addresses are part of the random resolveable addresses to implement privacy on newer phones (Otherwise you can track device movement and connections/usage).

Here's a thread that covers working with random resolveable addresses (if the address from the iOS/Android is not resolveable, then there is nothing you can do to deal with authenticating the device based on the address alone)

Whitelist, bonding, random addresses

Here's a thread with some similar information:

Whitelisting with resolvable random address

0 Likes
lock attach
Attachments are accessible only for community members.
GyanC_36
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

Hello,

    Please find a sample code example to get the Android/iOS ID address.

-Gyan

0 Likes