<?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>Change Advertising mask</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/53112/change-advertising-mask</link><description>Hello, 
 I want to change the channel mask of the advertising channels like this 
 m_advertising.adv_params.channel_mask[4] = 0xC0; // only Channel 37 
 and sniff it. 
 I can compile and flash the code but on sniffer the advertiser still send on the three</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 10 Oct 2019 13:05:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/53112/change-advertising-mask" /><item><title>RE: Change Advertising mask</title><link>https://devzone.nordicsemi.com/thread/214379?ContentTypeID=1</link><pubDate>Thu, 10 Oct 2019 13:05:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b364297-a626-4ceb-acb1-0c0316f97b12</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I see that you set channel_mask[4] = 0xC0;&lt;/p&gt;
&lt;p&gt;The channel mask is set up like this (each channel contains 8 bits) :&lt;/p&gt;
&lt;p&gt;channel_mask[0] = [&lt;span&gt;ch 07,&amp;nbsp;&lt;/span&gt;&lt;span&gt;ch 06,&amp;nbsp;&lt;/span&gt;&lt;span&gt;ch 05,&amp;nbsp;&lt;/span&gt;&lt;span&gt;ch 04,&amp;nbsp;&lt;/span&gt;&lt;span&gt;ch 03,&amp;nbsp;&lt;/span&gt;&lt;span&gt;ch 02,&amp;nbsp;&lt;/span&gt;&lt;span&gt;ch 01,&amp;nbsp;&lt;/span&gt;&lt;span&gt;ch 00]&lt;br /&gt;channel_mask[1] = [ch 15,&amp;nbsp;ch 14,&amp;nbsp;ch 13,&amp;nbsp;ch 12,&amp;nbsp;ch 11,&amp;nbsp;ch 10,&amp;nbsp;ch 09,&amp;nbsp;ch 08]&lt;br /&gt;channel_mask[2] = [ch 23,&amp;nbsp;ch 22,&amp;nbsp;ch 21,&amp;nbsp;ch 20,&amp;nbsp;ch 19,&amp;nbsp;ch 18,&amp;nbsp;ch 17,&amp;nbsp;ch 16]&lt;br /&gt;channel_mask[3] = [ch 31,&amp;nbsp;ch 30,&amp;nbsp;ch 29,&amp;nbsp;ch 28,&amp;nbsp;ch 27,&amp;nbsp;ch 26,&amp;nbsp;ch 25,&amp;nbsp;ch 24]&lt;br /&gt;channel_mask[4] = [ch 39,&amp;nbsp;ch 38,&amp;nbsp;ch 37,&amp;nbsp;ch 36,&amp;nbsp;ch 35,&amp;nbsp;ch 34,&amp;nbsp;ch 33,&amp;nbsp;ch 32]&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So if you set channel_mask[4] = 0xC0 = 0b 1100 0000. As you say, this means that channel 39 and 38 is not used, while 37 and the rest of the channels are used.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So far so good.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The issue is that you set&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;m_advertising.adv_params.channel_mask[4] = 0xC0;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;And later you call ble_advertising_start();&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you peek into ble_advertising_start(), you will see that there is a line saying:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;memset(&amp;amp;p_advertising-&amp;gt;adv_params, 0, sizeof(p_advertising-&amp;gt;adv_params));&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This will erase all settings you have written to m_advertising-&amp;gt;adv_params, including the channel_map.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Try to either comment out that line, but then remember to call this before you set the channel map, e.g. in advertising_init, or you can set the channel map after the call to&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;memset(&amp;amp;p_advertising-&amp;gt;adv_params, 0, sizeof(p_advertising-&amp;gt;adv_params));&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;in the ble_advertising_start() function.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I tested it now, and it seems to work.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Please note that I only picked up one packet using the nrf sniffer, but it seems like it is looking for the next advertisement on channel 38. I then tried to program another DK with a central looking for this device, and it was able to connect to the peripheral.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Edvin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Change Advertising mask</title><link>https://devzone.nordicsemi.com/thread/214346?ContentTypeID=1</link><pubDate>Thu, 10 Oct 2019 11:36:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:46c3d6e0-8c62-4e40-b798-f61edab80a4b</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;SDK library manages adv_params on its own, resetting any values you set before. And there&amp;#39;s no handling for channel map in&amp;nbsp;ble_advertising.c. You have to set up advertising directly with softdevice API.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>