<?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>Active scanning with enabled filter causes sending SCAN_REQ to every advertiser</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/88589/active-scanning-with-enabled-filter-causes-sending-scan_req-to-every-advertiser</link><description>Hi everybody, 
 
 I saw topics with similar naming like mine, but none of them actually describes my issue. 
 
 I develop some simple scanner and advertiser solution. 
 
 On advertiser side I&amp;#39;ve implemented ADV_SCAN_IND and SCAN_RSP packets. In ADV_SCAN_IND</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 16 Jun 2022 15:06:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/88589/active-scanning-with-enabled-filter-causes-sending-scan_req-to-every-advertiser" /><item><title>RE: Active scanning with enabled filter causes sending SCAN_REQ to every advertiser</title><link>https://devzone.nordicsemi.com/thread/372865?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 15:06:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d438b539-b582-4917-8ed0-d5f23a23573d</guid><dc:creator>Kedlov</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/88589/active-scanning-with-enabled-filter-causes-sending-scan_req-to-every-advertiser/372824#372824"]So if you plan to not bond the devices, how do you plan to transfer the IRK?[/quote]
&lt;p&gt;During post production process when I will have all around 32 or 64 peripherals on big PCB &amp;quot;matrix&amp;quot; and program it with UART/SPI through test pads and spring needles. Also bond information would need to be stored in central, but central should handle hundreds of peripherals so CONFIG_BT_KEYS_OVERWRITE_OLDEST would need to be enabled. If I would perform paring+bonding with every peripheral it will be time consuming, it&amp;#39;s not only about the time to exchange data and create keys, but also to check every peripheral if the bond has been created. Another option would be to switch roles and advertise IRK key from central to all nodes in close area for few seconds, but there will be no confirmation from every node that it received IRK key.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/88589/active-scanning-with-enabled-filter-causes-sending-scan_req-to-every-advertiser/372824#372824"]And why do you need to change addresses in the first place?[/quote]
&lt;p&gt;I think I was misunderstood - I don&amp;#39;t need to change address, I&amp;#39;ve just observed on nRF sniffer that scanner address has changed few times. Maybe at happened only for scanner on mobile phone, but it would be also good for my scanner based on nRF528xx chip to change from time to time.&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/88589/active-scanning-with-enabled-filter-causes-sending-scan_req-to-every-advertiser/372824#372824"]To put you on track, you can use the configuration CONFIG_BT_PRIVACY=y to enable address switching.[/quote]
&lt;p&gt;I already have it turned on, anyway thanks for that hint &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/88589/active-scanning-with-enabled-filter-causes-sending-scan_req-to-every-advertiser/372824#372824"]Not between every advertising packet. If you are not connecting, I don&amp;#39;t see what sort of security this adds.[/quote]
&lt;p&gt;Sure, I don&amp;#39;t want to change address of peripherals, I didn&amp;#39;t write anything like that :) I only wanted to send scan requests only to my peripherals (based on advertising data in first packet) and from peripherals side I want to send scan response only to my central. It&amp;#39;s not about security, I just want to reduce cases when somebody will come with smartphone in range of central and peripherals, will try to act as central/peripheral and will disrupt my data flow. Of course if somebody will come with SDR, then only encrypted connection may help but storing keys for several hundreds of nodes may take a &amp;quot;little&amp;quot; of flash memory ;)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/88589/active-scanning-with-enabled-filter-causes-sending-scan_req-to-every-advertiser/372824#372824"]&lt;span&gt;int&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;bt_id_create&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;bt_addr_le_t&lt;/span&gt;&lt;span&gt; *&lt;/span&gt;&lt;span&gt;addr&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt; *&lt;/span&gt;&lt;span&gt;irk&lt;/span&gt;&lt;span&gt;) from id.c. I think you can use this, and set the IRK to whatever you like (look at the declaration of bt_id_create() in bluetooth.h.&lt;/span&gt;[/quote]
&lt;p&gt;Great! Probably I will use it or something similar for central to get my own IRK key and distribute it to peripherals.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Anyway I think now everything is clear and I will somehow handle it in the code.&lt;/p&gt;
&lt;p&gt;Thank you for help and I think I can close this case :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Active scanning with enabled filter causes sending SCAN_REQ to every advertiser</title><link>https://devzone.nordicsemi.com/thread/372824?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 12:55:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2417c85-4ff0-469d-b41b-ed3c0e67b32e</guid><dc:creator>Edvin</dc:creator><description>[quote user="Kedlov"]&lt;p&gt;- from central point of view - sends scan requests only to &amp;quot;my&amp;quot; peripherals&lt;/p&gt;
&lt;p&gt;- from peripheral point of view - sends scan responses only to &amp;quot;my&amp;quot; centrals&lt;/p&gt;[/quote]
&lt;p&gt;No. That is not possible.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So if you plan to not bond the devices, how do you plan to transfer the IRK? And why do you need to change addresses in the first place? I am not sure whether or not you can set this manually in NCS, but even if you can, you would only be able to change the address every ~15 minutes, or in that order. Not between every advertising packet. If you are not connecting, I don&amp;#39;t see what sort of security this adds.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To put you on track, you can use the configuration CONFIG_BT_PRIVACY=y to enable address switching. You can also try to see if you figure out how the IRK is set using&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;int&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;bt_id_create&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;bt_addr_le_t&lt;/span&gt;&lt;span&gt; *&lt;/span&gt;&lt;span&gt;addr&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt; *&lt;/span&gt;&lt;span&gt;irk&lt;/span&gt;&lt;span&gt;) from id.c. I think you can use this, and set the IRK to whatever you like (look at the declaration of bt_id_create() in bluetooth.h. As long as it is not all zeroes (or a null pointer), you just need the scanner to be aware of the same IRK.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Active scanning with enabled filter causes sending SCAN_REQ to every advertiser</title><link>https://devzone.nordicsemi.com/thread/372285?ContentTypeID=1</link><pubDate>Tue, 14 Jun 2022 07:21:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:377297df-e20a-4ae8-90f9-89f8ffd1a79b</guid><dc:creator>Kedlov</dc:creator><description>&lt;p&gt;Thanks for reply!&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using NCS updated to v2.0.0, based on some example projects generated from &amp;quot;Create a new application from sample&amp;quot; and now I explore most common use case scenarios which would also adjust to my projects&amp;#39; requirements.&lt;/p&gt;
&lt;p&gt;Some of this requirements is:&lt;/p&gt;
&lt;p&gt;- use radio as short as possible (connectionless beacon mode)&lt;/p&gt;
&lt;p&gt;- get information is central node really received data or we should repeat it (data will change in some intervals but we shouldn&amp;#39;t miss any of that data)&lt;/p&gt;
&lt;p&gt;- from central point of view - sends scan requests only to &amp;quot;my&amp;quot; peripherals&lt;/p&gt;
&lt;p&gt;- from peripheral point of view - sends scan responses only to &amp;quot;my&amp;quot; centrals&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/88589/active-scanning-with-enabled-filter-causes-sending-scan_req-to-every-advertiser/372099#372099"]In BLE you have several address types. In private addresses, you can have resolvable or unresolvable addresses. Resolvable addresses means that there is an IRK (Identity Resolving Key), which you can use to figure out whether a seemingly random address actually belongs to a known device or not. [/quote]
&lt;p&gt;Exactly this is what i needed to know, thanks! Actually after tests with some example which used bonding, when my peripheral was bonded with scanner, I was able to see its static private address, so I think that bonding and storing IRK keys are essentials which I need in my peripheral to know which scanner is &amp;quot;my&amp;quot; scanner.&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/88589/active-scanning-with-enabled-filter-causes-sending-scan_req-to-every-advertiser/372099#372099"]What are you using to scan? Is it another nRF chip, a phone? Or something else?[/quote]
&lt;p&gt;I will use nRF chip, for few tests I&amp;#39;ve used phone but scanning performance was too low for me. With scanner on nRF52840 I think I was able to catch almost very first advertising packet every time. Time from starting advertising to send scan response was around 4-15ms (probably depends of current scanning and adv channel)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks to your reply, now I know how to figure out if scan request comes from my scanner.&lt;/p&gt;
&lt;p&gt;Now the issue is following:&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s say I have few hundreds peripheral nodes. Creating bond (by manually clicking some buttons for pairing mode) only to generate IRK keys would be time consuming. Let&amp;#39;s say I could program this keys through wired connection during production or change the roles and central for few seconds would broadcast it&amp;#39;s IRK key to all sensors in close proximity. I saw OOB pairing by using NFC and external antenna but we want to cut piece price for every peripheral node.&lt;/p&gt;
&lt;p&gt;After this long &amp;quot;preamble&amp;quot; here comes my question ;)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Is it possible to manually create/save IRK keys which will be later used to resolve scanner private address?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;For any help, thanks in advance!&lt;/p&gt;
&lt;p&gt;Adam&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Active scanning with enabled filter causes sending SCAN_REQ to every advertiser</title><link>https://devzone.nordicsemi.com/thread/372099?ContentTypeID=1</link><pubDate>Mon, 13 Jun 2022 10:59:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2cc5ea61-7d23-4107-ac96-339776da9056</guid><dc:creator>Edvin</dc:creator><description>[quote user="Kedlov"]&lt;strong&gt;Just to make sure - &lt;/strong&gt;if my device is connectable, I have to send CONNECT_IND after receiving first packet, Trying to establish connection in callback from receiving second packet is pointless, right? Then advertiser would need to send at least 2 adv packets, right?[/quote]
&lt;p&gt;Typically, the flow is that you receive an advertising packet, with or without a scan response (that doesn&amp;#39;t really matter). Then you decide whether you want to connect to it or not. If you want to connect, you will call&amp;nbsp;the API that will connect to the device (which depends on what SDK version you are using. Are you using the nRF5 SDK, or are you using NCS?). When this is called, the scanner will then wait for the next advertising packet from that device, and it will send the connect_ind immediately after receiving the advertisement.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This next part is also dependent on what SDK you are using, but the principle will be the same.&lt;/p&gt;
&lt;p&gt;In BLE you have several address types. In private addresses, you can have resolvable or unresolvable addresses. Resolvable addresses means that there is an IRK (Identity Resolving Key), which you can use to figure out whether a seemingly random address actually belongs to a known device or not. I don&amp;#39;t know exactly how that works on the mathematical level, but the Bluetooth Low Energy stack supports this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What are you using to scan? Is it another nRF chip, a phone? Or something else?&lt;/p&gt;
&lt;p&gt;And what SDK version are you using?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Active scanning with enabled filter causes sending SCAN_REQ to every advertiser</title><link>https://devzone.nordicsemi.com/thread/371671?ContentTypeID=1</link><pubDate>Thu, 09 Jun 2022 12:43:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:28e82173-8642-4aa5-95a8-5b95f3c4b548</guid><dc:creator>Kedlov</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;thank you for your fully explainable response! :) I&amp;#39;m quite new in BLE and in Nordic products, so some obvious stuff is still new to me.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;About sending scan response - you&amp;#39;re right, I forgot that time between receiving first advertising data and sending SCAN_REQ / CONNECT_IND is quite tight (150us).&lt;/p&gt;
&lt;p&gt;Right now I&amp;#39;ve implemented something similar as you suggested. I&amp;#39;ve put simple machine state and &amp;quot;match flags&amp;quot; in &amp;quot;no_match&amp;quot; callback and if data in both received packets is ok, I can determine if it&amp;#39;s my peripherals.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Just to make sure - &lt;/strong&gt;if my device is connectable, I have to send CONNECT_IND after receiving first packet, Trying to establish connection in callback from receiving second packet is pointless, right? Then advertiser would need to send at least 2 adv packets, right?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;From the advertiser device I have small issue with whitelists.&lt;/p&gt;
&lt;p&gt;I would like to response for SCAN_REQ only to &amp;quot;my&amp;quot; centrals. But central can send in SCAN_REQ only it&amp;#39;s own random address. During every scanning &amp;quot;session&amp;quot; scanner will have different (random) address. Let&amp;#39;s say I can send private static address of central during &amp;quot;initial phase&amp;quot;, but it gives me nothing when scanner will send random address in SCAN_REQ.&lt;/p&gt;
&lt;p&gt;How to properly handle it? I saw some article to make pairing and use IRK keys to resolve random address into private address, but I couldn&amp;#39;t find any example for that.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;For any help thanks in advance!&lt;/p&gt;
&lt;p&gt;Adam&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Active scanning with enabled filter causes sending SCAN_REQ to every advertiser</title><link>https://devzone.nordicsemi.com/thread/371152?ContentTypeID=1</link><pubDate>Tue, 07 Jun 2022 12:48:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:21c1ea61-b219-405e-94b7-d2f2a6c36915</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I understand that in your case, you only want to use active scanning if it is one of your own devices, and therefore it is a waste of time to send a scan request for devices that you know aren&amp;#39;t relevant. However, this is the way that bluetooth works. If you enable active scanning (which will send scan requests), then you will send scan requests for all advertising packs that you receive (that claim to have a scan response packet). The reason for this is partly that you don&amp;#39;t have much time between the initial advertisement and the scan request, so there is no time to involve the CPU to decide whether or not to send it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Also, in many cases these filters are used to determine whether you want to connect to a device or not. And in those cases, you may not know whether the data that you are looking for is in the initial advertising packet or in the scan response packet. So you would have to send a scan request even though the initial scan response packet didn&amp;#39;t match the filter.&amp;nbsp;&lt;/p&gt;
[quote user=""]- Can I configure my scanner in a way that it will send SCAN_REQ only to devices which contain correct data in first ADV_SCAN_IND?[/quote]
&lt;p&gt;No&lt;/p&gt;
[quote user=""]- Can I avoid invoking &amp;quot;no filter match&amp;quot; callback for devices which have correct data only in ADV_SCAN_IND packets?[/quote]
&lt;p&gt;No.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am not completely sure what exactly you want to do, but I imagine that you want to use the UUID to find your devices, and then look at the scan response packet from those devices only. Perhaps something like this can work:&lt;/p&gt;
&lt;p&gt;1: save the address of all the devices that match the UUID in the original advertising packet in an array.&lt;/p&gt;
&lt;p&gt;2: Whenever you receive a scan response, see if the address matches any of the addresses in the array, and proceed to interpret the data only if the address is present.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I guess you could add the UUID in your scan response packet as well, but I suspect that the reason you are using a scan response packet in the first place is because you couldn&amp;#39;t fit the UUID and the vendor specific (custom) data in the same advertising packet (but I may be wrong). If you can fit them in the same packet, see if you can fit everything into the initial advertising packet, and then you can skip the scan response packet altogether.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>