<?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>Write with authorization of one byte results in UnlikelyError</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/40952/write-with-authorization-of-one-byte-results-in-unlikelyerror</link><description>Hi, 
 we configure a GATT Server with a characteristic that is configuered for write with authorization. If we then try to write one byte to this characteristic from the client, we get an ErrorResponse with UnlikelyError. 
 The Error seems to be send</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 21 Feb 2019 11:11:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/40952/write-with-authorization-of-one-byte-results-in-unlikelyerror" /><item><title>RE: Write with authorization of one byte results in UnlikelyError</title><link>https://devzone.nordicsemi.com/thread/172279?ContentTypeID=1</link><pubDate>Thu, 21 Feb 2019 11:11:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:594bdb6a-1be3-4830-88c8-bfcd1351f9a6</guid><dc:creator>Niclas Heitz</dc:creator><description>&lt;p&gt;So, we found the error.&lt;/p&gt;
&lt;p&gt;A colleague implemented a new service and checked the length before checking the handle.&lt;/p&gt;
&lt;p&gt;Sorry for the trouble and thanks for all the help.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Niclas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write with authorization of one byte results in UnlikelyError</title><link>https://devzone.nordicsemi.com/thread/160995?ContentTypeID=1</link><pubDate>Mon, 10 Dec 2018 13:13:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:21466e28-59dc-4e56-b3cf-7d9283e64264</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Thank you for the sniffer log.&lt;/p&gt;
&lt;p&gt;Q1) After you get the event&amp;nbsp;&lt;span&gt;BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST, do you call any other sd_* function&amp;nbsp;except for the&amp;nbsp;sd_ble_gatts_rw_authorize_reply() function?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Q2)&amp;nbsp;Are you calling&amp;nbsp;sd_ble_gatts_hvx() ? If yes,&amp;nbsp;under what conditions are you calling it?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write with authorization of one byte results in UnlikelyError</title><link>https://devzone.nordicsemi.com/thread/160769?ContentTypeID=1</link><pubDate>Fri, 07 Dec 2018 14:28:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:91c8df0a-24af-4d54-800d-a5bc19271901</guid><dc:creator>Niclas Heitz</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;thank you for the explanation, since we do a full chip erase before the test on both Client and Server I think we are save.&lt;/p&gt;
&lt;p&gt;to 1)&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/20181121_5F00_WriteResp_5F00_UnlikelyError.zip"&gt;devzone.nordicsemi.com/.../20181121_5F00_WriteResp_5F00_UnlikelyError.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;to 2)&lt;/p&gt;
&lt;p&gt;Since we use a two-chip approach and additionally control the parameters over our testing environment I can&amp;#39;t&amp;nbsp; copy our code directly, but i will try to combine it so you can see how we configure the characteristic:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;ble_gatts_char_md_t char_md;
ble_gatts_attr_md_t cccd_md;
ble_gatts_attr_md_t attr_md;
ble_gatts_attr_t    attr_char_value;
ble_gatts_char_handles_t tmphandles;

memset(&amp;amp;char_md, 0, sizeof(char_md));
memset(&amp;amp;cccd_md,0, sizeof(cccd_md));
memset(&amp;amp;attr_md, 0, sizeof(attr_md));
memset(&amp;amp;attr_char_value, 0, sizeof(attr_char_value));

/*Set CCCD*/
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.read_perm);

cccd_md.write_perm.sm = 1;  
cccd_md.write_perm.lv = 1;
cccd_md.vloc       = BLE_GATTS_VLOC_STACK;

/*Set Char*/
char_md.char_props.broadcast     = 0;
char_md.char_props.read          = 0;
char_md.char_props.write         = 1;
char_md.char_props.write_wo_resp = 0;
char_md.char_props.notify        = 0;
char_md.char_props.indicate      = 1;
char_md.char_props.auth_signed_wr = 0;

