Replies: 2 comments
-
Hello, sadly I don't have an answer for you but right now im kinda struggeling with the same Problem. Can you tell me how you even got the scan response data. I am able to read the advertising data, but I cant find a way to get the scan response even if I put the scan in active mode. I also did't really find something in the docu of Zephyr. Thank you for your help!! |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi Zerberstian,
Find attached what I use. No support but it works for me with zephyr 2.4.0.
Hope this will help you.
Regards,
Thierry
De : Zerberstian ***@***.***
Envoyé : mercredi 23 mars 2022 16:32
À : zephyrproject-rtos/zephyr
Cc : LAMOTTE Thierry; Author
Objet : Re: [zephyrproject-rtos/zephyr] Bluetooth: how an active scanner can retrieve scan response data linked to a certain listened MAC address? (Discussion #30383)
Hello, sadly I don't have an answer for you but right now im kinda struggeling with the same Problem. Can you tell me how you even got the scan response data. I am able to read the advertising data, but I cant find a way to get the scan response even if I put the scan in active mode. I also did't really find something in the docu of Zephyr.
Thank you for your help!!
—
Reply to this email directly, view it on GitHub<#30383 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AHBSE3UVEEV7WLSIVQDAFX3VBM2OBANCNFSM4UKIGWMA>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
// ----------------------------------------------------------------------------
char *ble_get_scan_response_data_as_string(uint8_t device_state, uint8_t device_status)
{
char* str_pt;
if (ble_is_connected()==true)
{
target_infos.scan_response_data[1]=(uint8_t)device_state;
target_infos.scan_response_data[2]=(uint8_t)device_status;
str_pt = conv2str((uint8_t*)&target_infos.scan_response_data[0], target_infos.scan_response_data_len);
}
else
{
char tmpscanresp[25]={0x41, device_state, device_status}; // short one
str_pt = conv2str((uint8_t*)&tmpscanresp[0], 3);
}
return (char*)DEVICE_SCAN_RESP_DATA_IN_ASCII_BUFFER;
}
// ----------------------------------------------------------------------------
int ble_get_rssi_as_int(void)
{
return target_infos.rssi;
}
// ----------------------------------------------------------------------------
char *conv2str(uint8_t *pt, uint8_t len)
{
char tempstr[ADV_MAXSIZE]="";
memset(DEVICE_SCAN_RESP_DATA_IN_ASCII_BUFFER, 0, sizeof(DEVICE_SCAN_RESP_DATA_IN_ASCII_BUFFER));
for (int i=0;i<len;i++, pt++)
{
snprintk((char*)tempstr, (size_t)ADV_MAXSIZE, "%02X", (uint8_t)*pt);
strcat((char*)DEVICE_SCAN_RESP_DATA_IN_ASCII_BUFFER,(char*)tempstr);
}
return (char*)DEVICE_SCAN_RESP_DATA_IN_ASCII_BUFFER;
}
// ----------------------------------------------------------------------------
static uint8_t* get_complete_name(uint8_t *buf_pt)
{
// parse the adv (LEN, TYPE, VALUE) fields
for (uint8_t len=*buf_pt; len<ADV_MAXSIZE; )
{
len = *buf_pt;
if (*(buf_pt+1)==BT_DATA_NAME_COMPLETE) // looking for type complet name only
{
return (uint8_t*)(buf_pt+2); // point to start address of the complete name
}
// jump to the next adv (LEN, TYPE, VALUE) field
buf_pt+=len+1;
}
return (uint8_t*)0;
}
// ----------------------------------------------------------------------------
static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
struct net_buf_simple *ad)
{
char addr_str[BT_ADDR_LE_STR_LEN];
uint8_t zero_val[6]={0,0,0,0,0,0};
if ((default_conn) || (strcmp(BLE_TARGET_NAME,"")==0))
{
return;
}
// only close devices
if (rssi < -70)
{
return;
}
/* We're only interested in connectable events */
if ( type != BT_GAP_ADV_TYPE_ADV_IND
&& type != BT_GAP_ADV_TYPE_ADV_DIRECT_IND
&& type != BT_GAP_ADV_TYPE_SCAN_RSP)
{
return;
}
if (type == BT_GAP_ADV_TYPE_SCAN_RSP)
{
if ( (memcmp((void*)target_infos.mac_addr.a.val, zero_val, sizeof(bt_addr_t))!=0) // i.e. has been init at least once
&& (memcmp((void*)&target_infos.mac_addr, addr, sizeof(bt_addr_le_t))==0)// Scan Resp correspond to our target complete name
)
{
bt_addr_le_to_str(addr, addr_str, sizeof(addr_str));
// Keep a copy of the scan response data
memset((void*)target_infos.scan_response_data, 0, sizeof(target_infos.scan_response_data));
if (ad->len<=sizeof(target_infos.scan_response_data))
{
char* str_pt;
memcpy((void*)&target_infos.scan_response_data[0], (void*)&ad->data[6], ad->len-6);
target_infos.scan_response_data_len = ad->len-6;
str_pt = conv2str((uint8_t*)&target_infos.scan_response_data[0], target_infos.scan_response_data_len);
/*
...
*/
}
ble_request_delayed_connection(false);
}
}
else
{
uint8_t *ptto_crt_complete_name = get_complete_name((uint8_t*)&ad->data[0]);
if (
(ptto_crt_complete_name!=(void*)0)
&& (strstr((void*)ptto_crt_complete_name, (void*)BLE_TARGET_NAME )!=NULL)
)
{
bt_addr_le_to_str(addr, addr_str, sizeof(addr_str));
/*
...
*/
// Keep a copy of the MAC address to be used & checked by the Scan Response use case
memcpy((void*)&target_infos.mac_addr, addr, sizeof(bt_addr_le_t));
target_infos.rssi=rssi;
}
}
}
// ----------------------------------------------------------------------------
static void start_scan(bool reinit_dbg_retry_limit)
{
int err;
memset((void*)&target_infos,0,sizeof(target_infos_type));
//bt_le_scan_cb_register(&cb);
/* We require active scan to retrieve scan response data*/
bt_le_scan_stop();
err = bt_le_scan_start(BT_LE_SCAN_ACTIVE, device_found);
if (err) {
printk("Scanning failed to start (err %d)\n", err);
return;
}
printk("Scanning successfully started\n");
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi
I am struggling with Bluetooth API :
I am developing an active scanner that listens to a certain device complete name and it must continuously retrieve the corresponding scan response data of this device advertivements.
I am acostumized to work with Nordic nRF52 chips and nRF SDK where I could do it easily with the event BLE_GAP_EVT_ADV_REPORT and the p_gap_evt->params.adv_report in which both advertised data and scan response data are present. Using Zephyr API I do not find the way to do the same thing.
I could achieve in retrieving scan response data using a callback data_cb() but I do not known to which MAC address these data are link to?
Is anyone could help on that?
Thanks in advance,
Best regards,
Thierry
Beta Was this translation helpful? Give feedback.
All reactions