Contiki-NG
rf-ble-cmd.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, Graz University of Technology
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /**
32  * \file
33  * BLE commands for the TI CC26xx BLE radio.
34  * These functions are specific to the TI CC26xx and cannot be
35  * reused by other BLE radios.
36  *
37  * \author
38  * Michael Spoerk <michael.spoerk@tugraz.at>
39  */
40 /*---------------------------------------------------------------------------*/
41 
42 #ifndef RF_BLE_CMD_H_
43 #define RF_BLE_CMD_H_
44 
45 #include "os/dev/ble-hal.h"
46 #include "../../ble-addr.h"
47 #include "rf_common_cmd.h"
48 
49 #define RF_BLE_CMD_OK 1
50 #define RF_BLE_CMD_ERROR 0
51 
52 /*---------------------------------------------------------------------------*/
53 /**
54  * \brief Sends a BLE radio command to the radio
55  * \param cmd A pointer to the command to be send
56  * \return RF_CORE_CMD_OK or RF_CORE_CMD_ERROR
57  */
58 unsigned short rf_ble_cmd_send(uint8_t *cmd);
59 
60 /*---------------------------------------------------------------------------*/
61 /**
62  * \brief Waits for a running BLE radio command to be finished
63  * \param cmd A pointer to the running command
64  * \return RF_CORE_CMD_OK or RF_CORE_CMD_ERROR
65  */
66 unsigned short rf_ble_cmd_wait(uint8_t *cmd);
67 
68 /*---------------------------------------------------------------------------*/
69 /**
70  * \brief Initializes the radio core to be used as a BLE radio
71  * \return RF_CORE_CMD_OK or RF_CORE_CMD_ERROR
72  */
73 unsigned short rf_ble_cmd_setup_ble_mode(void);
74 
75 /*---------------------------------------------------------------------------*/
76 /**
77  * \brief Creates a BLE radio command structure that enables
78  * BLE advertisement when sent to the radio core
79  * \param command A pointer to command that is created
80  * \param channel The BLE advertisement channel used for advertisement
81  * \param param A pointer to the radio command parameters
82  * \param output A pointer to the radio command output
83  */
84 void rf_ble_cmd_create_adv_cmd(uint8_t *command, uint8_t channel,
85  uint8_t *param, uint8_t *output);
86 
87 /*---------------------------------------------------------------------------*/
88 /**
89  * \brief Creates BLE radio command parameters that are used to enable
90  * BLE advertisement on the radio core
91  * \param param A pointer to parameter structure that is created
92  * \param rx_queue A pointer to the RX queue that is used
93  * \param adv_data_len
94  * The length of the advertisement data
95  * \param adv_data A pointer to the advertisement data that is advertised
96  * \param scan_resp_data_len
97  * The length of the scan response data
98  * \param scan_resp_data
99  * A pointer to the scan response data
100  * \param own_addr_type
101  * Either BLE_ADDR_TYPE_PUBLIC or BLE_ADDR_TYPE_RANDOM
102  * \param own_addr A pointer to the device address that is used as own address
103  */
104 void rf_ble_cmd_create_adv_params(uint8_t *param, dataQueue_t *rx_queue,
105  uint8_t adv_data_len, uint8_t *adv_data,
106  uint8_t scan_resp_data_len, uint8_t *scan_resp_data,
107  ble_addr_type_t own_addr_type, uint8_t *own_addr);
108 
109 /*---------------------------------------------------------------------------*/
110 /**
111  * \brief Creates a BLE radio command structure that sets up
112  * BLE initiation event when sent to the radio core
113  * \param cmd A pointer to command that is created
114  * \param channel The BLE data channel used for the connection event
115  * \param params A pointer to the radio command parameters
116  * \param output A pointer to the radio command output
117  * \param start_time
118  * The time in rf_core_ticks when the connection event will start
119  */
120 void rf_ble_cmd_create_initiator_cmd(uint8_t *cmd, uint8_t channel, uint8_t *params,
121  uint8_t *output, uint32_t start_time);
122 
123 /*---------------------------------------------------------------------------*/
124 /**
125  * \brief Creates BLE radio command parameters that are used to set up
126  * BLE initiation event on the radio core
127  * \param param A pointer to parameter structure that is created
128  * \param rx_queue A pointer to the RX queue that is used
129  * \param initiator_window
130  * T
131  * \param own_addr_type
132  * Either BLE_ADDR_TYPE_PUBLIC or BLE_ADDR_TYPE_RANDOM
133  * \param own_addr A pointer to the device address that is used as own address
134  * \param peer_addr_type
135  * Either BLE_ADDR_TYPE_PUBLIC or BLE_ADDR_TYPE_RANDOM
136  * \param peer_addr A pointer to the device address that is used as peer address
137  * \param connect_time
138  The first possible start time of the first connection event
139  * \param conn_req_data A pointer to the connect request data
140  */
141 void rf_ble_cmd_create_initiator_params(uint8_t *param, dataQueue_t *rx_queue,
142  uint32_t initiator_window,
143  ble_addr_type_t own_addr_type, uint8_t *own_addr,
144  ble_addr_type_t peer_addr_type, uint8_t *peer_addr,
145  uint32_t connect_time,
146  uint8_t *conn_req_data);
147 
148 /*---------------------------------------------------------------------------*/
149 /**
150  * \brief Creates a BLE radio command structure that sets up a single
151  * BLE connection event when sent to the radio core
152  * \param cmd A pointer to command that is created
153  * \param channel The BLE data channel used for the connection event
154  * \param param A pointer to the radio command parameters
155  * \param output A pointer to the radio command output
156  * \param start_time
157  * The time in rf_core_ticks when the connection event will start
158  */
159 void rf_ble_cmd_create_slave_cmd(uint8_t *cmd, uint8_t channel, uint8_t *param,
160  uint8_t *output, uint32_t start_time);
161 
162 /*---------------------------------------------------------------------------*/
163 /**
164  * \brief Creates BLE radio command parameters that are used to setup a single
165  * BLE connection event on the radio core
166  * \param param A pointer to parameter structure that is created
167  * \param rx_queue A pointer to the RX queue that is used
168  * \param tx_queue A pointer to the TX queue that is used
169  * \param access_address
170  * The access address of the used BLE connection
171  * \param crc_init_0
172  * Part of the initialization of the CRC checksum
173  * \param crc_init_1
174  * Part of the initialization of the CRC checksum
175  * \param crc_init_2
176  * Part of the initialization of the CRC checksum
177  * \param win_size The window size parameter of the BLE connection event
178  * \param window_widening
179  * The window widening parameter used for this connection event
180  * \param first_packet
181  * 1 for the first packet of the BLE connection so that the
182  * connection is properly initialized
183  */
184 void rf_ble_cmd_create_slave_params(uint8_t *param, dataQueue_t *rx_queue,
185  dataQueue_t *tx_queue, uint32_t access_address,
186  uint8_t crc_init_0, uint8_t crc_init_1,
187  uint8_t crc_init_2, uint32_t win_size,
188  uint32_t window_widening, uint8_t first_packet);
189 
190 /*---------------------------------------------------------------------------*/
191 /**
192  * \brief Creates a BLE radio command structure that sets up
193  * BLE connection event when sent to the radio core
194  * \param cmd A pointer to command that is created
195  * \param channel The BLE data channel used for the connection event
196  * \param params A pointer to the radio command parameters
197  * \param output A pointer to the radio command output
198  * \param start_time
199  * The time in rf_core_ticks when the connection event will start
200  */
201 void rf_ble_cmd_create_master_cmd(uint8_t *cmd, uint8_t channel, uint8_t *params,
202  uint8_t *output, uint32_t start_time);
203 
204 /*---------------------------------------------------------------------------*/
205 /**
206  * \brief Creates BLE radio command parameters that are used to set up
207  * BLE connection event on the radio core
208  * \param params A pointer to parameter structure that is created
209  * \param rx_queue A pointer to the RX queue that is used
210  * \param tx_queue A pointer to the TX queue that is used
211  * \param access_address
212  * The access address of the used BLE connection
213  * \param crc_init_0
214  * Part of the initialization of the CRC checksum
215  * \param crc_init_1
216  * Part of the initialization of the CRC checksum
217  * \param crc_init_2
218  * Part of the initialization of the CRC checksum
219  * \param first_packet
220  * 1 for the first packet of the BLE connection so that the
221  * connection is properly initialized
222  */
223 void rf_ble_cmd_create_master_params(uint8_t *params, dataQueue_t *rx_queue,
224  dataQueue_t *tx_queue, uint32_t access_address,
225  uint8_t crc_init_0, uint8_t crc_init_1,
226  uint8_t crc_init_2, uint8_t first_packet);
227 
228 /*---------------------------------------------------------------------------*/
229 /**
230  * \brief Adds a data buffer to a BLE transmission queue
231  * \param q A pointer to BLE transmission queue where the buffer
232  * should be added
233  * \param e A pointer to the data buffer that is added
234  */
235 unsigned short rf_ble_cmd_add_data_queue_entry(dataQueue_t *q, uint8_t *e);
236 
237 #endif /* RF_BLE_CMD_H_ */
unsigned short rf_ble_cmd_wait(uint8_t *cmd)
Waits for a running BLE radio command to be finished.
Definition: rf-ble-cmd.c:145
void rf_ble_cmd_create_initiator_params(uint8_t *param, dataQueue_t *rx_queue, uint32_t initiator_window, ble_addr_type_t own_addr_type, uint8_t *own_addr, ble_addr_type_t peer_addr_type, uint8_t *peer_addr, uint32_t connect_time, uint8_t *conn_req_data)
Creates BLE radio command parameters that are used to set up BLE initiation event on the radio core...
Definition: rf-ble-cmd.c:290
void rf_ble_cmd_create_master_cmd(uint8_t *cmd, uint8_t channel, uint8_t *params, uint8_t *output, uint32_t start_time)
Creates a BLE radio command structure that sets up BLE connection event when sent to the radio core...
Definition: rf-ble-cmd.c:429
static uint8_t output(const linkaddr_t *localdest)
Take an IP packet and format it to be sent on an 802.15.4 network using 6lowpan.
Definition: sicslowpan.c:1565
void rf_ble_cmd_create_slave_cmd(uint8_t *cmd, uint8_t channel, uint8_t *param, uint8_t *output, uint32_t start_time)
Creates a BLE radio command structure that sets up a single BLE connection event when sent to the rad...
Definition: rf-ble-cmd.c:336
void rf_ble_cmd_create_master_params(uint8_t *params, dataQueue_t *rx_queue, dataQueue_t *tx_queue, uint32_t access_address, uint8_t crc_init_0, uint8_t crc_init_1, uint8_t crc_init_2, uint8_t first_packet)
Creates BLE radio command parameters that are used to set up BLE connection event on the radio core...
Definition: rf-ble-cmd.c:467
hardware abstraction for a BLE controller
void rf_ble_cmd_create_initiator_cmd(uint8_t *cmd, uint8_t channel, uint8_t *params, uint8_t *output, uint32_t start_time)
Creates a BLE radio command structure that sets up BLE initiation event when sent to the radio core...
Definition: rf-ble-cmd.c:254
unsigned short rf_ble_cmd_setup_ble_mode(void)
Initializes the radio core to be used as a BLE radio.
Definition: rf-ble-cmd.c:157
void rf_ble_cmd_create_adv_cmd(uint8_t *command, uint8_t channel, uint8_t *param, uint8_t *output)
Creates a BLE radio command structure that enables BLE advertisement when sent to the radio core...
Definition: rf-ble-cmd.c:195
unsigned short rf_ble_cmd_send(uint8_t *cmd)
Sends a BLE radio command to the radio.
Definition: rf-ble-cmd.c:131
void rf_ble_cmd_create_slave_params(uint8_t *param, dataQueue_t *rx_queue, dataQueue_t *tx_queue, uint32_t access_address, uint8_t crc_init_0, uint8_t crc_init_1, uint8_t crc_init_2, uint32_t win_size, uint32_t window_widening, uint8_t first_packet)
Creates BLE radio command parameters that are used to setup a single BLE connection event on the radi...
Definition: rf-ble-cmd.c:375
void rf_ble_cmd_create_adv_params(uint8_t *param, dataQueue_t *rx_queue, uint8_t adv_data_len, uint8_t *adv_data, uint8_t scan_resp_data_len, uint8_t *scan_resp_data, ble_addr_type_t own_addr_type, uint8_t *own_addr)
Creates BLE radio command parameters that are used to enable BLE advertisement on the radio core...
Definition: rf-ble-cmd.c:222
unsigned short rf_ble_cmd_add_data_queue_entry(dataQueue_t *q, uint8_t *e)
Adds a data buffer to a BLE transmission queue.
Definition: rf-ble-cmd.c:514