Fork for the GitHub

Committer:
DiegoOstuni
Date:
Thu Nov 14 10:34:11 2019 +0000
Revision:
0:de13951f30f6
Add files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DiegoOstuni 0:de13951f30f6 1 /**
DiegoOstuni 0:de13951f30f6 2 ******************************************************************************
DiegoOstuni 0:de13951f30f6 3 * @file lib_NDEF_Bluetooth.c
DiegoOstuni 0:de13951f30f6 4 * @author MMY Application Team
DiegoOstuni 0:de13951f30f6 5 * @version $Revision: 2702 $
DiegoOstuni 0:de13951f30f6 6 * @date $Date: 2016-07-13 18:45:05 +0200 (Wed, 13 Jul 2016) $
DiegoOstuni 0:de13951f30f6 7 * @ingroup LibNDEF_Bluetooth
DiegoOstuni 0:de13951f30f6 8 * @brief This file help to manage a NDEF file representing a Bluetooth pairing info.
DiegoOstuni 0:de13951f30f6 9 ******************************************************************************
DiegoOstuni 0:de13951f30f6 10 * @attention
DiegoOstuni 0:de13951f30f6 11 *
DiegoOstuni 0:de13951f30f6 12 * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
DiegoOstuni 0:de13951f30f6 13 *
DiegoOstuni 0:de13951f30f6 14 * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
DiegoOstuni 0:de13951f30f6 15 * You may not use this file except in compliance with the License.
DiegoOstuni 0:de13951f30f6 16 * You may obtain a copy of the License at:
DiegoOstuni 0:de13951f30f6 17 *
DiegoOstuni 0:de13951f30f6 18 * http://www.st.com/myliberty
DiegoOstuni 0:de13951f30f6 19 *
DiegoOstuni 0:de13951f30f6 20 * Unless required by applicable law or agreed to in writing, software
DiegoOstuni 0:de13951f30f6 21 * distributed under the License is distributed on an "AS IS" BASIS,
DiegoOstuni 0:de13951f30f6 22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
DiegoOstuni 0:de13951f30f6 23 * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
DiegoOstuni 0:de13951f30f6 24 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
DiegoOstuni 0:de13951f30f6 25 * See the License for the specific language governing permissions and
DiegoOstuni 0:de13951f30f6 26 * limitations under the License.
DiegoOstuni 0:de13951f30f6 27 *
DiegoOstuni 0:de13951f30f6 28 ******************************************************************************
DiegoOstuni 0:de13951f30f6 29 */
DiegoOstuni 0:de13951f30f6 30
DiegoOstuni 0:de13951f30f6 31 /* Includes ------------------------------------------------------------------*/
DiegoOstuni 0:de13951f30f6 32 #include "lib_NDEF_Bluetooth.h"
DiegoOstuni 0:de13951f30f6 33
DiegoOstuni 0:de13951f30f6 34
DiegoOstuni 0:de13951f30f6 35
DiegoOstuni 0:de13951f30f6 36 /** @addtogroup lib_NDEF_Bluetooth Bluetooth OOB library
DiegoOstuni 0:de13951f30f6 37 * @ingroup libNDEF
DiegoOstuni 0:de13951f30f6 38 * @{
DiegoOstuni 0:de13951f30f6 39 * @brief This module is used to manage a Bluetooth Out-Of-Band NDEF message, to start a communication based on Bluetooth.
DiegoOstuni 0:de13951f30f6 40 * @details The Bluetooth OOB format is described by the Bluetooth v4.0 core specification.
DiegoOstuni 0:de13951f30f6 41 * It consists in a list of Extended Inquiry Responses formated as length-type-value.
DiegoOstuni 0:de13951f30f6 42 * This module allows to build, write & read such data embedded in a NDEF message.
DiegoOstuni 0:de13951f30f6 43 * @section Bluetooth_Library_Usage Bluetooth NDEF Library usage
DiegoOstuni 0:de13951f30f6 44 * @subsection Bluetooth_Write_BrEdr How to write a Bluetooth Br/Edr OOB
DiegoOstuni 0:de13951f30f6 45 * 1. Instanciate & initialize a `Ndef_Bluetooth_OOB_t` structure, specifying:
DiegoOstuni 0:de13951f30f6 46 * - the `NDEF_BLUETOOTH_BREDR` type.
DiegoOstuni 0:de13951f30f6 47 * - the mandatory Device Address field.
DiegoOstuni 0:de13951f30f6 48 * - any other optional EIRs.
DiegoOstuni 0:de13951f30f6 49 *
DiegoOstuni 0:de13951f30f6 50 * Ndef_Bluetooth_OOB_t w_bredr_oob = { .Type = NDEF_BLUETOOTH_BREDR,
DiegoOstuni 0:de13951f30f6 51 * .DeviceAddress = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06},
DiegoOstuni 0:de13951f30f6 52 * .OptionalMask = NDEF_BLUETOOTH_OPTION(BLUETOOTH_EIR_COMPLETE_LOCAL_NAME) |
DiegoOstuni 0:de13951f30f6 53 * NDEF_BLUETOOTH_OPTION(BLUETOOTH_EIR_DEVICE_CLASS) |
DiegoOstuni 0:de13951f30f6 54 * NDEF_BLUETOOTH_OPTION(BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_16),
DiegoOstuni 0:de13951f30f6 55 * .LocalName = "MyDevice",
DiegoOstuni 0:de13951f30f6 56 * .nbUUID16 = 2,
DiegoOstuni 0:de13951f30f6 57 * .ClassUUID16 = {0x111E,0x110B},
DiegoOstuni 0:de13951f30f6 58 * .DeviceClass = {0x04,0x04,0x20}
DiegoOstuni 0:de13951f30f6 59 * };
DiegoOstuni 0:de13951f30f6 60 * 2. Clear the NDEF message and call the `NDEF_AppendBluetoothOOB` function to write the OOB:
DiegoOstuni 0:de13951f30f6 61 *
DiegoOstuni 0:de13951f30f6 62 * NDEF_ClearNDEF();
DiegoOstuni 0:de13951f30f6 63 * NDEF_AppendBluetoothOOB ( &w_bredr_oob, NULL );
DiegoOstuni 0:de13951f30f6 64 * @note Second parameter of `NDEF_AppendBluetoothOOB` can be used to specify an ID for the OOB record (useful for the NDEF Handover message, where specifying an ID is mandatory)
DiegoOstuni 0:de13951f30f6 65 * @subsection Bluetooth_Write_Ble How to write a Bluetooth LE OOB
DiegoOstuni 0:de13951f30f6 66 * 1. Instanciate & initialize a `Ndef_Bluetooth_OOB_t` structure, specifying:
DiegoOstuni 0:de13951f30f6 67 * - the `NDEF_BLUETOOTH_BLE` type.
DiegoOstuni 0:de13951f30f6 68 * - the mandatory Device Address & LE Role fields.
DiegoOstuni 0:de13951f30f6 69 * - any other optional EIRs.
DiegoOstuni 0:de13951f30f6 70 *
DiegoOstuni 0:de13951f30f6 71 * Ndef_Bluetooth_OOB_t w_ble_oob = { .Type = NDEF_BLUETOOTH_BLE,
DiegoOstuni 0:de13951f30f6 72 * .DeviceAddress = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06},
DiegoOstuni 0:de13951f30f6 73 * .DeviceAddressType = NDEF_BLE_PUBLIC_ADDRESS_TYPE,
DiegoOstuni 0:de13951f30f6 74 * .Role = NDEF_BLE_ROLE_PERIPH_ONLY,
DiegoOstuni 0:de13951f30f6 75 * .OptionalMask = NDEF_BLUETOOTH_OPTION(BLUETOOTH_EIR_COMPLETE_LOCAL_NAME),
DiegoOstuni 0:de13951f30f6 76 * .LocalName = "MyDeviceName",
DiegoOstuni 0:de13951f30f6 77 * };
DiegoOstuni 0:de13951f30f6 78 *
DiegoOstuni 0:de13951f30f6 79 * 2. Clear the NDEF message and call the `NDEF_AppendBluetoothOOB` function to write the OOB:
DiegoOstuni 0:de13951f30f6 80 *
DiegoOstuni 0:de13951f30f6 81 * NDEF_ClearNDEF();
DiegoOstuni 0:de13951f30f6 82 * NDEF_AppendBluetoothOOB ( &w_ble_oob, NULL );
DiegoOstuni 0:de13951f30f6 83 * @note Second parameter of `NDEF_AppendBluetoothOOB` can be used to specify an ID for the OOB record (useful for the NDEF Handover message, where specifying an ID is mandatory)
DiegoOstuni 0:de13951f30f6 84 *
DiegoOstuni 0:de13951f30f6 85 * @subsection Bluetooth_Read How to read a Bluetooth OOB
DiegoOstuni 0:de13951f30f6 86 * 1. Read the 1st record of the NDEF message:
DiegoOstuni 0:de13951f30f6 87 *
DiegoOstuni 0:de13951f30f6 88 * sRecordInfo_t record;
DiegoOstuni 0:de13951f30f6 89 * NDEF_ReadNDEF(NDEF_Buffer);
DiegoOstuni 0:de13951f30f6 90 * NDEF_IdentifyBuffer(record,NDEF_Buffer);
DiegoOstuni 0:de13951f30f6 91 * 2. Decode the Bluetooth OOB:
DiegoOstuni 0:de13951f30f6 92 *
DiegoOstuni 0:de13951f30f6 93 * Ndef_Bluetooth_OOB_t bluetooth_oob;
DiegoOstuni 0:de13951f30f6 94 * NDEF_ReadBluetoothOOB(&record,&bluetooth_oob);
DiegoOstuni 0:de13951f30f6 95 * 3. Use the data from the `Ndef_Bluetooth_OOB_t` structure to start a Bluetooth connexion.
DiegoOstuni 0:de13951f30f6 96 *
DiegoOstuni 0:de13951f30f6 97 *
DiegoOstuni 0:de13951f30f6 98 *
DiegoOstuni 0:de13951f30f6 99 */
DiegoOstuni 0:de13951f30f6 100
DiegoOstuni 0:de13951f30f6 101
DiegoOstuni 0:de13951f30f6 102 /**
DiegoOstuni 0:de13951f30f6 103 * @brief This function copies an array, changing its endianness, usefull to convert data to BLE endianess.
DiegoOstuni 0:de13951f30f6 104 * @param dst Pointer on 1st element of the destination array.
DiegoOstuni 0:de13951f30f6 105 * @param src pointer on 1st element of the source array .
DiegoOstuni 0:de13951f30f6 106 * @param length Number of element to copy.
DiegoOstuni 0:de13951f30f6 107 * @return Pointer to the destination array.
DiegoOstuni 0:de13951f30f6 108 */
DiegoOstuni 0:de13951f30f6 109 uint8_t* NDEF_BluetoothCopy(uint8_t* dst, uint8_t* src, uint32_t length)
DiegoOstuni 0:de13951f30f6 110 {
DiegoOstuni 0:de13951f30f6 111 uint32_t index;
DiegoOstuni 0:de13951f30f6 112 for(index = 0 ; index < length; index++)
DiegoOstuni 0:de13951f30f6 113 {
DiegoOstuni 0:de13951f30f6 114 dst[index] = src[length - index - 1];
DiegoOstuni 0:de13951f30f6 115 }
DiegoOstuni 0:de13951f30f6 116 return dst;
DiegoOstuni 0:de13951f30f6 117 }
DiegoOstuni 0:de13951f30f6 118
DiegoOstuni 0:de13951f30f6 119 /**
DiegoOstuni 0:de13951f30f6 120 * @brief This function reads a NDEF record and retrieves Bluetooth (BR/EDR or BLE) OOB information if present.
DiegoOstuni 0:de13951f30f6 121 * @param pRecord Pointer on the record structure.
DiegoOstuni 0:de13951f30f6 122 * @param pBluetooth Pointer on the structure to fill .
DiegoOstuni 0:de13951f30f6 123 * @retval NDEF_OK OOB information has been retrieved from the NDEF record.
DiegoOstuni 0:de13951f30f6 124 * @retval NDEF_ERROR OOB information cannot be retrieved.
DiegoOstuni 0:de13951f30f6 125 */
DiegoOstuni 0:de13951f30f6 126 uint16_t NDEF_ReadBluetoothOOB( sRecordInfo_t *pRecord, Ndef_Bluetooth_OOB_t *pBluetooth )
DiegoOstuni 0:de13951f30f6 127 {
DiegoOstuni 0:de13951f30f6 128 uint8_t* pData = pRecord->PayloadBufferAdd;
DiegoOstuni 0:de13951f30f6 129 uint8_t* OOBEnd = pRecord->PayloadBufferAdd + pRecord->PayloadLength;
DiegoOstuni 0:de13951f30f6 130
DiegoOstuni 0:de13951f30f6 131 pBluetooth->OptionalMask = 0;
DiegoOstuni 0:de13951f30f6 132 pBluetooth->nbServiceData = 0;
DiegoOstuni 0:de13951f30f6 133 pBluetooth->Role = NDEF_BLE_ROLE_UNDEF;
DiegoOstuni 0:de13951f30f6 134 pBluetooth->DeviceAddressType = NDEF_BLE_UNDEF_ADDRESS_TYPE;
DiegoOstuni 0:de13951f30f6 135 pBluetooth->nbUUID16 = 0;
DiegoOstuni 0:de13951f30f6 136 pBluetooth->nbUUID32 = 0;
DiegoOstuni 0:de13951f30f6 137 pBluetooth->nbUUID128 = 0;
DiegoOstuni 0:de13951f30f6 138 pBluetooth->nbServiceSolicitation16 = 0;
DiegoOstuni 0:de13951f30f6 139 pBluetooth->nbServiceSolicitation128 = 0;
DiegoOstuni 0:de13951f30f6 140
DiegoOstuni 0:de13951f30f6 141 if((pRecord->TypeLength == strlen(NDEF_BLUETOOTH_BREDR_MIME_TYPE)) &&
DiegoOstuni 0:de13951f30f6 142 !memcmp(pRecord->Type,NDEF_BLUETOOTH_BREDR_MIME_TYPE,strlen(NDEF_BLUETOOTH_BREDR_MIME_TYPE)))
DiegoOstuni 0:de13951f30f6 143 {
DiegoOstuni 0:de13951f30f6 144 pBluetooth->Type = NDEF_BLUETOOTH_BREDR;
DiegoOstuni 0:de13951f30f6 145 /* Retrieve mandatory OOB data: */
DiegoOstuni 0:de13951f30f6 146 /* 2 bytes for length and 6 bytes for device addr */
DiegoOstuni 0:de13951f30f6 147 NDEF_BluetoothCopy((uint8_t*)pBluetooth->DeviceAddress,&pData[2],sizeof(pBluetooth->DeviceAddress));
DiegoOstuni 0:de13951f30f6 148 pData += 8;
DiegoOstuni 0:de13951f30f6 149 } else if ((pRecord->TypeLength == strlen(NDEF_BLUETOOTH_BLE_MIME_TYPE)) &&
DiegoOstuni 0:de13951f30f6 150 !memcmp(pRecord->Type,NDEF_BLUETOOTH_BLE_MIME_TYPE,strlen(NDEF_BLUETOOTH_BLE_MIME_TYPE)))
DiegoOstuni 0:de13951f30f6 151 {
DiegoOstuni 0:de13951f30f6 152 pBluetooth->Type = NDEF_BLUETOOTH_BLE;
DiegoOstuni 0:de13951f30f6 153 /* for BLE, mandatory fields are in EIR */
DiegoOstuni 0:de13951f30f6 154 } else {
DiegoOstuni 0:de13951f30f6 155 /* This is an unknown MIME type */
DiegoOstuni 0:de13951f30f6 156 return NDEF_ERROR;
DiegoOstuni 0:de13951f30f6 157 }
DiegoOstuni 0:de13951f30f6 158
DiegoOstuni 0:de13951f30f6 159 /* EIR format: 1 byte for length, 1 byte for type, n bytes for data */
DiegoOstuni 0:de13951f30f6 160 while (pData < OOBEnd)
DiegoOstuni 0:de13951f30f6 161 {
DiegoOstuni 0:de13951f30f6 162 NDEF_EIR_t* rEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 163 /* +1 for EIR length byte */
DiegoOstuni 0:de13951f30f6 164 pData += rEIR->length + 1;
DiegoOstuni 0:de13951f30f6 165
DiegoOstuni 0:de13951f30f6 166 /* keep track of all EIR found */
DiegoOstuni 0:de13951f30f6 167 if(rEIR->type < 0x20)
DiegoOstuni 0:de13951f30f6 168 NDEF_BLUETOOTH_SET_OPTIONAL_MASK(pBluetooth,rEIR->type);
DiegoOstuni 0:de13951f30f6 169
DiegoOstuni 0:de13951f30f6 170 switch (rEIR->type)
DiegoOstuni 0:de13951f30f6 171 {
DiegoOstuni 0:de13951f30f6 172 case BLUETOOTH_EIR_FLAGS:
DiegoOstuni 0:de13951f30f6 173 pBluetooth->Flags = *rEIR->value;
DiegoOstuni 0:de13951f30f6 174 break;
DiegoOstuni 0:de13951f30f6 175
DiegoOstuni 0:de13951f30f6 176 case BLUETOOTH_EIR_SERVICE_CLASS_UUID_PARTIAL_16:
DiegoOstuni 0:de13951f30f6 177 case BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_16:
DiegoOstuni 0:de13951f30f6 178 pBluetooth->nbUUID16 = (rEIR->length - 1) / 2 ;
DiegoOstuni 0:de13951f30f6 179 NDEF_BluetoothCopy((uint8_t*)pBluetooth->ClassUUID16,rEIR->value,rEIR->length-1);
DiegoOstuni 0:de13951f30f6 180 break;
DiegoOstuni 0:de13951f30f6 181
DiegoOstuni 0:de13951f30f6 182 case BLUETOOTH_EIR_SERVICE_CLASS_UUID_PARTIAL_32:
DiegoOstuni 0:de13951f30f6 183 case BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_32:
DiegoOstuni 0:de13951f30f6 184 pBluetooth->nbUUID32 = (rEIR->length - 1) / 4 ;
DiegoOstuni 0:de13951f30f6 185 NDEF_BluetoothCopy((uint8_t*)pBluetooth->ClassUUID32,rEIR->value,rEIR->length-1);
DiegoOstuni 0:de13951f30f6 186 break;
DiegoOstuni 0:de13951f30f6 187
DiegoOstuni 0:de13951f30f6 188 case BLUETOOTH_EIR_SERVICE_CLASS_UUID_PARTIAL_128:
DiegoOstuni 0:de13951f30f6 189 case BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_128:
DiegoOstuni 0:de13951f30f6 190 pBluetooth->nbUUID128 = (rEIR->length - 1) / 16 ;
DiegoOstuni 0:de13951f30f6 191 NDEF_BluetoothCopy((uint8_t*)pBluetooth->ClassUUID128,rEIR->value,rEIR->length-1);
DiegoOstuni 0:de13951f30f6 192 break;
DiegoOstuni 0:de13951f30f6 193
DiegoOstuni 0:de13951f30f6 194 case BLUETOOTH_EIR_SHORT_LOCAL_NAME:
DiegoOstuni 0:de13951f30f6 195 case BLUETOOTH_EIR_COMPLETE_LOCAL_NAME:
DiegoOstuni 0:de13951f30f6 196 /* No worry about name length as max EIR length is 0xff using 1 byte for the type metadata */
DiegoOstuni 0:de13951f30f6 197 memcpy(pBluetooth->LocalName,rEIR->value,rEIR->length-1);
DiegoOstuni 0:de13951f30f6 198 pBluetooth->LocalName[rEIR->length] = '\0';
DiegoOstuni 0:de13951f30f6 199 break;
DiegoOstuni 0:de13951f30f6 200
DiegoOstuni 0:de13951f30f6 201 case BLUETOOTH_EIR_TX_POWER_LEVEL:
DiegoOstuni 0:de13951f30f6 202 pBluetooth->TxPowerLevel = *rEIR->value;
DiegoOstuni 0:de13951f30f6 203 break;
DiegoOstuni 0:de13951f30f6 204
DiegoOstuni 0:de13951f30f6 205 case BLUETOOTH_EIR_DEVICE_CLASS:
DiegoOstuni 0:de13951f30f6 206 NDEF_BluetoothCopy((uint8_t*)pBluetooth->DeviceClass,rEIR->value,sizeof(pBluetooth->DeviceClass));
DiegoOstuni 0:de13951f30f6 207 break;
DiegoOstuni 0:de13951f30f6 208
DiegoOstuni 0:de13951f30f6 209 case BLUETOOTH_EIR_SIMPLE_PAIRING_HASH:
DiegoOstuni 0:de13951f30f6 210 NDEF_BluetoothCopy((uint8_t*)pBluetooth->SimplePairingHash,rEIR->value,sizeof(pBluetooth->SimplePairingHash));
DiegoOstuni 0:de13951f30f6 211 break;
DiegoOstuni 0:de13951f30f6 212
DiegoOstuni 0:de13951f30f6 213 case BLUETOOTH_EIR_SIMPLE_PAIRING_RANDOMIZER:
DiegoOstuni 0:de13951f30f6 214 NDEF_BluetoothCopy((uint8_t*)pBluetooth->SimplePairingRandomizer,rEIR->value,sizeof(pBluetooth->SimplePairingRandomizer));
DiegoOstuni 0:de13951f30f6 215 break;
DiegoOstuni 0:de13951f30f6 216
DiegoOstuni 0:de13951f30f6 217 case BLUETOOTH_EIR_SECURITY_MANAGER_TK_VALUE:
DiegoOstuni 0:de13951f30f6 218 NDEF_BluetoothCopy((uint8_t*)pBluetooth->SecureManagerTK,rEIR->value,sizeof(pBluetooth->SecureManagerTK));
DiegoOstuni 0:de13951f30f6 219 break;
DiegoOstuni 0:de13951f30f6 220
DiegoOstuni 0:de13951f30f6 221 case BLUETOOTH_EIR_SECURITY_MANAGER_FLAGS:
DiegoOstuni 0:de13951f30f6 222 pBluetooth->SMFlags = *rEIR->value;
DiegoOstuni 0:de13951f30f6 223 break;
DiegoOstuni 0:de13951f30f6 224
DiegoOstuni 0:de13951f30f6 225 case BLUETOOTH_EIR_SLAVE_CONNECTION_INTERVAL_RANGE:
DiegoOstuni 0:de13951f30f6 226 NDEF_BluetoothCopy((uint8_t*)pBluetooth->SlaveConnIntervalRange,rEIR->value,sizeof(pBluetooth->SlaveConnIntervalRange));
DiegoOstuni 0:de13951f30f6 227 break;
DiegoOstuni 0:de13951f30f6 228
DiegoOstuni 0:de13951f30f6 229 case BLUETOOTH_EIR_SERVICE_SOLICITATION_16:
DiegoOstuni 0:de13951f30f6 230 pBluetooth->nbServiceSolicitation16 = (rEIR->length - 1) / 2 ;
DiegoOstuni 0:de13951f30f6 231 NDEF_BluetoothCopy((uint8_t*)pBluetooth->ServiceSolicitation16,rEIR->value,rEIR->length-1);
DiegoOstuni 0:de13951f30f6 232 break;
DiegoOstuni 0:de13951f30f6 233
DiegoOstuni 0:de13951f30f6 234 case BLUETOOTH_EIR_SERVICE_SOLICITATION_128:
DiegoOstuni 0:de13951f30f6 235 pBluetooth->nbServiceSolicitation128 = (rEIR->length - 1) / 16 ;
DiegoOstuni 0:de13951f30f6 236 NDEF_BluetoothCopy((uint8_t*)pBluetooth->ServiceSolicitation128,rEIR->value,rEIR->length-1);
DiegoOstuni 0:de13951f30f6 237 break;
DiegoOstuni 0:de13951f30f6 238
DiegoOstuni 0:de13951f30f6 239 case BLUETOOTH_EIR_SERVICE_DATA:
DiegoOstuni 0:de13951f30f6 240 /* a specific function should be used for this EIR */
DiegoOstuni 0:de13951f30f6 241 pBluetooth->nbServiceData++;
DiegoOstuni 0:de13951f30f6 242 break;
DiegoOstuni 0:de13951f30f6 243
DiegoOstuni 0:de13951f30f6 244 case BLUETOOTH_EIR_MANUFACTURER_DATA:
DiegoOstuni 0:de13951f30f6 245 /* a specific function should be used for this EIR */
DiegoOstuni 0:de13951f30f6 246 pBluetooth->nbManufacturerData++;
DiegoOstuni 0:de13951f30f6 247 break;
DiegoOstuni 0:de13951f30f6 248
DiegoOstuni 0:de13951f30f6 249 case BLUETOOTH_EIR_APPEARANCE:
DiegoOstuni 0:de13951f30f6 250 pBluetooth->Appearance = *(uint16_t *)rEIR->value;
DiegoOstuni 0:de13951f30f6 251 break;
DiegoOstuni 0:de13951f30f6 252
DiegoOstuni 0:de13951f30f6 253 case BLUETOOTH_EIR_BLE_DEVICE_ADDRESS:
DiegoOstuni 0:de13951f30f6 254 NDEF_BluetoothCopy((uint8_t*)pBluetooth->DeviceAddress,rEIR->value,sizeof(pBluetooth->DeviceAddress));
DiegoOstuni 0:de13951f30f6 255 pBluetooth->DeviceAddressType = (Ndef_BLE_Address_Type_t)rEIR->value[sizeof(pBluetooth->DeviceAddress)];
DiegoOstuni 0:de13951f30f6 256 break;
DiegoOstuni 0:de13951f30f6 257
DiegoOstuni 0:de13951f30f6 258 case BLUETOOTH_EIR_BLE_ROLE:
DiegoOstuni 0:de13951f30f6 259 pBluetooth->Role = (Ndef_BLE_Role_t) *rEIR->value;
DiegoOstuni 0:de13951f30f6 260 break;
DiegoOstuni 0:de13951f30f6 261
DiegoOstuni 0:de13951f30f6 262 default:
DiegoOstuni 0:de13951f30f6 263 pBluetooth->nbUnknown++;
DiegoOstuni 0:de13951f30f6 264 break;
DiegoOstuni 0:de13951f30f6 265 } /* switch rEIR->type */
DiegoOstuni 0:de13951f30f6 266 } /* while (pData < OOBEnd) */
DiegoOstuni 0:de13951f30f6 267 /* Check that BLE mandatory fields are there */
DiegoOstuni 0:de13951f30f6 268 if((pBluetooth->Type == NDEF_BLUETOOTH_BLE) &&
DiegoOstuni 0:de13951f30f6 269 (!NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_BLE_DEVICE_ADDRESS) ||
DiegoOstuni 0:de13951f30f6 270 !NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_BLE_ROLE)))
DiegoOstuni 0:de13951f30f6 271 return NDEF_ERROR;
DiegoOstuni 0:de13951f30f6 272
DiegoOstuni 0:de13951f30f6 273 return NDEF_OK;
DiegoOstuni 0:de13951f30f6 274 }
DiegoOstuni 0:de13951f30f6 275
DiegoOstuni 0:de13951f30f6 276 /**
DiegoOstuni 0:de13951f30f6 277 * @brief This function appends a Bluetooth OOB record to the NDEF message, using the OOB data given in the input structure.
DiegoOstuni 0:de13951f30f6 278 * @param pBluetooth Pointer on a `Ndef_Bluetooth_OOB_t` structure containing the OOB information.
DiegoOstuni 0:de13951f30f6 279 * @param RecordID ID to be used for this record (required for Handover case, can be set to NULL in other cases).
DiegoOstuni 0:de13951f30f6 280 * @retval NDEF_OK The Bluetooth OOB record has been appended.
DiegoOstuni 0:de13951f30f6 281 * @retval NDEF_ERROR_MEMORY_INTERNAL The Bluetooth OOB record cannot be appended due to memory size limitation.
DiegoOstuni 0:de13951f30f6 282 * @retval NDEF_ERROR The Bluetooth OOB record cannot be appended.
DiegoOstuni 0:de13951f30f6 283 */
DiegoOstuni 0:de13951f30f6 284 uint16_t NDEF_AppendBluetoothOOB( Ndef_Bluetooth_OOB_t *pBluetooth, char* RecordID, I2C* mi2cChannel )
DiegoOstuni 0:de13951f30f6 285 {
DiegoOstuni 0:de13951f30f6 286 sRecordInfo_t Record;
DiegoOstuni 0:de13951f30f6 287 uint16_t status;
DiegoOstuni 0:de13951f30f6 288
DiegoOstuni 0:de13951f30f6 289 Record.RecordFlags = TNF_MediaType;
DiegoOstuni 0:de13951f30f6 290 Record.RecordFlags |= (RecordID != NULL) ? IL_Mask : 0;
DiegoOstuni 0:de13951f30f6 291 Record.IDLength = strlen(RecordID);
DiegoOstuni 0:de13951f30f6 292 memcpy(Record.ID,RecordID,Record.IDLength);
DiegoOstuni 0:de13951f30f6 293
DiegoOstuni 0:de13951f30f6 294 if(pBluetooth->Type == NDEF_BLUETOOTH_BREDR)
DiegoOstuni 0:de13951f30f6 295 {
DiegoOstuni 0:de13951f30f6 296 Record.TypeLength = strlen(NDEF_BLUETOOTH_BREDR_MIME_TYPE);
DiegoOstuni 0:de13951f30f6 297 memcpy(Record.Type, NDEF_BLUETOOTH_BREDR_MIME_TYPE, Record.TypeLength);
DiegoOstuni 0:de13951f30f6 298 }
DiegoOstuni 0:de13951f30f6 299 else if (pBluetooth->Type == NDEF_BLUETOOTH_BLE)
DiegoOstuni 0:de13951f30f6 300 {
DiegoOstuni 0:de13951f30f6 301 Record.TypeLength = strlen(NDEF_BLUETOOTH_BLE_MIME_TYPE);
DiegoOstuni 0:de13951f30f6 302 memcpy(Record.Type, NDEF_BLUETOOTH_BLE_MIME_TYPE, Record.TypeLength);
DiegoOstuni 0:de13951f30f6 303 }
DiegoOstuni 0:de13951f30f6 304 else
DiegoOstuni 0:de13951f30f6 305 {
DiegoOstuni 0:de13951f30f6 306 return NDEF_ERROR;
DiegoOstuni 0:de13951f30f6 307 }
DiegoOstuni 0:de13951f30f6 308
DiegoOstuni 0:de13951f30f6 309 /* Generate OOB payload */
DiegoOstuni 0:de13951f30f6 310 Record.PayloadLength = NDEF_GetBluetoothOOBLength(pBluetooth);
DiegoOstuni 0:de13951f30f6 311 Record.PayloadBufferAdd = NDEF_Record_Buffer;
DiegoOstuni 0:de13951f30f6 312 if(Record.PayloadLength > NDEF_RECORD_MAX_SIZE)
DiegoOstuni 0:de13951f30f6 313 return NDEF_ERROR_MEMORY_INTERNAL;
DiegoOstuni 0:de13951f30f6 314
DiegoOstuni 0:de13951f30f6 315 /* pData: pointer to ease increment of record buffer address (byte granularity) */
DiegoOstuni 0:de13951f30f6 316 uint8_t* pData = Record.PayloadBufferAdd;
DiegoOstuni 0:de13951f30f6 317
DiegoOstuni 0:de13951f30f6 318 /* for BR-EDR Device address & length are managed outside EIR */
DiegoOstuni 0:de13951f30f6 319 if(pBluetooth->Type == NDEF_BLUETOOTH_BREDR)
DiegoOstuni 0:de13951f30f6 320 {
DiegoOstuni 0:de13951f30f6 321 *pData = Record.PayloadLength;
DiegoOstuni 0:de13951f30f6 322 pData += 2;
DiegoOstuni 0:de13951f30f6 323 NDEF_BluetoothCopy(pData,(uint8_t*)pBluetooth->DeviceAddress,sizeof(pBluetooth->DeviceAddress));
DiegoOstuni 0:de13951f30f6 324 pData+=sizeof(pBluetooth->DeviceAddress);
DiegoOstuni 0:de13951f30f6 325 }
DiegoOstuni 0:de13951f30f6 326
DiegoOstuni 0:de13951f30f6 327 /* wEIR: pointer to ease write to the buffer.
DiegoOstuni 0:de13951f30f6 328 * length always set with an additional +1 corresponding to the EIR type byte.
DiegoOstuni 0:de13951f30f6 329 * pData increment is always done with an additional +1 corresponding to the EIR length byte.
DiegoOstuni 0:de13951f30f6 330 */
DiegoOstuni 0:de13951f30f6 331 NDEF_EIR_t* wEIR;
DiegoOstuni 0:de13951f30f6 332
DiegoOstuni 0:de13951f30f6 333
DiegoOstuni 0:de13951f30f6 334 if(pBluetooth->Type == NDEF_BLUETOOTH_BLE)
DiegoOstuni 0:de13951f30f6 335 {
DiegoOstuni 0:de13951f30f6 336 /* following EIR are mandatory for BLE */
DiegoOstuni 0:de13951f30f6 337 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 338 wEIR->length = sizeof(pBluetooth->DeviceAddress) + sizeof(pBluetooth->DeviceAddressType) + 1;
DiegoOstuni 0:de13951f30f6 339 wEIR->type = BLUETOOTH_EIR_BLE_DEVICE_ADDRESS;
DiegoOstuni 0:de13951f30f6 340 NDEF_BluetoothCopy(wEIR->value, (uint8_t*)pBluetooth->DeviceAddress,sizeof(pBluetooth->DeviceAddress));
DiegoOstuni 0:de13951f30f6 341 wEIR->value[sizeof(pBluetooth->DeviceAddress)] = pBluetooth->DeviceAddressType;
DiegoOstuni 0:de13951f30f6 342 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 343
DiegoOstuni 0:de13951f30f6 344 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 345 wEIR->length = sizeof(pBluetooth->Role) + 1;
DiegoOstuni 0:de13951f30f6 346 wEIR->type = BLUETOOTH_EIR_BLE_ROLE;
DiegoOstuni 0:de13951f30f6 347 wEIR->value[0] = pBluetooth->Role;
DiegoOstuni 0:de13951f30f6 348 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 349
DiegoOstuni 0:de13951f30f6 350 }
DiegoOstuni 0:de13951f30f6 351
DiegoOstuni 0:de13951f30f6 352 /* Rely on the optional mask to know if a EIR is required or not */
DiegoOstuni 0:de13951f30f6 353 if(NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_FLAGS))
DiegoOstuni 0:de13951f30f6 354 {
DiegoOstuni 0:de13951f30f6 355 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 356 wEIR->length = sizeof(pBluetooth->Flags) + 1;
DiegoOstuni 0:de13951f30f6 357 wEIR->type = BLUETOOTH_EIR_FLAGS;
DiegoOstuni 0:de13951f30f6 358 wEIR->value[0] = pBluetooth->Flags;
DiegoOstuni 0:de13951f30f6 359 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 360 }
DiegoOstuni 0:de13951f30f6 361
DiegoOstuni 0:de13951f30f6 362 if(pBluetooth->nbUUID16 > 0)
DiegoOstuni 0:de13951f30f6 363 {
DiegoOstuni 0:de13951f30f6 364 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 365 wEIR->length = 2 * pBluetooth->nbUUID16 + 1;
DiegoOstuni 0:de13951f30f6 366 if(NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_16))
DiegoOstuni 0:de13951f30f6 367 wEIR->type = BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_16;
DiegoOstuni 0:de13951f30f6 368 else
DiegoOstuni 0:de13951f30f6 369 wEIR->type = BLUETOOTH_EIR_SERVICE_CLASS_UUID_PARTIAL_16;
DiegoOstuni 0:de13951f30f6 370 NDEF_BluetoothCopy(wEIR->value, (uint8_t*) pBluetooth->ClassUUID16, 2 * pBluetooth->nbUUID16);
DiegoOstuni 0:de13951f30f6 371 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 372
DiegoOstuni 0:de13951f30f6 373 }
DiegoOstuni 0:de13951f30f6 374
DiegoOstuni 0:de13951f30f6 375 if(pBluetooth->nbUUID32 > 0)
DiegoOstuni 0:de13951f30f6 376 {
DiegoOstuni 0:de13951f30f6 377 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 378 wEIR->length = 4 * pBluetooth->nbUUID32 + 1;
DiegoOstuni 0:de13951f30f6 379 if(NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_32))
DiegoOstuni 0:de13951f30f6 380 wEIR->type = BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_32;
DiegoOstuni 0:de13951f30f6 381 else
DiegoOstuni 0:de13951f30f6 382 wEIR->type = BLUETOOTH_EIR_SERVICE_CLASS_UUID_PARTIAL_32;
DiegoOstuni 0:de13951f30f6 383 NDEF_BluetoothCopy(wEIR->value, (uint8_t*)pBluetooth->ClassUUID32, 4 * pBluetooth->nbUUID32);
DiegoOstuni 0:de13951f30f6 384 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 385
DiegoOstuni 0:de13951f30f6 386 }
DiegoOstuni 0:de13951f30f6 387
DiegoOstuni 0:de13951f30f6 388 if(pBluetooth->nbUUID128 > 0)
DiegoOstuni 0:de13951f30f6 389 {
DiegoOstuni 0:de13951f30f6 390 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 391 wEIR->length = 16 * pBluetooth->nbUUID128 + 1;
DiegoOstuni 0:de13951f30f6 392 if(NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_128))
DiegoOstuni 0:de13951f30f6 393 wEIR->type = BLUETOOTH_EIR_SERVICE_CLASS_UUID_COMPLETE_128;
DiegoOstuni 0:de13951f30f6 394 else
DiegoOstuni 0:de13951f30f6 395 wEIR->type = BLUETOOTH_EIR_SERVICE_CLASS_UUID_PARTIAL_128;
DiegoOstuni 0:de13951f30f6 396 NDEF_BluetoothCopy(wEIR->value, (uint8_t*) pBluetooth->ClassUUID128, 16 * pBluetooth->nbUUID128);
DiegoOstuni 0:de13951f30f6 397 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 398
DiegoOstuni 0:de13951f30f6 399 }
DiegoOstuni 0:de13951f30f6 400
DiegoOstuni 0:de13951f30f6 401 if(NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SHORT_LOCAL_NAME) ||
DiegoOstuni 0:de13951f30f6 402 NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_COMPLETE_LOCAL_NAME))
DiegoOstuni 0:de13951f30f6 403 {
DiegoOstuni 0:de13951f30f6 404 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 405 wEIR->length = strlen(pBluetooth->LocalName) + 1;
DiegoOstuni 0:de13951f30f6 406 if(NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SHORT_LOCAL_NAME))
DiegoOstuni 0:de13951f30f6 407 wEIR->type = BLUETOOTH_EIR_SHORT_LOCAL_NAME;
DiegoOstuni 0:de13951f30f6 408 else
DiegoOstuni 0:de13951f30f6 409 wEIR->type = BLUETOOTH_EIR_COMPLETE_LOCAL_NAME;
DiegoOstuni 0:de13951f30f6 410 memcpy(wEIR->value, pBluetooth->LocalName,strlen(pBluetooth->LocalName));
DiegoOstuni 0:de13951f30f6 411 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 412
DiegoOstuni 0:de13951f30f6 413 }
DiegoOstuni 0:de13951f30f6 414
DiegoOstuni 0:de13951f30f6 415 if(NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_TX_POWER_LEVEL))
DiegoOstuni 0:de13951f30f6 416 {
DiegoOstuni 0:de13951f30f6 417 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 418 wEIR->length = sizeof(pBluetooth->TxPowerLevel) + 1;
DiegoOstuni 0:de13951f30f6 419 wEIR->type = BLUETOOTH_EIR_TX_POWER_LEVEL;
DiegoOstuni 0:de13951f30f6 420 wEIR->value[0] = pBluetooth->TxPowerLevel;
DiegoOstuni 0:de13951f30f6 421 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 422 }
DiegoOstuni 0:de13951f30f6 423
DiegoOstuni 0:de13951f30f6 424 if(NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_DEVICE_CLASS))
DiegoOstuni 0:de13951f30f6 425 {
DiegoOstuni 0:de13951f30f6 426 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 427 wEIR->length = sizeof(pBluetooth->DeviceClass) + 1;
DiegoOstuni 0:de13951f30f6 428 wEIR->type = BLUETOOTH_EIR_DEVICE_CLASS;
DiegoOstuni 0:de13951f30f6 429 NDEF_BluetoothCopy(wEIR->value, pBluetooth->DeviceClass,sizeof(pBluetooth->DeviceClass));
DiegoOstuni 0:de13951f30f6 430 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 431
DiegoOstuni 0:de13951f30f6 432 }
DiegoOstuni 0:de13951f30f6 433
DiegoOstuni 0:de13951f30f6 434 if(NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SIMPLE_PAIRING_HASH))
DiegoOstuni 0:de13951f30f6 435 {
DiegoOstuni 0:de13951f30f6 436 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 437 wEIR->length = sizeof(pBluetooth->SimplePairingHash) + 1;
DiegoOstuni 0:de13951f30f6 438 wEIR->type = BLUETOOTH_EIR_SIMPLE_PAIRING_HASH;
DiegoOstuni 0:de13951f30f6 439 NDEF_BluetoothCopy(wEIR->value, pBluetooth->SimplePairingHash,sizeof(pBluetooth->SimplePairingHash));
DiegoOstuni 0:de13951f30f6 440 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 441
DiegoOstuni 0:de13951f30f6 442 }
DiegoOstuni 0:de13951f30f6 443
DiegoOstuni 0:de13951f30f6 444 if(NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SIMPLE_PAIRING_RANDOMIZER))
DiegoOstuni 0:de13951f30f6 445 {
DiegoOstuni 0:de13951f30f6 446 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 447 wEIR->length = sizeof(pBluetooth->SimplePairingRandomizer) + 1;
DiegoOstuni 0:de13951f30f6 448 wEIR->type = BLUETOOTH_EIR_SIMPLE_PAIRING_RANDOMIZER;
DiegoOstuni 0:de13951f30f6 449 NDEF_BluetoothCopy(wEIR->value, pBluetooth->SimplePairingRandomizer,sizeof(pBluetooth->SimplePairingRandomizer));
DiegoOstuni 0:de13951f30f6 450 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 451
DiegoOstuni 0:de13951f30f6 452 }
DiegoOstuni 0:de13951f30f6 453
DiegoOstuni 0:de13951f30f6 454 if(NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SECURITY_MANAGER_TK_VALUE))
DiegoOstuni 0:de13951f30f6 455 {
DiegoOstuni 0:de13951f30f6 456 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 457 wEIR->length = sizeof(pBluetooth->SecureManagerTK) + 1;
DiegoOstuni 0:de13951f30f6 458 wEIR->type = BLUETOOTH_EIR_SECURITY_MANAGER_TK_VALUE;
DiegoOstuni 0:de13951f30f6 459 NDEF_BluetoothCopy(wEIR->value, pBluetooth->SecureManagerTK,sizeof(pBluetooth->SecureManagerTK));
DiegoOstuni 0:de13951f30f6 460 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 461
DiegoOstuni 0:de13951f30f6 462 }
DiegoOstuni 0:de13951f30f6 463
DiegoOstuni 0:de13951f30f6 464 if(NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SECURITY_MANAGER_FLAGS))
DiegoOstuni 0:de13951f30f6 465 {
DiegoOstuni 0:de13951f30f6 466 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 467 wEIR->length = sizeof(pBluetooth->SMFlags) + 1;
DiegoOstuni 0:de13951f30f6 468 wEIR->type = BLUETOOTH_EIR_SECURITY_MANAGER_FLAGS;
DiegoOstuni 0:de13951f30f6 469 wEIR->value[0] = pBluetooth->SMFlags;
DiegoOstuni 0:de13951f30f6 470 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 471
DiegoOstuni 0:de13951f30f6 472 }
DiegoOstuni 0:de13951f30f6 473
DiegoOstuni 0:de13951f30f6 474 if(NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SLAVE_CONNECTION_INTERVAL_RANGE))
DiegoOstuni 0:de13951f30f6 475 {
DiegoOstuni 0:de13951f30f6 476 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 477 wEIR->length = sizeof(pBluetooth->SlaveConnIntervalRange) + 1;
DiegoOstuni 0:de13951f30f6 478 wEIR->type = BLUETOOTH_EIR_SLAVE_CONNECTION_INTERVAL_RANGE;
DiegoOstuni 0:de13951f30f6 479 NDEF_BluetoothCopy(wEIR->value, (uint8_t*)pBluetooth->SlaveConnIntervalRange,sizeof(pBluetooth->SlaveConnIntervalRange));
DiegoOstuni 0:de13951f30f6 480 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 481
DiegoOstuni 0:de13951f30f6 482 }
DiegoOstuni 0:de13951f30f6 483
DiegoOstuni 0:de13951f30f6 484 if(pBluetooth->nbServiceSolicitation16 > 0)
DiegoOstuni 0:de13951f30f6 485 {
DiegoOstuni 0:de13951f30f6 486 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 487 wEIR->length = 2 * pBluetooth->nbServiceSolicitation16 + 1;
DiegoOstuni 0:de13951f30f6 488 wEIR->type = BLUETOOTH_EIR_SERVICE_SOLICITATION_16;
DiegoOstuni 0:de13951f30f6 489 NDEF_BluetoothCopy(wEIR->value, (uint8_t*)pBluetooth->ServiceSolicitation16, 16 * pBluetooth->nbServiceSolicitation16);
DiegoOstuni 0:de13951f30f6 490 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 491
DiegoOstuni 0:de13951f30f6 492 }
DiegoOstuni 0:de13951f30f6 493
DiegoOstuni 0:de13951f30f6 494 if(pBluetooth->nbServiceSolicitation128 > 0)
DiegoOstuni 0:de13951f30f6 495 {
DiegoOstuni 0:de13951f30f6 496 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 497 wEIR->length = 16 * pBluetooth->nbServiceSolicitation128 + 1;
DiegoOstuni 0:de13951f30f6 498 wEIR->type = BLUETOOTH_EIR_SERVICE_SOLICITATION_128;
DiegoOstuni 0:de13951f30f6 499 NDEF_BluetoothCopy(wEIR->value, (uint8_t*) pBluetooth->ServiceSolicitation128, 16 * pBluetooth->nbServiceSolicitation128);
DiegoOstuni 0:de13951f30f6 500 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 501
DiegoOstuni 0:de13951f30f6 502 }
DiegoOstuni 0:de13951f30f6 503
DiegoOstuni 0:de13951f30f6 504 if(NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_APPEARANCE))
DiegoOstuni 0:de13951f30f6 505 {
DiegoOstuni 0:de13951f30f6 506 wEIR = (NDEF_EIR_t*)pData;
DiegoOstuni 0:de13951f30f6 507 wEIR->length = sizeof(pBluetooth->Appearance) + 1;
DiegoOstuni 0:de13951f30f6 508 wEIR->type = BLUETOOTH_EIR_APPEARANCE;
DiegoOstuni 0:de13951f30f6 509 wEIR->value[0] = pBluetooth->Appearance;
DiegoOstuni 0:de13951f30f6 510 pData += wEIR->length + 1;
DiegoOstuni 0:de13951f30f6 511
DiegoOstuni 0:de13951f30f6 512 }
DiegoOstuni 0:de13951f30f6 513
DiegoOstuni 0:de13951f30f6 514
DiegoOstuni 0:de13951f30f6 515 status = NDEF_AppendRecord(&Record, mi2cChannel);
DiegoOstuni 0:de13951f30f6 516 if(status != NDEF_OK) return status;
DiegoOstuni 0:de13951f30f6 517
DiegoOstuni 0:de13951f30f6 518 return NDEF_OK;
DiegoOstuni 0:de13951f30f6 519 }
DiegoOstuni 0:de13951f30f6 520
DiegoOstuni 0:de13951f30f6 521 /**
DiegoOstuni 0:de13951f30f6 522 * @brief This function computeS the payload size for the OOB, using the data given in the input `Ndef_Bluetooth_OOB_t` structure.
DiegoOstuni 0:de13951f30f6 523 * @param pBluetooth Pointer on a `Ndef_Bluetooth_OOB_t` structure containing the OOB information.
DiegoOstuni 0:de13951f30f6 524 * @return Computed length in bytes.
DiegoOstuni 0:de13951f30f6 525 */
DiegoOstuni 0:de13951f30f6 526 uint32_t NDEF_GetBluetoothOOBLength( Ndef_Bluetooth_OOB_t *pBluetooth )
DiegoOstuni 0:de13951f30f6 527 {
DiegoOstuni 0:de13951f30f6 528 uint32_t length = (pBluetooth->Type == NDEF_BLUETOOTH_BREDR) ? sizeof(pBluetooth->DeviceAddress) + 2 : 0; // +2 is for BR/EDR mandatory length
DiegoOstuni 0:de13951f30f6 529 length += NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_FLAGS)? sizeof(pBluetooth->Flags) + 2 : 0 ;
DiegoOstuni 0:de13951f30f6 530 length += pBluetooth->nbUUID16 ? pBluetooth->nbUUID16 * 2 + 2 : 0;
DiegoOstuni 0:de13951f30f6 531 length += pBluetooth->nbUUID32 ? pBluetooth->nbUUID32 * 4 + 2 : 0;
DiegoOstuni 0:de13951f30f6 532 length += pBluetooth->nbUUID128 ? pBluetooth->nbUUID128 * 16 + 2 : 0;
DiegoOstuni 0:de13951f30f6 533 length += NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SHORT_LOCAL_NAME)? strlen(pBluetooth->LocalName) + 2 : 0 ;
DiegoOstuni 0:de13951f30f6 534 length += NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_COMPLETE_LOCAL_NAME)? strlen(pBluetooth->LocalName) + 2 : 0 ;
DiegoOstuni 0:de13951f30f6 535 length += NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_TX_POWER_LEVEL)? sizeof(pBluetooth->TxPowerLevel + 2) : 0 ;
DiegoOstuni 0:de13951f30f6 536 length += NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_DEVICE_CLASS)? sizeof(pBluetooth->DeviceClass) + 2 : 0 ;
DiegoOstuni 0:de13951f30f6 537 length += NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SIMPLE_PAIRING_HASH)? sizeof(pBluetooth->SimplePairingHash) + 2 : 0 ;
DiegoOstuni 0:de13951f30f6 538 length += NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SIMPLE_PAIRING_RANDOMIZER)? sizeof(pBluetooth->SimplePairingRandomizer) + 2 : 0 ;
DiegoOstuni 0:de13951f30f6 539 length += NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SECURITY_MANAGER_TK_VALUE)? sizeof(pBluetooth->SecureManagerTK) + 2 : 0 ;
DiegoOstuni 0:de13951f30f6 540 length += NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SECURITY_MANAGER_FLAGS)? sizeof(pBluetooth->SMFlags) + 2 : 0 ;
DiegoOstuni 0:de13951f30f6 541 length += NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SLAVE_CONNECTION_INTERVAL_RANGE)? sizeof(pBluetooth->SlaveConnIntervalRange) + 2 : 0 ;
DiegoOstuni 0:de13951f30f6 542 length += NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SERVICE_SOLICITATION_16)? pBluetooth->nbServiceSolicitation16 * 2 + 2 : 0 ;
DiegoOstuni 0:de13951f30f6 543 length += NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_SERVICE_SOLICITATION_128)? pBluetooth->nbServiceSolicitation128 * 16 + 2 : 0 ;
DiegoOstuni 0:de13951f30f6 544 length += NDEF_BLUETOOTH_GET_OPTIONAL_MASK(pBluetooth,BLUETOOTH_EIR_APPEARANCE)? sizeof(pBluetooth->Appearance) + 2 : 0 ;
DiegoOstuni 0:de13951f30f6 545 length += (pBluetooth->Type == NDEF_BLUETOOTH_BLE)? sizeof(pBluetooth->DeviceAddress) + sizeof(pBluetooth->DeviceAddressType) + 2 : 0 ;
DiegoOstuni 0:de13951f30f6 546 length += (pBluetooth->Type == NDEF_BLUETOOTH_BLE)? sizeof(pBluetooth->Role) + 2 : 0;
DiegoOstuni 0:de13951f30f6 547
DiegoOstuni 0:de13951f30f6 548 return length;
DiegoOstuni 0:de13951f30f6 549 }
DiegoOstuni 0:de13951f30f6 550 /**
DiegoOstuni 0:de13951f30f6 551 * @}
DiegoOstuni 0:de13951f30f6 552 */
DiegoOstuni 0:de13951f30f6 553
DiegoOstuni 0:de13951f30f6 554 /******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/