48#include <ti/devices/DeviceFamily.h>
49#include DeviceFamily_constructPath(driverlib/chipinfo.h)
50#include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h)
51#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h)
53#include <ti/drivers/rf/RF.h>
69#define LOG_MODULE "Radio"
70#define LOG_LEVEL LOG_LEVEL_NONE
72#if RF_CONF_BLE_BEACON_ENABLE
75#define BLE_ADV_MAX_SIZE 31
81#define BLE_ADV_INTERVAL ((100 * CLOCK_SECOND) / 1000)
84#define BLE_ADV_TYPE_FLAGS 0x01
85#define BLE_ADV_TYPE_16BIT_MORE 0x02
86#define BLE_ADV_TYPE_16BIT_COMPLETE 0x03
87#define BLE_ADV_TYPE_32BIT_MORE 0x04
88#define BLE_ADV_TYPE_32BIT_COMPLETE 0x05
89#define BLE_ADV_TYPE_128BIT_MORE 0x06
90#define BLE_ADV_TYPE_128BIT_COMPLETE 0x07
91#define BLE_ADV_TYPE_LOCAL_NAME_SHORT 0x08
92#define BLE_ADV_TYPE_LOCAL_NAME_COMPLETE 0x09
93#define BLE_ADV_TYPE_POWER_LEVEL 0x0A
94#define BLE_ADV_TYPE_OOB_CLASS_OF_DEVICE 0x0D
95#define BLE_ADV_TYPE_OOB_SIMPLE_PAIRING_HASHC 0x0E
96#define BLE_ADV_TYPE_OOB_SIMPLE_PAIRING_RANDR 0x0F
97#define BLE_ADV_TYPE_SM_TK 0x10
98#define BLE_ADV_TYPE_SM_OOB_FLAG 0x11
99#define BLE_ADV_TYPE_SLAVE_CONN_INTERVAL_RANGE 0x12
100#define BLE_ADV_TYPE_SIGNED_DATA 0x13
101#define BLE_ADV_TYPE_SERVICE_LIST_16BIT 0x14
102#define BLE_ADV_TYPE_SERVICE_LIST_128BIT 0x15
103#define BLE_ADV_TYPE_SERVICE_DATA 0x16
104#define BLE_ADV_TYPE_PUBLIC_TARGET_ADDR 0x17
105#define BLE_ADV_TYPE_RANDOM_TARGET_ADDR 0x18
106#define BLE_ADV_TYPE_APPEARANCE 0x19
107#define BLE_ADV_TYPE_ADV_INTERVAL 0x1A
108#define BLE_ADV_TYPE_LE_BD_ADDR 0x1B
109#define BLE_ADV_TYPE_LE_ROLE 0x1C
110#define BLE_ADV_TYPE_SIMPLE_PAIRING_HASHC_256 0x1D
111#define BLE_ADV_TYPE_SIMPLE_PAIRING_RANDR_256 0x1E
112#define BLE_ADV_TYPE_SERVICE_DATA_32BIT 0x20
113#define BLE_ADV_TYPE_SERVICE_DATA_128BIT 0x21
114#define BLE_ADV_TYPE_3D_INFO_DATA 0x3D
115#define BLE_ADV_TYPE_MANUFACTURER_SPECIFIC 0xFF
120#define BLE_ADV_TYPE_FLAGS_LIMITED 0x01
122#define BLE_ADV_TYPE_FLAGS_GENERAL 0x02
124#define BLE_ADV_TYPE_FLAGS_BREDR_NOT_SUPPORTED 0x04
126#define BLE_ADV_NAME_BUF_LEN BLE_ADV_MAX_SIZE
127#define BLE_ADV_PAYLOAD_BUF_LEN 64
128#define BLE_UUID_SIZE 16
132 uint8_t tx_buf[BLE_ADV_PAYLOAD_BUF_LEN] CC_ALIGN(4);
136 char adv_name[BLE_ADV_NAME_BUF_LEN];
142 clock_time_t ble_adv_interval;
149 uint8_t ble_mac_addr[6];
150 rfc_bleAdvPar_t ble_adv_par;
151 rfc_bleAdvOutput_t ble_adv_output;
154static ble_beacond_t ble_beacond;
156PROCESS(ble_beacond_process,
"RF BLE Beacon Daemon Process");
158rf_ble_beacond_result_t
161 ble_cmd_radio_setup.config.frontEndMode = RF_2_4_GHZ_FRONT_END_MODE;
162 ble_cmd_radio_setup.config.biasMode = RF_2_4_GHZ_BIAS_MODE;
165 RF_Params_init(&rf_params);
169 ble_beacond.rf_handle = ble_open(&rf_params);
171 if(ble_beacond.rf_handle == NULL) {
172 return RF_BLE_BEACOND_ERROR;
181 ble_beacond.ble_adv_par.pDeviceAddress = (uint16_t *)ble_beacond.ble_mac_addr;
182 ble_beacond.ble_adv_par.endTrigger.triggerType = TRIG_NEVER;
184 rf_ble_cmd_ble_adv_nc.pParams = &ble_beacond.ble_adv_par;
185 rf_ble_cmd_ble_adv_nc.pOutput = &ble_beacond.ble_adv_output;
187 return RF_BLE_BEACOND_OK;
190rf_ble_beacond_result_t
193 rf_ble_beacond_result_t res;
195 res = RF_BLE_BEACOND_ERROR;
198 ble_beacond.ble_adv_interval = interval;
200 res = RF_BLE_BEACOND_OK;
202 ble_beacond.ble_adv_interval = BLE_ADV_INTERVAL;
206 const size_t name_len = strlen(name);
208 if((0 < name_len) && (name_len < BLE_ADV_NAME_BUF_LEN)) {
209 ble_beacond.adv_name_len = name_len;
210 memcpy(ble_beacond.adv_name, name, name_len);
212 res = RF_BLE_BEACOND_OK;
219rf_ble_beacond_result_t
222 if(ble_beacond.is_active) {
223 return RF_BLE_BEACOND_OK;
226 ble_beacond.is_active =
true;
230 return RF_BLE_BEACOND_OK;
233rf_ble_beacond_result_t
236 if(!ble_beacond.is_active) {
237 return RF_BLE_BEACOND_OK;
240 ble_beacond.is_active =
false;
244 return RF_BLE_BEACOND_OK;
250 return (int8_t)ble_beacond.is_active;
253rf_ble_beacond_result_t
258 if(!tx_power_in_range(dbm, ble_tx_power_table, ble_tx_power_table_size)) {
262 res = rf_set_tx_power(ble_beacond.rf_handle, ble_tx_power_table, dbm);
264 return (res == RF_RESULT_OK)
266 : RF_BLE_BEACOND_ERROR;
275 res = rf_get_tx_power(ble_beacond.rf_handle, ble_tx_power_table, &dbm);
277 if(res != RF_RESULT_OK) {
278 return RF_TxPowerTable_INVALID_DBM;
291 etimer_set(&ble_beacond.ble_adv_et, ble_beacond.ble_adv_interval);
293 (ev == PROCESS_EVENT_EXIT));
295 if(ev == PROCESS_EVENT_EXIT) {
303 #define append_byte(x) ble_beacond.tx_buf[len++] = (uint8_t)((x))
307 append_byte(BLE_ADV_TYPE_FLAGS);
309 append_byte(BLE_ADV_TYPE_FLAGS_GENERAL |
310 BLE_ADV_TYPE_FLAGS_BREDR_NOT_SUPPORTED);
313 append_byte(1 + ble_beacond.adv_name_len);
314 append_byte(BLE_ADV_TYPE_LOCAL_NAME_COMPLETE);
316 memcpy(ble_beacond.tx_buf + len, ble_beacond.adv_name, ble_beacond.adv_name_len);
317 len += ble_beacond.adv_name_len;
322 ble_beacond.ble_adv_par.advLen = len;
323 ble_beacond.ble_adv_par.pAdvData = ble_beacond.tx_buf;
325 ble_sched_beacons(BLE_ADV_CHANNEL_ALL);
332rf_ble_beacond_result_t
335 return RF_BLE_BEACOND_DISABLED;
338rf_ble_beacond_result_t
343 return RF_BLE_BEACOND_DISABLED;
346rf_ble_beacond_result_t
349 return RF_BLE_BEACOND_DISABLED;
353rf_ble_beacond_result_t
356 return RF_BLE_BEACOND_DISABLED;
365rf_ble_beacond_result_t
369 return RF_BLE_BEACOND_DISABLED;
Header file for the CC13xx/CC26xx BLE Beacon Daemon.
Default definitions of C compiler quirk work-arounds.
#define RF_CONF_INACTIVITY_TIMEOUT
2 ms
int ble_addr_le_cpy(uint8_t *dst)
Copy the node's factory BLE address to a destination memory area in little-endian (le) order.
rf_ble_beacond_result_t rf_ble_beacond_stop(void)
Stop the BLE advertisement/beacon daemon.
rf_ble_beacond_result_t rf_ble_beacond_start(void)
Start the BLE advertisement/beacon daemon.
rf_ble_beacond_result_t rf_ble_beacond_config(clock_time_t interval, const char *name)
Set the device name to use with the BLE advertisement/beacon daemon.
int8_t rf_ble_is_active(void)
Check whether the BLE beacond is currently active.
rf_ble_beacond_result_t rf_ble_set_tx_power(int8_t power)
Set TX power for BLE advertisements.
rf_ble_beacond_result_t rf_ble_beacond_init(void)
Initialize the BLE advertisement/beacon daemon.
int8_t rf_ble_get_tx_power(void)
Get TX power for BLE advertisements.
static bool etimer_expired(struct etimer *et)
Check if an event timer has expired.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
#define PROCESS(name, strname)
Declare a process.
#define PROCESS_EXIT()
Exit the currently running process.
void process_exit(struct process *p)
Cause a process to exit.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
#define PROCESS_END()
Define the end of a process.
void process_start(struct process *p, process_data_t data)
Start a process.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
@ RADIO_RESULT_INVALID_VALUE
The value argument was incorrect.
Header file for the link-layer address representation.
Header file for the logging system.
Include file for the Contiki low-layer network stack (NETSTACK)
Header file for the Contiki process interface.
Header file of common CC13xx/CC26xx RF functionality.
Header file of the CC13xx/CC26xx RF scheduler.
Header file of RF settings for CC13xx/CC26xx.
Header file for the CC13xx/CC26xx BLE address driver.
Header file of TX power functionality of CC13xx/CC26xx.