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