├── README.md ├── examples ├── SPBTLE_BeaconDemo │ └── SPBTLE_BeaconDemo.ino └── SPBTLE_SensorDemo │ └── SPBTLE_SensorDemo.ino ├── library.properties └── src ├── SPBTLE_RF.cpp ├── SPBTLE_RF.h ├── STM32_BlueNRG └── SimpleBlueNRG_HCI │ ├── hci │ ├── controller │ │ ├── bluenrg_IFR.c │ │ ├── bluenrg_gap_aci.c │ │ ├── bluenrg_gatt_aci.c │ │ ├── bluenrg_hal_aci.c │ │ ├── bluenrg_l2cap_aci.c │ │ ├── bluenrg_updater_aci.c │ │ └── bluenrg_utils.c │ ├── hci.c │ └── hci_le.c │ └── utils │ ├── ble_list.c │ ├── gp_timer.c │ └── osal.c ├── beacon_service.cpp ├── beacon_service.h ├── ble_clock.h ├── ble_list.h ├── ble_status.h ├── bluenrg_aci.h ├── bluenrg_aci_const.h ├── bluenrg_gap.h ├── bluenrg_gap_aci.h ├── bluenrg_gatt_aci.h ├── bluenrg_gatt_server.h ├── bluenrg_hal_aci.h ├── bluenrg_interface.c ├── bluenrg_interface.h ├── bluenrg_l2cap_aci.h ├── bluenrg_updater_aci.h ├── bluenrg_utils.h ├── compiler.h ├── connection_config.h ├── debug.h ├── eddystone_beacon.c ├── eddystone_beacon.h ├── gp_timer.h ├── hal.h ├── hal_types.h ├── hci.h ├── hci_const.h ├── hci_le.h ├── link_layer.h ├── osal.h ├── sensor_service.cpp ├── sensor_service.h ├── sm.h └── stm32_bluenrg_ble.h /README.md: -------------------------------------------------------------------------------- 1 | # SPBTLE-RF 2 | Arduino library to support the Bluetooth (V4.1 compliant) SPBTLE-RF module 3 | 4 | ## API 5 | 6 | The library provides a basic BLE class to configure and enable the Bluetooth module. 7 | Each profile provides its own class. See Beacon and sensorDemo profiles. 8 | 9 | ## Examples 10 | 11 | The library includes two sketches. They are very similar, one sketch provides a Beacon Service, an other a Sensor Service. 12 | 13 | For the Beacon Service sketch, we can see on the monitor window all the initialization phase, and the message 14 | "Beacon service start!" when the bluetooth module is started and ready. 15 | Two mode are supported, UID mode and URL mode. On both mode, user can choose the bluetooth MAC address of the device by 16 | configuring SERVER_BDADDR in the Arduino sketch. 17 | On UID mode, user can choose the Namespace and the Instance. This data are sent to the associated device (for example your smartphone). 18 | On URL mode, user can choose the webURL sended. 19 | 20 | You can test this application by connecting it with your smartphone. 21 | On Android, donwload the Beacon Scanner Apps (iBeacon & Eddystone Scanner by flurp laboratories). The Apps can 22 | also be found [here](https://play.google.com/store/apps/details?id=de.flurp.beaconscanner.app). 23 | Then start the app, it will ask you to enable the bluetooth on your smartphone. Start scanning and you will see the the device. 24 | If you use it on UID mode, you will the see the Namespace and the instance. 25 | If you use it on URL mode, you will see the URL, you can click on it and you will send the web page. 26 | 27 | 28 | For the Sensor Service sketch, we can see on the monitor window all the initialization phase, and a message for each service started. 29 | Three services are started : Acc, Environnemental and Time. 30 | For testing the sketch, you can download on the playstore the "BLueNRG" application provided by STMicroelectronics. 31 | Launch the application and enable Bluetooth on your smartphone. Connect it to the BLueNRG device. You will see all the services, 32 | you can click on each one and read the data. 33 | Pay attention that the device name can't be more than 7 characters long. If the string passed to the begin function is longer, it is 34 | automatically trimmed to the first 7 characters. 35 | The BlueNRG app expects "BlueNRG" as device name, using anything else will make the device not connectable. 36 | 37 | 38 | The SPBTLE-RF uses SPI. You need to configure the pin used for spi link. 39 | SPIClass SPI_3(MOSI, MISO, CLK); 40 | 41 | Choose the SPI used by the SPBTLE-RF, and the pinout of the device. A cheep select pin, spiIRQ pin, reset PIN and a led (optional) are required. 42 | SPBTLERFClass BTLE(SPI_X, CS pin, IRQ pin, reset pin); 43 | SPBTLERFClass BTLE(SPI_X, CS pin, IRQ pin, reset pin, LED pin); 44 | 45 | Start the bluetooth module. 46 | BTLE.begin(); 47 | 48 | Start the service. For example the BeaconService in UID_TYPE. 49 | BeaconService.begin(SERVER_BDADDR, beaconID, NameSpace); 50 | 51 | ## BLE stack 52 | 53 | Version: 3.0.0 54 | The Bluetooth stack comes from [STM32CubeExpansion_BLE1_V3.0.0](http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software-expansion/x-cube-ble1.html). 55 | 56 | The BlueNRG stack is composed of some specific parts: 57 | 58 | * **HCI** files provide API for HCI (Host Controller Interface) layer 59 | * **GAP** files provide API for GAP (Generic Access Profile) layer 60 | * **GATT** files provide API for GATT (Generic Attribute Profile) layer 61 | * **L2CAP** files provide API for L2CAP (Logical Link Control and Adaptation Protocol) layer 62 | 63 | More information about the different layers: 64 | * https://www.bluetooth.com/specifications/bluetooth-core-specification 65 | * https://www.bluetooth.com/specifications/gatt 66 | 67 | ## Note 68 | 69 | At the compilation time a warning is raised about an IFR configuration not valid. 70 | This is normal because the library proposes an API to update the firmware of the 71 | BLE module but the configuration flag isn't declared. See STM32CubeExpansion_BLE1_V3.0.0 72 | documentation for more information about the IFR updater. 73 | 74 | ## Documentation 75 | 76 | You can find the source files at 77 | https://github.com/stm32duino/SPBTLE-RF 78 | 79 | The SPBTLE-RF module datasheet is available at 80 | http://www.st.com/content/st_com/en/products/wireless-connectivity/bluetooth-bluetooth-low-energy/spbtle-rf.html 81 | -------------------------------------------------------------------------------- /examples/SPBTLE_BeaconDemo/SPBTLE_BeaconDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | SPBTLE_BeaconDemo 4 | 5 | This sketch provides a default example how to use BLE with: 6 | - Discovery L475VG IoT board 7 | 8 | For the Beacon Service, two modes are supported: 9 | - UID mode, you can choose the Namespace and the ID. This data are sent 10 | to the associated device (for example your smartphone). 11 | Or 12 | - URL mode, you can choose the webURL sended. 13 | 14 | You can choose the bluetooth MAC address of the device by configuring SERVER_BDADDR. 15 | 16 | You can test this application by connecting it with your smartphone. 17 | On Android, donwload any Beacon Scanner Apps (e.g. iBeacon & Eddystone Scanner 18 | by flurp laboratories https://play.google.com/store/apps/details?id=de.flurp.beaconscanner.app). 19 | Then start the app, enable the bluetooth on your smartphone, start scanning and 20 | you will see the device. 21 | If you use UID mode, you will the see the Namespace and the instance. 22 | If you use URL mode, you will see the URL, you can click on it and you will 23 | send to the web page. 24 | 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #define PIN_BLE_SPI_MOSI (PC12) 32 | #define PIN_BLE_SPI_MISO (PC11) 33 | #define PIN_BLE_SPI_SCK (PC10) 34 | 35 | #define PIN_BLE_SPI_nCS (PD13) 36 | #define PIN_BLE_SPI_RESET (PA8) 37 | #define PIN_BLE_SPI_IRQ (PE6) 38 | 39 | #define PIN_BLE_LED (LED4) 40 | 41 | // Configure BTLE_SPI 42 | SPIClass BTLE_SPI(PIN_BLE_SPI_MOSI, PIN_BLE_SPI_MISO, PIN_BLE_SPI_SCK); 43 | 44 | // Configure BTLE pins 45 | SPBTLERFClass BTLE(&BTLE_SPI, PIN_BLE_SPI_nCS, PIN_BLE_SPI_IRQ, PIN_BLE_SPI_RESET, PIN_BLE_LED); 46 | 47 | // Mac address 48 | uint8_t SERVER_BDADDR[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x03}; 49 | 50 | //Comment this line to use URL mode 51 | #define USE_UID_MODE 52 | 53 | #ifdef USE_UID_MODE 54 | // Beacon ID, the 6 last bytes are used for NameSpace 55 | uint8_t NameSpace[] = "ST BTLE"; 56 | uint8_t beaconID[] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6}; 57 | #else 58 | char url[] = "www.st.com"; 59 | #endif 60 | 61 | void setup() { 62 | Serial.begin(9600); 63 | 64 | if(BTLE.begin()) 65 | { 66 | Serial.println("Bluetooth module configuration error!"); 67 | while(1); 68 | } 69 | 70 | #ifdef USE_UID_MODE 71 | // Enable the beacon service in UID mode 72 | if(BeaconService.begin(SERVER_BDADDR, beaconID, NameSpace)) 73 | { 74 | Serial.println("Beacon service configuration error!"); 75 | while(1); 76 | } 77 | else 78 | { 79 | Serial.println("Beacon service started!"); 80 | } 81 | #else 82 | //Enable the beacon service in URL mode 83 | if(BeaconService.begin(SERVER_BDADDR, url)) 84 | { 85 | Serial.println("Beacon service configuration error!"); 86 | while(1); 87 | } 88 | else 89 | { 90 | Serial.println("Beacon service started!"); 91 | } 92 | #endif 93 | } 94 | 95 | void loop() { 96 | // Update the BLE module state 97 | BTLE.update(); 98 | } 99 | -------------------------------------------------------------------------------- /examples/SPBTLE_SensorDemo/SPBTLE_SensorDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | SPBTLE_SensorDemo 4 | 5 | This sketch provides a default example how to use BLE with: 6 | - Discovery L475VG IoT board 7 | 8 | For the Sensor Service sketch, 3 services are started : Acc, Environnemental and Time. 9 | For testing the sketch, you can download on the playstore the "BlueNRG" 10 | application provided by STMICROELECTRONICS. 11 | Launch the application and enable Bluetooth on your smartphone. Connect it to 12 | the BLueNRG device. You will see all the services, you can click on each one. 13 | 14 | You can choose the bluetooth MAC address of the device by configuring SERVER_BDADDR. 15 | 16 | Accelerometer values are updated on user action (press user button). 17 | Environnemental values (Temperature, humidity and pressure) are updated each seconds. 18 | Each minute a notification is sent to the user and seconds can be read. 19 | 20 | Pay attention that the device name can't be more than 7 characters long. If the string 21 | passed to the begin function is longer, it is automatically trimmed to the first 7 characters. 22 | The BlueNRG app expects "BlueNRG" as device name, using anything else will make the device 23 | not connectable. 24 | 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #define PIN_BLE_SPI_MOSI (PC12) 32 | #define PIN_BLE_SPI_MISO (PC11) 33 | #define PIN_BLE_SPI_SCK (PC10) 34 | 35 | #define PIN_BLE_SPI_nCS (PD13) 36 | #define PIN_BLE_SPI_RESET (PA8) 37 | #define PIN_BLE_SPI_IRQ (PE6) 38 | 39 | #define PIN_BLE_LED (LED4) 40 | 41 | // Configure BTLE_SPI 42 | SPIClass BTLE_SPI(PIN_BLE_SPI_MOSI, PIN_BLE_SPI_MISO, PIN_BLE_SPI_SCK); 43 | 44 | // Configure BTLE pins 45 | SPBTLERFClass BTLE(&BTLE_SPI, PIN_BLE_SPI_nCS, PIN_BLE_SPI_IRQ, PIN_BLE_SPI_RESET, PIN_BLE_LED); 46 | 47 | const char *name = "BlueNRG"; //Should be at most 7 characters 48 | uint8_t SERVER_BDADDR[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x03}; 49 | 50 | AxesRaw_t axes_data; 51 | uint32_t previousSecond = 0; 52 | 53 | void setup() { 54 | int ret; 55 | 56 | Serial.begin(9600); 57 | 58 | if(BTLE.begin() == SPBTLERF_ERROR) 59 | { 60 | Serial.println("Bluetooth module configuration error!"); 61 | while(1); 62 | } 63 | 64 | if(SensorService.begin(name, SERVER_BDADDR)) 65 | { 66 | Serial.println("Sensor service configuration error!"); 67 | while(1); 68 | } 69 | 70 | /* Configure the User Button in GPIO Mode */ 71 | pinMode(USER_BTN, INPUT); 72 | 73 | ret = SensorService.Add_Acc_Service(); 74 | 75 | if(ret == BLE_STATUS_SUCCESS) 76 | Serial.println("Acc service added successfully."); 77 | else 78 | Serial.println("Error while adding Acc service."); 79 | 80 | ret = SensorService.Add_Environmental_Sensor_Service(); 81 | 82 | if(ret == BLE_STATUS_SUCCESS) 83 | Serial.println("Environmental Sensor service added successfully."); 84 | else 85 | Serial.println("Error while adding Environmental Sensor service."); 86 | 87 | randomSeed(analogRead(A0)); 88 | 89 | /* Instantiate Timer Service with two characteristics: 90 | * - seconds characteristic (Readable only) 91 | * - minutes characteristics (Readable and Notifiable ) 92 | */ 93 | ret = SensorService.Add_Time_Service(); 94 | 95 | if(ret == BLE_STATUS_SUCCESS) 96 | Serial.println("Time service added successfully."); 97 | else 98 | Serial.println("Error while adding Time service."); 99 | } 100 | 101 | void loop() { 102 | BTLE.update(); 103 | 104 | if(SensorService.isConnected() == TRUE) 105 | { 106 | //Update accelerometer values 107 | User_Process(&axes_data); 108 | 109 | //Update time 110 | SensorService.Update_Time_Characteristics(); 111 | 112 | if((millis() - previousSecond) >= 1000) 113 | { 114 | //Update environnemental data 115 | //Data are set with random values but can be replace with data from sensors. 116 | previousSecond = millis(); 117 | SensorService.Temp_Update(random(-100,400)); 118 | SensorService.Press_Update(random(95000,105000)); 119 | SensorService.Humidity_Update(random(0,100)); 120 | } 121 | } 122 | else 123 | { 124 | //Keep the Bluetooth module in discoverable mode 125 | SensorService.setConnectable(); 126 | } 127 | } 128 | 129 | /** 130 | * @brief Process user input (i.e. pressing the USER button on Nucleo board) 131 | * and send the updated acceleration data to the remote client. 132 | * 133 | * @param AxesRaw_t* p_axes 134 | * @retval None 135 | */ 136 | void User_Process(AxesRaw_t* p_axes) 137 | { 138 | /* Check if the user has pushed the button */ 139 | if(digitalRead(USER_BTN) == RESET) 140 | { 141 | while (digitalRead(USER_BTN) == RESET); 142 | 143 | /* Update acceleration data */ 144 | p_axes->AXIS_X += 100; 145 | p_axes->AXIS_Y += 100; 146 | p_axes->AXIS_Z += 100; 147 | SensorService.Acc_Update(p_axes); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=STM32duino SPBTLE-RF 2 | version=1.0.3 3 | author=STMicroelectronics, AMS, Wi6Labs 4 | maintainer=stm32duino 5 | sentence=This library includes drivers for ST's BlueNRG/BlueNRG-MS Bluetooth Low Energy device. 6 | paragraph=This library is built for STM32 microcontrollers and comes with examples of implementation of the BLE drivers. 7 | category=Communication 8 | url=https://github.com/stm32duino/SPBTLE-RF 9 | architectures=stm32 10 | -------------------------------------------------------------------------------- /src/SPBTLE_RF.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file SPBTLE_RF.cpp 4 | * @author Wi6Labs 5 | * @version V1.0.0 6 | * @date 18-August-2017 7 | * @brief 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2017 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Includes ------------------------------------------------------------------*/ 39 | #include 40 | #include "Arduino.h" 41 | #include "hci.h" 42 | #include "stm32_bluenrg_ble.h" 43 | #include "bluenrg_interface.h" 44 | #include "debug.h" 45 | #include "gp_timer.h" 46 | #include "hal.h" 47 | 48 | #define HEADER_SIZE 5 49 | #define MAX_BUFFER_SIZE 255 50 | 51 | uint8_t bnrg_expansion_board; 52 | 53 | void (*HCI_callback)(void *); 54 | 55 | static SPIClass *SPIBTLE; 56 | static uint8_t csPin; 57 | static uint8_t spiIRQPin; 58 | static uint8_t resetPin; 59 | static uint8_t ledPin; 60 | 61 | SPBTLERFClass::SPBTLERFClass(SPIClass *SPIx, uint8_t cs, uint8_t spiIRQ, 62 | uint8_t reset, uint8_t led) 63 | { 64 | SPIBTLE = SPIx; 65 | csPin = cs; 66 | spiIRQPin = spiIRQ; 67 | resetPin = reset; 68 | ledPin = led; 69 | } 70 | 71 | SPBTLERF_state_t SPBTLERFClass::begin(void) 72 | { 73 | /* Initialize the BlueNRG SPI driver */ 74 | // Configure SPI and CS pin 75 | SPIBTLE->begin(); 76 | pinMode(csPin, OUTPUT); 77 | digitalWrite(csPin, HIGH); 78 | 79 | // Enable SPI EXTI interrupt 80 | attachInterrupt(spiIRQPin, SPI_EXTI_Callback, RISING); 81 | 82 | // Configure Reset pin 83 | pinMode(resetPin, OUTPUT); 84 | digitalWrite(resetPin, LOW); // Keep module in reset state 85 | 86 | /* Initialize the BlueNRG HCI */ 87 | HCI_Init(); 88 | 89 | /* Reset BlueNRG hardware */ 90 | BlueNRG_RST(); 91 | 92 | // If a LED is associated, enable it to indicate the module is ready 93 | if(ledPin != 0xFF) { 94 | pinMode(ledPin, OUTPUT); 95 | digitalWrite(ledPin, LOW); 96 | } 97 | 98 | return SPBTLERF_OK; 99 | } 100 | 101 | void SPBTLERFClass::end(void) 102 | { 103 | digitalWrite(resetPin, LOW); 104 | detachInterrupt(spiIRQPin); 105 | SPIBTLE->end(); 106 | 107 | if(ledPin != 0xFF) { 108 | digitalWrite(ledPin, HIGH); 109 | // Allows to not enable the WiFi LED on board Discovery L475VG IOT 110 | pinMode(ledPin, INPUT); 111 | } 112 | } 113 | 114 | void SPBTLERFClass::update(void) 115 | { 116 | HCI_Process(); 117 | } 118 | 119 | /** 120 | * @brief This function is a utility to print the log time 121 | * in the format HH:MM:SS:MSS (DK GUI time format) 122 | * @param None 123 | * @retval None 124 | */ 125 | #ifdef PRINT_CSV_FORMAT 126 | void print_csv_time(void){ 127 | uint32_t ms = HAL_GetTick(); 128 | PRINT_CSV("%02d:%02d:%02d.%03d", ms/(60*60*1000)%24, ms/(60*1000)%60, (ms/1000)%60, ms%1000); 129 | } 130 | #endif //PRINT_CSV_FORMAT 131 | 132 | /** 133 | * @brief Writes data to a serial interface. 134 | * @param data1 : 1st buffer 135 | * @param data2 : 2nd buffer 136 | * @param n_bytes1: number of bytes in 1st buffer 137 | * @param n_bytes2: number of bytes in 2nd buffer 138 | * @retval None 139 | */ 140 | void Hal_Write_Serial(const void* data1, const void* data2, int32_t n_bytes1, 141 | int32_t n_bytes2) 142 | { 143 | struct timer t; 144 | 145 | Timer_Set(&t, CLOCK_SECOND/5); 146 | 147 | #ifdef PRINT_CSV_FORMAT 148 | print_csv_time(); 149 | for (int i=0; itransfer(header_master, header_slave, HEADER_SIZE); 237 | 238 | if (header_slave[0] == 0x02) { 239 | /* device is ready */ 240 | byte_count = (header_slave[4]<<8)|header_slave[3]; 241 | 242 | if (byte_count > 0) { 243 | 244 | /* avoid to read more data that size of the buffer */ 245 | if (byte_count > buff_size){ 246 | byte_count = buff_size; 247 | } 248 | 249 | for (len = 0; len < byte_count; len++){ 250 | read_char = SPIBTLE->transfer(char_ff); 251 | buffer[len] = read_char; 252 | } 253 | 254 | } 255 | } 256 | /* Release CS line */ 257 | digitalWrite(csPin, HIGH); 258 | 259 | // Add a small delay to give time to the BlueNRG to set the IRQ pin low 260 | // to avoid a useless SPI read at the end of the transaction 261 | for(volatile int i = 0; i < 2; i++)__NOP(); 262 | 263 | #ifdef PRINT_CSV_FORMAT 264 | if (len > 0) { 265 | print_csv_time(); 266 | for (int i=0; itransfer(header_master, header_slave, HEADER_SIZE); 304 | 305 | if (header_slave[0] == 0x02) { 306 | /* SPI is ready */ 307 | if (header_slave[1] >= (Nb_bytes1+Nb_bytes2)) { 308 | 309 | /* Buffer is big enough */ 310 | if (Nb_bytes1 > 0) { 311 | SPIBTLE->transfer(data1, read_char_buf, Nb_bytes1); 312 | } 313 | if (Nb_bytes2 > 0) { 314 | SPIBTLE->transfer(data2, read_char_buf, Nb_bytes2); 315 | } 316 | 317 | } else { 318 | /* Buffer is too small */ 319 | result = -2; 320 | } 321 | } else { 322 | /* SPI is not ready */ 323 | result = -1; 324 | } 325 | 326 | /* Release CS line */ 327 | digitalWrite(csPin, HIGH); 328 | 329 | Enable_SPI_IRQ(); 330 | 331 | return result; 332 | } 333 | 334 | /** 335 | * @brief Enable SPI IRQ. 336 | * @param None 337 | * @retval None 338 | */ 339 | void Enable_SPI_IRQ(void) 340 | { 341 | attachInterrupt(spiIRQPin, SPI_EXTI_Callback, RISING); 342 | } 343 | 344 | /** 345 | * @brief Disable SPI IRQ. 346 | * @param None 347 | * @retval None 348 | */ 349 | void Disable_SPI_IRQ(void) 350 | { 351 | detachInterrupt(spiIRQPin); 352 | } 353 | 354 | /** 355 | * @brief Clear EXTI (External Interrupt) line for SPI IRQ. 356 | * @Note This function is kept for compatibility with native source code. 357 | * @param None 358 | * @retval None 359 | */ 360 | void Clear_SPI_EXTI_Flag(void) 361 | { 362 | //Empty function. 363 | } 364 | 365 | /** 366 | * @brief This function allows to attach a HCI callback from a profil. 367 | * @param callback: function pointer of the callback to attach. 368 | * @retval None 369 | */ 370 | void attach_HCI_CB(void (*callback)(void *pckt)) 371 | { 372 | HCI_callback = callback; 373 | } 374 | 375 | /** 376 | * @brief Callback processing the ACI events. 377 | * @note Inside this function each event must be identified and correctly 378 | * parsed. 379 | * @param void* Pointer to the ACI packet 380 | * @retval None 381 | */ 382 | void HCI_Event_CB(void *pckt) 383 | { 384 | HCI_callback(pckt); 385 | } 386 | 387 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 388 | -------------------------------------------------------------------------------- /src/SPBTLE_RF.h: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2017, STMicroelectronics 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | ******************************************************************************* 29 | */ 30 | 31 | #ifndef __SPBTLE_RF_H 32 | #define __SPBTLE_RF_H 33 | 34 | #include "Arduino.h" 35 | #include 36 | 37 | #define IDB04A1 0 38 | #define IDB05A1 1 39 | 40 | #define BDADDR_SIZE 6 41 | 42 | typedef enum { 43 | SPBTLERF_OK = 0, 44 | SPBTLERF_ERROR 45 | } SPBTLERF_state_t; 46 | 47 | typedef enum { 48 | DISABLE_LOW_POWER_MODE = 0, 49 | ENABLE_LOW_POWER_MODE 50 | } lowPowerMode_t; 51 | 52 | void attach_HCI_CB(void (*callback)(void *pckt)); 53 | 54 | class SPBTLERFClass 55 | { 56 | public: 57 | SPBTLERFClass(); 58 | SPBTLERFClass(SPIClass *SPIx, uint8_t csPin, uint8_t spiIRQ, uint8_t reset, uint8_t led = 0xFF); 59 | 60 | SPBTLERF_state_t begin(void); 61 | void end(void); 62 | 63 | void update(void); 64 | }; 65 | 66 | #endif //__SPBTLE_RF_H 67 | -------------------------------------------------------------------------------- /src/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_IFR.c: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | #include "hal.h" 6 | #include "hal_types.h" 7 | #include "ble_status.h" 8 | #include "bluenrg_updater_aci.h" 9 | #include "bluenrg_utils.h" 10 | 11 | /************** Do not change this define section ************/ 12 | 13 | #define BLUENRG_32_MHZ 1 14 | #define BLUENRG_32_MHZ_RO 2 15 | #define BLUENRG_16_MHZ 3 16 | #define BLUENRG_16_MHZ_RO 4 17 | #define BLUENRG_CUSTOM_CONFIG 5 18 | 19 | #define MASTER_SCA_500ppm 0 // 251 ppm to 500 ppm 20 | #define MASTER_SCA_250ppm 1 // 151 ppm to 250 ppm 21 | #define MASTER_SCA_150ppm 2 // 101 ppm to 150 ppm 22 | #define MASTER_SCA_100ppm 3 // 76 ppm to 100 ppm 23 | #define MASTER_SCA_75ppm 4 // 51 ppm to 75 ppm 24 | #define MASTER_SCA_50ppm 5 // 31 ppm to 50 ppm 25 | #define MASTER_SCA_30ppm 6 // 21 ppm to 30 ppm 26 | #define MASTER_SCA_20ppm 7 // 0 ppm to 20 ppm 27 | 28 | #define SMPS_4MHz 0 29 | #define SMPS_8MHz 1 30 | 31 | #ifndef SMPS_FREQUENCY 32 | #define SMPS_FREQUENCY SMPS_4MHz 33 | #endif 34 | 35 | #if !BLUENRG_MS && (SMPS_FREQUENCY == SMPS_8MHz) 36 | #error Unsupported SMPS_FREQUENCY 37 | #endif 38 | 39 | /************************************************************/ 40 | 41 | 42 | /************** Definitions that can be changed. ************/ 43 | 44 | #define STACK_MODE 2 45 | #define SLAVE_SCA_PPM 100 46 | #define MASTER_SCA MASTER_SCA_100ppm 47 | #define HS_STARTUP_TIME_US 800 48 | #define DAY 13 49 | #define MONTH 06 50 | #define YEAR 16 51 | /************************************************************/ 52 | 53 | /* 54 | * IMPORTANT! 55 | * This IFR configurations are only for BlueNRG Firmware v6.4 and 7.x. 56 | */ 57 | 58 | #if BLUENRG_CONFIG == BLUENRG_32_MHZ 59 | 60 | const IFR_config_TypeDef IFR_config = { 61 | #if BLUENRG_MS 62 | #if SMPS_FREQUENCY == SMPS_4MHz 63 | 0x02,0x3A,0x44,0x02, 64 | 0x34,0x5B,0x02,0x39, 65 | 0xA2,0x02,0x3C,0x20, 66 | 0x00,0xFF,0xFF,0xFF, 67 | #elif SMPS_FREQUENCY == SMPS_8MHz 68 | 0x02,0x3A,0x44,0x02, 69 | 0x34,0x5B,0x02,0x39, 70 | 0xAE,0x00,0xFF,0xFF, 71 | 0x00,0xFF,0xFF,0xFF, 72 | #else 73 | #error Incorrect SMPS_FREQUENCY 74 | #endif /* SMPS_FREQUENCY */ 75 | #else 76 | 0x02,0x3A,0x5C,0x02, 77 | 0x39,0xA2,0x02,0x34, 78 | 0x5B,0x00,0xFF,0xFF, 79 | 0xFF,0xFF,0xFF,0xFF, 80 | #endif /* BLUENRG_MS */ 81 | 0xFF,0xFF,0xFF,0xFF, 82 | 0xFF,0xFF,0xFF,0xFF, 83 | 0xFF,0xFF,0xFF,0xFF, 84 | 0xFF,0xFF,0xFF,0xFF, 85 | 0xFF,0xFF,0xFF,0xFF, 86 | 0xFF,0xFF,0xFF,0xFF, 87 | 0xFF,0xFF,0xFF,0xFF, 88 | 0xFF,0xFF,0xFF,0xFF, 89 | 0xFF,0xFF,0xFF,0xFF, 90 | 0xFF,0xFF,0xFF,0xFF, 91 | 0xFF,0xFF,0xFF,0xFF, 92 | 0xFF,0xFF,0xFF,0xFF, 93 | 94 | 0x02,0x1C,0x43,0x02, 95 | 0x20,0xEC,0x02,0x1F, 96 | 0xAF,0x00,0xFF,0xFF, 97 | 0xFF,0xFF,0xFF,0xFF, 98 | 0xFF,0xFF,0xFF,0xFF, 99 | 0xFF,0xFF,0xFF,0xFF, 100 | 0xFF,0xFF,0xFF,0xFF, 101 | 0xFF,0xFF,0xFF,0xFF, 102 | 0xFF,0xFF,0xFF,0xFF, 103 | 0xFF,0xFF,0xFF,0xFF, 104 | 0xFF,0xFF,0xFF,0xFF, 105 | 0xFF,0xFF,0xFF,0xFF, 106 | 0xFF,0xFF,0xFF,0xFF, 107 | 0xFF,0xFF,0xFF,0xFF, 108 | 0xFF,0xFF,0xFF,0xFF, 109 | 0xFF,0xFF,0xFF,0xFF, 110 | 111 | STACK_MODE, 112 | 0xFF,0xFF,0xFF, 113 | 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF, 114 | 0xFFFFFFFF, 115 | htobl(0x00190000), 116 | htobl(0x0028F5C2), 117 | htobs(SLAVE_SCA_PPM), 118 | MASTER_SCA, 119 | 0xFF, 120 | htobs(FROM_US_TO_SYS_TIME(HS_STARTUP_TIME_US)), 121 | 0xFF,0xFF, 122 | 0xFFFFFFFF, 123 | 0xFF, 124 | INT_TO_BCD(YEAR),INT_TO_BCD(MONTH),INT_TO_BCD(DAY), 125 | 0xFFFFFFFF, 126 | 0xFFFFFFFF, 127 | 0xFFFFFFFF, 128 | 0xFFFFFFFF, 129 | 0xFFFFFFFF 130 | }; 131 | 132 | #elif BLUENRG_CONFIG == BLUENRG_32_MHZ_RO 133 | 134 | const IFR_config_TypeDef IFR_config = { 135 | #if BLUENRG_MS 136 | #if SMPS_FREQUENCY == SMPS_4MHz 137 | 0x02,0x3A,0x44,0x02, 138 | 0x34,0x1B,0x02,0x39, 139 | 0xA2,0x02,0x3C,0x20, 140 | 0x00,0xFF,0xFF,0xFF, 141 | #elif SMPS_FREQUENCY == SMPS_8MHz 142 | 0x02,0x3A,0x44,0x02, 143 | 0x34,0x1B,0x02,0x39, 144 | 0xAE,0x00,0xFF,0xFF, 145 | 0x00,0xFF,0xFF,0xFF, 146 | #else 147 | #error Incorrect SMPS_FREQUENCY 148 | #endif /* SMPS_FREQUENCY */ 149 | #else 150 | 0x02,0x3A,0x5C,0x02, 151 | 0x39,0xA2,0x02,0x34, 152 | 0x1B,0x00,0xFF,0xFF, 153 | 0xFF,0xFF,0xFF,0xFF, 154 | #endif /* BLUENRG_MS */ 155 | 0xFF,0xFF,0xFF,0xFF, 156 | 0xFF,0xFF,0xFF,0xFF, 157 | 0xFF,0xFF,0xFF,0xFF, 158 | 0xFF,0xFF,0xFF,0xFF, 159 | 0xFF,0xFF,0xFF,0xFF, 160 | 0xFF,0xFF,0xFF,0xFF, 161 | 0xFF,0xFF,0xFF,0xFF, 162 | 0xFF,0xFF,0xFF,0xFF, 163 | 0xFF,0xFF,0xFF,0xFF, 164 | 0xFF,0xFF,0xFF,0xFF, 165 | 0xFF,0xFF,0xFF,0xFF, 166 | 0xFF,0xFF,0xFF,0xFF, 167 | 168 | 0x02,0x1C,0x43,0x02, 169 | 0x20,0xEC,0x02,0x1F, 170 | 0xAF,0x00,0xFF,0xFF, 171 | 0xFF,0xFF,0xFF,0xFF, 172 | 0xFF,0xFF,0xFF,0xFF, 173 | 0xFF,0xFF,0xFF,0xFF, 174 | 0xFF,0xFF,0xFF,0xFF, 175 | 0xFF,0xFF,0xFF,0xFF, 176 | 0xFF,0xFF,0xFF,0xFF, 177 | 0xFF,0xFF,0xFF,0xFF, 178 | 0xFF,0xFF,0xFF,0xFF, 179 | 0xFF,0xFF,0xFF,0xFF, 180 | 0xFF,0xFF,0xFF,0xFF, 181 | 0xFF,0xFF,0xFF,0xFF, 182 | 0xFF,0xFF,0xFF,0xFF, 183 | 0xFF,0xFF,0xFF,0xFF, 184 | 185 | STACK_MODE, 186 | 0xFF,0xFF,0xFF, 187 | 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF, 188 | 0xFFFFFFFF, 189 | 0xFFFFFFFF, 190 | 0xFFFFFFFF, 191 | htobs(0x01F4), 192 | 0x00, 193 | 0xFF, 194 | htobs(FROM_US_TO_SYS_TIME(HS_STARTUP_TIME_US)), 195 | 0xFF,0xFF, 196 | 0xFFFFFFFF, 197 | 0xFF, 198 | INT_TO_BCD(YEAR),INT_TO_BCD(MONTH),INT_TO_BCD(DAY), 199 | 0xFFFFFFFF, 200 | 0xFFFFFFFF, 201 | 0xFFFFFFFF, 202 | 0xFFFFFFFF, 203 | 0xFFFFFFFF 204 | }; 205 | 206 | #elif BLUENRG_CONFIG == BLUENRG_16_MHZ 207 | 208 | const IFR_config_TypeDef IFR_config = { 209 | #if BLUENRG_MS 210 | #if SMPS_FREQUENCY == SMPS_4MHz 211 | 0x02,0x3A,0x40,0x02, 212 | 0x34,0x5B,0x02,0x39, 213 | 0xA2,0x02,0x3C,0x20, 214 | 0x00,0xFF,0xFF,0xFF, 215 | #elif SMPS_FREQUENCY == SMPS_8MHz 216 | 0x02,0x3A,0x40,0x02, 217 | 0x34,0x5B,0x02,0x39, 218 | 0xAE,0x00,0xFF,0xFF, 219 | 0x00,0xFF,0xFF,0xFF, 220 | #else 221 | #error Incorrect SMPS_FREQUENCY 222 | #endif /* SMPS_FREQUENCY */ 223 | #else 224 | 0x02,0x3A,0x58,0x02, 225 | 0x39,0xA2,0x02,0x34, 226 | 0x5B,0x00,0xFF,0xFF, 227 | 0xFF,0xFF,0xFF,0xFF, 228 | #endif /* BLUENRG_MS */ 229 | 0xFF,0xFF,0xFF,0xFF, 230 | 0xFF,0xFF,0xFF,0xFF, 231 | 0xFF,0xFF,0xFF,0xFF, 232 | 0xFF,0xFF,0xFF,0xFF, 233 | 0xFF,0xFF,0xFF,0xFF, 234 | 0xFF,0xFF,0xFF,0xFF, 235 | 0xFF,0xFF,0xFF,0xFF, 236 | 0xFF,0xFF,0xFF,0xFF, 237 | 0xFF,0xFF,0xFF,0xFF, 238 | 0xFF,0xFF,0xFF,0xFF, 239 | 0xFF,0xFF,0xFF,0xFF, 240 | 0xFF,0xFF,0xFF,0xFF, 241 | 242 | 0x02,0x1C,0x43,0x02, 243 | 0x20,0xEC,0x02,0x1F, 244 | 0xAF,0x00,0xFF,0xFF, 245 | 0xFF,0xFF,0xFF,0xFF, 246 | 0xFF,0xFF,0xFF,0xFF, 247 | 0xFF,0xFF,0xFF,0xFF, 248 | 0xFF,0xFF,0xFF,0xFF, 249 | 0xFF,0xFF,0xFF,0xFF, 250 | 0xFF,0xFF,0xFF,0xFF, 251 | 0xFF,0xFF,0xFF,0xFF, 252 | 0xFF,0xFF,0xFF,0xFF, 253 | 0xFF,0xFF,0xFF,0xFF, 254 | 0xFF,0xFF,0xFF,0xFF, 255 | 0xFF,0xFF,0xFF,0xFF, 256 | 0xFF,0xFF,0xFF,0xFF, 257 | 0xFF,0xFF,0xFF,0xFF, 258 | 259 | STACK_MODE, 260 | 0xFF,0xFF,0xFF, 261 | 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF, 262 | 0xFFFFFFFF, 263 | htobl(0x00190000), 264 | htobl(0x0028F5C2), 265 | htobs(SLAVE_SCA_PPM), 266 | MASTER_SCA, 267 | 0xFF, 268 | htobs(FROM_US_TO_SYS_TIME(HS_STARTUP_TIME_US)), 269 | 0xFF,0xFF, 270 | 0xFFFFFFFF, 271 | 0xFF, 272 | INT_TO_BCD(YEAR),INT_TO_BCD(MONTH),INT_TO_BCD(DAY), 273 | 0xFFFFFFFF, 274 | 0xFFFFFFFF, 275 | 0xFFFFFFFF, 276 | 0xFFFFFFFF, 277 | 0xFFFFFFFF 278 | 279 | }; 280 | 281 | #elif BLUENRG_CONFIG == BLUENRG_16_MHZ_RO 282 | 283 | const IFR_config_TypeDef IFR_config = { 284 | #if BLUENRG_MS 285 | #if SMPS_FREQUENCY == SMPS_4MHz 286 | 0x02,0x3A,0x40,0x02, 287 | 0x34,0x1B,0x02,0x39, 288 | 0xA2,0x02,0x3C,0x20, 289 | 0x00,0xFF,0xFF,0xFF, 290 | #elif SMPS_FREQUENCY == SMPS_8MHz 291 | 0x02,0x3A,0x40,0x02, 292 | 0x34,0x1B,0x02,0x39, 293 | 0xAE,0x00,0xFF,0xFF, 294 | 0x00,0xFF,0xFF,0xFF, 295 | #else 296 | #error Incorrect SMPS_FREQUENCY 297 | #endif /* SMPS_FREQUENCY */ 298 | #else 299 | 0x02,0x3A,0x58,0x02, 300 | 0x39,0xA2,0x02,0x34, 301 | 0x1B,0x00,0xFF,0xFF, 302 | 0xFF,0xFF,0xFF,0xFF, 303 | #endif /* BLUENRG_MS */ 304 | 0xFF,0xFF,0xFF,0xFF, 305 | 0xFF,0xFF,0xFF,0xFF, 306 | 0xFF,0xFF,0xFF,0xFF, 307 | 0xFF,0xFF,0xFF,0xFF, 308 | 0xFF,0xFF,0xFF,0xFF, 309 | 0xFF,0xFF,0xFF,0xFF, 310 | 0xFF,0xFF,0xFF,0xFF, 311 | 0xFF,0xFF,0xFF,0xFF, 312 | 0xFF,0xFF,0xFF,0xFF, 313 | 0xFF,0xFF,0xFF,0xFF, 314 | 0xFF,0xFF,0xFF,0xFF, 315 | 0xFF,0xFF,0xFF,0xFF, 316 | 317 | 0x02,0x1C,0x43,0x02, 318 | 0x20,0xEC,0x02,0x1F, 319 | 0xAF,0x00,0xFF,0xFF, 320 | 0xFF,0xFF,0xFF,0xFF, 321 | 0xFF,0xFF,0xFF,0xFF, 322 | 0xFF,0xFF,0xFF,0xFF, 323 | 0xFF,0xFF,0xFF,0xFF, 324 | 0xFF,0xFF,0xFF,0xFF, 325 | 0xFF,0xFF,0xFF,0xFF, 326 | 0xFF,0xFF,0xFF,0xFF, 327 | 0xFF,0xFF,0xFF,0xFF, 328 | 0xFF,0xFF,0xFF,0xFF, 329 | 0xFF,0xFF,0xFF,0xFF, 330 | 0xFF,0xFF,0xFF,0xFF, 331 | 0xFF,0xFF,0xFF,0xFF, 332 | 0xFF,0xFF,0xFF,0xFF, 333 | 334 | STACK_MODE, 335 | 0xFF,0xFF,0xFF, 336 | 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF, 337 | 0xFFFFFFFF, 338 | 0xFFFFFFFF, 339 | 0xFFFFFFFF, 340 | htobs(0x01F4), 341 | 0x00, 342 | 0xFF, 343 | htobs(FROM_US_TO_SYS_TIME(HS_STARTUP_TIME_US)), 344 | 0xFF,0xFF, 345 | 0xFFFFFFFF, 346 | 0xFF, 347 | INT_TO_BCD(YEAR),INT_TO_BCD(MONTH),INT_TO_BCD(DAY), 348 | 0xFFFFFFFF, 349 | 0xFFFFFFFF, 350 | 0xFFFFFFFF, 351 | 0xFFFFFFFF, 352 | 0xFFFFFFFF 353 | }; 354 | 355 | #elif BLUENRG_CONFIG == BLUENRG_CUSTOM_CONFIG 356 | /* Copy and paste here your custom IFR_config structure. It can be generated 357 | * with BlueNRG GUI. 358 | */ 359 | #else 360 | #warning "BLUENRG_CONFIG not valid. IFR can't be used." 361 | #endif 362 | 363 | #ifdef __cplusplus 364 | } 365 | #endif 366 | -------------------------------------------------------------------------------- /src/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_hal_aci.c: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2013 STMicroelectronics ******************** 2 | * File Name : bluenrg_hci.c 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 4-Oct-2013 6 | * Description : File with HCI commands for BlueNRG FW6.0 and above. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include "hal_types.h" 21 | #include "osal.h" 22 | #include "ble_status.h" 23 | #include "hal.h" 24 | #include "osal.h" 25 | #include "hci_const.h" 26 | #include "bluenrg_aci_const.h" 27 | #include "bluenrg_hal_aci.h" 28 | #include "bluenrg_gatt_server.h" 29 | #include "bluenrg_gap.h" 30 | 31 | #define MIN(a,b) ((a) < (b) )? (a) : (b) 32 | #define MAX(a,b) ((a) > (b) )? (a) : (b) 33 | 34 | tBleStatus aci_hal_get_fw_build_number(uint16_t *build_number) 35 | { 36 | struct hci_request rq; 37 | hal_get_fw_build_number_rp rp; 38 | 39 | Osal_MemSet(&rq, 0, sizeof(rq)); 40 | rq.ogf = OGF_VENDOR_CMD; 41 | rq.ocf = OCF_HAL_GET_FW_BUILD_NUMBER; 42 | rq.rparam = &rp; 43 | rq.rlen = sizeof(rp); 44 | 45 | if (hci_send_req(&rq, FALSE) < 0) 46 | return BLE_STATUS_TIMEOUT; 47 | 48 | if(rp.status) 49 | return rp.status; 50 | 51 | *build_number = rp.build_number; 52 | 53 | return 0; 54 | } 55 | 56 | tBleStatus aci_hal_write_config_data(uint8_t offset, 57 | uint8_t len, 58 | const uint8_t *val) 59 | { 60 | struct hci_request rq; 61 | uint8_t status; 62 | uint8_t buffer[HCI_MAX_PAYLOAD_SIZE]; 63 | uint8_t indx = 0; 64 | 65 | if ((len+2) > HCI_MAX_PAYLOAD_SIZE) 66 | return BLE_STATUS_INVALID_PARAMS; 67 | 68 | buffer[indx] = offset; 69 | indx++; 70 | 71 | buffer[indx] = len; 72 | indx++; 73 | 74 | Osal_MemCpy(buffer + indx, val, len); 75 | indx += len; 76 | 77 | Osal_MemSet(&rq, 0, sizeof(rq)); 78 | rq.ogf = OGF_VENDOR_CMD; 79 | rq.ocf = OCF_HAL_WRITE_CONFIG_DATA; 80 | rq.cparam = (void *)buffer; 81 | rq.clen = indx; 82 | rq.rparam = &status; 83 | rq.rlen = 1; 84 | 85 | if (hci_send_req(&rq, FALSE) < 0) 86 | return BLE_STATUS_TIMEOUT; 87 | 88 | return status; 89 | } 90 | 91 | tBleStatus aci_hal_read_config_data(uint8_t offset, uint16_t data_len, uint8_t *data_len_out_p, uint8_t *data) 92 | { 93 | struct hci_request rq; 94 | hal_read_config_data_cp cp; 95 | hal_read_config_data_rp rp; 96 | 97 | cp.offset = offset; 98 | 99 | Osal_MemSet(&rq, 0, sizeof(rq)); 100 | rq.ogf = OGF_VENDOR_CMD; 101 | rq.ocf = OCF_HAL_READ_CONFIG_DATA; 102 | rq.cparam = &cp; 103 | rq.clen = sizeof(cp); 104 | rq.rparam = &rp; 105 | rq.rlen = sizeof(rp); 106 | 107 | if (hci_send_req(&rq, FALSE) < 0) 108 | return BLE_STATUS_TIMEOUT; 109 | 110 | if(rp.status) 111 | return rp.status; 112 | 113 | *data_len_out_p = rq.rlen-1; 114 | 115 | Osal_MemCpy(data, rp.data, MIN(data_len, *data_len_out_p)); 116 | 117 | return 0; 118 | } 119 | 120 | tBleStatus aci_hal_set_tx_power_level(uint8_t en_high_power, uint8_t pa_level) 121 | { 122 | struct hci_request rq; 123 | hal_set_tx_power_level_cp cp; 124 | uint8_t status; 125 | 126 | cp.en_high_power = en_high_power; 127 | cp.pa_level = pa_level; 128 | 129 | Osal_MemSet(&rq, 0, sizeof(rq)); 130 | rq.ogf = OGF_VENDOR_CMD; 131 | rq.ocf = OCF_HAL_SET_TX_POWER_LEVEL; 132 | rq.cparam = &cp; 133 | rq.clen = HAL_SET_TX_POWER_LEVEL_CP_SIZE; 134 | rq.rparam = &status; 135 | rq.rlen = 1; 136 | 137 | if (hci_send_req(&rq, FALSE) < 0) 138 | return BLE_STATUS_TIMEOUT; 139 | 140 | return status; 141 | } 142 | 143 | tBleStatus aci_hal_le_tx_test_packet_number(uint32_t *number_of_packets) 144 | { 145 | struct hci_request rq; 146 | hal_le_tx_test_packet_number_rp resp; 147 | 148 | Osal_MemSet(&rq, 0, sizeof(rq)); 149 | rq.ogf = OGF_VENDOR_CMD; 150 | rq.ocf = OCF_HAL_LE_TX_TEST_PACKET_NUMBER; 151 | rq.rparam = &resp; 152 | rq.rlen = sizeof(resp); 153 | 154 | if (hci_send_req(&rq, FALSE) < 0) 155 | return BLE_STATUS_TIMEOUT; 156 | 157 | if (resp.status) { 158 | return resp.status; 159 | } 160 | 161 | *number_of_packets = btohl(resp.number_of_packets); 162 | 163 | return 0; 164 | } 165 | 166 | tBleStatus aci_hal_device_standby(void) 167 | { 168 | struct hci_request rq; 169 | uint8_t status; 170 | 171 | Osal_MemSet(&rq, 0, sizeof(rq)); 172 | rq.ogf = OGF_VENDOR_CMD; 173 | rq.ocf = OCF_HAL_DEVICE_STANDBY; 174 | rq.rparam = &status; 175 | rq.rlen = 1; 176 | 177 | if (hci_send_req(&rq, FALSE) < 0) 178 | return BLE_STATUS_TIMEOUT; 179 | 180 | return status; 181 | } 182 | 183 | tBleStatus aci_hal_tone_start(uint8_t rf_channel) 184 | { 185 | struct hci_request rq; 186 | hal_tone_start_cp cp; 187 | uint8_t status; 188 | 189 | cp.rf_channel = rf_channel; 190 | 191 | Osal_MemSet(&rq, 0, sizeof(rq)); 192 | rq.ogf = OGF_VENDOR_CMD; 193 | rq.ocf = OCF_HAL_TONE_START; 194 | rq.cparam = &cp; 195 | rq.clen = HAL_TONE_START_CP_SIZE; 196 | rq.rparam = &status; 197 | rq.rlen = 1; 198 | 199 | if (hci_send_req(&rq, FALSE) < 0) 200 | return BLE_STATUS_TIMEOUT; 201 | 202 | return status; 203 | } 204 | 205 | tBleStatus aci_hal_tone_stop(void) 206 | { 207 | struct hci_request rq; 208 | uint8_t status; 209 | 210 | Osal_MemSet(&rq, 0, sizeof(rq)); 211 | rq.ogf = OGF_VENDOR_CMD; 212 | rq.ocf = OCF_HAL_TONE_STOP; 213 | rq.rparam = &status; 214 | rq.rlen = 1; 215 | 216 | if (hci_send_req(&rq, FALSE) < 0) 217 | return BLE_STATUS_TIMEOUT; 218 | 219 | return status; 220 | } 221 | 222 | tBleStatus aci_hal_get_link_status(uint8_t link_status[8], uint16_t conn_handle[8]) 223 | { 224 | struct hci_request rq; 225 | hal_get_link_status_rp rp; 226 | 227 | Osal_MemSet(&rq, 0, sizeof(rq)); 228 | rq.ogf = OGF_VENDOR_CMD; 229 | rq.ocf = OCF_HAL_GET_LINK_STATUS; 230 | rq.rparam = &rp; 231 | rq.rlen = sizeof(rp); 232 | 233 | if (hci_send_req(&rq, FALSE) < 0) 234 | return BLE_STATUS_TIMEOUT; 235 | 236 | if(rp.status) 237 | return rp.status; 238 | 239 | Osal_MemCpy(link_status,rp.link_status,8); 240 | for(int i = 0; i < 8; i++) 241 | conn_handle[i] = btohs(rp.conn_handle[i]); 242 | 243 | return 0; 244 | } 245 | 246 | tBleStatus aci_hal_get_anchor_period(uint32_t *anchor_period, uint32_t *max_free_slot) 247 | { 248 | struct hci_request rq; 249 | hal_get_anchor_period_rp rp; 250 | 251 | Osal_MemSet(&rq, 0, sizeof(rq)); 252 | rq.ogf = OGF_VENDOR_CMD; 253 | rq.ocf = OCF_HAL_GET_ANCHOR_PERIOD; 254 | rq.rparam = &rp; 255 | rq.rlen = sizeof(rp); 256 | 257 | if (hci_send_req(&rq, FALSE) < 0) 258 | return BLE_STATUS_TIMEOUT; 259 | 260 | if(rp.status) 261 | return rp.status; 262 | 263 | *anchor_period = btohl(rp.anchor_period); 264 | *max_free_slot = btohl(rp.max_free_slot); 265 | 266 | return 0; 267 | } 268 | 269 | #ifdef __cplusplus 270 | } 271 | #endif 272 | -------------------------------------------------------------------------------- /src/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_l2cap_aci.c: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2013 STMicroelectronics ******************** 2 | * File Name : bluenrg_hci.c 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 4-Oct-2013 6 | * Description : File with HCI commands for BlueNRG FW6.0 and above. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include "hal_types.h" 21 | #include "osal.h" 22 | #include "ble_status.h" 23 | #include "hal.h" 24 | #include "osal.h" 25 | #include "hci_const.h" 26 | #include "bluenrg_aci_const.h" 27 | #include "bluenrg_hal_aci.h" 28 | #include "bluenrg_gap.h" 29 | 30 | #define MIN(a,b) ((a) < (b) )? (a) : (b) 31 | #define MAX(a,b) ((a) > (b) )? (a) : (b) 32 | 33 | tBleStatus aci_l2cap_connection_parameter_update_request(uint16_t conn_handle, uint16_t interval_min, 34 | uint16_t interval_max, uint16_t slave_latency, 35 | uint16_t timeout_multiplier) 36 | { 37 | struct hci_request rq; 38 | uint8_t status; 39 | l2cap_conn_param_update_req_cp cp; 40 | 41 | cp.conn_handle = htobs(conn_handle); 42 | cp.interval_min = htobs(interval_min); 43 | cp.interval_max = htobs(interval_max); 44 | cp.slave_latency = htobs(slave_latency); 45 | cp.timeout_multiplier = htobs(timeout_multiplier); 46 | 47 | Osal_MemSet(&rq, 0, sizeof(rq)); 48 | rq.ogf = OGF_VENDOR_CMD; 49 | rq.ocf = OCF_L2CAP_CONN_PARAM_UPDATE_REQ; 50 | rq.cparam = &cp; 51 | rq.clen = L2CAP_CONN_PARAM_UPDATE_REQ_CP_SIZE; 52 | rq.event = EVT_CMD_STATUS; 53 | rq.rparam = &status; 54 | rq.rlen = 1; 55 | 56 | if (hci_send_req(&rq, FALSE) < 0) 57 | return BLE_STATUS_TIMEOUT; 58 | 59 | return status; 60 | } 61 | 62 | tBleStatus aci_l2cap_connection_parameter_update_response_IDB05A1(uint16_t conn_handle, uint16_t interval_min, 63 | uint16_t interval_max, uint16_t slave_latency, 64 | uint16_t timeout_multiplier, uint16_t min_ce_length, uint16_t max_ce_length, 65 | uint8_t id, uint8_t accept) 66 | { 67 | struct hci_request rq; 68 | uint8_t status; 69 | l2cap_conn_param_update_resp_cp_IDB05A1 cp; 70 | 71 | cp.conn_handle = htobs(conn_handle); 72 | cp.interval_min = htobs(interval_min); 73 | cp.interval_max = htobs(interval_max); 74 | cp.slave_latency = htobs(slave_latency); 75 | cp.timeout_multiplier = htobs(timeout_multiplier); 76 | cp.min_ce_length = htobs(min_ce_length); 77 | cp.max_ce_length = htobs(max_ce_length); 78 | cp.id = id; 79 | cp.accept = accept; 80 | 81 | Osal_MemSet(&rq, 0, sizeof(rq)); 82 | rq.ogf = OGF_VENDOR_CMD; 83 | rq.ocf = OCF_L2CAP_CONN_PARAM_UPDATE_RESP; 84 | rq.cparam = &cp; 85 | rq.clen = sizeof(cp); 86 | rq.rparam = &status; 87 | rq.rlen = 1; 88 | 89 | if (hci_send_req(&rq, FALSE) < 0) 90 | return BLE_STATUS_TIMEOUT; 91 | 92 | return status; 93 | } 94 | 95 | tBleStatus aci_l2cap_connection_parameter_update_response_IDB04A1(uint16_t conn_handle, uint16_t interval_min, 96 | uint16_t interval_max, uint16_t slave_latency, 97 | uint16_t timeout_multiplier, uint8_t id, uint8_t accept) 98 | { 99 | struct hci_request rq; 100 | uint8_t status; 101 | l2cap_conn_param_update_resp_cp_IDB04A1 cp; 102 | 103 | cp.conn_handle = htobs(conn_handle); 104 | cp.interval_min = htobs(interval_min); 105 | cp.interval_max = htobs(interval_max); 106 | cp.slave_latency = htobs(slave_latency); 107 | cp.timeout_multiplier = htobs(timeout_multiplier); 108 | cp.id = id; 109 | cp.accept = accept; 110 | 111 | Osal_MemSet(&rq, 0, sizeof(rq)); 112 | rq.ogf = OGF_VENDOR_CMD; 113 | rq.ocf = OCF_L2CAP_CONN_PARAM_UPDATE_RESP; 114 | rq.cparam = &cp; 115 | rq.clen = sizeof(cp); 116 | rq.rparam = &status; 117 | rq.rlen = 1; 118 | 119 | if (hci_send_req(&rq, FALSE) < 0) 120 | return BLE_STATUS_TIMEOUT; 121 | 122 | return status; 123 | } 124 | 125 | #ifdef __cplusplus 126 | } 127 | #endif 128 | -------------------------------------------------------------------------------- /src/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_updater_aci.c: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2013 STMicroelectronics ******************** 2 | * File Name : bluenrg_hci.c 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 4-Oct-2013 6 | * Description : File with HCI commands for BlueNRG FW6.0 and above. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include "hal_types.h" 21 | #include "osal.h" 22 | #include "ble_status.h" 23 | #include "hal.h" 24 | #include "osal.h" 25 | #include "hci_const.h" 26 | #include "bluenrg_aci_const.h" 27 | #include "bluenrg_updater_aci.h" 28 | 29 | #define MIN(a,b) ((a) < (b) )? (a) : (b) 30 | #define MAX(a,b) ((a) > (b) )? (a) : (b) 31 | 32 | tBleStatus aci_updater_start(void) 33 | { 34 | struct hci_request rq; 35 | uint8_t status = 0; 36 | 37 | Osal_MemSet(&rq, 0, sizeof(rq)); 38 | rq.ogf = OGF_VENDOR_CMD; 39 | rq.ocf = OCF_UPDATER_START; 40 | rq.rparam = &status; 41 | rq.rlen = 1; 42 | 43 | hci_send_req(&rq, FALSE); // No command complete is sent. 44 | 45 | return status; 46 | } 47 | 48 | tBleStatus aci_updater_reboot(void) 49 | { 50 | struct hci_request rq; 51 | uint8_t status = 0; 52 | 53 | Osal_MemSet(&rq, 0, sizeof(rq)); 54 | rq.ogf = OGF_VENDOR_CMD; 55 | rq.ocf = OCF_UPDATER_REBOOT; 56 | rq.rparam = &status; 57 | rq.rlen = 1; 58 | 59 | hci_send_req(&rq, FALSE); // No command complete is sent. 60 | 61 | return status; 62 | } 63 | 64 | tBleStatus aci_get_updater_version(uint8_t *version) 65 | { 66 | struct hci_request rq; 67 | get_updater_version_rp resp; 68 | 69 | Osal_MemSet(&resp, 0, sizeof(resp)); 70 | 71 | Osal_MemSet(&rq, 0, sizeof(rq)); 72 | rq.ogf = OGF_VENDOR_CMD; 73 | rq.ocf = OCF_GET_UPDATER_VERSION; 74 | rq.rparam = &resp; 75 | rq.rlen = GET_UPDATER_VERSION_RP_SIZE; 76 | 77 | if (hci_send_req(&rq, FALSE) < 0) 78 | return BLE_STATUS_TIMEOUT; 79 | 80 | *version = resp.version; 81 | 82 | return resp.status; 83 | } 84 | 85 | tBleStatus aci_get_updater_buffer_size(uint8_t *buffer_size) 86 | { 87 | struct hci_request rq; 88 | get_updater_bufsize_rp resp; 89 | 90 | Osal_MemSet(&resp, 0, sizeof(resp)); 91 | 92 | Osal_MemSet(&rq, 0, sizeof(rq)); 93 | rq.ogf = OGF_VENDOR_CMD; 94 | rq.ocf = OCF_GET_UPDATER_BUFSIZE; 95 | rq.rparam = &resp; 96 | rq.rlen = GET_UPDATER_BUFSIZE_RP_SIZE; 97 | 98 | if (hci_send_req(&rq, FALSE) < 0) 99 | return BLE_STATUS_TIMEOUT; 100 | 101 | *buffer_size = resp.buffer_size; 102 | 103 | return resp.status; 104 | } 105 | 106 | tBleStatus aci_erase_blue_flag(void) 107 | { 108 | struct hci_request rq; 109 | uint8_t status; 110 | 111 | Osal_MemSet(&rq, 0, sizeof(rq)); 112 | rq.ogf = OGF_VENDOR_CMD; 113 | rq.ocf = OCF_UPDATER_ERASE_BLUE_FLAG; 114 | rq.rparam = &status; 115 | rq.rlen = 1; 116 | 117 | if (hci_send_req(&rq, FALSE) < 0) 118 | return BLE_STATUS_TIMEOUT; 119 | 120 | return status; 121 | } 122 | 123 | tBleStatus aci_reset_blue_flag(void) 124 | { 125 | struct hci_request rq; 126 | uint8_t status; 127 | 128 | Osal_MemSet(&rq, 0, sizeof(rq)); 129 | rq.ogf = OGF_VENDOR_CMD; 130 | rq.ocf = OCF_UPDATER_RESET_BLUE_FLAG; 131 | rq.rparam = &status; 132 | rq.rlen = 1; 133 | 134 | if (hci_send_req(&rq, FALSE) < 0) 135 | return BLE_STATUS_TIMEOUT; 136 | 137 | return status; 138 | } 139 | 140 | tBleStatus aci_updater_erase_sector(uint32_t address) 141 | { 142 | struct hci_request rq; 143 | updater_erase_sector_cp cp; 144 | uint8_t status; 145 | 146 | cp.address = htobl(address); 147 | 148 | Osal_MemSet(&rq, 0, sizeof(rq)); 149 | rq.ogf = OGF_VENDOR_CMD; 150 | rq.ocf = OCF_UPDATER_ERASE_SECTOR; 151 | rq.cparam = &cp; 152 | rq.clen = UPDATER_ERASE_SECTOR_CP_SIZE; 153 | rq.rparam = &status; 154 | rq.rlen = 1; 155 | 156 | if (hci_send_req(&rq, FALSE) < 0) 157 | return BLE_STATUS_TIMEOUT; 158 | 159 | return status; 160 | } 161 | 162 | tBleStatus aci_updater_program_data_block(uint32_t address, 163 | uint16_t len, 164 | const uint8_t *data) 165 | { 166 | struct hci_request rq; 167 | uint8_t status; 168 | updater_prog_data_block_cp cp; 169 | 170 | if( len > sizeof(cp.data)) 171 | return BLE_STATUS_INVALID_PARAMS; 172 | 173 | cp.address = htobl(address); 174 | cp.data_len = htobs(len); 175 | Osal_MemCpy(cp.data, data, len); 176 | 177 | Osal_MemSet(&rq, 0, sizeof(rq)); 178 | rq.ogf = OGF_VENDOR_CMD; 179 | rq.ocf = OCF_UPDATER_PROG_DATA_BLOCK; 180 | rq.cparam = &cp; 181 | rq.clen = UPDATER_PROG_DATA_BLOCK_CP_SIZE+len; 182 | rq.rparam = &status; 183 | rq.rlen = 1; 184 | 185 | if (hci_send_req(&rq, FALSE) < 0) 186 | return BLE_STATUS_TIMEOUT; 187 | 188 | return status; 189 | } 190 | 191 | tBleStatus aci_updater_read_data_block(uint32_t address, 192 | uint16_t data_len, 193 | uint8_t *data) 194 | { 195 | struct hci_request rq; 196 | updater_read_data_block_cp cp; 197 | uint8_t buffer[HCI_MAX_PAYLOAD_SIZE]; 198 | 199 | if((data_len+1) > HCI_MAX_PAYLOAD_SIZE) 200 | return BLE_STATUS_INVALID_PARAMS; 201 | 202 | cp.address = htobl(address); 203 | cp.data_len = htobs(data_len); 204 | 205 | Osal_MemSet(&rq, 0, sizeof(rq)); 206 | rq.ogf = OGF_VENDOR_CMD; 207 | rq.ocf = OCF_UPDATER_READ_DATA_BLOCK; 208 | rq.cparam = &cp; 209 | rq.clen = UPDATER_READ_DATA_BLOCK_CP_SIZE; 210 | rq.rparam = buffer; 211 | rq.rlen = data_len + 1; 212 | 213 | if (hci_send_req(&rq, FALSE) < 0) 214 | return BLE_STATUS_TIMEOUT; 215 | 216 | // First byte is status 217 | Osal_MemCpy(data, buffer+1, data_len); 218 | 219 | return buffer[0]; 220 | } 221 | 222 | tBleStatus aci_updater_calc_crc(uint32_t address, 223 | uint8_t num_sectors, 224 | uint32_t *crc) 225 | { 226 | struct hci_request rq; 227 | updater_calc_crc_cp cp; 228 | updater_calc_crc_rp resp; 229 | 230 | Osal_MemSet(&resp, 0, sizeof(resp)); 231 | 232 | cp.address = htobl(address); 233 | cp.num_sectors = num_sectors; 234 | 235 | Osal_MemSet(&rq, 0, sizeof(rq)); 236 | rq.ogf = OGF_VENDOR_CMD; 237 | rq.ocf = OCF_UPDATER_CALC_CRC; 238 | rq.cparam = &cp; 239 | rq.clen = UPDATER_CALC_CRC_CP_SIZE; 240 | rq.rparam = &resp; 241 | rq.rlen = UPDATER_CALC_CRC_RP_SIZE; 242 | 243 | if (hci_send_req(&rq, FALSE) < 0) 244 | return BLE_STATUS_TIMEOUT; 245 | 246 | *crc = btohl(resp.crc); 247 | 248 | return resp.status; 249 | } 250 | 251 | tBleStatus aci_updater_hw_version(uint8_t *version) 252 | { 253 | struct hci_request rq; 254 | updater_hw_version_rp resp; 255 | 256 | Osal_MemSet(&resp, 0, sizeof(resp)); 257 | 258 | Osal_MemSet(&rq, 0, sizeof(rq)); 259 | rq.ogf = OGF_VENDOR_CMD; 260 | rq.ocf = OCF_UPDATER_HW_VERSION; 261 | rq.rparam = &resp; 262 | rq.rlen = UPDATER_HW_VERSION_RP_SIZE; 263 | 264 | if (hci_send_req(&rq, FALSE) < 0) 265 | return BLE_STATUS_TIMEOUT; 266 | 267 | *version = resp.version; 268 | 269 | return resp.status; 270 | } 271 | 272 | #ifdef __cplusplus 273 | } 274 | #endif 275 | -------------------------------------------------------------------------------- /src/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/controller/bluenrg_utils.c: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | #include "hal.h" 6 | #include "hal_types.h" 7 | #include "ble_status.h" 8 | #include "bluenrg_aci.h" 9 | #include "bluenrg_utils.h" 10 | #include "hci.h" 11 | #include "hci_le.h" 12 | #include "osal.h" 13 | #include "string.h" 14 | #include "stm32_bluenrg_ble.h" 15 | 16 | #define SUPPORTED_BOOTLOADER_VERSION_MIN 3 17 | #define SUPPORTED_BOOTLOADER_VERSION_MAX 5 18 | 19 | #define BASE_ADDRESS 0x10010000 20 | 21 | #define FW_OFFSET (2*1024) // 2 KB 22 | #define FW_OFFSET_MS 0 23 | #define FULL_STACK_SIZE (66*1024) // 66 KB 24 | #define BOOTLOADER_SIZE (2*1024) // 2 kB 25 | #define SECTOR_SIZE (2*1024) // 2 KB 26 | 27 | // x**32 + x**26 + x**23 + x ** 22 + x**16 + x**12 + x**11 + 28 | // x**10 + x**8 + x**7 + x**5 + x**4 + x**2 + x**1 + x**0 29 | #define CRC_POLY 0x04C11DB7 // the poly without the x**32 30 | 31 | #define BOOTLOADER_CRC_NOT_PATCHED 0x878FB3FC 32 | 33 | #define IFR_SIZE 192 34 | #define IFR_BASE_ADDRESS 0x10020000 35 | #define IFR_CONFIG_DATA_OFFSET (SECTOR_SIZE-IFR_SIZE) // Offset in IFR sector containing configuration data 36 | 37 | #if BLUENRG_MS 38 | #define IFR_WRITE_OFFSET_BEGIN IFR_CONFIG_DATA_OFFSET 39 | #else 40 | #define IFR_WRITE_OFFSET_BEGIN 0 41 | #endif 42 | 43 | 44 | #define BLUE_FLAG_OFFSET 0x8C0 45 | #define MAX_ERASE_RETRIES 2 46 | #define MAX_WRITE_RETRIES 2 47 | #define MIN_WRITE_BLOCK_SIZE 4 48 | #define MAX_WRITE_BLOCK_SIZE 64 // 64 bytes 49 | #define READ_BLOCK_SIZE 64 // 64 bytes 50 | 51 | #define RETRY_COMMAND(func, num_ret, error) \ 52 | { \ 53 | uint8_t num_retries; \ 54 | num_retries = 0; \ 55 | error = 0; \ 56 | while (num_retries++ < num_ret) { \ 57 | if (func == BLE_STATUS_SUCCESS) \ 58 | break; \ 59 | if (num_retries == num_ret) \ 60 | error = BLE_UTIL_ACI_ERROR; \ 61 | } \ 62 | } 63 | 64 | #define MIN(a,b) (((a)<(b))?(a):(b)) 65 | 66 | /* This function calculates the CRC of a sector of flash, if bytes passed are less than sector size, 67 | they are extended with 0xFF until sector size is reached 68 | */ 69 | static uint32_t updater_calc_crc(const uint8_t* data, uint16_t nr_of_bytes) 70 | { 71 | uint32_t i, j, a1; 72 | uint32_t crc, value; 73 | 74 | crc = 0; 75 | for (i = 0; i < SECTOR_SIZE; i += 4) { 76 | uint8_t *dataw = (uint8_t *) &value; 77 | 78 | dataw[0] = (i < nr_of_bytes) ? data[i] : 0xFF; 79 | dataw[1] = ((i + 1) < nr_of_bytes) ? data[i+1] : 0xFF; 80 | dataw[2] = ((i + 2) < nr_of_bytes) ? data[i+2] : 0xFF; 81 | dataw[3] = ((i + 3) < nr_of_bytes) ? data[i+3] : 0xFF; 82 | 83 | crc = crc ^ value; 84 | for (j = 0; j < 32; j ++) { 85 | a1 = (crc >> 31) & 0x1; 86 | crc = (crc << 1) ^ (a1 * CRC_POLY); 87 | } 88 | } 89 | 90 | return crc; 91 | } 92 | 93 | int program_device(const uint8_t *fw_image, uint32_t fw_size) 94 | { 95 | uint8_t version, num_erase_retries, status, write_block_size; 96 | uint32_t address; 97 | uint32_t crc, crc2, crc_size; 98 | uint32_t fw_offset = FW_OFFSET; 99 | 100 | BlueNRG_HW_Bootloader(); 101 | HCI_Process(); // To receive the EVT_INITIALIZED 102 | 103 | if(aci_get_updater_version(&version)) 104 | return BLE_UTIL_ACI_ERROR; 105 | 106 | if(version < SUPPORTED_BOOTLOADER_VERSION_MIN || version > SUPPORTED_BOOTLOADER_VERSION_MAX) 107 | return BLE_UTIL_UNSUPPORTED_VERSION; 108 | 109 | if(aci_updater_hw_version(&version)) 110 | return BLE_UTIL_ACI_ERROR; 111 | 112 | if(version==0x31){ 113 | // It does not contain bootloader inside first sector. It may contain code. 114 | fw_offset = FW_OFFSET_MS; 115 | } 116 | 117 | if (fw_size != FULL_STACK_SIZE) 118 | return BLE_UTIL_WRONG_IMAGE_SIZE; 119 | 120 | if (fw_size % MIN_WRITE_BLOCK_SIZE) 121 | return BLE_UTIL_WRONG_IMAGE_SIZE; 122 | 123 | /*********************************************************************** 124 | * Erase BLUE flag 125 | ************************************************************************/ 126 | RETRY_COMMAND(aci_erase_blue_flag(), MAX_WRITE_RETRIES, status); 127 | if (status != BLE_STATUS_SUCCESS) 128 | return status; 129 | 130 | /*********************************************************************** 131 | * Erase and Program sectors 132 | ************************************************************************/ 133 | for(uint32_t i = fw_offset; i < fw_size; i += SECTOR_SIZE) { 134 | num_erase_retries = 0; 135 | while (num_erase_retries++ < MAX_ERASE_RETRIES) { 136 | aci_updater_erase_sector(BASE_ADDRESS + i); 137 | for (uint32_t j=i; ((j SUPPORTED_BOOTLOADER_VERSION_MAX) 191 | return BLE_UTIL_UNSUPPORTED_VERSION; 192 | 193 | /*********************************************************************** 194 | * Reading last 3 IFR 64-byte blocks 195 | ************************************************************************/ 196 | for(int i = (FULL_STACK_SIZE - IFR_SIZE); i < FULL_STACK_SIZE; i += READ_BLOCK_SIZE){ 197 | ret = aci_updater_read_data_block(BASE_ADDRESS+i, READ_BLOCK_SIZE, (data+offset)); 198 | offset += READ_BLOCK_SIZE; 199 | if(ret) return BLE_UTIL_ACI_ERROR; 200 | } 201 | 202 | BlueNRG_RST(); 203 | HCI_Process(); // To receive the EVT_INITIALIZED 204 | 205 | return BLE_STATUS_SUCCESS; 206 | 207 | } 208 | 209 | void parse_IFR_data_config(const uint8_t data[64], IFR_config2_TypeDef *IFR_config) 210 | { 211 | IFR_config->stack_mode = data[0]; 212 | IFR_config->slave_sca_ppm = LE_TO_HOST_16(data+28); 213 | IFR_config->master_sca = data[30]; 214 | IFR_config->hs_startup_time = LE_TO_HOST_16(data+32); 215 | IFR_config->year = BCD_TO_INT(data[41]); 216 | IFR_config->month = BCD_TO_INT(data[42]); 217 | IFR_config->day = BCD_TO_INT(data[43]); 218 | } 219 | 220 | int IFR_validate(IFR_config2_TypeDef *IFR_config) 221 | { 222 | #if BLUENRG_MS 223 | if(IFR_config->stack_mode < 1 || IFR_config->stack_mode > 4) 224 | #else 225 | if(IFR_config->stack_mode < 1 || IFR_config->stack_mode > 3) 226 | #endif 227 | return BLE_UTIL_PARSE_ERROR; // Unknown Stack Mode 228 | if(IFR_config->master_sca > 7) 229 | return BLE_UTIL_PARSE_ERROR; // Invalid Master SCA 230 | if(IFR_config->month > 12 || IFR_config->month < 1) 231 | return BLE_UTIL_PARSE_ERROR; // Invalid date 232 | if(IFR_config->day > 31 || IFR_config->day < 1) 233 | return BLE_UTIL_PARSE_ERROR; // Invalid date 234 | if(IFR_config->month > 12 || IFR_config->month < 1) 235 | return BLE_UTIL_PARSE_ERROR; // Invalid date 236 | 237 | return BLE_STATUS_SUCCESS; 238 | } 239 | 240 | /* TODO: Function to generate data from given options. */ 241 | 242 | void change_IFR_data_config(IFR_config2_TypeDef *IFR_config, uint8_t data[64]) 243 | { 244 | data[0] = IFR_config->stack_mode; 245 | HOST_TO_LE_16(data+28, IFR_config->slave_sca_ppm); 246 | data[30] = IFR_config->master_sca; 247 | HOST_TO_LE_16(data+32, IFR_config->hs_startup_time); 248 | data[41] = INT_TO_BCD(IFR_config->year); 249 | data[42] = INT_TO_BCD(IFR_config->month); 250 | data[43] = INT_TO_BCD(IFR_config->day); 251 | } 252 | 253 | 254 | int program_IFR(const IFR_config_TypeDef *ifr_image) 255 | { 256 | uint8_t version, num_erase_retries; 257 | tBleStatus ret; 258 | #if BLUENRG_MS 259 | const uint8_t *ifr_data = (uint8_t *)ifr_image; 260 | #else 261 | uint8_t ifr_data[SECTOR_SIZE]; 262 | #endif 263 | uint8_t hwVersion; 264 | uint16_t fwVersion; 265 | 266 | if(getBlueNRGVersion(&hwVersion, &fwVersion)) 267 | return BLE_UTIL_ACI_ERROR; 268 | 269 | BlueNRG_HW_Bootloader(); 270 | HCI_Process(); // To receive the EVT_INITIALIZED 271 | 272 | if(aci_get_updater_version(&version)) 273 | return BLE_UTIL_ACI_ERROR; 274 | 275 | if(version < SUPPORTED_BOOTLOADER_VERSION_MIN || version > SUPPORTED_BOOTLOADER_VERSION_MAX) 276 | return BLE_UTIL_UNSUPPORTED_VERSION; 277 | 278 | #ifndef BLUENRG_MS 279 | /*********************************************************************** 280 | * READ IFR data 281 | ************************************************************************/ 282 | for(int i = 0; i < SECTOR_SIZE; i += READ_BLOCK_SIZE){ 283 | ret = aci_updater_read_data_block(IFR_BASE_ADDRESS+i, READ_BLOCK_SIZE, ifr_data+i); 284 | if(ret != BLE_STATUS_SUCCESS){ 285 | return ret; 286 | } 287 | } 288 | #endif 289 | 290 | /*********************************************************************** 291 | * Erase & Flashing IFR sectors 292 | ************************************************************************/ 293 | #ifndef BLUENRG_MS 294 | Osal_MemCpy(&ifr_data[SECTOR_SIZE-IFR_SIZE], ifr_image, IFR_SIZE); 295 | #endif 296 | num_erase_retries = 0; 297 | while (num_erase_retries++ < MAX_ERASE_RETRIES) { 298 | aci_updater_erase_sector(IFR_BASE_ADDRESS); 299 | for(int i = IFR_WRITE_OFFSET_BEGIN, j = 0; i < SECTOR_SIZE; i += MAX_WRITE_BLOCK_SIZE, j += MAX_WRITE_BLOCK_SIZE) { 300 | RETRY_COMMAND(aci_updater_program_data_block(IFR_BASE_ADDRESS+i, MAX_WRITE_BLOCK_SIZE, ifr_data+j), MAX_WRITE_RETRIES, ret); 301 | if (ret != BLE_STATUS_SUCCESS) 302 | break; 303 | } 304 | if (ret == BLE_STATUS_SUCCESS) 305 | break; 306 | } 307 | if (num_erase_retries == MAX_ERASE_RETRIES) 308 | return BLE_UTIL_ACI_ERROR; 309 | 310 | /*********************************************************************** 311 | * Verify IFR 312 | ************************************************************************/ 313 | { 314 | uint8_t ifr_updated[READ_BLOCK_SIZE]; 315 | for(int i = IFR_WRITE_OFFSET_BEGIN, j = 0; i < SECTOR_SIZE; i += READ_BLOCK_SIZE, j += READ_BLOCK_SIZE){ 316 | ret = aci_updater_read_data_block(IFR_BASE_ADDRESS+i, READ_BLOCK_SIZE, ifr_updated); 317 | if(ret != BLE_STATUS_SUCCESS){ 318 | return ret; 319 | } 320 | if (memcmp(ifr_updated, ifr_data+j, READ_BLOCK_SIZE) != 0) 321 | return BLE_UTIL_WRONG_VERIFY; 322 | } 323 | } 324 | 325 | BlueNRG_RST(); 326 | HCI_Process(); // To receive the EVT_INITIALIZED 327 | 328 | return BLE_STATUS_SUCCESS; 329 | } 330 | 331 | uint8_t verify_IFR(const IFR_config_TypeDef *ifr_data) 332 | { 333 | uint8_t ifr_updated[READ_BLOCK_SIZE]; 334 | uint8_t version, ret = BLE_STATUS_SUCCESS; 335 | 336 | aci_updater_start(); 337 | if(aci_get_updater_version(&version)) 338 | return BLE_UTIL_ACI_ERROR; 339 | for(int i = 0; i < IFR_SIZE; i += READ_BLOCK_SIZE){ 340 | ret = aci_updater_read_data_block((IFR_BASE_ADDRESS+SECTOR_SIZE-IFR_SIZE)+i, READ_BLOCK_SIZE, ifr_updated); 341 | if(ret != BLE_STATUS_SUCCESS){ 342 | return ret; 343 | } 344 | if (memcmp(ifr_updated, ((uint8_t*)ifr_data)+i, READ_BLOCK_SIZE) != 0) 345 | { 346 | ret = BLE_UTIL_WRONG_VERIFY; 347 | break; 348 | } 349 | } 350 | 351 | BlueNRG_RST(); 352 | HCI_Process(); // To receive the EVT_INITIALIZED 353 | 354 | return ret; 355 | } 356 | 357 | uint8_t getBlueNRGVersion(uint8_t *hwVersion, uint16_t *fwVersion) 358 | { 359 | uint8_t status; 360 | uint8_t hci_version, lmp_pal_version; 361 | uint16_t hci_revision, manufacturer_name, lmp_pal_subversion; 362 | 363 | status = hci_le_read_local_version(&hci_version, &hci_revision, &lmp_pal_version, 364 | &manufacturer_name, &lmp_pal_subversion); 365 | 366 | if (status == BLE_STATUS_SUCCESS) { 367 | *hwVersion = hci_revision >> 8; 368 | *fwVersion = (hci_revision & 0xFF) << 8; // Major Version Number 369 | *fwVersion |= ((lmp_pal_subversion >> 4) & 0xF) << 4; // Minor Version Number 370 | *fwVersion |= lmp_pal_subversion & 0xF; // Patch Version Number 371 | } 372 | 373 | return status; 374 | } 375 | 376 | uint8_t getBlueNRGUpdaterVersion(uint8_t *version) 377 | { 378 | 379 | BlueNRG_HW_Bootloader(); 380 | HCI_Process(); // To receive the EVT_INITIALIZED 381 | 382 | if(aci_get_updater_version(version)) 383 | return BLE_UTIL_ACI_ERROR; 384 | 385 | if(*version < SUPPORTED_BOOTLOADER_VERSION_MIN || *version > SUPPORTED_BOOTLOADER_VERSION_MAX) 386 | return BLE_UTIL_UNSUPPORTED_VERSION; 387 | 388 | BlueNRG_RST(); 389 | HCI_Process(); // To receive the EVT_INITIALIZED 390 | 391 | return BLE_STATUS_SUCCESS; 392 | } 393 | 394 | uint8_t isHWBootloader_Patched(void) 395 | { 396 | uint8_t status, version; 397 | uint32_t crc, address = 0x10010000; 398 | 399 | if(aci_get_updater_version(&version)) 400 | return BLE_UTIL_ACI_ERROR; 401 | 402 | RETRY_COMMAND(aci_updater_calc_crc(address, 1, &crc), 2, status); 403 | if (status != BLE_STATUS_SUCCESS) 404 | return 0; 405 | 406 | if (crc == BOOTLOADER_CRC_NOT_PATCHED) 407 | return 0; 408 | 409 | return 1; 410 | } 411 | 412 | #ifdef __cplusplus 413 | } 414 | #endif 415 | -------------------------------------------------------------------------------- /src/STM32_BlueNRG/SimpleBlueNRG_HCI/hci/hci.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file hci.c 4 | * @author AMG RF Application Team 5 | * @brief Function for managing framework required for handling HCI interface. 6 | ****************************************************************************** 7 | * 8 | * 9 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 10 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 11 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 12 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 13 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 14 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 15 | * 16 | *

