No Description

aci_cmds.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /* Copyright (c) 2014, Nordic Semiconductor ASA
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in all
  11. * copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19. * SOFTWARE.
  20. */
  21. /**
  22. * @file
  23. *
  24. * @ingroup aci
  25. *
  26. * @brief Definitions for the ACI (Application Control Interface) commands
  27. * @remarks
  28. *
  29. */
  30. #ifndef ACI_CMDS_H__
  31. #define ACI_CMDS_H__
  32. #include "aci.h"
  33. /**
  34. * @enum aci_cmd_opcode_t
  35. * @brief ACI command opcodes
  36. */
  37. typedef enum
  38. {
  39. /**
  40. * Enter test mode
  41. */
  42. ACI_CMD_TEST = 0x01,
  43. /**
  44. * Echo (loopback) test command
  45. */
  46. ACI_CMD_ECHO = 0x02,
  47. /**
  48. * Send a BTLE DTM command to the radio
  49. */
  50. ACI_CMD_DTM_CMD = 0x03,
  51. /**
  52. * Put the device to sleep
  53. */
  54. ACI_CMD_SLEEP = 0x04,
  55. /**
  56. * Wakeup the device from deep sleep
  57. */
  58. ACI_CMD_WAKEUP = 0x05,
  59. /**
  60. * Replace the contents of the internal database with
  61. * user provided data
  62. */
  63. ACI_CMD_SETUP = 0x06,
  64. /**
  65. * Read the portions of memory required to be restored after a power cycle
  66. */
  67. ACI_CMD_READ_DYNAMIC_DATA = 0x07,
  68. /**
  69. * Write back the data retrieved using ACI_CMD_READ_DYNAMIC_DATA
  70. */
  71. ACI_CMD_WRITE_DYNAMIC_DATA = 0x08,
  72. /**
  73. * Retrieve the device's version information
  74. */
  75. ACI_CMD_GET_DEVICE_VERSION = 0x09,
  76. /**
  77. * Request the Bluetooth address and its type
  78. */
  79. ACI_CMD_GET_DEVICE_ADDRESS = 0x0A,
  80. /**
  81. * Request the battery level measured by nRF8001
  82. */
  83. ACI_CMD_GET_BATTERY_LEVEL = 0x0B,
  84. /**
  85. * Request the temperature value measured by nRF8001
  86. */
  87. ACI_CMD_GET_TEMPERATURE = 0x0C,
  88. /**
  89. * Write to the local Attribute Database
  90. */
  91. ACI_CMD_SET_LOCAL_DATA = 0x0D,
  92. /**
  93. * Reset the baseband and radio and go back to idle
  94. */
  95. ACI_CMD_RADIO_RESET = 0x0E,
  96. /**
  97. * Start advertising and wait for a master connection
  98. */
  99. ACI_CMD_CONNECT = 0x0F,
  100. /**
  101. * Start advertising and wait for a master connection
  102. */
  103. ACI_CMD_BOND = 0x10,
  104. /**
  105. * Start advertising and wait for a master connection
  106. */
  107. ACI_CMD_DISCONNECT = 0x11,
  108. /**
  109. * Throttles the Radio transmit power
  110. */
  111. ACI_CMD_SET_TX_POWER = 0x12,
  112. /**
  113. * Trigger a connection parameter update
  114. */
  115. ACI_CMD_CHANGE_TIMING = 0x13,
  116. /**
  117. * Open a remote pipe for data reception
  118. */
  119. ACI_CMD_OPEN_REMOTE_PIPE = 0x14,
  120. /**
  121. * Transmit data over an open pipe
  122. */
  123. ACI_CMD_SEND_DATA = 0x15,
  124. /**
  125. * Send an acknowledgment of received data
  126. */
  127. ACI_CMD_SEND_DATA_ACK = 0x16,
  128. /**
  129. * Request data over an open pipe
  130. */
  131. ACI_CMD_REQUEST_DATA = 0x17,
  132. /**
  133. * NACK a data reception
  134. */
  135. ACI_CMD_SEND_DATA_NACK = 0x18,
  136. /**
  137. * Set application latency
  138. */
  139. ACI_CMD_SET_APP_LATENCY = 0x19,
  140. /**
  141. * Set a security key
  142. */
  143. ACI_CMD_SET_KEY = 0x1A,
  144. /**
  145. * Open Advertising Pipes
  146. */
  147. ACI_CMD_OPEN_ADV_PIPE = 0x1B,
  148. /**
  149. * Start non-connectable advertising
  150. */
  151. ACI_CMD_BROADCAST = 0x1C,
  152. /**
  153. * Start a security request in bonding mode
  154. */
  155. ACI_CMD_BOND_SECURITY_REQUEST = 0x1D,
  156. /**
  157. * Start Directed advertising towards a Bonded Peer
  158. */
  159. ACI_CMD_CONNECT_DIRECT = 0x1E,
  160. /**
  161. * Close a previously opened remote pipe
  162. */
  163. ACI_CMD_CLOSE_REMOTE_PIPE = 0x1F,
  164. /**
  165. * Invalid ACI command opcode
  166. */
  167. ACI_CMD_INVALID = 0xFF
  168. } _aci_packed_ aci_cmd_opcode_t;
  169. ACI_ASSERT_SIZE(aci_cmd_opcode_t, 1);
  170. /**
  171. * @struct aci_cmd_params_test_t
  172. * @brief Structure for the ACI_CMD_TEST ACI command parameters
  173. */
  174. typedef struct
  175. {
  176. aci_test_mode_change_t test_mode_change; /**< enum aci_test_mode_change_t */
  177. } _aci_packed_ aci_cmd_params_test_t;
  178. ACI_ASSERT_SIZE(aci_cmd_params_test_t, 1);
  179. /**
  180. * @struct aci_cmd_params_echo_t
  181. * @brief Structure for the ACI_CMD_ECHO ACI command parameters
  182. */
  183. typedef struct
  184. {
  185. uint8_t echo_data[ACI_ECHO_DATA_MAX_LEN];
  186. } _aci_packed_ aci_cmd_params_echo_t;
  187. ACI_ASSERT_SIZE(aci_cmd_params_echo_t, ACI_ECHO_DATA_MAX_LEN);
  188. /**
  189. * @struct aci_cmd_params_dtm_cmd_t
  190. * @brief Structure for the ACI_CMD_DTM_CMD ACI command parameters
  191. */
  192. typedef struct
  193. {
  194. uint8_t cmd_msb;
  195. uint8_t cmd_lsb;
  196. } _aci_packed_ aci_cmd_params_dtm_cmd_t;
  197. /**
  198. * @struct aci_cmd_params_setup_t
  199. * @brief Structure for the ACI_CMD_SETUP ACI command parameters
  200. */
  201. typedef struct
  202. {
  203. uint8_t setup_data[1];
  204. } _aci_packed_ aci_cmd_params_setup_t;
  205. ACI_ASSERT_SIZE(aci_cmd_params_setup_t, 1);
  206. /**
  207. * @struct aci_cmd_params_write_dynamic_data_t
  208. * @brief Structure for the ACI_CMD_WRITE_DYNAMIC_DATA ACI command parameters
  209. * @note Dynamic data chunk size in this command is defined to go up to ACI_PACKET_MAX_LEN - 3
  210. */
  211. typedef struct
  212. {
  213. uint8_t seq_no;
  214. uint8_t dynamic_data[1];
  215. } _aci_packed_ aci_cmd_params_write_dynamic_data_t;
  216. /**
  217. * @define aci_cmd_params_set_local_data_t
  218. * @brief Structure for the ACI_CMD_SET_LOCAL_DATA ACI command parameters
  219. */
  220. typedef struct
  221. {
  222. aci_tx_data_t tx_data;
  223. } _aci_packed_ aci_cmd_params_set_local_data_t;
  224. /**
  225. * @struct aci_cmd_params_connect_t
  226. * @brief Structure for the ACI_CMD_CONNECT ACI command parameters
  227. */
  228. typedef struct
  229. {
  230. uint16_t timeout; /**< 0x0000 (no timeout) to 0x3FFF */
  231. uint16_t adv_interval; /**< 16 bits of advertising interval for general discovery */
  232. } _aci_packed_ aci_cmd_params_connect_t;
  233. ACI_ASSERT_SIZE(aci_cmd_params_connect_t, 4);
  234. /**
  235. * @define aci_cmd_params_bond_t
  236. * @brief Structure for the ACI_CMD_BOND ACI command parameters
  237. */
  238. typedef struct
  239. {
  240. uint16_t timeout; /**< 0x0000 (no timeout) to 0x3FFF */
  241. uint16_t adv_interval; /**< 16 bits of advertising interval for general discovery */
  242. } _aci_packed_ aci_cmd_params_bond_t;
  243. ACI_ASSERT_SIZE(aci_cmd_params_bond_t, 4);
  244. /**
  245. * @struct aci_cmd_params_disconnect_t
  246. * @brief Structure for the ACI_CMD_DISCONNECT ACI command parameters
  247. */
  248. typedef struct
  249. {
  250. aci_disconnect_reason_t reason; /**< enum aci_disconnect_reason_t */
  251. } _aci_packed_ aci_cmd_params_disconnect_t;
  252. ACI_ASSERT_SIZE(aci_cmd_params_disconnect_t, 1);
  253. /**
  254. * @struct aci_cmd_params_set_tx_power_t
  255. * @brief Structure for the ACI_CMD_SET_TX_POWER ACI command parameters
  256. */
  257. typedef struct
  258. {
  259. aci_device_output_power_t device_power; /**< enum aci_device_output_power_t */
  260. } _aci_packed_ aci_cmd_params_set_tx_power_t;
  261. ACI_ASSERT_SIZE(aci_cmd_params_set_tx_power_t, 1);
  262. /**
  263. * @struct aci_cmd_params_change_timing_t
  264. * @brief Structure for the ACI_CMD_CHANGE_TIMING ACI command parameters
  265. */
  266. typedef struct
  267. {
  268. aci_ll_conn_params_t conn_params;
  269. } _aci_packed_ aci_cmd_params_change_timing_t;
  270. ACI_ASSERT_SIZE(aci_cmd_params_change_timing_t, 8);
  271. /**
  272. * @struct aci_cmd_params_open_remote_pipe_t
  273. * @brief Structure for the ACI_CMD_OPEN_REMOTE_PIPE ACI command parameters
  274. */
  275. typedef struct
  276. {
  277. uint8_t pipe_number;
  278. } _aci_packed_ aci_cmd_params_open_remote_pipe_t;
  279. /**
  280. * @struct aci_cmd_params_send_data_t
  281. * @brief Structure for the ACI_CMD_SEND_DATA ACI command parameters
  282. */
  283. typedef struct
  284. {
  285. aci_tx_data_t tx_data;
  286. } _aci_packed_ aci_cmd_params_send_data_t;
  287. /**
  288. * @define aci_cmd_params_send_data_ack_t
  289. * @brief Structure for the ACI_CMD_SEND_DATA_ACK ACI command parameters
  290. */
  291. typedef struct
  292. {
  293. uint8_t pipe_number;
  294. } _aci_packed_ aci_cmd_params_send_data_ack_t;
  295. /**
  296. * @struct aci_cmd_params_send_data_t
  297. * @brief Structure for the ACI_CMD_SEND_DATA ACI command parameters
  298. */
  299. typedef struct
  300. {
  301. uint8_t pipe_number;
  302. } _aci_packed_ aci_cmd_params_request_data_t;
  303. /**
  304. * @define aci_cmd_params_send_data_nack_t
  305. * @brief Structure for the ACI_CMD_SEND_DATA_NACK ACI command parameters
  306. */
  307. typedef struct
  308. {
  309. uint8_t pipe_number;
  310. uint8_t error_code;
  311. } _aci_packed_ aci_cmd_params_send_data_nack_t;
  312. ACI_ASSERT_SIZE(aci_cmd_params_send_data_nack_t, 2);
  313. /**
  314. * @define aci_cmd_params_set_app_latency_t
  315. * @brief Structure for the ACI_CMD_SET_APP_LATENCY ACI command parameters
  316. */
  317. typedef struct
  318. {
  319. aci_app_latency_mode_t mode;
  320. uint16_t latency;
  321. } _aci_packed_ aci_cmd_params_set_app_latency_t;
  322. ACI_ASSERT_SIZE(aci_cmd_params_set_app_latency_t, 3);
  323. /**
  324. * @define aci_cmd_params_set_key_t
  325. * @brief Structure for the ACI_CMD_SET_KEY ACI command parameters
  326. */
  327. typedef struct
  328. {
  329. aci_key_type_t key_type;
  330. union
  331. {
  332. uint8_t passkey[6];
  333. uint8_t oob_key[16];
  334. } key;
  335. } _aci_packed_ aci_cmd_params_set_key_t;
  336. ACI_ASSERT_SIZE(aci_cmd_params_set_key_t, 17);
  337. /**
  338. * @define aci_cmd_params_open_adv_pipe_t
  339. * @brief Structure for the ACI_CMD_OPEN_ADV_PIPE ACI command parameters
  340. */
  341. typedef struct
  342. {
  343. uint8_t pipes[8];
  344. } _aci_packed_ aci_cmd_params_open_adv_pipe_t;
  345. /**
  346. * @define aci_cmd_params_broadcast_t
  347. * @brief Structure for the ACI_CMD_BROADCAST ACI command parameters
  348. */
  349. typedef struct
  350. {
  351. uint16_t timeout; /**< 0x0000 (no timeout) to 0x3FFF */
  352. uint16_t adv_interval; /**< 16 bits of advertising interval for general discovery */
  353. } _aci_packed_ aci_cmd_params_broadcast_t;
  354. /**
  355. * @struct aci_cmd_params_close_remote_pipe_t
  356. * @brief Structure for the ACI_CMD_CLOSE_REMOTE_PIPE ACI command parameters
  357. */
  358. typedef struct
  359. {
  360. uint8_t pipe_number;
  361. } _aci_packed_ aci_cmd_params_close_remote_pipe_t;
  362. /**
  363. * @struct aci_cmd_t
  364. * @brief Encapsulates a generic ACI command
  365. */
  366. typedef struct
  367. {
  368. uint8_t len; /**< Length of the ACI command */
  369. aci_cmd_opcode_t cmd_opcode; /**< enum aci_cmd_opcode_t -> Opcode of the ACI command */
  370. union
  371. {
  372. aci_cmd_params_test_t test;
  373. aci_cmd_params_echo_t echo;
  374. aci_cmd_params_dtm_cmd_t dtm_cmd;
  375. aci_cmd_params_setup_t setup;
  376. aci_cmd_params_write_dynamic_data_t write_dynamic_data;
  377. aci_cmd_params_set_local_data_t set_local_data;
  378. aci_cmd_params_connect_t connect;
  379. aci_cmd_params_bond_t bond;
  380. aci_cmd_params_disconnect_t disconnect;
  381. aci_cmd_params_set_tx_power_t set_tx_power;
  382. aci_cmd_params_change_timing_t change_timing;
  383. aci_cmd_params_open_remote_pipe_t open_remote_pipe;
  384. aci_cmd_params_send_data_t send_data;
  385. aci_cmd_params_send_data_ack_t send_data_ack;
  386. aci_cmd_params_request_data_t request_data;
  387. aci_cmd_params_send_data_nack_t send_data_nack;
  388. aci_cmd_params_set_app_latency_t set_app_latency;
  389. aci_cmd_params_set_key_t set_key;
  390. aci_cmd_params_open_adv_pipe_t open_adv_pipe;
  391. aci_cmd_params_broadcast_t broadcast;
  392. aci_cmd_params_close_remote_pipe_t close_remote_pipe;
  393. } params;
  394. } _aci_packed_ aci_cmd_t;
  395. #endif // ACI_CMDS_H__