ser_dbg_sd_str.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /**
  2. * Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #include "ser_dbg_sd_str.h"
  41. #include "nrf_soc.h"
  42. #include "nrf_log.h"
  43. #include <string.h>
  44. #include "sdk_common.h"
  45. #ifdef BLE_STACK_SUPPORT_REQD
  46. #include "ble_ranges.h"
  47. #endif
  48. #ifdef ANT_STACK_SUPPORT_REQD
  49. #include "ant_interface.h"
  50. #include "ant_parameters.h"
  51. #endif
  52. #if NRF_MODULE_ENABLED(NRF_LOG) && defined(BLE_STACK_SUPPORT_REQD)
  53. static const char * sd_events[] = {
  54. "BLE_EVT_TX_COMPLETE", /*0x01*/
  55. "BLE_EVT_USER_MEM_REQUEST", /*0x02*/
  56. "BLE_EVT_USER_MEM_RELEASE", /*0x03*/
  57. "BLE_EVT_DATA_LENGTH_CHANGED", /*0x04*/
  58. "SD_EVT_UNKNOWN", /*0x05*/
  59. "SD_EVT_UNKNOWN", /*0x06*/
  60. "SD_EVT_UNKNOWN", /*0x07*/
  61. "SD_EVT_UNKNOWN", /*0x08*/
  62. "SD_EVT_UNKNOWN", /*0x09*/
  63. "SD_EVT_UNKNOWN", /*0x0a*/
  64. "SD_EVT_UNKNOWN", /*0x0b*/
  65. "SD_EVT_UNKNOWN", /*0x0c*/
  66. "SD_EVT_UNKNOWN", /*0x0d*/
  67. "SD_EVT_UNKNOWN", /*0x0e*/
  68. "SD_EVT_UNKNOWN", /*0x0f*/
  69. "BLE_GAP_EVT_CONNECTED", /*0x10*/
  70. "BLE_GAP_EVT_DISCONNECTED", /*0x11*/
  71. "BLE_GAP_EVT_CONN_PARAM_UPDATE", /*0x12*/
  72. "BLE_GAP_EVT_SEC_PARAMS_REQUEST", /*0x13*/
  73. "BLE_GAP_EVT_SEC_INFO_REQUEST", /*0x14*/
  74. "BLE_GAP_EVT_PASSKEY_DISPLAY", /*0x15*/
  75. "BLE_GAP_EVT_KEY_PRESxSED", /*0x16*/
  76. "BLE_GAP_EVT_AUTH_KEY_REQUEST", /*0x17*/
  77. "BLE_GAP_EVT_LESC_DHKEY_REQUEST", /*0x18*/
  78. "BLE_GAP_EVT_AUTH_STATUS", /*0x19*/
  79. "BLE_GAP_EVT_CONN_SEC_UPDATE", /*0x1a*/
  80. "BLE_GAP_EVT_TIMEOUT", /*0x1b*/
  81. "BLE_GAP_EVT_RSSI_CHANGED", /*0x1c*/
  82. "BLE_GAP_EVT_ADV_REPORT", /*0x1d*/
  83. "BLE_GAP_EVT_SEC_REQUEST", /*0x1e*/
  84. "BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST", /*0x1f*/
  85. "BLE_GAP_EVT_SCAN_REQ_REPORT", /*0x20*/
  86. "SD_EVT_UNKNOWN", /*0x21*/
  87. "SD_EVT_UNKNOWN", /*0x22*/
  88. "SD_EVT_UNKNOWN", /*0x23*/
  89. "SD_EVT_UNKNOWN", /*0x24*/
  90. "SD_EVT_UNKNOWN", /*0x25*/
  91. "SD_EVT_UNKNOWN", /*0x26*/
  92. "SD_EVT_UNKNOWN", /*0x27*/
  93. "SD_EVT_UNKNOWN", /*0x28*/
  94. "SD_EVT_UNKNOWN", /*0x29*/
  95. "SD_EVT_UNKNOWN", /*0x2a*/
  96. "SD_EVT_UNKNOWN", /*0x2b*/
  97. "SD_EVT_UNKNOWN", /*0x2c*/
  98. "SD_EVT_UNKNOWN", /*0x2d*/
  99. "SD_EVT_UNKNOWN", /*0x2e*/
  100. "SD_EVT_UNKNOWN", /*0x2f*/
  101. "BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP", /*0x30*/
  102. "BLE_GATTC_EVT_REL_DISC_RSP", /*0x31*/
  103. "BLE_GATTC_EVT_CHAR_DISC_RSP", /*0x32*/
  104. "BLE_GATTC_EVT_DESC_DISC_RSP", /*0x33*/
  105. "BLE_GATTC_EVT_ATTR_INFO_DISC_RSP", /*0x34*/
  106. "BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP", /*0x35*/
  107. "BLE_GATTC_EVT_READ_RSP", /*0x36*/
  108. "BLE_GATTC_EVT_CHAR_VALS_READ_RSP", /*0x37*/
  109. "BLE_GATTC_EVT_WRITE_RSP", /*0x38*/
  110. "BLE_GATTC_EVT_HVX", /*0x39*/
  111. "BLE_GATTC_EVT_EXCHANGE_MTU_RSP", /*0x3a*/
  112. "BLE_GATTC_EVT_TIMEOUT", /*0x3b*/
  113. "SD_EVT_UNKNOWN", /*0x3c*/
  114. "SD_EVT_UNKNOWN", /*0x3d*/
  115. "SD_EVT_UNKNOWN", /*0x3e*/
  116. "SD_EVT_UNKNOWN", /*0x3f*/
  117. "SD_EVT_UNKNOWN", /*0x40*/
  118. "SD_EVT_UNKNOWN", /*0x41*/
  119. "SD_EVT_UNKNOWN", /*0x42*/
  120. "SD_EVT_UNKNOWN", /*0x43*/
  121. "SD_EVT_UNKNOWN", /*0x44*/
  122. "SD_EVT_UNKNOWN", /*0x45*/
  123. "SD_EVT_UNKNOWN", /*0x46*/
  124. "SD_EVT_UNKNOWN", /*0x47*/
  125. "SD_EVT_UNKNOWN", /*0x48*/
  126. "SD_EVT_UNKNOWN", /*0x49*/
  127. "SD_EVT_UNKNOWN", /*0x4a*/
  128. "SD_EVT_UNKNOWN", /*0x4b*/
  129. "SD_EVT_UNKNOWN", /*0x4c*/
  130. "SD_EVT_UNKNOWN", /*0x4d*/
  131. "SD_EVT_UNKNOWN", /*0x4e*/
  132. "SD_EVT_UNKNOWN", /*0x4f*/
  133. "BLE_GATTS_EVT_WRITE", /*0x50*/
  134. "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST", /*0x51*/
  135. "BLE_GATTS_EVT_SYS_ATTR_MISSING", /*0x52*/
  136. "BLE_GATTS_EVT_HVC", /*0x53*/
  137. "BLE_GATTS_EVT_SC_CONFIRM", /*0x54*/
  138. "BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST", /*0x55*/
  139. "BLE_GATTS_EVT_TIMEOUT", /*0x56*/
  140. };
  141. static const char * sd_functions[] = {
  142. /* 0x60 offset */
  143. "SD_BLE_ENABLE", /*0x60*/
  144. "SD_BLE_EVT_GET", /*0x61*/
  145. "SD_BLE_UUID_VS_ADD", /*0x62*/
  146. "SD_BLE_UUID_DECODE", /*0x63*/
  147. "SD_BLE_UUID_ENCODE", /*0x64*/
  148. "SD_BLE_VERSION_GET", /*0x65*/
  149. "SD_BLE_USER_MEM_REPLY", /*0x66*/
  150. "SD_BLE_OPT_SET", /*0x67*/
  151. "SD_BLE_OPT_GET", /*0x68*/
  152. "SD_BLE_CFG_SET", /*0x69*/
  153. "SD_UNKNOWN", /*0x6A*/
  154. "SD_UNKNOWN", /*0x6B*/
  155. "SD_BLE_GAP_ADDR_SET" , /*0x6C*/
  156. "SD_BLE_GAP_ADDR_GET" , /*0x6D*/
  157. "SD_BLE_GAP_WHITELIST_SET" , /*0x6E*/
  158. "SD_BLE_GAP_DEVICE_IDENTITIES_SET" , /*0x6F*/
  159. "SD_BLE_GAP_PRIVACY_SET" , /*0x70*/
  160. "SD_BLE_GAP_PRIVACY_GET" , /*0x71*/
  161. "SD_BLE_GAP_ADV_SET_CONFIGURE" , /*0x72*/
  162. "SD_BLE_GAP_ADV_START" , /*0x73*/
  163. "SD_BLE_GAP_ADV_STOP" , /*0x74*/
  164. "SD_BLE_GAP_CONN_PARAM_UPDATE" , /*0x75*/
  165. "SD_BLE_GAP_DISCONNECT" , /*0x76*/
  166. "SD_BLE_GAP_TX_POWER_SET" , /*0x77*/
  167. "SD_BLE_GAP_APPEARANCE_SET" , /*0x78*/
  168. "SD_BLE_GAP_APPEARANCE_GET" , /*0x79*/
  169. "SD_BLE_GAP_PPCP_SET" , /*0x7a*/
  170. "SD_BLE_GAP_PPCP_GET" , /*0x7b*/
  171. "SD_BLE_GAP_DEVICE_NAME_SET" , /*0x7c*/
  172. "SD_BLE_GAP_DEVICE_NAME_GET" , /*0x7d*/
  173. "SD_BLE_GAP_AUTHENTICATE" , /*0x7e*/
  174. "SD_BLE_GAP_SEC_PARAMS_REPLY" , /*0x7f*/
  175. "SD_BLE_GAP_AUTH_KEY_REPLY" , /*0x80*/
  176. "SD_BLE_GAP_LESC_DHKEY_REPLY" , /*0x81*/
  177. "SD_BLE_GAP_KEYPRESS_NOTIFY" , /*0x82*/
  178. "SD_BLE_GAP_LESC_OOB_DATA_GET" , /*0x83*/
  179. "SD_BLE_GAP_LESC_OOB_DATA_SET" , /*0x84*/
  180. "SD_BLE_GAP_ENCRYPT" , /*0x85*/
  181. "SD_BLE_GAP_SEC_INFO_REPLY" , /*0x86*/
  182. "SD_BLE_GAP_CONN_SEC_GET" , /*0x87*/
  183. "SD_BLE_GAP_RSSI_START" , /*0x88*/
  184. "SD_BLE_GAP_RSSI_STOP" , /*0x89*/
  185. "SD_BLE_GAP_SCAN_START" , /*0x8a*/
  186. "SD_BLE_GAP_SCAN_STOP" , /*0x8b*/
  187. "SD_BLE_GAP_CONNECT" , /*0x8c*/
  188. "SD_BLE_GAP_CONNECT_CANCEL " , /*0x8d*/
  189. "SD_BLE_GAP_RSSI_GET" , /*0x8e*/
  190. "SD_BLE_GAP_PHY_UPDATE" , /*0x8f*/
  191. "SD_BLE_GAP_DATA_LENGTH_UPDATE" , /*0x90*/
  192. "SD_BLE_GAP_QOS_CHANNEL_SURVEY_START", /*0x91*/
  193. "SD_BLE_GAP_QOS_CHANNEL_SURVEY_STOP" , /*0x92*/
  194. "SD_UNKNOWN", /*0x93*/
  195. "SD_UNKNOWN", /*0x94*/
  196. "SD_UNKNOWN", /*0x95*/
  197. "SD_UNKNOWN", /*0x96*/
  198. "SD_UNKNOWN", /*0x97*/
  199. "SD_UNKNOWN", /*0x98*/
  200. "SD_UNKNOWN", /*0x99*/
  201. "SD_UNKNOWN", /*0x9A*/
  202. "SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER", /*0x9B*/
  203. "SD_BLE_GATTC_RELATIONSHIPS_DISCOVER", /*0x9C*/
  204. "SD_BLE_GATTC_CHARACTERISTICS_DISCOVER", /*0x9D*/
  205. "SD_BLE_GATTC_DESCRIPTORS_DISCOVER", /*0x9E*/
  206. "SD_BLE_GATTC_ATTR_INFO_DISCOVER", /*0x9F*/
  207. "SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ", /*0xA0*/
  208. "SD_BLE_GATTC_READ", /*0xA1*/
  209. "SD_BLE_GATTC_CHAR_VALUES_READ", /*0xA2*/
  210. "SD_BLE_GATTC_WRITE", /*0xA3*/
  211. "SD_BLE_GATTC_HV_CONFIRM", /*0xA4*/
  212. "SD_BLE_GATTC_EXCHANGE_MTU_REQUEST", /*0xA5*/
  213. "SD_UNKNOWN", /*0xA6*/
  214. "SD_UNKNOWN", /*0xA7*/
  215. "SD_BLE_GATTS_SERVICE_ADD", /*0xA8*/
  216. "SD_BLE_GATTS_INCLUDE_ADD", /*0xA9*/
  217. "SD_BLE_GATTS_CHARACTERISTIC_ADD", /*0xAA*/
  218. "SD_BLE_GATTS_DESCRIPTOR_ADD", /*0xAB*/
  219. "SD_BLE_GATTS_VALUE_SET", /*0xAC*/
  220. "SD_BLE_GATTS_VALUE_GET", /*0xAD*/
  221. "SD_BLE_GATTS_HVX", /*0xAE*/
  222. "SD_BLE_GATTS_SERVICE_CHANGED", /*0xAF*/
  223. "SD_BLE_GATTS_RW_AUTHORIZE_REPLY", /*0xB0*/
  224. "SD_BLE_GATTS_SYS_ATTR_SET", /*0xB1*/
  225. "SD_BLE_GATTS_SYS_ATTR_GET", /*0xB2*/
  226. "SD_BLE_GATTS_INITIAL_USER_HANDLE_GET", /*0xB3*/
  227. "SD_BLE_GATTS_ATTR_GET", /*0xB4*/
  228. "SD_BLE_GATTS_EXCHANGE_MTU_REPLY", /*0xB5*/
  229. };
  230. #endif // NRF_MODULE_ENABLED(NRF_LOG) && defined(BLE_STACK_SUPPORT_REQD)
  231. #ifdef ANT_STACK_SUPPORT_REQD
  232. const char * string[] =
  233. {
  234. "ANT SVC",
  235. "ANT_EVT",
  236. };
  237. #endif // ANT_STACK_SUPPORT_REQD
  238. const char * ser_dbg_sd_call_str_get(uint8_t opcode)
  239. {
  240. #if NRF_MODULE_ENABLED(NRF_LOG)
  241. const char * p_str = "SD_CALL_UNKNOWN";
  242. #ifdef BLE_STACK_SUPPORT_REQD
  243. if (opcode >= BLE_SVC_BASE && opcode <= BLE_GATTS_SVC_LAST)
  244. {
  245. uint32_t idx = opcode-BLE_SVC_BASE;
  246. if (idx < ARRAY_SIZE(sd_functions) )
  247. {
  248. p_str = sd_functions[idx];
  249. }
  250. }
  251. #endif // BLE_STACK_SUPPORT_REQD
  252. #ifdef ANT_STACK_SUPPORT_REQD
  253. // Check if opcode is within the range of the ANT Stack API SVC numbers
  254. #ifdef BLE_STACK_SUPPORT_REQD
  255. else if (opcode >= STK_SVC_BASE_2)
  256. #else
  257. if (opcode >= STK_SVC_BASE_2)
  258. #endif // BLE_STACK_SUPPORT_REQD
  259. {
  260. p_str = string[0];
  261. }
  262. #endif // ANT_STACK_SUPPORT_REQD
  263. else
  264. {
  265. switch (opcode)
  266. {
  267. case SD_ECB_BLOCK_ENCRYPT:
  268. p_str = "SD_ECB_BLOCK_ENCRYPT";
  269. break;
  270. case SD_TEMP_GET:
  271. p_str = "SD_TEMP_GET";
  272. break;
  273. default:
  274. break;
  275. }
  276. }
  277. return p_str;
  278. #else
  279. return NULL;
  280. #endif
  281. }
  282. const char * ser_dbg_sd_evt_str_get(uint16_t opcode)
  283. {
  284. #if NRF_MODULE_ENABLED(NRF_LOG)
  285. const char * p_str = "SD_EVT_UNKNOWN";
  286. #ifdef BLE_STACK_SUPPORT_REQD
  287. if (opcode >= BLE_EVT_BASE && opcode <= BLE_GATTS_EVT_LAST)
  288. {
  289. uint32_t idx = opcode - BLE_EVT_BASE;
  290. if (idx < ARRAY_SIZE(sd_events))
  291. {
  292. p_str = sd_events[idx];
  293. }
  294. }
  295. #endif // BLE_STACK_SUPPORT_REQD
  296. #ifdef ANT_STACK_SUPPORT_REQD
  297. // Check if opcode is within the range of the ANT Stack API SVC numbers
  298. #ifdef BLE_STACK_SUPPORT_REQD
  299. else if (opcode <= EVENT_BLOCKED)
  300. #else
  301. if (opcode <= EVENT_BLOCKED)
  302. #endif // BLE_STACK_SUPPORT_REQD
  303. {
  304. p_str = string[1];
  305. }
  306. #endif
  307. return p_str;
  308. #else
  309. return NULL;
  310. #endif // NRF_MODULE_ENABLED(NRF_LOG)
  311. }