bluetooth control motor
Dependents: BLE_LED_IDB0XA1_demo MOTOR_BLE_V2 Motor_Ble_v1 Motor_Ble_v10223 ... more
Fork of X_NUCLEO_IDB0XA1 by
Revision 301:9c0d8f9382c7, committed 2016-09-15
- Comitter:
- Vincent Coubard
- Date:
- Thu Sep 15 10:52:09 2016 +0100
- Branch:
- sync_with_github
- Parent:
- 279:30a6a8ad2623
- Parent:
- 300:85b12e23a7ba
- Child:
- 302:ed6f74ab78f9
- Child:
- 303:fb52f2a212d2
- Commit message:
- Sync with 6781fbb835912132d7fed0d78606c7090ae03959
Merge c21998c9579e3c57e3e1619a977b9bc47a36d249 into 947ff7cf03846721ec9970f16d373390cbf71f39
2016-07-28 20:46:25+01:00: Vincent Coubard
Merge pull request #11 from ARMmbed/fix_filename_collision
Fix filename collision
Changed in this revision
--- a/source/BlueNRGDevice.cpp Thu Sep 15 10:51:44 2016 +0100 +++ b/source/BlueNRGDevice.cpp Thu Sep 15 10:52:09 2016 +0100 @@ -47,14 +47,14 @@ #include "BlueNRGGattServer.h" #include "btle.h" -#include "Utils.h" -#include "osal.h" +#include "ble_utils.h" +#include "ble_osal.h" -#include "debug.h" +#include "ble_debug.h" #include "stm32_bluenrg_ble.h" extern "C" { - #include "hci.h" + #include "ble_hci.h" #include "bluenrg_utils.h" }
--- a/source/BlueNRGGap.cpp Thu Sep 15 10:51:44 2016 +0100 +++ b/source/BlueNRGGap.cpp Thu Sep 15 10:52:09 2016 +0100 @@ -44,9 +44,9 @@ #else #include "mbed.h" #endif -#include "Payload.h" -#include "Utils.h" -#include "debug.h" +#include "ble_payload.h" +#include "ble_utils.h" +#include "ble_debug.h" /* * Utility to process GAP specific events (e.g., Advertising timeout)
--- a/source/BlueNRGGattClient.cpp Thu Sep 15 10:51:44 2016 +0100 +++ b/source/BlueNRGGattClient.cpp Thu Sep 15 10:52:09 2016 +0100 @@ -43,8 +43,8 @@ #include "mbed.h" #endif #include "BlueNRGGap.h" -#include "Utils.h" -#include "debug.h" +#include "ble_utils.h" +#include "ble_debug.h" static uint8_t props_mask[] = { 0x01,
--- a/source/BlueNRGGattServer.cpp Thu Sep 15 10:51:44 2016 +0100 +++ b/source/BlueNRGGattServer.cpp Thu Sep 15 10:52:09 2016 +0100 @@ -43,8 +43,8 @@ #include "mbed.h" #endif #include "BlueNRGGap.h" -#include "Utils.h" -#include "debug.h" +#include "ble_utils.h" +#include "ble_debug.h" /**************************************************************************/ /*!
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/source/bluenrg-hci/hci/ble_hci.c Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,1227 @@ +/** + ****************************************************************************** + * @file ble_hci.c + * @author AMS/HESA Application Team + * @brief Function for managing HCI interface. + ****************************************************************************** + * + * + * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS + * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE + * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY + * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING + * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + * + * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2> + */ + +#include "ble_hal_types.h" +#include "ble_osal.h" +#include "ble_status.h" +#include "ble_hal.h" +#include "ble_hci_const.h" +#include "ble_gp_timer.h" +#include "ble_debug.h" + +#include "stm32_bluenrg_ble.h" + +#if BLE_CONFIG_DBG_ENABLE +#undef PRINTF +#endif + +#define HCI_LOG_ON 0 + +#define HCI_READ_PACKET_NUM_MAX (0x40) + +#define MIN(a,b) ((a) < (b) )? (a) : (b) +#define MAX(a,b) ((a) > (b) )? (a) : (b) + +tListNode hciReadPktPool; +tListNode hciReadPktRxQueue; + +// betzw - DEBUG: +//#define POOL_CNT +#ifdef POOL_CNT +#include <stdio.h> +static unsigned int nr_hciReadPktPool; +static unsigned int lowest_nr_hciReadPktPool; +#endif // POOL_CNT + +/* pool of hci read packets */ +static tHciDataPacket hciReadPacketBuffer[HCI_READ_PACKET_NUM_MAX]; + +static volatile uint8_t readPacketListFull=FALSE; + +static volatile uint8_t hci_timer_id; +static volatile uint8_t hci_timeout; + +void hci_timeout_callback(void) +{ + hci_timeout = 1; + return; +} + +void HCI_Init(void) +{ + uint8_t index; + + Disable_SPI_IRQ(); + +#ifdef POOL_CNT + nr_hciReadPktPool = 0; +#endif // POOL_CNT + + /* Initialize list heads of ready and free hci data packet queues */ + list_init_head (&hciReadPktPool); + list_init_head (&hciReadPktRxQueue); + + /* Initialize the queue of free hci data packets */ + for (index = 0; index < HCI_READ_PACKET_NUM_MAX; index++) + { + list_insert_tail(&hciReadPktPool, (tListNode *)&hciReadPacketBuffer[index]); +#ifdef POOL_CNT + nr_hciReadPktPool++; +#endif // POOL_CNT + } + +#ifdef POOL_CNT + lowest_nr_hciReadPktPool = nr_hciReadPktPool; +#endif // POOL_CNT + + Enable_SPI_IRQ(); +} + +#define HCI_PCK_TYPE_OFFSET 0 +#define EVENT_PARAMETER_TOT_LEN_OFFSET 2 + +/** + * Verify if HCI packet is correctly formatted.. + * + * @param[in] hciReadPacket The packet that is received from HCI interface. + * @return 0 if HCI packet is as expected + */ +int HCI_verify(const tHciDataPacket * hciReadPacket) +{ + const uint8_t *hci_pckt = hciReadPacket->dataBuff; + + if(hci_pckt[HCI_PCK_TYPE_OFFSET] != HCI_EVENT_PKT) + return 1; /* Incorrect type. */ + + if(hci_pckt[EVENT_PARAMETER_TOT_LEN_OFFSET] != hciReadPacket->data_len - (1+HCI_EVENT_HDR_SIZE)) + return 2; /* Wrong length (packet truncated or too long). */ + + return 0; +} + +void HCI_Process(void) +{ + uint8_t data_len; + uint8_t buffer[HCI_READ_PACKET_SIZE]; + tHciDataPacket * hciReadPacket = NULL; + +#ifdef POOL_CNT + printf("betzw(%s, %d): nr_hciReadPktPool = %u (lowest = %u)\r\n", __func__, __LINE__, + nr_hciReadPktPool, lowest_nr_hciReadPktPool); +#endif // POOL_CNT + + Disable_SPI_IRQ(); + uint8_t list_empty = list_is_empty(&hciReadPktRxQueue); + /* process any pending events read */ + while(list_empty == FALSE) + { + list_remove_head (&hciReadPktRxQueue, (tListNode **)&hciReadPacket); + Enable_SPI_IRQ(); + HCI_Event_CB(hciReadPacket->dataBuff); + Disable_SPI_IRQ(); + list_insert_tail(&hciReadPktPool, (tListNode *)hciReadPacket); +#ifdef POOL_CNT + nr_hciReadPktPool++; +#endif + list_empty = list_is_empty(&hciReadPktRxQueue); + } + if (readPacketListFull) { + while(BlueNRG_DataPresent()) { + data_len = BlueNRG_SPI_Read_All(buffer, HCI_READ_PACKET_SIZE); + if(data_len > 0) + HCI_Event_CB(buffer); + } + readPacketListFull = FALSE; + } + + Enable_SPI_IRQ(); +} + +BOOL HCI_Queue_Empty(void) +{ + return list_is_empty(&hciReadPktRxQueue); +} + +void HCI_Isr(void) +{ + tHciDataPacket * hciReadPacket = NULL; + uint8_t data_len; + + Clear_SPI_EXTI_Flag(); + while(BlueNRG_DataPresent()){ + if (list_is_empty (&hciReadPktPool) == FALSE){ + + /* enqueueing a packet for read */ + list_remove_head (&hciReadPktPool, (tListNode **)&hciReadPacket); +#ifdef POOL_CNT + nr_hciReadPktPool--; + if(nr_hciReadPktPool < lowest_nr_hciReadPktPool) + lowest_nr_hciReadPktPool = nr_hciReadPktPool; +#endif + + data_len = BlueNRG_SPI_Read_All(hciReadPacket->dataBuff, HCI_READ_PACKET_SIZE); + if(data_len > 0){ + hciReadPacket->data_len = data_len; + if(HCI_verify(hciReadPacket) == 0) { + list_insert_tail(&hciReadPktRxQueue, (tListNode *)hciReadPacket); + signalEventsToProcess(); + } else { + list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket); +#ifdef POOL_CNT + nr_hciReadPktPool++; +#endif + } + } + else { + // Insert the packet back into the pool. + list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket); +#ifdef POOL_CNT + nr_hciReadPktPool++; +#endif + } + } + else{ + // HCI Read Packet Pool is empty, wait for a free packet. + signalEventsToProcess(); + readPacketListFull = TRUE; + Clear_SPI_EXTI_Flag(); + return; + } + Clear_SPI_EXTI_Flag(); + } +} + +void hci_write(const void* data1, const void* data2, uint8_t n_bytes1, uint8_t n_bytes2){ +#if HCI_LOG_ON + PRINTF("HCI <- "); + for(int i=0; i < n_bytes1; i++) + PRINTF("%02X ", *((uint8_t*)data1 + i)); + for(int i=0; i < n_bytes2; i++) + PRINTF("%02X ", *((uint8_t*)data2 + i)); + PRINTF("\n"); +#endif + + Hal_Write_Serial(data1, data2, n_bytes1, n_bytes2); +} + +void hci_send_cmd(uint16_t ogf, uint16_t ocf, uint8_t plen, void *param) +{ + hci_command_hdr hc; + + hc.opcode = htobs(cmd_opcode_pack(ogf, ocf)); + hc.plen= plen; + + uint8_t header[HCI_HDR_SIZE + HCI_COMMAND_HDR_SIZE]; + header[0] = HCI_COMMAND_PKT; + Osal_MemCpy(header+1, &hc, sizeof(hc)); + + hci_write(header, param, sizeof(header), plen); +} + +static void move_list(tListNode * dest_list, tListNode * src_list) +{ + pListNode tmp_node; + + while(!list_is_empty(src_list)){ + list_remove_head(src_list, &tmp_node); + list_insert_tail(dest_list, tmp_node); + } +} + +int hci_send_req(struct hci_request *r, BOOL async) +{ + uint8_t *ptr; + uint16_t opcode = htobs(cmd_opcode_pack(r->ogf, r->ocf)); + hci_event_pckt *event_pckt; + hci_uart_pckt *hci_hdr; + int to = DEFAULT_TIMEOUT; + struct timer t; + tHciDataPacket * hciReadPacket = NULL; + tListNode hciTempQueue; + + list_init_head(&hciTempQueue); + + hci_send_cmd(r->ogf, r->ocf, r->clen, r->cparam); + + if(async){ + goto done; + } + + /* Minimum timeout is 1. */ + if(to == 0) + to = 1; + + Timer_Set(&t, to); + + while(1) { + evt_cmd_complete *cc; + evt_cmd_status *cs; + evt_le_meta_event *me; + int len; + +#if ENABLE_MICRO_SLEEP + while(1){ + ATOMIC_SECTION_BEGIN(); + if(Timer_Expired(&t)){ + ATOMIC_SECTION_END(); + goto failed; + } + if(!HCI_Queue_Empty()){ + ATOMIC_SECTION_END(); + break; + } + Enter_Sleep_Mode(); + ATOMIC_SECTION_END(); + } +#else + while(1){ + if(Timer_Expired(&t)){ + goto failed; + } + if(!HCI_Queue_Empty()){ + break; + } + } +#endif + + /* Extract packet from HCI event queue. */ + Disable_SPI_IRQ(); + list_remove_head(&hciReadPktRxQueue, (tListNode **)&hciReadPacket); + + hci_hdr = (void *)hciReadPacket->dataBuff; + if(hci_hdr->type != HCI_EVENT_PKT){ + list_insert_tail(&hciTempQueue, (tListNode *)hciReadPacket); // See comment below + Enable_SPI_IRQ(); + continue; + } + + event_pckt = (void *) (hci_hdr->data); + + ptr = hciReadPacket->dataBuff + (1 + HCI_EVENT_HDR_SIZE); + len = hciReadPacket->data_len - (1 + HCI_EVENT_HDR_SIZE); + + switch (event_pckt->evt) { + + case EVT_CMD_STATUS: + cs = (void *) ptr; + + if (cs->opcode != opcode) + goto failed; + + if (r->event != EVT_CMD_STATUS) { + if (cs->status) { + goto failed; + } + break; + } + + r->rlen = MIN(len, r->rlen); + Osal_MemCpy(r->rparam, ptr, r->rlen); + goto done; + + case EVT_CMD_COMPLETE: + cc = (void *) ptr; + + if (cc->opcode != opcode) + goto failed; + + ptr += EVT_CMD_COMPLETE_SIZE; + len -= EVT_CMD_COMPLETE_SIZE; + + r->rlen = MIN(len, r->rlen); + Osal_MemCpy(r->rparam, ptr, r->rlen); + goto done; + + case EVT_LE_META_EVENT: + me = (void *) ptr; + + if (me->subevent != r->event) + break; + + len -= 1; + r->rlen = MIN(len, r->rlen); + Osal_MemCpy(r->rparam, me->data, r->rlen); + goto done; + + case EVT_HARDWARE_ERROR: + goto failed; + + default: + break; + } + + /* In the meantime there could be other events from the controller. + In this case, insert the packet in a different queue. These packets will be + inserted back in the main queue just before exiting from send_req(). + */ + if(hciReadPacket != NULL) { + list_insert_tail(&hciTempQueue, (tListNode *)hciReadPacket); + hciReadPacket = NULL; + } + /* Be sure there is at list one packet in the pool to process the expected event. */ + if(list_is_empty(&hciReadPktPool)){ // betzw: this is a kind of steeling (should never happen?!?) + pListNode tmp_node; + list_remove_head(&hciReadPktRxQueue, &tmp_node); + list_insert_tail(&hciReadPktPool, tmp_node); +#ifdef POOL_CNT + nr_hciReadPktPool++; +#endif + } + + Enable_SPI_IRQ(); + + } + +failed: + // Insert the packet back into the pool. + if(hciReadPacket != NULL) { + list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket); +#ifdef POOL_CNT + nr_hciReadPktPool++; +#endif + hciReadPacket = NULL; + } + move_list(&hciReadPktRxQueue, &hciTempQueue); + Enable_SPI_IRQ(); + return -1; + +done: + // Insert the packet back into the pool. + if(hciReadPacket != NULL) { + list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket); +#ifdef POOL_CNT + nr_hciReadPktPool++; +#endif + hciReadPacket = NULL; + } + move_list(&hciReadPktRxQueue, &hciTempQueue); + + Enable_SPI_IRQ(); + return 0; +} + +int hci_reset() +{ + struct hci_request rq; + uint8_t status; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_HOST_CTL; + rq.ocf = OCF_RESET; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + return status; +} + +int hci_disconnect(uint16_t handle, uint8_t reason) +{ + struct hci_request rq; + disconnect_cp cp; + uint8_t status; + + cp.handle = handle; + cp.reason = reason; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LINK_CTL; + rq.ocf = OCF_DISCONNECT; + rq.cparam = &cp; + rq.clen = DISCONNECT_CP_SIZE; + rq.event = EVT_CMD_STATUS; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + return status; +} + +int hci_le_read_local_version(uint8_t *hci_version, uint16_t *hci_revision, uint8_t *lmp_pal_version, + uint16_t *manufacturer_name, uint16_t *lmp_pal_subversion) +{ + struct hci_request rq; + read_local_version_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_INFO_PARAM; + rq.ocf = OCF_READ_LOCAL_VERSION; + rq.cparam = NULL; + rq.clen = 0; + rq.rparam = &resp; + rq.rlen = READ_LOCAL_VERSION_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + if (resp.status) { + return resp.status; + } + + + *hci_version = resp.hci_version; + *hci_revision = btohs(resp.hci_revision); + *lmp_pal_version = resp.lmp_pal_version; + *manufacturer_name = btohs(resp.manufacturer_name); + *lmp_pal_subversion = btohs(resp.lmp_pal_subversion); + + return 0; +} + +int hci_le_read_buffer_size(uint16_t *pkt_len, uint8_t *max_pkt) +{ + struct hci_request rq; + le_read_buffer_size_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_READ_BUFFER_SIZE; + rq.cparam = NULL; + rq.clen = 0; + rq.rparam = &resp; + rq.rlen = LE_READ_BUFFER_SIZE_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + if (resp.status) { + return resp.status; + } + + *pkt_len = resp.pkt_len; + *max_pkt = resp.max_pkt; + + return 0; +} + +int hci_le_set_advertising_parameters(uint16_t min_interval, uint16_t max_interval, uint8_t advtype, + uint8_t own_bdaddr_type, uint8_t direct_bdaddr_type, const tBDAddr direct_bdaddr, uint8_t chan_map, + uint8_t filter) +{ + struct hci_request rq; + le_set_adv_parameters_cp adv_cp; + uint8_t status; + + Osal_MemSet(&adv_cp, 0, sizeof(adv_cp)); + adv_cp.min_interval = min_interval; + adv_cp.max_interval = max_interval; + adv_cp.advtype = advtype; + adv_cp.own_bdaddr_type = own_bdaddr_type; + adv_cp.direct_bdaddr_type = direct_bdaddr_type; + if(direct_bdaddr != NULL) + Osal_MemCpy(adv_cp.direct_bdaddr,direct_bdaddr,sizeof(adv_cp.direct_bdaddr)); + adv_cp.chan_map = chan_map; + adv_cp.filter = filter; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_SET_ADV_PARAMETERS; + rq.cparam = &adv_cp; + rq.clen = LE_SET_ADV_PARAMETERS_CP_SIZE; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + return status; +} + +int hci_le_set_advertising_data(uint8_t length, const uint8_t data[]) +{ + struct hci_request rq; + le_set_adv_data_cp adv_cp; + uint8_t status; + + Osal_MemSet(&adv_cp, 0, sizeof(adv_cp)); + adv_cp.length = length; + Osal_MemCpy(adv_cp.data, data, MIN(31,length)); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_SET_ADV_DATA; + rq.cparam = &adv_cp; + rq.clen = LE_SET_ADV_DATA_CP_SIZE; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + return status; +} + +int hci_le_set_advertise_enable(uint8_t enable) +{ + struct hci_request rq; + le_set_advertise_enable_cp adv_cp; + uint8_t status; + + Osal_MemSet(&adv_cp, 0, sizeof(adv_cp)); + adv_cp.enable = enable?1:0; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_SET_ADVERTISE_ENABLE; + rq.cparam = &adv_cp; + rq.clen = LE_SET_ADVERTISE_ENABLE_CP_SIZE; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + return status; +} + +int hci_le_set_scan_parameters(uint8_t type, uint16_t interval, + uint16_t window, uint8_t own_bdaddr_type, + uint8_t filter) +{ + struct hci_request rq; + le_set_scan_parameters_cp scan_cp; + uint8_t status; + + Osal_MemSet(&scan_cp, 0, sizeof(scan_cp)); + scan_cp.type = type; + scan_cp.interval = interval; + scan_cp.window = window; + scan_cp.own_bdaddr_type = own_bdaddr_type; + scan_cp.filter = filter; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_SET_SCAN_PARAMETERS; + rq.cparam = &scan_cp; + rq.clen = LE_SET_SCAN_PARAMETERS_CP_SIZE; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + return status; +} + +int hci_le_set_scan_enable(uint8_t enable, uint8_t filter_dup) +{ + struct hci_request rq; + le_set_scan_enable_cp scan_cp; + uint8_t status; + + Osal_MemSet(&scan_cp, 0, sizeof(scan_cp)); + scan_cp.enable = enable?1:0; + scan_cp.filter_dup = filter_dup; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_SET_SCAN_ENABLE; + rq.cparam = &scan_cp; + rq.clen = LE_SET_SCAN_ENABLE_CP_SIZE; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + return status; +} + +int hci_le_rand(uint8_t random_number[8]) +{ + struct hci_request rq; + le_rand_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_RAND; + rq.cparam = NULL; + rq.clen = 0; + rq.rparam = &resp; + rq.rlen = LE_RAND_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + if (resp.status) { + return resp.status; + } + + Osal_MemCpy(random_number, resp.random, 8); + + return 0; +} + +int hci_le_set_scan_resp_data(uint8_t length, const uint8_t data[]) +{ + struct hci_request rq; + le_set_scan_response_data_cp scan_resp_cp; + uint8_t status; + + Osal_MemSet(&scan_resp_cp, 0, sizeof(scan_resp_cp)); + scan_resp_cp.length = length; + Osal_MemCpy(scan_resp_cp.data, data, MIN(31,length)); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_SET_SCAN_RESPONSE_DATA; + rq.cparam = &scan_resp_cp; + rq.clen = LE_SET_SCAN_RESPONSE_DATA_CP_SIZE; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + return status; +} + +int hci_le_read_advertising_channel_tx_power(int8_t *tx_power_level) +{ + struct hci_request rq; + le_read_adv_channel_tx_power_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_READ_ADV_CHANNEL_TX_POWER; + rq.cparam = NULL; + rq.clen = 0; + rq.rparam = &resp; + rq.rlen = LE_RAND_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + if (resp.status) { + return resp.status; + } + + *tx_power_level = resp.level; + + return 0; +} + +int hci_le_set_random_address(tBDAddr bdaddr) +{ + struct hci_request rq; + le_set_random_address_cp set_rand_addr_cp; + uint8_t status; + + Osal_MemSet(&set_rand_addr_cp, 0, sizeof(set_rand_addr_cp)); + Osal_MemCpy(set_rand_addr_cp.bdaddr, bdaddr, sizeof(tBDAddr)); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_SET_RANDOM_ADDRESS; + rq.cparam = &set_rand_addr_cp; + rq.clen = LE_SET_RANDOM_ADDRESS_CP_SIZE; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + return status; +} + +int hci_read_bd_addr(tBDAddr bdaddr) +{ + struct hci_request rq; + read_bd_addr_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_INFO_PARAM; + rq.ocf = OCF_READ_BD_ADDR; + rq.cparam = NULL; + rq.clen = 0; + rq.rparam = &resp; + rq.rlen = READ_BD_ADDR_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + if (resp.status) { + return resp.status; + } + Osal_MemCpy(bdaddr, resp.bdaddr, sizeof(tBDAddr)); + + return 0; +} + +int hci_le_create_connection(uint16_t interval, uint16_t window, uint8_t initiator_filter, uint8_t peer_bdaddr_type, + const tBDAddr peer_bdaddr, uint8_t own_bdaddr_type, uint16_t min_interval, uint16_t max_interval, + uint16_t latency, uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length) +{ + struct hci_request rq; + le_create_connection_cp create_cp; + uint8_t status; + + Osal_MemSet(&create_cp, 0, sizeof(create_cp)); + create_cp.interval = interval; + create_cp.window = window; + create_cp.initiator_filter = initiator_filter; + create_cp.peer_bdaddr_type = peer_bdaddr_type; + Osal_MemCpy(create_cp.peer_bdaddr, peer_bdaddr, sizeof(tBDAddr)); + create_cp.own_bdaddr_type = own_bdaddr_type; + create_cp.min_interval=min_interval; + create_cp.max_interval=max_interval; + create_cp.latency = latency; + create_cp.supervision_timeout=supervision_timeout; + create_cp.min_ce_length=min_ce_length; + create_cp.max_ce_length=max_ce_length; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_CREATE_CONN; + rq.cparam = &create_cp; + rq.clen = LE_CREATE_CONN_CP_SIZE; + rq.event = EVT_CMD_STATUS; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + return status; +} + +int hci_le_create_connection_cancel(void) +{ + struct hci_request rq; + uint8_t status; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_CREATE_CONN_CANCEL; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + return status; +} + +int hci_le_encrypt(uint8_t key[16], uint8_t plaintextData[16], uint8_t encryptedData[16]) +{ + struct hci_request rq; + le_encrypt_cp params; + le_encrypt_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + Osal_MemCpy(params.key, key, 16); + Osal_MemCpy(params.plaintext, plaintextData, 16); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_ENCRYPT; + rq.cparam = ¶ms; + rq.clen = LE_ENCRYPT_CP_SIZE; + rq.rparam = &resp; + rq.rlen = LE_ENCRYPT_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0){ + return BLE_STATUS_TIMEOUT; + } + + if (resp.status) { + return resp.status; + } + + Osal_MemCpy(encryptedData, resp.encdata, 16); + + return 0; +} + +int hci_le_ltk_request_reply(uint8_t key[16]) +{ + struct hci_request rq; + le_ltk_reply_cp params; + le_ltk_reply_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + params.handle = 1; + Osal_MemCpy(params.key, key, 16); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_LTK_REPLY; + rq.cparam = ¶ms; + rq.clen = LE_LTK_REPLY_CP_SIZE; + rq.rparam = &resp; + rq.rlen = LE_LTK_REPLY_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + return resp.status; +} + +int hci_le_ltk_request_neg_reply() +{ + struct hci_request rq; + le_ltk_neg_reply_cp params; + le_ltk_neg_reply_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + params.handle = 1; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_LTK_NEG_REPLY; + rq.cparam = ¶ms; + rq.clen = LE_LTK_NEG_REPLY_CP_SIZE; + rq.rparam = &resp; + rq.rlen = LE_LTK_NEG_REPLY_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0) + return BLE_STATUS_TIMEOUT; + + return resp.status; +} + +int hci_le_read_white_list_size(uint8_t *size) +{ + struct hci_request rq; + le_read_white_list_size_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_READ_WHITE_LIST_SIZE; + rq.rparam = &resp; + rq.rlen = LE_READ_WHITE_LIST_SIZE_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0){ + return BLE_STATUS_TIMEOUT; + } + + if (resp.status) { + return resp.status; + } + + *size = resp.size; + + return 0; +} + +int hci_le_clear_white_list() +{ + struct hci_request rq; + uint8_t status; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_CLEAR_WHITE_LIST; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0){ + return BLE_STATUS_TIMEOUT; + } + + return status; +} + +int hci_le_add_device_to_white_list(uint8_t bdaddr_type, tBDAddr bdaddr) +{ + struct hci_request rq; + le_add_device_to_white_list_cp params; + uint8_t status; + + params.bdaddr_type = bdaddr_type; + Osal_MemCpy(params.bdaddr, bdaddr, 6); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_ADD_DEVICE_TO_WHITE_LIST; + rq.cparam = ¶ms; + rq.clen = LE_ADD_DEVICE_TO_WHITE_LIST_CP_SIZE; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0){ + return BLE_STATUS_TIMEOUT; + } + + return status; +} + +int hci_le_remove_device_from_white_list(uint8_t bdaddr_type, tBDAddr bdaddr) +{ + struct hci_request rq; + le_remove_device_from_white_list_cp params; + uint8_t status; + + params.bdaddr_type = bdaddr_type; + Osal_MemCpy(params.bdaddr, bdaddr, 6); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_REMOVE_DEVICE_FROM_WHITE_LIST; + rq.cparam = ¶ms; + rq.clen = LE_REMOVE_DEVICE_FROM_WHITE_LIST_CP_SIZE; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0){ + return BLE_STATUS_TIMEOUT; + } + + return status; +} + +int hci_read_transmit_power_level(uint16_t *conn_handle, uint8_t type, int8_t * tx_level) +{ + struct hci_request rq; + read_transmit_power_level_cp params; + read_transmit_power_level_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + params.handle = *conn_handle; + params.type = type; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_HOST_CTL; + rq.ocf = OCF_READ_TRANSMIT_POWER_LEVEL; + rq.cparam = ¶ms; + rq.clen = READ_TRANSMIT_POWER_LEVEL_CP_SIZE; + rq.rparam = &resp; + rq.rlen = READ_TRANSMIT_POWER_LEVEL_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0){ + return BLE_STATUS_TIMEOUT; + } + + if (resp.status) { + return resp.status; + } + + *conn_handle = resp.handle; + *tx_level = resp.level; + + return 0; +} + +int hci_read_rssi(uint16_t *conn_handle, int8_t * rssi) +{ + struct hci_request rq; + read_rssi_cp params; + read_rssi_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + params.handle = *conn_handle; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_STATUS_PARAM; + rq.ocf = OCF_READ_RSSI; + rq.cparam = ¶ms; + rq.clen = READ_RSSI_CP_SIZE; + rq.rparam = &resp; + rq.rlen = READ_RSSI_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0){ + return BLE_STATUS_TIMEOUT; + } + + if (resp.status) { + return resp.status; + } + + *conn_handle = resp.handle; + *rssi = resp.rssi; + + return 0; +} + +int hci_le_read_local_supported_features(uint8_t *features) +{ + struct hci_request rq; + le_read_local_supported_features_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_READ_LOCAL_SUPPORTED_FEATURES; + rq.rparam = &resp; + rq.rlen = LE_READ_LOCAL_SUPPORTED_FEATURES_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0){ + return BLE_STATUS_TIMEOUT; + } + + if (resp.status) { + return resp.status; + } + + Osal_MemCpy(features, resp.features, sizeof(resp.features)); + + return 0; +} + +int hci_le_read_channel_map(uint16_t conn_handle, uint8_t ch_map[5]) +{ + struct hci_request rq; + le_read_channel_map_cp params; + le_read_channel_map_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + params.handle = conn_handle; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_READ_CHANNEL_MAP; + rq.cparam = ¶ms; + rq.clen = LE_READ_CHANNEL_MAP_CP_SIZE; + rq.rparam = &resp; + rq.rlen = LE_READ_CHANNEL_MAP_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0){ + return BLE_STATUS_TIMEOUT; + } + + if (resp.status) { + return resp.status; + } + + Osal_MemCpy(ch_map, resp.map, 5); + + return 0; +} + +int hci_le_read_supported_states(uint8_t states[8]) +{ + struct hci_request rq; + le_read_supported_states_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_READ_SUPPORTED_STATES; + rq.rparam = &resp; + rq.rlen = LE_READ_SUPPORTED_STATES_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0){ + return BLE_STATUS_TIMEOUT; + } + + if (resp.status) { + return resp.status; + } + + Osal_MemCpy(states, resp.states, 8); + + return 0; +} + +int hci_le_receiver_test(uint8_t frequency) +{ + struct hci_request rq; + le_receiver_test_cp params; + uint8_t status; + + params.frequency = frequency; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_RECEIVER_TEST; + rq.cparam = ¶ms; + rq.clen = LE_RECEIVER_TEST_CP_SIZE; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0){ + return BLE_STATUS_TIMEOUT; + } + + return status; +} + +int hci_le_transmitter_test(uint8_t frequency, uint8_t length, uint8_t payload) +{ + struct hci_request rq; + le_transmitter_test_cp params; + uint8_t status; + + params.frequency = frequency; + params.length = length; + params.payload = payload; + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_TRANSMITTER_TEST; + rq.cparam = ¶ms; + rq.clen = LE_TRANSMITTER_TEST_CP_SIZE; + rq.rparam = &status; + rq.rlen = 1; + + if (hci_send_req(&rq, FALSE) < 0){ + return BLE_STATUS_TIMEOUT; + } + + return status; +} + +int hci_le_test_end(uint16_t *num_pkts) +{ + struct hci_request rq; + le_test_end_rp resp; + + Osal_MemSet(&resp, 0, sizeof(resp)); + + Osal_MemSet(&rq, 0, sizeof(rq)); + rq.ogf = OGF_LE_CTL; + rq.ocf = OCF_LE_TEST_END; + rq.rparam = &resp; + rq.rlen = LE_TEST_END_RP_SIZE; + + if (hci_send_req(&rq, FALSE) < 0){ + return BLE_STATUS_TIMEOUT; + } + + if (resp.status) { + return resp.status; + } + + *num_pkts = resp.num_pkts; + + return 0; +}
--- a/source/bluenrg-hci/hci/controller/bluenrg_gap_aci.c Thu Sep 15 10:51:44 2016 +0100 +++ b/source/bluenrg-hci/hci/controller/bluenrg_gap_aci.c Thu Sep 15 10:52:09 2016 +0100 @@ -13,12 +13,12 @@ * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. *******************************************************************************/ -#include "hal_types.h" -#include "osal.h" +#include "ble_hal_types.h" +#include "ble_osal.h" #include "ble_status.h" -#include "hal.h" -#include "osal.h" -#include "hci_const.h" +#include "ble_hal.h" +#include "ble_osal.h" +#include "ble_hci_const.h" #include "bluenrg_aci_const.h" #include "bluenrg_gap_aci.h" #include "bluenrg_gatt_server.h" @@ -1304,4 +1304,4 @@ Osal_MemCpy(device_list, rp.dev_list, MIN(device_list_size,rp.num_addr*7)); return 0; -} +} \ No newline at end of file
--- a/source/bluenrg-hci/hci/controller/bluenrg_gatt_aci.c Thu Sep 15 10:51:44 2016 +0100 +++ b/source/bluenrg-hci/hci/controller/bluenrg_gatt_aci.c Thu Sep 15 10:52:09 2016 +0100 @@ -13,12 +13,11 @@ * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. *******************************************************************************/ -#include "hal_types.h" -#include "osal.h" +#include "ble_hal_types.h" +#include "ble_osal.h" #include "ble_status.h" -#include "hal.h" -#include "osal.h" -#include "hci_const.h" +#include "ble_hal.h" +#include "ble_hci_const.h" #include "bluenrg_aci_const.h" #include "bluenrg_gatt_aci.h" #include "bluenrg_gatt_server.h" @@ -1469,4 +1468,4 @@ Osal_MemCpy(data, rp.value, MIN(data_len, *data_len_out_p)); return 0; -} +} \ No newline at end of file
--- a/source/bluenrg-hci/hci/controller/bluenrg_hal_aci.c Thu Sep 15 10:51:44 2016 +0100 +++ b/source/bluenrg-hci/hci/controller/bluenrg_hal_aci.c Thu Sep 15 10:52:09 2016 +0100 @@ -13,12 +13,12 @@ * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. *******************************************************************************/ -#include "hal_types.h" -#include "osal.h" +#include "ble_hal_types.h" +#include "ble_osal.h" #include "ble_status.h" -#include "hal.h" -#include "osal.h" -#include "hci_const.h" +#include "ble_hal.h" +#include "ble_osal.h" +#include "ble_hci_const.h" #include "bluenrg_aci_const.h" #include "bluenrg_hal_aci.h" #include "bluenrg_gatt_server.h" @@ -180,4 +180,3 @@ } -
--- a/source/bluenrg-hci/hci/controller/bluenrg_l2cap_aci.c Thu Sep 15 10:51:44 2016 +0100 +++ b/source/bluenrg-hci/hci/controller/bluenrg_l2cap_aci.c Thu Sep 15 10:52:09 2016 +0100 @@ -13,12 +13,12 @@ * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. *******************************************************************************/ -#include "hal_types.h" -#include "osal.h" +#include "ble_hal_types.h" +#include "ble_osal.h" #include "ble_status.h" -#include "hal.h" -#include "osal.h" -#include "hci_const.h" +#include "ble_hal.h" +#include "ble_osal.h" +#include "ble_hci_const.h" #include "bluenrg_aci_const.h" #include "bluenrg_hal_aci.h" #include "bluenrg_gap.h" @@ -115,4 +115,4 @@ return BLE_STATUS_TIMEOUT; return status; -} +} \ No newline at end of file
--- a/source/bluenrg-hci/hci/controller/bluenrg_updater_aci.c Thu Sep 15 10:51:44 2016 +0100 +++ b/source/bluenrg-hci/hci/controller/bluenrg_updater_aci.c Thu Sep 15 10:52:09 2016 +0100 @@ -13,12 +13,12 @@ * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. *******************************************************************************/ -#include "hal_types.h" -#include "osal.h" +#include "ble_hal_types.h" +#include "ble_osal.h" #include "ble_status.h" -#include "hal.h" -#include "osal.h" -#include "hci_const.h" +#include "ble_hal.h" +#include "ble_osal.h" +#include "ble_hci_const.h" #include "bluenrg_aci_const.h" #include "bluenrg_updater_aci.h" @@ -267,4 +267,3 @@ -
--- a/source/bluenrg-hci/hci/controller/bluenrg_utils.c Thu Sep 15 10:51:44 2016 +0100 +++ b/source/bluenrg-hci/hci/controller/bluenrg_utils.c Thu Sep 15 10:52:09 2016 +0100 @@ -1,11 +1,11 @@ -#include "hal.h" -#include "hal_types.h" +#include "ble_hal.h" +#include "ble_hal_types.h" #include "ble_status.h" #include "bluenrg_aci.h" #include "bluenrg_utils.h" -#include "hci.h" -#include "osal.h" +#include "ble_hci.h" +#include "ble_osal.h" #include "string.h" #include "stm32_bluenrg_ble.h" @@ -427,4 +427,4 @@ return 0; return 1; -} +} \ No newline at end of file
--- a/source/bluenrg-hci/hci/hci.c Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1227 +0,0 @@ -/** - ****************************************************************************** - * @file hci.c - * @author AMS/HESA Application Team - * @brief Function for managing HCI interface. - ****************************************************************************** - * - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2> - */ - -#include "hal_types.h" -#include "osal.h" -#include "ble_status.h" -#include "hal.h" -#include "hci_const.h" -#include "gp_timer.h" -#include "debug.h" - -#include "stm32_bluenrg_ble.h" - -#if BLE_CONFIG_DBG_ENABLE -#undef PRINTF -#endif - -#define HCI_LOG_ON 0 - -#define HCI_READ_PACKET_NUM_MAX (0x40) - -#define MIN(a,b) ((a) < (b) )? (a) : (b) -#define MAX(a,b) ((a) > (b) )? (a) : (b) - -tListNode hciReadPktPool; -tListNode hciReadPktRxQueue; - -// betzw - DEBUG: -//#define POOL_CNT -#ifdef POOL_CNT -#include <stdio.h> -static unsigned int nr_hciReadPktPool; -static unsigned int lowest_nr_hciReadPktPool; -#endif // POOL_CNT - -/* pool of hci read packets */ -static tHciDataPacket hciReadPacketBuffer[HCI_READ_PACKET_NUM_MAX]; - -static volatile uint8_t readPacketListFull=FALSE; - -static volatile uint8_t hci_timer_id; -static volatile uint8_t hci_timeout; - -void hci_timeout_callback(void) -{ - hci_timeout = 1; - return; -} - -void HCI_Init(void) -{ - uint8_t index; - - Disable_SPI_IRQ(); - -#ifdef POOL_CNT - nr_hciReadPktPool = 0; -#endif // POOL_CNT - - /* Initialize list heads of ready and free hci data packet queues */ - list_init_head (&hciReadPktPool); - list_init_head (&hciReadPktRxQueue); - - /* Initialize the queue of free hci data packets */ - for (index = 0; index < HCI_READ_PACKET_NUM_MAX; index++) - { - list_insert_tail(&hciReadPktPool, (tListNode *)&hciReadPacketBuffer[index]); -#ifdef POOL_CNT - nr_hciReadPktPool++; -#endif // POOL_CNT - } - -#ifdef POOL_CNT - lowest_nr_hciReadPktPool = nr_hciReadPktPool; -#endif // POOL_CNT - - Enable_SPI_IRQ(); -} - -#define HCI_PCK_TYPE_OFFSET 0 -#define EVENT_PARAMETER_TOT_LEN_OFFSET 2 - -/** - * Verify if HCI packet is correctly formatted.. - * - * @param[in] hciReadPacket The packet that is received from HCI interface. - * @return 0 if HCI packet is as expected - */ -int HCI_verify(const tHciDataPacket * hciReadPacket) -{ - const uint8_t *hci_pckt = hciReadPacket->dataBuff; - - if(hci_pckt[HCI_PCK_TYPE_OFFSET] != HCI_EVENT_PKT) - return 1; /* Incorrect type. */ - - if(hci_pckt[EVENT_PARAMETER_TOT_LEN_OFFSET] != hciReadPacket->data_len - (1+HCI_EVENT_HDR_SIZE)) - return 2; /* Wrong length (packet truncated or too long). */ - - return 0; -} - -void HCI_Process(void) -{ - uint8_t data_len; - uint8_t buffer[HCI_READ_PACKET_SIZE]; - tHciDataPacket * hciReadPacket = NULL; - -#ifdef POOL_CNT - printf("betzw(%s, %d): nr_hciReadPktPool = %u (lowest = %u)\r\n", __func__, __LINE__, - nr_hciReadPktPool, lowest_nr_hciReadPktPool); -#endif // POOL_CNT - - Disable_SPI_IRQ(); - uint8_t list_empty = list_is_empty(&hciReadPktRxQueue); - /* process any pending events read */ - while(list_empty == FALSE) - { - list_remove_head (&hciReadPktRxQueue, (tListNode **)&hciReadPacket); - Enable_SPI_IRQ(); - HCI_Event_CB(hciReadPacket->dataBuff); - Disable_SPI_IRQ(); - list_insert_tail(&hciReadPktPool, (tListNode *)hciReadPacket); -#ifdef POOL_CNT - nr_hciReadPktPool++; -#endif - list_empty = list_is_empty(&hciReadPktRxQueue); - } - if (readPacketListFull) { - while(BlueNRG_DataPresent()) { - data_len = BlueNRG_SPI_Read_All(buffer, HCI_READ_PACKET_SIZE); - if(data_len > 0) - HCI_Event_CB(buffer); - } - readPacketListFull = FALSE; - } - - Enable_SPI_IRQ(); -} - -BOOL HCI_Queue_Empty(void) -{ - return list_is_empty(&hciReadPktRxQueue); -} - -void HCI_Isr(void) -{ - tHciDataPacket * hciReadPacket = NULL; - uint8_t data_len; - - Clear_SPI_EXTI_Flag(); - while(BlueNRG_DataPresent()){ - if (list_is_empty (&hciReadPktPool) == FALSE){ - - /* enqueueing a packet for read */ - list_remove_head (&hciReadPktPool, (tListNode **)&hciReadPacket); -#ifdef POOL_CNT - nr_hciReadPktPool--; - if(nr_hciReadPktPool < lowest_nr_hciReadPktPool) - lowest_nr_hciReadPktPool = nr_hciReadPktPool; -#endif - - data_len = BlueNRG_SPI_Read_All(hciReadPacket->dataBuff, HCI_READ_PACKET_SIZE); - if(data_len > 0){ - hciReadPacket->data_len = data_len; - if(HCI_verify(hciReadPacket) == 0) { - list_insert_tail(&hciReadPktRxQueue, (tListNode *)hciReadPacket); - signalEventsToProcess(); - } else { - list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket); -#ifdef POOL_CNT - nr_hciReadPktPool++; -#endif - } - } - else { - // Insert the packet back into the pool. - list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket); -#ifdef POOL_CNT - nr_hciReadPktPool++; -#endif - } - } - else{ - // HCI Read Packet Pool is empty, wait for a free packet. - signalEventsToProcess(); - readPacketListFull = TRUE; - Clear_SPI_EXTI_Flag(); - return; - } - Clear_SPI_EXTI_Flag(); - } -} - -void hci_write(const void* data1, const void* data2, uint8_t n_bytes1, uint8_t n_bytes2){ -#if HCI_LOG_ON - PRINTF("HCI <- "); - for(int i=0; i < n_bytes1; i++) - PRINTF("%02X ", *((uint8_t*)data1 + i)); - for(int i=0; i < n_bytes2; i++) - PRINTF("%02X ", *((uint8_t*)data2 + i)); - PRINTF("\n"); -#endif - - Hal_Write_Serial(data1, data2, n_bytes1, n_bytes2); -} - -void hci_send_cmd(uint16_t ogf, uint16_t ocf, uint8_t plen, void *param) -{ - hci_command_hdr hc; - - hc.opcode = htobs(cmd_opcode_pack(ogf, ocf)); - hc.plen= plen; - - uint8_t header[HCI_HDR_SIZE + HCI_COMMAND_HDR_SIZE]; - header[0] = HCI_COMMAND_PKT; - Osal_MemCpy(header+1, &hc, sizeof(hc)); - - hci_write(header, param, sizeof(header), plen); -} - -static void move_list(tListNode * dest_list, tListNode * src_list) -{ - pListNode tmp_node; - - while(!list_is_empty(src_list)){ - list_remove_head(src_list, &tmp_node); - list_insert_tail(dest_list, tmp_node); - } -} - -int hci_send_req(struct hci_request *r, BOOL async) -{ - uint8_t *ptr; - uint16_t opcode = htobs(cmd_opcode_pack(r->ogf, r->ocf)); - hci_event_pckt *event_pckt; - hci_uart_pckt *hci_hdr; - int to = DEFAULT_TIMEOUT; - struct timer t; - tHciDataPacket * hciReadPacket = NULL; - tListNode hciTempQueue; - - list_init_head(&hciTempQueue); - - hci_send_cmd(r->ogf, r->ocf, r->clen, r->cparam); - - if(async){ - goto done; - } - - /* Minimum timeout is 1. */ - if(to == 0) - to = 1; - - Timer_Set(&t, to); - - while(1) { - evt_cmd_complete *cc; - evt_cmd_status *cs; - evt_le_meta_event *me; - int len; - -#if ENABLE_MICRO_SLEEP - while(1){ - ATOMIC_SECTION_BEGIN(); - if(Timer_Expired(&t)){ - ATOMIC_SECTION_END(); - goto failed; - } - if(!HCI_Queue_Empty()){ - ATOMIC_SECTION_END(); - break; - } - Enter_Sleep_Mode(); - ATOMIC_SECTION_END(); - } -#else - while(1){ - if(Timer_Expired(&t)){ - goto failed; - } - if(!HCI_Queue_Empty()){ - break; - } - } -#endif - - /* Extract packet from HCI event queue. */ - Disable_SPI_IRQ(); - list_remove_head(&hciReadPktRxQueue, (tListNode **)&hciReadPacket); - - hci_hdr = (void *)hciReadPacket->dataBuff; - if(hci_hdr->type != HCI_EVENT_PKT){ - list_insert_tail(&hciTempQueue, (tListNode *)hciReadPacket); // See comment below - Enable_SPI_IRQ(); - continue; - } - - event_pckt = (void *) (hci_hdr->data); - - ptr = hciReadPacket->dataBuff + (1 + HCI_EVENT_HDR_SIZE); - len = hciReadPacket->data_len - (1 + HCI_EVENT_HDR_SIZE); - - switch (event_pckt->evt) { - - case EVT_CMD_STATUS: - cs = (void *) ptr; - - if (cs->opcode != opcode) - goto failed; - - if (r->event != EVT_CMD_STATUS) { - if (cs->status) { - goto failed; - } - break; - } - - r->rlen = MIN(len, r->rlen); - Osal_MemCpy(r->rparam, ptr, r->rlen); - goto done; - - case EVT_CMD_COMPLETE: - cc = (void *) ptr; - - if (cc->opcode != opcode) - goto failed; - - ptr += EVT_CMD_COMPLETE_SIZE; - len -= EVT_CMD_COMPLETE_SIZE; - - r->rlen = MIN(len, r->rlen); - Osal_MemCpy(r->rparam, ptr, r->rlen); - goto done; - - case EVT_LE_META_EVENT: - me = (void *) ptr; - - if (me->subevent != r->event) - break; - - len -= 1; - r->rlen = MIN(len, r->rlen); - Osal_MemCpy(r->rparam, me->data, r->rlen); - goto done; - - case EVT_HARDWARE_ERROR: - goto failed; - - default: - break; - } - - /* In the meantime there could be other events from the controller. - In this case, insert the packet in a different queue. These packets will be - inserted back in the main queue just before exiting from send_req(). - */ - if(hciReadPacket != NULL) { - list_insert_tail(&hciTempQueue, (tListNode *)hciReadPacket); - hciReadPacket = NULL; - } - /* Be sure there is at list one packet in the pool to process the expected event. */ - if(list_is_empty(&hciReadPktPool)){ // betzw: this is a kind of steeling (should never happen?!?) - pListNode tmp_node; - list_remove_head(&hciReadPktRxQueue, &tmp_node); - list_insert_tail(&hciReadPktPool, tmp_node); -#ifdef POOL_CNT - nr_hciReadPktPool++; -#endif - } - - Enable_SPI_IRQ(); - - } - -failed: - // Insert the packet back into the pool. - if(hciReadPacket != NULL) { - list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket); -#ifdef POOL_CNT - nr_hciReadPktPool++; -#endif - hciReadPacket = NULL; - } - move_list(&hciReadPktRxQueue, &hciTempQueue); - Enable_SPI_IRQ(); - return -1; - -done: - // Insert the packet back into the pool. - if(hciReadPacket != NULL) { - list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket); -#ifdef POOL_CNT - nr_hciReadPktPool++; -#endif - hciReadPacket = NULL; - } - move_list(&hciReadPktRxQueue, &hciTempQueue); - - Enable_SPI_IRQ(); - return 0; -} - -int hci_reset() -{ - struct hci_request rq; - uint8_t status; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_HOST_CTL; - rq.ocf = OCF_RESET; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - return status; -} - -int hci_disconnect(uint16_t handle, uint8_t reason) -{ - struct hci_request rq; - disconnect_cp cp; - uint8_t status; - - cp.handle = handle; - cp.reason = reason; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LINK_CTL; - rq.ocf = OCF_DISCONNECT; - rq.cparam = &cp; - rq.clen = DISCONNECT_CP_SIZE; - rq.event = EVT_CMD_STATUS; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - return status; -} - -int hci_le_read_local_version(uint8_t *hci_version, uint16_t *hci_revision, uint8_t *lmp_pal_version, - uint16_t *manufacturer_name, uint16_t *lmp_pal_subversion) -{ - struct hci_request rq; - read_local_version_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_INFO_PARAM; - rq.ocf = OCF_READ_LOCAL_VERSION; - rq.cparam = NULL; - rq.clen = 0; - rq.rparam = &resp; - rq.rlen = READ_LOCAL_VERSION_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - if (resp.status) { - return resp.status; - } - - - *hci_version = resp.hci_version; - *hci_revision = btohs(resp.hci_revision); - *lmp_pal_version = resp.lmp_pal_version; - *manufacturer_name = btohs(resp.manufacturer_name); - *lmp_pal_subversion = btohs(resp.lmp_pal_subversion); - - return 0; -} - -int hci_le_read_buffer_size(uint16_t *pkt_len, uint8_t *max_pkt) -{ - struct hci_request rq; - le_read_buffer_size_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_READ_BUFFER_SIZE; - rq.cparam = NULL; - rq.clen = 0; - rq.rparam = &resp; - rq.rlen = LE_READ_BUFFER_SIZE_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - if (resp.status) { - return resp.status; - } - - *pkt_len = resp.pkt_len; - *max_pkt = resp.max_pkt; - - return 0; -} - -int hci_le_set_advertising_parameters(uint16_t min_interval, uint16_t max_interval, uint8_t advtype, - uint8_t own_bdaddr_type, uint8_t direct_bdaddr_type, const tBDAddr direct_bdaddr, uint8_t chan_map, - uint8_t filter) -{ - struct hci_request rq; - le_set_adv_parameters_cp adv_cp; - uint8_t status; - - Osal_MemSet(&adv_cp, 0, sizeof(adv_cp)); - adv_cp.min_interval = min_interval; - adv_cp.max_interval = max_interval; - adv_cp.advtype = advtype; - adv_cp.own_bdaddr_type = own_bdaddr_type; - adv_cp.direct_bdaddr_type = direct_bdaddr_type; - if(direct_bdaddr != NULL) - Osal_MemCpy(adv_cp.direct_bdaddr,direct_bdaddr,sizeof(adv_cp.direct_bdaddr)); - adv_cp.chan_map = chan_map; - adv_cp.filter = filter; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_SET_ADV_PARAMETERS; - rq.cparam = &adv_cp; - rq.clen = LE_SET_ADV_PARAMETERS_CP_SIZE; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - return status; -} - -int hci_le_set_advertising_data(uint8_t length, const uint8_t data[]) -{ - struct hci_request rq; - le_set_adv_data_cp adv_cp; - uint8_t status; - - Osal_MemSet(&adv_cp, 0, sizeof(adv_cp)); - adv_cp.length = length; - Osal_MemCpy(adv_cp.data, data, MIN(31,length)); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_SET_ADV_DATA; - rq.cparam = &adv_cp; - rq.clen = LE_SET_ADV_DATA_CP_SIZE; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - return status; -} - -int hci_le_set_advertise_enable(uint8_t enable) -{ - struct hci_request rq; - le_set_advertise_enable_cp adv_cp; - uint8_t status; - - Osal_MemSet(&adv_cp, 0, sizeof(adv_cp)); - adv_cp.enable = enable?1:0; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_SET_ADVERTISE_ENABLE; - rq.cparam = &adv_cp; - rq.clen = LE_SET_ADVERTISE_ENABLE_CP_SIZE; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - return status; -} - -int hci_le_set_scan_parameters(uint8_t type, uint16_t interval, - uint16_t window, uint8_t own_bdaddr_type, - uint8_t filter) -{ - struct hci_request rq; - le_set_scan_parameters_cp scan_cp; - uint8_t status; - - Osal_MemSet(&scan_cp, 0, sizeof(scan_cp)); - scan_cp.type = type; - scan_cp.interval = interval; - scan_cp.window = window; - scan_cp.own_bdaddr_type = own_bdaddr_type; - scan_cp.filter = filter; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_SET_SCAN_PARAMETERS; - rq.cparam = &scan_cp; - rq.clen = LE_SET_SCAN_PARAMETERS_CP_SIZE; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - return status; -} - -int hci_le_set_scan_enable(uint8_t enable, uint8_t filter_dup) -{ - struct hci_request rq; - le_set_scan_enable_cp scan_cp; - uint8_t status; - - Osal_MemSet(&scan_cp, 0, sizeof(scan_cp)); - scan_cp.enable = enable?1:0; - scan_cp.filter_dup = filter_dup; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_SET_SCAN_ENABLE; - rq.cparam = &scan_cp; - rq.clen = LE_SET_SCAN_ENABLE_CP_SIZE; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - return status; -} - -int hci_le_rand(uint8_t random_number[8]) -{ - struct hci_request rq; - le_rand_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_RAND; - rq.cparam = NULL; - rq.clen = 0; - rq.rparam = &resp; - rq.rlen = LE_RAND_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - if (resp.status) { - return resp.status; - } - - Osal_MemCpy(random_number, resp.random, 8); - - return 0; -} - -int hci_le_set_scan_resp_data(uint8_t length, const uint8_t data[]) -{ - struct hci_request rq; - le_set_scan_response_data_cp scan_resp_cp; - uint8_t status; - - Osal_MemSet(&scan_resp_cp, 0, sizeof(scan_resp_cp)); - scan_resp_cp.length = length; - Osal_MemCpy(scan_resp_cp.data, data, MIN(31,length)); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_SET_SCAN_RESPONSE_DATA; - rq.cparam = &scan_resp_cp; - rq.clen = LE_SET_SCAN_RESPONSE_DATA_CP_SIZE; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - return status; -} - -int hci_le_read_advertising_channel_tx_power(int8_t *tx_power_level) -{ - struct hci_request rq; - le_read_adv_channel_tx_power_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_READ_ADV_CHANNEL_TX_POWER; - rq.cparam = NULL; - rq.clen = 0; - rq.rparam = &resp; - rq.rlen = LE_RAND_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - if (resp.status) { - return resp.status; - } - - *tx_power_level = resp.level; - - return 0; -} - -int hci_le_set_random_address(tBDAddr bdaddr) -{ - struct hci_request rq; - le_set_random_address_cp set_rand_addr_cp; - uint8_t status; - - Osal_MemSet(&set_rand_addr_cp, 0, sizeof(set_rand_addr_cp)); - Osal_MemCpy(set_rand_addr_cp.bdaddr, bdaddr, sizeof(tBDAddr)); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_SET_RANDOM_ADDRESS; - rq.cparam = &set_rand_addr_cp; - rq.clen = LE_SET_RANDOM_ADDRESS_CP_SIZE; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - return status; -} - -int hci_read_bd_addr(tBDAddr bdaddr) -{ - struct hci_request rq; - read_bd_addr_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_INFO_PARAM; - rq.ocf = OCF_READ_BD_ADDR; - rq.cparam = NULL; - rq.clen = 0; - rq.rparam = &resp; - rq.rlen = READ_BD_ADDR_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - if (resp.status) { - return resp.status; - } - Osal_MemCpy(bdaddr, resp.bdaddr, sizeof(tBDAddr)); - - return 0; -} - -int hci_le_create_connection(uint16_t interval, uint16_t window, uint8_t initiator_filter, uint8_t peer_bdaddr_type, - const tBDAddr peer_bdaddr, uint8_t own_bdaddr_type, uint16_t min_interval, uint16_t max_interval, - uint16_t latency, uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length) -{ - struct hci_request rq; - le_create_connection_cp create_cp; - uint8_t status; - - Osal_MemSet(&create_cp, 0, sizeof(create_cp)); - create_cp.interval = interval; - create_cp.window = window; - create_cp.initiator_filter = initiator_filter; - create_cp.peer_bdaddr_type = peer_bdaddr_type; - Osal_MemCpy(create_cp.peer_bdaddr, peer_bdaddr, sizeof(tBDAddr)); - create_cp.own_bdaddr_type = own_bdaddr_type; - create_cp.min_interval=min_interval; - create_cp.max_interval=max_interval; - create_cp.latency = latency; - create_cp.supervision_timeout=supervision_timeout; - create_cp.min_ce_length=min_ce_length; - create_cp.max_ce_length=max_ce_length; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_CREATE_CONN; - rq.cparam = &create_cp; - rq.clen = LE_CREATE_CONN_CP_SIZE; - rq.event = EVT_CMD_STATUS; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - return status; -} - -int hci_le_create_connection_cancel(void) -{ - struct hci_request rq; - uint8_t status; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_CREATE_CONN_CANCEL; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - return status; -} - -int hci_le_encrypt(uint8_t key[16], uint8_t plaintextData[16], uint8_t encryptedData[16]) -{ - struct hci_request rq; - le_encrypt_cp params; - le_encrypt_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - Osal_MemCpy(params.key, key, 16); - Osal_MemCpy(params.plaintext, plaintextData, 16); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_ENCRYPT; - rq.cparam = ¶ms; - rq.clen = LE_ENCRYPT_CP_SIZE; - rq.rparam = &resp; - rq.rlen = LE_ENCRYPT_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0){ - return BLE_STATUS_TIMEOUT; - } - - if (resp.status) { - return resp.status; - } - - Osal_MemCpy(encryptedData, resp.encdata, 16); - - return 0; -} - -int hci_le_ltk_request_reply(uint8_t key[16]) -{ - struct hci_request rq; - le_ltk_reply_cp params; - le_ltk_reply_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - params.handle = 1; - Osal_MemCpy(params.key, key, 16); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_LTK_REPLY; - rq.cparam = ¶ms; - rq.clen = LE_LTK_REPLY_CP_SIZE; - rq.rparam = &resp; - rq.rlen = LE_LTK_REPLY_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - return resp.status; -} - -int hci_le_ltk_request_neg_reply() -{ - struct hci_request rq; - le_ltk_neg_reply_cp params; - le_ltk_neg_reply_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - params.handle = 1; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_LTK_NEG_REPLY; - rq.cparam = ¶ms; - rq.clen = LE_LTK_NEG_REPLY_CP_SIZE; - rq.rparam = &resp; - rq.rlen = LE_LTK_NEG_REPLY_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0) - return BLE_STATUS_TIMEOUT; - - return resp.status; -} - -int hci_le_read_white_list_size(uint8_t *size) -{ - struct hci_request rq; - le_read_white_list_size_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_READ_WHITE_LIST_SIZE; - rq.rparam = &resp; - rq.rlen = LE_READ_WHITE_LIST_SIZE_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0){ - return BLE_STATUS_TIMEOUT; - } - - if (resp.status) { - return resp.status; - } - - *size = resp.size; - - return 0; -} - -int hci_le_clear_white_list() -{ - struct hci_request rq; - uint8_t status; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_CLEAR_WHITE_LIST; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0){ - return BLE_STATUS_TIMEOUT; - } - - return status; -} - -int hci_le_add_device_to_white_list(uint8_t bdaddr_type, tBDAddr bdaddr) -{ - struct hci_request rq; - le_add_device_to_white_list_cp params; - uint8_t status; - - params.bdaddr_type = bdaddr_type; - Osal_MemCpy(params.bdaddr, bdaddr, 6); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_ADD_DEVICE_TO_WHITE_LIST; - rq.cparam = ¶ms; - rq.clen = LE_ADD_DEVICE_TO_WHITE_LIST_CP_SIZE; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0){ - return BLE_STATUS_TIMEOUT; - } - - return status; -} - -int hci_le_remove_device_from_white_list(uint8_t bdaddr_type, tBDAddr bdaddr) -{ - struct hci_request rq; - le_remove_device_from_white_list_cp params; - uint8_t status; - - params.bdaddr_type = bdaddr_type; - Osal_MemCpy(params.bdaddr, bdaddr, 6); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_REMOVE_DEVICE_FROM_WHITE_LIST; - rq.cparam = ¶ms; - rq.clen = LE_REMOVE_DEVICE_FROM_WHITE_LIST_CP_SIZE; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0){ - return BLE_STATUS_TIMEOUT; - } - - return status; -} - -int hci_read_transmit_power_level(uint16_t *conn_handle, uint8_t type, int8_t * tx_level) -{ - struct hci_request rq; - read_transmit_power_level_cp params; - read_transmit_power_level_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - params.handle = *conn_handle; - params.type = type; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_HOST_CTL; - rq.ocf = OCF_READ_TRANSMIT_POWER_LEVEL; - rq.cparam = ¶ms; - rq.clen = READ_TRANSMIT_POWER_LEVEL_CP_SIZE; - rq.rparam = &resp; - rq.rlen = READ_TRANSMIT_POWER_LEVEL_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0){ - return BLE_STATUS_TIMEOUT; - } - - if (resp.status) { - return resp.status; - } - - *conn_handle = resp.handle; - *tx_level = resp.level; - - return 0; -} - -int hci_read_rssi(uint16_t *conn_handle, int8_t * rssi) -{ - struct hci_request rq; - read_rssi_cp params; - read_rssi_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - params.handle = *conn_handle; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_STATUS_PARAM; - rq.ocf = OCF_READ_RSSI; - rq.cparam = ¶ms; - rq.clen = READ_RSSI_CP_SIZE; - rq.rparam = &resp; - rq.rlen = READ_RSSI_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0){ - return BLE_STATUS_TIMEOUT; - } - - if (resp.status) { - return resp.status; - } - - *conn_handle = resp.handle; - *rssi = resp.rssi; - - return 0; -} - -int hci_le_read_local_supported_features(uint8_t *features) -{ - struct hci_request rq; - le_read_local_supported_features_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_READ_LOCAL_SUPPORTED_FEATURES; - rq.rparam = &resp; - rq.rlen = LE_READ_LOCAL_SUPPORTED_FEATURES_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0){ - return BLE_STATUS_TIMEOUT; - } - - if (resp.status) { - return resp.status; - } - - Osal_MemCpy(features, resp.features, sizeof(resp.features)); - - return 0; -} - -int hci_le_read_channel_map(uint16_t conn_handle, uint8_t ch_map[5]) -{ - struct hci_request rq; - le_read_channel_map_cp params; - le_read_channel_map_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - params.handle = conn_handle; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_READ_CHANNEL_MAP; - rq.cparam = ¶ms; - rq.clen = LE_READ_CHANNEL_MAP_CP_SIZE; - rq.rparam = &resp; - rq.rlen = LE_READ_CHANNEL_MAP_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0){ - return BLE_STATUS_TIMEOUT; - } - - if (resp.status) { - return resp.status; - } - - Osal_MemCpy(ch_map, resp.map, 5); - - return 0; -} - -int hci_le_read_supported_states(uint8_t states[8]) -{ - struct hci_request rq; - le_read_supported_states_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_READ_SUPPORTED_STATES; - rq.rparam = &resp; - rq.rlen = LE_READ_SUPPORTED_STATES_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0){ - return BLE_STATUS_TIMEOUT; - } - - if (resp.status) { - return resp.status; - } - - Osal_MemCpy(states, resp.states, 8); - - return 0; -} - -int hci_le_receiver_test(uint8_t frequency) -{ - struct hci_request rq; - le_receiver_test_cp params; - uint8_t status; - - params.frequency = frequency; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_RECEIVER_TEST; - rq.cparam = ¶ms; - rq.clen = LE_RECEIVER_TEST_CP_SIZE; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0){ - return BLE_STATUS_TIMEOUT; - } - - return status; -} - -int hci_le_transmitter_test(uint8_t frequency, uint8_t length, uint8_t payload) -{ - struct hci_request rq; - le_transmitter_test_cp params; - uint8_t status; - - params.frequency = frequency; - params.length = length; - params.payload = payload; - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_TRANSMITTER_TEST; - rq.cparam = ¶ms; - rq.clen = LE_TRANSMITTER_TEST_CP_SIZE; - rq.rparam = &status; - rq.rlen = 1; - - if (hci_send_req(&rq, FALSE) < 0){ - return BLE_STATUS_TIMEOUT; - } - - return status; -} - -int hci_le_test_end(uint16_t *num_pkts) -{ - struct hci_request rq; - le_test_end_rp resp; - - Osal_MemSet(&resp, 0, sizeof(resp)); - - Osal_MemSet(&rq, 0, sizeof(rq)); - rq.ogf = OGF_LE_CTL; - rq.ocf = OCF_LE_TEST_END; - rq.rparam = &resp; - rq.rlen = LE_TEST_END_RP_SIZE; - - if (hci_send_req(&rq, FALSE) < 0){ - return BLE_STATUS_TIMEOUT; - } - - if (resp.status) { - return resp.status; - } - - *num_pkts = resp.num_pkts; - - return 0; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/source/bluenrg-hci/utils/ble_gp_timer.c Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2004, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Adam Dunkels <adam@sics.se> + * + */ + +#include "ble_clock.h" +#include "ble_gp_timer.h" + +/*---------------------------------------------------------------------------*/ +/** + * Set a timer. + * + * This function sets a timer for a time sometime in the + * future. The function timer_expired() will evaluate to true after + * the timer has expired. + * + * @param[in] t A pointer to the timer + * @param[in] interval The interval before the timer expires. + * + */ +void +Timer_Set(struct timer *t, tClockTime interval) +{ + t->interval = interval; + t->start = Clock_Time(); +} +/*---------------------------------------------------------------------------*/ +/** + * Reset the timer with the same interval. + * + * This function resets the timer with the same interval that was + * given to the timer_set() function. The start point of the interval + * is the exact time that the timer last expired. Therefore, this + * function will cause the timer to be stable over time, unlike the + * timer_restart() function. + * + * \param t A pointer to the timer. + * + * \sa timer_restart() + */ +void +Timer_Reset(struct timer *t) +{ + t->start += t->interval; +} +/*---------------------------------------------------------------------------*/ +/** + * Restart the timer from the current point in time + * + * This function restarts a timer with the same interval that was + * given to the timer_set() function. The timer will start at the + * current time. + * + * \note A periodic timer will drift if this function is used to reset + * it. For preioric timers, use the timer_reset() function instead. + * + * \param t A pointer to the timer. + * + * \sa timer_reset() + */ +void +Timer_Restart(struct timer *t) +{ + t->start = Clock_Time(); +} +/*---------------------------------------------------------------------------*/ +/** + * Check if a timer has expired. + * + * This function tests if a timer has expired and returns true or + * false depending on its status. + * + * \param t A pointer to the timer + * + * \return Non-zero if the timer has expired, zero otherwise. + * + */ +int +Timer_Expired(struct timer *t) +{ + /* Note: Can not return diff >= t->interval so we add 1 to diff and return + t->interval < diff - required to avoid an internal error in mspgcc. */ + tClockTime diff = (Clock_Time() - t->start) + 1; + return t->interval < diff; + +} +/*---------------------------------------------------------------------------*/ +/** + * The time until the timer expires + * + * This function returns the time until the timer expires. + * + * \param t A pointer to the timer + * + * \return The time until the timer expires + * + */ +tClockTime +Timer_Remaining(struct timer *t) +{ + return t->start + t->interval - Clock_Time(); +} +/*---------------------------------------------------------------------------*/ +#ifdef __DMA_LP__ + +tBleStatus Blue_NRG_HCI_Timer_Start(uint32_t expiryTime, + TIMER_HCI_TIMEOUT_NOTIFY_CALLBACK_TYPE timercb, + uint8_t *timerID) +{ + TIMER_Create(eTimerModuleID_BlueNRG_HCI, timerID, eTimerMode_SingleShot, + (pf_TIMER_TimerCallBack_t) timercb); + TIMER_Start(*timerID, expiryTime*1000/TIMERSERVER_TICK_VALUE); + + return (BLE_STATUS_SUCCESS); +} + +/*---------------------------------------------------------------------------*/ +tBleStatus Blue_NRG_HCI_Timer_Stop(uint8_t timerID) +{ + TIMER_Delete(timerID); + + return (BLE_STATUS_SUCCESS); +} + +#endif /* __DMA_LP__ */ +/*---------------------------------------------------------------------------*/ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/source/bluenrg-hci/utils/ble_list.c Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,118 @@ +/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** +* File Name : ble_list.c +* Author : AMS - HEA&RF BU +* Version : V1.0.0 +* Date : 19-July-2012 +* Description : Circular Linked List Implementation. +******************************************************************************** +* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ + +/****************************************************************************** + * Include Files +******************************************************************************/ +#include <ble_hal_types.h> +#include "ble_list.h" + +/****************************************************************************** + * Function Definitions +******************************************************************************/ +void list_init_head (tListNode * listHead) +{ + listHead->next = listHead; + listHead->prev = listHead; +} + +uint8_t list_is_empty (tListNode * listHead) +{ + return ((listHead->next == listHead)? TRUE:FALSE); +} + +void list_insert_head (tListNode * listHead, tListNode * node) +{ + node->next = listHead->next; + node->prev = listHead; + listHead->next = node; + (node->next)->prev = node; +} + + +void list_insert_tail (tListNode * listHead, tListNode * node) +{ + node->next = listHead; + node->prev = listHead->prev; + listHead->prev = node; + (node->prev)->next = node; +} + + +void list_remove_node (tListNode * node) +{ + (node->prev)->next = node->next; + (node->next)->prev = node->prev; +} + + +void list_remove_head (tListNode * listHead, tListNode ** node ) +{ + *node = listHead->next; + list_remove_node (listHead->next); + (*node)->next = NULL; + (*node)->prev = NULL; +} + + +void list_remove_tail (tListNode * listHead, tListNode ** node ) +{ + *node = listHead->prev; + list_remove_node (listHead->prev); + (*node)->next = NULL; + (*node)->prev = NULL; +} + + +void list_insert_node_after (tListNode * node, tListNode * ref_node) +{ + node->next = ref_node->next; + node->prev = ref_node; + ref_node->next = node; + (node->next)->prev = node; +} + + +void list_insert_node_before (tListNode * node, tListNode * ref_node) +{ + node->next = ref_node; + node->prev = ref_node->prev; + ref_node->prev = node; + (node->prev)->next = node; +} + + +int list_get_size (tListNode * listHead) +{ + int size = 0; + tListNode * temp = listHead->next; + while (temp != listHead) + { + size++; + temp = temp->next; + } + return (size); +} + +void list_get_next_node (tListNode * ref_node, tListNode ** node) +{ + *node = ref_node->next; +} + + +void list_get_prev_node (tListNode * ref_node, tListNode ** node) +{ + *node = ref_node->prev; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/source/bluenrg-hci/utils/ble_osal.c Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,72 @@ +/** +****************************************************************************** +* @file ble_osal.c +* @author AMS - HEA&RF BU / CL +* @version V1.0.0 +* @date 04-July-2014 +* @brief Implementation of OS abstraction layer functions used by the +* library. +****************************************************************************** +* @attention + * + * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include <string.h> +#include <ble_osal.h> + + /** + * @brief Osal_MemCpy + * @param dest: Pointer to the destination buffer + * @param src : Pointer to the source buffer + * @param size: Number of bytes to copy from the source to the destination + * buffer + * @retval Pointer to the destination buffer + */ +void* Osal_MemCpy(void *dest, const void *src, unsigned int size) +{ + return(memcpy(dest,src,size)); +} + +/** + * @brief Osal_MemSet + * @param ptr : Pointer to block of memory to fill + * @param value: Value to assign to each byte of the memory block + * @param size : Number of bytes to be set to "value" + * @retval Pointer to the filled block of memory + */ +void* Osal_MemSet(void *ptr, int value, unsigned int size) +{ + return(memset(ptr,value,size)); +} + +/****************************************************************************** + * local Functions + *****************************************************************************/ + + /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ \ No newline at end of file
--- a/source/bluenrg-hci/utils/gp_timer.c Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2004, Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the Contiki operating system. - * - * Author: Adam Dunkels <adam@sics.se> - * - */ - -#include "clock.h" -#include "gp_timer.h" - -/*---------------------------------------------------------------------------*/ -/** - * Set a timer. - * - * This function sets a timer for a time sometime in the - * future. The function timer_expired() will evaluate to true after - * the timer has expired. - * - * @param[in] t A pointer to the timer - * @param[in] interval The interval before the timer expires. - * - */ -void -Timer_Set(struct timer *t, tClockTime interval) -{ - t->interval = interval; - t->start = Clock_Time(); -} -/*---------------------------------------------------------------------------*/ -/** - * Reset the timer with the same interval. - * - * This function resets the timer with the same interval that was - * given to the timer_set() function. The start point of the interval - * is the exact time that the timer last expired. Therefore, this - * function will cause the timer to be stable over time, unlike the - * timer_restart() function. - * - * \param t A pointer to the timer. - * - * \sa timer_restart() - */ -void -Timer_Reset(struct timer *t) -{ - t->start += t->interval; -} -/*---------------------------------------------------------------------------*/ -/** - * Restart the timer from the current point in time - * - * This function restarts a timer with the same interval that was - * given to the timer_set() function. The timer will start at the - * current time. - * - * \note A periodic timer will drift if this function is used to reset - * it. For preioric timers, use the timer_reset() function instead. - * - * \param t A pointer to the timer. - * - * \sa timer_reset() - */ -void -Timer_Restart(struct timer *t) -{ - t->start = Clock_Time(); -} -/*---------------------------------------------------------------------------*/ -/** - * Check if a timer has expired. - * - * This function tests if a timer has expired and returns true or - * false depending on its status. - * - * \param t A pointer to the timer - * - * \return Non-zero if the timer has expired, zero otherwise. - * - */ -int -Timer_Expired(struct timer *t) -{ - /* Note: Can not return diff >= t->interval so we add 1 to diff and return - t->interval < diff - required to avoid an internal error in mspgcc. */ - tClockTime diff = (Clock_Time() - t->start) + 1; - return t->interval < diff; - -} -/*---------------------------------------------------------------------------*/ -/** - * The time until the timer expires - * - * This function returns the time until the timer expires. - * - * \param t A pointer to the timer - * - * \return The time until the timer expires - * - */ -tClockTime -Timer_Remaining(struct timer *t) -{ - return t->start + t->interval - Clock_Time(); -} -/*---------------------------------------------------------------------------*/ -#ifdef __DMA_LP__ - -tBleStatus Blue_NRG_HCI_Timer_Start(uint32_t expiryTime, - TIMER_HCI_TIMEOUT_NOTIFY_CALLBACK_TYPE timercb, - uint8_t *timerID) -{ - TIMER_Create(eTimerModuleID_BlueNRG_HCI, timerID, eTimerMode_SingleShot, - (pf_TIMER_TimerCallBack_t) timercb); - TIMER_Start(*timerID, expiryTime*1000/TIMERSERVER_TICK_VALUE); - - return (BLE_STATUS_SUCCESS); -} - -/*---------------------------------------------------------------------------*/ -tBleStatus Blue_NRG_HCI_Timer_Stop(uint8_t timerID) -{ - TIMER_Delete(timerID); - - return (BLE_STATUS_SUCCESS); -} - -#endif /* __DMA_LP__ */ -/*---------------------------------------------------------------------------*/
--- a/source/bluenrg-hci/utils/list.c Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** -* File Name : list.c -* Author : AMS - HEA&RF BU -* Version : V1.0.0 -* Date : 19-July-2012 -* Description : Circular Linked List Implementation. -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -/****************************************************************************** - * Include Files -******************************************************************************/ -#include <hal_types.h> -#include "list.h" - -/****************************************************************************** - * Function Definitions -******************************************************************************/ -void list_init_head (tListNode * listHead) -{ - listHead->next = listHead; - listHead->prev = listHead; -} - -uint8_t list_is_empty (tListNode * listHead) -{ - return ((listHead->next == listHead)? TRUE:FALSE); -} - -void list_insert_head (tListNode * listHead, tListNode * node) -{ - node->next = listHead->next; - node->prev = listHead; - listHead->next = node; - (node->next)->prev = node; -} - - -void list_insert_tail (tListNode * listHead, tListNode * node) -{ - node->next = listHead; - node->prev = listHead->prev; - listHead->prev = node; - (node->prev)->next = node; -} - - -void list_remove_node (tListNode * node) -{ - (node->prev)->next = node->next; - (node->next)->prev = node->prev; -} - - -void list_remove_head (tListNode * listHead, tListNode ** node ) -{ - *node = listHead->next; - list_remove_node (listHead->next); - (*node)->next = NULL; - (*node)->prev = NULL; -} - - -void list_remove_tail (tListNode * listHead, tListNode ** node ) -{ - *node = listHead->prev; - list_remove_node (listHead->prev); - (*node)->next = NULL; - (*node)->prev = NULL; -} - - -void list_insert_node_after (tListNode * node, tListNode * ref_node) -{ - node->next = ref_node->next; - node->prev = ref_node; - ref_node->next = node; - (node->next)->prev = node; -} - - -void list_insert_node_before (tListNode * node, tListNode * ref_node) -{ - node->next = ref_node; - node->prev = ref_node->prev; - ref_node->prev = node; - (node->prev)->next = node; -} - - -int list_get_size (tListNode * listHead) -{ - int size = 0; - tListNode * temp = listHead->next; - while (temp != listHead) - { - size++; - temp = temp->next; - } - return (size); -} - -void list_get_next_node (tListNode * ref_node, tListNode ** node) -{ - *node = ref_node->next; -} - - -void list_get_prev_node (tListNode * ref_node, tListNode ** node) -{ - *node = ref_node->prev; -} -
--- a/source/bluenrg-hci/utils/osal.c Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/** -****************************************************************************** -* @file osal.c -* @author AMS - HEA&RF BU / CL -* @version V1.0.0 -* @date 04-July-2014 -* @brief Implementation of OS abstraction layer functions used by the -* library. -****************************************************************************** -* @attention - * - * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include <string.h> -#include <osal.h> - - /** - * @brief Osal_MemCpy - * @param dest: Pointer to the destination buffer - * @param src : Pointer to the source buffer - * @param size: Number of bytes to copy from the source to the destination - * buffer - * @retval Pointer to the destination buffer - */ -void* Osal_MemCpy(void *dest, const void *src, unsigned int size) -{ - return(memcpy(dest,src,size)); -} - -/** - * @brief Osal_MemSet - * @param ptr : Pointer to block of memory to fill - * @param value: Value to assign to each byte of the memory block - * @param size : Number of bytes to be set to "value" - * @retval Pointer to the filled block of memory - */ -void* Osal_MemSet(void *ptr, int value, unsigned int size) -{ - return(memset(ptr,value,size)); -} - -/****************************************************************************** - * local Functions - *****************************************************************************/ - - /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/source/platform/ble_clock.c Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,36 @@ + +#include "ble_clock.h" +#ifdef YOTTA_CFG_MBED_OS + #include "mbed-drivers/wait_api.h" + #include "mbed-drivers/rtc_time.h" +#else + #include "wait_api.h" + #include "rtc_time.h" +#endif + +const uint32_t CLOCK_SECOND = 1000; + +/*---------------------------------------------------------------------------*/ + +void Clock_Init(void) +{ + //Not Used +} + +/*---------------------------------------------------------------------------*/ + +tClockTime Clock_Time(void) +{ + return clock(); +} + +/*---------------------------------------------------------------------------*/ +/** + * Wait for a multiple of 1 ms. + * + */ +void Clock_Wait(uint32_t i) +{ + wait_ms(i); +} +/*---------------------------------------------------------------------------*/ \ No newline at end of file
--- a/source/platform/btle.cpp Thu Sep 15 10:51:44 2016 +0100 +++ b/source/platform/btle.cpp Thu Sep 15 10:52:09 2016 +0100 @@ -40,7 +40,7 @@ #include "BlueNRGGap.h" #include "BlueNRGGattServer.h" #include "BlueNRGGattClient.h" -#include "Utils.h" +#include "ble_utils.h" #include "x_nucleo_idb0xa1_targets.h" @@ -52,19 +52,19 @@ /* C File Includes ------------------------------------------------------------------*/ #include <stdio.h> #include <string.h> -#include "hci.h" -#include "hci_const.h" +#include "ble_hci.h" +#include "ble_hci_const.h" #include "bluenrg_aci.h" #include "bluenrg_hal_aci.h" #include "bluenrg_gap.h" #include "bluenrg_utils.h" -#include "hal_types.h" -#include "hal.h" -#include "gp_timer.h" -#include "osal.h" -#include "sm.h" -#include "debug.h" +#include "ble_hal_types.h" +#include "ble_hal.h" +#include "ble_gp_timer.h" +#include "ble_osal.h" +#include "ble_sm.h" +#include "ble_debug.h" #ifdef __cplusplus }
--- a/source/platform/clock.c Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ - -#include "clock.h" -#ifdef YOTTA_CFG_MBED_OS - #include "mbed-drivers/wait_api.h" - #include "mbed-drivers/rtc_time.h" -#else - #include "wait_api.h" - #include "rtc_time.h" -#endif - -const uint32_t CLOCK_SECOND = 1000; - -/*---------------------------------------------------------------------------*/ - -void Clock_Init(void) -{ - //Not Used -} - -/*---------------------------------------------------------------------------*/ - -tClockTime Clock_Time(void) -{ - return clock(); -} - -/*---------------------------------------------------------------------------*/ -/** - * Wait for a multiple of 1 ms. - * - */ -void Clock_Wait(uint32_t i) -{ - wait_ms(i); -} -/*---------------------------------------------------------------------------*/ \ No newline at end of file
--- a/source/platform/stm32_bluenrg_ble.cpp Thu Sep 15 10:51:44 2016 +0100 +++ b/source/platform/stm32_bluenrg_ble.cpp Thu Sep 15 10:52:09 2016 +0100 @@ -52,8 +52,8 @@ #endif #include "stm32_bluenrg_ble.h" -#include "gp_timer.h" -#include "debug.h" +#include "ble_gp_timer.h" +#include "ble_debug.h" void BlueNRG_RST(void)
--- a/source/utils/Payload.cpp Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +0,0 @@ -/* mbed Microcontroller Library -* Copyright (c) 2006-2013 ARM Limited -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include <Payload.h> - -Payload::Payload() { - stringLength = 0; - payloadUnitCount = 0; - payload = NULL; -} - -Payload::Payload(const uint8_t *tokenString, uint8_t string_ength) { - // initialize private data members - stringLength = string_ength; - payloadUnitCount = 0; - payload = NULL; - - int index = 0; - while( index!=stringLength) { - int len=tokenString[index]; - index=index+1+len; - payloadUnitCount++; - } - - UnitPayload *obj = new UnitPayload[payloadUnitCount]; - int i=0; - int c=0; - int j,k; - - while(i<payloadUnitCount) - { - obj[i].length=tokenString[c]; - obj[i].id=tokenString[c+1]; - - obj[i].data = new uint8_t[obj[i].length]; - for(j=c+2,k=0;(j<(c+obj[i].length+1))&&(k<obj[i].length-1);j++,k++) - { - obj[i].data[k]=tokenString[j]; - - } - - c=c+obj[i].length+1; - i++; - - } - payload = obj; -} - -uint8_t Payload::getPayloadUnitCount() { - return payloadUnitCount; -} - -uint8_t Payload::getIDAtIndex(int index) { - return payload[index].get_id(); -} - -uint8_t Payload::getLengthAtIndex(int index) { - return payload[index].get_length(); -} - -uint8_t* Payload::getDataAtIndex(int index) { - return payload[index].get_data(); -} - -int8_t Payload::getInt8AtIndex(int index) { - uint8_t* str = payload[index].get_data(); - int8_t value = (int8_t)str[0]; - return value; -} - -uint16_t Payload::getUint16AtIndex(int index) { - uint16_t* str = (uint16_t*)payload[index].get_data(); - uint16_t value = str[0]; - return value; -} - -uint8_t* Payload::getSerializedAdDataAtIndex(int index) { - uint8_t length = payload[index].get_length(); - uint8_t* data = payload[index].get_data(); - uint8_t id = payload[index].get_id(); - uint8_t *serializedAdData = new uint8_t[length]; - - serializedAdData[0] = id; - for(int i=0; i<length-1; i++) { - serializedAdData[i+1] = data[i]; - } - return serializedAdData; -} - -Payload::~Payload() { - int i = 0; - - if(payload) { - while(i<payloadUnitCount) { - if(payload->data) { - delete[] payload->data; - payload->data = NULL; - } - } - delete[] payload; - payload = NULL; - } - -} -
--- a/source/utils/Utils.cpp Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -/* mbed Microcontroller Library -* Copyright (c) 2006-2013 ARM Limited -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "Utils.h" - -/**************************************************************************/ -/*! - @brief sets values of EN_HIGH_POWER and PA_LEVEL corresponding to dBMLevel of tx power - -*/ -/**************************************************************************/ -tBleStatus getHighPowerAndPALevelValue(int8_t dBMLevel, int8_t& EN_HIGH_POWER, int8_t& PA_LEVEL) { - tBleStatus ret = BLE_STATUS_SUCCESS; - - if(dBMLevel==-18) { - EN_HIGH_POWER = 0; - PA_LEVEL = 0; - } - else if(dBMLevel==-15) { - EN_HIGH_POWER = 0; - PA_LEVEL = 1; - } - else if(dBMLevel==-14) { - EN_HIGH_POWER = 1; - PA_LEVEL = 0; - } - else if(dBMLevel==-12) { - EN_HIGH_POWER = 0; - PA_LEVEL = 2; - } - else if(dBMLevel==-11) { - EN_HIGH_POWER = 1; - PA_LEVEL = 1; - } - else if(dBMLevel==-9) { - EN_HIGH_POWER = 0; - PA_LEVEL = 3; - } - else if(dBMLevel==-8) { - EN_HIGH_POWER = 1; - PA_LEVEL = 2; - } - else if(dBMLevel==-6) { - EN_HIGH_POWER = 0; - PA_LEVEL = 4; - } - else if(dBMLevel==-5) { - EN_HIGH_POWER = 1; - PA_LEVEL = 3; - } - else if(dBMLevel==-2) { - EN_HIGH_POWER = 1; - PA_LEVEL = 4; - } - else if(dBMLevel==0) { - EN_HIGH_POWER = 0; - PA_LEVEL = 6; - } - else if(dBMLevel==2) { - EN_HIGH_POWER = 1; - PA_LEVEL = 5; - } - else if(dBMLevel==4) { - EN_HIGH_POWER = 1; - PA_LEVEL = 6; - } - else if(dBMLevel==5) { - EN_HIGH_POWER = 0; - PA_LEVEL = 7; - } - else if(dBMLevel==8) { - EN_HIGH_POWER = 1; - PA_LEVEL = 7; - } - else { - ret = ERR_INVALID_HCI_CMD_PARAMS; - } - - return ret; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/source/utils/ble_payload.cpp Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,117 @@ +/* mbed Microcontroller Library +* Copyright (c) 2006-2013 ARM Limited +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include <ble_payload.h> + +Payload::Payload() { + stringLength = 0; + payloadUnitCount = 0; + payload = NULL; +} + +Payload::Payload(const uint8_t *tokenString, uint8_t string_ength) { + // initialize private data members + stringLength = string_ength; + payloadUnitCount = 0; + payload = NULL; + + int index = 0; + while( index!=stringLength) { + int len=tokenString[index]; + index=index+1+len; + payloadUnitCount++; + } + + UnitPayload *obj = new UnitPayload[payloadUnitCount]; + int i=0; + int c=0; + int j,k; + + while(i<payloadUnitCount) + { + obj[i].length=tokenString[c]; + obj[i].id=tokenString[c+1]; + + obj[i].data = new uint8_t[obj[i].length]; + for(j=c+2,k=0;(j<(c+obj[i].length+1))&&(k<obj[i].length-1);j++,k++) + { + obj[i].data[k]=tokenString[j]; + + } + + c=c+obj[i].length+1; + i++; + + } + payload = obj; +} + +uint8_t Payload::getPayloadUnitCount() { + return payloadUnitCount; +} + +uint8_t Payload::getIDAtIndex(int index) { + return payload[index].get_id(); +} + +uint8_t Payload::getLengthAtIndex(int index) { + return payload[index].get_length(); +} + +uint8_t* Payload::getDataAtIndex(int index) { + return payload[index].get_data(); +} + +int8_t Payload::getInt8AtIndex(int index) { + uint8_t* str = payload[index].get_data(); + int8_t value = (int8_t)str[0]; + return value; +} + +uint16_t Payload::getUint16AtIndex(int index) { + uint16_t* str = (uint16_t*)payload[index].get_data(); + uint16_t value = str[0]; + return value; +} + +uint8_t* Payload::getSerializedAdDataAtIndex(int index) { + uint8_t length = payload[index].get_length(); + uint8_t* data = payload[index].get_data(); + uint8_t id = payload[index].get_id(); + uint8_t *serializedAdData = new uint8_t[length]; + + serializedAdData[0] = id; + for(int i=0; i<length-1; i++) { + serializedAdData[i+1] = data[i]; + } + return serializedAdData; +} + +Payload::~Payload() { + int i = 0; + + if(payload) { + while(i<payloadUnitCount) { + if(payload->data) { + delete[] payload->data; + payload->data = NULL; + } + } + delete[] payload; + payload = NULL; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/source/utils/ble_utils.cpp Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,93 @@ +/* mbed Microcontroller Library +* Copyright (c) 2006-2013 ARM Limited +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "ble_utils.h" + +/**************************************************************************/ +/*! + @brief sets values of EN_HIGH_POWER and PA_LEVEL corresponding to dBMLevel of tx power + +*/ +/**************************************************************************/ +tBleStatus getHighPowerAndPALevelValue(int8_t dBMLevel, int8_t& EN_HIGH_POWER, int8_t& PA_LEVEL) { + tBleStatus ret = BLE_STATUS_SUCCESS; + + if(dBMLevel==-18) { + EN_HIGH_POWER = 0; + PA_LEVEL = 0; + } + else if(dBMLevel==-15) { + EN_HIGH_POWER = 0; + PA_LEVEL = 1; + } + else if(dBMLevel==-14) { + EN_HIGH_POWER = 1; + PA_LEVEL = 0; + } + else if(dBMLevel==-12) { + EN_HIGH_POWER = 0; + PA_LEVEL = 2; + } + else if(dBMLevel==-11) { + EN_HIGH_POWER = 1; + PA_LEVEL = 1; + } + else if(dBMLevel==-9) { + EN_HIGH_POWER = 0; + PA_LEVEL = 3; + } + else if(dBMLevel==-8) { + EN_HIGH_POWER = 1; + PA_LEVEL = 2; + } + else if(dBMLevel==-6) { + EN_HIGH_POWER = 0; + PA_LEVEL = 4; + } + else if(dBMLevel==-5) { + EN_HIGH_POWER = 1; + PA_LEVEL = 3; + } + else if(dBMLevel==-2) { + EN_HIGH_POWER = 1; + PA_LEVEL = 4; + } + else if(dBMLevel==0) { + EN_HIGH_POWER = 0; + PA_LEVEL = 6; + } + else if(dBMLevel==2) { + EN_HIGH_POWER = 1; + PA_LEVEL = 5; + } + else if(dBMLevel==4) { + EN_HIGH_POWER = 1; + PA_LEVEL = 6; + } + else if(dBMLevel==5) { + EN_HIGH_POWER = 0; + PA_LEVEL = 7; + } + else if(dBMLevel==8) { + EN_HIGH_POWER = 1; + PA_LEVEL = 7; + } + else { + ret = ERR_INVALID_HCI_CMD_PARAMS; + } + + return ret; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x-nucleo-idb0xa1/bluenrg-hci/ble_clock.h Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,58 @@ +/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** +* File Name : ble_clock.h +* Author : AMS - HEA&RF BU +* Version : V1.0.1 +* Date : 19-July-2012 +* Description : Header file for clock library, that gives a simple time +* reference to the BLE Stack. +******************************************************************************** +* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ + +#ifndef __CLOCK_H__ +#define __CLOCK_H__ + +#include <ble_hal_types.h> + +/** + * Number of clocks in one seconds. + * This value must be set by each platorm implementation, basing on its needs. + */ +extern const uint32_t CLOCK_SECOND; + +typedef uint32_t tClockTime; + +/** + * This function initializes the clock library and should be called before + * any other Stack functions. + * + */ +void Clock_Init(void); + +/** + * This function returns the current system clock time. it is used by + * the host stack and has to be implemented. + * + * @return The current clock time, measured in system ticks. + */ +tClockTime Clock_Time(void); + +/** + * This function waits for a given number of milliseconds. + * + */ +void Clock_Wait(uint32_t i); + +/** + * It suspends system clock. + * + */ +void Clock_Suspend(void); + + +#endif /* __CLOCK_H__ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x-nucleo-idb0xa1/bluenrg-hci/ble_compiler.h Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,34 @@ +/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** +* File Name : compiler.h +* Author : AMS - HEA&RF BU +* Version : V1.0.0 +* Date : 19-July-2012 +* Description : Compiler-dependent macros. +******************************************************************************** +* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + +#ifdef __ICCARM__ +#define PACKED +#else +#ifdef __GNUC__ +#undef __packed +#define __packed +#define PACKED __attribute__((packed)) +#else +#define PACKED +#define __packed +#endif +#endif + +/* Change this define to 1 if zero-length arrays are not supported by your compiler. */ +#define VARIABLE_SIZE 1 + +#endif /* DOXYGEN_SHOULD_SKIP_THIS */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x-nucleo-idb0xa1/bluenrg-hci/ble_debug.h Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,73 @@ +/** + ****************************************************************************** + * @file ble_debug.h + * @author CL + * @version V1.0.0 + * @date 04-July-2014 + * @brief This file defines print functions for debug purposes. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __DEBUG_H +#define __DEBUG_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include <string.h> + +/* Exported macro ------------------------------------------------------------*/ +//#define DEBUG +#ifdef DEBUG +#include <stdio.h> +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif + +/* Print the data travelling over the SPI in the .csv format for the GUI*/ +//#define PRINT_CSV_FORMAT +#ifdef PRINT_CSV_FORMAT +#include <stdio.h> +#define PRINT_CSV(...) printf(__VA_ARGS__) +#else +#define PRINT_CSV(...) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __DEBUG_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x-nucleo-idb0xa1/bluenrg-hci/ble_gp_timer.h Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,105 @@ +/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** +* File Name : gp_timer.h +* Author : AMS - HEA&RF BU +* Version : V1.0.0 +* Date : 19-July-2012 +* Description : General purpose timer library. +******************************************************************************** +* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ + +#ifndef __GP_TIMER_H__ +#define __GP_TIMER_H__ + +#include "ble_clock.h" +#include "ble_status.h" +#ifdef __DMA_LP__ +#include "stm32xx_timerserver.h" +#endif /* __DMA_LP__ */ + +/** + * timer + * + * A structure that represents a timer. Use Timer_Set() to set the timer. + * + */ +struct timer { + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + + tClockTime start; + tClockTime interval; + +#endif +}; + +typedef void (* TIMER_HCI_TIMEOUT_NOTIFY_CALLBACK_TYPE)(void); + +/** + * Timer_Set + * + * @param[in] t Pointer to a timer structure + * @param[in] interval timeout value + * + * This function sets the timeout value of a timer. + * + */ +void Timer_Set(struct timer *t, tClockTime interval); + +/** + * Timer_Reset + * + * @param[in] t Pointer to a timer structure + * + * This function resets the timer with the same interval given + * with Timer_Set, starting from the time it previously expired. + * + */ +void Timer_Reset(struct timer *t); + +/** + * Timer_Restart + * + * @param[in] t Pointer to a timer structure + * + * This function resets the timer with the same interval given + * with Timer_Set, starting from the current time. + * + */ +void Timer_Restart(struct timer *t); + +/** + * Timer_Expired + * + * @param[in] t Pointer to a timer structure + * + * This function returns TRUE if timer is expired, FALSE otherwise. + * + */ +int Timer_Expired(struct timer *t); + +/** + * Timer_Expired + * + * @param[in] t Pointer to a timer structure + * + * This function returns the time needed for expiration. + * + * @return Time before timer's expiration. + */ +tClockTime Timer_Remaining(struct timer *t); + +#ifdef __DMA_LP__ +tBleStatus Blue_NRG_HCI_Timer_Start(uint32_t expiryTime, + TIMER_HCI_TIMEOUT_NOTIFY_CALLBACK_TYPE timercb, + uint8_t *timerID); + +tBleStatus Blue_NRG_HCI_Timer_Stop(uint8_t timerID); +#endif /* __DMA_LP__ */ + +#endif /* __GP_TIMER_H__ */ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x-nucleo-idb0xa1/bluenrg-hci/ble_hal.h Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,108 @@ +/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** +* File Name : hal.h +* Author : AMS - HEA&RF BU +* Version : V1.0.0 +* Date : 19-July-2012 +* Description : Header file which defines Hardware abstraction layer APIs +* used by the BLE stack. It defines the set of functions +* which needs to be ported to the target platform. +******************************************************************************** +* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ +#ifndef __HAL_H__ +#define __HAL_H__ + +/****************************************************************************** + * Includes + *****************************************************************************/ +#include <ble_hal_types.h> +#include <ble_status.h> + + +/****************************************************************************** + * Macros + *****************************************************************************/ +/* Little Endian buffer to host endianess conversion */ +#define LE_TO_HOST_16(ptr) (uint16_t) ( ((uint16_t) \ + *((uint8_t *)ptr)) | \ + ((uint16_t) \ + *((uint8_t *)ptr + 1) << 8 ) ) + +#define LE_TO_HOST_32(ptr) (uint32_t) ( ((uint32_t) \ + *((uint8_t *)ptr)) | \ + ((uint32_t) \ + *((uint8_t *)ptr + 1) << 8) | \ + ((uint32_t) \ + *((uint8_t *)ptr + 2) << 16) | \ + ((uint32_t) \ + *((uint8_t *)ptr + 3) << 24) ) + +/* Big Endian buffer to host endianess conversion */ +#define BE_TO_HOST_16(ptr) (uint16_t) ( ((uint16_t) \ + *((uint8_t *)ptr)) << 8 | \ + ((uint16_t) \ + *((uint8_t *)ptr + 1) ) ) + +/* Store Value into a buffer in Little Endian Format */ +#define HOST_TO_LE_16(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \ + ((buf)[1] = (uint8_t) (val>>8) ) ) + +#define HOST_TO_LE_32(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \ + ((buf)[1] = (uint8_t) (val>>8) ) , \ + ((buf)[2] = (uint8_t) (val>>16) ) , \ + ((buf)[3] = (uint8_t) (val>>24) ) ) + + +/* Store Value into a buffer in Big Endian Format */ +#define HOST_TO_BE_16(buf, val) ( ((buf)[1] = (uint8_t) (val) ) , \ + ((buf)[0] = (uint8_t) (val>>8) ) ) + +#define DISABLE_INTERRUPTS() __disable_interrupt() +#define ENABLE_INTERRUPTS() __enable_interrupt() +#define SAVE_PRIMASK() uint32_t uwPRIMASK_Bit = __get_PRIMASK() +#define ATOMIC_SECTION_BEGIN() uint32_t uwPRIMASK_Bit = __get_PRIMASK(); \ + __disable_interrupt(); \ +/* Must be called in the same or in a lower scope of SUSPEND_INTERRUPTS */ +#define ATOMIC_SECTION_END() __set_PRIMASK(uwPRIMASK_Bit) + +/****************************************************************************** + * Types + *****************************************************************************/ + +/****************************************************************************** + * Function Prototypes + *****************************************************************************/ + +/** + * Writes data to a serial interface. + * + * @param[in] data1 1st buffer + * @param[in] data2 2nd buffer + * @param[in] n_bytes1 number of bytes in 1st buffer + * @param[in] n_bytes2 number of bytes in 2nd buffer + */ +void Hal_Write_Serial(const void* data1, const void* data2, int32_t n_bytes1, int32_t n_bytes2); + +/** + * Enable interrupts from HCI controller. + */ +void Enable_SPI_IRQ(void); + +/** + * Disable interrupts from BLE controller. + */ +void Disable_SPI_IRQ(void); + +void signalEventsToProcess(void); + +void Hal_Init_Timer(void); +uint32_t Hal_Get_Timer_Value(void); +void Hal_Start_Timer(uint32_t timeout); +void Hal_Stop_Timer(void); + +#endif /* __HAL_H__ */ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x-nucleo-idb0xa1/bluenrg-hci/ble_hal_types.h Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,57 @@ +/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** +* File Name : ble_hal_types.h +* Author : AMS - HEA&RF BU +* Version : V1.0.0 +* Date : 19-July-2012 +* Description : This header file defines the basic data types used by the +* BLE stack. +******************************************************************************** +* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ +#ifndef __HAL_TYPES_H__ +#define __HAL_TYPES_H__ + +#include <stdint.h> + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#ifndef __LITTLE_ENDIAN +#define __LITTLE_ENDIAN 0 +#define __BIG_ENDIAN 1 +#endif + +/* Byte order conversions */ +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define htobs(d) (d) +#define htobl(d) (d) +#define btohs(d) (d) +#define btohl(d) (d) +#elif __BYTE_ORDER == __BIG_ENDIAN +#define htobs(d) (d<<8|d>>8) +#define htobl(d) (d<<24|((d<<8)&0x00ff0000)|((d>>8)&0x0000ff00)|((d>>24)&0x000000ff)) +#define btohs(d) (d<<8|d>>8) +#define btohl(d) (d<<24|((d<<8)&0x00ff0000)|((d>>8)&0x0000ff00)|((d>>24)&0x000000ff)) +#else +#error "Unknown byte order" +#endif + +typedef uint8_t BOOL; + +#ifndef TRUE +#define TRUE (1) +#endif + +#ifndef FALSE +#define FALSE (0) +#endif + + + +#endif /* __HAL_TYPES_H__ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x-nucleo-idb0xa1/bluenrg-hci/ble_hci.h Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,241 @@ +/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** +* File Name : hci.h +* Author : AMS - HEA&RF BU +* Version : V1.0.0 +* Date : 19-July-2012 +* Description : Constants and functions for HCI layer. See Bluetooth Core +* v 4.0, Vol. 2, Part E. +******************************************************************************** +* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ + +#ifndef __HCI_H_ +#define __HCI_H_ + +#include "ble_hal_types.h" +#include "ble_link_layer.h" +#include <ble_list.h> + +#define HCI_READ_PACKET_SIZE 128 //71 + +/*** Data types ***/ + +/* structure used to read received data */ +typedef struct _tHciDataPacket +{ + tListNode currentNode; + uint8_t dataBuff[HCI_READ_PACKET_SIZE]; + uint8_t data_len; +} tHciDataPacket; + +typedef enum +{ + BUSY, + AVAILABLE +} HCI_CMD_STATUS_t; + +/** + * @defgroup HCI_Error_codes HCI Error codes + * @{ + */ +#define HCI_UNKNOWN_COMMAND 0x01 +#define HCI_NO_CONNECTION 0x02 +#define HCI_HARDWARE_FAILURE 0x03 +#define HCI_PAGE_TIMEOUT 0x04 +#define HCI_AUTHENTICATION_FAILURE 0x05 +#define HCI_PIN_OR_KEY_MISSING 0x06 +#define HCI_MEMORY_FULL 0x07 +#define HCI_CONNECTION_TIMEOUT 0x08 +#define HCI_MAX_NUMBER_OF_CONNECTIONS 0x09 +#define HCI_MAX_NUMBER_OF_SCO_CONNECTIONS 0x0a +#define HCI_ACL_CONNECTION_EXISTS 0x0b +#define HCI_COMMAND_DISALLOWED 0x0c +#define HCI_REJECTED_LIMITED_RESOURCES 0x0d +#define HCI_REJECTED_SECURITY 0x0e +#define HCI_REJECTED_PERSONAL 0x0f +#define HCI_HOST_TIMEOUT 0x10 +#define HCI_UNSUPPORTED_FEATURE 0x11 +#define HCI_INVALID_PARAMETERS 0x12 +#define HCI_OE_USER_ENDED_CONNECTION 0x13 +#define HCI_OE_LOW_RESOURCES 0x14 +#define HCI_OE_POWER_OFF 0x15 +#define HCI_CONNECTION_TERMINATED 0x16 +#define HCI_REPEATED_ATTEMPTS 0x17 +#define HCI_PAIRING_NOT_ALLOWED 0x18 +#define HCI_UNKNOWN_LMP_PDU 0x19 +#define HCI_UNSUPPORTED_REMOTE_FEATURE 0x1a +#define HCI_SCO_OFFSET_REJECTED 0x1b +#define HCI_SCO_INTERVAL_REJECTED 0x1c +#define HCI_AIR_MODE_REJECTED 0x1d +#define HCI_INVALID_LMP_PARAMETERS 0x1e +#define HCI_UNSPECIFIED_ERROR 0x1f +#define HCI_UNSUPPORTED_LMP_PARAMETER_VALUE 0x20 +#define HCI_ROLE_CHANGE_NOT_ALLOWED 0x21 +#define HCI_LMP_RESPONSE_TIMEOUT 0x22 +#define HCI_LMP_ERROR_TRANSACTION_COLLISION 0x23 +#define HCI_LMP_PDU_NOT_ALLOWED 0x24 +#define HCI_ENCRYPTION_MODE_NOT_ACCEPTED 0x25 +#define HCI_UNIT_LINK_KEY_USED 0x26 +#define HCI_QOS_NOT_SUPPORTED 0x27 +#define HCI_INSTANT_PASSED 0x28 +#define HCI_PAIRING_NOT_SUPPORTED 0x29 +#define HCI_TRANSACTION_COLLISION 0x2a +#define HCI_QOS_UNACCEPTABLE_PARAMETER 0x2c +#define HCI_QOS_REJECTED 0x2d +#define HCI_CLASSIFICATION_NOT_SUPPORTED 0x2e +#define HCI_INSUFFICIENT_SECURITY 0x2f +#define HCI_PARAMETER_OUT_OF_RANGE 0x30 +#define HCI_ROLE_SWITCH_PENDING 0x32 +#define HCI_SLOT_VIOLATION 0x34 +#define HCI_ROLE_SWITCH_FAILED 0x35 +#define HCI_EIR_TOO_LARGE 0x36 +#define HCI_SIMPLE_PAIRING_NOT_SUPPORTED 0x37 +#define HCI_HOST_BUSY_PAIRING 0x38 +#define HCI_CONN_REJ_NO_CH_FOUND 0x39 +#define HCI_CONTROLLER_BUSY 0x3A +#define HCI_UNACCEPTABLE_CONN_INTERV 0x3B +#define HCI_DIRECTED_ADV_TIMEOUT 0x3C +#define HCI_CONN_TERM_MIC_FAIL 0x3D +#define HCI_CONN_FAIL_TO_BE_ESTABL 0x3E +#define HCI_MAC_CONN_FAILED 0x3F +/** + * @} + */ + + +/* + * HCI library functions. + * Each function returns 0 in case of success, otherwise one of the error codes. + */ + +int hci_reset(void); + +int hci_disconnect(uint16_t handle, uint8_t reason); + +int hci_le_set_advertise_enable(uint8_t enable); + +int hci_le_set_advertising_parameters(uint16_t min_interval, uint16_t max_interval, uint8_t advtype, + uint8_t own_bdaddr_type, uint8_t direct_bdaddr_type, const tBDAddr direct_bdaddr, uint8_t chan_map, + uint8_t filter); + +int hci_le_set_scan_parameters(uint8_t type, uint16_t interval, + uint16_t window, uint8_t own_bdaddr_type, + uint8_t filter); + +int hci_le_set_scan_enable(uint8_t enable, uint8_t filter_dup); + +int hci_le_set_advertising_data(uint8_t length, const uint8_t data[]); + +int hci_le_set_scan_resp_data(uint8_t length, const uint8_t data[]); + +int hci_le_rand(uint8_t random_number[8]); + +int hci_le_read_advertising_channel_tx_power(int8_t *tx_power_level); + +int hci_acl_data(const uint8_t * data, uint16_t len); + +int hci_le_set_random_address(tBDAddr bdaddr); + +int hci_read_bd_addr(tBDAddr bdaddr); + +int hci_le_read_white_list_size(uint8_t *size); + +int hci_le_clear_white_list(void); + +int hci_le_add_device_to_white_list(uint8_t bdaddr_type, tBDAddr bdaddr); + +int hci_le_remove_device_from_white_list(uint8_t bdaddr_type, tBDAddr bdaddr); + +int hci_le_encrypt(uint8_t key[16], uint8_t plaintextData[16], uint8_t encryptedData[16]); + +int hci_le_ltk_request_reply(uint8_t key[16]); + +int hci_le_ltk_request_neg_reply(void); + +int hci_le_read_buffer_size(uint16_t *pkt_len, uint8_t *max_pkt); + +int hci_le_create_connection(uint16_t interval, uint16_t window, uint8_t initiator_filter, uint8_t peer_bdaddr_type, + const tBDAddr peer_bdaddr, uint8_t own_bdaddr_type, uint16_t min_interval, uint16_t max_interval, + uint16_t latency, uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length); + +int hci_le_create_connection_cancel(void); + +int hci_read_transmit_power_level(uint16_t *conn_handle, uint8_t type, int8_t *tx_level); + +int hci_read_rssi(uint16_t *conn_handle, int8_t *rssi); + +int hci_le_read_local_supported_features(uint8_t *features); + +int hci_le_read_channel_map(uint16_t conn_handle, uint8_t ch_map[5]); + +int hci_le_read_supported_states(uint8_t states[8]); + +int hci_le_receiver_test(uint8_t frequency); + +int hci_le_transmitter_test(uint8_t frequency, uint8_t length, uint8_t payload); + +int hci_le_test_end(uint16_t *num_pkts); + +int hci_le_read_local_version(uint8_t *hci_version, uint16_t *hci_revision, uint8_t *lmp_pal_version, + uint16_t *manufacturer_name, uint16_t *lmp_pal_subversion); + +/** + * This function must be used to pass the packet received from the HCI + * interface to the BLE Stack HCI state machine. + * + * @param[in] hciReadPacket The packet that is received from HCI interface. + * + */ +void HCI_Input(tHciDataPacket *hciReadPacket); + +/** + * Initialization function. Must be done before any data can be received from + * BLE controller. + */ +void HCI_Init(void); + +/** + * Callback used to pass events to application. + * + * @param[in] pckt The event. + * + */ +extern void HCI_Event_CB(void *pckt); + +/** + * Processing function that must be called after an event is received from + * HCI interface. Must be called outside ISR. It will call HCI_Event_CB if + * necessary. +*/ +void HCI_Process(void); + +/** + * @brief Check if queue of HCI event is empty or not. + * @note This funtion can be used to check if the event queue from BlueNRG is empty. This + * is useful when checking if it is safe to go to sleep. + * @return TRUE if event queue is empty. FALSE otherwhise. + */ +BOOL HCI_Queue_Empty(void); +/** + * Iterrupt service routine that must be called when the BlueNRG + * reports a packet received or an event to the host through the + * BlueNRG interrupt line. + */ +#ifdef __DMA_LP__ +void HCI_Isr(uint8_t *buffer, uint8_t event_payload_len); +void HCI_Process_Notification_Request(void); +void HCI_Cmd_Status(HCI_CMD_STATUS_t Hci_Cmd_Status); +void HCI_Wait_For_Response(void); +#else +void HCI_Isr(void); +#endif /* __DMA_LP__ */ + +extern tListNode hciReadPktPool; +extern tListNode hciReadPktRxQueue; + +#endif /* __HCI_H_ */ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x-nucleo-idb0xa1/bluenrg-hci/ble_hci_const.h Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,563 @@ +/****************************************************************************** +* +* File Description +* --------------------- +* This file defines constants and functions for HCI layer. +* See Bluetooth Core v 4.0, Vol. 2, Part E. +* +*******************************************************************************/ + +#ifndef __HCI_INTERNAL_H_ +#define __HCI_INTERNAL_H_ + +#include "ble_compiler.h" +#include "ble_hal_types.h" +#include "ble_clock.h" +#include "ble_link_layer.h" +#include "ble_hci.h" + +#define DEFAULT_TIMEOUT (CLOCK_SECOND/10) + +/** + * Maximum payload of HCI commands that can be sent. Change this value if needed. + * This value can be up to 255. + */ +#define HCI_MAX_PAYLOAD_SIZE 128 + +/* HCI Packet types */ +#define HCI_COMMAND_PKT 0x01 +#define HCI_ACLDATA_PKT 0x02 +#define HCI_SCODATA_PKT 0x03 +#define HCI_EVENT_PKT 0x04 +#define HCI_VENDOR_PKT 0xff + +typedef __packed struct _hci_uart_pckt{ + uint8_t type; + uint8_t data[VARIABLE_SIZE]; +} PACKED hci_uart_pckt; +#define HCI_HDR_SIZE 1 + +typedef __packed struct _hci_command_hdr{ + uint16_t opcode; /* OCF & OGF */ + uint8_t plen; +} PACKED hci_command_hdr; +#define HCI_COMMAND_HDR_SIZE 3 + +typedef __packed struct _hci_event_pckt{ + uint8_t evt; + uint8_t plen; + uint8_t data[VARIABLE_SIZE]; +} PACKED hci_event_pckt; +#define HCI_EVENT_HDR_SIZE 2 + +typedef __packed struct _hci_acl_hdr{ + uint16_t handle; /* Handle & Flags(PB, BC) */ + uint16_t dlen; +} PACKED hci_acl_hdr; +#define HCI_ACL_HDR_SIZE 4 + +/* Link Control */ +#define OGF_LINK_CTL 0x01 + +#define OCF_DISCONNECT 0x0006 +typedef __packed struct _disconnect_cp{ + uint16_t handle; + uint8_t reason; +} PACKED disconnect_cp; +#define DISCONNECT_CP_SIZE 3 + +/* Host Controller and Baseband */ +#define OGF_HOST_CTL 0x03 + +#define OCF_SET_EVENT_MASK 0x0001 +#define OCF_RESET 0x0003 + +#define OCF_READ_TRANSMIT_POWER_LEVEL 0x002D +typedef __packed struct _read_transmit_power_level_cp{ + uint16_t handle; + uint8_t type; +} PACKED read_transmit_power_level_cp; +#define READ_TRANSMIT_POWER_LEVEL_CP_SIZE 3 +typedef __packed struct _read_transmit_power_level_rp{ + uint8_t status; + uint16_t handle; + int8_t level; +} PACKED read_transmit_power_level_rp; +#define READ_TRANSMIT_POWER_LEVEL_RP_SIZE 4 + +#define OCF_SET_CONTROLLER_TO_HOST_FC 0x0031 +#define OCF_HOST_BUFFER_SIZE 0x0033 +#define OCF_HOST_NUM_COMP_PKTS 0x0035 + +/* Informational Parameters */ +#define OGF_INFO_PARAM 0x04 + +#define OCF_READ_LOCAL_VERSION 0x0001 +typedef __packed struct _read_local_version_rp{ + uint8_t status; + uint8_t hci_version; + uint16_t hci_revision; + uint8_t lmp_pal_version; + uint16_t manufacturer_name; + uint16_t lmp_pal_subversion; +} PACKED read_local_version_rp; +#define READ_LOCAL_VERSION_RP_SIZE 9 + +#define OCF_READ_LOCAL_COMMANDS 0x0002 +#define OCF_READ_LOCAL_FEATURES 0x0003 + +#define OCF_READ_BD_ADDR 0x0009 +typedef __packed struct _read_bd_addr_rp{ + uint8_t status; + tBDAddr bdaddr; +} PACKED read_bd_addr_rp; +#define READ_BD_ADDR_RP_SIZE 7 + +/* Status params */ +#define OGF_STATUS_PARAM 0x05 + +#define OCF_READ_RSSI 0x0005 +typedef __packed struct _read_rssi_cp{ + uint16_t handle; +} PACKED read_rssi_cp; +#define READ_RSSI_CP_SIZE 2 +typedef __packed struct _read_rssi_rp{ + uint8_t status; + uint16_t handle; + int8_t rssi; +} PACKED read_rssi_rp; +#define READ_RSSI_RP_SIZE 4 + + +/* LE commands */ +#define OGF_LE_CTL 0x08 + +#define OCF_LE_SET_EVENT_MASK 0x0001 +typedef __packed struct _le_set_event_mask_cp{ + uint8_t mask[8]; +} PACKED le_set_event_mask_cp; +#define LE_SET_EVENT_MASK_CP_SIZE 8 + +#define OCF_LE_READ_BUFFER_SIZE 0x0002 +typedef __packed struct _le_read_buffer_size_rp{ + uint8_t status; + uint16_t pkt_len; + uint8_t max_pkt; +} PACKED le_read_buffer_size_rp; +#define LE_READ_BUFFER_SIZE_RP_SIZE 4 + +#define OCF_LE_READ_LOCAL_SUPPORTED_FEATURES 0x0003 +typedef __packed struct _le_read_local_supported_features_rp{ + uint8_t status; + uint8_t features[8]; +} PACKED le_read_local_supported_features_rp; +#define LE_READ_LOCAL_SUPPORTED_FEATURES_RP_SIZE 9 + +#define OCF_LE_SET_RANDOM_ADDRESS 0x0005 +typedef __packed struct _le_set_random_address_cp{ + tBDAddr bdaddr; +} PACKED le_set_random_address_cp; +#define LE_SET_RANDOM_ADDRESS_CP_SIZE 6 + +#define OCF_LE_SET_ADV_PARAMETERS 0x0006 +typedef __packed struct _le_set_adv_parameters_cp{ + uint16_t min_interval; + uint16_t max_interval; + uint8_t advtype; + uint8_t own_bdaddr_type; + uint8_t direct_bdaddr_type; + tBDAddr direct_bdaddr; + uint8_t chan_map; + uint8_t filter; +} PACKED le_set_adv_parameters_cp; +#define LE_SET_ADV_PARAMETERS_CP_SIZE 15 + +#define OCF_LE_READ_ADV_CHANNEL_TX_POWER 0x0007 +typedef __packed struct _le_read_adv_channel_tx_power_rp{ + uint8_t status; + int8_t level; +} PACKED le_read_adv_channel_tx_power_rp; +#define LE_READ_ADV_CHANNEL_TX_POWER_RP_SIZE 2 + +#define OCF_LE_SET_ADV_DATA 0x0008 +typedef __packed struct _le_set_adv_data_cp{ + uint8_t length; + uint8_t data[31]; +} PACKED le_set_adv_data_cp; +#define LE_SET_ADV_DATA_CP_SIZE 32 + +#define OCF_LE_SET_SCAN_RESPONSE_DATA 0x0009 +typedef __packed struct _le_set_scan_response_data_cp{ + uint8_t length; + uint8_t data[31]; +} PACKED le_set_scan_response_data_cp; +#define LE_SET_SCAN_RESPONSE_DATA_CP_SIZE 32 + +#define OCF_LE_SET_ADVERTISE_ENABLE 0x000A +typedef __packed struct _le_set_advertise_enable_cp{ + uint8_t enable; +} PACKED le_set_advertise_enable_cp; +#define LE_SET_ADVERTISE_ENABLE_CP_SIZE 1 + +#define OCF_LE_SET_SCAN_PARAMETERS 0x000B +typedef __packed struct _le_set_scan_parameters_cp{ + uint8_t type; + uint16_t interval; + uint16_t window; + uint8_t own_bdaddr_type; + uint8_t filter; +} PACKED le_set_scan_parameters_cp; +#define LE_SET_SCAN_PARAMETERS_CP_SIZE 7 + +#define OCF_LE_SET_SCAN_ENABLE 0x000C +typedef __packed struct _le_set_scan_enable_cp{ + uint8_t enable; + uint8_t filter_dup; +} PACKED le_set_scan_enable_cp; +#define LE_SET_SCAN_ENABLE_CP_SIZE 2 + +#define OCF_LE_CREATE_CONN 0x000D +typedef __packed struct _le_create_connection_cp{ + uint16_t interval; + uint16_t window; + uint8_t initiator_filter; + uint8_t peer_bdaddr_type; + tBDAddr peer_bdaddr; + uint8_t own_bdaddr_type; + uint16_t min_interval; + uint16_t max_interval; + uint16_t latency; + uint16_t supervision_timeout; + uint16_t min_ce_length; + uint16_t max_ce_length; +} PACKED le_create_connection_cp; +#define LE_CREATE_CONN_CP_SIZE 25 + +#define OCF_LE_CREATE_CONN_CANCEL 0x000E + +#define OCF_LE_READ_WHITE_LIST_SIZE 0x000F +typedef __packed struct _le_read_white_list_size_rp{ + uint8_t status; + uint8_t size; +} PACKED le_read_white_list_size_rp; +#define LE_READ_WHITE_LIST_SIZE_RP_SIZE 2 + +#define OCF_LE_CLEAR_WHITE_LIST 0x0010 + +#define OCF_LE_ADD_DEVICE_TO_WHITE_LIST 0x0011 +typedef __packed struct _le_add_device_to_white_list_cp{ + uint8_t bdaddr_type; + tBDAddr bdaddr; +} PACKED le_add_device_to_white_list_cp; +#define LE_ADD_DEVICE_TO_WHITE_LIST_CP_SIZE 7 + +#define OCF_LE_REMOVE_DEVICE_FROM_WHITE_LIST 0x0012 +typedef __packed struct _le_remove_device_from_white_list_cp{ + uint8_t bdaddr_type; + tBDAddr bdaddr; +} PACKED le_remove_device_from_white_list_cp; +#define LE_REMOVE_DEVICE_FROM_WHITE_LIST_CP_SIZE 7 + +#define OCF_LE_CONN_UPDATE 0x0013 +typedef __packed struct _le_connection_update_cp{ + uint16_t handle; + uint16_t min_interval; + uint16_t max_interval; + uint16_t latency; + uint16_t supervision_timeout; + uint16_t min_ce_length; + uint16_t max_ce_length; +} PACKED le_connection_update_cp; +#define LE_CONN_UPDATE_CP_SIZE 14 + +#define OCF_LE_SET_HOST_CHANNEL_CLASSIFICATION 0x0014 +typedef __packed struct _le_set_host_channel_classification_cp{ + uint8_t map[5]; +} PACKED le_set_host_channel_classification_cp; +#define LE_SET_HOST_CHANNEL_CLASSIFICATION_CP_SIZE 5 + +#define OCF_LE_READ_CHANNEL_MAP 0x0015 +typedef __packed struct _le_read_channel_map_cp{ + uint16_t handle; +} PACKED le_read_channel_map_cp; +#define LE_READ_CHANNEL_MAP_CP_SIZE 2 + +typedef __packed struct _le_read_channel_map_rp{ + uint8_t status; + uint16_t handle; + uint8_t map[5]; +} PACKED le_read_channel_map_rp; +#define LE_READ_CHANNEL_MAP_RP_SIZE 8 + +#define OCF_LE_READ_REMOTE_USED_FEATURES 0x0016 +typedef __packed struct _le_read_remote_used_features_cp{ + uint16_t handle; +} PACKED le_read_remote_used_features_cp; +#define LE_READ_REMOTE_USED_FEATURES_CP_SIZE 2 + +#define OCF_LE_ENCRYPT 0x0017 +typedef __packed struct _le_encrypt_cp{ + uint8_t key[16]; + uint8_t plaintext[16]; +} PACKED le_encrypt_cp; +#define LE_ENCRYPT_CP_SIZE 32 + +typedef __packed struct _le_encrypt_rp{ + uint8_t status; + uint8_t encdata[16]; +} PACKED le_encrypt_rp; +#define LE_ENCRYPT_RP_SIZE 17 + +#define OCF_LE_RAND 0x0018 +typedef __packed struct _le_rand_rp{ + uint8_t status; + uint8_t random[8]; +} PACKED le_rand_rp; +#define LE_RAND_RP_SIZE 9 + +#define OCF_LE_START_ENCRYPTION 0x0019 +typedef __packed struct _le_start_encryption_cp{ + uint16_t handle; + uint8_t random[8]; + uint16_t diversifier; + uint8_t key[16]; +} PACKED le_start_encryption_cp; +#define LE_START_ENCRYPTION_CP_SIZE 28 + +#define OCF_LE_LTK_REPLY 0x001A +typedef __packed struct _le_ltk_reply_cp{ + uint16_t handle; + uint8_t key[16]; +} PACKED le_ltk_reply_cp; +#define LE_LTK_REPLY_CP_SIZE 18 + +typedef __packed struct _le_ltk_reply_rp{ + uint8_t status; + uint16_t handle; +} PACKED le_ltk_reply_rp; +#define LE_LTK_REPLY_RP_SIZE 3 + +#define OCF_LE_LTK_NEG_REPLY 0x001B +typedef __packed struct _le_ltk_neg_reply_cp{ + uint16_t handle; +} PACKED le_ltk_neg_reply_cp; +#define LE_LTK_NEG_REPLY_CP_SIZE 2 + +typedef __packed struct _le_ltk_neg_reply_rp{ + uint8_t status; + uint16_t handle; +} PACKED le_ltk_neg_reply_rp; +#define LE_LTK_NEG_REPLY_RP_SIZE 3 + +#define OCF_LE_READ_SUPPORTED_STATES 0x001C +typedef __packed struct _le_read_supported_states_rp{ + uint8_t status; + uint8_t states[8]; +} PACKED le_read_supported_states_rp; +#define LE_READ_SUPPORTED_STATES_RP_SIZE 9 + +#define OCF_LE_RECEIVER_TEST 0x001D +typedef __packed struct _le_receiver_test_cp{ + uint8_t frequency; +} PACKED le_receiver_test_cp; +#define LE_RECEIVER_TEST_CP_SIZE 1 + +#define OCF_LE_TRANSMITTER_TEST 0x001E +typedef __packed struct _le_transmitter_test_cp{ + uint8_t frequency; + uint8_t length; + uint8_t payload; +} PACKED le_transmitter_test_cp; +#define LE_TRANSMITTER_TEST_CP_SIZE 3 + +#define OCF_LE_TEST_END 0x001F +typedef __packed struct _le_test_end_rp{ + uint8_t status; + uint16_t num_pkts; +} PACKED le_test_end_rp; +#define LE_TEST_END_RP_SIZE 3 + +/* Vendor specific commands */ +#define OGF_VENDOR_CMD 0x3f + + +/*------------- Events -------------*/ +#define EVT_CONN_COMPLETE 0x03 +typedef __packed struct _evt_conn_complete{ + uint8_t status; + uint16_t handle; + tBDAddr bdaddr; + uint8_t link_type; + uint8_t encr_mode; +} PACKED evt_conn_complete; +#define EVT_CONN_COMPLETE_SIZE 13 + +#define EVT_DISCONN_COMPLETE 0x05 +typedef __packed struct _evt_disconn_complete{ + uint8_t status; + uint16_t handle; + uint8_t reason; +} PACKED evt_disconn_complete; +#define EVT_DISCONN_COMPLETE_SIZE 4 + +#define EVT_ENCRYPT_CHANGE 0x08 +typedef __packed struct _evt_encrypt_change{ + uint8_t status; + uint16_t handle; + uint8_t encrypt; +} PACKED evt_encrypt_change; +#define EVT_ENCRYPT_CHANGE_SIZE 5 + +#define EVT_READ_REMOTE_VERSION_COMPLETE 0x0C + +#define EVT_CMD_COMPLETE 0x0E +typedef __packed struct _evt_cmd_complete{ + uint8_t ncmd; + uint16_t opcode; +} PACKED evt_cmd_complete; +#define EVT_CMD_COMPLETE_SIZE 3 + +#define EVT_CMD_STATUS 0x0F +typedef __packed struct _evt_cmd_status{ + uint8_t status; + uint8_t ncmd; + uint16_t opcode; +} PACKED evt_cmd_status; +#define EVT_CMD_STATUS_SIZE 4 + +#define EVT_HARDWARE_ERROR 0x10 +typedef __packed struct _evt_hardware_error{ + uint8_t code; +} PACKED evt_hardware_error; +#define EVT_HARDWARE_ERROR_SIZE 1 + +#define EVT_NUM_COMP_PKTS 0x13 +typedef __packed struct _evt_num_comp_pkts{ + uint8_t num_hndl; + /* variable length part */ +} PACKED evt_num_comp_pkts; +#define EVT_NUM_COMP_PKTS_SIZE 1 + +/* variable length part of evt_num_comp_pkts. */ +typedef __packed struct _evt_num_comp_pkts_param{ + uint16_t hndl; + uint16_t num_comp_pkts; +} PACKED evt_num_comp_pkts_param; +#define EVT_NUM_COMP_PKTS_PARAM_SIZE 1 + +#define EVT_DATA_BUFFER_OVERFLOW 0x1A +typedef __packed struct _evt_data_buffer_overflow{ + uint8_t link_type; +} PACKED evt_data_buffer_overflow; +#define EVT_DATA_BUFFER_OVERFLOW_SIZE 1 + +#define EVT_ENCRYPTION_KEY_REFRESH_COMPLETE 0x30 +typedef __packed struct _evt_encryption_key_refresh_complete{ + uint8_t status; + uint16_t handle; +} PACKED evt_encryption_key_refresh_complete; +#define EVT_ENCRYPTION_KEY_REFRESH_COMPLETE_SIZE 3 + +#define EVT_LE_META_EVENT 0x3E +typedef __packed struct _evt_le_meta_event{ + uint8_t subevent; + uint8_t data[VARIABLE_SIZE]; +} PACKED evt_le_meta_event; +#define EVT_LE_META_EVENT_SIZE 1 + +#define EVT_LE_CONN_COMPLETE 0x01 +typedef __packed struct _evt_le_connection_complete{ + uint8_t status; + uint16_t handle; + uint8_t role; + uint8_t peer_bdaddr_type; + tBDAddr peer_bdaddr; + uint16_t interval; + uint16_t latency; + uint16_t supervision_timeout; + uint8_t master_clock_accuracy; +} PACKED evt_le_connection_complete; +#define EVT_LE_CONN_COMPLETE_SIZE 18 + +#define EVT_LE_ADVERTISING_REPORT 0x02 +typedef __packed struct _le_advertising_info{ + uint8_t evt_type; + uint8_t bdaddr_type; + tBDAddr bdaddr; + uint8_t data_length; + uint8_t data_RSSI[VARIABLE_SIZE]; // RSSI is last octect (signed integer). +} PACKED le_advertising_info; +#define LE_ADVERTISING_INFO_SIZE 9 + +#define EVT_LE_CONN_UPDATE_COMPLETE 0x03 +typedef __packed struct _evt_le_connection_update_complete{ + uint8_t status; + uint16_t handle; + uint16_t interval; + uint16_t latency; + uint16_t supervision_timeout; +} PACKED evt_le_connection_update_complete; +#define EVT_LE_CONN_UPDATE_COMPLETE_SIZE 9 + +#define EVT_LE_READ_REMOTE_USED_FEATURES_COMPLETE 0x04 +typedef __packed struct _evt_le_read_remote_used_features_complete{ + uint8_t status; + uint16_t handle; + uint8_t features[8]; +} PACKED evt_le_read_remote_used_features_complete; +#define EVT_LE_READ_REMOTE_USED_FEATURES_COMPLETE_SIZE 11 + +#define EVT_LE_LTK_REQUEST 0x05 +typedef __packed struct _evt_le_long_term_key_request{ + uint16_t handle; + uint8_t random[8]; + uint16_t ediv; +} PACKED evt_le_long_term_key_request; +#define EVT_LE_LTK_REQUEST_SIZE 12 + +/** +* The event code in the @ref hci_event_pckt structure. If event code is EVT_VENDOR, +* application can use @ref evt_blue_aci structure to parse the packet. +*/ +#define EVT_VENDOR 0xFF + + +/* Command opcode pack/unpack */ +#define cmd_opcode_pack(ogf, ocf) (uint16_t)((ocf & 0x03ff)|(ogf << 10)) +#define cmd_opcode_ogf(op) (op >> 10) +#define cmd_opcode_ocf(op) (op & 0x03ff) + + +struct hci_request { + uint16_t ogf; + uint16_t ocf; + int event; + void *cparam; + int clen; + void *rparam; + int rlen; +}; + +void hci_send_cmd(uint16_t ogf, uint16_t ocf, uint8_t plen, void *param); + +typedef enum { + WAITING_TYPE, + WAITING_OPCODE1, + WAITING_OPCODE2, + WAITING_EVENT_CODE, + WAITING_HANDLE, + WAITING_HANDLE_FLAG, + WAITING_PARAM_LEN, + WAITING_DATA_LEN1, + WAITING_DATA_LEN2, + WAITING_PAYLOAD +}hci_state; + +typedef void (*hci_packet_complete_callback)(void *pckt, uint16_t len); + +/* HCI library functions. */ +void hci_init(void); + +int hci_send_req(struct hci_request *r, BOOL async); + +#endif /* __HCI_INTERNAL_H_ */ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x-nucleo-idb0xa1/bluenrg-hci/ble_link_layer.h Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,161 @@ +/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** +* File Name : link_layer.h +* Author : AMS - HEA&RF BU +* Version : V1.0.0 +* Date : 19-July-2012 +* Description : Header file for BlueNRG's link layer. It contains +* definition of functions for link layer, most of which are +* mapped to HCI commands. +******************************************************************************** +* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ + +#ifndef _LINK_LAYER_H +#define _LINK_LAYER_H + +#include <ble_status.h> + +/** + *@addtogroup GAP GAP + *@brief API for GAP layer. + *@{ + */ + +/** + *@name Advertising filter + *Advertising policy for filtering (white list related) + *@{ + */ +#define NO_WHITE_LIST_USE (0x00) /**< Process scan and connection requests from all devices (i.e., the White List is not in use) */ +#define WHITE_LIST_FOR_ONLY_SCAN (0x01) /**< Process connection requests from all devices and only scan requests from devices that are in the White List */ +#define WHITE_LIST_FOR_ONLY_CONN (0x02) /**< Process scan requests from all devices and only connection requests from devices that are in the White List */ +#define WHITE_LIST_FOR_ALL (0x03) /**< Process scan and connection requests only from devices in the White List. */ +/** + * @} + */ + + +/** + * Bluetooth 48 bit address (in little-endian order). + */ +typedef uint8_t tBDAddr[6]; + + +/** + *@name Bluetooth address types + * Bluetooth address types + *@{ + */ +#define PUBLIC_ADDR (0) +#define RANDOM_ADDR (1) +#define STATIC_RANDOM_ADDR (1) +#define RESOLVABLE_PRIVATE_ADDR (2) +#define NON_RESOLVABLE_PRIVATE_ADDR (3) +/** + * @} + */ + +/** + *@name Directed advertising types + * Type of advertising during directed advertising + *@{ + */ +#define HIGH_DUTY_CYCLE_DIRECTED_ADV (1) +#define LOW_DUTY_CYCLE_DIRECTED_ADV (4) +/** + * @} + */ + +/** + * @name Advertising type + * @{ + */ + +/** + * undirected scannable and connectable + */ +#define ADV_IND (0x00) + +/** + * directed non scannable + */ +#define ADV_DIRECT_IND (0x01) + +/** + * scannable non connectable + */ +#define ADV_SCAN_IND (0x02) + +/** + * non-connectable and no scan response (used for passive scan) + */ +#define ADV_NONCONN_IND (0x03) + +/** + * scan response + */ +#define SCAN_RSP (0x04) + +/** + * @} + */ + +/* 0X05-0XFF RESERVED */ + +/** + * @name Advertising ranges + * @{ + */ + +/** + * lowest allowed interval value for connectable types(20ms)..multiple of 625us + */ +#define ADV_INTERVAL_LOWEST_CONN (0X0020) + +/** + * highest allowed interval value (10.24s)..multiple of 625us. + */ +#define ADV_INTERVAL_HIGHEST (0X4000) + +/** + * lowest allowed interval value for non connectable types + * (100ms)..multiple of 625us. + */ +#define ADV_INTERVAL_LOWEST_NONCONN (0X00a0) + +/** + * @} + */ + +/** + * @name Advertising channels + * @{ + */ +#define ADV_CH_37 0x01 +#define ADV_CH_38 0x02 +#define ADV_CH_39 0x04 +/** + * @} + */ + +/** + * @name Scan_types Scan types + * @{ + */ +#define PASSIVE_SCAN 0 +#define ACTIVE_SCAN 1 +/** + * @} + */ + +/** + * @} + */ + + +#endif /* _LINK_LAYER_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x-nucleo-idb0xa1/bluenrg-hci/ble_list.h Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,47 @@ +/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** +* File Name : list.h +* Author : AMS - HEA&RF BU +* Version : V1.0.0 +* Date : 19-July-2012 +* Description : Header file for linked list library. +******************************************************************************** +* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ +#ifndef _LIST_H_ +#define _LIST_H_ + +typedef struct _tListNode { + struct _tListNode * next; + struct _tListNode * prev; +}tListNode, *pListNode; + +void list_init_head (tListNode * listHead); + +uint8_t list_is_empty (tListNode * listHead); + +void list_insert_head (tListNode * listHead, tListNode * node); + +void list_insert_tail (tListNode * listHead, tListNode * node); + +void list_remove_node (tListNode * node); + +void list_remove_head (tListNode * listHead, tListNode ** node ); + +void list_remove_tail (tListNode * listHead, tListNode ** node ); + +void list_insert_node_after (tListNode * node, tListNode * ref_node); + +void list_insert_node_before (tListNode * node, tListNode * ref_node); + +int list_get_size (tListNode * listHead); + +void list_get_next_node (tListNode * ref_node, tListNode ** node); + +void list_get_prev_node (tListNode * ref_node, tListNode ** node); + +#endif /* _LIST_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x-nucleo-idb0xa1/bluenrg-hci/ble_osal.h Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,81 @@ +/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** +* File Name : ble_osal.h +* Author : AMS - HEA&RF BU +* Version : V1.0.0 +* Date : 19-July-2012 +* Description : This header file defines the OS abstraction layer used by +* the BLE stack. OSAL defines the set of functions +* which needs to be ported to target operating system and +* target platform. +******************************************************************************** +* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ + +#ifndef __OSAL_H__ +#define __OSAL_H__ + +/****************************************************************************** + * Includes + *****************************************************************************/ +#include <ble_hal_types.h> +#ifdef __ICCARM__ +#include <intrinsics.h> +#endif + +/****************************************************************************** + * Macros + *****************************************************************************/ + + +/****************************************************************************** + * Function Prototypes + *****************************************************************************/ + +/** + * This function copies size number of bytes from a + * memory location pointed by src to a destination + * memory location pointed by dest + * + * @param[in] dest Destination address + * @param[in] src Source address + * @param[in] size size in the bytes + * + * @return Address of the destination + */ + +extern void* Osal_MemCpy(void *dest,const void *src, unsigned int size); + + +/** + * This function sets first number of bytes, specified + * by size, to the destination memory pointed by ptr + * to the specified value + * + * @param[in] ptr Destination address + * @param[in] value Value to be set + * @param[in] size Size in the bytes + * + * @return Address of the destination + */ + +extern void* Osal_MemSet(void *ptr, int value, unsigned int size); + +/** + * Osal_Get_Cur_Time + * + * returns the current time in milliseconds + */ +/** + * Returns the number of ticks (1 tick = 1 millisecond) + * + * @return Time in milliseconds + */ +uint32_t Osal_Get_Cur_Time(void); + + +#endif /* __OSAL_H__ */ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x-nucleo-idb0xa1/bluenrg-hci/ble_sm.h Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,158 @@ +/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** +* File Name : sm.h +* Author : AMS - HEA&RF BU +* Version : V1.0.0 +* Date : 19-July-2012 +* Description : Header file for BlueNRG's security manager. +******************************************************************************** +* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ + +#ifndef __SM_H__ +#define __SM_H__ + +/****************************************************************************** +* Macros +*****************************************************************************/ + +/** + *@addtogroup GAP GAP + *@brief API for GAP layer. + *@{ + */ + +/* IO capabilities */ +/** + * @anchor IO_capabilities + * @name IO capabilities + * @{ + */ +#define IO_CAP_DISPLAY_ONLY (0x00) +#define IO_CAP_DISPLAY_YES_NO (0x01) +#define IO_CAP_KEYBOARD_ONLY (0x02) +#define IO_CAP_NO_INPUT_NO_OUTPUT (0x03) +#define IO_CAP_KEYBOARD_DISPLAY (0x04) +/** + * @} + */ + +/** + * @anchor Auth_req + * @name Authentication requirements + * @{ + */ +#define BONDING (0x01) +#define NO_BONDING (0x00) +/** + * @} + */ + +/** + * @anchor MITM_req + * @name MITM protection requirements + * @{ + */ +#define MITM_PROTECTION_NOT_REQUIRED (0x00) +#define MITM_PROTECTION_REQUIRED (0x01) +/** + * @} + */ + +/** + * @anchor OOB_Data + * @name Out-Of-Band data + * @{ + */ +#define OOB_AUTH_DATA_ABSENT (0x00) +#define OOB_AUTH_DATA_PRESENT (0x01) +/** + * @} + */ + +/** + * @anchor Author_req + * @name Authorization requirements + * @{ + */ +#define AUTHORIZATION_NOT_REQUIRED (0x00) +#define AUTHORIZATION_REQUIRED (0x01) +/** + * @} + */ + +/** + * @anchor Conn_authorization + * @name Connection authorization + * @{ + */ +#define CONNECTION_AUTHORIZED (0x01) +#define CONNECTION_REJECTED (0x02) +/** + * @} + */ + +/** + * @anchor Use_fixed_pin + * @name Use fixed pin + * @{ + */ +#define USE_FIXED_PIN_FOR_PAIRING (0x0) +#define DONOT_USE_FIXED_PIN_FOR_PAIRING (0x01) +/** + * @} + */ + +/** + * @anchor link_security_status + * @name Link security status + * @{ + */ +#define SM_LINK_AUTHENTICATED (0x01) +#define SM_LINK_AUTHORIZED (0x02) +#define SM_LINK_ENCRYPTED (0x04) +/** + * @} + */ + +/** + * @anchor SMP_pairing_failed_codes + * @name SMP pairing failed reason codes + * @{ + */ +#define PASSKEY_ENTRY_FAILED (0x01) +#define OOB_NOT_AVAILABLE (0x02) +#define AUTH_REQ_CANNOT_BE_MET (0x03) +#define CONFIRM_VALUE_FAILED (0x04) +#define PAIRING_NOT_SUPPORTED (0x05) +#define INSUFF_ENCRYPTION_KEY_SIZE (0x06) +#define CMD_NOT_SUPPORTED (0x07) +#define UNSPECIFIED_REASON (0x08) +#define VERY_EARLY_NEXT_ATTEMPT (0x09) +#define SM_INVALID_PARAMS (0x0A) +/** + * @} + */ + +/** + * @anchor pairing_failed_codes + * @name Pairing failed error codes + * Error codes in @ref EVT_BLUE_GAP_PAIRING_CMPLT event + * @{ + */ +#define SM_PAIRING_SUCCESS (0x00) +#define SM_PAIRING_TIMEOUT (0x01) +#define SM_PAIRING_FAILED (0x02) +/** + * @} + */ + +/** + * @} + */ + +#endif /* __SM_H__ */
--- a/x-nucleo-idb0xa1/bluenrg-hci/ble_status.h Thu Sep 15 10:51:44 2016 +0100 +++ b/x-nucleo-idb0xa1/bluenrg-hci/ble_status.h Thu Sep 15 10:52:09 2016 +0100 @@ -15,7 +15,7 @@ #ifndef __BLE_STATUS_H__ #define __BLE_STATUS_H__ -#include <hal_types.h> +#include <ble_hal_types.h> /** @defgroup ble_status Bluetooth Status/Error Codes @@ -112,4 +112,4 @@ */ -#endif /* __BLE_STATUS_H__ */ +#endif /* __BLE_STATUS_H__ */ \ No newline at end of file
--- a/x-nucleo-idb0xa1/bluenrg-hci/bluenrg_aci_const.h Thu Sep 15 10:51:44 2016 +0100 +++ b/x-nucleo-idb0xa1/bluenrg-hci/bluenrg_aci_const.h Thu Sep 15 10:52:09 2016 +0100 @@ -16,9 +16,9 @@ #ifndef __BLUENRG_ACI_CONST_H_ #define __BLUENRG_ACI_CONST_H_ -#include "compiler.h" -#include "link_layer.h" -#include "hci_const.h" +#include "ble_compiler.h" +#include "ble_link_layer.h" +#include "ble_hci_const.h" #include "bluenrg_gatt_server.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -777,4 +777,4 @@ * @} */ -#endif /* __BLUENRG_ACI_CONST_H_ */ +#endif /* __BLUENRG_ACI_CONST_H_ */ \ No newline at end of file
--- a/x-nucleo-idb0xa1/bluenrg-hci/bluenrg_gap.h Thu Sep 15 10:51:44 2016 +0100 +++ b/x-nucleo-idb0xa1/bluenrg-hci/bluenrg_gap.h Thu Sep 15 10:52:09 2016 +0100 @@ -15,7 +15,7 @@ #ifndef __BNRG_GAP_H__ #define __BNRG_GAP_H__ -#include <link_layer.h> +#include <ble_link_layer.h> /** *@addtogroup GAP GAP @@ -227,4 +227,4 @@ * @} */ -#endif /* __BNRG_GAP_H__ */ +#endif /* __BNRG_GAP_H__ */ \ No newline at end of file
--- a/x-nucleo-idb0xa1/bluenrg-hci/bluenrg_gatt_server.h Thu Sep 15 10:51:44 2016 +0100 +++ b/x-nucleo-idb0xa1/bluenrg-hci/bluenrg_gatt_server.h Thu Sep 15 10:52:09 2016 +0100 @@ -16,7 +16,7 @@ #ifndef __BNRG_GATT_SERVER_H__ #define __BNRG_GATT_SERVER_H__ -#include "compiler.h" +#include "ble_compiler.h" #include "ble_status.h" /** @@ -220,4 +220,4 @@ -#endif /* __BNRG_GATT_SERVER_H__ */ +#endif /* __BNRG_GATT_SERVER_H__ */ \ No newline at end of file
--- a/x-nucleo-idb0xa1/bluenrg-hci/bluenrg_updater_aci.h Thu Sep 15 10:51:44 2016 +0100 +++ b/x-nucleo-idb0xa1/bluenrg-hci/bluenrg_updater_aci.h Thu Sep 15 10:52:09 2016 +0100 @@ -16,7 +16,7 @@ #ifndef __BLUENRG_UPDATER_ACI_H__ #define __BLUENRG_UPDATER_ACI_H__ -#include <compiler.h> +#include <ble_compiler.h> /** * @defgroup Updater Updater @@ -75,4 +75,4 @@ -#endif /* __BLUENRG_UPDATER_ACI_H__ */ +#endif /* __BLUENRG_UPDATER_ACI_H__ */ \ No newline at end of file
--- a/x-nucleo-idb0xa1/bluenrg-hci/bluenrg_utils.h Thu Sep 15 10:51:44 2016 +0100 +++ b/x-nucleo-idb0xa1/bluenrg-hci/bluenrg_utils.h Thu Sep 15 10:52:09 2016 +0100 @@ -27,8 +27,8 @@ #endif /* Includes ------------------------------------------------------------------*/ -#include "hal_types.h" -#include "compiler.h" +#include "ble_hal_types.h" +#include "ble_compiler.h" /* Exported types ------------------------------------------------------------*/ typedef struct{ @@ -201,4 +201,4 @@ #endif /*__BLUENRG_UTILS_H */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ \ No newline at end of file
--- a/x-nucleo-idb0xa1/bluenrg-hci/clock.h Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** -* File Name : clock.h -* Author : AMS - HEA&RF BU -* Version : V1.0.1 -* Date : 19-July-2012 -* Description : Header file for clock library, that gives a simple time -* reference to the BLE Stack. -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -#ifndef __CLOCK_H__ -#define __CLOCK_H__ - -#include <hal_types.h> - -/** - * Number of clocks in one seconds. - * This value must be set by each platorm implementation, basing on its needs. - */ -extern const uint32_t CLOCK_SECOND; - -typedef uint32_t tClockTime; - -/** - * This function initializes the clock library and should be called before - * any other Stack functions. - * - */ -void Clock_Init(void); - -/** - * This function returns the current system clock time. it is used by - * the host stack and has to be implemented. - * - * @return The current clock time, measured in system ticks. - */ -tClockTime Clock_Time(void); - -/** - * This function waits for a given number of milliseconds. - * - */ -void Clock_Wait(uint32_t i); - -/** - * It suspends system clock. - * - */ -void Clock_Suspend(void); - - -#endif /* __CLOCK_H__ */ -
--- a/x-nucleo-idb0xa1/bluenrg-hci/compiler.h Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** -* File Name : compiler.h -* Author : AMS - HEA&RF BU -* Version : V1.0.0 -* Date : 19-July-2012 -* Description : Compiler-dependent macros. -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -#ifndef DOXYGEN_SHOULD_SKIP_THIS - -#ifdef __ICCARM__ -#define PACKED -#else -#ifdef __GNUC__ -#undef __packed -#define __packed -#define PACKED __attribute__((packed)) -#else -#define PACKED -#define __packed -#endif -#endif - -/* Change this define to 1 if zero-length arrays are not supported by your compiler. */ -#define VARIABLE_SIZE 1 - -#endif /* DOXYGEN_SHOULD_SKIP_THIS */
--- a/x-nucleo-idb0xa1/bluenrg-hci/debug.h Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/** - ****************************************************************************** - * @file debug.h - * @author CL - * @version V1.0.0 - * @date 04-July-2014 - * @brief This file defines print functions for debug purposes. - ****************************************************************************** - * @attention - * - * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __DEBUG_H -#define __DEBUG_H - -#ifdef __cplusplus - extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include <string.h> - -/* Exported macro ------------------------------------------------------------*/ -//#define DEBUG -#ifdef DEBUG -#include <stdio.h> -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) -#endif - -/* Print the data travelling over the SPI in the .csv format for the GUI*/ -//#define PRINT_CSV_FORMAT -#ifdef PRINT_CSV_FORMAT -#include <stdio.h> -#define PRINT_CSV(...) printf(__VA_ARGS__) -#else -#define PRINT_CSV(...) -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* __DEBUG_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ \ No newline at end of file
--- a/x-nucleo-idb0xa1/bluenrg-hci/gp_timer.h Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** -* File Name : gp_timer.h -* Author : AMS - HEA&RF BU -* Version : V1.0.0 -* Date : 19-July-2012 -* Description : General purpose timer library. -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -#ifndef __GP_TIMER_H__ -#define __GP_TIMER_H__ - -#include "clock.h" -#include "ble_status.h" -#ifdef __DMA_LP__ -#include "stm32xx_timerserver.h" -#endif /* __DMA_LP__ */ - -/** - * timer - * - * A structure that represents a timer. Use Timer_Set() to set the timer. - * - */ -struct timer { - -#ifndef DOXYGEN_SHOULD_SKIP_THIS - - tClockTime start; - tClockTime interval; - -#endif -}; - -typedef void (* TIMER_HCI_TIMEOUT_NOTIFY_CALLBACK_TYPE)(void); - -/** - * Timer_Set - * - * @param[in] t Pointer to a timer structure - * @param[in] interval timeout value - * - * This function sets the timeout value of a timer. - * - */ -void Timer_Set(struct timer *t, tClockTime interval); - -/** - * Timer_Reset - * - * @param[in] t Pointer to a timer structure - * - * This function resets the timer with the same interval given - * with Timer_Set, starting from the time it previously expired. - * - */ -void Timer_Reset(struct timer *t); - -/** - * Timer_Restart - * - * @param[in] t Pointer to a timer structure - * - * This function resets the timer with the same interval given - * with Timer_Set, starting from the current time. - * - */ -void Timer_Restart(struct timer *t); - -/** - * Timer_Expired - * - * @param[in] t Pointer to a timer structure - * - * This function returns TRUE if timer is expired, FALSE otherwise. - * - */ -int Timer_Expired(struct timer *t); - -/** - * Timer_Expired - * - * @param[in] t Pointer to a timer structure - * - * This function returns the time needed for expiration. - * - * @return Time before timer's expiration. - */ -tClockTime Timer_Remaining(struct timer *t); - -#ifdef __DMA_LP__ -tBleStatus Blue_NRG_HCI_Timer_Start(uint32_t expiryTime, - TIMER_HCI_TIMEOUT_NOTIFY_CALLBACK_TYPE timercb, - uint8_t *timerID); - -tBleStatus Blue_NRG_HCI_Timer_Stop(uint8_t timerID); -#endif /* __DMA_LP__ */ - -#endif /* __GP_TIMER_H__ */
--- a/x-nucleo-idb0xa1/bluenrg-hci/hal.h Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** -* File Name : hal.h -* Author : AMS - HEA&RF BU -* Version : V1.0.0 -* Date : 19-July-2012 -* Description : Header file which defines Hardware abstraction layer APIs -* used by the BLE stack. It defines the set of functions -* which needs to be ported to the target platform. -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ -#ifndef __HAL_H__ -#define __HAL_H__ - -/****************************************************************************** - * Includes - *****************************************************************************/ -#include <hal_types.h> -#include <ble_status.h> - - -/****************************************************************************** - * Macros - *****************************************************************************/ -/* Little Endian buffer to host endianess conversion */ -#define LE_TO_HOST_16(ptr) (uint16_t) ( ((uint16_t) \ - *((uint8_t *)ptr)) | \ - ((uint16_t) \ - *((uint8_t *)ptr + 1) << 8 ) ) - -#define LE_TO_HOST_32(ptr) (uint32_t) ( ((uint32_t) \ - *((uint8_t *)ptr)) | \ - ((uint32_t) \ - *((uint8_t *)ptr + 1) << 8) | \ - ((uint32_t) \ - *((uint8_t *)ptr + 2) << 16) | \ - ((uint32_t) \ - *((uint8_t *)ptr + 3) << 24) ) - -/* Big Endian buffer to host endianess conversion */ -#define BE_TO_HOST_16(ptr) (uint16_t) ( ((uint16_t) \ - *((uint8_t *)ptr)) << 8 | \ - ((uint16_t) \ - *((uint8_t *)ptr + 1) ) ) - -/* Store Value into a buffer in Little Endian Format */ -#define HOST_TO_LE_16(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \ - ((buf)[1] = (uint8_t) (val>>8) ) ) - -#define HOST_TO_LE_32(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \ - ((buf)[1] = (uint8_t) (val>>8) ) , \ - ((buf)[2] = (uint8_t) (val>>16) ) , \ - ((buf)[3] = (uint8_t) (val>>24) ) ) - - -/* Store Value into a buffer in Big Endian Format */ -#define HOST_TO_BE_16(buf, val) ( ((buf)[1] = (uint8_t) (val) ) , \ - ((buf)[0] = (uint8_t) (val>>8) ) ) - -#define DISABLE_INTERRUPTS() __disable_interrupt() -#define ENABLE_INTERRUPTS() __enable_interrupt() -#define SAVE_PRIMASK() uint32_t uwPRIMASK_Bit = __get_PRIMASK() -#define ATOMIC_SECTION_BEGIN() uint32_t uwPRIMASK_Bit = __get_PRIMASK(); \ - __disable_interrupt(); \ -/* Must be called in the same or in a lower scope of SUSPEND_INTERRUPTS */ -#define ATOMIC_SECTION_END() __set_PRIMASK(uwPRIMASK_Bit) - -/****************************************************************************** - * Types - *****************************************************************************/ - -/****************************************************************************** - * Function Prototypes - *****************************************************************************/ - -/** - * Writes data to a serial interface. - * - * @param[in] data1 1st buffer - * @param[in] data2 2nd buffer - * @param[in] n_bytes1 number of bytes in 1st buffer - * @param[in] n_bytes2 number of bytes in 2nd buffer - */ -void Hal_Write_Serial(const void* data1, const void* data2, int32_t n_bytes1, int32_t n_bytes2); - -/** - * Enable interrupts from HCI controller. - */ -void Enable_SPI_IRQ(void); - -/** - * Disable interrupts from BLE controller. - */ -void Disable_SPI_IRQ(void); - -void signalEventsToProcess(void); - -void Hal_Init_Timer(void); -uint32_t Hal_Get_Timer_Value(void); -void Hal_Start_Timer(uint32_t timeout); -void Hal_Stop_Timer(void); - -#endif /* __HAL_H__ */ \ No newline at end of file
--- a/x-nucleo-idb0xa1/bluenrg-hci/hal_types.h Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** -* File Name : hal_types.h -* Author : AMS - HEA&RF BU -* Version : V1.0.0 -* Date : 19-July-2012 -* Description : This header file defines the basic data types used by the -* BLE stack. -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ -#ifndef __HAL_TYPES_H__ -#define __HAL_TYPES_H__ - -#include <stdint.h> - -#ifndef NULL -#define NULL ((void *)0) -#endif - -#ifndef __LITTLE_ENDIAN -#define __LITTLE_ENDIAN 0 -#define __BIG_ENDIAN 1 -#endif - -/* Byte order conversions */ -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define htobs(d) (d) -#define htobl(d) (d) -#define btohs(d) (d) -#define btohl(d) (d) -#elif __BYTE_ORDER == __BIG_ENDIAN -#define htobs(d) (d<<8|d>>8) -#define htobl(d) (d<<24|((d<<8)&0x00ff0000)|((d>>8)&0x0000ff00)|((d>>24)&0x000000ff)) -#define btohs(d) (d<<8|d>>8) -#define btohl(d) (d<<24|((d<<8)&0x00ff0000)|((d>>8)&0x0000ff00)|((d>>24)&0x000000ff)) -#else -#error "Unknown byte order" -#endif - -typedef uint8_t BOOL; - -#ifndef TRUE -#define TRUE (1) -#endif - -#ifndef FALSE -#define FALSE (0) -#endif - - - -#endif /* __HAL_TYPES_H__ */ -
--- a/x-nucleo-idb0xa1/bluenrg-hci/hci.h Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,241 +0,0 @@ -/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** -* File Name : hci.h -* Author : AMS - HEA&RF BU -* Version : V1.0.0 -* Date : 19-July-2012 -* Description : Constants and functions for HCI layer. See Bluetooth Core -* v 4.0, Vol. 2, Part E. -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -#ifndef __HCI_H_ -#define __HCI_H_ - -#include "hal_types.h" -#include "link_layer.h" -#include <list.h> - -#define HCI_READ_PACKET_SIZE 128 //71 - -/*** Data types ***/ - -/* structure used to read received data */ -typedef struct _tHciDataPacket -{ - tListNode currentNode; - uint8_t dataBuff[HCI_READ_PACKET_SIZE]; - uint8_t data_len; -} tHciDataPacket; - -typedef enum -{ - BUSY, - AVAILABLE -} HCI_CMD_STATUS_t; - -/** - * @defgroup HCI_Error_codes HCI Error codes - * @{ - */ -#define HCI_UNKNOWN_COMMAND 0x01 -#define HCI_NO_CONNECTION 0x02 -#define HCI_HARDWARE_FAILURE 0x03 -#define HCI_PAGE_TIMEOUT 0x04 -#define HCI_AUTHENTICATION_FAILURE 0x05 -#define HCI_PIN_OR_KEY_MISSING 0x06 -#define HCI_MEMORY_FULL 0x07 -#define HCI_CONNECTION_TIMEOUT 0x08 -#define HCI_MAX_NUMBER_OF_CONNECTIONS 0x09 -#define HCI_MAX_NUMBER_OF_SCO_CONNECTIONS 0x0a -#define HCI_ACL_CONNECTION_EXISTS 0x0b -#define HCI_COMMAND_DISALLOWED 0x0c -#define HCI_REJECTED_LIMITED_RESOURCES 0x0d -#define HCI_REJECTED_SECURITY 0x0e -#define HCI_REJECTED_PERSONAL 0x0f -#define HCI_HOST_TIMEOUT 0x10 -#define HCI_UNSUPPORTED_FEATURE 0x11 -#define HCI_INVALID_PARAMETERS 0x12 -#define HCI_OE_USER_ENDED_CONNECTION 0x13 -#define HCI_OE_LOW_RESOURCES 0x14 -#define HCI_OE_POWER_OFF 0x15 -#define HCI_CONNECTION_TERMINATED 0x16 -#define HCI_REPEATED_ATTEMPTS 0x17 -#define HCI_PAIRING_NOT_ALLOWED 0x18 -#define HCI_UNKNOWN_LMP_PDU 0x19 -#define HCI_UNSUPPORTED_REMOTE_FEATURE 0x1a -#define HCI_SCO_OFFSET_REJECTED 0x1b -#define HCI_SCO_INTERVAL_REJECTED 0x1c -#define HCI_AIR_MODE_REJECTED 0x1d -#define HCI_INVALID_LMP_PARAMETERS 0x1e -#define HCI_UNSPECIFIED_ERROR 0x1f -#define HCI_UNSUPPORTED_LMP_PARAMETER_VALUE 0x20 -#define HCI_ROLE_CHANGE_NOT_ALLOWED 0x21 -#define HCI_LMP_RESPONSE_TIMEOUT 0x22 -#define HCI_LMP_ERROR_TRANSACTION_COLLISION 0x23 -#define HCI_LMP_PDU_NOT_ALLOWED 0x24 -#define HCI_ENCRYPTION_MODE_NOT_ACCEPTED 0x25 -#define HCI_UNIT_LINK_KEY_USED 0x26 -#define HCI_QOS_NOT_SUPPORTED 0x27 -#define HCI_INSTANT_PASSED 0x28 -#define HCI_PAIRING_NOT_SUPPORTED 0x29 -#define HCI_TRANSACTION_COLLISION 0x2a -#define HCI_QOS_UNACCEPTABLE_PARAMETER 0x2c -#define HCI_QOS_REJECTED 0x2d -#define HCI_CLASSIFICATION_NOT_SUPPORTED 0x2e -#define HCI_INSUFFICIENT_SECURITY 0x2f -#define HCI_PARAMETER_OUT_OF_RANGE 0x30 -#define HCI_ROLE_SWITCH_PENDING 0x32 -#define HCI_SLOT_VIOLATION 0x34 -#define HCI_ROLE_SWITCH_FAILED 0x35 -#define HCI_EIR_TOO_LARGE 0x36 -#define HCI_SIMPLE_PAIRING_NOT_SUPPORTED 0x37 -#define HCI_HOST_BUSY_PAIRING 0x38 -#define HCI_CONN_REJ_NO_CH_FOUND 0x39 -#define HCI_CONTROLLER_BUSY 0x3A -#define HCI_UNACCEPTABLE_CONN_INTERV 0x3B -#define HCI_DIRECTED_ADV_TIMEOUT 0x3C -#define HCI_CONN_TERM_MIC_FAIL 0x3D -#define HCI_CONN_FAIL_TO_BE_ESTABL 0x3E -#define HCI_MAC_CONN_FAILED 0x3F -/** - * @} - */ - - -/* - * HCI library functions. - * Each function returns 0 in case of success, otherwise one of the error codes. - */ - -int hci_reset(void); - -int hci_disconnect(uint16_t handle, uint8_t reason); - -int hci_le_set_advertise_enable(uint8_t enable); - -int hci_le_set_advertising_parameters(uint16_t min_interval, uint16_t max_interval, uint8_t advtype, - uint8_t own_bdaddr_type, uint8_t direct_bdaddr_type, const tBDAddr direct_bdaddr, uint8_t chan_map, - uint8_t filter); - -int hci_le_set_scan_parameters(uint8_t type, uint16_t interval, - uint16_t window, uint8_t own_bdaddr_type, - uint8_t filter); - -int hci_le_set_scan_enable(uint8_t enable, uint8_t filter_dup); - -int hci_le_set_advertising_data(uint8_t length, const uint8_t data[]); - -int hci_le_set_scan_resp_data(uint8_t length, const uint8_t data[]); - -int hci_le_rand(uint8_t random_number[8]); - -int hci_le_read_advertising_channel_tx_power(int8_t *tx_power_level); - -int hci_acl_data(const uint8_t * data, uint16_t len); - -int hci_le_set_random_address(tBDAddr bdaddr); - -int hci_read_bd_addr(tBDAddr bdaddr); - -int hci_le_read_white_list_size(uint8_t *size); - -int hci_le_clear_white_list(void); - -int hci_le_add_device_to_white_list(uint8_t bdaddr_type, tBDAddr bdaddr); - -int hci_le_remove_device_from_white_list(uint8_t bdaddr_type, tBDAddr bdaddr); - -int hci_le_encrypt(uint8_t key[16], uint8_t plaintextData[16], uint8_t encryptedData[16]); - -int hci_le_ltk_request_reply(uint8_t key[16]); - -int hci_le_ltk_request_neg_reply(void); - -int hci_le_read_buffer_size(uint16_t *pkt_len, uint8_t *max_pkt); - -int hci_le_create_connection(uint16_t interval, uint16_t window, uint8_t initiator_filter, uint8_t peer_bdaddr_type, - const tBDAddr peer_bdaddr, uint8_t own_bdaddr_type, uint16_t min_interval, uint16_t max_interval, - uint16_t latency, uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length); - -int hci_le_create_connection_cancel(void); - -int hci_read_transmit_power_level(uint16_t *conn_handle, uint8_t type, int8_t *tx_level); - -int hci_read_rssi(uint16_t *conn_handle, int8_t *rssi); - -int hci_le_read_local_supported_features(uint8_t *features); - -int hci_le_read_channel_map(uint16_t conn_handle, uint8_t ch_map[5]); - -int hci_le_read_supported_states(uint8_t states[8]); - -int hci_le_receiver_test(uint8_t frequency); - -int hci_le_transmitter_test(uint8_t frequency, uint8_t length, uint8_t payload); - -int hci_le_test_end(uint16_t *num_pkts); - -int hci_le_read_local_version(uint8_t *hci_version, uint16_t *hci_revision, uint8_t *lmp_pal_version, - uint16_t *manufacturer_name, uint16_t *lmp_pal_subversion); - -/** - * This function must be used to pass the packet received from the HCI - * interface to the BLE Stack HCI state machine. - * - * @param[in] hciReadPacket The packet that is received from HCI interface. - * - */ -void HCI_Input(tHciDataPacket *hciReadPacket); - -/** - * Initialization function. Must be done before any data can be received from - * BLE controller. - */ -void HCI_Init(void); - -/** - * Callback used to pass events to application. - * - * @param[in] pckt The event. - * - */ -extern void HCI_Event_CB(void *pckt); - -/** - * Processing function that must be called after an event is received from - * HCI interface. Must be called outside ISR. It will call HCI_Event_CB if - * necessary. -*/ -void HCI_Process(void); - -/** - * @brief Check if queue of HCI event is empty or not. - * @note This funtion can be used to check if the event queue from BlueNRG is empty. This - * is useful when checking if it is safe to go to sleep. - * @return TRUE if event queue is empty. FALSE otherwhise. - */ -BOOL HCI_Queue_Empty(void); -/** - * Iterrupt service routine that must be called when the BlueNRG - * reports a packet received or an event to the host through the - * BlueNRG interrupt line. - */ -#ifdef __DMA_LP__ -void HCI_Isr(uint8_t *buffer, uint8_t event_payload_len); -void HCI_Process_Notification_Request(void); -void HCI_Cmd_Status(HCI_CMD_STATUS_t Hci_Cmd_Status); -void HCI_Wait_For_Response(void); -#else -void HCI_Isr(void); -#endif /* __DMA_LP__ */ - -extern tListNode hciReadPktPool; -extern tListNode hciReadPktRxQueue; - -#endif /* __HCI_H_ */
--- a/x-nucleo-idb0xa1/bluenrg-hci/hci_const.h Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,563 +0,0 @@ -/****************************************************************************** -* -* File Description -* --------------------- -* This file defines constants and functions for HCI layer. -* See Bluetooth Core v 4.0, Vol. 2, Part E. -* -*******************************************************************************/ - -#ifndef __HCI_INTERNAL_H_ -#define __HCI_INTERNAL_H_ - -#include "compiler.h" -#include "hal_types.h" -#include "clock.h" -#include "link_layer.h" -#include "hci.h" - -#define DEFAULT_TIMEOUT (CLOCK_SECOND/10) - -/** - * Maximum payload of HCI commands that can be sent. Change this value if needed. - * This value can be up to 255. - */ -#define HCI_MAX_PAYLOAD_SIZE 128 - -/* HCI Packet types */ -#define HCI_COMMAND_PKT 0x01 -#define HCI_ACLDATA_PKT 0x02 -#define HCI_SCODATA_PKT 0x03 -#define HCI_EVENT_PKT 0x04 -#define HCI_VENDOR_PKT 0xff - -typedef __packed struct _hci_uart_pckt{ - uint8_t type; - uint8_t data[VARIABLE_SIZE]; -} PACKED hci_uart_pckt; -#define HCI_HDR_SIZE 1 - -typedef __packed struct _hci_command_hdr{ - uint16_t opcode; /* OCF & OGF */ - uint8_t plen; -} PACKED hci_command_hdr; -#define HCI_COMMAND_HDR_SIZE 3 - -typedef __packed struct _hci_event_pckt{ - uint8_t evt; - uint8_t plen; - uint8_t data[VARIABLE_SIZE]; -} PACKED hci_event_pckt; -#define HCI_EVENT_HDR_SIZE 2 - -typedef __packed struct _hci_acl_hdr{ - uint16_t handle; /* Handle & Flags(PB, BC) */ - uint16_t dlen; -} PACKED hci_acl_hdr; -#define HCI_ACL_HDR_SIZE 4 - -/* Link Control */ -#define OGF_LINK_CTL 0x01 - -#define OCF_DISCONNECT 0x0006 -typedef __packed struct _disconnect_cp{ - uint16_t handle; - uint8_t reason; -} PACKED disconnect_cp; -#define DISCONNECT_CP_SIZE 3 - -/* Host Controller and Baseband */ -#define OGF_HOST_CTL 0x03 - -#define OCF_SET_EVENT_MASK 0x0001 -#define OCF_RESET 0x0003 - -#define OCF_READ_TRANSMIT_POWER_LEVEL 0x002D -typedef __packed struct _read_transmit_power_level_cp{ - uint16_t handle; - uint8_t type; -} PACKED read_transmit_power_level_cp; -#define READ_TRANSMIT_POWER_LEVEL_CP_SIZE 3 -typedef __packed struct _read_transmit_power_level_rp{ - uint8_t status; - uint16_t handle; - int8_t level; -} PACKED read_transmit_power_level_rp; -#define READ_TRANSMIT_POWER_LEVEL_RP_SIZE 4 - -#define OCF_SET_CONTROLLER_TO_HOST_FC 0x0031 -#define OCF_HOST_BUFFER_SIZE 0x0033 -#define OCF_HOST_NUM_COMP_PKTS 0x0035 - -/* Informational Parameters */ -#define OGF_INFO_PARAM 0x04 - -#define OCF_READ_LOCAL_VERSION 0x0001 -typedef __packed struct _read_local_version_rp{ - uint8_t status; - uint8_t hci_version; - uint16_t hci_revision; - uint8_t lmp_pal_version; - uint16_t manufacturer_name; - uint16_t lmp_pal_subversion; -} PACKED read_local_version_rp; -#define READ_LOCAL_VERSION_RP_SIZE 9 - -#define OCF_READ_LOCAL_COMMANDS 0x0002 -#define OCF_READ_LOCAL_FEATURES 0x0003 - -#define OCF_READ_BD_ADDR 0x0009 -typedef __packed struct _read_bd_addr_rp{ - uint8_t status; - tBDAddr bdaddr; -} PACKED read_bd_addr_rp; -#define READ_BD_ADDR_RP_SIZE 7 - -/* Status params */ -#define OGF_STATUS_PARAM 0x05 - -#define OCF_READ_RSSI 0x0005 -typedef __packed struct _read_rssi_cp{ - uint16_t handle; -} PACKED read_rssi_cp; -#define READ_RSSI_CP_SIZE 2 -typedef __packed struct _read_rssi_rp{ - uint8_t status; - uint16_t handle; - int8_t rssi; -} PACKED read_rssi_rp; -#define READ_RSSI_RP_SIZE 4 - - -/* LE commands */ -#define OGF_LE_CTL 0x08 - -#define OCF_LE_SET_EVENT_MASK 0x0001 -typedef __packed struct _le_set_event_mask_cp{ - uint8_t mask[8]; -} PACKED le_set_event_mask_cp; -#define LE_SET_EVENT_MASK_CP_SIZE 8 - -#define OCF_LE_READ_BUFFER_SIZE 0x0002 -typedef __packed struct _le_read_buffer_size_rp{ - uint8_t status; - uint16_t pkt_len; - uint8_t max_pkt; -} PACKED le_read_buffer_size_rp; -#define LE_READ_BUFFER_SIZE_RP_SIZE 4 - -#define OCF_LE_READ_LOCAL_SUPPORTED_FEATURES 0x0003 -typedef __packed struct _le_read_local_supported_features_rp{ - uint8_t status; - uint8_t features[8]; -} PACKED le_read_local_supported_features_rp; -#define LE_READ_LOCAL_SUPPORTED_FEATURES_RP_SIZE 9 - -#define OCF_LE_SET_RANDOM_ADDRESS 0x0005 -typedef __packed struct _le_set_random_address_cp{ - tBDAddr bdaddr; -} PACKED le_set_random_address_cp; -#define LE_SET_RANDOM_ADDRESS_CP_SIZE 6 - -#define OCF_LE_SET_ADV_PARAMETERS 0x0006 -typedef __packed struct _le_set_adv_parameters_cp{ - uint16_t min_interval; - uint16_t max_interval; - uint8_t advtype; - uint8_t own_bdaddr_type; - uint8_t direct_bdaddr_type; - tBDAddr direct_bdaddr; - uint8_t chan_map; - uint8_t filter; -} PACKED le_set_adv_parameters_cp; -#define LE_SET_ADV_PARAMETERS_CP_SIZE 15 - -#define OCF_LE_READ_ADV_CHANNEL_TX_POWER 0x0007 -typedef __packed struct _le_read_adv_channel_tx_power_rp{ - uint8_t status; - int8_t level; -} PACKED le_read_adv_channel_tx_power_rp; -#define LE_READ_ADV_CHANNEL_TX_POWER_RP_SIZE 2 - -#define OCF_LE_SET_ADV_DATA 0x0008 -typedef __packed struct _le_set_adv_data_cp{ - uint8_t length; - uint8_t data[31]; -} PACKED le_set_adv_data_cp; -#define LE_SET_ADV_DATA_CP_SIZE 32 - -#define OCF_LE_SET_SCAN_RESPONSE_DATA 0x0009 -typedef __packed struct _le_set_scan_response_data_cp{ - uint8_t length; - uint8_t data[31]; -} PACKED le_set_scan_response_data_cp; -#define LE_SET_SCAN_RESPONSE_DATA_CP_SIZE 32 - -#define OCF_LE_SET_ADVERTISE_ENABLE 0x000A -typedef __packed struct _le_set_advertise_enable_cp{ - uint8_t enable; -} PACKED le_set_advertise_enable_cp; -#define LE_SET_ADVERTISE_ENABLE_CP_SIZE 1 - -#define OCF_LE_SET_SCAN_PARAMETERS 0x000B -typedef __packed struct _le_set_scan_parameters_cp{ - uint8_t type; - uint16_t interval; - uint16_t window; - uint8_t own_bdaddr_type; - uint8_t filter; -} PACKED le_set_scan_parameters_cp; -#define LE_SET_SCAN_PARAMETERS_CP_SIZE 7 - -#define OCF_LE_SET_SCAN_ENABLE 0x000C -typedef __packed struct _le_set_scan_enable_cp{ - uint8_t enable; - uint8_t filter_dup; -} PACKED le_set_scan_enable_cp; -#define LE_SET_SCAN_ENABLE_CP_SIZE 2 - -#define OCF_LE_CREATE_CONN 0x000D -typedef __packed struct _le_create_connection_cp{ - uint16_t interval; - uint16_t window; - uint8_t initiator_filter; - uint8_t peer_bdaddr_type; - tBDAddr peer_bdaddr; - uint8_t own_bdaddr_type; - uint16_t min_interval; - uint16_t max_interval; - uint16_t latency; - uint16_t supervision_timeout; - uint16_t min_ce_length; - uint16_t max_ce_length; -} PACKED le_create_connection_cp; -#define LE_CREATE_CONN_CP_SIZE 25 - -#define OCF_LE_CREATE_CONN_CANCEL 0x000E - -#define OCF_LE_READ_WHITE_LIST_SIZE 0x000F -typedef __packed struct _le_read_white_list_size_rp{ - uint8_t status; - uint8_t size; -} PACKED le_read_white_list_size_rp; -#define LE_READ_WHITE_LIST_SIZE_RP_SIZE 2 - -#define OCF_LE_CLEAR_WHITE_LIST 0x0010 - -#define OCF_LE_ADD_DEVICE_TO_WHITE_LIST 0x0011 -typedef __packed struct _le_add_device_to_white_list_cp{ - uint8_t bdaddr_type; - tBDAddr bdaddr; -} PACKED le_add_device_to_white_list_cp; -#define LE_ADD_DEVICE_TO_WHITE_LIST_CP_SIZE 7 - -#define OCF_LE_REMOVE_DEVICE_FROM_WHITE_LIST 0x0012 -typedef __packed struct _le_remove_device_from_white_list_cp{ - uint8_t bdaddr_type; - tBDAddr bdaddr; -} PACKED le_remove_device_from_white_list_cp; -#define LE_REMOVE_DEVICE_FROM_WHITE_LIST_CP_SIZE 7 - -#define OCF_LE_CONN_UPDATE 0x0013 -typedef __packed struct _le_connection_update_cp{ - uint16_t handle; - uint16_t min_interval; - uint16_t max_interval; - uint16_t latency; - uint16_t supervision_timeout; - uint16_t min_ce_length; - uint16_t max_ce_length; -} PACKED le_connection_update_cp; -#define LE_CONN_UPDATE_CP_SIZE 14 - -#define OCF_LE_SET_HOST_CHANNEL_CLASSIFICATION 0x0014 -typedef __packed struct _le_set_host_channel_classification_cp{ - uint8_t map[5]; -} PACKED le_set_host_channel_classification_cp; -#define LE_SET_HOST_CHANNEL_CLASSIFICATION_CP_SIZE 5 - -#define OCF_LE_READ_CHANNEL_MAP 0x0015 -typedef __packed struct _le_read_channel_map_cp{ - uint16_t handle; -} PACKED le_read_channel_map_cp; -#define LE_READ_CHANNEL_MAP_CP_SIZE 2 - -typedef __packed struct _le_read_channel_map_rp{ - uint8_t status; - uint16_t handle; - uint8_t map[5]; -} PACKED le_read_channel_map_rp; -#define LE_READ_CHANNEL_MAP_RP_SIZE 8 - -#define OCF_LE_READ_REMOTE_USED_FEATURES 0x0016 -typedef __packed struct _le_read_remote_used_features_cp{ - uint16_t handle; -} PACKED le_read_remote_used_features_cp; -#define LE_READ_REMOTE_USED_FEATURES_CP_SIZE 2 - -#define OCF_LE_ENCRYPT 0x0017 -typedef __packed struct _le_encrypt_cp{ - uint8_t key[16]; - uint8_t plaintext[16]; -} PACKED le_encrypt_cp; -#define LE_ENCRYPT_CP_SIZE 32 - -typedef __packed struct _le_encrypt_rp{ - uint8_t status; - uint8_t encdata[16]; -} PACKED le_encrypt_rp; -#define LE_ENCRYPT_RP_SIZE 17 - -#define OCF_LE_RAND 0x0018 -typedef __packed struct _le_rand_rp{ - uint8_t status; - uint8_t random[8]; -} PACKED le_rand_rp; -#define LE_RAND_RP_SIZE 9 - -#define OCF_LE_START_ENCRYPTION 0x0019 -typedef __packed struct _le_start_encryption_cp{ - uint16_t handle; - uint8_t random[8]; - uint16_t diversifier; - uint8_t key[16]; -} PACKED le_start_encryption_cp; -#define LE_START_ENCRYPTION_CP_SIZE 28 - -#define OCF_LE_LTK_REPLY 0x001A -typedef __packed struct _le_ltk_reply_cp{ - uint16_t handle; - uint8_t key[16]; -} PACKED le_ltk_reply_cp; -#define LE_LTK_REPLY_CP_SIZE 18 - -typedef __packed struct _le_ltk_reply_rp{ - uint8_t status; - uint16_t handle; -} PACKED le_ltk_reply_rp; -#define LE_LTK_REPLY_RP_SIZE 3 - -#define OCF_LE_LTK_NEG_REPLY 0x001B -typedef __packed struct _le_ltk_neg_reply_cp{ - uint16_t handle; -} PACKED le_ltk_neg_reply_cp; -#define LE_LTK_NEG_REPLY_CP_SIZE 2 - -typedef __packed struct _le_ltk_neg_reply_rp{ - uint8_t status; - uint16_t handle; -} PACKED le_ltk_neg_reply_rp; -#define LE_LTK_NEG_REPLY_RP_SIZE 3 - -#define OCF_LE_READ_SUPPORTED_STATES 0x001C -typedef __packed struct _le_read_supported_states_rp{ - uint8_t status; - uint8_t states[8]; -} PACKED le_read_supported_states_rp; -#define LE_READ_SUPPORTED_STATES_RP_SIZE 9 - -#define OCF_LE_RECEIVER_TEST 0x001D -typedef __packed struct _le_receiver_test_cp{ - uint8_t frequency; -} PACKED le_receiver_test_cp; -#define LE_RECEIVER_TEST_CP_SIZE 1 - -#define OCF_LE_TRANSMITTER_TEST 0x001E -typedef __packed struct _le_transmitter_test_cp{ - uint8_t frequency; - uint8_t length; - uint8_t payload; -} PACKED le_transmitter_test_cp; -#define LE_TRANSMITTER_TEST_CP_SIZE 3 - -#define OCF_LE_TEST_END 0x001F -typedef __packed struct _le_test_end_rp{ - uint8_t status; - uint16_t num_pkts; -} PACKED le_test_end_rp; -#define LE_TEST_END_RP_SIZE 3 - -/* Vendor specific commands */ -#define OGF_VENDOR_CMD 0x3f - - -/*------------- Events -------------*/ -#define EVT_CONN_COMPLETE 0x03 -typedef __packed struct _evt_conn_complete{ - uint8_t status; - uint16_t handle; - tBDAddr bdaddr; - uint8_t link_type; - uint8_t encr_mode; -} PACKED evt_conn_complete; -#define EVT_CONN_COMPLETE_SIZE 13 - -#define EVT_DISCONN_COMPLETE 0x05 -typedef __packed struct _evt_disconn_complete{ - uint8_t status; - uint16_t handle; - uint8_t reason; -} PACKED evt_disconn_complete; -#define EVT_DISCONN_COMPLETE_SIZE 4 - -#define EVT_ENCRYPT_CHANGE 0x08 -typedef __packed struct _evt_encrypt_change{ - uint8_t status; - uint16_t handle; - uint8_t encrypt; -} PACKED evt_encrypt_change; -#define EVT_ENCRYPT_CHANGE_SIZE 5 - -#define EVT_READ_REMOTE_VERSION_COMPLETE 0x0C - -#define EVT_CMD_COMPLETE 0x0E -typedef __packed struct _evt_cmd_complete{ - uint8_t ncmd; - uint16_t opcode; -} PACKED evt_cmd_complete; -#define EVT_CMD_COMPLETE_SIZE 3 - -#define EVT_CMD_STATUS 0x0F -typedef __packed struct _evt_cmd_status{ - uint8_t status; - uint8_t ncmd; - uint16_t opcode; -} PACKED evt_cmd_status; -#define EVT_CMD_STATUS_SIZE 4 - -#define EVT_HARDWARE_ERROR 0x10 -typedef __packed struct _evt_hardware_error{ - uint8_t code; -} PACKED evt_hardware_error; -#define EVT_HARDWARE_ERROR_SIZE 1 - -#define EVT_NUM_COMP_PKTS 0x13 -typedef __packed struct _evt_num_comp_pkts{ - uint8_t num_hndl; - /* variable length part */ -} PACKED evt_num_comp_pkts; -#define EVT_NUM_COMP_PKTS_SIZE 1 - -/* variable length part of evt_num_comp_pkts. */ -typedef __packed struct _evt_num_comp_pkts_param{ - uint16_t hndl; - uint16_t num_comp_pkts; -} PACKED evt_num_comp_pkts_param; -#define EVT_NUM_COMP_PKTS_PARAM_SIZE 1 - -#define EVT_DATA_BUFFER_OVERFLOW 0x1A -typedef __packed struct _evt_data_buffer_overflow{ - uint8_t link_type; -} PACKED evt_data_buffer_overflow; -#define EVT_DATA_BUFFER_OVERFLOW_SIZE 1 - -#define EVT_ENCRYPTION_KEY_REFRESH_COMPLETE 0x30 -typedef __packed struct _evt_encryption_key_refresh_complete{ - uint8_t status; - uint16_t handle; -} PACKED evt_encryption_key_refresh_complete; -#define EVT_ENCRYPTION_KEY_REFRESH_COMPLETE_SIZE 3 - -#define EVT_LE_META_EVENT 0x3E -typedef __packed struct _evt_le_meta_event{ - uint8_t subevent; - uint8_t data[VARIABLE_SIZE]; -} PACKED evt_le_meta_event; -#define EVT_LE_META_EVENT_SIZE 1 - -#define EVT_LE_CONN_COMPLETE 0x01 -typedef __packed struct _evt_le_connection_complete{ - uint8_t status; - uint16_t handle; - uint8_t role; - uint8_t peer_bdaddr_type; - tBDAddr peer_bdaddr; - uint16_t interval; - uint16_t latency; - uint16_t supervision_timeout; - uint8_t master_clock_accuracy; -} PACKED evt_le_connection_complete; -#define EVT_LE_CONN_COMPLETE_SIZE 18 - -#define EVT_LE_ADVERTISING_REPORT 0x02 -typedef __packed struct _le_advertising_info{ - uint8_t evt_type; - uint8_t bdaddr_type; - tBDAddr bdaddr; - uint8_t data_length; - uint8_t data_RSSI[VARIABLE_SIZE]; // RSSI is last octect (signed integer). -} PACKED le_advertising_info; -#define LE_ADVERTISING_INFO_SIZE 9 - -#define EVT_LE_CONN_UPDATE_COMPLETE 0x03 -typedef __packed struct _evt_le_connection_update_complete{ - uint8_t status; - uint16_t handle; - uint16_t interval; - uint16_t latency; - uint16_t supervision_timeout; -} PACKED evt_le_connection_update_complete; -#define EVT_LE_CONN_UPDATE_COMPLETE_SIZE 9 - -#define EVT_LE_READ_REMOTE_USED_FEATURES_COMPLETE 0x04 -typedef __packed struct _evt_le_read_remote_used_features_complete{ - uint8_t status; - uint16_t handle; - uint8_t features[8]; -} PACKED evt_le_read_remote_used_features_complete; -#define EVT_LE_READ_REMOTE_USED_FEATURES_COMPLETE_SIZE 11 - -#define EVT_LE_LTK_REQUEST 0x05 -typedef __packed struct _evt_le_long_term_key_request{ - uint16_t handle; - uint8_t random[8]; - uint16_t ediv; -} PACKED evt_le_long_term_key_request; -#define EVT_LE_LTK_REQUEST_SIZE 12 - -/** -* The event code in the @ref hci_event_pckt structure. If event code is EVT_VENDOR, -* application can use @ref evt_blue_aci structure to parse the packet. -*/ -#define EVT_VENDOR 0xFF - - -/* Command opcode pack/unpack */ -#define cmd_opcode_pack(ogf, ocf) (uint16_t)((ocf & 0x03ff)|(ogf << 10)) -#define cmd_opcode_ogf(op) (op >> 10) -#define cmd_opcode_ocf(op) (op & 0x03ff) - - -struct hci_request { - uint16_t ogf; - uint16_t ocf; - int event; - void *cparam; - int clen; - void *rparam; - int rlen; -}; - -void hci_send_cmd(uint16_t ogf, uint16_t ocf, uint8_t plen, void *param); - -typedef enum { - WAITING_TYPE, - WAITING_OPCODE1, - WAITING_OPCODE2, - WAITING_EVENT_CODE, - WAITING_HANDLE, - WAITING_HANDLE_FLAG, - WAITING_PARAM_LEN, - WAITING_DATA_LEN1, - WAITING_DATA_LEN2, - WAITING_PAYLOAD -}hci_state; - -typedef void (*hci_packet_complete_callback)(void *pckt, uint16_t len); - -/* HCI library functions. */ -void hci_init(void); - -int hci_send_req(struct hci_request *r, BOOL async); - -#endif /* __HCI_INTERNAL_H_ */
--- a/x-nucleo-idb0xa1/bluenrg-hci/link_layer.h Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,161 +0,0 @@ -/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** -* File Name : link_layer.h -* Author : AMS - HEA&RF BU -* Version : V1.0.0 -* Date : 19-July-2012 -* Description : Header file for BlueNRG's link layer. It contains -* definition of functions for link layer, most of which are -* mapped to HCI commands. -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -#ifndef _LINK_LAYER_H -#define _LINK_LAYER_H - -#include <ble_status.h> - -/** - *@addtogroup GAP GAP - *@brief API for GAP layer. - *@{ - */ - -/** - *@name Advertising filter - *Advertising policy for filtering (white list related) - *@{ - */ -#define NO_WHITE_LIST_USE (0x00) /**< Process scan and connection requests from all devices (i.e., the White List is not in use) */ -#define WHITE_LIST_FOR_ONLY_SCAN (0x01) /**< Process connection requests from all devices and only scan requests from devices that are in the White List */ -#define WHITE_LIST_FOR_ONLY_CONN (0x02) /**< Process scan requests from all devices and only connection requests from devices that are in the White List */ -#define WHITE_LIST_FOR_ALL (0x03) /**< Process scan and connection requests only from devices in the White List. */ -/** - * @} - */ - - -/** - * Bluetooth 48 bit address (in little-endian order). - */ -typedef uint8_t tBDAddr[6]; - - -/** - *@name Bluetooth address types - * Bluetooth address types - *@{ - */ -#define PUBLIC_ADDR (0) -#define RANDOM_ADDR (1) -#define STATIC_RANDOM_ADDR (1) -#define RESOLVABLE_PRIVATE_ADDR (2) -#define NON_RESOLVABLE_PRIVATE_ADDR (3) -/** - * @} - */ - -/** - *@name Directed advertising types - * Type of advertising during directed advertising - *@{ - */ -#define HIGH_DUTY_CYCLE_DIRECTED_ADV (1) -#define LOW_DUTY_CYCLE_DIRECTED_ADV (4) -/** - * @} - */ - -/** - * @name Advertising type - * @{ - */ - -/** - * undirected scannable and connectable - */ -#define ADV_IND (0x00) - -/** - * directed non scannable - */ -#define ADV_DIRECT_IND (0x01) - -/** - * scannable non connectable - */ -#define ADV_SCAN_IND (0x02) - -/** - * non-connectable and no scan response (used for passive scan) - */ -#define ADV_NONCONN_IND (0x03) - -/** - * scan response - */ -#define SCAN_RSP (0x04) - -/** - * @} - */ - -/* 0X05-0XFF RESERVED */ - -/** - * @name Advertising ranges - * @{ - */ - -/** - * lowest allowed interval value for connectable types(20ms)..multiple of 625us - */ -#define ADV_INTERVAL_LOWEST_CONN (0X0020) - -/** - * highest allowed interval value (10.24s)..multiple of 625us. - */ -#define ADV_INTERVAL_HIGHEST (0X4000) - -/** - * lowest allowed interval value for non connectable types - * (100ms)..multiple of 625us. - */ -#define ADV_INTERVAL_LOWEST_NONCONN (0X00a0) - -/** - * @} - */ - -/** - * @name Advertising channels - * @{ - */ -#define ADV_CH_37 0x01 -#define ADV_CH_38 0x02 -#define ADV_CH_39 0x04 -/** - * @} - */ - -/** - * @name Scan_types Scan types - * @{ - */ -#define PASSIVE_SCAN 0 -#define ACTIVE_SCAN 1 -/** - * @} - */ - -/** - * @} - */ - - -#endif /* _LINK_LAYER_H */
--- a/x-nucleo-idb0xa1/bluenrg-hci/list.h Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** -* File Name : list.h -* Author : AMS - HEA&RF BU -* Version : V1.0.0 -* Date : 19-July-2012 -* Description : Header file for linked list library. -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ -#ifndef _LIST_H_ -#define _LIST_H_ - -typedef struct _tListNode { - struct _tListNode * next; - struct _tListNode * prev; -}tListNode, *pListNode; - -void list_init_head (tListNode * listHead); - -uint8_t list_is_empty (tListNode * listHead); - -void list_insert_head (tListNode * listHead, tListNode * node); - -void list_insert_tail (tListNode * listHead, tListNode * node); - -void list_remove_node (tListNode * node); - -void list_remove_head (tListNode * listHead, tListNode ** node ); - -void list_remove_tail (tListNode * listHead, tListNode ** node ); - -void list_insert_node_after (tListNode * node, tListNode * ref_node); - -void list_insert_node_before (tListNode * node, tListNode * ref_node); - -int list_get_size (tListNode * listHead); - -void list_get_next_node (tListNode * ref_node, tListNode ** node); - -void list_get_prev_node (tListNode * ref_node, tListNode ** node); - -#endif /* _LIST_H_ */
--- a/x-nucleo-idb0xa1/bluenrg-hci/osal.h Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** -* File Name : osal.h -* Author : AMS - HEA&RF BU -* Version : V1.0.0 -* Date : 19-July-2012 -* Description : This header file defines the OS abstraction layer used by -* the BLE stack. OSAL defines the set of functions -* which needs to be ported to target operating system and -* target platform. -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -#ifndef __OSAL_H__ -#define __OSAL_H__ - -/****************************************************************************** - * Includes - *****************************************************************************/ -#include <hal_types.h> -#ifdef __ICCARM__ -#include <intrinsics.h> -#endif - -/****************************************************************************** - * Macros - *****************************************************************************/ - - -/****************************************************************************** - * Function Prototypes - *****************************************************************************/ - -/** - * This function copies size number of bytes from a - * memory location pointed by src to a destination - * memory location pointed by dest - * - * @param[in] dest Destination address - * @param[in] src Source address - * @param[in] size size in the bytes - * - * @return Address of the destination - */ - -extern void* Osal_MemCpy(void *dest,const void *src, unsigned int size); - - -/** - * This function sets first number of bytes, specified - * by size, to the destination memory pointed by ptr - * to the specified value - * - * @param[in] ptr Destination address - * @param[in] value Value to be set - * @param[in] size Size in the bytes - * - * @return Address of the destination - */ - -extern void* Osal_MemSet(void *ptr, int value, unsigned int size); - -/** - * Osal_Get_Cur_Time - * - * returns the current time in milliseconds - */ -/** - * Returns the number of ticks (1 tick = 1 millisecond) - * - * @return Time in milliseconds - */ -uint32_t Osal_Get_Cur_Time(void); - - -#endif /* __OSAL_H__ */
--- a/x-nucleo-idb0xa1/bluenrg-hci/sm.h Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,158 +0,0 @@ -/******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** -* File Name : sm.h -* Author : AMS - HEA&RF BU -* Version : V1.0.0 -* Date : 19-July-2012 -* Description : Header file for BlueNRG's security manager. -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -#ifndef __SM_H__ -#define __SM_H__ - -/****************************************************************************** -* Macros -*****************************************************************************/ - -/** - *@addtogroup GAP GAP - *@brief API for GAP layer. - *@{ - */ - -/* IO capabilities */ -/** - * @anchor IO_capabilities - * @name IO capabilities - * @{ - */ -#define IO_CAP_DISPLAY_ONLY (0x00) -#define IO_CAP_DISPLAY_YES_NO (0x01) -#define IO_CAP_KEYBOARD_ONLY (0x02) -#define IO_CAP_NO_INPUT_NO_OUTPUT (0x03) -#define IO_CAP_KEYBOARD_DISPLAY (0x04) -/** - * @} - */ - -/** - * @anchor Auth_req - * @name Authentication requirements - * @{ - */ -#define BONDING (0x01) -#define NO_BONDING (0x00) -/** - * @} - */ - -/** - * @anchor MITM_req - * @name MITM protection requirements - * @{ - */ -#define MITM_PROTECTION_NOT_REQUIRED (0x00) -#define MITM_PROTECTION_REQUIRED (0x01) -/** - * @} - */ - -/** - * @anchor OOB_Data - * @name Out-Of-Band data - * @{ - */ -#define OOB_AUTH_DATA_ABSENT (0x00) -#define OOB_AUTH_DATA_PRESENT (0x01) -/** - * @} - */ - -/** - * @anchor Author_req - * @name Authorization requirements - * @{ - */ -#define AUTHORIZATION_NOT_REQUIRED (0x00) -#define AUTHORIZATION_REQUIRED (0x01) -/** - * @} - */ - -/** - * @anchor Conn_authorization - * @name Connection authorization - * @{ - */ -#define CONNECTION_AUTHORIZED (0x01) -#define CONNECTION_REJECTED (0x02) -/** - * @} - */ - -/** - * @anchor Use_fixed_pin - * @name Use fixed pin - * @{ - */ -#define USE_FIXED_PIN_FOR_PAIRING (0x0) -#define DONOT_USE_FIXED_PIN_FOR_PAIRING (0x01) -/** - * @} - */ - -/** - * @anchor link_security_status - * @name Link security status - * @{ - */ -#define SM_LINK_AUTHENTICATED (0x01) -#define SM_LINK_AUTHORIZED (0x02) -#define SM_LINK_ENCRYPTED (0x04) -/** - * @} - */ - -/** - * @anchor SMP_pairing_failed_codes - * @name SMP pairing failed reason codes - * @{ - */ -#define PASSKEY_ENTRY_FAILED (0x01) -#define OOB_NOT_AVAILABLE (0x02) -#define AUTH_REQ_CANNOT_BE_MET (0x03) -#define CONFIRM_VALUE_FAILED (0x04) -#define PAIRING_NOT_SUPPORTED (0x05) -#define INSUFF_ENCRYPTION_KEY_SIZE (0x06) -#define CMD_NOT_SUPPORTED (0x07) -#define UNSPECIFIED_REASON (0x08) -#define VERY_EARLY_NEXT_ATTEMPT (0x09) -#define SM_INVALID_PARAMS (0x0A) -/** - * @} - */ - -/** - * @anchor pairing_failed_codes - * @name Pairing failed error codes - * Error codes in @ref EVT_BLUE_GAP_PAIRING_CMPLT event - * @{ - */ -#define SM_PAIRING_SUCCESS (0x00) -#define SM_PAIRING_TIMEOUT (0x01) -#define SM_PAIRING_FAILED (0x02) -/** - * @} - */ - -/** - * @} - */ - -#endif /* __SM_H__ */
--- a/x-nucleo-idb0xa1/platform/btle.h Thu Sep 15 10:51:44 2016 +0100 +++ b/x-nucleo-idb0xa1/platform/btle.h Thu Sep 15 10:52:09 2016 +0100 @@ -26,9 +26,9 @@ #include <stdio.h> #include <string.h> -#include "hci.h" +#include "ble_hci.h" #include "bluenrg_aci.h" -#include "hci_const.h" +#include "ble_hci_const.h" #include "bluenrg_hal_aci.h" #include "stm32_bluenrg_ble.h" #include "bluenrg_gap.h"
--- a/x-nucleo-idb0xa1/platform/stm32_bluenrg_ble.h Thu Sep 15 10:51:44 2016 +0100 +++ b/x-nucleo-idb0xa1/platform/stm32_bluenrg_ble.h Thu Sep 15 10:52:09 2016 +0100 @@ -45,8 +45,8 @@ #include <stdint.h> -#include "gp_timer.h" -#include "hal.h" +#include "ble_gp_timer.h" +#include "ble_hal.h" /** @addtogroup BSP * @{ @@ -101,4 +101,3 @@ #endif /* __STM32_BLUENRG_BLE_H */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ -
--- a/x-nucleo-idb0xa1/utils/Payload.h Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,195 +0,0 @@ -/* mbed Microcontroller Library -* Copyright (c) 2006-2013 ARM Limited -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifdef YOTTA_CFG_MBED_OS - #include "mbed-drivers/mbed.h" -#else - #include "mbed.h" -#endif -#include "debug.h" - -#ifndef __PAYLOAD_H__ -#define __PAYLOAD_H__ - -class UnitPayload -{ -public: - uint8_t length; - uint8_t id; - uint8_t *data; - uint8_t *idptr; - - - - void set_length(uint8_t l) { - length=l; - } - - void set_id(uint8_t i) { - id=i; - } - - void set_data(uint8_t* data1) { - for(int j=0;j<length;j++) - { - data[j]=data1[j]; - } - } - - uint8_t get_length() { - return length; - } - - uint8_t get_id() { - return id; - } - - uint8_t* get_data() { - return data; - } - -}; - -class Payload { - UnitPayload *payload; - int stringLength; - int payloadUnitCount; - -public: - Payload(const uint8_t *tokenString, uint8_t string_ength); - Payload(); - ~Payload(); - uint8_t getPayloadUnitCount(); - - uint8_t getIDAtIndex(int index); - uint8_t getLengthAtIndex(int index); - uint8_t* getDataAtIndex(int index); - int8_t getInt8AtIndex(int index); - uint16_t getUint16AtIndex(int index); - uint8_t* getSerializedAdDataAtIndex(int index); -}; - - -class PayloadUnit { -private: - uint8_t* lenPtr; - uint8_t* adTypePtr; - uint8_t* dataPtr; - -public: - PayloadUnit() { - lenPtr = NULL; - adTypePtr = NULL; - dataPtr = NULL; - } - - PayloadUnit(uint8_t *len, uint8_t *adType, uint8_t* data) { - lenPtr = len; - adTypePtr = adType; - dataPtr = data; - } - - void setLenPtr(uint8_t *len) { - lenPtr = len; - } - - void setAdTypePtr(uint8_t *adType) { - adTypePtr = adType; - } - - void setDataPtr(uint8_t *data) { - dataPtr = data; - } - - uint8_t* getLenPtr() { - return lenPtr; - } - - uint8_t* getAdTypePtr() { - return adTypePtr; - } - - uint8_t* getDataPtr() { - return dataPtr; - } - - void printDataAsHex() { - int i = 0; - PRINTF("AdData="); - for(i=0; i<*lenPtr-1; i++) { - PRINTF("0x%x ", dataPtr[i]); - } - PRINTF("\n"); - } - - void printDataAsString() { - int i = 0; - PRINTF("AdData="); - for(i=0; i<*lenPtr-1; i++) { - PRINTF("%c", dataPtr[i]); - } - PRINTF("\n"); - } - -}; - -class PayloadPtr { -private: - PayloadUnit *unit; - int payloadUnitCount; -public: - PayloadPtr(const uint8_t *tokenString, uint8_t string_ength) { - // initialize private data members - int stringLength = string_ength; - payloadUnitCount = 0; - - int index = 0; - while(index!=stringLength) { - int len=tokenString[index]; - index=index+1+len; - payloadUnitCount++; - } - - // allocate memory to unit - unit = new PayloadUnit[payloadUnitCount]; - int i = 0; - int nextUnitOffset = 0; - - while(i<payloadUnitCount) { - unit[i].setLenPtr((uint8_t *)tokenString+nextUnitOffset); - unit[i].setAdTypePtr((uint8_t *)tokenString+nextUnitOffset+1); - unit[i].setDataPtr((uint8_t *)tokenString+nextUnitOffset+2); - - nextUnitOffset += *unit[i].getLenPtr()+1; - i++; - - } - } - - PayloadUnit getUnitAtIndex(int index) { - return unit[index]; - } - - int getPayloadUnitCount() { return payloadUnitCount; } - - ~PayloadPtr() { - if(unit) delete[] unit; - - unit = NULL; - } -}; - -#endif // __PAYLOAD_H__ \ No newline at end of file
--- a/x-nucleo-idb0xa1/utils/Utils.h Thu Sep 15 10:51:44 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* mbed Microcontroller Library -* Copyright (c) 2006-2013 ARM Limited -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -// utility functions - -#ifndef __UTIL_H__ -#define __UTIL_H__ - -#include "ble_status.h" -#include "hal_types.h" -#ifdef YOTTA_CFG_MBED_OS - #include "mbed-drivers/mbed.h" -#else - #include "mbed.h" -#endif - -#define STORE_LE_16(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \ - ((buf)[1] = (uint8_t) (val>>8) ) ) - -#define STORE_LE_32(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \ - ((buf)[1] = (uint8_t) (val>>8) ) , \ - ((buf)[2] = (uint8_t) (val>>16) ) , \ - ((buf)[3] = (uint8_t) (val>>24) ) ) - -#define COPY_UUID_128(uuid_struct, uuid_15, uuid_14, uuid_13, uuid_12, uuid_11, uuid_10, uuid_9, uuid_8, uuid_7, uuid_6, uuid_5, uuid_4, uuid_3, uuid_2, uuid_1, uuid_0) \ - do {\ - uuid_struct[0] = uuid_0; uuid_struct[1] = uuid_1; uuid_struct[2] = uuid_2; uuid_struct[3] = uuid_3; \ - uuid_struct[4] = uuid_4; uuid_struct[5] = uuid_5; uuid_struct[6] = uuid_6; uuid_struct[7] = uuid_7; \ - uuid_struct[8] = uuid_8; uuid_struct[9] = uuid_9; uuid_struct[10] = uuid_10; uuid_struct[11] = uuid_11; \ - uuid_struct[12] = uuid_12; uuid_struct[13] = uuid_13; uuid_struct[14] = uuid_14; uuid_struct[15] = uuid_15; \ - }while(0) - - -tBleStatus getHighPowerAndPALevelValue(int8_t dBMLevel, int8_t& EN_HIGH_POWER, int8_t& PA_LEVEL); - -#endif // __UTIL_H__ - \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x-nucleo-idb0xa1/utils/ble_payload.h Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,195 @@ +/* mbed Microcontroller Library +* Copyright (c) 2006-2013 ARM Limited +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifdef YOTTA_CFG_MBED_OS + #include "mbed-drivers/mbed.h" +#else + #include "mbed.h" +#endif +#include "ble_debug.h" + +#ifndef __PAYLOAD_H__ +#define __PAYLOAD_H__ + +class UnitPayload +{ +public: + uint8_t length; + uint8_t id; + uint8_t *data; + uint8_t *idptr; + + + + void set_length(uint8_t l) { + length=l; + } + + void set_id(uint8_t i) { + id=i; + } + + void set_data(uint8_t* data1) { + for(int j=0;j<length;j++) + { + data[j]=data1[j]; + } + } + + uint8_t get_length() { + return length; + } + + uint8_t get_id() { + return id; + } + + uint8_t* get_data() { + return data; + } + +}; + +class Payload { + UnitPayload *payload; + int stringLength; + int payloadUnitCount; + +public: + Payload(const uint8_t *tokenString, uint8_t string_ength); + Payload(); + ~Payload(); + uint8_t getPayloadUnitCount(); + + uint8_t getIDAtIndex(int index); + uint8_t getLengthAtIndex(int index); + uint8_t* getDataAtIndex(int index); + int8_t getInt8AtIndex(int index); + uint16_t getUint16AtIndex(int index); + uint8_t* getSerializedAdDataAtIndex(int index); +}; + + +class PayloadUnit { +private: + uint8_t* lenPtr; + uint8_t* adTypePtr; + uint8_t* dataPtr; + +public: + PayloadUnit() { + lenPtr = NULL; + adTypePtr = NULL; + dataPtr = NULL; + } + + PayloadUnit(uint8_t *len, uint8_t *adType, uint8_t* data) { + lenPtr = len; + adTypePtr = adType; + dataPtr = data; + } + + void setLenPtr(uint8_t *len) { + lenPtr = len; + } + + void setAdTypePtr(uint8_t *adType) { + adTypePtr = adType; + } + + void setDataPtr(uint8_t *data) { + dataPtr = data; + } + + uint8_t* getLenPtr() { + return lenPtr; + } + + uint8_t* getAdTypePtr() { + return adTypePtr; + } + + uint8_t* getDataPtr() { + return dataPtr; + } + + void printDataAsHex() { + int i = 0; + PRINTF("AdData="); + for(i=0; i<*lenPtr-1; i++) { + PRINTF("0x%x ", dataPtr[i]); + } + PRINTF("\n"); + } + + void printDataAsString() { + int i = 0; + PRINTF("AdData="); + for(i=0; i<*lenPtr-1; i++) { + PRINTF("%c", dataPtr[i]); + } + PRINTF("\n"); + } + +}; + +class PayloadPtr { +private: + PayloadUnit *unit; + int payloadUnitCount; +public: + PayloadPtr(const uint8_t *tokenString, uint8_t string_ength) { + // initialize private data members + int stringLength = string_ength; + payloadUnitCount = 0; + + int index = 0; + while(index!=stringLength) { + int len=tokenString[index]; + index=index+1+len; + payloadUnitCount++; + } + + // allocate memory to unit + unit = new PayloadUnit[payloadUnitCount]; + int i = 0; + int nextUnitOffset = 0; + + while(i<payloadUnitCount) { + unit[i].setLenPtr((uint8_t *)tokenString+nextUnitOffset); + unit[i].setAdTypePtr((uint8_t *)tokenString+nextUnitOffset+1); + unit[i].setDataPtr((uint8_t *)tokenString+nextUnitOffset+2); + + nextUnitOffset += *unit[i].getLenPtr()+1; + i++; + + } + } + + PayloadUnit getUnitAtIndex(int index) { + return unit[index]; + } + + int getPayloadUnitCount() { return payloadUnitCount; } + + ~PayloadPtr() { + if(unit) delete[] unit; + + unit = NULL; + } +}; + +#endif // __PAYLOAD_H__ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x-nucleo-idb0xa1/utils/ble_utils.h Thu Sep 15 10:52:09 2016 +0100 @@ -0,0 +1,46 @@ +/* mbed Microcontroller Library +* Copyright (c) 2006-2013 ARM Limited +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +// utility functions + +#ifndef __UTIL_H__ +#define __UTIL_H__ + +#include "ble_status.h" +#include "ble_hal_types.h" + +#define STORE_LE_16(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \ + ((buf)[1] = (uint8_t) (val>>8) ) ) + +#define STORE_LE_32(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \ + ((buf)[1] = (uint8_t) (val>>8) ) , \ + ((buf)[2] = (uint8_t) (val>>16) ) , \ + ((buf)[3] = (uint8_t) (val>>24) ) ) + +#define COPY_UUID_128(uuid_struct, uuid_15, uuid_14, uuid_13, uuid_12, uuid_11, uuid_10, uuid_9, uuid_8, uuid_7, uuid_6, uuid_5, uuid_4, uuid_3, uuid_2, uuid_1, uuid_0) \ + do {\ + uuid_struct[0] = uuid_0; uuid_struct[1] = uuid_1; uuid_struct[2] = uuid_2; uuid_struct[3] = uuid_3; \ + uuid_struct[4] = uuid_4; uuid_struct[5] = uuid_5; uuid_struct[6] = uuid_6; uuid_struct[7] = uuid_7; \ + uuid_struct[8] = uuid_8; uuid_struct[9] = uuid_9; uuid_struct[10] = uuid_10; uuid_struct[11] = uuid_11; \ + uuid_struct[12] = uuid_12; uuid_struct[13] = uuid_13; uuid_struct[14] = uuid_14; uuid_struct[15] = uuid_15; \ + }while(0) + + +tBleStatus getHighPowerAndPALevelValue(int8_t dBMLevel, int8_t& EN_HIGH_POWER, int8_t& PA_LEVEL); + +#endif // __UTIL_H__ + \ No newline at end of file