© COPYRIGHT 2013 STMicroelectronics

17 | */ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include "hal_types.h" 24 | #include "osal.h" 25 | #include "ble_status.h" 26 | #include "hal.h" 27 | #include "hci_const.h" 28 | #include "gp_timer.h" 29 | #include "bluenrg_interface.h" 30 | #include "ble_list.h" 31 | 32 | #include "stm32_bluenrg_ble.h" 33 | 34 | #if BLE_CONFIG_DBG_ENABLE 35 | #define PRINTF(...) printf(__VA_ARGS__) 36 | #else 37 | #define PRINTF(...) 38 | #endif 39 | 40 | #define HCI_LOG_ON 0 41 | 42 | #define HCI_READ_PACKET_NUM_MAX (5) 43 | 44 | #define MIN(a,b) ((a) < (b) )? (a) : (b) 45 | #define MAX(a,b) ((a) > (b) )? (a) : (b) 46 | 47 | tListNode hciReadPktPool; 48 | tListNode hciReadPktRxQueue; 49 | /* pool of hci read packets */ 50 | static tHciDataPacket hciReadPacketBuffer[HCI_READ_PACKET_NUM_MAX]; 51 | 52 | static volatile uint8_t hci_timer_id; 53 | static volatile uint8_t hci_timeout; 54 | 55 | void hci_timeout_callback(void) 56 | { 57 | hci_timeout = 1; 58 | return; 59 | } 60 | 61 | void HCI_Init(void) 62 | { 63 | uint8_t index; 64 | 65 | /* Initialize list heads of ready and free hci data packet queues */ 66 | list_init_head (&hciReadPktPool); 67 | list_init_head (&hciReadPktRxQueue); 68 | 69 | /* Initialize the queue of free hci data packets */ 70 | for (index = 0; index < HCI_READ_PACKET_NUM_MAX; index++) 71 | { 72 | list_insert_tail(&hciReadPktPool, (tListNode *)&hciReadPacketBuffer[index]); 73 | } 74 | } 75 | 76 | #define HCI_PCK_TYPE_OFFSET 0 77 | #define EVENT_PARAMETER_TOT_LEN_OFFSET 2 78 | 79 | /** 80 | * Verify if HCI packet is correctly formatted. 81 | * 82 | * @param[in] hciReadPacket The packet that is received from HCI interface. 83 | * @return 0 if HCI packet is as expected 84 | */ 85 | int HCI_verify(const tHciDataPacket * hciReadPacket) 86 | { 87 | const uint8_t *hci_pckt = hciReadPacket->dataBuff; 88 | 89 | if(hci_pckt[HCI_PCK_TYPE_OFFSET] != HCI_EVENT_PKT) 90 | return 1; /* Incorrect type. */ 91 | 92 | if(hci_pckt[EVENT_PARAMETER_TOT_LEN_OFFSET] != hciReadPacket->data_len - (1+HCI_EVENT_HDR_SIZE)) 93 | return 2; /* Wrong length (packet truncated or too long). */ 94 | 95 | return 0; 96 | } 97 | 98 | void HCI_Process(void) 99 | { 100 | tHciDataPacket * hciReadPacket = NULL; 101 | 102 | Disable_SPI_IRQ(); 103 | uint8_t list_empty = list_is_empty(&hciReadPktRxQueue); 104 | /* process any pending events read */ 105 | while(list_empty == FALSE) 106 | { 107 | list_remove_head (&hciReadPktRxQueue, (tListNode **)&hciReadPacket); 108 | Enable_SPI_IRQ(); 109 | HCI_Event_CB(hciReadPacket->dataBuff); 110 | Disable_SPI_IRQ(); 111 | list_insert_tail(&hciReadPktPool, (tListNode *)hciReadPacket); 112 | list_empty = list_is_empty(&hciReadPktRxQueue); 113 | } 114 | /* Explicit call to HCI_Isr(), since it cannot be called by ISR if IRQ is kept high by 115 | BlueNRG. */ 116 | HCI_Isr(); 117 | Enable_SPI_IRQ(); 118 | } 119 | 120 | BOOL HCI_Queue_Empty(void) 121 | { 122 | return list_is_empty(&hciReadPktRxQueue); 123 | } 124 | 125 | void HCI_Isr(void) 126 | { 127 | tHciDataPacket * hciReadPacket = NULL; 128 | uint8_t data_len; 129 | 130 | Clear_SPI_EXTI_Flag(); 131 | while(BlueNRG_DataPresent()){ 132 | if (list_is_empty (&hciReadPktPool) == FALSE){ 133 | 134 | /* enqueueing a packet for read */ 135 | list_remove_head (&hciReadPktPool, (tListNode **)&hciReadPacket); 136 | 137 | data_len = BlueNRG_SPI_Read_All(hciReadPacket->dataBuff, HCI_READ_PACKET_SIZE); 138 | if(data_len > 0){ 139 | hciReadPacket->data_len = data_len; 140 | if(HCI_verify(hciReadPacket) == 0) 141 | list_insert_tail(&hciReadPktRxQueue, (tListNode *)hciReadPacket); 142 | else 143 | list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket); 144 | } 145 | else { 146 | // Insert the packet back into the pool. 147 | list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket); 148 | } 149 | 150 | } 151 | else{ 152 | // HCI Read Packet Pool is empty, wait for a free packet. 153 | Clear_SPI_EXTI_Flag(); 154 | return; 155 | } 156 | 157 | Clear_SPI_EXTI_Flag(); 158 | } 159 | } 160 | 161 | void hci_write(const void* data1, const void* data2, uint8_t n_bytes1, uint8_t n_bytes2){ 162 | #if HCI_LOG_ON 163 | PRINTF("HCI <- "); 164 | for(int i=0; i < n_bytes1; i++) 165 | PRINTF("%02X ", *((uint8_t*)data1 + i)); 166 | for(int i=0; i < n_bytes2; i++) 167 | PRINTF("%02X ", *((uint8_t*)data2 + i)); 168 | PRINTF("\n"); 169 | #endif 170 | 171 | Hal_Write_Serial(data1, data2, n_bytes1, n_bytes2); 172 | } 173 | 174 | void hci_send_cmd(uint16_t ogf, uint16_t ocf, uint8_t plen, void *param) 175 | { 176 | hci_command_hdr hc; 177 | 178 | hc.opcode = htobs(cmd_opcode_pack(ogf, ocf)); 179 | hc.plen= plen; 180 | 181 | uint8_t header[HCI_HDR_SIZE + HCI_COMMAND_HDR_SIZE]; 182 | header[0] = HCI_COMMAND_PKT; 183 | Osal_MemCpy(header+1, &hc, sizeof(hc)); 184 | 185 | hci_write(header, param, sizeof(header), plen); 186 | } 187 | 188 | static void move_list(tListNode * dest_list, tListNode * src_list) 189 | { 190 | pListNode tmp_node; 191 | 192 | while(!list_is_empty(src_list)){ 193 | list_remove_tail(src_list, &tmp_node); 194 | list_insert_head(dest_list, tmp_node); 195 | } 196 | } 197 | 198 | /* It ensures that we have at least half of the free buffers in the pool. */ 199 | static void free_event_list(void) 200 | { 201 | tHciDataPacket * pckt; 202 | 203 | Disable_SPI_IRQ(); 204 | 205 | while(list_get_size(&hciReadPktPool) < HCI_READ_PACKET_NUM_MAX/2){ 206 | list_remove_head(&hciReadPktRxQueue, (tListNode **)&pckt); 207 | list_insert_tail(&hciReadPktPool, (tListNode *)pckt); 208 | /* Explicit call to HCI_Isr(), since it cannot be called by ISR if IRQ is kept high by 209 | BlueNRG */ 210 | HCI_Isr(); 211 | } 212 | 213 | Enable_SPI_IRQ(); 214 | } 215 | 216 | int hci_send_req(struct hci_request *r, BOOL async) 217 | { 218 | uint8_t *ptr; 219 | uint16_t opcode = htobs(cmd_opcode_pack(r->ogf, r->ocf)); 220 | hci_event_pckt *event_pckt; 221 | hci_uart_pckt *hci_hdr; 222 | int to = DEFAULT_TIMEOUT; 223 | struct timer t; 224 | tHciDataPacket * hciReadPacket = NULL; 225 | tListNode hciTempQueue; 226 | 227 | list_init_head(&hciTempQueue); 228 | 229 | free_event_list(); 230 | 231 | hci_send_cmd(r->ogf, r->ocf, r->clen, r->cparam); 232 | 233 | if(async){ 234 | return 0; 235 | } 236 | 237 | /* Minimum timeout is 1. */ 238 | if(to == 0) 239 | to = 1; 240 | 241 | Timer_Set(&t, to); 242 | 243 | while(1) { 244 | evt_cmd_complete *cc; 245 | evt_cmd_status *cs; 246 | evt_le_meta_event *me; 247 | int len; 248 | 249 | while(1){ 250 | if(Timer_Expired(&t)){ 251 | goto failed; 252 | } 253 | if(!HCI_Queue_Empty()){ 254 | break; 255 | } 256 | } 257 | 258 | /* Extract packet from HCI event queue. */ 259 | Disable_SPI_IRQ(); 260 | list_remove_head(&hciReadPktRxQueue, (tListNode **)&hciReadPacket); 261 | 262 | hci_hdr = (void *)hciReadPacket->dataBuff; 263 | 264 | if(hci_hdr->type == HCI_EVENT_PKT){ 265 | 266 | event_pckt = (void *) (hci_hdr->data); 267 | 268 | ptr = hciReadPacket->dataBuff + (1 + HCI_EVENT_HDR_SIZE); 269 | len = hciReadPacket->data_len - (1 + HCI_EVENT_HDR_SIZE); 270 | 271 | switch (event_pckt->evt) { 272 | 273 | case EVT_CMD_STATUS: 274 | cs = (void *) ptr; 275 | 276 | if (cs->opcode != opcode) 277 | goto failed; 278 | 279 | if (r->event != EVT_CMD_STATUS) { 280 | if (cs->status) { 281 | goto failed; 282 | } 283 | break; 284 | } 285 | 286 | r->rlen = MIN(len, r->rlen); 287 | Osal_MemCpy(r->rparam, ptr, r->rlen); 288 | goto done; 289 | 290 | case EVT_CMD_COMPLETE: 291 | cc = (void *) ptr; 292 | 293 | if (cc->opcode != opcode) 294 | goto failed; 295 | 296 | ptr += EVT_CMD_COMPLETE_SIZE; 297 | len -= EVT_CMD_COMPLETE_SIZE; 298 | 299 | r->rlen = MIN(len, r->rlen); 300 | Osal_MemCpy(r->rparam, ptr, r->rlen); 301 | goto done; 302 | 303 | case EVT_LE_META_EVENT: 304 | me = (void *) ptr; 305 | 306 | if (me->subevent != r->event) 307 | break; 308 | 309 | len -= 1; 310 | r->rlen = MIN(len, r->rlen); 311 | Osal_MemCpy(r->rparam, me->data, r->rlen); 312 | goto done; 313 | 314 | case EVT_HARDWARE_ERROR: 315 | goto failed; 316 | 317 | default: 318 | break; 319 | } 320 | } 321 | 322 | /* If there are no more packets to be processed, be sure there is at list one 323 | packet in the pool to process the expected event. 324 | If no free packets are available, discard the processed event and insert it 325 | into the pool. */ 326 | if(list_is_empty(&hciReadPktPool) && list_is_empty(&hciReadPktRxQueue)){ 327 | list_insert_tail(&hciReadPktPool, (tListNode *)hciReadPacket); 328 | hciReadPacket=NULL; 329 | } 330 | else { 331 | /* Insert the packet in a different queue. These packets will be 332 | inserted back in the main queue just before exiting from send_req(), so that 333 | these events can be processed by the application. 334 | */ 335 | list_insert_tail(&hciTempQueue, (tListNode *)hciReadPacket); 336 | hciReadPacket=NULL; 337 | } 338 | 339 | HCI_Isr(); 340 | 341 | Enable_SPI_IRQ(); 342 | 343 | } 344 | 345 | failed: 346 | if(hciReadPacket!=NULL){ 347 | list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket); 348 | } 349 | move_list(&hciReadPktRxQueue, &hciTempQueue); 350 | Enable_SPI_IRQ(); 351 | return -1; 352 | 353 | done: 354 | // Insert the packet back into the pool. 355 | list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket); 356 | move_list(&hciReadPktRxQueue, &hciTempQueue); 357 | 358 | Enable_SPI_IRQ(); 359 | return 0; 360 | } 361 | 362 | #ifdef __cplusplus 363 | } 364 | #endif 365 | -------------------------------------------------------------------------------- /src/STM32_BlueNRG/SimpleBlueNRG_HCI/utils/ble_list.c: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** 2 | * File Name : ble_list.c 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 19-July-2012 6 | * Description : Circular Linked List Implementation. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | /****************************************************************************** 21 | * Include Files 22 | ******************************************************************************/ 23 | #include 24 | #include "ble_list.h" 25 | #include "stm32_def.h" 26 | 27 | /****************************************************************************** 28 | * Function Definitions 29 | ******************************************************************************/ 30 | void list_init_head (tListNode * listHead) 31 | { 32 | listHead->next = listHead; 33 | listHead->prev = listHead; 34 | } 35 | 36 | uint8_t list_is_empty (tListNode * listHead) 37 | { 38 | uint32_t uwPRIMASK_Bit; 39 | uint8_t return_value; 40 | 41 | uwPRIMASK_Bit = __get_PRIMASK(); /**< backup PRIMASK bit */ 42 | __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ 43 | if(listHead->next == listHead) 44 | { 45 | return_value = TRUE; 46 | } 47 | else 48 | { 49 | return_value = FALSE; 50 | } 51 | __set_PRIMASK(uwPRIMASK_Bit); /**< Restore PRIMASK bit*/ 52 | 53 | return return_value; 54 | } 55 | 56 | void list_insert_head (tListNode * listHead, tListNode * node) 57 | { 58 | uint32_t uwPRIMASK_Bit; 59 | 60 | uwPRIMASK_Bit = __get_PRIMASK(); /**< backup PRIMASK bit */ 61 | __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ 62 | 63 | node->next = listHead->next; 64 | node->prev = listHead; 65 | listHead->next = node; 66 | (node->next)->prev = node; 67 | 68 | __set_PRIMASK(uwPRIMASK_Bit); /**< Restore PRIMASK bit*/ 69 | } 70 | 71 | void list_insert_tail (tListNode * listHead, tListNode * node) 72 | { 73 | uint32_t uwPRIMASK_Bit; 74 | 75 | uwPRIMASK_Bit = __get_PRIMASK(); /**< backup PRIMASK bit */ 76 | __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ 77 | 78 | node->next = listHead; 79 | node->prev = listHead->prev; 80 | listHead->prev = node; 81 | (node->prev)->next = node; 82 | 83 | __set_PRIMASK(uwPRIMASK_Bit); /**< Restore PRIMASK bit*/ 84 | } 85 | 86 | void list_remove_node (tListNode * node) 87 | { 88 | uint32_t uwPRIMASK_Bit; 89 | 90 | uwPRIMASK_Bit = __get_PRIMASK(); /**< backup PRIMASK bit */ 91 | __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ 92 | 93 | (node->prev)->next = node->next; 94 | (node->next)->prev = node->prev; 95 | 96 | __set_PRIMASK(uwPRIMASK_Bit); /**< Restore PRIMASK bit*/ 97 | } 98 | 99 | void list_remove_head (tListNode * listHead, tListNode ** node ) 100 | { 101 | uint32_t uwPRIMASK_Bit; 102 | 103 | uwPRIMASK_Bit = __get_PRIMASK(); /**< backup PRIMASK bit */ 104 | __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ 105 | 106 | *node = listHead->next; 107 | list_remove_node (listHead->next); 108 | (*node)->next = NULL; 109 | (*node)->prev = NULL; 110 | 111 | __set_PRIMASK(uwPRIMASK_Bit); /**< Restore PRIMASK bit*/ 112 | } 113 | 114 | void list_remove_tail (tListNode * listHead, tListNode ** node ) 115 | { 116 | uint32_t uwPRIMASK_Bit; 117 | 118 | uwPRIMASK_Bit = __get_PRIMASK(); /**< backup PRIMASK bit */ 119 | __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ 120 | 121 | *node = listHead->prev; 122 | list_remove_node (listHead->prev); 123 | (*node)->next = NULL; 124 | (*node)->prev = NULL; 125 | 126 | __set_PRIMASK(uwPRIMASK_Bit); /**< Restore PRIMASK bit*/ 127 | } 128 | 129 | void list_insert_node_after (tListNode * node, tListNode * ref_node) 130 | { 131 | uint32_t uwPRIMASK_Bit; 132 | 133 | uwPRIMASK_Bit = __get_PRIMASK(); /**< backup PRIMASK bit */ 134 | __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ 135 | 136 | node->next = ref_node->next; 137 | node->prev = ref_node; 138 | ref_node->next = node; 139 | (node->next)->prev = node; 140 | 141 | __set_PRIMASK(uwPRIMASK_Bit); /**< Restore PRIMASK bit*/ 142 | } 143 | 144 | void list_insert_node_before (tListNode * node, tListNode * ref_node) 145 | { 146 | uint32_t uwPRIMASK_Bit; 147 | 148 | uwPRIMASK_Bit = __get_PRIMASK(); /**< backup PRIMASK bit */ 149 | __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ 150 | 151 | node->next = ref_node; 152 | node->prev = ref_node->prev; 153 | ref_node->prev = node; 154 | (node->prev)->next = node; 155 | 156 | __set_PRIMASK(uwPRIMASK_Bit); /**< Restore PRIMASK bit*/ 157 | } 158 | 159 | int list_get_size (tListNode * listHead) 160 | { 161 | int size = 0; 162 | tListNode * temp; 163 | uint32_t uwPRIMASK_Bit; 164 | 165 | uwPRIMASK_Bit = __get_PRIMASK(); /**< backup PRIMASK bit */ 166 | __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ 167 | 168 | temp = listHead->next; 169 | while (temp != listHead) 170 | { 171 | size++; 172 | temp = temp->next; 173 | } 174 | 175 | __set_PRIMASK(uwPRIMASK_Bit); /**< Restore PRIMASK bit*/ 176 | return (size); 177 | } 178 | 179 | void list_get_next_node (tListNode * ref_node, tListNode ** node) 180 | { 181 | uint32_t uwPRIMASK_Bit; 182 | 183 | uwPRIMASK_Bit = __get_PRIMASK(); /**< backup PRIMASK bit */ 184 | __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ 185 | 186 | *node = ref_node->next; 187 | 188 | __set_PRIMASK(uwPRIMASK_Bit); /**< Restore PRIMASK bit*/ 189 | } 190 | 191 | void list_get_prev_node (tListNode * ref_node, tListNode ** node) 192 | { 193 | uint32_t uwPRIMASK_Bit; 194 | 195 | uwPRIMASK_Bit = __get_PRIMASK(); /**< backup PRIMASK bit */ 196 | __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ 197 | 198 | *node = ref_node->prev; 199 | 200 | __set_PRIMASK(uwPRIMASK_Bit); /**< Restore PRIMASK bit*/ 201 | } 202 | 203 | 204 | #ifdef __cplusplus 205 | } 206 | #endif 207 | -------------------------------------------------------------------------------- /src/STM32_BlueNRG/SimpleBlueNRG_HCI/utils/gp_timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004, Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the Contiki operating system. 30 | * 31 | * Author: Adam Dunkels 32 | * 33 | */ 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #include "ble_clock.h" 40 | #include "gp_timer.h" 41 | 42 | /*---------------------------------------------------------------------------*/ 43 | /** 44 | * Set a timer. 45 | * 46 | * This function sets a timer for a time sometime in the 47 | * future. The function timer_expired() will evaluate to true after 48 | * the timer has expired. 49 | * 50 | * @param[in] t A pointer to the timer 51 | * @param[in] interval The interval before the timer expires. 52 | * 53 | */ 54 | void 55 | Timer_Set(struct timer *t, tClockTime interval) 56 | { 57 | t->interval = interval; 58 | t->start = Clock_Time(); 59 | } 60 | /*---------------------------------------------------------------------------*/ 61 | /** 62 | * Reset the timer with the same interval. 63 | * 64 | * This function resets the timer with the same interval that was 65 | * given to the timer_set() function. The start point of the interval 66 | * is the exact time that the timer last expired. Therefore, this 67 | * function will cause the timer to be stable over time, unlike the 68 | * timer_restart() function. 69 | * 70 | * \param t A pointer to the timer. 71 | * 72 | * \sa timer_restart() 73 | */ 74 | void 75 | Timer_Reset(struct timer *t) 76 | { 77 | t->start += t->interval; 78 | } 79 | /*---------------------------------------------------------------------------*/ 80 | /** 81 | * Restart the timer from the current point in time 82 | * 83 | * This function restarts a timer with the same interval that was 84 | * given to the timer_set() function. The timer will start at the 85 | * current time. 86 | * 87 | * \note A periodic timer will drift if this function is used to reset 88 | * it. For preioric timers, use the timer_reset() function instead. 89 | * 90 | * \param t A pointer to the timer. 91 | * 92 | * \sa timer_reset() 93 | */ 94 | void 95 | Timer_Restart(struct timer *t) 96 | { 97 | t->start = Clock_Time(); 98 | } 99 | /*---------------------------------------------------------------------------*/ 100 | /** 101 | * Check if a timer has expired. 102 | * 103 | * This function tests if a timer has expired and returns true or 104 | * false depending on its status. 105 | * 106 | * \param t A pointer to the timer 107 | * 108 | * \return Non-zero if the timer has expired, zero otherwise. 109 | * 110 | */ 111 | int 112 | Timer_Expired(struct timer *t) 113 | { 114 | /* Note: Can not return diff >= t->interval so we add 1 to diff and return 115 | t->interval < diff - required to avoid an internal error in mspgcc. */ 116 | tClockTime diff = (Clock_Time() - t->start) + 1; 117 | return t->interval < diff; 118 | 119 | } 120 | /*---------------------------------------------------------------------------*/ 121 | /** 122 | * The time until the timer expires 123 | * 124 | * This function returns the time until the timer expires. 125 | * 126 | * \param t A pointer to the timer 127 | * 128 | * \return The time until the timer expires 129 | * 130 | */ 131 | tClockTime 132 | Timer_Remaining(struct timer *t) 133 | { 134 | return t->start + t->interval - Clock_Time(); 135 | } 136 | /*---------------------------------------------------------------------------*/ 137 | 138 | #ifdef __cplusplus 139 | } 140 | #endif 141 | /*---------------------------------------------------------------------------*/ 142 | -------------------------------------------------------------------------------- /src/STM32_BlueNRG/SimpleBlueNRG_HCI/utils/osal.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file osal.c 4 | * @author AMS - HEA&RF BU / CL 5 | * @version V1.0.0 6 | * @date 04-July-2014 7 | * @brief Implementation of OS abstraction layer functions used by the 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT(c) 2014 STMicroelectronics