char_md.p_char_user_desc = NULL;
char_md.p_char_pf        = NULL;
char_md.p_user_desc_md   = NULL;
char_md.p_cccd_md        = &amp;amp;cccd_md;
char_md.p_sccd_md        = NULL;

/* Set Attr */
attr_md.read_perm.sm = 0;
attr_md.read_perm.lv = 0;
attr_md.write_perm.sm = 1;
attr_md.write_perm.lv = 1;
attr_md.vloc       = BLE_GATTS_VLOC_STACK;
attr_md.vlen       = 1;

attr_md.rd_auth    = 0;
attr_md.wr_auth    = 1;

attr_char_value.p_uuid    = &amp;amp;ble_uuid;
attr_char_value.p_attr_md = &amp;amp;attr_md;
attr_char_value.init_len  = 20;
attr_char_value.init_offs = 0;
attr_char_value.max_len   = 20;
attr_char_value.p_value   = NULL;

err_code = sd_ble_gatts_characteristic_add(service_handle,
      &amp;amp;char_md,
      &amp;amp;attr_char_value,
      &amp;amp;tmphandles);

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;to 3)&lt;/p&gt;
&lt;p&gt;As the UnlikelyError happens indepent of sending the sd_ble_gatts_rw_authorize_reply(). We can see that we are still in a connection, but with sending the ATT-Error we think the authorization request is cancelled. So most likely &amp;quot;no authorization request pending&amp;quot; is the cause of the wrong state. This should be resolved automatically if we can prevent the UnlikelyError.&lt;/p&gt;
&lt;p&gt;to 4)&lt;/p&gt;
&lt;p&gt;As I said, our default usecase is having our own Firmware for Client/Central and Server/Peripheral. Just to be sure we modiefied our tests, so we could use nRFConnect as a Client/Central. This we tried with an Android Phone as well as with PC using a Nordic Dongle.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you,&lt;/p&gt;
&lt;p&gt;Niclas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write with authorization of one byte results in UnlikelyError</title><link>https://devzone.nordicsemi.com/thread/160753?ContentTypeID=1</link><pubDate>Fri, 07 Dec 2018 13:33:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ab452fd-52e3-4288-8e8e-3d372e9833de</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote userid="49718" url="~/f/nordic-q-a/40952/write-with-authorization-of-one-byte-results-in-unlikelyerror/159706"]What exactly does Refresh device cache do with the server? Or is it just something for the nRF Connect Client?[/quote]
&lt;p&gt;&lt;span&gt;Smartphones will typically cache the attributes(service and characteristics) it discovered last time it connected to the BLE device(server). In that way, it doesn&amp;rsquo;t need to do the service discovery procedure each time it connects to a known device. Refresh&amp;nbsp;device cache will clear/refresh this&amp;nbsp;cache.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;1) Do you have a sniffer log showing the sequence of packets leading to this error? (&lt;a href="https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Sniffer/Download#infotabs"&gt;nRF sniffer v2 link&lt;/a&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;2)&lt;/span&gt;&lt;/p&gt;
[quote userid="49718" url="~/f/nordic-q-a/40952/write-with-authorization-of-one-byte-results-in-unlikelyerror"]we configure a GATT Server with a characteristic that is configuered for write with authorization[/quote]
&lt;p&gt;&lt;span&gt;Could you post some code that shows how the service and characteristic&amp;nbsp;is configured?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;3)&lt;/span&gt;&lt;/p&gt;
[quote userid="49718" url="~/f/nordic-q-a/40952/write-with-authorization-of-one-byte-results-in-unlikelyerror/159407"]BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST. If we then send the sd_ble_gatts_rw_authorize_reply we get a wrongState Error[/quote]
&lt;p&gt;From the SD API doc, this means that there is either a &amp;quot;Invalid Connection State or no authorization request pending.&amp;quot;. Could you post the code on how you use the&amp;nbsp;sd_ble_gatts_rw_authorize_reply() ?&lt;/p&gt;
&lt;p&gt;&lt;span&gt;4) You reproduced this with using nRF Connect for desktop as the central ?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write with authorization of one byte results in UnlikelyError</title><link>https://devzone.nordicsemi.com/thread/160337?ContentTypeID=1</link><pubDate>Wed, 05 Dec 2018 10:29:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:59393de2-4340-42eb-8215-87029572bdc7</guid><dc:creator>Niclas Heitz</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;since there was no further answer to my question we tried to refresh the device cache, but it didn&amp;#39;t work.&lt;/p&gt;
&lt;p&gt;If you have any other idea, what could cause this I would be grateful. Please also regard my other reply with the open question on softdevice behaviour.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Niclas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write with authorization of one byte results in UnlikelyError</title><link>https://devzone.nordicsemi.com/thread/159706?ContentTypeID=1</link><pubDate>Fri, 30 Nov 2018 13:00:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aef3aeef-3ae8-43f1-832c-4c10ba0caa5d</guid><dc:creator>Niclas Heitz</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;yes we have enabled service changed.&lt;/p&gt;
&lt;p&gt;We normally use our own Client Firmware to do the write operation and just used nRF Connect to verify it&amp;#39;s not caused by our Client FW. What exactly does Refresh device cache do with the server? Or is it just something for the nRF Connect Client?&lt;/p&gt;
&lt;p&gt;It would cause some hassle to rewrite the code again to work with nRFConnect and through our tests with multiple client-softwares we are confident it&amp;#39;s not caused by the Client behaviour, so I want to make sure.&lt;/p&gt;
&lt;p&gt;Could you maybe also look into the softdevice code what even can cause an Unlikely Error, so we can look at those parts? As the name implies I imagine there can&amp;#39;t be many occurences. Especially since it already triggered the BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST. I would think that all checks are done before sending the event, not after since it gets obsolete if a check fails and the authorisation procedure is canceled.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Niclas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write with authorization of one byte results in UnlikelyError</title><link>https://devzone.nordicsemi.com/thread/159598?ContentTypeID=1</link><pubDate>Thu, 29 Nov 2018 15:05:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b074c823-d717-4da5-9f67-3d139f8a8c71</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Have you enable the Service Changed characteristic? (NRF_SDH_BLE_SERVICE_CHANGED set to 1 in sdk_config)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Could you try to &amp;quot;Refresh device cache&amp;quot; using nRF Connect ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img height="151" src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-a1f55bed06f04de8a1b90da17084a5eb/pastedimage1543503880784v1.png" width="162" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write with authorization of one byte results in UnlikelyError</title><link>https://devzone.nordicsemi.com/thread/159407?ContentTypeID=1</link><pubDate>Wed, 28 Nov 2018 12:16:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1cbc1c71-b66f-4d53-b5aa-10ef3b6d0846</guid><dc:creator>Niclas Heitz</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;we can see the UnlikelyError in the ATT ErrorResponse over Bluetooth and it is reported by the nrfConnect App, when trying to write one byte.&lt;/p&gt;
&lt;p&gt;On the server we get no notification about this error or why it is happening, just the normal BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST. If we then send the sd_ble_gatts_rw_authorize_reply we get a wrongState Error (most likely because the softdevice already ended the authorization request when sending the UnlikelyError).&lt;/p&gt;
&lt;p&gt;Even if we ignore the BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST, the error is sent immediately in the next connection event following the received write request.&lt;/p&gt;
&lt;p&gt;Thanks for looking into it.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Niclas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write with authorization of one byte results in UnlikelyError</title><link>https://devzone.nordicsemi.com/thread/159405?ContentTypeID=1</link><pubDate>Wed, 28 Nov 2018 11:59:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:796a3f4c-7253-4178-9a1f-1312cfe40581</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Where exactly are you&amp;nbsp;receiving this&lt;span&gt;&amp;nbsp;&amp;quot;ErrorResponse with UnlikelyError.&amp;quot; ? What function?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>