<?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>Custom service Characteristic write wrong handle on Samsung</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/26750/custom-service-characteristic-write-wrong-handle-on-samsung</link><description>Hi 
 We have problems with Samsung tablets and phones at the moment. 
 We have an application with two custom services, Secure DFU Service and some standard SIG services, i.e. Battery Service and Device information Service.
We are using nRF52832 with</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 16 Nov 2017 11:29:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/26750/custom-service-characteristic-write-wrong-handle-on-samsung" /><item><title>RE: Custom service Characteristic write wrong handle on Samsung</title><link>https://devzone.nordicsemi.com/thread/105175?ContentTypeID=1</link><pubDate>Thu, 16 Nov 2017 11:29:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81f605df-20db-4d06-93e8-9ad32c64460e</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Jan,&lt;/p&gt;
&lt;p&gt;It&amp;#39;s a very important information you provided: you remove and add Secure DFU service into the att table when you switch between debug and release version. It maybe not a very good idea for testing. Changing attribute table requires the application to send service changed indication. This can cause funny behaviour as you observed. You can see the Samsung phone (which do bonding) try to write to a handle 20 which is 7 from handle 13, most likely because of the missing &amp;quot;secure DFU service&amp;quot;.&lt;/p&gt;
&lt;p&gt;My suggestion is to test with nRFConnect app on the phone, because we do a att table clear everytime you disconnect. Please try not to change the attribute table. Make sure you clear bonding on both the phone and the device before testing.&lt;/p&gt;
&lt;p&gt;If the application requires att table to be changed often, you may consider sending sd_ble_gatts_service_changed() to request the peer to re-do service discovery .&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom service Characteristic write wrong handle on Samsung</title><link>https://devzone.nordicsemi.com/thread/105173?ContentTypeID=1</link><pubDate>Wed, 15 Nov 2017 15:37:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1082130-258e-443a-9a01-f81fff025198</guid><dc:creator>janR</dc:creator><description>&lt;p&gt;Hi Hung,&lt;/p&gt;
&lt;p&gt;Now I managed to get debug out with the error present.&lt;/p&gt;
&lt;p&gt;Write to command characteristic with Samsung SM-T550:&lt;/p&gt;
&lt;p&gt; app: Connected to previously bonded device&lt;/p&gt;
&lt;p&gt; app: Link secured. Role: 1. conn_handle: 0, Procedure: 0&lt;/p&gt;
&lt;p&gt; app: NEB_OnWrite - Handle:20. Current value handle for NEB command characteristics:16&lt;/p&gt;
&lt;p&gt; app: NBS handles:
Service handle:14&lt;/p&gt;
&lt;p&gt; app:    Command char-
Value handle:16
User desc handle:17
CCCD handle:0
SCCD handle:0&lt;/p&gt;
&lt;p&gt; app:    Responce char-
Value handle:19
User desc handle:21
CCCD handle:20
SCCD handle:0&lt;/p&gt;
&lt;p&gt;Write to same command characteristic with Asus Zenpad:&lt;/p&gt;
&lt;p&gt; app: NEB_OnWrite - Handle:13. Current value handle for NEB command characteristics:16&lt;/p&gt;
&lt;p&gt; app: NBS handles:
Service handle:14&lt;/p&gt;
&lt;p&gt; app:    Command char-
Value handle:16
User desc handle:17
CCCD handle:0
SCCD handle:0&lt;/p&gt;
&lt;p&gt; app:    Responce char-
Value handle:19
User desc handle:21
CCCD handle:20
SCCD handle:0&lt;/p&gt;
&lt;p&gt; app: NEB_OnWrite - Handle:16. Current value handle for NEB command characteristics:16&lt;/p&gt;
&lt;p&gt; app: NBS handles:
Service handle:14&lt;/p&gt;
&lt;p&gt; app:    Command char-
Value handle:16
User desc handle:17
CCCD handle:0
SCCD handle:0&lt;/p&gt;
&lt;p&gt; app:    Responce char-
Value handle:19
User desc handle:21
CCCD handle:20
SCCD handle:0&lt;/p&gt;
&lt;p&gt;With Asus Zenpad, the application behaves correctly, with Samsung, the write is to the CCCD handler of another characteristic, the responce characteristic.&lt;/p&gt;
&lt;p&gt;I tried to write several times, same thing happened.&lt;/p&gt;
&lt;p&gt;But, after successful write with the Asus, I was able to do a successful write with the Samsung.
Notice that the service changed indication (0x0D) occurred only with the Asus, not with the Samsung. Could this be the cause of the problem?&lt;/p&gt;
&lt;p&gt;However, believe it or not, I am able to change behaviour of the BLE with changing code (adding and removing debug).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I managed to get debug out with the error present by removing debug code from the NSS service (the other custom service).&lt;/li&gt;
&lt;li&gt;I also changed the behaviour by building a release version. Then the application behaved correctly. Only difference between release and debug version is that NRF_LOG_LEVEL is set to 0 in release, and 5 in debug. (In the release version that works, the NRF_LOG_LEVEL is set to 5). In addition &amp;quot;Secure DFU Service&amp;quot; is enabled in release.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Regards, Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom service Characteristic write wrong handle on Samsung</title><link>https://devzone.nordicsemi.com/thread/105174?ContentTypeID=1</link><pubDate>Wed, 15 Nov 2017 08:51:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ea499bc-48ea-4d23-909a-122f26429b77</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Jan,&lt;/p&gt;
&lt;p&gt;Please specify what&amp;#39;s the different between your debug and release versions ?&lt;/p&gt;
&lt;p&gt;Handle ID = 13 = 0x0D is the service changed indication, so it&amp;#39;s normal that the phone write to that characteristic.&lt;/p&gt;
&lt;p&gt;Procedure is the indication on how the link is encrypted, look for pm_conn_sec_procedure_t you will find it.&lt;/p&gt;
&lt;p&gt;And yes, bonding was done automatically, I&amp;#39;m not sure why, could be that your device has HID characteristic. Or if you connect using Bluetooth setting , the phone will automatically bond.&lt;/p&gt;
&lt;p&gt;Please try to find a way to debug with the release version, simply add some printf shouldn&amp;#39;t cause the change in the behaviour of the handle id to be set.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom service Characteristic write wrong handle on Samsung</title><link>https://devzone.nordicsemi.com/thread/105171?ContentTypeID=1</link><pubDate>Tue, 14 Nov 2017 14:26:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4b6b5d7-61af-42cc-bc13-1a12c3238456</guid><dc:creator>janR</dc:creator><description>&lt;p&gt;I have verified that NRF_SDH_BLE_SERVICE_CHANGED = 1 in both old and new application.
Tablet is restarted (and turned off and then on). It did not help.
Bonding is erased, bluetooth is turned on and off. No help&lt;/p&gt;
&lt;p&gt;I now have added debug out to the cusom services.
But this made the behaviour even stranger; now it started to work again.
The only change was adding debug code.&lt;/p&gt;
&lt;p&gt;Could the behaviour be due to a timing issue somewhere?&lt;/p&gt;
&lt;p&gt;Here is the debug out:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;info&amp;gt; app: Connected
&amp;lt;debug&amp;gt; app: BLE connected
&amp;lt;debug&amp;gt; app: Link secured. Role: 1. conn_handle: 0, Procedure: 1
&amp;lt;debug&amp;gt; app: NEB_OnWrite - Handle:13. Current value handle for NEB command characteristics:16
&amp;lt;debug&amp;gt; app: NSS_OnWrite - Handle:13. Current value handle for NSS command characteristics:24
&amp;lt;debug&amp;gt; app: NEB_OnWrite - Handle:16. Current value handle for NEB command characteristics:16
&amp;lt;debug&amp;gt; app: NSS_OnWrite - Handle:16. Current value handle for NSS command characteristics:24
&amp;lt;info&amp;gt; app: Disconnected
&amp;lt;debug&amp;gt; app: BLE disconnected