13 | * 14 | * Redistribution and use in source and binary forms, with or without modification, 15 | * are permitted provided that the following conditions are met: 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | * 36 | ****************************************************************************** 37 | */ 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | /****************************************************************************** 43 | * Includes 44 | *****************************************************************************/ 45 | #include 46 | #include 47 | #include 48 | 49 | /** 50 | * Osal_MemCpy 51 | * 52 | */ 53 | void* Osal_MemCpy(void *dest, const void *src, unsigned int size) 54 | { 55 | return(memcpy(dest,src,size)); 56 | } 57 | 58 | /** 59 | * Osal_MemSet 60 | * 61 | */ 62 | void* Osal_MemSet(void *ptr, int value, unsigned int size) 63 | { 64 | return(memset(ptr,value,size)); 65 | } 66 | 67 | /****************************************************************************** 68 | * local Functions 69 | *****************************************************************************/ 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 75 | -------------------------------------------------------------------------------- /src/beacon_service.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file sensor_service.c 4 | * @author MCD Application Team 5 | * @version V1.0.0 6 | * @date 04-July-2014 7 | * @brief Add a sample service using a vendor specific profile. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2014 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | #include "beacon_service.h" 38 | #include "bluenrg_utils.h" 39 | #include "bluenrg_hal_aci.h" 40 | #include "hci.h" 41 | #include "hci_le.h" 42 | #include "bluenrg_utils.h" 43 | #include "stm32_bluenrg_ble.h" 44 | #include "osal.h" 45 | #include "bluenrg_gap_aci.h" 46 | #include "bluenrg_gatt_aci.h" 47 | #include "SPBTLE_RF.h" 48 | 49 | /** @addtogroup X-CUBE-BLE1_Applications 50 | * @{ 51 | */ 52 | 53 | /** @addtogroup Beacon 54 | * @{ 55 | */ 56 | 57 | /** @defgroup SENSOR_SERVICE 58 | * @{ 59 | */ 60 | extern uint8_t bnrg_expansion_board; 61 | BeaconServiceClass BeaconService; 62 | 63 | void Beacon_HCI_Event_CB(void *pckt); 64 | 65 | /** 66 | * @brief Begin a BeaconService 67 | * @param addr : MAC Address 68 | * @param beaconType : Type of Beacon, UID or URL 69 | * @param webURL : URL for Beacon Type URL 70 | * @param beaconID : Instace name for UID 71 | * @param nameSpace : Namespace for UID 72 | * @retval BLE_STATUS_SUCCESS if success 73 | */ 74 | tBleStatus BeaconServiceClass::begin(uint8_t addr[BDADDR_SIZE], uint8_t beaconType, 75 | char* webURL, uint8_t *beaconID, uint8_t *nameSpace) 76 | { 77 | uint8_t bdaddr[BDADDR_SIZE]; 78 | uint16_t service_handle, dev_name_char_handle, appearance_char_handle; 79 | 80 | uint8_t hwVersion; 81 | uint16_t fwVersion; 82 | 83 | int ret; 84 | 85 | if(addr == NULL) { 86 | return BLE_STATUS_NULL_PARAM; 87 | } 88 | 89 | attach_HCI_CB(Beacon_HCI_Event_CB); 90 | 91 | /* get the BlueNRG HW and FW versions */ 92 | ret = getBlueNRGVersion(&hwVersion, &fwVersion); 93 | if(ret) { 94 | PRINTF("Reading Version failed.\n"); 95 | return ret; 96 | } 97 | 98 | /* 99 | * Reset BlueNRG again otherwise we won't 100 | * be able to change its MAC address. 101 | * aci_hal_write_config_data() must be the first 102 | * command after reset otherwise it will fail. 103 | */ 104 | BlueNRG_RST(); 105 | 106 | if (hwVersion > 0x30) { /* X-NUCLEO-IDB05A1 expansion board is used */ 107 | bnrg_expansion_board = IDB05A1; 108 | } 109 | 110 | /* The Nucleo board must be configured as SERVER */ 111 | Osal_MemCpy(bdaddr, addr, BDADDR_SIZE); 112 | 113 | ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, 114 | CONFIG_DATA_PUBADDR_LEN, 115 | bdaddr); 116 | if(ret){ 117 | PRINTF("Setting BD_ADDR failed.\n"); 118 | return ret; 119 | } 120 | 121 | ret = aci_gatt_init(); 122 | if(ret){ 123 | PRINTF("GATT_Init failed.\n"); 124 | return ret; 125 | } 126 | 127 | if (bnrg_expansion_board == IDB05A1) { 128 | ret = aci_gap_init_IDB05A1(GAP_PERIPHERAL_ROLE_IDB05A1, 0, 0x07, &service_handle, &dev_name_char_handle, &appearance_char_handle); 129 | } 130 | else { 131 | ret = aci_gap_init_IDB04A1(GAP_PERIPHERAL_ROLE_IDB04A1, &service_handle, &dev_name_char_handle, &appearance_char_handle); 132 | } 133 | 134 | if(ret){ 135 | PRINTF("GAP_Init failed.\n"); 136 | return ret; 137 | } 138 | 139 | /* Set output power level */ 140 | ret = aci_hal_set_tx_power_level(1,4); 141 | 142 | if (ret) { 143 | PRINTF("Setting Tx Power Level failed.\n"); 144 | } 145 | 146 | /* Initialize beacon services */ 147 | if ((beaconType & EDDYSTONE_UID_BEACON_TYPE) && 148 | (beaconID != NULL) && (nameSpace != NULL)) 149 | { 150 | if((beaconID != NULL) && (nameSpace != NULL)) { 151 | ret = EddystoneUID_Start(beaconID, nameSpace); 152 | } else { 153 | ret = BLE_STATUS_NULL_PARAM; 154 | } 155 | } 156 | if ((beaconType & EDDYSTONE_URL_BEACON_TYPE) && (webURL != NULL)) 157 | { 158 | if(webURL != NULL) { 159 | ret = EddystoneURL_Start((uint8_t*)webURL); 160 | } else { 161 | ret = BLE_STATUS_NULL_PARAM; 162 | } 163 | } 164 | 165 | return ret; 166 | } 167 | 168 | tBleStatus BeaconServiceClass::begin(uint8_t addr[BDADDR_SIZE], char* webURL) 169 | { 170 | return begin(addr, URL_TYPE, webURL, NULL, NULL); 171 | } 172 | 173 | tBleStatus BeaconServiceClass::begin(uint8_t addr[BDADDR_SIZE], 174 | uint8_t *beaconID, uint8_t *nameSpace) 175 | { 176 | return begin(addr, UID_TYPE, NULL, beaconID, nameSpace); 177 | } 178 | 179 | /** 180 | * @brief Callback processing the ACI events. 181 | * @note Inside this function each event must be identified and correctly 182 | * parsed. 183 | * @param void* Pointer to the ACI packet 184 | * @retval None 185 | */ 186 | void Beacon_HCI_Event_CB(void *pckt) 187 | { 188 | hci_uart_pckt *hci_pckt = (hci_uart_pckt *)pckt; 189 | 190 | /* obtain event packet */ 191 | hci_event_pckt *event_pckt = (hci_event_pckt*)hci_pckt->data; 192 | 193 | if(hci_pckt->type != HCI_EVENT_PKT) 194 | { 195 | return; 196 | } 197 | 198 | switch(event_pckt->evt) 199 | { 200 | 201 | case EVT_DISCONN_COMPLETE: 202 | { 203 | ; 204 | } 205 | break; 206 | 207 | case EVT_LE_META_EVENT: 208 | { 209 | evt_le_meta_event *evt = (evt_le_meta_event *)event_pckt->data; 210 | 211 | switch(evt->subevent) 212 | { 213 | case EVT_LE_CONN_COMPLETE: 214 | { 215 | ; 216 | } 217 | break; 218 | } 219 | } 220 | break; 221 | 222 | case EVT_VENDOR: 223 | { 224 | ; 225 | } 226 | break; 227 | } 228 | } 229 | 230 | /** 231 | * @} 232 | */ 233 | 234 | /** 235 | * @} 236 | */ 237 | 238 | /** 239 | * @} 240 | */ 241 | 242 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 243 | -------------------------------------------------------------------------------- /src/beacon_service.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file sensor_service.h 4 | * @author CL 5 | * @version V1.0.0 6 | * @date 04-July-2014 7 | * @brief 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2014 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef _SENSOR_SERVICE_H_ 40 | #define _SENSOR_SERVICE_H_ 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | #include "hal_types.h" 44 | #include "bluenrg_gatt_server.h" 45 | #include "bluenrg_gap.h" 46 | #include "string.h" 47 | #include "bluenrg_gap_aci.h" 48 | #include "bluenrg_gatt_aci.h" 49 | #include "hci_const.h" 50 | #include "gp_timer.h" 51 | #include "bluenrg_hal_aci.h" 52 | #include "bluenrg_aci_const.h" 53 | #include "hci.h" 54 | #include "hal.h" 55 | #include "sm.h" 56 | #include "debug.h" 57 | #include 58 | #include 59 | #include "eddystone_beacon.h" 60 | 61 | #define UID_TYPE EDDYSTONE_UID_BEACON_TYPE 62 | #define URL_TYPE EDDYSTONE_URL_BEACON_TYPE 63 | 64 | class BeaconServiceClass 65 | { 66 | public: 67 | tBleStatus begin(uint8_t addr[BDADDR_SIZE], uint8_t beaconType, char* webURL, 68 | uint8_t* beaconID, uint8_t *nameSpace); 69 | tBleStatus begin(uint8_t addr[BDADDR_SIZE], char* webURL); 70 | tBleStatus begin(uint8_t addr[BDADDR_SIZE], uint8_t* beaconID, uint8_t *nameSpace); 71 | }; 72 | 73 | extern BeaconServiceClass BeaconService; 74 | 75 | #endif /* _SENSOR_SERVICE_H_ */ 76 | 77 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 78 | -------------------------------------------------------------------------------- /src/ble_clock.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** 2 | * File Name : ble_clock.h 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.1 5 | * Date : 19-July-2012 6 | * Description : Header file for clock library, that gives a simple time 7 | * reference to the BLE Stack. 8 | ******************************************************************************** 9 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 10 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 11 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 12 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 13 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 14 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 15 | *******************************************************************************/ 16 | 17 | #ifndef __BLE_CLOCK_H__ 18 | #define __BLE_CLOCK_H__ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "wiring_time.h" 25 | 26 | typedef uint32_t tClockTime; 27 | #define CLOCK_SECOND 1000 28 | #define Clock_Init() 29 | #define Clock_Time millis 30 | #define Clock_Wait delay 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif /* __BLE_CLOCK_H__ */ 37 | -------------------------------------------------------------------------------- /src/ble_list.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** 2 | * File Name : ble_list.h 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 19-July-2012 6 | * Description : Header file for linked list library. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | #ifndef _BLE_LIST_H_ 16 | #define _BLE_LIST_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | typedef struct _tListNode { 23 | struct _tListNode * next; 24 | struct _tListNode * prev; 25 | }tListNode, *pListNode; 26 | 27 | void list_init_head (tListNode * listHead); 28 | 29 | uint8_t list_is_empty (tListNode * listHead); 30 | 31 | void list_insert_head (tListNode * listHead, tListNode * node); 32 | 33 | void list_insert_tail (tListNode * listHead, tListNode * node); 34 | 35 | void list_remove_node (tListNode * node); 36 | 37 | void list_remove_head (tListNode * listHead, tListNode ** node ); 38 | 39 | void list_remove_tail (tListNode * listHead, tListNode ** node ); 40 | 41 | void list_insert_node_after (tListNode * node, tListNode * ref_node); 42 | 43 | void list_insert_node_before (tListNode * node, tListNode * ref_node); 44 | 45 | int list_get_size (tListNode * listHead); 46 | 47 | void list_get_next_node (tListNode * ref_node, tListNode ** node); 48 | 49 | void list_get_prev_node (tListNode * ref_node, tListNode ** node); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif /* _BLE_LIST_H_ */ 56 | -------------------------------------------------------------------------------- /src/ble_status.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** 2 | * File Name : ble_status.h 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 19-July-2012 6 | * Description : Header file with BLE Stack status codes. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | #ifndef __BLE_STATUS_H__ 16 | #define __BLE_STATUS_H__ 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #include 23 | 24 | /** @addtogroup Middlewares 25 | * @{ 26 | */ 27 | 28 | /** @defgroup ST 29 | * @{ 30 | */ 31 | 32 | /** @defgroup SimpleBlueNRG_HCI 33 | * @{ 34 | */ 35 | 36 | /** @defgroup ble_status Bluetooth Status/Error Codes 37 | * @{ 38 | */ 39 | 40 | typedef uint8_t tBleStatus; 41 | 42 | /* Error Codes as specified by the specification 43 | * according to the spec the error codes range 44 | * from 0x00 to 0x3F 45 | */ 46 | /** 47 | * @name Standard error codes 48 | * @brief Standard error codes. See Core v 4.1, Vol. 2, part D. 49 | * @{ 50 | */ 51 | #define ERR_CMD_SUCCESS (0x00) 52 | #define BLE_STATUS_SUCCESS (0x00) 53 | #define ERR_UNKNOWN_HCI_COMMAND (0x01) 54 | #define ERR_UNKNOWN_CONN_IDENTIFIER (0x02) 55 | 56 | #define ERR_AUTH_FAILURE (0x05) 57 | #define ERR_PIN_OR_KEY_MISSING (0x06) 58 | #define ERR_MEM_CAPACITY_EXCEEDED (0x07) 59 | #define ERR_CONNECTION_TIMEOUT (0x08) 60 | 61 | #define ERR_COMMAND_DISALLOWED (0x0C) 62 | 63 | #define ERR_UNSUPPORTED_FEATURE (0x11) 64 | #define ERR_INVALID_HCI_CMD_PARAMS (0x12) 65 | #define ERR_RMT_USR_TERM_CONN (0x13) 66 | #define ERR_RMT_DEV_TERM_CONN_LOW_RESRCES (0x14) 67 | #define ERR_RMT_DEV_TERM_CONN_POWER_OFF (0x15) 68 | #define ERR_LOCAL_HOST_TERM_CONN (0x16) 69 | 70 | #define ERR_UNSUPP_RMT_FEATURE (0x1A) 71 | 72 | #define ERR_INVALID_LMP_PARAM (0x1E) 73 | #define ERR_UNSPECIFIED_ERROR (0x1F) 74 | 75 | #define ERR_LL_RESP_TIMEOUT (0x22) 76 | #define ERR_LMP_PDU_NOT_ALLOWED (0x24) 77 | 78 | #define ERR_INSTANT_PASSED (0x28) 79 | 80 | #define ERR_PAIR_UNIT_KEY_NOT_SUPP (0x29) 81 | #define ERR_CONTROLLER_BUSY (0x3A) 82 | 83 | #define ERR_DIRECTED_ADV_TIMEOUT (0x3C) 84 | 85 | #define ERR_CONN_END_WITH_MIC_FAILURE (0x3D) 86 | 87 | #define ERR_CONN_FAILED_TO_ESTABLISH (0x3E) 88 | 89 | 90 | /** 91 | * @} 92 | */ 93 | /** 94 | * @name Vendor-specific error codes 95 | * @brief Error codes defined by ST related to BlueNRG stack 96 | * @{ 97 | */ 98 | /** 99 | * The command cannot be executed due to the current state of the device. 100 | */ 101 | #define BLE_STATUS_FAILED (0x41) 102 | /** 103 | * Some parameters are invalid. 104 | */ 105 | #define BLE_STATUS_INVALID_PARAMS (0x42) 106 | /** 107 | * It is not allowed to start the procedure (e.g. another the procedure is ongoing 108 | * or cannot be started on the given handle). 109 | */ 110 | #define BLE_STATUS_NOT_ALLOWED (0x46) 111 | /** 112 | * Unexpected error. 113 | */ 114 | #define BLE_STATUS_ERROR (0x47) 115 | #define BLE_STATUS_ADDR_NOT_RESOLVED (0x48) 116 | 117 | #define FLASH_READ_FAILED (0x49) 118 | #define FLASH_WRITE_FAILED (0x4A) 119 | #define FLASH_ERASE_FAILED (0x4B) 120 | 121 | #define BLE_STATUS_INVALID_CID (0x50) 122 | 123 | #define TIMER_NOT_VALID_LAYER (0x54) 124 | #define TIMER_INSUFFICIENT_RESOURCES (0x55) 125 | 126 | #define BLE_STATUS_CSRK_NOT_FOUND (0x5A) 127 | #define BLE_STATUS_IRK_NOT_FOUND (0x5B) 128 | #define BLE_STATUS_DEV_NOT_FOUND_IN_DB (0x5C) 129 | #define BLE_STATUS_SEC_DB_FULL (0x5D) 130 | #define BLE_STATUS_DEV_NOT_BONDED (0x5E) 131 | #define BLE_STATUS_DEV_IN_BLACKLIST (0x5F) 132 | 133 | #define BLE_STATUS_INVALID_HANDLE (0x60) 134 | #define BLE_STATUS_INVALID_PARAMETER (0x61) 135 | #define BLE_STATUS_OUT_OF_HANDLE (0x62) 136 | #define BLE_STATUS_INVALID_OPERATION (0x63) 137 | #define BLE_STATUS_INSUFFICIENT_RESOURCES (0x64) 138 | #define BLE_INSUFFICIENT_ENC_KEYSIZE (0x65) 139 | #define BLE_STATUS_CHARAC_ALREADY_EXISTS (0x66) 140 | 141 | /** 142 | * Returned when no valid slots are available (e.g. when there are no available state machines). 143 | */ 144 | #define BLE_STATUS_NO_VALID_SLOT (0x82) 145 | 146 | /** 147 | * Returned when a scan window shorter than minimum allowed value has been requested (i.e. 2ms) 148 | */ 149 | 150 | #define BLE_STATUS_SCAN_WINDOW_SHORT (0x83) 151 | /** 152 | * Returned when the maximum requested interval to be allocated is shorter then the current 153 | * anchor period and a there is no submultiple for the current anchor period that is between 154 | * the minimum and the maximum requested intervals. 155 | */ 156 | 157 | #define BLE_STATUS_NEW_INTERVAL_FAILED (0x84) 158 | /** 159 | * Returned when the maximum requested interval to be allocated is greater than the current anchor 160 | * period and there is no multiple of the anchor period that is between the minimum and the maximum 161 | * requested intervals. 162 | */ 163 | 164 | #define BLE_STATUS_INTERVAL_TOO_LARGE (0x85) 165 | /** 166 | * Returned when the current anchor period or a new one can be found that is compatible to the 167 | * interval range requested by the new slot but the maximum available length that can be allocated is 168 | * less than the minimum requested slot length. 169 | */ 170 | 171 | #define BLE_STATUS_LENGTH_FAILED (0x86) 172 | /** 173 | * @} 174 | */ 175 | 176 | /** 177 | * @name Library Error Codes 178 | * @brief Error codes defined by ST related to MCU library. 179 | * @{ 180 | */ 181 | #define BLE_STATUS_TIMEOUT (0xFF) 182 | #define BLE_STATUS_PROFILE_ALREADY_INITIALIZED (0xF0) 183 | #define BLE_STATUS_NULL_PARAM (0xF1) 184 | /** 185 | * @} 186 | */ 187 | 188 | /** 189 | * @} 190 | */ 191 | 192 | #ifdef __cplusplus 193 | } 194 | #endif 195 | 196 | #endif /* __BLE_STATUS_H__ */ 197 | -------------------------------------------------------------------------------- /src/bluenrg_aci.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2014 STMicroelectronics ******************** 2 | * File Name : bluenrg_aci.h 3 | * Author : AMS - AAS 4 | * Version : V1.0.0 5 | * Date : 26-Jun-2014 6 | * Description : Header file that includes commands and events for BlueNRG 7 | * FW6.3. 8 | ******************************************************************************** 9 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 10 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 11 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 12 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 13 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 14 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 15 | *******************************************************************************/ 16 | 17 | #ifndef __BLUENRG_ACI_H__ 18 | #define __BLUENRG_ACI_H__ 19 | 20 | #include "bluenrg_aci_const.h" 21 | #include "bluenrg_gap_aci.h" 22 | #include "bluenrg_gatt_aci.h" 23 | #include "bluenrg_l2cap_aci.h" 24 | #include "bluenrg_hal_aci.h" 25 | #include "bluenrg_updater_aci.h" 26 | 27 | #endif /* __BLUENRG_ACI_H__ */ 28 | -------------------------------------------------------------------------------- /src/bluenrg_gap.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** 2 | * File Name : bluenrg_gap.h 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 19-July-2012 6 | * Description : Header file for BlueNRG's GAP layer. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | #ifndef __GAP_H__ 16 | #define __GAP_H__ 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #include 23 | 24 | /** @addtogroup Middlewares 25 | * @{ 26 | */ 27 | 28 | /** @defgroup ST 29 | * @{ 30 | */ 31 | 32 | /** @defgroup SimpleBlueNRG_HCI 33 | * @{ 34 | */ 35 | 36 | /** 37 | *@addtogroup GAP GAP 38 | *@brief API for GAP layer. 39 | *@{ 40 | */ 41 | 42 | /** 43 | * @name GAP UUIDs 44 | * @{ 45 | */ 46 | #define GAP_SERVICE_UUID (0x1800) 47 | #define DEVICE_NAME_UUID (0x2A00) 48 | #define APPEARANCE_UUID (0x2A01) 49 | #define PERIPHERAL_PRIVACY_FLAG_UUID (0x2A02) 50 | #define RECONNECTION_ADDR_UUID (0x2A03) 51 | #define PERIPHERAL_PREFERRED_CONN_PARAMS_UUID (0x2A04) 52 | /** 53 | * @} 54 | */ 55 | 56 | /** 57 | * @name Characteristic value lengths 58 | * @{ 59 | */ 60 | #define DEVICE_NAME_CHARACTERISTIC_LEN (8) 61 | #define APPEARANCE_CHARACTERISTIC_LEN (2) 62 | #define PERIPHERAL_PRIVACY_CHARACTERISTIC_LEN (1) 63 | #define RECONNECTION_ADDR_CHARACTERISTIC_LEN (6) 64 | #define PERIPHERAL_PREF_CONN_PARAMS_CHARACTERISTIC_LEN (8) 65 | /** 66 | * @} 67 | */ 68 | 69 | /*------------- AD types for adv data and scan response data ----------------*/ 70 | 71 | /** 72 | * @defgroup AD_Types AD Types 73 | * @brief AD Types 74 | * @{ 75 | */ 76 | 77 | /* FLAGS AD type */ 78 | #define AD_TYPE_FLAGS (0x01) 79 | /* flag bits */ 80 | /** 81 | * @anchor Flags_AD_Type_bits 82 | * @name Flags AD Type bits 83 | * @brief Bits in Flags AD Type 84 | * @{ 85 | */ 86 | #define FLAG_BIT_LE_LIMITED_DISCOVERABLE_MODE (0x01) 87 | #define FLAG_BIT_LE_GENERAL_DISCOVERABLE_MODE (0x02) 88 | #define FLAG_BIT_BR_EDR_NOT_SUPPORTED (0x04) 89 | #define FLAG_BIT_LE_BR_EDR_CONTROLLER (0x08) 90 | #define FLAG_BIT_LE_BR_EDR_HOST (0x10) 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @name Service UUID AD types 97 | * @{ 98 | */ 99 | #define AD_TYPE_16_BIT_SERV_UUID (0x02) 100 | #define AD_TYPE_16_BIT_SERV_UUID_CMPLT_LIST (0x03) 101 | #define AD_TYPE_32_BIT_SERV_UUID (0x04) 102 | #define AD_TYPE_32_BIT_SERV_UUID_CMPLT_LIST (0x05) 103 | #define AD_TYPE_128_BIT_SERV_UUID (0x06) 104 | #define AD_TYPE_128_BIT_SERV_UUID_CMPLT_LIST (0x07) 105 | /** 106 | * @} 107 | */ 108 | 109 | /* LOCAL NAME AD types */ 110 | /** 111 | * @name Local name AD types 112 | * @{ 113 | */ 114 | #define AD_TYPE_SHORTENED_LOCAL_NAME (0x08) 115 | #define AD_TYPE_COMPLETE_LOCAL_NAME (0x09) 116 | /** 117 | * @} 118 | */ 119 | 120 | /* TX power level AD type*/ 121 | #define AD_TYPE_TX_POWER_LEVEL (0x0A) 122 | 123 | /* Class of device */ 124 | #define AD_TYPE_CLASS_OF_DEVICE (0x0D) 125 | 126 | /* security manager TK value AD type */ 127 | #define AD_TYPE_SEC_MGR_TK_VALUE (0x10) 128 | 129 | /* security manager OOB flags */ 130 | #define AD_TYPE_SEC_MGR_OOB_FLAGS (0x11) 131 | 132 | /* slave connection interval AD type */ 133 | #define AD_TYPE_SLAVE_CONN_INTERVAL (0x12) 134 | 135 | /* service solicitation UUID list Ad types*/ 136 | /** 137 | * @name Service solicitation UUID list AD types 138 | * @{ 139 | */ 140 | #define AD_TYPE_SERV_SOLICIT_16_BIT_UUID_LIST (0x14) 141 | #define AD_TYPE_SERV_SOLICIT_32_BIT_UUID_LIST (0x1F) 142 | #define AD_TYPE_SERV_SOLICIT_128_BIT_UUID_LIST (0x15) 143 | /** 144 | * @} 145 | */ 146 | 147 | /* service data AD type */ 148 | #define AD_TYPE_SERVICE_DATA (0x16) 149 | 150 | /* manufaturer specific data AD type */ 151 | #define AD_TYPE_MANUFACTURER_SPECIFIC_DATA (0xFF) 152 | 153 | /** 154 | * @} 155 | */ 156 | 157 | #define MAX_ADV_DATA_LEN (31) 158 | 159 | #define DEVICE_NAME_LEN (7) 160 | #define BD_ADDR_SIZE (6) 161 | 162 | /** 163 | * @name Privacy flag values 164 | * @{ 165 | */ 166 | #define PRIVACY_ENABLED (0x01) 167 | #define PRIVACY_DISABLED (0x00) 168 | /** 169 | * @} 170 | */ 171 | 172 | /** 173 | * @name Intervals 174 | * Intervals in terms of 625 micro sec 175 | * @{ 176 | */ 177 | #define DIR_CONN_ADV_INT_MIN (0x190)/*250ms*/ 178 | #define DIR_CONN_ADV_INT_MAX (0x320)/*500ms*/ 179 | #define UNDIR_CONN_ADV_INT_MIN (0x800)/*1.28s*/ 180 | #define UNDIR_CONN_ADV_INT_MAX (0x1000)/*2.56s*/ 181 | #define LIM_DISC_ADV_INT_MIN (0x190)/*250ms*/ 182 | #define LIM_DISC_ADV_INT_MAX (0x320)/*500ms*/ 183 | #define GEN_DISC_ADV_INT_MIN (0x800)/*1.28s*/ 184 | #define GEN_DISC_ADV_INT_MAX (0x1000)/*2.56s*/ 185 | /** 186 | * @} 187 | */ 188 | 189 | /** 190 | * @name Timeout values 191 | * @{ 192 | */ 193 | #define LIM_DISC_MODE_TIMEOUT (180000)/* 180 seconds. according to the errata published */ 194 | #define PRIVATE_ADDR_INT_TIMEOUT (900000)/* 15 minutes */ 195 | /** 196 | * @} 197 | */ 198 | 199 | /** 200 | * @anchor gap_roles 201 | * @name GAP Roles 202 | * @{ 203 | */ 204 | #define GAP_PERIPHERAL_ROLE_IDB05A1 (0x01) 205 | #define GAP_BROADCASTER_ROLE_IDB05A1 (0x02) 206 | #define GAP_CENTRAL_ROLE_IDB05A1 (0x04) 207 | #define GAP_OBSERVER_ROLE_IDB05A1 (0x08) 208 | 209 | #define GAP_PERIPHERAL_ROLE_IDB04A1 (0x01) 210 | #define GAP_BROADCASTER_ROLE_IDB04A1 (0x02) 211 | #define GAP_CENTRAL_ROLE_IDB04A1 (0x03) 212 | #define GAP_OBSERVER_ROLE_IDB04A1 (0x04) 213 | 214 | /** 215 | * @} 216 | */ 217 | 218 | /** 219 | * @anchor gap_procedure_codes 220 | * @name GAP procedure codes 221 | * Procedure codes for EVT_BLUE_GAP_PROCEDURE_COMPLETE event 222 | * and aci_gap_terminate_gap_procedure() command. 223 | * @{ 224 | */ 225 | #define GAP_LIMITED_DISCOVERY_PROC (0x01) 226 | #define GAP_GENERAL_DISCOVERY_PROC (0x02) 227 | #define GAP_NAME_DISCOVERY_PROC (0x04) 228 | #define GAP_AUTO_CONNECTION_ESTABLISHMENT_PROC (0x08) 229 | #define GAP_GENERAL_CONNECTION_ESTABLISHMENT_PROC (0x10) 230 | #define GAP_SELECTIVE_CONNECTION_ESTABLISHMENT_PROC (0x20) 231 | #define GAP_DIRECT_CONNECTION_ESTABLISHMENT_PROC (0x40) 232 | 233 | #define GAP_OBSERVATION_PROC_IDB05A1 (0x80) 234 | 235 | /** 236 | * @} 237 | */ 238 | 239 | /** 240 | * @} 241 | */ 242 | 243 | /** 244 | * @} 245 | */ 246 | 247 | /** 248 | * @} 249 | */ 250 | 251 | /** 252 | * @} 253 | */ 254 | 255 | #ifdef __cplusplus 256 | } 257 | #endif 258 | 259 | #endif /* __GAP_H__ */ 260 | -------------------------------------------------------------------------------- /src/bluenrg_gatt_server.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** 2 | * File Name : bluenrg_gatt_server.h 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 19-July-2012 6 | * Description : Header file for BlueNRG's GATT server layer. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | #ifndef __GATT_SERVER_H__ 17 | #define __GATT_SERVER_H__ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include "compiler.h" 24 | #include "ble_status.h" 25 | 26 | /** @addtogroup Middlewares 27 | * @{ 28 | */ 29 | 30 | /** @defgroup ST 31 | * @{ 32 | */ 33 | 34 | /** @defgroup SimpleBlueNRG_HCI 35 | * @{ 36 | */ 37 | 38 | /** 39 | *@addtogroup GATT GATT 40 | *@{ 41 | */ 42 | 43 | /** 44 | * @anchor Well-Known_UUIDs 45 | * @name Well-Known UUIDs 46 | * @{ 47 | */ 48 | #define PRIMARY_SERVICE_UUID (0x2800) 49 | #define SECONDARY_SERVICE_UUID (0x2801) 50 | #define INCLUDE_SERVICE_UUID (0x2802) 51 | #define CHARACTERISTIC_UUID (0x2803) 52 | #define CHAR_EXTENDED_PROP_DESC_UUID (0x2900) 53 | #define CHAR_USER_DESC_UUID (0x2901) 54 | #define CHAR_CLIENT_CONFIG_DESC_UUID (0x2902) 55 | #define CHAR_SERVER_CONFIG_DESC_UUID (0x2903) 56 | #define CHAR_FORMAT_DESC_UUID (0x2904) 57 | #define CHAR_AGGR_FMT_DESC_UUID (0x2905) 58 | #define GATT_SERVICE_UUID (0x1801) 59 | #define GAP_SERVICE_UUID (0x1800) 60 | #define SERVICE_CHANGED_UUID (0x2A05) 61 | /** 62 | * @} 63 | */ 64 | 65 | /** 66 | * @anchor Access_permissions 67 | * @name Access permissions 68 | * Access permissions for an attribute 69 | * @{ 70 | */ 71 | #define ATTR_NO_ACCESS (0x00) 72 | #define ATTR_ACCESS_READ_ONLY (0x01) 73 | #define ATTR_ACCESS_WRITE_REQ_ONLY (0x02) 74 | #define ATTR_ACCESS_READ_WRITE (0x03) 75 | #define ATTR_ACCESS_WRITE_WITHOUT_RESPONSE (0x04) 76 | #define ATTR_ACCESS_SIGNED_WRITE_ALLOWED (0x08) 77 | /** 78 | * Allows all write procedures 79 | */ 80 | #define ATTR_ACCESS_WRITE_ANY (0x0E) 81 | /** 82 | * @} 83 | */ 84 | 85 | /** 86 | * @anchor Char_properties 87 | * @name Characteristic properties. 88 | * @{ 89 | */ 90 | #define CHAR_PROP_BROADCAST (0x01) 91 | #define CHAR_PROP_READ (0x02) 92 | #define CHAR_PROP_WRITE_WITHOUT_RESP (0x04) 93 | #define CHAR_PROP_WRITE (0x08) 94 | #define CHAR_PROP_NOTIFY (0x10) 95 | #define CHAR_PROP_INDICATE (0x20) 96 | #define CHAR_PROP_SIGNED_WRITE (0x40) 97 | #define CHAR_PROP_EXT (0x80) 98 | /** 99 | * @} 100 | */ 101 | 102 | 103 | /** 104 | * @anchor Security_permissions 105 | * @name Security permissions for an attribute. 106 | * @{ 107 | */ 108 | #define ATTR_PERMISSION_NONE (0x00) /**< No security. */ 109 | #define ATTR_PERMISSION_AUTHEN_READ (0x01) /**< Need authentication to read */ 110 | #define ATTR_PERMISSION_AUTHOR_READ (0x02) /**< Need authorization to read */ 111 | #define ATTR_PERMISSION_ENCRY_READ (0x04) /**< Link must be encrypted to read */ 112 | #define ATTR_PERMISSION_AUTHEN_WRITE (0x08) /**< Need authentication to write */ 113 | #define ATTR_PERMISSION_AUTHOR_WRITE (0x10) /**< Need authorization to write */ 114 | #define ATTR_PERMISSION_ENCRY_WRITE (0x20) /**< Link must be encrypted for write */ 115 | /** 116 | * @} 117 | */ 118 | 119 | /** 120 | * @anchor UUID_Types 121 | * @name Type of UUID (16 bit or 128 bit). 122 | * @{ 123 | */ 124 | #define UUID_TYPE_16 (0x01) 125 | #define UUID_TYPE_128 (0x02) 126 | /** 127 | * @} 128 | */ 129 | 130 | /** 131 | * @anchor Service_type 132 | * @name Type of service (primary or secondary) 133 | * @{ 134 | */ 135 | #define PRIMARY_SERVICE (0x01) 136 | #define SECONDARY_SERVICE (0x02) 137 | /** 138 | * @} 139 | */ 140 | 141 | /** 142 | * @anchor Gatt_Event_Mask 143 | * @name Gatt Event Mask 144 | * Type of event generated by GATT server 145 | * @{ 146 | */ 147 | #define GATT_DONT_NOTIFY_EVENTS (0x00) /**< Do not notify events. */ 148 | #define GATT_NOTIFY_ATTRIBUTE_WRITE (0x01) /**< The application will be notified when a client writes to this attribute. 149 | An @ref EVT_BLUE_GATT_ATTRIBUTE_MODIFIED will be issued. */ 150 | #define GATT_NOTIFY_WRITE_REQ_AND_WAIT_FOR_APPL_RESP (0x02) /**< The application will be notified when a write request, a write cmd 151 | or a signed write cmd are received by the server for this attribute. 152 | An @ref EVT_BLUE_GATT_WRITE_PERMIT_REQ will be issued. */ 153 | #define GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP (0x04) /**< The application will be notified when a read request of any type is 154 | received for this attribute. An @ref EVT_BLUE_GATT_READ_PERMIT_REQ will be issued. */ 155 | /** 156 | * @} 157 | */ 158 | 159 | /** 160 | * @name Type of characteristic length 161 | * See aci_gatt_add_char() 162 | * @{ 163 | */ 164 | #define CHAR_VALUE_LEN_CONSTANT (0x00) 165 | #define CHAR_VALUE_LEN_VARIABLE (0x01) 166 | /** 167 | * @} 168 | */ 169 | 170 | 171 | /** 172 | * @name Encryption key size 173 | * @{ 174 | */ 175 | /** 176 | * Minimum encryption key size 177 | */ 178 | #define MIN_ENCRY_KEY_SIZE (7) 179 | 180 | /** 181 | * Maximum encryption key size 182 | */ 183 | #define MAX_ENCRY_KEY_SIZE (0x10) 184 | /** 185 | * @} 186 | */ 187 | 188 | /** 189 | * @name Characteristic Presentation Format 190 | * @{ 191 | */ 192 | typedef __packed struct _charactFormat { 193 | uint8_t format; 194 | int8_t exp; 195 | uint16_t unit; 196 | uint8_t name_space; 197 | uint16_t desc; 198 | } PACKED charactFormat; 199 | 200 | /** 201 | * @} 202 | */ 203 | 204 | /** 205 | * @name Format 206 | * @{ 207 | */ 208 | #define FORMAT_UINT8 0x04 209 | #define FORMAT_UINT16 0x06 210 | #define FORMAT_UINT32 0x08 211 | #define FORMAT_SINT16 0x0E 212 | #define FORMAT_SINT24 0x0F 213 | /** 214 | * @} 215 | */ 216 | 217 | /** 218 | * @name Unit 219 | * @{ 220 | */ 221 | #define UNIT_UNITLESS 0x2700 222 | #define UNIT_PRESSURE_PASCAL 0x2724 223 | #define UNIT_TEMP_CELSIUS 0x272F 224 | #define UNIT_PRESSURE_BAR 0x2780 225 | #define UNIT_PERCENTAGE 0x27AD 226 | /** 227 | * @} 228 | */ 229 | 230 | 231 | /** 232 | * ATT MTU size 233 | */ 234 | #define ATT_MTU (23) 235 | 236 | /** 237 | * @} 238 | */ 239 | 240 | /** 241 | * @name Update type of aci_gatt_upd_char_val_ext(). 242 | * @{ 243 | */ 244 | 245 | #define NOTIFICATION 1 246 | #define INDICATION 2 247 | 248 | /** 249 | * @} 250 | */ 251 | 252 | #ifdef __cplusplus 253 | } 254 | #endif 255 | 256 | #endif /* __GATT_SERVER_H__ */ 257 | -------------------------------------------------------------------------------- /src/bluenrg_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file bluenrg_interface.h 4 | * @author MCD Application Team 5 | * @version V1.0.0 6 | * @date 04-July-2014 7 | * @brief This file provides code for the BlueNRG Expansion Board driver 8 | * based on STM32Cube HAL for STM32 Nucleo boards. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT(c) 2014 STMicroelectronics

