<?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>[nRF52833] Peripheral changing IRK while connected, on bonding attempt</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/94506/nrf52833-peripheral-changing-irk-while-connected-on-bonding-attempt</link><description>Hi, 
 I&amp;#39;m working on a legacy program (Peripheral) using nRF52833 and nRF5 SDK using SoftDevice S113. 
 One of the requirements of my peripheral application is that it should automatically reconnect (whenever in range) to only one Central device (the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 06 Dec 2022 07:50:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/94506/nrf52833-peripheral-changing-irk-while-connected-on-bonding-attempt" /><item><title>RE: [nRF52833] Peripheral changing IRK while connected, on bonding attempt</title><link>https://devzone.nordicsemi.com/thread/399097?ContentTypeID=1</link><pubDate>Tue, 06 Dec 2022 07:50:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:383fdc8d-2efd-4304-b1e5-9f185398efa9</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote userid="117078" url="~/f/nordic-q-a/94506/nrf52833-peripheral-changing-irk-while-connected-on-bonding-attempt/399036"]so I could call&amp;nbsp;sd_ble_gap_privacy_set() while handling the Connected BLE GAP event? In other words once the app gets&amp;nbsp;BLE_GAP_EVT_CONNECTED, the state of the connection is now &amp;quot;during&amp;quot; (not &amp;quot;initiating&amp;quot;)[/quote]
&lt;p&gt;Yes, that is what I mean. I must admit I have not tested it, but I see not reason why it should not work. (Both because it should according to the SoftDevice spec, and in Bluetooth the device addresses are not use during a connection. In a connection, the randomly generated &lt;em&gt;access address&lt;/em&gt; is used instead.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [nRF52833] Peripheral changing IRK while connected, on bonding attempt</title><link>https://devzone.nordicsemi.com/thread/399036?ContentTypeID=1</link><pubDate>Mon, 05 Dec 2022 17:29:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68c5ce2a-7b3e-4b95-bf84-c85b47a1e72a</guid><dc:creator>Marco R</dc:creator><description>&lt;p&gt;Thanks for the clarification Einar.&lt;/p&gt;
&lt;p&gt;A couple of follow up questions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;br /&gt;[quote userid="7377" url="~/f/nordic-q-a/94506/nrf52833-peripheral-changing-irk-while-connected-on-bonding-attempt/398930"]Another important point is that the&amp;nbsp;Bluetooth address is not used &lt;em&gt;during&lt;/em&gt; a connection[/quote]&lt;span&gt;You mean that the Bluetooth address is not used (for the purpose of scanning for devices or initiating a connection), after the Peripheral gets&amp;nbsp;BLE_GAP_EVT_CONNECTED, so I could call&amp;nbsp;sd_ble_gap_privacy_set() while handling the Connected BLE GAP event? In other words once the app gets&amp;nbsp;BLE_GAP_EVT_CONNECTED, the state of the connection is now &amp;quot;during&amp;quot; (not &amp;quot;initiating&amp;quot;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;[quote userid="7377" url="~/f/nordic-q-a/94506/nrf52833-peripheral-changing-irk-while-connected-on-bonding-attempt/398930"]instead of the approach you described I would suggest that you change the IRK earlier, before you start advertising in your step 4.[/quote]&lt;span&gt;The problem that I see with that is that if I change IRK when starting advertising after connected to CentralA (last bonded device), then what IRK should be used in step 2 (advertising after boot). If the previous IRK (curr_IRK) is used, CentralA can connect when in range,&amp;nbsp;but if using a newly generated on (new_IRK) then CentralA won&amp;#39;t be able to connect. So advertising with curr_IRK would allow bonded CentralA to connect (and also other Centrals), but changing it&amp;nbsp;on&amp;nbsp;PM_EVT_CONN_SEC_PARAMS_REQ would cause bonds to new Centrals to use the new IRK&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [nRF52833] Peripheral changing IRK while connected, on bonding attempt</title><link>https://devzone.nordicsemi.com/thread/398930?ContentTypeID=1</link><pubDate>Mon, 05 Dec 2022 09:19:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c466f05-ee12-4af9-badf-654e82ca1267</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Marco,&lt;/p&gt;
[quote user=""]1. Is the above approach feasible to meet my requirement (would changing the IRK when attempting bonding with CentralB while CentralA is connected cause any problems with either[/quote]
&lt;p&gt;Yes and no. The general approach is valid, but I would make a small adjustment. First though,&amp;nbsp;pm_privacy_set() essentially just calls&amp;nbsp;sd_ble_gap_privacy_set(), and unfortunately the API documentation of&amp;nbsp;pm_privacy_set() is not entirely correct. The documentation for&amp;nbsp;sd_ble_gap_privacy_set() is though, and states the following (for S132 version 7.2.0):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Set privacy settings.
 *
 * @note  Privacy settings cannot be changed while advertising, scanning or creating a connection.
 *
 * @param[in] p_privacy_params Privacy settings.
 *
 * @mscs
 * @mmsc{@ref BLE_GAP_PRIVACY_ADV_MSC}
 * @mmsc{@ref BLE_GAP_PRIVACY_SCAN_MSC}
 * @mmsc{@ref BLE_GAP_PRIVACY_ADV_DIR_PRIV_MSC}
 * @endmscs
 *
 * @retval ::NRF_SUCCESS Set successfully.
 * @retval ::NRF_ERROR_BUSY The stack is busy, process pending events and retry.
 * @retval ::BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid address type is supplied.
 * @retval ::NRF_ERROR_INVALID_ADDR The pointer to privacy settings is NULL or invalid.
 *                                  Otherwise, the p_device_irk pointer in privacy parameter is an invalid pointer.
 * @retval ::NRF_ERROR_INVALID_PARAM Out of range parameters are provided.
 * @retval ::NRF_ERROR_NOT_SUPPORTED The SoftDevice does not support privacy if the Central Address Resolution
                                     characteristic is not configured to be included and the SoftDevice is configured
                                     to support central roles.
                                     See @ref ble_gap_cfg_car_incl_cfg_t and @ref ble_gap_cfg_role_count_t.
 * @retval ::NRF_ERROR_INVALID_STATE Privacy settings cannot be changed while advertising, scanning
 *                                   or creating a connection.
 */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As you can see, you cannot call&amp;nbsp;sd_ble_gap_privacy_set() (and thus not&amp;nbsp;pm_privacy_set()) while advertising, scanning or &lt;em&gt;initiating&lt;/em&gt; a connection. Another important point is that the&amp;nbsp;Bluetooth address is not used &lt;em&gt;during&lt;/em&gt; a connection. Therefore, instead of the approach you described I would suggest that you change the IRK earlier, before you start advertising in your step 4.&lt;/p&gt;
[quote user=""]&lt;p&gt;2. If the above approach sounds possible, what&amp;#39;s the latest valid AUTH/BLE event that I can use to change the IRK via pm_security_set()&amp;nbsp;before the change is rejected by the SoftDevice? Should it be&amp;nbsp;PM_EVT_CONN_SEC_START,&amp;nbsp;SD_BLE_GAP_AUTHENTICATE,&amp;nbsp;BLE_GAP_EVT_SEC_PARAMS_REQUEST (or other)?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;As mentioned above I would consider doing it a bit differently so that this would not be relevant, but if not, you should update the IRK before calling&amp;nbsp;sd_ble_gap_sec_params_reply() as you can see from this note in the API doc of&amp;nbsp;ble_gap_privacy_params_t:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt; * @note  If the device IRK is updated, the new IRK becomes the one to be distributed in all
 *        bonding procedures performed after @ref sd_ble_gap_privacy_set returns.
 *        The IRK distributed during bonding procedure is the device IRK that is active when @ref sd_ble_gap_sec_params_reply is called.&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The last event you will get before that when using the peer manager library is&amp;nbsp;PM_EVT_CONN_SEC_PARAMS_REQ.&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>