NFC NDEF library

Dependents:   Nucleo_NFC_Example I2C_NFC_Master Print_Entire_Nucleo_NFC01A1_Memory

Fork of lib_NDEF by Enrico Gregoratto

Committer:
EnricoG
Date:
Mon Dec 15 19:41:36 2014 +0000
Revision:
0:3b093bd0819e
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EnricoG 0:3b093bd0819e 1 /**
EnricoG 0:3b093bd0819e 2 ******************************************************************************
EnricoG 0:3b093bd0819e 3 * @file lib_NDEF_Email.c
EnricoG 0:3b093bd0819e 4 * @author MMY Application Team
EnricoG 0:3b093bd0819e 5 * @version V1.0.0
EnricoG 0:3b093bd0819e 6 * @date 19-March-2014
EnricoG 0:3b093bd0819e 7 * @brief This file help to manage NDEF file that represent Email.
EnricoG 0:3b093bd0819e 8 ******************************************************************************
EnricoG 0:3b093bd0819e 9 * @attention
EnricoG 0:3b093bd0819e 10 *
EnricoG 0:3b093bd0819e 11 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
EnricoG 0:3b093bd0819e 12 *
EnricoG 0:3b093bd0819e 13 * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License");
EnricoG 0:3b093bd0819e 14 * You may not use this file except in compliance with the License.
EnricoG 0:3b093bd0819e 15 * You may obtain a copy of the License at:
EnricoG 0:3b093bd0819e 16 *
EnricoG 0:3b093bd0819e 17 * http://www.st.com/software_license_agreement_liberty_v2
EnricoG 0:3b093bd0819e 18 *
EnricoG 0:3b093bd0819e 19 * Unless required by applicable law or agreed to in writing, software
EnricoG 0:3b093bd0819e 20 * distributed under the License is distributed on an "AS IS" BASIS,
EnricoG 0:3b093bd0819e 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
EnricoG 0:3b093bd0819e 22 * See the License for the specific language governing permissions and
EnricoG 0:3b093bd0819e 23 * limitations under the License.
EnricoG 0:3b093bd0819e 24 *
EnricoG 0:3b093bd0819e 25 ******************************************************************************
EnricoG 0:3b093bd0819e 26 */
EnricoG 0:3b093bd0819e 27
EnricoG 0:3b093bd0819e 28 /* Includes ------------------------------------------------------------------*/
EnricoG 0:3b093bd0819e 29 #include "lib_NDEF_Email.h"
EnricoG 0:3b093bd0819e 30
EnricoG 0:3b093bd0819e 31 /** @addtogroup NFC_libraries
EnricoG 0:3b093bd0819e 32 * @{
EnricoG 0:3b093bd0819e 33 * @brief <b>This is the library used to manage the content of the TAG (data)
EnricoG 0:3b093bd0819e 34 * But also the specific feature of the tag, for instance
EnricoG 0:3b093bd0819e 35 * password, gpo... </b>
EnricoG 0:3b093bd0819e 36 */
EnricoG 0:3b093bd0819e 37
EnricoG 0:3b093bd0819e 38
EnricoG 0:3b093bd0819e 39 /** @addtogroup libNFC_FORUM
EnricoG 0:3b093bd0819e 40 * @{
EnricoG 0:3b093bd0819e 41 * @brief This part of the library manage data which follow NFC forum organisation.
EnricoG 0:3b093bd0819e 42 */
EnricoG 0:3b093bd0819e 43
EnricoG 0:3b093bd0819e 44 /**
EnricoG 0:3b093bd0819e 45 * @brief This buffer contains the data send/received by TAG
EnricoG 0:3b093bd0819e 46 */
EnricoG 0:3b093bd0819e 47 extern uint8_t NDEF_Buffer [NDEF_MAX_SIZE];
EnricoG 0:3b093bd0819e 48
EnricoG 0:3b093bd0819e 49
EnricoG 0:3b093bd0819e 50 /** @defgroup libEmail_Private_Functions
EnricoG 0:3b093bd0819e 51 * @{
EnricoG 0:3b093bd0819e 52 */
EnricoG 0:3b093bd0819e 53
EnricoG 0:3b093bd0819e 54
EnricoG 0:3b093bd0819e 55 static void NDEF_FillEmailStruct( uint8_t* pPayload, uint32_t PayloadSize, sEmailInfo *pEmailStruct);
EnricoG 0:3b093bd0819e 56 static void NDEF_ReadURI_Email ( sRecordInfo *pRecordStruct, sEmailInfo *pEmailStruct );
EnricoG 0:3b093bd0819e 57
EnricoG 0:3b093bd0819e 58 /**
EnricoG 0:3b093bd0819e 59 * @brief This fonction fill Email structure with information of NDEF message
EnricoG 0:3b093bd0819e 60 * @param pPayload : pointer on the payload data of the NDEF message
EnricoG 0:3b093bd0819e 61 * @param PayloadSize : number of data in the payload
EnricoG 0:3b093bd0819e 62 * @param pEmailStruct : pointer on the structure to fill
EnricoG 0:3b093bd0819e 63 * @retval NONE
EnricoG 0:3b093bd0819e 64 */
EnricoG 0:3b093bd0819e 65 static void NDEF_FillEmailStruct( uint8_t* pPayload, uint32_t PayloadSize, sEmailInfo *pEmailStruct)
EnricoG 0:3b093bd0819e 66 {
EnricoG 0:3b093bd0819e 67 uint8_t* pLastByteAdd, *pLook4Word, *pEndString ;
EnricoG 0:3b093bd0819e 68 uint32_t SizeOfKeyWord;
EnricoG 0:3b093bd0819e 69
EnricoG 0:3b093bd0819e 70 /* First charactere force to NULL in case not matching found */
EnricoG 0:3b093bd0819e 71 *pEmailStruct->EmailAdd = 0;
EnricoG 0:3b093bd0819e 72 *pEmailStruct->Subject = 0;
EnricoG 0:3b093bd0819e 73 *pEmailStruct->Message = 0;
EnricoG 0:3b093bd0819e 74
EnricoG 0:3b093bd0819e 75 /* Interresting information are stored before picture if any */
EnricoG 0:3b093bd0819e 76 /* Moreover picture is not used in this demonstration SW */
EnricoG 0:3b093bd0819e 77 pLastByteAdd = (uint8_t*)(pPayload + PayloadSize);
EnricoG 0:3b093bd0819e 78
EnricoG 0:3b093bd0819e 79 /* first byte should be the "mailto:" well know URI type, skip it */
EnricoG 0:3b093bd0819e 80 pLook4Word = ++pPayload;
EnricoG 0:3b093bd0819e 81
EnricoG 0:3b093bd0819e 82 pEndString = pLook4Word;
EnricoG 0:3b093bd0819e 83
EnricoG 0:3b093bd0819e 84 /* Retrieve email add */
EnricoG 0:3b093bd0819e 85 if( pLook4Word != pLastByteAdd)
EnricoG 0:3b093bd0819e 86 {
EnricoG 0:3b093bd0819e 87 while( memcmp( pEndString, URI_FIRST_DATA_END, URI_FIRST_DATA_END_LENGTH) && pEndString<pLastByteAdd )
EnricoG 0:3b093bd0819e 88 {
EnricoG 0:3b093bd0819e 89 pEndString++;
EnricoG 0:3b093bd0819e 90 }
EnricoG 0:3b093bd0819e 91 if( pEndString != pLastByteAdd)
EnricoG 0:3b093bd0819e 92 {
EnricoG 0:3b093bd0819e 93 memcpy( pEmailStruct->EmailAdd, pLook4Word, pEndString-pLook4Word);
EnricoG 0:3b093bd0819e 94 /* add end of string charactere */
EnricoG 0:3b093bd0819e 95 pEmailStruct->EmailAdd[pEndString-pLook4Word] = 0;
EnricoG 0:3b093bd0819e 96 }
EnricoG 0:3b093bd0819e 97 }
EnricoG 0:3b093bd0819e 98
EnricoG 0:3b093bd0819e 99 pEndString += URI_FIRST_DATA_END_LENGTH;
EnricoG 0:3b093bd0819e 100 pLook4Word = pEndString;
EnricoG 0:3b093bd0819e 101
EnricoG 0:3b093bd0819e 102 /* check if e-mail subject is present */
EnricoG 0:3b093bd0819e 103 if(!memcmp( pLook4Word, SUBJECT_BEGIN_STRING, SUBJECT_BEGIN_STRING_LENGTH))
EnricoG 0:3b093bd0819e 104 {
EnricoG 0:3b093bd0819e 105 SizeOfKeyWord = SUBJECT_BEGIN_STRING_LENGTH;
EnricoG 0:3b093bd0819e 106
EnricoG 0:3b093bd0819e 107 /* Retrieve subject */
EnricoG 0:3b093bd0819e 108 if( pLook4Word != pLastByteAdd)
EnricoG 0:3b093bd0819e 109 {
EnricoG 0:3b093bd0819e 110 pLook4Word += SizeOfKeyWord;
EnricoG 0:3b093bd0819e 111 pEndString = pLook4Word;
EnricoG 0:3b093bd0819e 112 while( memcmp( pEndString, URI_SECOND_DATA_END, URI_SECOND_DATA_END_LENGTH) && pEndString<pLastByteAdd )
EnricoG 0:3b093bd0819e 113 {
EnricoG 0:3b093bd0819e 114 pEndString++;
EnricoG 0:3b093bd0819e 115 }
EnricoG 0:3b093bd0819e 116 if( pEndString != pLastByteAdd)
EnricoG 0:3b093bd0819e 117 {
EnricoG 0:3b093bd0819e 118 memcpy( pEmailStruct->Subject, pLook4Word, pEndString-pLook4Word);
EnricoG 0:3b093bd0819e 119 /* add end of string charactere */
EnricoG 0:3b093bd0819e 120 pEmailStruct->Subject[pEndString-pLook4Word] = 0;
EnricoG 0:3b093bd0819e 121 }
EnricoG 0:3b093bd0819e 122 pEndString += URI_SECOND_DATA_END_LENGTH;
EnricoG 0:3b093bd0819e 123 }
EnricoG 0:3b093bd0819e 124 }
EnricoG 0:3b093bd0819e 125
EnricoG 0:3b093bd0819e 126 pLook4Word = pEndString;
EnricoG 0:3b093bd0819e 127
EnricoG 0:3b093bd0819e 128 /* check if e-mail message is present */
EnricoG 0:3b093bd0819e 129 if(!memcmp( pLook4Word, MESSAGE_BEGIN_STRING, MESSAGE_BEGIN_STRING_LENGTH))
EnricoG 0:3b093bd0819e 130 {
EnricoG 0:3b093bd0819e 131 pEndString += MESSAGE_BEGIN_STRING_LENGTH;
EnricoG 0:3b093bd0819e 132 /* Retrieve message */
EnricoG 0:3b093bd0819e 133 memcpy( pEmailStruct->Message, pEndString, PayloadSize-(pEndString-pPayload+1));
EnricoG 0:3b093bd0819e 134 /* add end of string charactere */
EnricoG 0:3b093bd0819e 135 pEmailStruct->Message[PayloadSize-(pEndString-pPayload+1)] = 0;
EnricoG 0:3b093bd0819e 136 }
EnricoG 0:3b093bd0819e 137 }
EnricoG 0:3b093bd0819e 138
EnricoG 0:3b093bd0819e 139 /**
EnricoG 0:3b093bd0819e 140 * @brief This fonction read the Email and store data in a structure
EnricoG 0:3b093bd0819e 141 * @param pRecordStruct : Pointer on the record structure
EnricoG 0:3b093bd0819e 142 * @param pEmailStruct : pointer on the structure to fill
EnricoG 0:3b093bd0819e 143 * @retval NONE
EnricoG 0:3b093bd0819e 144 */
EnricoG 0:3b093bd0819e 145 static void NDEF_ReadURI_Email ( sRecordInfo *pRecordStruct, sEmailInfo *pEmailStruct )
EnricoG 0:3b093bd0819e 146 {
EnricoG 0:3b093bd0819e 147 uint8_t* pPayload;
EnricoG 0:3b093bd0819e 148 uint32_t PayloadSize;
EnricoG 0:3b093bd0819e 149
EnricoG 0:3b093bd0819e 150 PayloadSize = ((uint32_t)(pRecordStruct->PayloadLength3)<<24) | ((uint32_t)(pRecordStruct->PayloadLength2)<<16) |
EnricoG 0:3b093bd0819e 151 ((uint32_t)(pRecordStruct->PayloadLength1)<<8) | pRecordStruct->PayloadLength0;
EnricoG 0:3b093bd0819e 152
EnricoG 0:3b093bd0819e 153 /* Read record header */
EnricoG 0:3b093bd0819e 154 pPayload = (uint8_t*)(pRecordStruct->PayloadBufferAdd);
EnricoG 0:3b093bd0819e 155
EnricoG 0:3b093bd0819e 156 if( pRecordStruct->NDEF_Type == URI_EMAIL_TYPE)
EnricoG 0:3b093bd0819e 157 NDEF_FillEmailStruct(pPayload , PayloadSize, pEmailStruct);
EnricoG 0:3b093bd0819e 158
EnricoG 0:3b093bd0819e 159 }
EnricoG 0:3b093bd0819e 160
EnricoG 0:3b093bd0819e 161 /**
EnricoG 0:3b093bd0819e 162 * @}
EnricoG 0:3b093bd0819e 163 */
EnricoG 0:3b093bd0819e 164
EnricoG 0:3b093bd0819e 165 /** @defgroup libEmail_Public_Functions
EnricoG 0:3b093bd0819e 166 * @{
EnricoG 0:3b093bd0819e 167 * @brief This file is used to manage Email (stored or loaded in tag)
EnricoG 0:3b093bd0819e 168 */
EnricoG 0:3b093bd0819e 169
EnricoG 0:3b093bd0819e 170 /**
EnricoG 0:3b093bd0819e 171 * @brief This fonction read NDEF and retrieve Eamil information if any
EnricoG 0:3b093bd0819e 172 * @param pRecordStruct : Pointer on the record structure
EnricoG 0:3b093bd0819e 173 * @param pEmailStruct : pointer on the structure to fill
EnricoG 0:3b093bd0819e 174 * @retval SUCCESS : Email information from NDEF have been retrieved
EnricoG 0:3b093bd0819e 175 * @retval ERROR : Not able to retrieve Email information
EnricoG 0:3b093bd0819e 176 */
EnricoG 0:3b093bd0819e 177 uint16_t NDEF_ReadEmail(sRecordInfo *pRecordStruct, sEmailInfo *pEmailStruct)
EnricoG 0:3b093bd0819e 178 {
EnricoG 0:3b093bd0819e 179 uint16_t status = ERROR;
EnricoG 0:3b093bd0819e 180 sRecordInfo *pSPRecordStruct;
EnricoG 0:3b093bd0819e 181 uint32_t PayloadSize, RecordPosition;
EnricoG 0:3b093bd0819e 182 uint8_t* pData;
EnricoG 0:3b093bd0819e 183
EnricoG 0:3b093bd0819e 184
EnricoG 0:3b093bd0819e 185 if( pRecordStruct->NDEF_Type == URI_EMAIL_TYPE )
EnricoG 0:3b093bd0819e 186 {
EnricoG 0:3b093bd0819e 187 NDEF_ReadURI_Email(pRecordStruct, pEmailStruct );
EnricoG 0:3b093bd0819e 188 status = SUCCESS;
EnricoG 0:3b093bd0819e 189 }
EnricoG 0:3b093bd0819e 190 else if( pRecordStruct->NDEF_Type == SMARTPOSTER_TYPE)
EnricoG 0:3b093bd0819e 191 {
EnricoG 0:3b093bd0819e 192 for (RecordPosition = 0; RecordPosition<pRecordStruct->NbOfRecordInSPPayload; RecordPosition++)
EnricoG 0:3b093bd0819e 193 {
EnricoG 0:3b093bd0819e 194 pSPRecordStruct = (sRecordInfo *)(pRecordStruct->SPRecordStructAdd[RecordPosition]);
EnricoG 0:3b093bd0819e 195 if(pSPRecordStruct->NDEF_Type == URI_EMAIL_TYPE )
EnricoG 0:3b093bd0819e 196 {
EnricoG 0:3b093bd0819e 197 NDEF_ReadURI_Email(pSPRecordStruct, pEmailStruct );
EnricoG 0:3b093bd0819e 198 status = SUCCESS;
EnricoG 0:3b093bd0819e 199 }
EnricoG 0:3b093bd0819e 200 if(pSPRecordStruct->NDEF_Type == TEXT_TYPE )
EnricoG 0:3b093bd0819e 201 {
EnricoG 0:3b093bd0819e 202 PayloadSize = ((uint32_t)(pSPRecordStruct->PayloadLength3)<<24) | ((uint32_t)(pSPRecordStruct->PayloadLength2)<<16) |
EnricoG 0:3b093bd0819e 203 ((uint32_t)(pSPRecordStruct->PayloadLength1)<<8) | pSPRecordStruct->PayloadLength0;
EnricoG 0:3b093bd0819e 204
EnricoG 0:3b093bd0819e 205 /* The instruction content the UTF-8 language code that is not used here */
EnricoG 0:3b093bd0819e 206 pData = (uint8_t*)pSPRecordStruct->PayloadBufferAdd;
EnricoG 0:3b093bd0819e 207 pData += *pData+1;
EnricoG 0:3b093bd0819e 208
EnricoG 0:3b093bd0819e 209 memcpy(pEmailStruct->Information, pData, PayloadSize);
EnricoG 0:3b093bd0819e 210 }
EnricoG 0:3b093bd0819e 211 }
EnricoG 0:3b093bd0819e 212 }
EnricoG 0:3b093bd0819e 213
EnricoG 0:3b093bd0819e 214 return status;
EnricoG 0:3b093bd0819e 215 }
EnricoG 0:3b093bd0819e 216
EnricoG 0:3b093bd0819e 217 /**
EnricoG 0:3b093bd0819e 218 * @brief This fonction write the NDEF file with the Email data given in the structure
EnricoG 0:3b093bd0819e 219 * @param pEmailStruct : pointer on structure that contain the Email information
EnricoG 0:3b093bd0819e 220 * @retval SUCCESS : the function is succesful
EnricoG 0:3b093bd0819e 221 * @retval ERROR : Not able to store NDEF file inside tag.
EnricoG 0:3b093bd0819e 222 */
EnricoG 0:3b093bd0819e 223 uint16_t NDEF_WriteEmail ( sEmailInfo *pEmailStruct )
EnricoG 0:3b093bd0819e 224 {
EnricoG 0:3b093bd0819e 225 uint16_t status = ERROR;
EnricoG 0:3b093bd0819e 226 uint32_t Offset = 0;
EnricoG 0:3b093bd0819e 227 uint32_t emailSize, infoSize, totalSize;
EnricoG 0:3b093bd0819e 228
EnricoG 0:3b093bd0819e 229 /* Email is an URI but can be included in a smart poster to add text to give instruction to user for instance */
EnricoG 0:3b093bd0819e 230
EnricoG 0:3b093bd0819e 231 /* Email (smart poster) Record Header */
EnricoG 0:3b093bd0819e 232 /************************************/
EnricoG 0:3b093bd0819e 233 /* 7 | 6 | 5 | 4 | 3 | 2 1 0 */
EnricoG 0:3b093bd0819e 234 /*----------------------------------*/
EnricoG 0:3b093bd0819e 235 /* MB ME CF SR IL TNF */ /* <---- CF=0, IL=0 and SR=1 TNF=1 NFC Forum Well-known type*/
EnricoG 0:3b093bd0819e 236 /*----------------------------------*/
EnricoG 0:3b093bd0819e 237 /* TYPE LENGTH */
EnricoG 0:3b093bd0819e 238 /*----------------------------------*/
EnricoG 0:3b093bd0819e 239 /* PAYLOAD LENGTH 3 */ /* <---- Used only if SR=0 */
EnricoG 0:3b093bd0819e 240 /*----------------------------------*/
EnricoG 0:3b093bd0819e 241 /* PAYLOAD LENGTH 2 */ /* <---- Used only if SR=0 */
EnricoG 0:3b093bd0819e 242 /*----------------------------------*/
EnricoG 0:3b093bd0819e 243 /* PAYLOAD LENGTH 1 */ /* <---- Used only if SR=0 */
EnricoG 0:3b093bd0819e 244 /*----------------------------------*/
EnricoG 0:3b093bd0819e 245 /* PAYLOAD LENGTH 0 */
EnricoG 0:3b093bd0819e 246 /*----------------------------------*/
EnricoG 0:3b093bd0819e 247 /* ID LENGTH */ /* <---- Not Used */
EnricoG 0:3b093bd0819e 248 /*----------------------------------*/
EnricoG 0:3b093bd0819e 249 /* TYPE */
EnricoG 0:3b093bd0819e 250 /*----------------------------------*/
EnricoG 0:3b093bd0819e 251 /* ID */ /* <---- Not Used */
EnricoG 0:3b093bd0819e 252 /************************************/
EnricoG 0:3b093bd0819e 253 /* Leave the size of the file empty */
EnricoG 0:3b093bd0819e 254 NDEF_Buffer[0] = 0;
EnricoG 0:3b093bd0819e 255 NDEF_Buffer[1] = 0;
EnricoG 0:3b093bd0819e 256 Offset = FIRST_RECORD_OFFSET;
EnricoG 0:3b093bd0819e 257 infoSize = 0;
EnricoG 0:3b093bd0819e 258
EnricoG 0:3b093bd0819e 259 /* Email : 1+@+1+subject+1+message */
EnricoG 0:3b093bd0819e 260 emailSize = 1+strlen(pEmailStruct->EmailAdd)+URI_FIRST_DATA_END_LENGTH+SUBJECT_BEGIN_STRING_LENGTH+strlen(pEmailStruct->Subject)+URI_SECOND_DATA_END_LENGTH+MESSAGE_BEGIN_STRING_LENGTH+strlen(pEmailStruct->Message);
EnricoG 0:3b093bd0819e 261
EnricoG 0:3b093bd0819e 262 /* Check if a Smart poster is needed */
EnricoG 0:3b093bd0819e 263 if (pEmailStruct->Information[0] != '\0')
EnricoG 0:3b093bd0819e 264 {
EnricoG 0:3b093bd0819e 265 /* Info : 1+2+info */
EnricoG 0:3b093bd0819e 266 infoSize = 1+ISO_ENGLISH_CODE_STRING_LENGTH+strlen(pEmailStruct->Information);
EnricoG 0:3b093bd0819e 267 /* Total */
EnricoG 0:3b093bd0819e 268 totalSize = 4+emailSize+4+infoSize;
EnricoG 0:3b093bd0819e 269 if (emailSize > 255) totalSize+=3; /* Normal Email size */
EnricoG 0:3b093bd0819e 270 if (infoSize > 255) totalSize+=3; /* Normal Info size */
EnricoG 0:3b093bd0819e 271
EnricoG 0:3b093bd0819e 272 /* SmartPoster header */
EnricoG 0:3b093bd0819e 273 if (totalSize > 255)
EnricoG 0:3b093bd0819e 274 {
EnricoG 0:3b093bd0819e 275 NDEF_Buffer[Offset++] = 0xC1;
EnricoG 0:3b093bd0819e 276 NDEF_Buffer[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH;
EnricoG 0:3b093bd0819e 277 NDEF_Buffer[Offset++] = (totalSize & 0xFF000000)>>24;
EnricoG 0:3b093bd0819e 278 NDEF_Buffer[Offset++] = (totalSize & 0x00FF0000)>>16;
EnricoG 0:3b093bd0819e 279 NDEF_Buffer[Offset++] = (totalSize & 0x0000FF00)>>8;
EnricoG 0:3b093bd0819e 280 NDEF_Buffer[Offset++] = (totalSize & 0x000000FF);
EnricoG 0:3b093bd0819e 281 }
EnricoG 0:3b093bd0819e 282 else
EnricoG 0:3b093bd0819e 283 {
EnricoG 0:3b093bd0819e 284 NDEF_Buffer[Offset++] = 0xD1;
EnricoG 0:3b093bd0819e 285 NDEF_Buffer[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH;
EnricoG 0:3b093bd0819e 286 NDEF_Buffer[Offset++] = (uint8_t)totalSize;
EnricoG 0:3b093bd0819e 287 }
EnricoG 0:3b093bd0819e 288 memcpy(&NDEF_Buffer[Offset], SMART_POSTER_TYPE_STRING, SMART_POSTER_TYPE_STRING_LENGTH);
EnricoG 0:3b093bd0819e 289 Offset+=SMART_POSTER_TYPE_STRING_LENGTH;
EnricoG 0:3b093bd0819e 290 }
EnricoG 0:3b093bd0819e 291
EnricoG 0:3b093bd0819e 292 /* Email header */
EnricoG 0:3b093bd0819e 293 NDEF_Buffer[Offset] = 0x81;
EnricoG 0:3b093bd0819e 294 if (emailSize < 256) NDEF_Buffer[Offset] |= 0x10; // Set the SR bit
EnricoG 0:3b093bd0819e 295 if (pEmailStruct->Information[0] == '\0') NDEF_Buffer[Offset] |= 0x40; // Set the ME bit
EnricoG 0:3b093bd0819e 296 Offset++;
EnricoG 0:3b093bd0819e 297
EnricoG 0:3b093bd0819e 298 NDEF_Buffer[Offset++] = URI_TYPE_STRING_LENGTH;
EnricoG 0:3b093bd0819e 299 if (emailSize > 255)
EnricoG 0:3b093bd0819e 300 {
EnricoG 0:3b093bd0819e 301 NDEF_Buffer[Offset++] = (emailSize & 0xFF000000)>>24;
EnricoG 0:3b093bd0819e 302 NDEF_Buffer[Offset++] = (emailSize & 0x00FF0000)>>16;
EnricoG 0:3b093bd0819e 303 NDEF_Buffer[Offset++] = (emailSize & 0x0000FF00)>>8;
EnricoG 0:3b093bd0819e 304 NDEF_Buffer[Offset++] = (emailSize & 0x000000FF);
EnricoG 0:3b093bd0819e 305 }
EnricoG 0:3b093bd0819e 306 else
EnricoG 0:3b093bd0819e 307 {
EnricoG 0:3b093bd0819e 308 NDEF_Buffer[Offset++] = (uint8_t)emailSize;
EnricoG 0:3b093bd0819e 309 }
EnricoG 0:3b093bd0819e 310 memcpy(&NDEF_Buffer[Offset], URI_TYPE_STRING, URI_TYPE_STRING_LENGTH);
EnricoG 0:3b093bd0819e 311 Offset+=URI_TYPE_STRING_LENGTH;
EnricoG 0:3b093bd0819e 312
EnricoG 0:3b093bd0819e 313 /* Email payload */
EnricoG 0:3b093bd0819e 314 NDEF_Buffer[Offset++] = URI_ID_0x06;
EnricoG 0:3b093bd0819e 315 memcpy( &NDEF_Buffer[Offset], pEmailStruct->EmailAdd,strlen(pEmailStruct->EmailAdd));
EnricoG 0:3b093bd0819e 316 Offset += strlen(pEmailStruct->EmailAdd);
EnricoG 0:3b093bd0819e 317 memcpy( &NDEF_Buffer[Offset], URI_FIRST_DATA_END,URI_FIRST_DATA_END_LENGTH);
EnricoG 0:3b093bd0819e 318 Offset += URI_FIRST_DATA_END_LENGTH;
EnricoG 0:3b093bd0819e 319
EnricoG 0:3b093bd0819e 320 memcpy(&NDEF_Buffer[Offset], SUBJECT_BEGIN_STRING, SUBJECT_BEGIN_STRING_LENGTH);
EnricoG 0:3b093bd0819e 321 Offset += SUBJECT_BEGIN_STRING_LENGTH;
EnricoG 0:3b093bd0819e 322 memcpy( &NDEF_Buffer[Offset], pEmailStruct->Subject,strlen(pEmailStruct->Subject));
EnricoG 0:3b093bd0819e 323 Offset += strlen(pEmailStruct->Subject);
EnricoG 0:3b093bd0819e 324 memcpy( &NDEF_Buffer[Offset], URI_SECOND_DATA_END,URI_SECOND_DATA_END_LENGTH);
EnricoG 0:3b093bd0819e 325 Offset += URI_SECOND_DATA_END_LENGTH;
EnricoG 0:3b093bd0819e 326
EnricoG 0:3b093bd0819e 327 memcpy( &NDEF_Buffer[Offset], MESSAGE_BEGIN_STRING, MESSAGE_BEGIN_STRING_LENGTH);
EnricoG 0:3b093bd0819e 328 Offset += MESSAGE_BEGIN_STRING_LENGTH;
EnricoG 0:3b093bd0819e 329 memcpy( &NDEF_Buffer[Offset], pEmailStruct->Message, strlen(pEmailStruct->Message));
EnricoG 0:3b093bd0819e 330 Offset += strlen(pEmailStruct->Message);
EnricoG 0:3b093bd0819e 331
EnricoG 0:3b093bd0819e 332 /* Information header */
EnricoG 0:3b093bd0819e 333 if (pEmailStruct->Information[0] != '\0')
EnricoG 0:3b093bd0819e 334 {
EnricoG 0:3b093bd0819e 335 if (infoSize > 255)
EnricoG 0:3b093bd0819e 336 {
EnricoG 0:3b093bd0819e 337 NDEF_Buffer[Offset++] = 0x41;
EnricoG 0:3b093bd0819e 338 NDEF_Buffer[Offset++] = TEXT_TYPE_STRING_LENGTH;
EnricoG 0:3b093bd0819e 339 NDEF_Buffer[Offset++] = (infoSize & 0xFF000000)>>24;
EnricoG 0:3b093bd0819e 340 NDEF_Buffer[Offset++] = (infoSize & 0x00FF0000)>>16;
EnricoG 0:3b093bd0819e 341 NDEF_Buffer[Offset++] = (infoSize & 0x0000FF00)>>8;
EnricoG 0:3b093bd0819e 342 NDEF_Buffer[Offset++] = (infoSize & 0x000000FF);
EnricoG 0:3b093bd0819e 343 }
EnricoG 0:3b093bd0819e 344 else
EnricoG 0:3b093bd0819e 345 {
EnricoG 0:3b093bd0819e 346 NDEF_Buffer[Offset++] = 0x51;
EnricoG 0:3b093bd0819e 347 NDEF_Buffer[Offset++] = TEXT_TYPE_STRING_LENGTH;
EnricoG 0:3b093bd0819e 348 NDEF_Buffer[Offset++] = (uint8_t)infoSize;
EnricoG 0:3b093bd0819e 349 }
EnricoG 0:3b093bd0819e 350
EnricoG 0:3b093bd0819e 351 memcpy(&NDEF_Buffer[Offset], TEXT_TYPE_STRING, TEXT_TYPE_STRING_LENGTH);
EnricoG 0:3b093bd0819e 352 Offset+=TEXT_TYPE_STRING_LENGTH;
EnricoG 0:3b093bd0819e 353 NDEF_Buffer[Offset++] = ISO_ENGLISH_CODE_STRING_LENGTH; /* UTF-8 with x byte language code */
EnricoG 0:3b093bd0819e 354 memcpy(&NDEF_Buffer[Offset], ISO_ENGLISH_CODE_STRING, ISO_ENGLISH_CODE_STRING_LENGTH);
EnricoG 0:3b093bd0819e 355 Offset+=ISO_ENGLISH_CODE_STRING_LENGTH;
EnricoG 0:3b093bd0819e 356
EnricoG 0:3b093bd0819e 357 /* Information payload */
EnricoG 0:3b093bd0819e 358 memcpy( &NDEF_Buffer[Offset], pEmailStruct->Information,strlen(pEmailStruct->Information));
EnricoG 0:3b093bd0819e 359 Offset += strlen(pEmailStruct->Information);
EnricoG 0:3b093bd0819e 360 }
EnricoG 0:3b093bd0819e 361
EnricoG 0:3b093bd0819e 362 /* Write NDEF */
EnricoG 0:3b093bd0819e 363 status = WriteData ( 0x00 , Offset , NDEF_Buffer);
EnricoG 0:3b093bd0819e 364
EnricoG 0:3b093bd0819e 365 /* Write NDEF size to complete*/
EnricoG 0:3b093bd0819e 366 if( status == NDEF_ACTION_COMPLETED)
EnricoG 0:3b093bd0819e 367 {
EnricoG 0:3b093bd0819e 368 Offset -= 2; /* Must not count the 2 byte that represent the NDEF size */
EnricoG 0:3b093bd0819e 369 NDEF_Buffer[0] = (Offset & 0xFF00)>>8;
EnricoG 0:3b093bd0819e 370 NDEF_Buffer[1] = (Offset & 0x00FF);
EnricoG 0:3b093bd0819e 371
EnricoG 0:3b093bd0819e 372 status = WriteData ( 0x00 , 2 , NDEF_Buffer);
EnricoG 0:3b093bd0819e 373 }
EnricoG 0:3b093bd0819e 374
EnricoG 0:3b093bd0819e 375 if( status == NDEF_ACTION_COMPLETED)
EnricoG 0:3b093bd0819e 376 return SUCCESS;
EnricoG 0:3b093bd0819e 377 else
EnricoG 0:3b093bd0819e 378 return ERROR;
EnricoG 0:3b093bd0819e 379 }
EnricoG 0:3b093bd0819e 380
EnricoG 0:3b093bd0819e 381
EnricoG 0:3b093bd0819e 382 /**
EnricoG 0:3b093bd0819e 383 * @}
EnricoG 0:3b093bd0819e 384 */
EnricoG 0:3b093bd0819e 385
EnricoG 0:3b093bd0819e 386 /**
EnricoG 0:3b093bd0819e 387 * @}
EnricoG 0:3b093bd0819e 388 */
EnricoG 0:3b093bd0819e 389
EnricoG 0:3b093bd0819e 390 /**
EnricoG 0:3b093bd0819e 391 * @}
EnricoG 0:3b093bd0819e 392 */
EnricoG 0:3b093bd0819e 393
EnricoG 0:3b093bd0819e 394 /******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
EnricoG 0:3b093bd0819e 395
EnricoG 0:3b093bd0819e 396