13 | * 14 | * Redistribution and use in source and binary forms, with or without modification, 15 | * are permitted provided that the following conditions are met: 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | * 36 | ****************************************************************************** 37 | */ 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /* Includes ------------------------------------------------------------------*/ 44 | #include "bluenrg_interface.h" 45 | 46 | #include "debug.h" 47 | #include "ble_status.h" 48 | #include "hci.h" 49 | #include "stm32_bluenrg_ble.h" 50 | 51 | /** 52 | * @brief EXTI line detection callback. 53 | * @param Specifies the pins connected EXTI line 54 | * @retval None 55 | */ 56 | __weak void SPI_EXTI_Callback(void) 57 | { 58 | HCI_Isr(); 59 | } 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 66 | -------------------------------------------------------------------------------- /src/bluenrg_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file bluenrg_interface.h 4 | * @author CL 5 | * @version V1.0.0 6 | * @date 04-July-2014 7 | * @brief 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2014 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __BLUENRG_INTERFACE_H_ 40 | #define __BLUENRG_INTERFACE_H_ 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "stm32_bluenrg_ble.h" 48 | #include "hal_types.h" 49 | 50 | void Hal_Write_Serial(const void* data1, const void* data2, int32_t n_bytes1, 51 | int32_t n_bytes2); 52 | void SPI_EXTI_Callback(void); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif //__BLUENRG_INTERFACE_H_ 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /src/bluenrg_l2cap_aci.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2014 STMicroelectronics ******************** 2 | * File Name : bluenrg_l2cap_aci.h 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 26-Jun-2014 6 | * Description : Header file with L2CAP commands for BlueNRG FW6.3. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | #ifndef __BLUENRG_L2CAP_ACI_H__ 17 | #define __BLUENRG_L2CAP_ACI_H__ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** @addtogroup Middlewares 24 | * @{ 25 | */ 26 | 27 | /** @defgroup ST 28 | * @{ 29 | */ 30 | 31 | /** @defgroup SimpleBlueNRG_HCI 32 | * @{ 33 | */ 34 | 35 | /** 36 | *@addtogroup L2CAP L2CAP 37 | *@brief L2CAP layer. 38 | *@{ 39 | */ 40 | 41 | /** 42 | *@defgroup L2CAP_Functions L2CAP functions 43 | *@brief API for L2CAP layer. 44 | *@{ 45 | */ 46 | 47 | /** 48 | * @brief Send an L2CAP Connection Parameter Update request from the slave to the master. 49 | * @note An @ref EVT_BLUE_L2CAP_CONN_UPD_RESP event will be raised when the master will respond to the request 50 | * (accepts or rejects). 51 | * @param conn_handle Connection handle on which the connection parameter update request has to be sent. 52 | * @param interval_min Defines minimum value for the connection event interval in the following manner: 53 | * connIntervalMin = interval_min x 1.25ms 54 | * @param interval_max Defines maximum value for the connection event interval in the following manner: 55 | * connIntervalMax = interval_max x 1.25ms 56 | * @param slave_latency Defines the slave latency parameter (number of connection events that can be skipped). 57 | * @param timeout_multiplier Defines connection timeout parameter in the following manner: 58 | * timeout_multiplier x 10ms. 59 | * @return Value indicating success or error code. 60 | */ 61 | tBleStatus aci_l2cap_connection_parameter_update_request(uint16_t conn_handle, uint16_t interval_min, 62 | uint16_t interval_max, uint16_t slave_latency, 63 | uint16_t timeout_multiplier); 64 | /** 65 | * @brief Accept or reject a connection update. 66 | * @note This command should be sent in response to a @ref EVT_BLUE_L2CAP_CONN_UPD_REQ event from the controller. 67 | * The accept parameter has to be set if the connection parameters given in the event are acceptable. 68 | * @param conn_handle Handle received in @ref EVT_BLUE_L2CAP_CONN_UPD_REQ event. 69 | * @param interval_min The connection interval parameter as received in the l2cap connection update request event 70 | * @param interval_max The maximum connection interval parameter as received in the l2cap connection update request event. 71 | * @param slave_latency The slave latency parameter as received in the l2cap connection update request event. 72 | * @param timeout_multiplier The supervision connection timeout parameter as received in the l2cap connection update request event. 73 | * @param min_ce_length Minimum length of connection event needed for the LE connection.\n 74 | * Range: 0x0000 - 0xFFFF\n 75 | * Time = N x 0.625 msec. 76 | * @param max_ce_length Maximum length of connection event needed for the LE connection.\n 77 | * Range: 0x0000 - 0xFFFF\n 78 | * Time = N x 0.625 msec. 79 | * @param id Identifier received in @ref EVT_BLUE_L2CAP_CONN_UPD_REQ event. 80 | * @param accept @arg 0x00: The connection update parameters are not acceptable. 81 | * @arg 0x01: The connection update parameters are acceptable. 82 | * @return Value indicating success or error code. 83 | */ 84 | tBleStatus aci_l2cap_connection_parameter_update_response_IDB05A1(uint16_t conn_handle, uint16_t interval_min, 85 | uint16_t interval_max, uint16_t slave_latency, 86 | uint16_t timeout_multiplier, uint16_t min_ce_length, uint16_t max_ce_length, 87 | uint8_t id, uint8_t accept); 88 | 89 | /** 90 | * @brief Accept or reject a connection update. 91 | * @note This command should be sent in response to a @ref EVT_BLUE_L2CAP_CONN_UPD_REQ event from the controller. 92 | * The accept parameter has to be set if the connection parameters given in the event are acceptable. 93 | * @param conn_handle Handle received in @ref EVT_BLUE_L2CAP_CONN_UPD_REQ event. 94 | * @param interval_min The connection interval parameter as received in the l2cap connection update request event 95 | * @param interval_max The maximum connection interval parameter as received in the l2cap connection update request event. 96 | * @param slave_latency The slave latency parameter as received in the l2cap connection update request event. 97 | * @param timeout_multiplier The supervision connection timeout parameter as received in the l2cap connection update request event. 98 | * @param id Identifier received in @ref EVT_BLUE_L2CAP_CONN_UPD_REQ event. 99 | * @param accept @arg 0x00: The connection update parameters are not acceptable. 100 | * @arg 0x01: The connection update parameters are acceptable. 101 | * @return Value indicating success or error code. 102 | */ 103 | tBleStatus aci_l2cap_connection_parameter_update_response_IDB04A1(uint16_t conn_handle, uint16_t interval_min, 104 | uint16_t interval_max, uint16_t slave_latency, 105 | uint16_t timeout_multiplier, uint8_t id, uint8_t accept); 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @defgroup L2CAP_Events L2CAP events 113 | * @{ 114 | */ 115 | 116 | /** 117 | * This event is generated when the master responds to the L2CAP connection update request packet. 118 | * For more info see CONNECTION PARAMETER UPDATE RESPONSE and COMMAND REJECT in Bluetooth Core v4.0 spec. 119 | */ 120 | #define EVT_BLUE_L2CAP_CONN_UPD_RESP (0x0800) 121 | typedef __packed struct _evt_l2cap_conn_upd_resp{ 122 | uint16_t conn_handle; /**< The connection handle related to the event. */ 123 | uint8_t event_data_length; /**< Length of following data. */ 124 | /** 125 | * @li 0x13 in case of valid L2CAP Connection Parameter Update Response packet. 126 | * @li 0x01 in case of Command Reject. 127 | */ 128 | uint8_t code; 129 | uint8_t identifier; /**< Identifier of the response. It is equal to the request. */ 130 | uint16_t l2cap_length; /**< Length of following data. It should always be 2 */ 131 | /** 132 | * Result code (parameters accepted or rejected) in case of Connection Parameter Update 133 | * Response (code=0x13) or reason code for rejection in case of Command Reject (code=0x01). 134 | */ 135 | uint16_t result; 136 | } PACKED evt_l2cap_conn_upd_resp; 137 | 138 | /** 139 | * This event is generated when the master does not respond to the connection update request 140 | * within 30 seconds. 141 | */ 142 | #define EVT_BLUE_L2CAP_PROCEDURE_TIMEOUT (0x0801) 143 | typedef __packed struct _evt_l2cap_procedure_timeout{ 144 | uint16_t conn_handle; /**< The connection handle related to the event. */ 145 | uint8_t event_data_length; /**< Length of following data. It should be always 0 for this event. */ 146 | } PACKED evt_l2cap_procedure_timeout; 147 | 148 | /** 149 | * The event is given by the L2CAP layer when a connection update request is received from the slave. 150 | * The application has to respond by calling aci_l2cap_connection_parameter_update_response(). 151 | */ 152 | #define EVT_BLUE_L2CAP_CONN_UPD_REQ (0x0802) 153 | typedef __packed struct _evt_l2cap_conn_upd_req{ 154 | /** 155 | * Handle of the connection for which the connection update request has been received. 156 | * The same handle has to be returned while responding to the event with the command 157 | * aci_l2cap_connection_parameter_update_response(). 158 | */ 159 | uint16_t conn_handle; 160 | uint8_t event_data_length; /**< Length of following data. */ 161 | /** 162 | * This is the identifier which associates the request to the 163 | * response. The same identifier has to be returned by the upper 164 | * layer in the command aci_l2cap_connection_parameter_update_response(). 165 | */ 166 | uint8_t identifier; 167 | uint16_t l2cap_length; /**< Length of the L2CAP connection update request. */ 168 | uint16_t interval_min; /**< Value as defined in Bluetooth 4.0 spec, Volume 3, Part A 4.20. */ 169 | uint16_t interval_max; /**< Value as defined in Bluetooth 4.0 spec, Volume 3, Part A 4.20. */ 170 | uint16_t slave_latency; /**< Value as defined in Bluetooth 4.0 spec, Volume 3, Part A 4.20. */ 171 | uint16_t timeout_mult; /**< Value as defined in Bluetooth 4.0 spec, Volume 3, Part A 4.20. */ 172 | } PACKED evt_l2cap_conn_upd_req; 173 | 174 | /** 175 | * @} 176 | */ 177 | 178 | /** 179 | * @} 180 | */ 181 | 182 | /** 183 | * @} 184 | */ 185 | 186 | /** 187 | * @} 188 | */ 189 | 190 | /** 191 | * @} 192 | */ 193 | 194 | #ifdef __cplusplus 195 | } 196 | #endif 197 | 198 | #endif /* __BLUENRG_L2CAP_ACI_H__ */ 199 | -------------------------------------------------------------------------------- /src/bluenrg_updater_aci.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2014 STMicroelectronics ******************** 2 | * File Name : bluenrg_updater_aci.h 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 26-Jun-2014 6 | * Description : Header file with updater commands for BlueNRG FW6.3. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | #ifndef __BLUENRG_UPDATER_ACI_H__ 17 | #define __BLUENRG_UPDATER_ACI_H__ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | /** @addtogroup Middlewares 26 | * @{ 27 | */ 28 | 29 | /** @defgroup ST 30 | * @{ 31 | */ 32 | 33 | /** @defgroup SimpleBlueNRG_HCI 34 | * @{ 35 | */ 36 | 37 | /** 38 | * @defgroup Updater Updater 39 | * @brief Updater. 40 | * @{ 41 | */ 42 | 43 | /** 44 | * @defgroup Updater_Functions Updater functions 45 | * @brief API for BlueNRG Updater. 46 | * @{ 47 | */ 48 | 49 | tBleStatus aci_updater_start(void); 50 | 51 | tBleStatus aci_updater_reboot(void); 52 | 53 | tBleStatus aci_get_updater_version(uint8_t *version); 54 | 55 | tBleStatus aci_get_updater_buffer_size(uint8_t *buffer_size); 56 | 57 | tBleStatus aci_erase_blue_flag(void); 58 | 59 | tBleStatus aci_reset_blue_flag(void); 60 | 61 | tBleStatus aci_updater_erase_sector(uint32_t address); 62 | 63 | tBleStatus aci_updater_program_data_block(uint32_t address, uint16_t len, const uint8_t *data); 64 | 65 | tBleStatus aci_updater_read_data_block(uint32_t address, uint16_t data_len, uint8_t *data); 66 | 67 | tBleStatus aci_updater_calc_crc(uint32_t address, uint8_t num_sectors, uint32_t *crc); 68 | 69 | tBleStatus aci_updater_hw_version(uint8_t *version); 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** 76 | * @defgroup Updater_Events Updater events 77 | * @{ 78 | */ 79 | /** HCI vendor specific event, raised at BlueNRG power-up or reboot. */ 80 | #define EVT_BLUE_INITIALIZED (0x0001) 81 | typedef __packed struct _evt_blue_initialized{ 82 | uint8_t reason_code; 83 | } PACKED evt_blue_initialized; 84 | /** 85 | * @} 86 | */ 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /** 93 | * @} 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif /* __BLUENRG_UPDATER_ACI_H__ */ 109 | -------------------------------------------------------------------------------- /src/bluenrg_utils.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2014 STMicroelectronics ******************** 2 | * File Name : bluenrg_utils.h 3 | * Author : AMS - VMA, RF Application Team 4 | * Version : V1.0.1 5 | * Date : 03-October-2014 6 | * Description : Header file for BlueNRG utility functions 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | /** 16 | * @file bluenrg_utils.h 17 | * @brief BlueNRG IFR updater & BlueNRG stack updater utility APIs description 18 | * 19 | * 20 | **/ 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __BLUENRG_UTILS_H 23 | #define __BLUENRG_UTILS_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "hal_types.h" 31 | #include "compiler.h" 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | typedef struct{ 35 | uint8_t stack_mode; 36 | uint8_t day; 37 | uint8_t month; 38 | uint8_t year; 39 | uint16_t slave_sca_ppm; 40 | uint8_t master_sca; 41 | uint16_t hs_startup_time; /* In system time units*/ 42 | } IFR_config2_TypeDef; 43 | 44 | /** 45 | * Structure inside IFR for configuration options. 46 | */ 47 | typedef __packed struct{ 48 | uint8_t cold_ana_act_config_table[64]; 49 | uint8_t hot_ana_config_table[64]; 50 | uint8_t stack_mode; 51 | uint8_t gpio_config; 52 | uint8_t rsrvd1[2]; 53 | uint32_t rsrvd2[3]; 54 | uint32_t max_conn_event_time; 55 | uint32_t ls_crystal_period; 56 | uint32_t ls_crystal_freq; 57 | uint16_t slave_sca_ppm; 58 | uint8_t master_sca; 59 | uint8_t rsrvd3; 60 | uint16_t hs_startup_time; /* In system time units*/ 61 | uint8_t rsrvd4[2]; 62 | uint32_t uid; 63 | uint8_t rsrvd5; 64 | uint8_t year; 65 | uint8_t month; 66 | uint8_t day; 67 | uint32_t unused[5]; 68 | } PACKED IFR_config_TypeDef; 69 | 70 | /* Exported constants --------------------------------------------------------*/ 71 | extern const IFR_config_TypeDef IFR_config; 72 | 73 | /* Exported macros -----------------------------------------------------------*/ 74 | #define FROM_US_TO_SYS_TIME(us) ((uint16_t)(us/2.4414)+1) 75 | #define FROM_SYS_TIME_TO_US(sys) ((uint16_t)(sys*2.4414)) 76 | 77 | /* Convert 2 digit BCD number to an integer */ 78 | #define BCD_TO_INT(bcd) ((bcd & 0xF) + ((bcd & 0xF0) >> 4)*10) 79 | 80 | /* Convert 2 digit number to a BCD number */ 81 | #define INT_TO_BCD(n) ((((uint8_t)n/10)<<4) + (uint8_t)n%10) 82 | 83 | /** 84 | * Return values 85 | */ 86 | #define BLE_UTIL_SUCCESS 0 87 | #define BLE_UTIL_UNSUPPORTED_VERSION 1 88 | #define BLE_UTIL_WRONG_IMAGE_SIZE 2 89 | #define BLE_UTIL_ACI_ERROR 3 90 | #define BLE_UTIL_CRC_ERROR 4 91 | #define BLE_UTIL_PARSE_ERROR 5 92 | #define BLE_UTIL_WRONG_VERIFY 6 93 | 94 | /* Exported functions ------------------------------------------------------- */ 95 | /** 96 | * @brief Flash a new firmware using internal bootloader. 97 | * @param fw_image Pointer to the firmware image (raw binary data, 98 | * little-endian). 99 | * @param fw_size Size of the firmware image. The firmware image size shall 100 | * be multiple of 4 bytes. 101 | * @retval int It returns 0 if successful, or a number not equal to 0 in 102 | * case of error (ACI_ERROR, UNSUPPORTED_VERSION, 103 | * WRONG_IMAGE_SIZE, CRC_ERROR) 104 | */ 105 | int program_device(const uint8_t *fw_image, uint32_t fw_size); 106 | 107 | /** 108 | * @brief Read raw data from IFR (3 64-bytes blocks). 109 | * @param data Pointer to the buffer that will contain the read data. 110 | * Its size must be 192 bytes. This data can be parsed by 111 | * parse_IFR_data_config(). 112 | * @retval int It returns 0 if successful, or a number not equal to 0 in 113 | * case of error (ACI_ERROR, UNSUPPORTED_VERSION) 114 | */ 115 | int read_IFR(uint8_t data[192]); 116 | 117 | /** 118 | * @brief Verify raw data from IFR (3 64-bytes blocks). 119 | * @param ifr_data Pointer to the buffer that will contain the data to verify. 120 | * Its size must be 192 bytes. 121 | * @retval int It returns 0 if successful, or a number not equal to 0 in 122 | case of error (ACI_ERROR, BLE_UTIL_WRONG_VERIFY) 123 | */ 124 | uint8_t verify_IFR(const IFR_config_TypeDef *ifr_data); 125 | 126 | /** 127 | * @brief Program raw data to IFR (3 64-bytes blocks). 128 | * @param ifr_image Pointer to the buffer that will contain the data to program. 129 | * Its size must be 192 bytes. 130 | * @retval int It returns 0 if successful 131 | */ 132 | int program_IFR(const IFR_config_TypeDef *ifr_image); 133 | 134 | /** 135 | * @brief Parse IFR raw data. 136 | * @param data Pointer to the raw data: last 64 bytes read from IFR sector. 137 | * @param IFR_config Data structure that will be filled with parsed data. 138 | * @retval None 139 | */ 140 | void parse_IFR_data_config(const uint8_t data[64], IFR_config2_TypeDef *IFR_config); 141 | 142 | /** 143 | * @brief Check for the correctness of parsed data. 144 | * @param IFR_config Data structure filled with parsed data. 145 | * @retval int It returns 0 if successful, or PARSE_ERROR in case data is 146 | * not correct. 147 | */ 148 | int IFR_validate(IFR_config2_TypeDef *IFR_config); 149 | 150 | /** 151 | * @brief Modify IFR data. (Last 64-bytes block). 152 | * @param IFR_config Structure that contains the new parameters inside the 153 | * IFR configuration data. 154 | * @note It is highly recommended to parse the IFR configuration from 155 | * a working IFR block (this should be done with parse_IFR_data_config()). 156 | * Then it is possible to write the new parameters inside the IFR_config 157 | * structure. 158 | * @param data Pointer to the buffer that contains the original data. It 159 | * will be modified according to the new data in the IFR_config 160 | * structure. Then this data must be written in the last 161 | * 64-byte block in the IFR. 162 | * Its size must be 64 bytes. 163 | * @retval None 164 | */ 165 | void change_IFR_data_config(IFR_config2_TypeDef *IFR_config, uint8_t data[64]); 166 | 167 | /** 168 | * @brief Get BlueNRG hardware and firmware version 169 | * @param hwVersion This parameter returns the Hardware Version (i.e. CUT 3.0 = 0x30, CUT 3.1 = 0x31). 170 | * @param fwVersion This parameter returns the Firmware Version in the format 0xJJMN 171 | * where JJ = Major Version number, M = Minor Version number and N = Patch Version number. 172 | * @retval Status of the call 173 | */ 174 | uint8_t getBlueNRGVersion(uint8_t *hwVersion, uint16_t *fwVersion); 175 | 176 | /** 177 | * @brief Get BlueNRG updater version 178 | * @param version This parameter returns the updater version. If the updadter version is 0x03 179 | * the chip has the updater old, needs to update the bootloader. 180 | * @retval Status of the call 181 | */ 182 | uint8_t getBlueNRGUpdaterVersion(uint8_t *version); 183 | 184 | /** 185 | * @brief Verifies if the bootloader is patched or not. This function shall be used to fix a bug on 186 | * the HW bootloader related to the 32 MHz external crystal oscillator. 187 | * @retval TRUE if the HW bootloader is already patched, FALSE otherwise 188 | */ 189 | uint8_t isHWBootloader_Patched(void); 190 | 191 | #ifdef __cplusplus 192 | } 193 | #endif 194 | 195 | #endif /*__BLUENRG_UTILS_H */ 196 | 197 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 198 | -------------------------------------------------------------------------------- /src/compiler.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** 2 | * File Name : compiler.h 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 19-July-2012 6 | * Description : Compiler-dependent macros. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 21 | 22 | //#ifdef __ICCARM__ 23 | //#define PACKED 24 | //#else 25 | //#ifdef __GNUC__ 26 | //#undef __packed 27 | //#define __packed 28 | //#define PACKED __attribute__((packed)) 29 | //#else 30 | //#define PACKED 31 | //#define __packed 32 | //#endif 33 | //#endif 34 | // 35 | ///* Change this define to 1 if zero-length arrays are not supported by your compiler. */ 36 | //#define VARIABLE_SIZE 0 37 | 38 | #ifdef __GNUC__ 39 | #undef __packed 40 | #define __packed 41 | #define PACKED __attribute__((packed)) 42 | #else 43 | #define PACKED 44 | #endif 45 | 46 | /* Change this define to 1 if zero-length arrays are not supported by your compiler. */ 47 | #define VARIABLE_SIZE 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 54 | -------------------------------------------------------------------------------- /src/connection_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file connection_config.h 4 | * @author CL 5 | * @version V1.0.0 6 | * @date 04-July-2014 7 | * @brief This file defines macros for configuring the BlueNRG connection. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2014 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef _CONNECTION_CONFIG_ 40 | #define _CONNECTION_CONFIG_ 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @addtogroup X-CUBE-BLE1_Applications 47 | * @{ 48 | */ 49 | 50 | /** @addtogroup SensorDemo 51 | * @{ 52 | */ 53 | 54 | /** @defgroup CONNECTION_CONFIG 55 | * @{ 56 | */ 57 | 58 | /** @defgroup CONNECTION_CONFIG_Exported_Defines 59 | * @{ 60 | */ 61 | /* Exported defines ----------------------------------------------------------*/ 62 | #define SCAN_P (0x4000) 63 | #define SCAN_L (0x4000) 64 | 65 | /** 66 | * @brief Supervision timeout, arg in msec. 67 | */ 68 | //#define SUPERV_TIMEOUT (60) 69 | #define SUPERV_TIMEOUT (600) 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup CONNECTION_CONFIG_Exported_Macros 75 | * @{ 76 | */ 77 | /* Exported macros -----------------------------------------------------------*/ 78 | /** 79 | * @brief Connection period, arg in msec. 80 | */ 81 | #define CONN_P(x) ((int)((x)/1.25f)) 82 | /** 83 | * @brief Connection length, arg in msec. 84 | */ 85 | #define CONN_L(x) ((int)((x)/0.625f)) 86 | 87 | //#define CONN_P1 (CONN_P(10)) 88 | //#define CONN_P2 (CONN_P(10)) 89 | #define CONN_P1 (CONN_P(1000)) 90 | #define CONN_P2 (CONN_P(1000)) 91 | 92 | #define CONN_L1 (CONN_L(5)) 93 | #define CONN_L2 (CONN_L(5)) 94 | /** 95 | * @} 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | 106 | /** 107 | * @} 108 | */ 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /* _CONNECTION_CONFIG_ */ 115 | 116 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 117 | -------------------------------------------------------------------------------- /src/debug.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file debug.h 4 | * @author CL 5 | * @version V1.0.0 6 | * @date 04-July-2014 7 | * @brief This file defines print functions for debug purposes. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2014 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __DEBUG_H 40 | #define __DEBUG_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include 48 | 49 | /* Exported macro ------------------------------------------------------------*/ 50 | //#define DEBUG 51 | #ifdef DEBUG 52 | #include 53 | #define PRINTF(...) printf(__VA_ARGS__) 54 | #else 55 | #define PRINTF(...) 56 | #endif 57 | 58 | /* Print the data travelling over the SPI in the .csv format for the GUI*/ 59 | //#define PRINT_CSV_FORMAT 60 | #ifdef PRINT_CSV_FORMAT 61 | #include 62 | #define PRINT_CSV(...) printf(__VA_ARGS__) 63 | #else 64 | #define PRINT_CSV(...) 65 | #endif 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* __DEBUG_H */ 72 | 73 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 74 | -------------------------------------------------------------------------------- /src/eddystone_beacon.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file eddystone_beacon.h 4 | * @author MCD Application Team & Central Labs 5 | * @version 6 | * @date 20 May 2016 7 | * @brief 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2015 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef EDDYSTONE_BEACON_H 40 | #define EDDYSTONE_BEACON_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @addtogroup X-CUBE-BLE1_Applications 47 | * @{ 48 | */ 49 | 50 | /** @addtogroup Beacon 51 | * @{ 52 | */ 53 | 54 | /** @addtogroup EDDYSTONE_BEACON 55 | * @{ 56 | */ 57 | 58 | /* Includes ------------------------------------------------------------------*/ 59 | #if defined (__CC_ARM) 60 | #define ASSERT_CONCAT_(a, b) a##b 61 | #define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) 62 | /* These can't be used after statements in c89. */ 63 | #ifdef __COUNTER__ 64 | #define STATIC_ASSERT(e,m) \ 65 | ;enum { ASSERT_CONCAT(static_assert_, __COUNTER__) = 1/(!!(e)) } 66 | #else 67 | /* This can't be used twice on the same line so ensure if using in headers 68 | * that the headers are not included twice (by wrapping in #ifndef...#endif) 69 | * Note it doesn't cause an issue when used on same line of separate modules 70 | * compiled with gcc -combine -fwhole-program. */ 71 | #define static_assert(e,m) \ 72 | ;enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(e)) } 73 | #endif 74 | #endif 75 | 76 | /** @addtogroup EDDYSTONE_BEACON_Exported_Types 77 | * @{ 78 | */ 79 | /* Exported types ------------------------------------------------------------*/ 80 | 81 | /** 82 | * @brief Eddystone Beacon UID structure 83 | */ 84 | typedef struct 85 | { 86 | uint16_t AdvertisingInterval;/*!< Specifies the desired advertising interval. */ 87 | uint8_t CalibratedTxPower; /*!< Specifies the power at 0m. */ 88 | uint8_t * NamespaceID; /*!< Specifies the 10-byte namespace to which the beacon belongs. */ 89 | uint8_t * BeaconID; /*!< Specifies the unique 6-byte beacon ID within the specified namespace. */ 90 | } EddystoneUID_InitTypeDef; 91 | 92 | /** 93 | * @brief Eddystone Beacon URL structure 94 | */ 95 | typedef struct 96 | { 97 | uint16_t AdvertisingInterval;/*!< Specifies the desired advertising interval. */ 98 | uint8_t CalibratedTxPower; /*!< Specifies the power at 0m. */ 99 | uint8_t UrlScheme; /*!< Specifies the URL Encoded Scheme Prefix. */ 100 | uint8_t * Url; /*!< Specifies the Encoded URL (max 17 characters). */ 101 | uint8_t UrlLength; /*!< Specifies the length of the Encoded URL (max 17 characters). */ 102 | } EddystoneURL_InitTypeDef; 103 | /** 104 | * @} 105 | */ 106 | 107 | /** @addtogroup EDDYSTONE_BEACON_Exported_Constants 108 | * @{ 109 | */ 110 | /* Exported constants --------------------------------------------------------*/ 111 | #define MAC_ADDRESS 0x12, 0x34, 0x00, 0xE1, 0x80, 0x03 112 | 113 | #define EDDYSTONE_UID_BEACON_TYPE (0x01u) 114 | #define EDDYSTONE_URL_BEACON_TYPE (0x02u) 115 | 116 | #define HTTP_WWW (0x00u) 117 | #define HTTPS_WWW (0x01u) 118 | #define HTTP (0x02u) 119 | #define HTTPS (0x03u) 120 | 121 | #define DOT_COM_SLASH (0x00u) 122 | #define DOT_ORG_SLASH (0x01u) 123 | #define DOT_EDU_SLASH (0x02u) 124 | #define DOT_NET_SLASH (0x03u) 125 | #define DOT_INFO_SLASH (0x04u) 126 | #define DOT_BIZ_SLASH (0x05u) 127 | #define DOT_GOV_SLASH (0x06u) 128 | #define DOT_COM (0x07u) 129 | #define DOT_ORG (0x08u) 130 | #define DOT_EDU (0x09u) 131 | #define DOT_NET (0x0Au) 132 | #define DOT_INFO (0x0Bu) 133 | #define DOT_BIZ (0x0Cu) 134 | #define DOT_GOV (0x0Du) 135 | 136 | //#define EDDYSTONE_BEACON_TYPE (EDDYSTONE_URL_BEACON_TYPE) /* defined in configuration options */ 137 | 138 | #define ADVERTISING_INTERVAL_IN_MS (1000) 139 | #define CALIBRATED_TX_POWER_AT_0_M ((uint8_t) (-22)) 140 | #define URL_PREFIX HTTP 141 | 142 | #if (0 != (EDDYSTONE_BEACON_TYPE & (EDDYSTONE_BEACON_TYPE - 1))) 143 | #error "Please select only a single beacon type!" 144 | #endif 145 | 146 | #if ((ADVERTISING_INTERVAL_IN_MS <= 0) || (ADVERTISING_INTERVAL_IN_MS > 40959)) 147 | #error "Invalid advertising interval! Please select a value between 0 and 40959 ms." 148 | #endif 149 | 150 | #if (0 != (EDDYSTONE_BEACON_TYPE & EDDYSTONE_URL_BEACON_TYPE)) 151 | #if defined(__CC_ARM) | defined(__ICCARM__) 152 | static_assert(sizeof(PHYSICAL_WEB_URL) < 17, "The URL must be less than 17 characters."); 153 | #else 154 | #warning Please check that sizeof(PHYSICAL_WEB_URL) < 17 155 | #endif 156 | #endif 157 | /** 158 | * @} 159 | */ 160 | 161 | /* Exported Macros -----------------------------------------------------------*/ 162 | 163 | /** @addtogroup EDDYSTONE_BEACON_Exported_Functions 164 | * @{ 165 | */ 166 | /* Exported functions --------------------------------------------------------*/ 167 | 168 | tBleStatus EddystoneUID_Start(uint8_t* beaconID, uint8_t* nameSpace); 169 | 170 | tBleStatus EddystoneURL_Start(uint8_t* webURL); 171 | 172 | tBleStatus EddystoneUID_Init(EddystoneUID_InitTypeDef *EddystoneUID_Init); 173 | 174 | tBleStatus EddystoneURL_Init(EddystoneURL_InitTypeDef *EddystoneURL_Init); 175 | 176 | /** 177 | * @} 178 | */ 179 | 180 | /** 181 | * @} 182 | */ 183 | 184 | /** 185 | * @} 186 | */ 187 | 188 | /** 189 | * @} 190 | */ 191 | 192 | /** 193 | * @} 194 | */ 195 | 196 | #ifdef __cplusplus 197 | } 198 | #endif 199 | 200 | #endif /* EDDYSTONE_BEACON_H */ 201 | 202 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 203 | -------------------------------------------------------------------------------- /src/gp_timer.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** 2 | * File Name : gp_timer.h 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 19-July-2012 6 | * Description : General purpose timer library. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | #ifndef __GP_TIMER_H__ 17 | #define __GP_TIMER_H__ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include "ble_clock.h" 24 | #include "ble_status.h" 25 | 26 | /** 27 | * timer 28 | * 29 | * A structure that represents a timer. Use Timer_Set() to set the timer. 30 | * 31 | */ 32 | struct timer { 33 | 34 | #ifndef DOXYGEN_SHOULD_SKIP_THIS 35 | 36 | tClockTime start; 37 | tClockTime interval; 38 | 39 | #endif 40 | }; 41 | 42 | typedef void (* TIMER_HCI_TIMEOUT_NOTIFY_CALLBACK_TYPE)(void); 43 | 44 | /** 45 | * Timer_Set 46 | * 47 | * @param[in] t Pointer to a timer structure 48 | * @param[in] interval timeout value 49 | * 50 | * This function sets the timeout value of a timer. 51 | * 52 | */ 53 | void Timer_Set(struct timer *t, tClockTime interval); 54 | 55 | /** 56 | * Timer_Reset 57 | * 58 | * @param[in] t Pointer to a timer structure 59 | * 60 | * This function resets the timer with the same interval given 61 | * with Timer_Set, starting from the time it previously expired. 62 | * 63 | */ 64 | void Timer_Reset(struct timer *t); 65 | 66 | /** 67 | * Timer_Restart 68 | * 69 | * @param[in] t Pointer to a timer structure 70 | * 71 | * This function resets the timer with the same interval given 72 | * with Timer_Set, starting from the current time. 73 | * 74 | */ 75 | void Timer_Restart(struct timer *t); 76 | 77 | /** 78 | * Timer_Expired 79 | * 80 | * @param[in] t Pointer to a timer structure 81 | * 82 | * This function returns TRUE if timer is expired, FALSE otherwise. 83 | * 84 | */ 85 | int Timer_Expired(struct timer *t); 86 | 87 | /** 88 | * Timer_Expired 89 | * 90 | * @param[in] t Pointer to a timer structure 91 | * 92 | * This function returns the time needed for expiration. 93 | * 94 | * @return Time before timer's expiration. 95 | */ 96 | tClockTime Timer_Remaining(struct timer *t); 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /* __GP_TIMER_H__ */ 103 | -------------------------------------------------------------------------------- /src/hal.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** 2 | * File Name : hal.h 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 19-July-2012 6 | * Description : Header file which defines Hardware abstraction layer APIs 7 | * used by the BLE stack. It defines the set of functions 8 | * which needs to be ported to the target platform. 9 | ******************************************************************************** 10 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 11 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 12 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 13 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 14 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 15 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 16 | *******************************************************************************/ 17 | #ifndef __HAL_H__ 18 | #define __HAL_H__ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /****************************************************************************** 25 | * Includes 26 | *****************************************************************************/ 27 | #include 28 | #include 29 | 30 | 31 | /****************************************************************************** 32 | * Macros 33 | *****************************************************************************/ 34 | /* Little Endian buffer to host endianess conversion */ 35 | #define LE_TO_HOST_16(ptr) (uint16_t) ( ((uint16_t) \ 36 | *((uint8_t *)ptr)) | \ 37 | ((uint16_t) \ 38 | *((uint8_t *)ptr + 1) << 8 ) ) 39 | 40 | #define LE_TO_HOST_32(ptr) (uint32_t) ( ((uint32_t) \ 41 | *((uint8_t *)ptr)) | \ 42 | ((uint32_t) \ 43 | *((uint8_t *)ptr + 1) << 8) | \ 44 | ((uint32_t) \ 45 | *((uint8_t *)ptr + 2) << 16) | \ 46 | ((uint32_t) \ 47 | *((uint8_t *)ptr + 3) << 24) ) 48 | 49 | /* Big Endian buffer to host endianess conversion */ 50 | #define BE_TO_HOST_16(ptr) (uint16_t) ( ((uint16_t) \ 51 | *((uint8_t *)ptr)) << 8 | \ 52 | ((uint16_t) \ 53 | *((uint8_t *)ptr + 1) ) ) 54 | 55 | /* Store Value into a buffer in Little Endian Format */ 56 | #define HOST_TO_LE_16(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \ 57 | ((buf)[1] = (uint8_t) (val>>8) ) ) 58 | 59 | #define HOST_TO_LE_32(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \ 60 | ((buf)[1] = (uint8_t) (val>>8) ) , \ 61 | ((buf)[2] = (uint8_t) (val>>16) ) , \ 62 | ((buf)[3] = (uint8_t) (val>>24) ) ) 63 | 64 | 65 | /* Store Value into a buffer in Big Endian Format */ 66 | #define HOST_TO_BE_16(buf, val) ( ((buf)[1] = (uint8_t) (val) ) , \ 67 | ((buf)[0] = (uint8_t) (val>>8) ) ) 68 | 69 | #define DISABLE_INTERRUPTS() __disable_interrupt() 70 | #define ENABLE_INTERRUPTS() __enable_interrupt() 71 | #define SAVE_PRIMASK() uint32_t uwPRIMASK_Bit = __get_PRIMASK() 72 | #define ATOMIC_SECTION_BEGIN() uint32_t uwPRIMASK_Bit = __get_PRIMASK(); \ 73 | __disable_interrupt(); \ 74 | /* Must be called in the same or in a lower scope of SUSPEND_INTERRUPTS */ 75 | #define ATOMIC_SECTION_END() __set_PRIMASK(uwPRIMASK_Bit) 76 | 77 | /****************************************************************************** 78 | * Types 79 | *****************************************************************************/ 80 | 81 | /****************************************************************************** 82 | * Function Prototypes 83 | *****************************************************************************/ 84 | 85 | /** 86 | * Writes data to a serial interface. 87 | * 88 | * @param[in] data1 1st buffer 89 | * @param[in] data2 2nd buffer 90 | * @param[in] n_bytes1 number of bytes in 1st buffer 91 | * @param[in] n_bytes2 number of bytes in 2nd buffer 92 | */ 93 | //void Hal_Write_Serial(const void* data1, const void* data2, uint16_t n_bytes1, uint16_t n_bytes2); 94 | 95 | /** 96 | * Enable interrupts from HCI controller. 97 | */ 98 | void Enable_SPI_IRQ(void); 99 | 100 | /** 101 | * Disable interrupts from BLE controller. 102 | */ 103 | void Disable_SPI_IRQ(void); 104 | 105 | void Clear_SPI_EXTI_Flag(void); 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | #endif /* __HAL_H__ */ 112 | -------------------------------------------------------------------------------- /src/hal_types.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** 2 | * File Name : hal_types.h 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 19-July-2012 6 | * Description : This header file defines the basic data types used by the 7 | * BLE stack. 8 | ******************************************************************************** 9 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 10 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 11 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 12 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 13 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 14 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 15 | *******************************************************************************/ 16 | #ifndef __HAL_TYPES_H__ 17 | #define __HAL_TYPES_H__ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | #ifndef NULL 26 | #define NULL ((void *)0) 27 | #endif 28 | 29 | #ifndef __LITTLE_ENDIAN 30 | #define __LITTLE_ENDIAN 0 31 | #define __BIG_ENDIAN 1 32 | #endif 33 | 34 | /* Byte order conversions */ 35 | #if __BYTE_ORDER == __LITTLE_ENDIAN 36 | #define htobs(d) (d) 37 | #define htobl(d) (d) 38 | #define btohs(d) (d) 39 | #define btohl(d) (d) 40 | #elif __BYTE_ORDER == __BIG_ENDIAN 41 | #define htobs(d) (d<<8|d>>8) 42 | #define htobl(d) (d<<24|((d<<8)&0x00ff0000)|((d>>8)&0x0000ff00)|((d>>24)&0x000000ff)) 43 | #define btohs(d) (d<<8|d>>8) 44 | #define btohl(d) (d<<24|((d<<8)&0x00ff0000)|((d>>8)&0x0000ff00)|((d>>24)&0x000000ff)) 45 | #else 46 | #error "Unknown byte order" 47 | #endif 48 | 49 | typedef uint8_t BOOL; 50 | 51 | #ifndef TRUE 52 | #define TRUE (1) 53 | #endif 54 | 55 | #ifndef FALSE 56 | #define FALSE (0) 57 | #endif 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* __HAL_TYPES_H__ */ 64 | -------------------------------------------------------------------------------- /src/hci.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2016 STMicroelectronics ******************** 2 | * File Name : hci.h 3 | * Author : AMG RF FW team 4 | * Version : V1.1.0 5 | * Date : 18-July-2016 6 | * Description : Header file for framework required for handling HCI interface. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | #ifndef __HCI_H_ 17 | #define __HCI_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include "hal_types.h" 24 | #include "hal.h" 25 | #include "link_layer.h" 26 | #include 27 | 28 | #define HCI_READ_PACKET_SIZE 128 //71 29 | 30 | /** 31 | * Maximum payload of HCI commands that can be sent. Change this value if needed. 32 | * This value can be up to 255. 33 | */ 34 | #define HCI_MAX_PAYLOAD_SIZE 128 35 | 36 | /** @addtogroup Middlewares 37 | * @{ 38 | */ 39 | 40 | /** @defgroup ST 41 | * @{ 42 | */ 43 | 44 | /** @defgroup SimpleBlueNRG_HCI 45 | * @{ 46 | */ 47 | 48 | /*** Data types ***/ 49 | 50 | /* structure used to read received data */ 51 | typedef struct _tHciDataPacket 52 | { 53 | tListNode currentNode; 54 | uint8_t dataBuff[HCI_READ_PACKET_SIZE]; 55 | uint8_t data_len; 56 | } tHciDataPacket; 57 | 58 | struct hci_request { 59 | uint16_t ogf; 60 | uint16_t ocf; 61 | int event; 62 | void *cparam; 63 | int clen; 64 | void *rparam; 65 | int rlen; 66 | }; 67 | 68 | typedef enum 69 | { 70 | BUSY, 71 | AVAILABLE 72 | } HCI_CMD_STATUS_t; 73 | 74 | /** 75 | * This function must be used to pass the packet received from the HCI 76 | * interface to the BLE Stack HCI state machine. 77 | * 78 | * @param[in] hciReadPacket The packet that is received from HCI interface. 79 | * 80 | */ 81 | void HCI_Input(tHciDataPacket *hciReadPacket); 82 | 83 | /** 84 | * Initialization function. Must be done before any data can be received from 85 | * BLE controller. 86 | */ 87 | void HCI_Init(void); 88 | 89 | /** 90 | * Callback used to pass events to application. 91 | * 92 | * @param[in] pckt The event. 93 | * 94 | */ 95 | extern void HCI_Event_CB(void *pckt); 96 | 97 | /** 98 | * Processing function that must be called after an event is received from 99 | * HCI interface. Must be called outside ISR. It will call HCI_Event_CB if 100 | * necessary. 101 | */ 102 | void HCI_Process(void); 103 | 104 | /** 105 | * @brief Check if queue of HCI event is empty or not. 106 | * @note This funtion can be used to check if the event queue from BlueNRG is empty. This 107 | * is useful when checking if it is safe to go to sleep. 108 | * @return TRUE if event queue is empty. FALSE otherwhise. 109 | */ 110 | BOOL HCI_Queue_Empty(void); 111 | /** 112 | * Iterrupt service routine that must be called when the BlueNRG 113 | * reports a packet received or an event to the host through the 114 | * BlueNRG interrupt line. 115 | */ 116 | void HCI_Isr(void); 117 | 118 | int hci_send_req(struct hci_request *r, BOOL async); 119 | 120 | 121 | extern tListNode hciReadPktPool; 122 | extern tListNode hciReadPktRxQueue; 123 | 124 | /** 125 | * @} 126 | */ 127 | 128 | /** 129 | * @} 130 | */ 131 | 132 | /** 133 | * @} 134 | */ 135 | 136 | #ifdef __cplusplus 137 | } 138 | #endif 139 | 140 | #endif /* __HCI_H_ */ 141 | -------------------------------------------------------------------------------- /src/hci_le.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2016 STMicroelectronics ******************** 2 | * File Name : hci_le.h 3 | * Author : AMG RF FW team 4 | * Version : V1.1.0 5 | * Date : 18-July-2016 6 | * Description : Constants and functions for HCI layer. See Bluetooth Core 7 | * v 4.1, Vol. 2, Part E. 8 | ******************************************************************************** 9 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 10 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 11 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 12 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 13 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 14 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 15 | *******************************************************************************/ 16 | 17 | #ifndef __HCI_LE_H_ 18 | #define __HCI_LE_H_ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "hal_types.h" 25 | #include "link_layer.h" 26 | 27 | /** 28 | * @defgroup HCI_Error_codes HCI Error codes 29 | * @{ 30 | */ 31 | #define HCI_UNKNOWN_COMMAND 0x01 32 | #define HCI_NO_CONNECTION 0x02 33 | #define HCI_HARDWARE_FAILURE 0x03 34 | #define HCI_PAGE_TIMEOUT 0x04 35 | #define HCI_AUTHENTICATION_FAILURE 0x05 36 | #define HCI_PIN_OR_KEY_MISSING 0x06 37 | #define HCI_MEMORY_FULL 0x07 38 | #define HCI_CONNECTION_TIMEOUT 0x08 39 | #define HCI_MAX_NUMBER_OF_CONNECTIONS 0x09 40 | #define HCI_MAX_NUMBER_OF_SCO_CONNECTIONS 0x0a 41 | #define HCI_ACL_CONNECTION_EXISTS 0x0b 42 | #define HCI_COMMAND_DISALLOWED 0x0c 43 | #define HCI_REJECTED_LIMITED_RESOURCES 0x0d 44 | #define HCI_REJECTED_SECURITY 0x0e 45 | #define HCI_REJECTED_PERSONAL 0x0f 46 | #define HCI_HOST_TIMEOUT 0x10 47 | #define HCI_UNSUPPORTED_FEATURE 0x11 48 | #define HCI_INVALID_PARAMETERS 0x12 49 | #define HCI_OE_USER_ENDED_CONNECTION 0x13 50 | #define HCI_OE_LOW_RESOURCES 0x14 51 | #define HCI_OE_POWER_OFF 0x15 52 | #define HCI_CONNECTION_TERMINATED 0x16 53 | #define HCI_REPEATED_ATTEMPTS 0x17 54 | #define HCI_PAIRING_NOT_ALLOWED 0x18 55 | #define HCI_UNKNOWN_LMP_PDU 0x19 56 | #define HCI_UNSUPPORTED_REMOTE_FEATURE 0x1a 57 | #define HCI_SCO_OFFSET_REJECTED 0x1b 58 | #define HCI_SCO_INTERVAL_REJECTED 0x1c 59 | #define HCI_AIR_MODE_REJECTED 0x1d 60 | #define HCI_INVALID_LMP_PARAMETERS 0x1e 61 | #define HCI_UNSPECIFIED_ERROR 0x1f 62 | #define HCI_UNSUPPORTED_LMP_PARAMETER_VALUE 0x20 63 | #define HCI_ROLE_CHANGE_NOT_ALLOWED 0x21 64 | #define HCI_LMP_RESPONSE_TIMEOUT 0x22 65 | #define HCI_LMP_ERROR_TRANSACTION_COLLISION 0x23 66 | #define HCI_LMP_PDU_NOT_ALLOWED 0x24 67 | #define HCI_ENCRYPTION_MODE_NOT_ACCEPTED 0x25 68 | #define HCI_UNIT_LINK_KEY_USED 0x26 69 | #define HCI_QOS_NOT_SUPPORTED 0x27 70 | #define HCI_INSTANT_PASSED 0x28 71 | #define HCI_PAIRING_NOT_SUPPORTED 0x29 72 | #define HCI_TRANSACTION_COLLISION 0x2a 73 | #define HCI_QOS_UNACCEPTABLE_PARAMETER 0x2c 74 | #define HCI_QOS_REJECTED 0x2d 75 | #define HCI_CLASSIFICATION_NOT_SUPPORTED 0x2e 76 | #define HCI_INSUFFICIENT_SECURITY 0x2f 77 | #define HCI_PARAMETER_OUT_OF_RANGE 0x30 78 | #define HCI_ROLE_SWITCH_PENDING 0x32 79 | #define HCI_SLOT_VIOLATION 0x34 80 | #define HCI_ROLE_SWITCH_FAILED 0x35 81 | #define HCI_EIR_TOO_LARGE 0x36 82 | #define HCI_SIMPLE_PAIRING_NOT_SUPPORTED 0x37 83 | #define HCI_HOST_BUSY_PAIRING 0x38 84 | #define HCI_CONN_REJ_NO_CH_FOUND 0x39 85 | #define HCI_CONTROLLER_BUSY 0x3A 86 | #define HCI_UNACCEPTABLE_CONN_INTERV 0x3B 87 | #define HCI_DIRECTED_ADV_TIMEOUT 0x3C 88 | #define HCI_CONN_TERM_MIC_FAIL 0x3D 89 | #define HCI_CONN_FAIL_TO_BE_ESTABL 0x3E 90 | #define HCI_MAC_CONN_FAILED 0x3F 91 | /** 92 | * @} 93 | */ 94 | 95 | 96 | /* 97 | * HCI library functions. 98 | * Each function returns 0 in case of success, otherwise one of the error codes. 99 | */ 100 | 101 | int hci_reset(void); 102 | 103 | int hci_disconnect(uint16_t handle, uint8_t reason); 104 | 105 | int hci_le_set_advertise_enable(uint8_t enable); 106 | 107 | int hci_le_set_advertising_parameters(uint16_t min_interval, uint16_t max_interval, uint8_t advtype, 108 | uint8_t own_bdaddr_type, uint8_t direct_bdaddr_type, const tBDAddr direct_bdaddr, uint8_t chan_map, 109 | uint8_t filter); 110 | 111 | int hci_le_set_scan_parameters(uint8_t type, uint16_t interval, 112 | uint16_t window, uint8_t own_bdaddr_type, 113 | uint8_t filter); 114 | 115 | int hci_le_set_scan_enable(uint8_t enable, uint8_t filter_dup); 116 | 117 | int hci_le_set_advertising_data(uint8_t length, const uint8_t data[]); 118 | 119 | int hci_le_set_scan_resp_data(uint8_t length, const uint8_t data[]); 120 | 121 | int hci_le_rand(uint8_t random_number[8]); 122 | 123 | int hci_le_read_advertising_channel_tx_power(int8_t *tx_power_level); 124 | 125 | int hci_acl_data(const uint8_t * data, uint16_t len); 126 | 127 | int hci_le_set_random_address(tBDAddr bdaddr); 128 | 129 | int hci_read_bd_addr(tBDAddr bdaddr); 130 | 131 | int hci_le_read_white_list_size(uint8_t *size); 132 | 133 | int hci_le_clear_white_list(void); 134 | 135 | int hci_le_add_device_to_white_list(uint8_t bdaddr_type, tBDAddr bdaddr); 136 | 137 | int hci_le_remove_device_from_white_list(uint8_t bdaddr_type, tBDAddr bdaddr); 138 | 139 | int hci_le_encrypt(uint8_t key[16], uint8_t plaintextData[16], uint8_t encryptedData[16]); 140 | 141 | int hci_le_ltk_request_reply(uint8_t key[16]); 142 | 143 | int hci_le_ltk_request_neg_reply(void); 144 | 145 | int hci_le_read_buffer_size(uint16_t *pkt_len, uint8_t *max_pkt); 146 | 147 | int hci_le_create_connection(uint16_t interval, uint16_t window, uint8_t initiator_filter, uint8_t peer_bdaddr_type, 148 | const tBDAddr peer_bdaddr, uint8_t own_bdaddr_type, uint16_t min_interval, uint16_t max_interval, 149 | uint16_t latency, uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length); 150 | 151 | int hci_le_create_connection_cancel(void); 152 | 153 | int hci_read_transmit_power_level(uint16_t *conn_handle, uint8_t type, int8_t * tx_level); 154 | 155 | int hci_read_rssi(uint16_t *conn_handle, int8_t * rssi); 156 | 157 | int hci_le_read_local_supported_features(uint8_t *features); 158 | 159 | int hci_le_read_channel_map(uint16_t conn_handle, uint8_t ch_map[5]); 160 | 161 | int hci_le_read_supported_states(uint8_t states[8]); 162 | 163 | int hci_le_receiver_test(uint8_t frequency); 164 | 165 | int hci_le_transmitter_test(uint8_t frequency, uint8_t length, uint8_t payload); 166 | 167 | int hci_le_test_end(uint16_t *num_pkts); 168 | 169 | int hci_le_read_local_version(uint8_t *hci_version, uint16_t *hci_revision, uint8_t *lmp_pal_version, 170 | uint16_t *manufacturer_name, uint16_t *lmp_pal_subversion); 171 | 172 | #ifdef __cplusplus 173 | } 174 | #endif 175 | 176 | #endif /* __HCI_LE_H_ */ 177 | -------------------------------------------------------------------------------- /src/link_layer.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** 2 | * File Name : link_layer.h 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 19-July-2012 6 | * Description : Header file for BlueNRG's link layer. It contains 7 | * definition of functions for link layer, most of which are 8 | * mapped to HCI commands. 9 | ******************************************************************************** 10 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 11 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 12 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 13 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 14 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 15 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 16 | *******************************************************************************/ 17 | 18 | #ifndef _LINK_LAYER_H 19 | #define _LINK_LAYER_H 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #include 26 | 27 | /** @addtogroup Middlewares 28 | * @{ 29 | */ 30 | 31 | /** @defgroup ST 32 | * @{ 33 | */ 34 | 35 | /** @defgroup SimpleBlueNRG_HCI 36 | * @{ 37 | */ 38 | 39 | /** 40 | *@addtogroup GAP GAP 41 | *@brief API for GAP layer. 42 | *@{ 43 | */ 44 | 45 | /** 46 | *@name Advertising filter 47 | *Advertising policy for filtering (white list related) 48 | *@{ 49 | */ 50 | #define NO_WHITE_LIST_USE (0x00) /**< Process scan and connection requests from all devices (i.e., the White List is not in use) */ 51 | #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 */ 52 | #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 */ 53 | #define WHITE_LIST_FOR_ALL (0x03) /**< Process scan and connection requests only from devices in the White List. */ 54 | /** 55 | * @} 56 | */ 57 | 58 | 59 | /** 60 | * Bluetooth 48 bit address (in little-endian order). 61 | */ 62 | typedef uint8_t tBDAddr[6]; 63 | 64 | 65 | /** 66 | *@name Bluetooth address types 67 | * Bluetooth address types 68 | *@{ 69 | */ 70 | #define PUBLIC_ADDR (0) 71 | #define RANDOM_ADDR (1) 72 | #define STATIC_RANDOM_ADDR (1) 73 | #define RESOLVABLE_PRIVATE_ADDR (2) 74 | #define NON_RESOLVABLE_PRIVATE_ADDR (3) 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | *@name Directed advertising types 81 | * Type of advertising during directed advertising 82 | *@{ 83 | */ 84 | #define HIGH_DUTY_CYCLE_DIRECTED_ADV (1) 85 | #define LOW_DUTY_CYCLE_DIRECTED_ADV (4) 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @name Advertising type 92 | * @{ 93 | */ 94 | 95 | /** 96 | * undirected scannable and connectable 97 | */ 98 | #define ADV_IND (0x00) 99 | 100 | /** 101 | * directed non scannable 102 | */ 103 | #define ADV_DIRECT_IND (0x01) 104 | 105 | /** 106 | * scannable non connectable 107 | */ 108 | #define ADV_SCAN_IND (0x02) 109 | 110 | /** 111 | * non-connectable and no scan response 112 | */ 113 | #define ADV_NONCONN_IND (0x03) 114 | 115 | /** 116 | * scan response 117 | */ 118 | #define SCAN_RSP (0x04) 119 | 120 | /** 121 | * @} 122 | */ 123 | 124 | /* 0X05-0XFF RESERVED */ 125 | 126 | /** 127 | * @name Advertising ranges 128 | * @{ 129 | */ 130 | 131 | /** 132 | * lowest allowed interval value for connectable types(20ms)..multiple of 625us 133 | */ 134 | #define ADV_INTERVAL_LOWEST_CONN (0X0020) 135 | 136 | /** 137 | * highest allowed interval value (10.24s)..multiple of 625us. 138 | */ 139 | #define ADV_INTERVAL_HIGHEST (0X4000) 140 | 141 | /** 142 | * lowest allowed interval value for non connectable types 143 | * (100ms)..multiple of 625us. 144 | */ 145 | #define ADV_INTERVAL_LOWEST_NONCONN (0X00a0) 146 | 147 | /** 148 | * @} 149 | */ 150 | 151 | /** 152 | * @name Advertising channels 153 | * @{ 154 | */ 155 | #define ADV_CH_37 0x01 156 | #define ADV_CH_38 0x02 157 | #define ADV_CH_39 0x04 158 | /** 159 | * @} 160 | */ 161 | 162 | /** 163 | * @name Scan_types Scan types 164 | * @{ 165 | */ 166 | #define PASSIVE_SCAN 0 167 | #define ACTIVE_SCAN 1 168 | /** 169 | * @} 170 | */ 171 | 172 | /** 173 | * @} 174 | */ 175 | 176 | /** 177 | * @} 178 | */ 179 | 180 | /** 181 | * @} 182 | */ 183 | 184 | /** 185 | * @} 186 | */ 187 | 188 | #ifdef __cplusplus 189 | } 190 | #endif 191 | 192 | #endif /* _LINK_LAYER_H */ 193 | -------------------------------------------------------------------------------- /src/osal.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** 2 | * File Name : osal.h 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 19-July-2012 6 | * Description : This header file defines the OS abstraction layer used by 7 | * the BLE stack. OSAL defines the set of functions 8 | * which needs to be ported to target operating system and 9 | * target platform. 10 | ******************************************************************************** 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 13 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 14 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 15 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 16 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | *******************************************************************************/ 18 | 19 | #ifndef __OSAL_H__ 20 | #define __OSAL_H__ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /****************************************************************************** 27 | * Includes 28 | *****************************************************************************/ 29 | #include 30 | #ifdef __ICCARM__ 31 | #include 32 | #endif 33 | 34 | /****************************************************************************** 35 | * Macros 36 | *****************************************************************************/ 37 | 38 | 39 | /****************************************************************************** 40 | * Function Prototypes 41 | *****************************************************************************/ 42 | 43 | /** 44 | * This function copies size number of bytes from a 45 | * memory location pointed by src to a destination 46 | * memory location pointed by dest 47 | * 48 | * @param[in] dest Destination address 49 | * @param[in] src Source address 50 | * @param[in] size size in the bytes 51 | * 52 | * @return Address of the destination 53 | */ 54 | 55 | extern void* Osal_MemCpy(void *dest,const void *src, unsigned int size); 56 | 57 | 58 | /** 59 | * This function sets first number of bytes, specified 60 | * by size, to the destination memory pointed by ptr 61 | * to the specified value 62 | * 63 | * @param[in] ptr Destination address 64 | * @param[in] value Value to be set 65 | * @param[in] size Size in the bytes 66 | * 67 | * @return Address of the destination 68 | */ 69 | 70 | extern void* Osal_MemSet(void *ptr, int value, unsigned int size); 71 | 72 | /** 73 | * Osal_Get_Cur_Time 74 | * 75 | * returns the current time in milliseconds 76 | */ 77 | /** 78 | * Returns the number of ticks (1 tick = 1 millisecond) 79 | * 80 | * @return Time in milliseconds 81 | */ 82 | uint32_t Osal_Get_Cur_Time(void); 83 | 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /* __OSAL_H__ */ 90 | -------------------------------------------------------------------------------- /src/sensor_service.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file sensor_service.h 4 | * @author CL 5 | * @version V1.0.0 6 | * @date 04-July-2014 7 | * @brief 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2014 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef _SENSOR_SERVICE_H_ 40 | #define _SENSOR_SERVICE_H_ 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | #include "hal_types.h" 44 | #include "bluenrg_gatt_server.h" 45 | #include "bluenrg_gap.h" 46 | #include "string.h" 47 | #include "bluenrg_gap_aci.h" 48 | #include "bluenrg_gatt_aci.h" 49 | #include "hci_const.h" 50 | #include "gp_timer.h" 51 | #include "bluenrg_hal_aci.h" 52 | #include "bluenrg_aci_const.h" 53 | #include "hci.h" 54 | #include "hci_le.h" 55 | #include "hal.h" 56 | #include "sm.h" 57 | #include "debug.h" 58 | #include 59 | #include 60 | 61 | /** @addtogroup X-CUBE-BLE1_Applications 62 | * @{ 63 | */ 64 | 65 | /** @addtogroup SensorDemo 66 | * @{ 67 | */ 68 | 69 | /** @addtogroup SENSOR_SERVICE 70 | * @{ 71 | */ 72 | 73 | /** @addtogroup SENSOR_SERVICE_Exported_Defines 74 | * @{ 75 | */ 76 | /* Exported defines ----------------------------------------------------------*/ 77 | // Default Name 78 | #define DEFAULT_DEVICE_NAME 'B','l','u','e','N','R','G' 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @addtogroup SENSOR_SERVICE_Exported_Types 84 | * @{ 85 | */ 86 | typedef int i32_t; 87 | 88 | /** 89 | * @brief Structure containing acceleration value (in mg) of each axis. 90 | */ 91 | typedef struct { 92 | i32_t AXIS_X; 93 | i32_t AXIS_Y; 94 | i32_t AXIS_Z; 95 | } AxesRaw_t; 96 | /** 97 | * @} 98 | */ 99 | 100 | /** @addtogroup SENSOR_SERVICE_Exported_Functions 101 | * @{ 102 | */ 103 | class SensorServiceClass 104 | { 105 | public: 106 | tBleStatus begin(const char *name, uint8_t addr[BDADDR_SIZE]); 107 | 108 | void setConnectable(void); 109 | int isConnected(void); 110 | 111 | tBleStatus Add_Acc_Service(void); 112 | tBleStatus Free_Fall_Notify(void); 113 | tBleStatus Acc_Update(AxesRaw_t *data); 114 | 115 | tBleStatus Add_Environmental_Sensor_Service(void); 116 | tBleStatus Temp_Update(int16_t temp); 117 | tBleStatus Press_Update(uint32_t press); 118 | tBleStatus Humidity_Update(uint16_t humidity); 119 | 120 | tBleStatus Add_Time_Service(void); 121 | void Update_Time_Characteristics(void); 122 | tBleStatus Seconds_Update(void); 123 | tBleStatus Minutes_Notify(void); 124 | 125 | tBleStatus Add_LED_Service(void); 126 | bool LED_State(void) {return ledState;} 127 | 128 | void GAP_ConnectionComplete_CB(uint8_t addr[BDADDR_SIZE], uint16_t handle); 129 | void GAP_DisconnectionComplete_CB(void); 130 | void Read_Request_CB(uint16_t handle); 131 | void Attribute_Modified_CB(uint16_t handle, uint8_t data_length, 132 | uint8_t *att_data); 133 | 134 | uint16_t sampleServHandle, TXCharHandle, RXCharHandle; 135 | uint16_t accServHandle, freeFallCharHandle, accCharHandle; 136 | uint16_t envSensServHandle, tempCharHandle, pressCharHandle, humidityCharHandle; 137 | 138 | uint16_t timeServHandle, secondsCharHandle, minuteCharHandle; 139 | uint16_t ledServHandle, ledButtonCharHandle; 140 | 141 | private: 142 | volatile uint16_t connection_handle = 0; 143 | 144 | volatile bool connected = FALSE; 145 | volatile bool set_connectable = TRUE; 146 | volatile bool notification_enabled = FALSE; 147 | 148 | volatile AxesRaw_t axes_data; 149 | volatile int16_t temp_data; 150 | volatile uint32_t press_data; 151 | volatile uint16_t hum_data; 152 | 153 | char dev_name[8] = {AD_TYPE_COMPLETE_LOCAL_NAME, DEFAULT_DEVICE_NAME}; 154 | uint8_t dev_nameLen; 155 | bool ledState = false; 156 | uint32_t previousMinuteValue = 0; 157 | }; 158 | 159 | extern SensorServiceClass SensorService; 160 | 161 | /** 162 | * @} 163 | */ 164 | 165 | /** 166 | * @} 167 | */ 168 | 169 | /** 170 | * @} 171 | */ 172 | 173 | /** 174 | * @} 175 | */ 176 | 177 | #endif /* _SENSOR_SERVICE_H_ */ 178 | 179 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 180 | -------------------------------------------------------------------------------- /src/sm.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** 2 | * File Name : sm.h 3 | * Author : AMS - HEA&RF BU 4 | * Version : V1.0.0 5 | * Date : 19-July-2012 6 | * Description : Header file for BlueNRG's security manager. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | #ifndef __SM_H__ 17 | #define __SM_H__ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /****************************************************************************** 24 | * Macros 25 | *****************************************************************************/ 26 | /** @addtogroup Middlewares 27 | * @{ 28 | */ 29 | 30 | /** @defgroup ST 31 | * @{ 32 | */ 33 | 34 | /** @defgroup SimpleBlueNRG_HCI 35 | * @{ 36 | */ 37 | 38 | /** 39 | *@addtogroup GAP GAP 40 | *@brief API for GAP layer. 41 | *@{ 42 | */ 43 | 44 | /* IO capabilities */ 45 | /** 46 | * @anchor IO_capabilities 47 | * @name IO capabilities 48 | * @{ 49 | */ 50 | #define IO_CAP_DISPLAY_ONLY (0x00) 51 | #define IO_CAP_DISPLAY_YES_NO (0x01) 52 | #define IO_CAP_KEYBOARD_ONLY (0x02) 53 | #define IO_CAP_NO_INPUT_NO_OUTPUT (0x03) 54 | #define IO_CAP_KEYBOARD_DISPLAY (0x04) 55 | /** 56 | * @} 57 | */ 58 | 59 | /** 60 | * @anchor Auth_req 61 | * @name Authentication requirements 62 | * @{ 63 | */ 64 | #define BONDING (0x01) 65 | #define NO_BONDING (0x00) 66 | /** 67 | * @} 68 | */ 69 | 70 | /** 71 | * @anchor MITM_req 72 | * @name MITM protection requirements 73 | * @{ 74 | */ 75 | #define MITM_PROTECTION_NOT_REQUIRED (0x00) 76 | #define MITM_PROTECTION_REQUIRED (0x01) 77 | /** 78 | * @} 79 | */ 80 | 81 | /** 82 | * @anchor OOB_Data 83 | * @name Out-Of-Band data 84 | * @{ 85 | */ 86 | #define OOB_AUTH_DATA_ABSENT (0x00) 87 | #define OOB_AUTH_DATA_PRESENT (0x01) 88 | /** 89 | * @} 90 | */ 91 | 92 | /** 93 | * @anchor Author_req 94 | * @name Authorization requirements 95 | * @{ 96 | */ 97 | #define AUTHORIZATION_NOT_REQUIRED (0x00) 98 | #define AUTHORIZATION_REQUIRED (0x01) 99 | /** 100 | * @} 101 | */ 102 | 103 | /** 104 | * @anchor Conn_authorization 105 | * @name Connection authorization 106 | * @{ 107 | */ 108 | #define CONNECTION_AUTHORIZED (0x01) 109 | #define CONNECTION_REJECTED (0x02) 110 | /** 111 | * @} 112 | */ 113 | 114 | /** 115 | * @anchor Use_fixed_pin 116 | * @name Use fixed pin 117 | * @{ 118 | */ 119 | #define USE_FIXED_PIN_FOR_PAIRING (0x00) 120 | #define DONOT_USE_FIXED_PIN_FOR_PAIRING (0x01) 121 | /** 122 | * @} 123 | */ 124 | 125 | /** 126 | * @anchor link_security_status 127 | * @name Link security status 128 | * @{ 129 | */ 130 | #define SM_LINK_AUTHENTICATED (0x01) 131 | #define SM_LINK_AUTHORIZED (0x02) 132 | #define SM_LINK_ENCRYPTED (0x04) 133 | /** 134 | * @} 135 | */ 136 | 137 | /** 138 | * @anchor SMP_pairing_failed_codes 139 | * @name SMP pairing failed reason codes 140 | * @{ 141 | */ 142 | #define PASSKEY_ENTRY_FAILED (0x01) 143 | #define OOB_NOT_AVAILABLE (0x02) 144 | #define AUTH_REQ_CANNOT_BE_MET (0x03) 145 | #define CONFIRM_VALUE_FAILED (0x04) 146 | #define PAIRING_NOT_SUPPORTED (0x05) 147 | #define INSUFF_ENCRYPTION_KEY_SIZE (0x06) 148 | #define CMD_NOT_SUPPORTED (0x07) 149 | #define UNSPECIFIED_REASON (0x08) 150 | #define VERY_EARLY_NEXT_ATTEMPT (0x09) 151 | #define SM_INVALID_PARAMS (0x0A) 152 | /** 153 | * @} 154 | */ 155 | 156 | /** 157 | * @anchor pairing_failed_codes 158 | * @name Pairing failed error codes 159 | * Error codes in @ref EVT_BLUE_GAP_PAIRING_CMPLT event 160 | * @{ 161 | */ 162 | #define SM_PAIRING_SUCCESS (0x00) 163 | #define SM_PAIRING_TIMEOUT (0x01) 164 | #define SM_PAIRING_FAILED (0x02) 165 | /** 166 | * @} 167 | */ 168 | 169 | /** 170 | * @} 171 | */ 172 | 173 | /** 174 | * @} 175 | */ 176 | 177 | /** 178 | * @} 179 | */ 180 | 181 | /** 182 | * @} 183 | */ 184 | 185 | #ifdef __cplusplus 186 | } 187 | #endif 188 | 189 | #endif /* __SM_H__ */ 190 | -------------------------------------------------------------------------------- /src/stm32_bluenrg_ble.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32_bluenrg_ble.h 4 | * @author CL 5 | * @version V1.0.0 6 | * @date 04-July-2014 7 | * @brief 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2014 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __STM32_BLUENRG_BLE_H 40 | #define __STM32_BLUENRG_BLE_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "stm32_def.h" 48 | 49 | 50 | /** @addtogroup BSP 51 | * @{ 52 | */ 53 | 54 | /** @addtogroup X-NUCLEO-IDB0xA1 55 | * @{ 56 | */ 57 | 58 | /** @addtogroup STM32_BLUENRG_BLE 59 | * @{ 60 | */ 61 | 62 | /** @defgroup STM32_BLUENRG_BLE_Exported_Functions 63 | * @{ 64 | */ 65 | 66 | // FIXME: add prototypes for BlueNRG here 67 | void BNRG_SPI_Init(void); 68 | void BlueNRG_RST(void); 69 | uint8_t BlueNRG_DataPresent(void); 70 | void BlueNRG_HW_Bootloader(void); 71 | int32_t BlueNRG_SPI_Read_All(uint8_t *buffer, 72 | uint8_t buff_size); 73 | int32_t BlueNRG_SPI_Write(uint8_t* data1, 74 | uint8_t* data2, 75 | uint8_t Nb_bytes1, 76 | uint8_t Nb_bytes2); 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif 97 | 98 | #endif /* __STM32_BLUENRG_BLE_H */ 99 | 100 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 101 | 102 | --------------------------------------------------------------------------------