48 #define LOG_MODULE "RADIO" 49 #define LOG_LEVEL LOG_LEVEL_MAIN 51 static uint16_t adv_interval;
52 static ble_adv_type_t adv_type;
53 static ble_addr_type_t adv_own_addr_type;
54 static uint8_t adv_channel_map;
55 static uint16_t buffer_size = 0;
57 static uint16_t scan_interval;
58 static uint16_t scan_window;
59 static ble_scan_type_t scan_type;
60 static ble_addr_type_t scan_own_addr_type;
62 static ble_addr_type_t initiator_peer_addr_type;
63 static uint8_t initiator_peer_addr[BLE_ADDR_SIZE];
65 static uint16_t connection_interval;
66 static uint16_t connection_latency;
67 static uint16_t connection_timeout;
72 int result = ble_hal.
reset();
73 return result == BLE_RESULT_OK;
77 send(
const void *payload,
unsigned short payload_len)
80 res = ble_hal.send((
void *)payload, payload_len);
81 LOG_DBG(
"ble-mode send() %d bytes\n", payload_len);
82 if(res == BLE_RESULT_OK) {
85 LOG_ERR(
"ble-mode send() error: %d\n", res);
103 static radio_result_t
109 return RADIO_RESULT_INVALID_VALUE;
113 case RADIO_CONST_CHANNEL_MIN:
114 *value = BLE_DATA_CHANNEL_MIN;
115 return RADIO_RESULT_OK;
116 case RADIO_CONST_CHANNEL_MAX:
117 *value = BLE_DATA_CHANNEL_MAX;
118 return RADIO_RESULT_OK;
119 case RADIO_CONST_BLE_BUFFER_SIZE:
120 if(buffer_size == 0) {
123 memcpy(value, &buffer_size, 2);
124 return RADIO_RESULT_OK;
125 case RADIO_CONST_BLE_BUFFER_AMOUNT:
127 return RADIO_RESULT_OK;
128 case RADIO_PARAM_BLE_CONN_INTERVAL:
129 ble_hal.read_connection_interval(0, (
unsigned int *)value);
130 return RADIO_RESULT_OK;
132 return RADIO_RESULT_NOT_SUPPORTED;
136 static radio_result_t
140 case RADIO_PARAM_BLE_ADV_INTERVAL:
141 if((value > BLE_ADV_INTERVAL_MAX) || (value < BLE_ADV_INTERVAL_MIN)) {
142 return RADIO_RESULT_INVALID_VALUE;
144 adv_interval = (uint16_t)value;
145 return RADIO_RESULT_OK;
146 case RADIO_PARAM_BLE_ADV_TYPE:
148 return RADIO_RESULT_OK;
149 case RADIO_PARAM_BLE_ADV_OWN_ADDR_TYPE:
150 adv_own_addr_type = value;
151 return RADIO_RESULT_OK;
152 case RADIO_PARAM_BLE_ADV_CHANNEL_MAP:
153 adv_channel_map = value;
154 return RADIO_RESULT_OK;
155 case RADIO_PARAM_BLE_ADV_ENABLE:
159 adv_own_addr_type, adv_channel_map);
162 return RADIO_RESULT_OK;
163 case RADIO_PARAM_BLE_SCAN_INTERVAL:
164 if((value > BLE_SCAN_INTERVAL_MAX) || (value < BLE_SCAN_INTERVAL_MIN)) {
165 return RADIO_RESULT_INVALID_VALUE;
167 scan_interval = (uint16_t)value;
168 return RADIO_RESULT_OK;
169 case RADIO_PARAM_BLE_SCAN_WINDOW:
170 if((value > BLE_SCAN_INTERVAL_MAX) || (value < BLE_SCAN_INTERVAL_MIN)) {
171 return RADIO_RESULT_INVALID_VALUE;
173 scan_window = (uint16_t)value;
174 return RADIO_RESULT_OK;
175 case RADIO_PARAM_BLE_SCAN_TYPE:
177 return RADIO_RESULT_OK;
178 case RADIO_PARAM_BLE_SCAN_OWN_ADDR_TYPE:
179 scan_own_addr_type = value;
180 return RADIO_RESULT_OK;
181 case RADIO_PARAM_BLE_SCAN_ENABLE:
184 scan_window, scan_own_addr_type);
187 return RADIO_RESULT_OK;
188 case RADIO_PARAM_BLE_PEER_ADDR_TYPE:
189 initiator_peer_addr_type = value;
190 return RADIO_RESULT_OK;
191 case RADIO_PARAM_BLE_CONN_INTERVAL:
192 connection_interval = value;
193 return RADIO_RESULT_OK;
194 case RADIO_PARAM_BLE_CONN_LATENCY:
195 connection_latency = value;
196 return RADIO_RESULT_OK;
197 case RADIO_PARAM_BLE_CONN_SUPERVISION_TIMEOUT:
198 connection_timeout = value;
199 return RADIO_RESULT_OK;
200 case RADIO_PARAM_BLE_INITIATOR_ENABLE:
203 initiator_peer_addr_type,
212 return RADIO_RESULT_OK;
213 case RADIO_PARAM_BLE_CONN_UPDATE:
215 return ble_hal.
connection_update(0, connection_interval, connection_latency, connection_timeout);
217 return RADIO_RESULT_INVALID_VALUE;
220 return RADIO_RESULT_NOT_SUPPORTED;
224 static radio_result_t
225 get_object(radio_param_t param,
void *dest,
size_t size)
228 case RADIO_CONST_BLE_BD_ADDR:
229 if(size != BLE_ADDR_SIZE || !dest) {
230 return RADIO_RESULT_INVALID_VALUE;
233 return RADIO_RESULT_OK;
235 return RADIO_RESULT_NOT_SUPPORTED;
238 static radio_result_t
239 set_object(radio_param_t param,
const void *src,
size_t size)
242 case RADIO_PARAM_BLE_ADV_PAYLOAD:
243 if(size <= 0 || size >= BLE_ADV_DATA_LEN || !src) {
244 return RADIO_RESULT_INVALID_VALUE;
246 ble_hal.
set_adv_data((
unsigned short)size, (
char *)src);
247 return RADIO_RESULT_OK;
248 case RADIO_PARAM_BLE_ADV_SCAN_RESPONSE:
249 if(size <= 0 || size >= BLE_SCAN_RESP_DATA_LEN || !src) {
250 return RADIO_RESULT_INVALID_VALUE;
253 return RADIO_RESULT_OK;
254 case RADIO_PARAM_BLE_PEER_ADDR:
255 if(size <= 0 || size > BLE_ADDR_SIZE || !src) {
256 return RADIO_RESULT_INVALID_VALUE;
258 memcpy(initiator_peer_addr, src, size);
259 return RADIO_RESULT_OK;
261 return RADIO_RESULT_NOT_SUPPORTED;
radio_result_t(* get_object)(radio_param_t param, void *dest, size_t size)
Get a radio parameter object.
ble_result_t(* set_scan_param)(ble_scan_type_t type, unsigned int scan_interval, unsigned int scan_window, ble_addr_type_t own_addr_type)
Sets the parameter for scanning.
ble_result_t(* reset)(void)
Resets the BLE controller.
ble_result_t(* set_adv_enable)(unsigned short enable)
Enables/disables advertising.
Header file for the radio API
ble_result_t(* create_connection_cancel)(void)
Cancels the initiation of a BLE connection.
radio_result_t(* set_value)(radio_param_t param, radio_value_t value)
Set a radio parameter value.
The structure of a device driver for a radio in Contiki.
int radio_value_t
Each radio has a set of parameters that designate the current configuration and state of the radio...
int(* send)(const void *payload, unsigned short payload_len)
Prepare & transmit a packet.
hardware abstraction for a BLE controller
int(* off)(void)
Turn the radio off.
ble_result_t(* set_adv_data)(unsigned short data_len, char *data)
Sets the advertising data.
ble_result_t(* set_adv_param)(unsigned int adv_interval, ble_adv_type_t type, ble_addr_type_t own_addr_type, unsigned short adv_channel_map)
Sets the parameter for advertising.
ble_result_t(* read_bd_addr)(uint8_t *addr)
Reads the static BLE device address.
ble_result_t(* read_buffer_size)(unsigned int *buf_len, unsigned int *num_buf)
Reads the size of the data buffers.
ble_result_t(* create_connection)(unsigned int scan_interval, unsigned int scan_window, ble_addr_type_t peer_addr_type, uint8_t *peer_addr, ble_addr_type_t own_addr_type, unsigned int conn_interval, unsigned int conn_latency, unsigned int supervision_timeout)
Initiates the creation of a BLE connection.
ble_result_t(* set_scan_enable)(unsigned short enable, unsigned short filter_duplicates)
Enables/disables scanning.
radio_result_t(* get_value)(radio_param_t param, radio_value_t *value)
Get a radio parameter value.
Header file for the logging system
radio_result_t(* set_object)(radio_param_t param, const void *src, size_t size)
Set a radio parameter object.
ble_result_t(* disconnect)(unsigned int connection_handle, unsigned short reason)
Disconnects the connection.
ble_result_t(* connection_update)(unsigned int connection_handle, unsigned int conn_interval, unsigned int conn_latency, unsigned int supervision_timeout)
Updates the connection parameters.
BLE radio hardware abstraction for the TI CC26XX controller.
int(* on)(void)
Turn the radio on.
ble_result_t(* set_scan_resp_data)(unsigned short data_len, char *data)
Sets the scan response data.