cancel
Showing results for 
Search instead for 
Did you mean: 

BLE extended advertising parsing

Hardik02
Associate II

 

Hello Team ST,

I am currently working on parsing my extended BLE data using the BLE_p2pClient_Ext application, specifically the `analyse_ext_adv_report` function to view the advertising data. However, I am having trouble parsing and appending the full extended advertising data. Could you please assist me with this issue?

Thank you in advance.

Here is my modified function.

 

 

 

static uint8_t analyse_ext_adv_report(hci_le_extended_advertising_report_event_rp0 *p_ext_adv_report) {
    uint8_t status;
    
    if ((display_filter != 0) && HAL_IS_BIT_SET(p_ext_adv_report->Event_Type, 0x0010)) {
        status = 1;
    } else {
        status = 0;
        
        l_buff_pos = 0;
        memset(&l_buff[l_buff_pos], 0, L_BUFF_SIZE);

        l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE - l_buff_pos, 
                                "%02X:%02X:%02X:%02X:%02X:%02X | ", 
                                p_ext_adv_report->Address[5], p_ext_adv_report->Address[4],
                                p_ext_adv_report->Address[3], p_ext_adv_report->Address[2],
                                p_ext_adv_report->Address[1], p_ext_adv_report->Address[0]);

        // Check for legacy or extended advertisement
        if (HAL_IS_BIT_SET(p_ext_adv_report->Event_Type, 0x0010)) {
            l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE, "LEGACY   |");
        } else {
            l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE, "EXTENDED |");
        }

        l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE - l_buff_pos, "%4d | ", (int8_t)p_ext_adv_report->RSSI);
        
        // Connection and scanning status
        if (HAL_IS_BIT_SET(p_ext_adv_report->Event_Type, 0x0001)) {
            l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE - l_buff_pos, "CONN |");
        } else {
            l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE - l_buff_pos, "     |");
        }

        if (HAL_IS_BIT_SET(p_ext_adv_report->Event_Type, 0x0002)) {
            if (HAL_IS_BIT_SET(p_ext_adv_report->Event_Type, 0x0008)) {
                l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE - l_buff_pos, "SCAN RSP |");
            } else {
                l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE - l_buff_pos, "SCAN     |");
            }
        } else {
            l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE - l_buff_pos, "         |");
        }

        l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE - l_buff_pos, "%3d | ", p_ext_adv_report->Data_Length);

        if (p_ext_adv_report->Advertising_SID != 0xFF) {
            l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE - l_buff_pos, "%2d | ", p_ext_adv_report->Advertising_SID);
        }

        if (HAL_IS_BIT_SET(p_ext_adv_report->Event_Type, 0x0020)) {
            l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE - l_buff_pos, "more data   | ");
        } else if (HAL_IS_BIT_SET(p_ext_adv_report->Event_Type, 0x0040)) {
            l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE - l_buff_pos, "trunc data | ");
        } else {
            /* Nothing to do */
        }

        // Extended advertisement and non-connectable/non-scannable advertisements
        if (!(HAL_IS_BIT_SET(p_ext_adv_report->Event_Type, 0x0010)) && // Extended
            !(HAL_IS_BIT_SET(p_ext_adv_report->Event_Type, 0x0001)) && // Non-connectable
            !(HAL_IS_BIT_SET(p_ext_adv_report->Event_Type, 0x0002))) { // Non-scannable

            uint8_t i = 0, adtype, adlength;
            l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE - l_buff_pos, "ADV Data: ");

            // Loop through the entire advertising data
            while (i < p_ext_adv_report->Data_Length) {
                adlength = p_ext_adv_report->Data[i];
                adtype = p_ext_adv_report->Data[i + 1];

                // Print each chunk of advertising data in hex
                for (uint8_t j = 0; j < adlength + 1; j++) {
                    l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE - l_buff_pos, "%02X ", p_ext_adv_report->Data[i + j]);
                }
                i += adlength + 1;
            }
        }

        l_buff_pos += snprintf(&l_buff[l_buff_pos], L_BUFF_SIZE - l_buff_pos, "\n");

        // Debug output for the full advertising data
        APP_DBG_MSG("%s", l_buff);
    }
    
    return status;
}

 

 

 

 

2 REPLIES 2
STTwo-32
ST Employee

Hello @Hardik02 

For more information about the Extended advertising on the STM32WB/WBA, you can check this wiki

You can also have a look at the implementation on these examples. It should help you to understand what to do.

Best Regards.

STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello,

I have gone through each example provided by you, but this can not solve my problem. 

regards