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_SMS.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 * @brief This file help to manage NDEF file that represent SMS.
DiegoOstuni 0:de13951f30f6 8 ******************************************************************************
DiegoOstuni 0:de13951f30f6 9 * @attention
DiegoOstuni 0:de13951f30f6 10 *
DiegoOstuni 0:de13951f30f6 11 * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
DiegoOstuni 0:de13951f30f6 12 *
DiegoOstuni 0:de13951f30f6 13 * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
DiegoOstuni 0:de13951f30f6 14 * You may not use this file except in compliance with the License.
DiegoOstuni 0:de13951f30f6 15 * You may obtain a copy of the License at:
DiegoOstuni 0:de13951f30f6 16 *
DiegoOstuni 0:de13951f30f6 17 * http://www.st.com/myliberty
DiegoOstuni 0:de13951f30f6 18 *
DiegoOstuni 0:de13951f30f6 19 * Unless required by applicable law or agreed to in writing, software
DiegoOstuni 0:de13951f30f6 20 * distributed under the License is distributed on an "AS IS" BASIS,
DiegoOstuni 0:de13951f30f6 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
DiegoOstuni 0:de13951f30f6 22 * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
DiegoOstuni 0:de13951f30f6 23 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
DiegoOstuni 0:de13951f30f6 24 * See the License for the specific language governing permissions and
DiegoOstuni 0:de13951f30f6 25 * limitations under the License.
DiegoOstuni 0:de13951f30f6 26 *
DiegoOstuni 0:de13951f30f6 27 ******************************************************************************
DiegoOstuni 0:de13951f30f6 28 */
DiegoOstuni 0:de13951f30f6 29
DiegoOstuni 0:de13951f30f6 30 /* Includes ------------------------------------------------------------------*/
DiegoOstuni 0:de13951f30f6 31 #include "lib_NDEF_SMS.h"
DiegoOstuni 0:de13951f30f6 32
DiegoOstuni 0:de13951f30f6 33
DiegoOstuni 0:de13951f30f6 34 /** @addtogroup NFC_libraries
DiegoOstuni 0:de13951f30f6 35 * @{
DiegoOstuni 0:de13951f30f6 36 * @brief <b>This is the library used to manage the content of the TAG (data)
DiegoOstuni 0:de13951f30f6 37 * But also the specific feature of the tag, for instance
DiegoOstuni 0:de13951f30f6 38 * password, gpo... </b>
DiegoOstuni 0:de13951f30f6 39 */
DiegoOstuni 0:de13951f30f6 40
DiegoOstuni 0:de13951f30f6 41
DiegoOstuni 0:de13951f30f6 42 /** @addtogroup libNFC_FORUM
DiegoOstuni 0:de13951f30f6 43 * @{
DiegoOstuni 0:de13951f30f6 44 * @brief This part of the library manage data which follow NFC forum organisation.
DiegoOstuni 0:de13951f30f6 45 */
DiegoOstuni 0:de13951f30f6 46
DiegoOstuni 0:de13951f30f6 47 /**
DiegoOstuni 0:de13951f30f6 48 * @brief This buffer contains the data send/received by TAG
DiegoOstuni 0:de13951f30f6 49 */
DiegoOstuni 0:de13951f30f6 50 extern uint8_t NDEF_Buffer [];
DiegoOstuni 0:de13951f30f6 51
DiegoOstuni 0:de13951f30f6 52 /** @defgroup libSMS_Private_Functions
DiegoOstuni 0:de13951f30f6 53 * @{
DiegoOstuni 0:de13951f30f6 54 */
DiegoOstuni 0:de13951f30f6 55
DiegoOstuni 0:de13951f30f6 56 static void NDEF_FillSMSStruct( uint8_t* pPayload, uint32_t PayloadSize, sSMSInfo *pSMSStruct );
DiegoOstuni 0:de13951f30f6 57 static void NDEF_ReadURI_SMS( sRecordInfo_t *pRecordStruct, sSMSInfo *pSMSStruct );
DiegoOstuni 0:de13951f30f6 58
DiegoOstuni 0:de13951f30f6 59 /**
DiegoOstuni 0:de13951f30f6 60 * @brief This function fill SMS structure with information of NDEF message.
DiegoOstuni 0:de13951f30f6 61 * @param pPayload : pointer on the payload data of the NDEF message.
DiegoOstuni 0:de13951f30f6 62 * @param PayloadSize : number of data in the payload.
DiegoOstuni 0:de13951f30f6 63 * @param pSMSStruct : pointer on the structure to fill.
DiegoOstuni 0:de13951f30f6 64 */
DiegoOstuni 0:de13951f30f6 65 static void NDEF_FillSMSStruct( uint8_t* pPayload, uint32_t PayloadSize, sSMSInfo *pSMSStruct )
DiegoOstuni 0:de13951f30f6 66 {
DiegoOstuni 0:de13951f30f6 67 uint8_t* pLastByteAdd, *pLook4Word, *pEndString;
DiegoOstuni 0:de13951f30f6 68 char* pKeyWord;
DiegoOstuni 0:de13951f30f6 69 uint32_t SizeOfKeyWord;
DiegoOstuni 0:de13951f30f6 70 pEndString = 0;
DiegoOstuni 0:de13951f30f6 71
DiegoOstuni 0:de13951f30f6 72 pKeyWord = SMS_TYPE_STRING;
DiegoOstuni 0:de13951f30f6 73 SizeOfKeyWord = SMS_TYPE_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 74
DiegoOstuni 0:de13951f30f6 75 /* First character force to NULL in case not matching found */
DiegoOstuni 0:de13951f30f6 76 *pSMSStruct->PhoneNumber = 0;
DiegoOstuni 0:de13951f30f6 77 *pSMSStruct->Message = 0;
DiegoOstuni 0:de13951f30f6 78
DiegoOstuni 0:de13951f30f6 79 /* Interesting information are stored before picture if any */
DiegoOstuni 0:de13951f30f6 80 /* Moreover picture is not used in this demonstration SW */
DiegoOstuni 0:de13951f30f6 81 pLastByteAdd = (uint8_t*)(pPayload + PayloadSize);
DiegoOstuni 0:de13951f30f6 82
DiegoOstuni 0:de13951f30f6 83 pLook4Word = pPayload;
DiegoOstuni 0:de13951f30f6 84 while( memcmp( pLook4Word, pKeyWord, SizeOfKeyWord ) && (pLook4Word < pLastByteAdd) )
DiegoOstuni 0:de13951f30f6 85 {
DiegoOstuni 0:de13951f30f6 86 pLook4Word++;
DiegoOstuni 0:de13951f30f6 87 }
DiegoOstuni 0:de13951f30f6 88
DiegoOstuni 0:de13951f30f6 89 /* Retrieve phone number */
DiegoOstuni 0:de13951f30f6 90 if( pLook4Word != pLastByteAdd )
DiegoOstuni 0:de13951f30f6 91 {
DiegoOstuni 0:de13951f30f6 92 pLook4Word += SizeOfKeyWord;
DiegoOstuni 0:de13951f30f6 93 pEndString = pLook4Word;
DiegoOstuni 0:de13951f30f6 94 while( memcmp( pEndString, URI_FIRST_DATA_END, URI_FIRST_DATA_END_LENGTH ) && (pEndString < pLastByteAdd) )
DiegoOstuni 0:de13951f30f6 95 {
DiegoOstuni 0:de13951f30f6 96 pEndString++;
DiegoOstuni 0:de13951f30f6 97 }
DiegoOstuni 0:de13951f30f6 98 if( pEndString != pLastByteAdd )
DiegoOstuni 0:de13951f30f6 99 {
DiegoOstuni 0:de13951f30f6 100 memcpy( pSMSStruct->PhoneNumber, pLook4Word, pEndString-pLook4Word );
DiegoOstuni 0:de13951f30f6 101 /* add end of string character */
DiegoOstuni 0:de13951f30f6 102 pSMSStruct->PhoneNumber[pEndString-pLook4Word] = 0;
DiegoOstuni 0:de13951f30f6 103 }
DiegoOstuni 0:de13951f30f6 104 }
DiegoOstuni 0:de13951f30f6 105 pEndString += URI_FIRST_DATA_END_LENGTH;
DiegoOstuni 0:de13951f30f6 106 pLook4Word = pEndString;
DiegoOstuni 0:de13951f30f6 107
DiegoOstuni 0:de13951f30f6 108 /* check if e-mail subject is present */
DiegoOstuni 0:de13951f30f6 109 if( !memcmp( pLook4Word, MESSAGE_BEGIN_STRING, MESSAGE_BEGIN_STRING_LENGTH ) )
DiegoOstuni 0:de13951f30f6 110 {
DiegoOstuni 0:de13951f30f6 111 pEndString += MESSAGE_BEGIN_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 112 /* Retrieve message */
DiegoOstuni 0:de13951f30f6 113 memcpy( pSMSStruct->Message, pEndString, PayloadSize - (pEndString - pPayload) );
DiegoOstuni 0:de13951f30f6 114 /* add end of string character */
DiegoOstuni 0:de13951f30f6 115 pSMSStruct->Message[PayloadSize-(pEndString-pPayload)] = 0;
DiegoOstuni 0:de13951f30f6 116 }
DiegoOstuni 0:de13951f30f6 117 }
DiegoOstuni 0:de13951f30f6 118
DiegoOstuni 0:de13951f30f6 119 /**
DiegoOstuni 0:de13951f30f6 120 * @brief This function read the SMS and store data in a structure.
DiegoOstuni 0:de13951f30f6 121 * @param pRecordStruct : Pointer on the record structure.
DiegoOstuni 0:de13951f30f6 122 * @param pSMSStruct : pointer on the structure to fill.
DiegoOstuni 0:de13951f30f6 123 */
DiegoOstuni 0:de13951f30f6 124 static void NDEF_ReadURI_SMS( sRecordInfo_t *pRecordStruct, sSMSInfo *pSMSStruct )
DiegoOstuni 0:de13951f30f6 125 {
DiegoOstuni 0:de13951f30f6 126 uint8_t* pPayload;
DiegoOstuni 0:de13951f30f6 127 uint32_t PayloadSize;
DiegoOstuni 0:de13951f30f6 128
DiegoOstuni 0:de13951f30f6 129 PayloadSize = pRecordStruct->PayloadLength;
DiegoOstuni 0:de13951f30f6 130
DiegoOstuni 0:de13951f30f6 131 /* Read record header */
DiegoOstuni 0:de13951f30f6 132 pPayload = (uint8_t*)(pRecordStruct->PayloadBufferAdd);
DiegoOstuni 0:de13951f30f6 133
DiegoOstuni 0:de13951f30f6 134 if( pRecordStruct->NDEF_Type == URI_SMS_TYPE )
DiegoOstuni 0:de13951f30f6 135 NDEF_FillSMSStruct( pPayload , PayloadSize, pSMSStruct );
DiegoOstuni 0:de13951f30f6 136
DiegoOstuni 0:de13951f30f6 137 }
DiegoOstuni 0:de13951f30f6 138
DiegoOstuni 0:de13951f30f6 139 /**
DiegoOstuni 0:de13951f30f6 140 * @}
DiegoOstuni 0:de13951f30f6 141 */
DiegoOstuni 0:de13951f30f6 142
DiegoOstuni 0:de13951f30f6 143 /** @defgroup libSMS_Public_Functions
DiegoOstuni 0:de13951f30f6 144 * @{
DiegoOstuni 0:de13951f30f6 145 * @brief This file is used to manage SMS (stored or loaded in tag)
DiegoOstuni 0:de13951f30f6 146 */
DiegoOstuni 0:de13951f30f6 147
DiegoOstuni 0:de13951f30f6 148 /**
DiegoOstuni 0:de13951f30f6 149 * @brief This function read NDEF and retrieve SMS information if any.
DiegoOstuni 0:de13951f30f6 150 * @param pRecordStruct : Pointer on the record structure.
DiegoOstuni 0:de13951f30f6 151 * @param pSMSStruct : pointer on the structure to fill.
DiegoOstuni 0:de13951f30f6 152 * @retval NDEF_OK : SMS information from NDEF have been retrieve.
DiegoOstuni 0:de13951f30f6 153 * @retval NDEF_ERROR : Not able to retrieve SMS information.
DiegoOstuni 0:de13951f30f6 154 */
DiegoOstuni 0:de13951f30f6 155 uint16_t NDEF_ReadSMS( sRecordInfo_t *pRecordStruct, sSMSInfo *pSMSStruct )
DiegoOstuni 0:de13951f30f6 156 {
DiegoOstuni 0:de13951f30f6 157 uint16_t status = NDEF_ERROR;
DiegoOstuni 0:de13951f30f6 158 sRecordInfo_t *pSPRecordStruct;
DiegoOstuni 0:de13951f30f6 159 uint32_t PayloadSize, RecordPosition;
DiegoOstuni 0:de13951f30f6 160 uint8_t* pData;
DiegoOstuni 0:de13951f30f6 161
DiegoOstuni 0:de13951f30f6 162 if( pRecordStruct->NDEF_Type == URI_SMS_TYPE )
DiegoOstuni 0:de13951f30f6 163 {
DiegoOstuni 0:de13951f30f6 164 NDEF_ReadURI_SMS( pRecordStruct, pSMSStruct );
DiegoOstuni 0:de13951f30f6 165 status = NDEF_OK;
DiegoOstuni 0:de13951f30f6 166 }
DiegoOstuni 0:de13951f30f6 167 else if( pRecordStruct->NDEF_Type == SMARTPOSTER_TYPE )
DiegoOstuni 0:de13951f30f6 168 {
DiegoOstuni 0:de13951f30f6 169 for( RecordPosition = 0; RecordPosition < pRecordStruct->NbOfRecordInSPPayload; RecordPosition++ )
DiegoOstuni 0:de13951f30f6 170 {
DiegoOstuni 0:de13951f30f6 171 pSPRecordStruct = pRecordStruct->SPRecordStructAdd[RecordPosition];
DiegoOstuni 0:de13951f30f6 172 if( pSPRecordStruct->NDEF_Type == URI_SMS_TYPE )
DiegoOstuni 0:de13951f30f6 173 {
DiegoOstuni 0:de13951f30f6 174 NDEF_ReadURI_SMS( pSPRecordStruct, pSMSStruct );
DiegoOstuni 0:de13951f30f6 175 status = NDEF_OK;
DiegoOstuni 0:de13951f30f6 176 }
DiegoOstuni 0:de13951f30f6 177 if( pSPRecordStruct->NDEF_Type == TEXT_TYPE )
DiegoOstuni 0:de13951f30f6 178 {
DiegoOstuni 0:de13951f30f6 179 PayloadSize = pSPRecordStruct->PayloadLength;
DiegoOstuni 0:de13951f30f6 180
DiegoOstuni 0:de13951f30f6 181 /* The instruction content the UTF-8 language code that is not used here */
DiegoOstuni 0:de13951f30f6 182 pData = (uint8_t*)pSPRecordStruct->PayloadBufferAdd;
DiegoOstuni 0:de13951f30f6 183 PayloadSize -= *pData + 1; /* remove not usefull data */
DiegoOstuni 0:de13951f30f6 184 pData += *pData + 1; /* set pointer on usefull data */
DiegoOstuni 0:de13951f30f6 185
DiegoOstuni 0:de13951f30f6 186 memcpy( pSMSStruct->Information, pData, PayloadSize );
DiegoOstuni 0:de13951f30f6 187 /* add end of string character */
DiegoOstuni 0:de13951f30f6 188 pSMSStruct->Information[PayloadSize] = 0;
DiegoOstuni 0:de13951f30f6 189 }
DiegoOstuni 0:de13951f30f6 190 }
DiegoOstuni 0:de13951f30f6 191 }
DiegoOstuni 0:de13951f30f6 192
DiegoOstuni 0:de13951f30f6 193 return status;
DiegoOstuni 0:de13951f30f6 194 }
DiegoOstuni 0:de13951f30f6 195
DiegoOstuni 0:de13951f30f6 196 /**
DiegoOstuni 0:de13951f30f6 197 * @brief This function write the NDEF file with the SMS data given in the structure.
DiegoOstuni 0:de13951f30f6 198 * @param pSMSStruct : pointer on structure that contain the SMS information.
DiegoOstuni 0:de13951f30f6 199 * @retval NDEF_OK : NDEF file data written in the tag.
DiegoOstuni 0:de13951f30f6 200 * @retval NDEF_ERROR : not able to store NDEF in tag.
DiegoOstuni 0:de13951f30f6 201 * @retval NDEF_ERROR_MEMORY_INTERNAL : Cannot write to tag.
DiegoOstuni 0:de13951f30f6 202 * @retval NDEF_ERROR_NOT_FORMATED : CCFile data not supported or not present.
DiegoOstuni 0:de13951f30f6 203 * @retval NDEF_ERROR_MEMORY_TAG : Size not compatible with memory.
DiegoOstuni 0:de13951f30f6 204 * @retval NDEF_ERROR_LOCKED : Tag locked, cannot be write.
DiegoOstuni 0:de13951f30f6 205 */
DiegoOstuni 0:de13951f30f6 206 uint16_t NDEF_WriteSMS( sSMSInfo *pSMSStruct, I2C* mi2cChannel )
DiegoOstuni 0:de13951f30f6 207 {
DiegoOstuni 0:de13951f30f6 208 uint16_t status = NDEF_ERROR, Offset = 0;
DiegoOstuni 0:de13951f30f6 209
DiegoOstuni 0:de13951f30f6 210 NDEF_PrepareSMSMessage( pSMSStruct, NDEF_Buffer, &Offset );
DiegoOstuni 0:de13951f30f6 211
DiegoOstuni 0:de13951f30f6 212 status = NfcTag_WriteNDEF( Offset , NDEF_Buffer, mi2cChannel );
DiegoOstuni 0:de13951f30f6 213
DiegoOstuni 0:de13951f30f6 214 return status;
DiegoOstuni 0:de13951f30f6 215 }
DiegoOstuni 0:de13951f30f6 216
DiegoOstuni 0:de13951f30f6 217 /**
DiegoOstuni 0:de13951f30f6 218 * @brief This function write the NDEF file with the SMS data given in the structure.
DiegoOstuni 0:de13951f30f6 219 * @param pSMSStruct : pointer on structure that contain the SMS information.
DiegoOstuni 0:de13951f30f6 220 * @param pNDEFMessage : pointer on the NDEF message.
DiegoOstuni 0:de13951f30f6 221 * @param size : to store the size of the NDEF message generated.
DiegoOstuni 0:de13951f30f6 222 */
DiegoOstuni 0:de13951f30f6 223 void NDEF_PrepareSMSMessage( sSMSInfo *pSMSStruct, uint8_t *pNDEFMessage, uint16_t *size )
DiegoOstuni 0:de13951f30f6 224 {
DiegoOstuni 0:de13951f30f6 225 uint16_t Offset = 0;
DiegoOstuni 0:de13951f30f6 226 uint32_t smsSize = 0;
DiegoOstuni 0:de13951f30f6 227 uint32_t infoSize= 0;
DiegoOstuni 0:de13951f30f6 228 uint32_t totalSize = 0;
DiegoOstuni 0:de13951f30f6 229
DiegoOstuni 0:de13951f30f6 230 /* SMS is an URI but can be included in a smart poster to add text to give instruction to user for instance */
DiegoOstuni 0:de13951f30f6 231
DiegoOstuni 0:de13951f30f6 232 /* SMS (smart poster) Record Header */
DiegoOstuni 0:de13951f30f6 233 /************************************/
DiegoOstuni 0:de13951f30f6 234 /* 7 | 6 | 5 | 4 | 3 | 2 1 0 */
DiegoOstuni 0:de13951f30f6 235 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 236 /* MB ME CF SR IL TNF */ /* <---- CF=0, IL=0 and SR=1 TNF=1 NFC Forum Well-known type*/
DiegoOstuni 0:de13951f30f6 237 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 238 /* TYPE LENGTH */
DiegoOstuni 0:de13951f30f6 239 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 240 /* PAYLOAD LENGTH 3 */ /* <---- Used only if SR=0 */
DiegoOstuni 0:de13951f30f6 241 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 242 /* PAYLOAD LENGTH 2 */ /* <---- Used only if SR=0 */
DiegoOstuni 0:de13951f30f6 243 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 244 /* PAYLOAD LENGTH 1 */ /* <---- Used only if SR=0 */
DiegoOstuni 0:de13951f30f6 245 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 246 /* PAYLOAD LENGTH 0 */
DiegoOstuni 0:de13951f30f6 247 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 248 /* ID LENGTH */ /* <---- Not Used */
DiegoOstuni 0:de13951f30f6 249 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 250 /* TYPE */
DiegoOstuni 0:de13951f30f6 251 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 252 /* ID */ /* <---- Not Used */
DiegoOstuni 0:de13951f30f6 253 /************************************/
DiegoOstuni 0:de13951f30f6 254
DiegoOstuni 0:de13951f30f6 255 /* SMS : 1+sms:+tel+1+body=+message */
DiegoOstuni 0:de13951f30f6 256 smsSize = 1 + SMS_TYPE_STRING_LENGTH + strlen(pSMSStruct->PhoneNumber) + URI_FIRST_DATA_END_LENGTH +
DiegoOstuni 0:de13951f30f6 257 MESSAGE_BEGIN_STRING_LENGTH + strlen(pSMSStruct->Message);
DiegoOstuni 0:de13951f30f6 258
DiegoOstuni 0:de13951f30f6 259 /* Check if a Smart poster is needed */
DiegoOstuni 0:de13951f30f6 260 if( pSMSStruct->Information[0] != '\0' )
DiegoOstuni 0:de13951f30f6 261 {
DiegoOstuni 0:de13951f30f6 262 /* Info : 1+2+info */
DiegoOstuni 0:de13951f30f6 263 infoSize = 1 + ISO_ENGLISH_CODE_STRING_LENGTH + strlen(pSMSStruct->Information);
DiegoOstuni 0:de13951f30f6 264 /* Total */
DiegoOstuni 0:de13951f30f6 265 totalSize = 4 + smsSize + 4 + infoSize;
DiegoOstuni 0:de13951f30f6 266 if( smsSize > 255 ) totalSize += 3; /* Normal Email size */
DiegoOstuni 0:de13951f30f6 267 if( infoSize > 255 ) totalSize += 3; /* Normal Info size */
DiegoOstuni 0:de13951f30f6 268
DiegoOstuni 0:de13951f30f6 269 /* SmartPoster header */
DiegoOstuni 0:de13951f30f6 270 if( totalSize > 255 )
DiegoOstuni 0:de13951f30f6 271 {
DiegoOstuni 0:de13951f30f6 272 pNDEFMessage[Offset++] = 0xC1;
DiegoOstuni 0:de13951f30f6 273 pNDEFMessage[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 274 pNDEFMessage[Offset++] = (totalSize & 0xFF000000) >> 24;
DiegoOstuni 0:de13951f30f6 275 pNDEFMessage[Offset++] = (totalSize & 0x00FF0000) >> 16;
DiegoOstuni 0:de13951f30f6 276 pNDEFMessage[Offset++] = (totalSize & 0x0000FF00) >> 8;
DiegoOstuni 0:de13951f30f6 277 pNDEFMessage[Offset++] = totalSize & 0x000000FF;
DiegoOstuni 0:de13951f30f6 278 }
DiegoOstuni 0:de13951f30f6 279 else
DiegoOstuni 0:de13951f30f6 280 {
DiegoOstuni 0:de13951f30f6 281 pNDEFMessage[Offset++] = 0xD1;
DiegoOstuni 0:de13951f30f6 282 pNDEFMessage[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 283 pNDEFMessage[Offset++] = (uint8_t)totalSize;
DiegoOstuni 0:de13951f30f6 284 }
DiegoOstuni 0:de13951f30f6 285 memcpy( &pNDEFMessage[Offset], SMART_POSTER_TYPE_STRING, SMART_POSTER_TYPE_STRING_LENGTH );
DiegoOstuni 0:de13951f30f6 286 Offset += SMART_POSTER_TYPE_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 287 }
DiegoOstuni 0:de13951f30f6 288
DiegoOstuni 0:de13951f30f6 289 /* SMS header */
DiegoOstuni 0:de13951f30f6 290 pNDEFMessage[Offset] = 0x81;
DiegoOstuni 0:de13951f30f6 291 if( smsSize < 256 ) pNDEFMessage[Offset] |= 0x10; // Set the SR bit
DiegoOstuni 0:de13951f30f6 292 if( pSMSStruct->Information[0] == '\0' ) pNDEFMessage[Offset] |= 0x40; // Set the ME bit
DiegoOstuni 0:de13951f30f6 293 Offset++;
DiegoOstuni 0:de13951f30f6 294
DiegoOstuni 0:de13951f30f6 295 pNDEFMessage[Offset++] = URI_TYPE_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 296 if( smsSize > 255 )
DiegoOstuni 0:de13951f30f6 297 {
DiegoOstuni 0:de13951f30f6 298 pNDEFMessage[Offset++] = (smsSize & 0xFF000000) >> 24;
DiegoOstuni 0:de13951f30f6 299 pNDEFMessage[Offset++] = (smsSize & 0x00FF0000) >> 16;
DiegoOstuni 0:de13951f30f6 300 pNDEFMessage[Offset++] = (smsSize & 0x0000FF00) >> 8;
DiegoOstuni 0:de13951f30f6 301 pNDEFMessage[Offset++] = smsSize & 0x000000FF;
DiegoOstuni 0:de13951f30f6 302 }
DiegoOstuni 0:de13951f30f6 303 else
DiegoOstuni 0:de13951f30f6 304 {
DiegoOstuni 0:de13951f30f6 305 pNDEFMessage[Offset++] = (uint8_t)smsSize;
DiegoOstuni 0:de13951f30f6 306 }
DiegoOstuni 0:de13951f30f6 307 memcpy( &pNDEFMessage[Offset], URI_TYPE_STRING, URI_TYPE_STRING_LENGTH );
DiegoOstuni 0:de13951f30f6 308 Offset += URI_TYPE_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 309
DiegoOstuni 0:de13951f30f6 310 /* SMS payload */
DiegoOstuni 0:de13951f30f6 311 pNDEFMessage[Offset++] = URI_ID_0x00;
DiegoOstuni 0:de13951f30f6 312 memcpy( &pNDEFMessage[Offset], SMS_TYPE_STRING, SMS_TYPE_STRING_LENGTH );
DiegoOstuni 0:de13951f30f6 313 Offset += SMS_TYPE_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 314 memcpy( &pNDEFMessage[Offset], pSMSStruct->PhoneNumber, strlen(pSMSStruct->PhoneNumber) );
DiegoOstuni 0:de13951f30f6 315 Offset += strlen( pSMSStruct->PhoneNumber );
DiegoOstuni 0:de13951f30f6 316 memcpy( &pNDEFMessage[Offset], URI_FIRST_DATA_END, URI_FIRST_DATA_END_LENGTH );
DiegoOstuni 0:de13951f30f6 317 Offset += URI_FIRST_DATA_END_LENGTH;
DiegoOstuni 0:de13951f30f6 318
DiegoOstuni 0:de13951f30f6 319 memcpy( &pNDEFMessage[Offset], MESSAGE_BEGIN_STRING, MESSAGE_BEGIN_STRING_LENGTH );
DiegoOstuni 0:de13951f30f6 320 Offset += MESSAGE_BEGIN_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 321 memcpy( &pNDEFMessage[Offset], pSMSStruct->Message, strlen(pSMSStruct->Message) );
DiegoOstuni 0:de13951f30f6 322 Offset += strlen( pSMSStruct->Message );
DiegoOstuni 0:de13951f30f6 323
DiegoOstuni 0:de13951f30f6 324 /* Information header */
DiegoOstuni 0:de13951f30f6 325 if( pSMSStruct->Information[0] != '\0' )
DiegoOstuni 0:de13951f30f6 326 {
DiegoOstuni 0:de13951f30f6 327 if( infoSize > 255 )
DiegoOstuni 0:de13951f30f6 328 {
DiegoOstuni 0:de13951f30f6 329 pNDEFMessage[Offset++] = 0x41;
DiegoOstuni 0:de13951f30f6 330 pNDEFMessage[Offset++] = TEXT_TYPE_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 331 pNDEFMessage[Offset++] = (infoSize & 0xFF000000) >> 24;
DiegoOstuni 0:de13951f30f6 332 pNDEFMessage[Offset++] = (infoSize & 0x00FF0000) >> 16;
DiegoOstuni 0:de13951f30f6 333 pNDEFMessage[Offset++] = (infoSize & 0x0000FF00) >> 8;
DiegoOstuni 0:de13951f30f6 334 pNDEFMessage[Offset++] = infoSize & 0x000000FF;
DiegoOstuni 0:de13951f30f6 335 }
DiegoOstuni 0:de13951f30f6 336 else
DiegoOstuni 0:de13951f30f6 337 {
DiegoOstuni 0:de13951f30f6 338 pNDEFMessage[Offset++] = 0x51;
DiegoOstuni 0:de13951f30f6 339 pNDEFMessage[Offset++] = TEXT_TYPE_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 340 pNDEFMessage[Offset++] = (uint8_t)infoSize;
DiegoOstuni 0:de13951f30f6 341 }
DiegoOstuni 0:de13951f30f6 342
DiegoOstuni 0:de13951f30f6 343 memcpy( &pNDEFMessage[Offset], TEXT_TYPE_STRING, TEXT_TYPE_STRING_LENGTH );
DiegoOstuni 0:de13951f30f6 344 Offset += TEXT_TYPE_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 345 pNDEFMessage[Offset++] = ISO_ENGLISH_CODE_STRING_LENGTH; /* UTF-8 with x byte language code */
DiegoOstuni 0:de13951f30f6 346 memcpy( &pNDEFMessage[Offset], ISO_ENGLISH_CODE_STRING, ISO_ENGLISH_CODE_STRING_LENGTH );
DiegoOstuni 0:de13951f30f6 347 Offset += ISO_ENGLISH_CODE_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 348
DiegoOstuni 0:de13951f30f6 349 /* Information payload */
DiegoOstuni 0:de13951f30f6 350 memcpy( &pNDEFMessage[Offset], pSMSStruct->Information, strlen(pSMSStruct->Information) );
DiegoOstuni 0:de13951f30f6 351 Offset += strlen( pSMSStruct->Information );
DiegoOstuni 0:de13951f30f6 352 }
DiegoOstuni 0:de13951f30f6 353
DiegoOstuni 0:de13951f30f6 354 *size = (uint16_t)(Offset);
DiegoOstuni 0:de13951f30f6 355 }
DiegoOstuni 0:de13951f30f6 356
DiegoOstuni 0:de13951f30f6 357
DiegoOstuni 0:de13951f30f6 358 /**
DiegoOstuni 0:de13951f30f6 359 * @}
DiegoOstuni 0:de13951f30f6 360 */
DiegoOstuni 0:de13951f30f6 361
DiegoOstuni 0:de13951f30f6 362 /**
DiegoOstuni 0:de13951f30f6 363 * @}
DiegoOstuni 0:de13951f30f6 364 */
DiegoOstuni 0:de13951f30f6 365
DiegoOstuni 0:de13951f30f6 366 /**
DiegoOstuni 0:de13951f30f6 367 * @}
DiegoOstuni 0:de13951f30f6 368 */
DiegoOstuni 0:de13951f30f6 369
DiegoOstuni 0:de13951f30f6 370 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/