&amp;lt;info&amp;gt; app: Connected
&amp;lt;debug&amp;gt; app: BLE connected
&amp;lt;debug&amp;gt; app: Connected to previously bonded device
&amp;lt;debug&amp;gt; app: NEB_OnWrite - Handle:16. Current value handle for NEB command characteristics:16
&amp;lt;debug&amp;gt; app: NSS_OnWrite - Handle:16. Current value handle for NSS command characteristics:24

&amp;lt;info&amp;gt; app: Disconnected
&amp;lt;debug&amp;gt; app: BLE disconnected
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;First connection is right after erasing chip, programming softdevice, and starting application.
I write to one of the characteristic (with value_handle 16) in one of the custom services
I then disconnect, connect, and write to the same characteristics again.
Then I disconnect.&lt;/p&gt;
&lt;p&gt;I noticed that before the first write, a write to an unknown handle (13) is done. I don&amp;#39;t know what this handle belongs to. It is not one of the custom characteristics.
I also noticed that the first connection is different than the second:
1st:  app: Link secured. Role: 1. conn_handle: 0, Procedure: 1
2.nd: app: Link secured. Role: 1. conn_handle: 0, Procedure: 0
Procedure is 1 in the first, and 0 in the second. What is actually this?
And &amp;quot;Connected to previously bonded device&amp;quot; appears on the second connection. I have not asked for any bonding, so this must be done automatically somehow. However, it is possible that this has nothing with the behaviour to do.&lt;/p&gt;
&lt;p&gt;When I build a release of the code (without debug), the problem is still there; I can&amp;#39;t write commands to the device probably because the handle is wrong.&lt;/p&gt;
&lt;p&gt;I know this could be due to too small task stacks (I&amp;#39;m using FreeRTOS), but the task stacks has plenty of room.
I also have the configCHECK_FOR_STACK_OVERFLOW set to 2, without finding anything.&lt;/p&gt;
&lt;p&gt;Regards, Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom service Characteristic write wrong handle on Samsung</title><link>https://devzone.nordicsemi.com/thread/105170?ContentTypeID=1</link><pubDate>Mon, 13 Nov 2017 15:29:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:16c01527-cf7d-4e1d-88aa-e324adb27241</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Have you made sure NRF_SDH_BLE_SERVICE_CHANGED set = 1 in your application (both the old and new) ?&lt;/p&gt;
&lt;p&gt;I also suspect attribute table was cached on the phone. You may want to restart the phone to make sure it would erase cache. But you mentioned that nRF Connect app running on the phone show the correct att table  ? If you add a log to UART to print p_evt_write-&amp;gt;handle , when you try to write to the characteristic from NRFConnect, which handle ID you would receive ? and how would it compare to the correct handle ID ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom service Characteristic write wrong handle on Samsung</title><link>https://devzone.nordicsemi.com/thread/105172?ContentTypeID=1</link><pubDate>Fri, 10 Nov 2017 15:36:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a8caccb2-5e29-4747-89e4-9d97d9d12da9</guid><dc:creator>janR</dc:creator><description>&lt;p&gt;Hi Hung&lt;/p&gt;
&lt;p&gt;I did in fact made an update that added a custom service with one characteristics.&lt;/p&gt;
&lt;p&gt;I verified the handle problem by first placing a breakpoint in the &amp;quot;onWrite&amp;quot; event handler (BLE_GATTS_EVT_WRITE) after the check of the handle
( if (p_evt_write-&amp;gt;handle == p_nbs-&amp;gt;commandHandle.value_handle) )
The code never hits the breakpoint when the error is present.
The breakpoint is hit when using other devices than Samsung.&lt;/p&gt;
&lt;p&gt;If I move the breakpoint before this, the breakpoint is hit, but then the handler is wrong.
It could of course be that the write to the CCCD handler is intended, but the value handler should be written anyway?&lt;/p&gt;
&lt;p&gt;The attribute table appears correct in nRF Connect.&lt;/p&gt;
&lt;p&gt;I have, as you recommended, tested with ble_app_uart, and this application behaves correct on Samsung.&lt;/p&gt;
&lt;p&gt;Anyway it is strange that I only see the problem with Samsung. Now I also have tested with an old Lenovo tablet, and also an old HANNspree tablet (both running Android). Both are working.&lt;/p&gt;
&lt;p&gt;It is maybe worth mentioning that both the Samsung tablets was connectd to the application before the service was added. I now suspect that there is some cached data in the two Samsungs that I can&amp;#39;t get rid of (I have tried unbounding). Could this be true?&lt;/p&gt;
&lt;p&gt;Regards, Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom service Characteristic write wrong handle on Samsung</title><link>https://devzone.nordicsemi.com/thread/105169?ContentTypeID=1</link><pubDate>Fri, 10 Nov 2017 12:04:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9fac243-ee63-497b-a77e-4c981b297e67</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Jan,&lt;/p&gt;
&lt;p&gt;Did you do any DFU update that involve a change of the attribute table ?
How do you verify that the handle value was not correct ?&lt;/p&gt;
&lt;p&gt;When you do service discovery using nRFConnect do you see the correct attribute table ? If you test with a stock example (e.g ble_app_uart) do you see the problem ? ble_app_uart also use customer service.&lt;/p&gt;
&lt;p&gt;Note that the phone may automatically enable notification (write to CCCD), could that be the case when you receive the event ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>