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

Equality condition always returns True when using manufacturer specific data

Hello,

I have been trying to have a central/peripheral device read UUIDs and RSSI values from surrounding peripherals using their advertisements and without actually connecting to them,

I have modified a part of the ble blinky client code from nRF5 SDK11.0 for the following snippet:

/**@brief Function for handling the advertising report BLE event.
 *
 * @param[in] p_ble_evt  Bluetooth stack event.
 */
static void on_adv_report(const ble_evt_t * const p_ble_evt)
{
    uint32_t err_code;
    data_t   adv_data;
    //bool     do_connect = false;
    data_t   dev_uuid;

    // For readibility.
    const ble_gap_evt_t * const  p_gap_evt  = &p_ble_evt->evt.gap_evt;
    //const ble_gap_addr_t * const peer_addr  = &p_gap_evt->params.adv_report.peer_addr;
       
        // Initialize advertisement report for parsing
        adv_data.p_data     = (uint8_t *)p_gap_evt->params.adv_report.data;
        adv_data.data_len   = p_gap_evt->params.adv_report.dlen;
				int8_t dev_rssi=p_gap_evt->params.adv_report.rssi;

        //search for advertising names
       // bool found_uuid = false;
        err_code = adv_report_parse(BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA,
                                    &adv_data,
                                    &dev_uuid);
        if (err_code != NRF_SUCCESS)
        {
					// If we can't parse the data, then exit
                return;
        }
        else
        {			if((dev_uuid.p_data[2]==0x02) && (dev_uuid.p_data[3]==0x15) && (dev_uuid.data_len==25)) //To check if the device is a beacon (iBeacon) (This is the condition that somehow always evaluates to True)
							{
								dev_uuid.p_data=&dev_uuid.p_data[4];    //This is the pointer to the byte where the UUID is supposed to start in Manufacturer specific data
								dev_uuid.data_len=16;       //length of UUID
								node *temp=create(dev_uuid,dev_rssi);	//creates a temporary note to store data and returns pointer to that node.
								addtolist(temp);		//adds a node to linked list of nodes at the end. 
							}
				}
			
}

I have observed However that, even devices with are not beacons (i.e they dont have 0x02 and 0x15 at 3rd and 4th byte) are added to the linked list and whatever data is present at the 4th - 20th byte for their packet are added into their respective node.

Here are some examples of the devices I am talking about:

   The kind of device I don't want in the list, but gets added anyways.

    The kind of device I want to get added to the list (Works fine)

Please suggest solutions for my problem. I can't see any logical/syntactical mistake in my method.

Thank you.

Parents
  • Hello,

    Notice that when the advertising data contains the type BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA, dev_uuid.p_data is set to point to  the p_gap_evt->params.adv_report.data.

    p_gap_evt->params.adv_report.data will be replaced every time there is a new BLE_GAP_EVT_ADV_REPORT event. And every time there is "match" (next time adv_report_parse finds BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA in an advertising report), the pointer will point to the data in the advertising report.

    That means that the dev_uuid.p_data may have been correct when you first added it to your list, but later when you inspect the list, the pointers point to different data.

    I can't see the inner workings of the create function so maybe you already took care of this (copy the data itself instead of just storing the pointer).

     

Reply Children
No Data
Related