<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to get manufacturer&amp;#39;s data from a received advertising message?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10649/how-to-get-manufacturer-s-data-from-a-received-advertising-message</link><description>In my application, I&amp;#39;m setting a message as manufacturer&amp;#39;s data to be sent with the advertising message. To do that is simple, since I have a data type ble_advdata_t , and I can set a pointer to an object of type ble_advdata_manuf_data_t . 
 But when</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 28 Jan 2019 16:08:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10649/how-to-get-manufacturer-s-data-from-a-received-advertising-message" /><item><title>RE: How to get manufacturer's data from a received advertising message?</title><link>https://devzone.nordicsemi.com/thread/168304?ContentTypeID=1</link><pubDate>Mon, 28 Jan 2019 16:08:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68fc8c6e-89d6-4fca-8841-2303a9edb63f</guid><dc:creator>Igor</dc:creator><description>&lt;p&gt;In NRF SDK 15.2 there is a method&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint8_t * ble_advdata_parse(uint8_t  * p_encoded_data, uint16_t data_len, uint8_t ad_type);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It returns pointer to the specified ad_type.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void ble_evt_handler(ble_evt_t const *p_ble_evt, void *p_context) {
    if (p_ble_evt-&amp;gt;header.evt_id != BLE_GAP_EVT_ADV_REPORT) // is this GAP advertisement?
        return;
    const ble_gap_evt_adv_report_t *p_adv_report = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt.params.adv_report;
    const ble_data_t *data = &amp;amp;p_adv_report-&amp;gt;data;
    uint8_t *mfd_data = ble_advdata_parse(data-&amp;gt;p_data, data-&amp;gt;len, BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA);
    // *mfd_data is a pointer to BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA data
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get manufacturer's data from a received advertising message?</title><link>https://devzone.nordicsemi.com/thread/39720?ContentTypeID=1</link><pubDate>Fri, 04 Dec 2015 18:07:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a51fec8-5be4-46f2-a6a3-8d722850048e</guid><dc:creator>Nildo</dc:creator><description>&lt;p&gt;Thank you, very much. I was going to implement a parser for the advertising myself but this was really handy for me.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get manufacturer's data from a received advertising message?</title><link>https://devzone.nordicsemi.com/thread/39718?ContentTypeID=1</link><pubDate>Fri, 04 Dec 2015 18:06:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:316d0105-6fa9-444b-bd7a-8c2e55d782cf</guid><dc:creator>Nildo</dc:creator><description>&lt;p&gt;Thank you for the explanation. All I really wanted to know was if I was really going to implement it that way.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get manufacturer's data from a received advertising message?</title><link>https://devzone.nordicsemi.com/thread/39719?ContentTypeID=1</link><pubDate>Fri, 04 Dec 2015 14:32:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8b745a6-96ce-4ed1-8e34-20bdaca92369</guid><dc:creator>Anders Strand</dc:creator><description>&lt;p&gt;See the scanning part of the &lt;a href="https://devzone.nordicsemi.com/tutorials/21/"&gt;BLE central tutorial&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Use this function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static uint32_t adv_report_parse(uint8_t type, data_t * p_advdata, data_t * p_typedata)

{
    uint32_t index = 0;
    uint8_t * p_data;

    p_data = p_advdata-&amp;gt;p_data;

    while (index &amp;lt; p_advdata-&amp;gt;data_len)
    {
        uint8_t field_length = p_data[index];
        uint8_t field_type = p_data[index+1];

        if (field_type == type)
        {
            p_typedata-&amp;gt;p_data = &amp;amp;p_data[index+2];
            p_typedata-&amp;gt;data_len = field_length-1;
            return NRF_SUCCESS;
        }
        index += field_length+1;
    }
    return NRF_ERROR_NOT_FOUND;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Call it with type = BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA (0xFF)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get manufacturer's data from a received advertising message?</title><link>https://devzone.nordicsemi.com/thread/39717?ContentTypeID=1</link><pubDate>Thu, 03 Dec 2015 23:15:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9f1a1b2d-548d-4e65-9b3c-00e887b963ae</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;&lt;code&gt;ble_advdata_set()&lt;/code&gt; is only for encoding data and setting it for outgoing advertising, the scan response in that API isn&amp;#39;t a response you got from a scan to be decoded, it&amp;#39;s the data you want to set as advertising data into the scan response you&amp;#39;re going to send out when you advertise yourself. So that&amp;#39;s not going to help you, &lt;code&gt;ble_advdata_set()&lt;/code&gt; is only used to &lt;em&gt;set&lt;/em&gt; advertising data.&lt;/p&gt;
&lt;p&gt;The advertising data is in a very simple format however. It&amp;#39;s .. where length is 1 byte and is the length of the  + , the type is the type, there&amp;#39;s a &lt;a href="https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile"&gt;list here&lt;/a&gt; and in the spec, manufacturer is 0xFF, then it&amp;#39;s data, if there&amp;#39;s another field it&amp;#39;s directly afterwards.&lt;/p&gt;
&lt;p&gt;So all you have to do is start at the beginning, figure out the type of the field which is the second byte, if it&amp;#39;s not advertising you use the length to skip to the next field and do it again until you find your manufacturer data and/or consume the whole buffer. You don&amp;#39;t even need to decode the other fields if you don&amp;#39;t need them, since you have the length, you can skip right over them. If you wrote a function to find data of a specific type and return the address and length, or NULL if it&amp;#39;s not there, it would probably be 3 lines of code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>