ST Expansion SW Team / libNDEF

Dependents:   mbed-os-nfc04a1 Wiagro-Lanza34-XDot

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lib_NDEF_Bluetooth.h Source File

lib_NDEF_Bluetooth.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    lib_NDEF_Bluetooth.h
00004   * @author  MMY Application Team
00005   * @version $Revision: 2475 $
00006   * @date    $Date: 2016-06-24 12:11:59 +0200 (Fri, 24 Jun 2016) $
00007   * @brief   This file help to manage a NDEF file representing a Bluetooth pairing info.
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/myliberty  
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
00022   * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
00023   * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
00024   * See the License for the specific language governing permissions and
00025   * limitations under the License.
00026   *
00027   ******************************************************************************
00028   */
00029 
00030 /* Define to prevent recursive inclusion -------------------------------------*/
00031 #ifndef __LIB_NDEF_BLUETOOTH_H
00032 #define __LIB_NDEF_BLUETOOTH_H
00033 
00034 
00035 /* Includes ------------------------------------------------------------------*/
00036 #include "lib_NDEF.h"
00037 
00038 /** @addtogroup lib_NDEF_Bluetooth
00039   * @{
00040   */
00041    
00042 /** @brief MIME type for the Bluetooth BR/EDR Out-Of-Band data. */
00043 #define NDEF_BLUETOOTH_BREDR_MIME_TYPE "application/vnd.bluetooth.ep.oob"
00044 /** @brief MIME type for the Bluetooth Low Energy Out-Of-Band data. */
00045 #define NDEF_BLUETOOTH_BLE_MIME_TYPE "application/vnd.bluetooth.le.oob"
00046 
00047    
00048 /** @brief Enumerates the Extended Inquiry Responses, as defined in the Bluetooth v4.0 core specification. */
00049 typedef enum {
00050   BLUETOOTH_EIR_FLAGS                           = 0x01, /**<  Bluetooth flags:\n
00051                                                               b0: LE limited Discoverable Mode,\n
00052                                                               b1: LE general Discoverable Mode,\n
00053                                                               b2: BR/EDR not supported,\n
00054                                                               b3: Simultaneous LE & BR/EDR Conroller,\n
00055                                                               b4: Simultaneous LE & BR/EDR Host
00056                                                           */
00057   BLUETOOTH_EIR_SERVICE_CLASS_UUID_PARTIAL_16   = 0x02, /**< Bluetooth service UUID on 16-bits (partial list) */
00058   BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_16  = 0x03, /**< Bluetooth service UUID on 16-bits (complete list) */
00059   BLUETOOTH_EIR_SERVICE_CLASS_UUID_PARTIAL_32   = 0x04, /**< Bluetooth service UUID on 32-bits (partial list) */
00060   BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_32  = 0x05, /**< Bluetooth service UUID on 32-bits (complete list) */
00061   BLUETOOTH_EIR_SERVICE_CLASS_UUID_PARTIAL_128  = 0x06, /**< Bluetooth service UUID on 128-bits (partial list) */
00062   BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_128 = 0x07, /**< Bluetooth service UUID on 128-bits (complete list) */
00063   BLUETOOTH_EIR_SHORT_LOCAL_NAME                = 0x08, /**< Shortened local name */
00064   BLUETOOTH_EIR_COMPLETE_LOCAL_NAME             = 0x09, /**< Complete local name */
00065   BLUETOOTH_EIR_TX_POWER_LEVEL                  = 0x0A, /**< TX Power Level (1 byte): 0xXX:-127 to +127dBm */
00066   BLUETOOTH_EIR_DEVICE_CLASS                    = 0x0D, /**< Class of device, Format defined in Assigned Numbers */
00067   BLUETOOTH_EIR_SIMPLE_PAIRING_HASH             = 0x0E, /**< Simple Pairing Hash C (16 octets), Format defined in [Vol. 2], Part H Section 7.2.2*/
00068   BLUETOOTH_EIR_SIMPLE_PAIRING_RANDOMIZER       = 0x0F, /**< Simple Pairing Randomizer R (16 octets), Format defined in[Vol. 2], Part H Section 7.2.2 */
00069   BLUETOOTH_EIR_SECURITY_MANAGER_TK_VALUE       = 0x10, /**< TK Value: Value as used in pairing over LE Physical channel. Format defined in [Vol. 3], Part H Section 2.3*/
00070   BLUETOOTH_EIR_SECURITY_MANAGER_FLAGS          = 0x11, /**< Flags (1 octet):\n
00071                                                              b0: OOB Flags Field (0 = OOB data not present, 1 = OOB data present),\n
00072                                                              b1: LE supported (Host) (i.e. bit 65 of LMP Extended Feature bits Page 1),\n
00073                                                              b2: Simultaneous LE and BR/EDR to Same Device Capable (Host) (i.e. bit 66 of LMP Extended Feature bits Page 1)\n
00074                                                              b3: Address type (0 = Public Address, 1 = Random Address)
00075                                                            */
00076   BLUETOOTH_EIR_SLAVE_CONNECTION_INTERVAL_RANGE = 0x12, /**< Slave Connection Interval Range: The first 2 octets defines the minimum value for the connection interval, The second 2 octets defines the maximum value for the connection interval */
00077   BLUETOOTH_EIR_SERVICE_SOLICITATION_16         = 0x14, /**< Service UUIDs: List of 16 bit Service UUIDs*/
00078   BLUETOOTH_EIR_SERVICE_SOLICITATION_128        = 0x15, /**< Service UUIDs: List of 128 bit Service UUID*/
00079   BLUETOOTH_EIR_SERVICE_DATA                    = 0x16, /**< Service Data (2 or more octets): The first 2 octets contain the 16 bit Service UUID followed by additional service data */
00080   BLUETOOTH_EIR_APPEARANCE                      = 0x19, /**< UUID for `Appearance`: The Appearance characteristic value shall be the enumerated value as defined by Bluetooth Assigned Numbers document. */
00081   BLUETOOTH_EIR_BLE_DEVICE_ADDRESS              = 0x1B, /**< 6 LSB bytes: Device address, 7th byte: Address type (Public/Random) */
00082   BLUETOOTH_EIR_BLE_ROLE                        = 0x1C, /**< Device Role: Periph only, Central only, Periph prefered, Central prefered */
00083   BLUETOOTH_EIR_MANUFACTURER_DATA               = 0xFF  /**< Manufacturer Specific Data (2 or more octets): The first 2 octets contain the Company Identifier Code followed by additional manufacturer specific data */
00084 } Ndef_Bluetooth_Eir_Types_t;
00085    
00086    
00087 /** @brief Bluetooth Flag field: LE limited discovery. */ 
00088 #define NDEF_BLE_LIMITED_DISCOVERY_FLAG     (0x1)
00089 /** @brief Bluetooth Flag field: LE general discovery. */ 
00090 #define NDEF_BLE_GENERAL_DISCOVERY_FLAG     (0x2)
00091 /** @brief Bluetooth Flag field: BR/EDR compliant. */ 
00092 #define NDEF_BLE_NOT_BREDR_COMPLIANT_FLAG   (0x4)
00093 /** @brief Bluetooth Flag field: LE & BR/EDR simultaneous support. */ 
00094 #define NDEF_BLE_LE_BREDR_SIMULTANEOUS_FLAG (0x8)
00095 
00096 /** @brief Enumerates the Bluetooth LE address types. */
00097 typedef enum {
00098   NDEF_BLE_PUBLIC_ADDRESS_TYPE  = 0x0, /**< Public Device Address. */
00099   NDEF_BLE_RANDOM_ADDRESS_TYPE  = 0x1, /**< Random Device Address. */
00100   NDEF_BLE_UNDEF_ADDRESS_TYPE   = 0xff /**< Device Address is undefined. */
00101 } Ndef_BLE_Address_Type_t;
00102 
00103 /** @brief Enumerates Bluetooth LE Roles */
00104 typedef enum {
00105   NDEF_BLE_ROLE_PERIPH_ONLY       = 0x0, /**< Only Peripheral Role supported. */
00106   NDEF_BLE_ROLE_CENTRAL_ONLY      = 0x1, /**< Only Central Role supported. */
00107   NDEF_BLE_ROLE_PERIPH_PREFERRED  = 0x2, /**< Peripheral and Central Role supported, Peripheral Role preferred for connection establishment. */
00108   NDEF_BLE_ROLE_CENTRAL_PREFERRED = 0x3, /**< Peripheral and Central Role supported, Central Role preferred for connection establishment. */
00109   NDEF_BLE_ROLE_UNDEF             = 0xff /**< LE Role is undefined. */
00110 } Ndef_BLE_Role_t;
00111 
00112 /** @brief Enumerates Bluetooth protocols */
00113 typedef enum {
00114   NDEF_BLUETOOTH_BREDR, /**< Standard bluetooth */
00115   NDEF_BLUETOOTH_BLE    /**< Bluetooth Low Energy */
00116 } Ndef_Bluetooth_type_t;
00117 
00118 /** @brief Helper macro to set a particular EIR in the EIR mask of a `Ndef_Bluetooth_OOB_t` instance.
00119   * @param bt     Pointer to a `Ndef_Bluetooth_OOB_t` struct
00120   * @param option Index of the option based on the `Ndef_Bluetooth_Eir_Types_t` */
00121 #define NDEF_BLUETOOTH_SET_OPTIONAL_MASK(bt,option)   do { bt->OptionalMask |= (1<<(option)); } while (0)  
00122 
00123 /** @brief Helper macro to unset a particular EIR in the EIR mask of a `Ndef_Bluetooth_OOB_t` instance.
00124   * @param bt     Pointer to a `Ndef_Bluetooth_OOB_t` struct
00125   * @param option Index of the option based on the `Ndef_Bluetooth_Eir_Types_t` */
00126 #define NDEF_BLUETOOTH_UNSET_OPTIONAL_MASK(bt,option) do {bt->OptionalMask &= ~(1<<(option)); } while (0)  
00127 
00128 /** @brief Helper macro to know if a particular EIR is present in the EIR mask of a `Ndef_Bluetooth_OOB_t` instance.
00129   * @param bt     Pointer to a `Ndef_Bluetooth_OOB_t` struct
00130   * @param option Index of the option based on the `Ndef_Bluetooth_Eir_Types_t` */
00131 #define NDEF_BLUETOOTH_GET_OPTIONAL_MASK(bt,option) ((bt->OptionalMask & (1<<(option))) >>  (option))
00132 
00133 /** @brief Helper macro to create a mask for a particular EIR.
00134   * @param option Index of the option based on the `Ndef_Bluetooth_Eir_Types_t` */
00135 #define NDEF_BLUETOOTH_OPTION(option)               (1<<(option))
00136 
00137 /** @brief    Bluetooth Out-Of-Band data structure.
00138   * @details  Some fields are shared by both Br/Edr & LE Bluetooth, some are specific...
00139   *           No union used here to comply with the Cube coding guidelines, despite the fact that it could have save memory space.
00140   */
00141 typedef struct
00142 {
00143   /* Mandatory fields */
00144   Ndef_Bluetooth_type_t   Type;                               /**< *Mandatory*: Bluetooth type (Br/Edr or LE). */
00145   char                    DeviceAddress[6];                   /**< *Mandatory*: Device address. For LE: 6 LSB of Device Address EIR. */
00146   /* Optionnal common fields */
00147   uint32_t                OptionalMask;                       /**< This Mask is used to keep track of EIRs present in the OOB: each bit index corresponds to a `Ndef_Bluetooth_Eir_Types_t` value. */
00148   uint8_t                 Flags;                              /**< Flags from BLUETOOTH_EIR_FLAGS. */
00149 
00150   uint16_t                ClassUUID16[0xff/2];                /**< UUIDs from BLUETOOTH_EIR_SERVICE_CLASS_UUID_PARTIAL_16 or BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_16. */
00151   uint32_t                ClassUUID32[0xff/4];                /**< UUIDs from BLUETOOTH_EIR_SERVICE_CLASS_UUID_PARTIAL_32 or BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_32. */
00152   uint32_t                ClassUUID128[0xff/16][4];           /**< UUIDs from BLUETOOTH_EIR_SERVICE_CLASS_UUID_PARTIAL_128 or BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_128. */
00153   uint8_t                 nbUUID16;                           /**< Number of UUIDs speficied in ClassUUID16. */
00154   uint8_t                 nbUUID32;                           /**< Number of UUIDs speficied in ClassUUID32. */
00155   uint8_t                 nbUUID128;                          /**< Number of UUIDs speficied in ClassUUID128. */
00156   
00157   char                    LocalName[0xff];                    /**< Device local name from BLUETOOTH_EIR_SHORT_LOCAL_NAME or BLUETOOTH_EIR_COMPLETE_LOCAL_NAME. */
00158   uint8_t                 DeviceClass[3];                     /**< Class of device from BLUETOOTH_EIR_DEVICE_CLASS. */
00159   // if no TPL, TPL is unknown
00160   uint8_t                 TxPowerLevel;                       /**< TX power Level from BLUETOOTH_EIR_TX_POWER_LEVEL. */
00161   
00162   uint8_t                 SMFlags;                            /**< Security Manager Flags from BLUETOOTH_EIR_SECURITY_MANAGER_FLAGS. */
00163   uint16_t                SlaveConnIntervalRange[2];          /**< Slave Connection Interval Range from BLUETOOTH_EIR_SLAVE_CONNECTION_INTERVAL_RANGE. */
00164   uint16_t                ServiceSolicitation16[0xff/2];      /**< Service Solicitation from BLUETOOTH_EIR_SERVICE_SOLICITATION_16. */
00165   uint32_t                ServiceSolicitation128[0xff/16][4]; /**< Service Solicitation from BLUETOOTH_EIR_SERVICE_SOLICITATION_128. */
00166   uint8_t                 nbServiceSolicitation16;            /**< Number of UUIDs in ServiceSolicitation16. */
00167   uint8_t                 nbServiceSolicitation128;           /**< Number of UUIDs in ServiceSolicitation128. */
00168   /* for br/edr only */
00169     uint8_t                 SimplePairingHash[16];            /**< *For Br/Edr only*: Simple Pairing Hash from BLUETOOTH_EIR_SIMPLE_PAIRING_HASH. */
00170     uint8_t                 SimplePairingRandomizer[16];      /**< *For Br/Edr only*: Simple Pairing Randomizer from BLUETOOTH_EIR_SIMPLE_PAIRING_RANDOMIZER. */
00171   /* BLE mandatory fields */
00172     Ndef_BLE_Address_Type_t DeviceAddressType;                /**< *For LE only*, *Mandatory*: Address Type, MSB of the Device Address EIR (Public or Random) */
00173     Ndef_BLE_Role_t         Role;                             /**< *For LE only*, *Mandatory*: LE Role from BLUETOOTH_EIR_BLE_ROLE and defined in `Ndef_BLE_Role_t`. */
00174   /* BLE optional fields */
00175     uint8_t                 SecureManagerTK[16];              /**< *For LE only*: Security Manager TK from BLUETOOTH_EIR_SECURITY_MANAGER_TK_VALUE. */
00176     uint16_t                Appearance;                       /**< *For LE only*: Appearance from BLUETOOTH_EIR_APPEARANCE. */
00177   /* track number of unparsed EIR */
00178   uint8_t                 nbUnknown;                          /**< Number of EIRs not parsed because of an unknown EIR type. */
00179   uint8_t                 nbServiceData;                      /**< Number of EIRs not parsed because being of type BLUETOOTH_EIR_SERVICE_DATA. */
00180   uint8_t                 nbManufacturerData;                 /**< Number of EIRs not parsed because being of type BLUETOOTH_EIR_MANUFACTURER_DATA. */
00181 } Ndef_Bluetooth_OOB_t ;
00182 
00183 /** @brief    Extended Inquiry Response format.
00184   * @details  This structure is used to parse/build EIRs in the Bluetooth OOB.
00185   */
00186 typedef  struct {
00187   uint8_t length;   /**< Length of the EIRs, including the type field (1 byte). */
00188   uint8_t type;     /**< EIR type as defined in `Ndef_Bluetooth_Eir_Types_t`. */
00189   uint8_t value[1]; /**< single-element array, to keep track of the address of the EIR data */
00190 }  NDEF_EIR_t ;
00191 
00192 uint16_t NDEF_ReadBluetoothOOB( sRecordInfo_t *pRecordStruct, Ndef_Bluetooth_OOB_t *pBluetooth );
00193 uint16_t NDEF_AppendBluetoothOOB( Ndef_Bluetooth_OOB_t *pBluetooth, char* RecordID, I2C* mi2cChannel );
00194 void NDEF_PrepareBluetoothMessage(Ndef_Bluetooth_OOB_t  *pBluetooth, uint8_t *pNDEFMessage, uint16_t *size );
00195 uint32_t NDEF_GetBluetoothOOBLength( Ndef_Bluetooth_OOB_t *pBluetooth );
00196 
00197 
00198 
00199 /** @}
00200   */
00201 
00202 #endif /* __LIB_NDEF_BLUETOOTH_H */
00203 
00204 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/