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

scanning and decryption of data

I had two nRF52832 where one broadcasts with encrypted data of advertising beacon info and another nRF52832 should only scan without connecting and should decrypt the data of beacon which is broadcasting.

for that what should i do?

please give me any sample code if available

Parents Reply
  • I would recommend you to take a look at the Scanning Module (the ble_app_uart_c example uses this library), to get an understanding of how the scanning works. The function nrf_ble_scan_on_ble_evt(..) receives the BLE scan events, and the advertising packets is redirected to the function nrf_ble_scan_on_adv_report(..) where the contents of the packets is located at the address in p_adv_report.data.p_data. Here you can check the content of the advertising packets, like UUID, Major, Minor, RSSI and so on..

    Best regards,

    Simon

Children
  • the advertising packets is redirected to the function nrf_ble_scan_on_adv_report(..) where the contents of the packets is located at the address in p_adv_report.data.p_data. Here you can check the content of the advertising packets, like UUID, Major, Minor, RSSI and so on..

    can please give me that code which displays all these fields with MAC address also 

  • Hi @Simon

           case BLE_GAP_EVT_ADV_REPORT:
    			
                            {
    				NRF_LOG_INFO("Advertise received");
    				scan_start();
                                    
    
    				
    				memmove(uuid, p_gap_evt->params.adv_report.data.p_data, p_gap_evt->params.adv_report.data.len);
    				
    				NRF_LOG_INFO("UUID: %02x%02x%02x%02x%02x%02x", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5]);
    				
    				NRF_LOG_INFO("TX_POWER: %02x", p_gap_evt->params.adv_report.tx_power);
    				
    				NRF_LOG_INFO("RSSI: %02x", p_gap_evt->params.adv_report.rssi);
                           
    				
    			} break;

    i wrote this code for UUID,RSSI but what i do get MAC Address and MAJOR,MINOR Values?

  • Take a look at the m_beacon_info array in the beacon example:

    static uint8_t m_beacon_info[APP_BEACON_INFO_LENGTH] =                    /**< Information advertised by the Beacon. */
    {
        APP_DEVICE_TYPE,     // Manufacturer specific information. Specifies the device type in this
                             // implementation.
        APP_ADV_DATA_LENGTH, // Manufacturer specific information. Specifies the length of the
                             // manufacturer specific data in this implementation.
        APP_BEACON_UUID,     // 128 bit UUID value.
        APP_MAJOR_VALUE,     // Major arbitrary value that can be used to distinguish between Beacons.
        APP_MINOR_VALUE,     // Minor arbitrary value that can be used to distinguish between Beacons.
        APP_MEASURED_RSSI    // Manufacturer specific information. The Beacon's measured TX power in
                             // this implementation.
    };

    Here you can see in which order the different field is put into the advertising packet.

    Next you can see that this array is sent as «Manufacturer Specific Data»:

    manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info;
    manuf_specific_data.data.size   = APP_BEACON_INFO_LENGTH;

    When you receive the advertising packet, you simply look for the AD type 0xFF (which is the type for Manufacturer Specific Data) and fetch the fields you are interested in, by using the offsets you see in the m_beacon_info array. Here  and here are some useful links that explains how the a BLE advertising packet is structured.

    The address can be found inside p_gap_evt->params.adv_report.peer_addr.addr.

    Best regards,

    Simon

  • Hi @Simon

    Can you give me the code to scan  UUID,RSSI,MAC Address and MAJOR,MINOR Values

    i wrote code to scan the mac address but there is no value displaying

           case BLE_GAP_EVT_ADV_REPORT:
    			
                            {
    				NRF_LOG_INFO("Advertise received");
    				scan_start();
                                    
    
    				
    				memmove(uuid, p_gap_evt->params.adv_report.data.p_data, p_gap_evt->params.adv_report.data.len);
    				
    				NRF_LOG_INFO("UUID: %02x%02x%02x%02x%02x%02x", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5]);
    				
    				NRF_LOG_INFO("TX_POWER: %02x", p_gap_evt->params.adv_report.tx_power);
    				
    				NRF_LOG_INFO("RSSI: %02x", p_gap_evt->params.adv_report.rssi);
                           
                                     ble_gap_addr_t  addr;
    
                                       printf(" Connected to %02x:%02x:%02x:%02x:%02x:%02x", 
                                         addr.addr[5],addr.addr[4],addr.addr[3],
                                         addr.addr[2],addr.addr[1],addr.addr[0],
                                         p_gap_evt->params.adv_report.peer_addr.addr);
    
                                        
    				
    			} break;

    Please help me to solve this problem.

    Thank you

  • Before you read my explanation I would recommend you to read through the links below. The first link explains how the advertising packet is structured. In short, the advertising  packet consist of a set of advertising data elements (AD types):

    Let me explain in more details and go through how the advertising data is set up and decoded on respectively the advertising and scanner side.

    On the peripheral/advertiser side:

    If you open the ble_app_beacon peripheral example and take a look inside the function advertising_init() you can see how the advertising beacon data is set.

    The example uses the ble_advdata library to configure the advertising packet and if you look inside the data structure ble_advdata_t you can see the data types needed to set up the advertising data. 

    In this example, the advertising data is set to contain two data types, specifically a flag and manufacturer specific data. If you look at link 2 you will see that their data types are respectively 0x01 and 0xFF. The flag included is BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED, which equals a value of 0x04 and. The manufacturer specific data includes a company identifier and the user specific data. The company identifier is set to 0x0059 and the actual data is filled with the data in the m_beacon_info array.

    As explained in link 1, the advertising packet is structured in this manner:   

    | Length | AD Type | AD Data | Length | AD Type | AD Data...........

    The beacon advertising packet should then look like this:

    | 0x02 (Length of flag) | 0x01 (flags) | 0x04 (BR_EDR_NOT_SUPPORTED) | 0x1A (Length of manuf. spec. data) | 0xFF (manuf. spec. data) | m_beacon_info[]

    On the central/scanner side:

    I modified the ble_app_uart central example, since it already implement scanning functionality.  Specifically inside the nrf_ble_scan.c library i added the code shown below to the nrf_ble_scan_on_ble_evt() function:

    void nrf_ble_scan_on_ble_evt()
    .
    .
     case BLE_GAP_EVT_ADV_REPORT:
            {
            if(p_adv_report->rssi > -35){
                    uint8_t adv_data[50] = {0};
                    memmove(adv_data, p_adv_report->data.p_data, p_adv_report->data.len);
                    uint8_t count = 0;
                    NRF_LOG_INFO("-----------------------------------------------------");
                    while(count < p_adv_report->data.len + 6){
                        NRF_LOG_INFO("values: %02x | %02x | %02x | %02x | %02x | %02x", adv_data[0+count], adv_data[1+count],   adv_data[2+count],  adv_data[3+count],  adv_data[4+count],  adv_data[5+count]);                 
                        count = count + 6;
                    }
                    NRF_LOG_INFO("-----------------------------------------------------");
                }
            .
            .
            .

    The output I got was the following:

    <info> ble_scan: values: 02 | 01 | 04 | 1A | FF | 59
    <info> ble_scan: values: 00 | 02 | 15 | 01 | 12 | 23
    <info> ble_scan: values: 34 | 45 | 56 | 67 | 78 | 89
    <info> ble_scan: values: 9A | AB | BC | CD | DE | EF
    <info> ble_scan: values: F0 | 01 | 02 | 03 | 04 | C3
    <info> ble_scan: values: 00 | 00 | 00 | 00 | 00 | 00

    Which matches the assumptions made above.

    The beacon UUID and the MINOR and MAJOR values are located inside the manufacturer specific data, and if you look inside the m_beacon_info array inside the ble_app_beacon example you can see that the UUID is on position 3 while the MAJOR and MINOR values are located on position 4 and 5 respectively.

    In order to get the UUID and the MINOR and MAJOR values , you first need to look for the field 0xFF inside the advertising data, then you need to know what offset/position the different values are located. In the code snippet I provided I also showed how to get the RSSI and the address is, as mentioned, inside the field p_gap_evt->params.adv_report.peer_addr.addr.

    Best regards,

    Simon

Related