ser_dbg_sd_str.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /**
  2. * Copyright (c) 2016 - 2020, 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_USER_MEM_REQUEST", /*0x01*/
  55. "BLE_EVT_USER_MEM_RELEASE", /*0x02*/
  56. "SD_EVT_UNKNOWN", /*0x03*/
  57. "SD_EVT_UNKNOWN", /*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_PRESSED", /*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. "BLE_GAP_EVT_PHY_UPDATE_REQUEST", /*0x21*/
  87. "BLE_GAP_EVT_PHY_UPDATE", /*0x22*/
  88. "BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST", /*0x23*/
  89. "BLE_GAP_EVT_DATA_LENGTH_UPDATE", /*0x24*/
  90. "BLE_GAP_EVT_QOS_CHANNEL_SURVEY_REPORT", /*0x25*/
  91. "BLE_GAP_EVT_ADV_SET_TERMINATED", /*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. "BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE", /*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. "BLE_GATTS_EVT_HVN_TX_COMPLETE", /*0x57*/
  141. };
  142. static const char * sd_functions[] = {
  143. /* 0x60 offset */
  144. "SD_BLE_ENABLE", /*0x60*/
  145. "SD_BLE_EVT_GET", /*0x61*/
  146. "SD_BLE_UUID_VS_ADD", /*0x62*/
  147. "SD_BLE_UUID_DECODE", /*0x63*/
  148. "SD_BLE_UUID_ENCODE", /*0x64*/
  149. "SD_BLE_VERSION_GET", /*0x65*/
  150. "SD_BLE_USER_MEM_REPLY", /*0x66*/
  151. "SD_BLE_OPT_SET", /*0x67*/
  152. "SD_BLE_OPT_GET", /*0x68*/
  153. "SD_BLE_CFG_SET", /*0x69*/
  154. "SD_BLE_UUID_VS_REMOVE", /*0x6A*/
  155. "SD_UNKNOWN", /*0x6B*/
  156. "SD_BLE_GAP_ADDR_SET" , /*0x6C*/
  157. "SD_BLE_GAP_ADDR_GET" , /*0x6D*/
  158. "SD_BLE_GAP_WHITELIST_SET" , /*0x6E*/
  159. "SD_BLE_GAP_DEVICE_IDENTITIES_SET" , /*0x6F*/
  160. "SD_BLE_GAP_PRIVACY_SET" , /*0x70*/
  161. "SD_BLE_GAP_PRIVACY_GET" , /*0x71*/
  162. "SD_BLE_GAP_ADV_SET_CONFIGURE" , /*0x72*/
  163. "SD_BLE_GAP_ADV_START" , /*0x73*/
  164. "SD_BLE_GAP_ADV_STOP" , /*0x74*/
  165. "SD_BLE_GAP_CONN_PARAM_UPDATE" , /*0x75*/
  166. "SD_BLE_GAP_DISCONNECT" , /*0x76*/
  167. "SD_BLE_GAP_TX_POWER_SET" , /*0x77*/
  168. "SD_BLE_GAP_APPEARANCE_SET" , /*0x78*/
  169. "SD_BLE_GAP_APPEARANCE_GET" , /*0x79*/
  170. "SD_BLE_GAP_PPCP_SET" , /*0x7a*/
  171. "SD_BLE_GAP_PPCP_GET" , /*0x7b*/
  172. "SD_BLE_GAP_DEVICE_NAME_SET" , /*0x7c*/
  173. "SD_BLE_GAP_DEVICE_NAME_GET" , /*0x7d*/
  174. "SD_BLE_GAP_AUTHENTICATE" , /*0x7e*/
  175. "SD_BLE_GAP_SEC_PARAMS_REPLY" , /*0x7f*/
  176. "SD_BLE_GAP_AUTH_KEY_REPLY" , /*0x80*/
  177. "SD_BLE_GAP_LESC_DHKEY_REPLY" , /*0x81*/
  178. "SD_BLE_GAP_KEYPRESS_NOTIFY" , /*0x82*/
  179. "SD_BLE_GAP_LESC_OOB_DATA_GET" , /*0x83*/
  180. "SD_BLE_GAP_LESC_OOB_DATA_SET" , /*0x84*/
  181. "SD_BLE_GAP_ENCRYPT" , /*0x85*/
  182. "SD_BLE_GAP_SEC_INFO_REPLY" , /*0x86*/
  183. "SD_BLE_GAP_CONN_SEC_GET" , /*0x87*/
  184. "SD_BLE_GAP_RSSI_START" , /*0x88*/
  185. "SD_BLE_GAP_RSSI_STOP" , /*0x89*/
  186. "SD_BLE_GAP_SCAN_START" , /*0x8a*/
  187. "SD_BLE_GAP_SCAN_STOP" , /*0x8b*/
  188. "SD_BLE_GAP_CONNECT" , /*0x8c*/
  189. "SD_BLE_GAP_CONNECT_CANCEL " , /*0x8d*/
  190. "SD_BLE_GAP_RSSI_GET" , /*0x8e*/
  191. "SD_BLE_GAP_PHY_UPDATE" , /*0x8f*/
  192. "SD_BLE_GAP_DATA_LENGTH_UPDATE" , /*0x90*/
  193. "SD_BLE_GAP_QOS_CHANNEL_SURVEY_START", /*0x91*/
  194. "SD_BLE_GAP_QOS_CHANNEL_SURVEY_STOP" , /*0x92*/
  195. "SD_UNKNOWN", /*0x93*/
  196. "SD_UNKNOWN", /*0x94*/
  197. "SD_UNKNOWN", /*0x95*/
  198. "SD_UNKNOWN", /*0x96*/
  199. "SD_UNKNOWN", /*0x97*/
  200. "SD_UNKNOWN", /*0x98*/
  201. "SD_UNKNOWN", /*0x99*/
  202. "SD_UNKNOWN", /*0x9A*/
  203. "SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER", /*0x9B*/
  204. "SD_BLE_GATTC_RELATIONSHIPS_DISCOVER", /*0x9C*/
  205. "SD_BLE_GATTC_CHARACTERISTICS_DISCOVER", /*0x9D*/
  206. "SD_BLE_GATTC_DESCRIPTORS_DISCOVER", /*0x9E*/
  207. "SD_BLE_GATTC_ATTR_INFO_DISCOVER", /*0x9F*/
  208. "SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ", /*0xA0*/
  209. "SD_BLE_GATTC_READ", /*0xA1*/
  210. "SD_BLE_GATTC_CHAR_VALUES_READ", /*0xA2*/
  211. "SD_BLE_GATTC_WRITE", /*0xA3*/
  212. "SD_BLE_GATTC_HV_CONFIRM", /*0xA4*/
  213. "SD_BLE_GATTC_EXCHANGE_MTU_REQUEST", /*0xA5*/
  214. "SD_UNKNOWN", /*0xA6*/
  215. "SD_UNKNOWN", /*0xA7*/
  216. "SD_BLE_GATTS_SERVICE_ADD", /*0xA8*/
  217. "SD_BLE_GATTS_INCLUDE_ADD", /*0xA9*/
  218. "SD_BLE_GATTS_CHARACTERISTIC_ADD", /*0xAA*/
  219. "SD_BLE_GATTS_DESCRIPTOR_ADD", /*0xAB*/
  220. "SD_BLE_GATTS_VALUE_SET", /*0xAC*/
  221. "SD_BLE_GATTS_VALUE_GET", /*0xAD*/
  222. "SD_BLE_GATTS_HVX", /*0xAE*/
  223. "SD_BLE_GATTS_SERVICE_CHANGED", /*0xAF*/
  224. "SD_BLE_GATTS_RW_AUTHORIZE_REPLY", /*0xB0*/
  225. "SD_BLE_GATTS_SYS_ATTR_SET", /*0xB1*/
  226. "SD_BLE_GATTS_SYS_ATTR_GET", /*0xB2*/
  227. "SD_BLE_GATTS_INITIAL_USER_HANDLE_GET", /*0xB3*/
  228. "SD_BLE_GATTS_ATTR_GET", /*0xB4*/
  229. "SD_BLE_GATTS_EXCHANGE_MTU_REPLY", /*0xB5*/
  230. };
  231. #endif // NRF_MODULE_ENABLED(NRF_LOG) && defined(BLE_STACK_SUPPORT_REQD)
  232. #ifdef ANT_STACK_SUPPORT_REQD
  233. const char * string[] =
  234. {
  235. "ANT SVC",
  236. "ANT_EVT",
  237. };
  238. #endif // ANT_STACK_SUPPORT_REQD
  239. const char * ser_dbg_sd_call_str_get(uint8_t opcode)
  240. {
  241. #if NRF_MODULE_ENABLED(NRF_LOG)
  242. const char * p_str = "SD_CALL_UNKNOWN";
  243. #ifdef BLE_STACK_SUPPORT_REQD
  244. if (opcode >= BLE_SVC_BASE && opcode <= BLE_GATTS_SVC_LAST)
  245. {
  246. uint32_t idx = opcode-BLE_SVC_BASE;
  247. if (idx < ARRAY_SIZE(sd_functions) )
  248. {
  249. p_str = sd_functions[idx];
  250. }
  251. }
  252. #endif // BLE_STACK_SUPPORT_REQD
  253. #ifdef ANT_STACK_SUPPORT_REQD
  254. // Check if opcode is within the range of the ANT Stack API SVC numbers
  255. #ifdef BLE_STACK_SUPPORT_REQD
  256. else if (opcode >= STK_SVC_BASE_2)
  257. #else
  258. if (opcode >= STK_SVC_BASE_2)
  259. #endif // BLE_STACK_SUPPORT_REQD
  260. {
  261. p_str = string[0];
  262. }
  263. #endif // ANT_STACK_SUPPORT_REQD
  264. switch (opcode)
  265. {
  266. case SD_ECB_BLOCK_ENCRYPT:
  267. p_str = "SD_ECB_BLOCK_ENCRYPT";
  268. break;
  269. case SD_TEMP_GET:
  270. p_str = "SD_TEMP_GET";
  271. break;
  272. default:
  273. break;
  274. }
  275. return p_str;
  276. #else
  277. return NULL;
  278. #endif
  279. }
  280. const char * ser_dbg_sd_evt_str_get(uint16_t opcode)
  281. {
  282. #if NRF_MODULE_ENABLED(NRF_LOG)
  283. const char * p_str = "SD_EVT_UNKNOWN";
  284. #ifdef BLE_STACK_SUPPORT_REQD
  285. if (opcode >= BLE_EVT_BASE && opcode <= BLE_GATTS_EVT_LAST)
  286. {
  287. uint32_t idx = opcode - BLE_EVT_BASE;
  288. if (idx < ARRAY_SIZE(sd_events))
  289. {
  290. p_str = sd_events[idx];
  291. }
  292. }
  293. #endif // BLE_STACK_SUPPORT_REQD
  294. #ifdef ANT_STACK_SUPPORT_REQD
  295. // Check if opcode is within the range of the ANT Stack API SVC numbers
  296. #ifdef BLE_STACK_SUPPORT_REQD
  297. else if (opcode <= EVENT_BLOCKED)
  298. #else
  299. if (opcode <= EVENT_BLOCKED)
  300. #endif // BLE_STACK_SUPPORT_REQD
  301. {
  302. p_str = string[1];
  303. }
  304. #endif
  305. return p_str;
  306. #else
  307. return NULL;
  308. #endif // NRF_MODULE_ENABLED(NRF_LOG)
  309. }