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 Children
  • 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

  • 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

Related