<?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>I can&amp;#39;t write 1 to a protected CCCD</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/38911/i-can-t-write-1-to-a-protected-cccd</link><description>I recently added bonding and authentication to my application. I have two characteristics with CCCDs and they are both broken. One characteristic is &amp;quot;protected&amp;quot; (requires authorization) and the other is not. 
 
 
 
 When I try to enable Indications to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 28 Sep 2018 22:40:11 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/38911/i-can-t-write-1-to-a-protected-cccd" /><item><title>RE: I can't write 1 to a protected CCCD</title><link>https://devzone.nordicsemi.com/thread/150841?ContentTypeID=1</link><pubDate>Fri, 28 Sep 2018 22:40:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0a254d7-4b51-4aee-82a9-cf42cc820ce7</guid><dc:creator>Andrew Ong</dc:creator><description>&lt;p&gt;Thanks Aryan. That helped. I also found out that&amp;nbsp;for my protected characteristic, given the following header:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void on_rw_authorize_req(health_data_service_t * p_service, ble_evt_t const * p_ble_evt)
{
ble_gatts_evt_rw_authorize_request_t const * req = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.authorize_request;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I had to read from&amp;nbsp;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;pre class="ui-code" data-mode="text"&gt;req-&amp;gt;request.write.handle == p_service-&amp;gt;rx_handles.cccd_handle&lt;/pre&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;not&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;p_evt_write-&amp;gt;handle == p_service-&amp;gt;rx_handles.cccd_handle&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Nevermind the question about the unprotected characteristic. I was looking at the wrong characteristic number.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I can't write 1 to a protected CCCD</title><link>https://devzone.nordicsemi.com/thread/150615?ContentTypeID=1</link><pubDate>Thu, 27 Sep 2018 08:00:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4e11610-4424-434c-b783-f969a038e185</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi Andrew,&lt;/p&gt;
&lt;p&gt;There are two types of writes you can do here&lt;/p&gt;
&lt;p&gt;1) The first one is &amp;quot;Write with Authorization&amp;quot; where you will get BLE_GATTS_EVT_WRITE event and the application needs to review the request and write to the characteristic manually using sd_ble_gatts_value_set. You can see the message sequence chart for this &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s140.api.v6.1.0%2Fgroup___b_l_e___g_a_t_t_s___w_r_i_t_e___c_m_d___a_u_t_h___m_s_c.html"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;2) The second one is the &amp;quot;Write Request with Authorization&amp;quot; , where the application will get BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST like you mentioned in your question and you set the characteristic to the requested value (or some other value) and give the response to the peer as a write response. The MSC for this can be seen &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s140.api.v6.1.0%2Fgroup___b_l_e___g_a_t_t_s___w_r_i_t_e___r_e_q___a_u_t_h___m_s_c.html"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Since your BLE handler is getting BLE_GATTS_EVT_WRITE event, this clearly means that the peer is doing a Write command instead of using the Write Request.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s140.api.v6.1.0%2Fgroup___b_l_e___g_a_t_t_c___v_a_l_u_e___w_r_i_t_e___w_i_t_h_o_u_t___r_e_s_p___m_s_c.html"&gt;Write Command from peer&lt;/a&gt;&amp;nbsp;(client)-&amp;gt;&amp;nbsp;&lt;span&gt;BLE_GATTS_EVT_WRITE event on our device (server)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s140.api.v6.1.0%2Fgroup___b_l_e___g_a_t_t_c___v_a_l_u_e___w_r_i_t_e___m_s_c.html"&gt;Write request from peer&lt;/a&gt;&amp;nbsp;(client) -&amp;gt;&amp;nbsp;BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST on our device (server)&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>