Fork for the GitHub
lib_NDEF_Vcard.cpp@0:de13951f30f6, 2019-11-14 (annotated)
- Committer:
- DiegoOstuni
- Date:
- Thu Nov 14 10:34:11 2019 +0000
- Revision:
- 0:de13951f30f6
Add files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DiegoOstuni | 0:de13951f30f6 | 1 | /** |
DiegoOstuni | 0:de13951f30f6 | 2 | ****************************************************************************** |
DiegoOstuni | 0:de13951f30f6 | 3 | * @file lib_NDEF_Vcard.c |
DiegoOstuni | 0:de13951f30f6 | 4 | * @author MMY Application Team |
DiegoOstuni | 0:de13951f30f6 | 5 | * @version $Revision: 3210 $ |
DiegoOstuni | 0:de13951f30f6 | 6 | * @date $Date: 2016-12-05 15:37:48 +0100 (Mon, 05 Dec 2016) $ |
DiegoOstuni | 0:de13951f30f6 | 7 | * @brief This file help to manage NDEF file that represent Vcard. |
DiegoOstuni | 0:de13951f30f6 | 8 | ****************************************************************************** |
DiegoOstuni | 0:de13951f30f6 | 9 | * @attention |
DiegoOstuni | 0:de13951f30f6 | 10 | * |
DiegoOstuni | 0:de13951f30f6 | 11 | * <h2><center>© 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_Vcard.h" |
DiegoOstuni | 0:de13951f30f6 | 32 | |
DiegoOstuni | 0:de13951f30f6 | 33 | |
DiegoOstuni | 0:de13951f30f6 | 34 | /** @addtogroup lib_NDEF_Vcard |
DiegoOstuni | 0:de13951f30f6 | 35 | * @ingroup libNDEF |
DiegoOstuni | 0:de13951f30f6 | 36 | * @{ |
DiegoOstuni | 0:de13951f30f6 | 37 | * @brief This part of the library manage the data which follow NFC forum organisation. |
DiegoOstuni | 0:de13951f30f6 | 38 | */ |
DiegoOstuni | 0:de13951f30f6 | 39 | |
DiegoOstuni | 0:de13951f30f6 | 40 | /* This buffer contains the data sent/received by TAG */ |
DiegoOstuni | 0:de13951f30f6 | 41 | extern uint8_t NDEF_Buffer []; |
DiegoOstuni | 0:de13951f30f6 | 42 | |
DiegoOstuni | 0:de13951f30f6 | 43 | static void NDEF_FillVcardStruct( uint8_t* pPayload, uint32_t PayloadSize, char* pKeyWord, uint32_t SizeOfKeyWord, uint8_t* pString ); |
DiegoOstuni | 0:de13951f30f6 | 44 | static void NDEF_ExtractVcard( sRecordInfo_t *pRecordStruct, sVcardInfo *pVcardStruct ); |
DiegoOstuni | 0:de13951f30f6 | 45 | |
DiegoOstuni | 0:de13951f30f6 | 46 | /** |
DiegoOstuni | 0:de13951f30f6 | 47 | * @brief This function extracts a Vcard particular property from a vCard. |
DiegoOstuni | 0:de13951f30f6 | 48 | * @param pPayload Pointer on the vCard payload data of the vCard record. |
DiegoOstuni | 0:de13951f30f6 | 49 | * @param PayloadSize Number of bytes in the vCard payload. |
DiegoOstuni | 0:de13951f30f6 | 50 | * @param pKeyWord Pointer on the vCard property keyword to look for. |
DiegoOstuni | 0:de13951f30f6 | 51 | * @param SizeOfKeyWord Number of bytes of the vCard property keyword we are looking for. |
DiegoOstuni | 0:de13951f30f6 | 52 | * @param pString Pointer on a string used to return the vCard property read. |
DiegoOstuni | 0:de13951f30f6 | 53 | */ |
DiegoOstuni | 0:de13951f30f6 | 54 | static void NDEF_FillVcardStruct( uint8_t* pPayload, uint32_t PayloadSize, char* pKeyWord, uint32_t SizeOfKeyWord, uint8_t* pString ) |
DiegoOstuni | 0:de13951f30f6 | 55 | { |
DiegoOstuni | 0:de13951f30f6 | 56 | uint8_t* pLastByteAdd, *pLook4Word, *pEndString; |
DiegoOstuni | 0:de13951f30f6 | 57 | |
DiegoOstuni | 0:de13951f30f6 | 58 | /* First character force to NULL in case not matching found */ |
DiegoOstuni | 0:de13951f30f6 | 59 | *pString = 0; |
DiegoOstuni | 0:de13951f30f6 | 60 | |
DiegoOstuni | 0:de13951f30f6 | 61 | /* Interresting information are stored before picture if any */ |
DiegoOstuni | 0:de13951f30f6 | 62 | /* Moreover picture is not used in this demonstration SW */ |
DiegoOstuni | 0:de13951f30f6 | 63 | pLastByteAdd = pPayload; |
DiegoOstuni | 0:de13951f30f6 | 64 | while( memcmp( pLastByteAdd, JPEG, JPEG_STRING_SIZE ) && (pLastByteAdd < (pPayload + PayloadSize)) ) |
DiegoOstuni | 0:de13951f30f6 | 65 | { |
DiegoOstuni | 0:de13951f30f6 | 66 | pLastByteAdd++; |
DiegoOstuni | 0:de13951f30f6 | 67 | } |
DiegoOstuni | 0:de13951f30f6 | 68 | |
DiegoOstuni | 0:de13951f30f6 | 69 | pLook4Word = pPayload; |
DiegoOstuni | 0:de13951f30f6 | 70 | while( memcmp( pLook4Word, pKeyWord, SizeOfKeyWord ) && (pLook4Word < pLastByteAdd) ) |
DiegoOstuni | 0:de13951f30f6 | 71 | { |
DiegoOstuni | 0:de13951f30f6 | 72 | pLook4Word++; |
DiegoOstuni | 0:de13951f30f6 | 73 | } |
DiegoOstuni | 0:de13951f30f6 | 74 | |
DiegoOstuni | 0:de13951f30f6 | 75 | /* Word found */ |
DiegoOstuni | 0:de13951f30f6 | 76 | if( pLook4Word != pLastByteAdd ) |
DiegoOstuni | 0:de13951f30f6 | 77 | { |
DiegoOstuni | 0:de13951f30f6 | 78 | pLook4Word += SizeOfKeyWord; |
DiegoOstuni | 0:de13951f30f6 | 79 | pEndString = pLook4Word; |
DiegoOstuni | 0:de13951f30f6 | 80 | while( memcmp( pEndString, LIMIT, LIMIT_STRING_SIZE ) && (pEndString < pLastByteAdd) ) |
DiegoOstuni | 0:de13951f30f6 | 81 | { |
DiegoOstuni | 0:de13951f30f6 | 82 | pEndString++; |
DiegoOstuni | 0:de13951f30f6 | 83 | } |
DiegoOstuni | 0:de13951f30f6 | 84 | if( pEndString != pLastByteAdd ) |
DiegoOstuni | 0:de13951f30f6 | 85 | { |
DiegoOstuni | 0:de13951f30f6 | 86 | memcpy( pString, pLook4Word, pEndString-pLook4Word ); |
DiegoOstuni | 0:de13951f30f6 | 87 | /* add end of string character */ |
DiegoOstuni | 0:de13951f30f6 | 88 | pString += pEndString - pLook4Word; |
DiegoOstuni | 0:de13951f30f6 | 89 | *pString = '\0'; |
DiegoOstuni | 0:de13951f30f6 | 90 | } |
DiegoOstuni | 0:de13951f30f6 | 91 | } |
DiegoOstuni | 0:de13951f30f6 | 92 | } |
DiegoOstuni | 0:de13951f30f6 | 93 | |
DiegoOstuni | 0:de13951f30f6 | 94 | /** |
DiegoOstuni | 0:de13951f30f6 | 95 | * @brief This function reads a Vcard record and stores data in a `sVcardInfo` structure. |
DiegoOstuni | 0:de13951f30f6 | 96 | * @param pRecordStruct Pointer on the vCard record structure. |
DiegoOstuni | 0:de13951f30f6 | 97 | * @param pVcardStruct Pointer on the `sCardInfo` structure to fill. |
DiegoOstuni | 0:de13951f30f6 | 98 | */ |
DiegoOstuni | 0:de13951f30f6 | 99 | static void NDEF_ExtractVcard( sRecordInfo_t *pRecordStruct, sVcardInfo *pVcardStruct ) |
DiegoOstuni | 0:de13951f30f6 | 100 | { |
DiegoOstuni | 0:de13951f30f6 | 101 | uint32_t PayloadSize; |
DiegoOstuni | 0:de13951f30f6 | 102 | uint8_t* pPayload; |
DiegoOstuni | 0:de13951f30f6 | 103 | |
DiegoOstuni | 0:de13951f30f6 | 104 | |
DiegoOstuni | 0:de13951f30f6 | 105 | PayloadSize = pRecordStruct->PayloadLength; |
DiegoOstuni | 0:de13951f30f6 | 106 | |
DiegoOstuni | 0:de13951f30f6 | 107 | /* Read record header */ |
DiegoOstuni | 0:de13951f30f6 | 108 | pPayload = (uint8_t*)(pRecordStruct->PayloadBufferAdd); |
DiegoOstuni | 0:de13951f30f6 | 109 | |
DiegoOstuni | 0:de13951f30f6 | 110 | NDEF_FillVcardStruct( pPayload, PayloadSize, VERSION, VERSION_STRING_SIZE, (uint8_t*)(pVcardStruct->Version) ); |
DiegoOstuni | 0:de13951f30f6 | 111 | if( !memcmp( pVcardStruct->Version, VCARD_VERSION_2_1, VCARD_VERSION_2_1_SIZE ) ) |
DiegoOstuni | 0:de13951f30f6 | 112 | { |
DiegoOstuni | 0:de13951f30f6 | 113 | NDEF_FillVcardStruct( pPayload, PayloadSize, FIRSTNAME, FIRSTNAME_STRING_SIZE, (uint8_t*)(pVcardStruct->FirstName) ); |
DiegoOstuni | 0:de13951f30f6 | 114 | NDEF_FillVcardStruct( pPayload, PayloadSize, TITLE, TITLE_STRING_SIZE, (uint8_t*)(pVcardStruct->Title) ); |
DiegoOstuni | 0:de13951f30f6 | 115 | NDEF_FillVcardStruct( pPayload, PayloadSize, ORG, ORG_STRING_SIZE, (uint8_t*)(pVcardStruct->Org) ); |
DiegoOstuni | 0:de13951f30f6 | 116 | NDEF_FillVcardStruct( pPayload, PayloadSize, HOME_ADDRESS, HOME_ADDRESS_STRING_SIZE, (uint8_t*)(pVcardStruct->HomeAddress) ); |
DiegoOstuni | 0:de13951f30f6 | 117 | NDEF_FillVcardStruct( pPayload, PayloadSize, GEN_ADDRESS, strlen(GEN_ADDRESS), (uint8_t*)(pVcardStruct->Address) ); |
DiegoOstuni | 0:de13951f30f6 | 118 | NDEF_FillVcardStruct( pPayload, PayloadSize, WORK_ADDRESS, WORK_ADDRESS_STRING_SIZE, (uint8_t*)(pVcardStruct->WorkAddress) ); |
DiegoOstuni | 0:de13951f30f6 | 119 | NDEF_FillVcardStruct( pPayload, PayloadSize, HOME_TEL, HOME_TEL_STRING_SIZE, (uint8_t*)(pVcardStruct->HomeTel) ); |
DiegoOstuni | 0:de13951f30f6 | 120 | NDEF_FillVcardStruct( pPayload, PayloadSize, WORK_TEL, WORK_TEL_STRING_SIZE, (uint8_t*)(pVcardStruct->WorkTel) ); |
DiegoOstuni | 0:de13951f30f6 | 121 | NDEF_FillVcardStruct( pPayload, PayloadSize, CELL_TEL, CELL_TEL_STRING_SIZE, (uint8_t*)(pVcardStruct->CellTel) ); |
DiegoOstuni | 0:de13951f30f6 | 122 | NDEF_FillVcardStruct( pPayload, PayloadSize, HOME_EMAIL, HOME_EMAIL_STRING_SIZE, (uint8_t*)(pVcardStruct->HomeEmail) ); |
DiegoOstuni | 0:de13951f30f6 | 123 | NDEF_FillVcardStruct( pPayload, PayloadSize, GEN_EMAIL, strlen(GEN_EMAIL), (uint8_t*)(pVcardStruct->Email) ); |
DiegoOstuni | 0:de13951f30f6 | 124 | NDEF_FillVcardStruct( pPayload, PayloadSize, WORK_EMAIL, WORK_EMAIL_STRING_SIZE, (uint8_t*)(pVcardStruct->WorkEmail) ); |
DiegoOstuni | 0:de13951f30f6 | 125 | } |
DiegoOstuni | 0:de13951f30f6 | 126 | else if( !memcmp( pVcardStruct->Version, VCARD_VERSION_3_0, VCARD_VERSION_3_0_SIZE ) ) |
DiegoOstuni | 0:de13951f30f6 | 127 | { |
DiegoOstuni | 0:de13951f30f6 | 128 | /* need to be implemented */ |
DiegoOstuni | 0:de13951f30f6 | 129 | } |
DiegoOstuni | 0:de13951f30f6 | 130 | else |
DiegoOstuni | 0:de13951f30f6 | 131 | { |
DiegoOstuni | 0:de13951f30f6 | 132 | /* maybe new version but not supported in this sw */ |
DiegoOstuni | 0:de13951f30f6 | 133 | } |
DiegoOstuni | 0:de13951f30f6 | 134 | |
DiegoOstuni | 0:de13951f30f6 | 135 | } |
DiegoOstuni | 0:de13951f30f6 | 136 | |
DiegoOstuni | 0:de13951f30f6 | 137 | /** |
DiegoOstuni | 0:de13951f30f6 | 138 | * @brief This function reads a Vcard record and stores data in a `sVcardInfo` structure. |
DiegoOstuni | 0:de13951f30f6 | 139 | * @param pRecordStruct Pointer on the vCard record structure. |
DiegoOstuni | 0:de13951f30f6 | 140 | * @param pVcardStruct Pointer on the `sCardInfo` structure to fill. |
DiegoOstuni | 0:de13951f30f6 | 141 | * @retval NDEF_OK The Vcard information has been retrieved. |
DiegoOstuni | 0:de13951f30f6 | 142 | * @retval NDEF_ERROR Not able to retrieve the Vcard information. |
DiegoOstuni | 0:de13951f30f6 | 143 | */ |
DiegoOstuni | 0:de13951f30f6 | 144 | uint16_t NDEF_ReadVcard( sRecordInfo_t *pRecordStruct, sVcardInfo *pVcardStruct ) |
DiegoOstuni | 0:de13951f30f6 | 145 | { |
DiegoOstuni | 0:de13951f30f6 | 146 | uint16_t status = NDEF_ERROR; |
DiegoOstuni | 0:de13951f30f6 | 147 | |
DiegoOstuni | 0:de13951f30f6 | 148 | if( pRecordStruct->NDEF_Type == VCARD_TYPE ) |
DiegoOstuni | 0:de13951f30f6 | 149 | { |
DiegoOstuni | 0:de13951f30f6 | 150 | NDEF_ExtractVcard( pRecordStruct, pVcardStruct ); |
DiegoOstuni | 0:de13951f30f6 | 151 | status = NDEF_OK; |
DiegoOstuni | 0:de13951f30f6 | 152 | } |
DiegoOstuni | 0:de13951f30f6 | 153 | |
DiegoOstuni | 0:de13951f30f6 | 154 | return status; |
DiegoOstuni | 0:de13951f30f6 | 155 | } |
DiegoOstuni | 0:de13951f30f6 | 156 | |
DiegoOstuni | 0:de13951f30f6 | 157 | /** |
DiegoOstuni | 0:de13951f30f6 | 158 | * @brief This function writes a NDEF message to the NFC tag with the Vcard data given in a `sVcardInfo` structure. |
DiegoOstuni | 0:de13951f30f6 | 159 | * @param pVcardStruct Pointer on a `sVcardInfo` structure containing the Vcard information. |
DiegoOstuni | 0:de13951f30f6 | 160 | * @retval NDEF_OK NDEF file data written in the tag. |
DiegoOstuni | 0:de13951f30f6 | 161 | * @retval NDEF_ERROR Not able to store the NDEF in tag. |
DiegoOstuni | 0:de13951f30f6 | 162 | * @retval NDEF_ERROR_MEMORY_INTERNAL Cannot write to tag. |
DiegoOstuni | 0:de13951f30f6 | 163 | * @retval NDEF_ERROR_NOT_FORMATED CCFile data not supported or not present. |
DiegoOstuni | 0:de13951f30f6 | 164 | * @retval NDEF_ERROR_MEMORY_TAG Size not compatible with memory. |
DiegoOstuni | 0:de13951f30f6 | 165 | * @retval NDEF_ERROR_LOCKED Tag locked, cannot be write. |
DiegoOstuni | 0:de13951f30f6 | 166 | */ |
DiegoOstuni | 0:de13951f30f6 | 167 | uint16_t NDEF_WriteVcard( sVcardInfo *pVcardStruct, I2C* mi2cChannel ) |
DiegoOstuni | 0:de13951f30f6 | 168 | { |
DiegoOstuni | 0:de13951f30f6 | 169 | uint16_t status = NDEF_ERROR, Offset = 0; |
DiegoOstuni | 0:de13951f30f6 | 170 | |
DiegoOstuni | 0:de13951f30f6 | 171 | NDEF_PrepareVcardMessage( pVcardStruct, NDEF_Buffer, &Offset ); |
DiegoOstuni | 0:de13951f30f6 | 172 | |
DiegoOstuni | 0:de13951f30f6 | 173 | status = NfcTag_WriteNDEF( Offset , NDEF_Buffer, mi2cChannel ); |
DiegoOstuni | 0:de13951f30f6 | 174 | |
DiegoOstuni | 0:de13951f30f6 | 175 | return status; |
DiegoOstuni | 0:de13951f30f6 | 176 | } |
DiegoOstuni | 0:de13951f30f6 | 177 | |
DiegoOstuni | 0:de13951f30f6 | 178 | /** |
DiegoOstuni | 0:de13951f30f6 | 179 | * @brief This function computes the size of a Vcard record from the data given in the `sVcardInfo` structure. |
DiegoOstuni | 0:de13951f30f6 | 180 | * @param pVcardStruct Pointer on a `sVcardInfo` structure containing the Vcard information. |
DiegoOstuni | 0:de13951f30f6 | 181 | * @return vCard record data size in bytes (excluding record metadata). |
DiegoOstuni | 0:de13951f30f6 | 182 | */ |
DiegoOstuni | 0:de13951f30f6 | 183 | uint32_t NDEF_GetVcardLength( sVcardInfo *pVcardStruct) |
DiegoOstuni | 0:de13951f30f6 | 184 | { |
DiegoOstuni | 0:de13951f30f6 | 185 | |
DiegoOstuni | 0:de13951f30f6 | 186 | uint32_t PayloadSize = 0; |
DiegoOstuni | 0:de13951f30f6 | 187 | |
DiegoOstuni | 0:de13951f30f6 | 188 | /* "BEGIN:VCARD\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 189 | PayloadSize += BEGIN_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 190 | PayloadSize += VCARD_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 191 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 192 | |
DiegoOstuni | 0:de13951f30f6 | 193 | /* "VERSION:2.1\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 194 | PayloadSize += VERSION_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 195 | PayloadSize += VCARD_VERSION_2_1_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 196 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 197 | |
DiegoOstuni | 0:de13951f30f6 | 198 | /* "N:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 199 | if(*pVcardStruct->Name != '\0') |
DiegoOstuni | 0:de13951f30f6 | 200 | { |
DiegoOstuni | 0:de13951f30f6 | 201 | PayloadSize += VCARD_NAME_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 202 | PayloadSize += strlen( pVcardStruct->Name ); |
DiegoOstuni | 0:de13951f30f6 | 203 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 204 | } |
DiegoOstuni | 0:de13951f30f6 | 205 | /* "FN:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 206 | if(*pVcardStruct->FirstName != '\0') |
DiegoOstuni | 0:de13951f30f6 | 207 | { |
DiegoOstuni | 0:de13951f30f6 | 208 | PayloadSize += FIRSTNAME_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 209 | PayloadSize += strlen( pVcardStruct->FirstName ); |
DiegoOstuni | 0:de13951f30f6 | 210 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 211 | } |
DiegoOstuni | 0:de13951f30f6 | 212 | if(*pVcardStruct->Title != '\0') |
DiegoOstuni | 0:de13951f30f6 | 213 | { |
DiegoOstuni | 0:de13951f30f6 | 214 | /* "TITLE:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 215 | PayloadSize += TITLE_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 216 | PayloadSize += strlen( pVcardStruct->Title ); |
DiegoOstuni | 0:de13951f30f6 | 217 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 218 | } |
DiegoOstuni | 0:de13951f30f6 | 219 | if(*pVcardStruct->Org != '\0') |
DiegoOstuni | 0:de13951f30f6 | 220 | { |
DiegoOstuni | 0:de13951f30f6 | 221 | /* "ORG:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 222 | PayloadSize += ORG_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 223 | PayloadSize += strlen( pVcardStruct->Org ); |
DiegoOstuni | 0:de13951f30f6 | 224 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 225 | } |
DiegoOstuni | 0:de13951f30f6 | 226 | if(*pVcardStruct->Url != '\0') |
DiegoOstuni | 0:de13951f30f6 | 227 | { |
DiegoOstuni | 0:de13951f30f6 | 228 | /* "URL:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 229 | PayloadSize += URL_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 230 | PayloadSize += strlen( pVcardStruct->Url ); |
DiegoOstuni | 0:de13951f30f6 | 231 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 232 | } |
DiegoOstuni | 0:de13951f30f6 | 233 | if(*pVcardStruct->HomeAddress != '\0') |
DiegoOstuni | 0:de13951f30f6 | 234 | { |
DiegoOstuni | 0:de13951f30f6 | 235 | /* "ADR;HOME:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 236 | PayloadSize += HOME_ADDRESS_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 237 | PayloadSize += strlen( pVcardStruct->HomeAddress ); |
DiegoOstuni | 0:de13951f30f6 | 238 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 239 | } |
DiegoOstuni | 0:de13951f30f6 | 240 | if(*pVcardStruct->WorkAddress != '\0') |
DiegoOstuni | 0:de13951f30f6 | 241 | { |
DiegoOstuni | 0:de13951f30f6 | 242 | /* "ADR;WORK:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 243 | PayloadSize += WORK_ADDRESS_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 244 | PayloadSize += strlen( pVcardStruct->WorkAddress ); |
DiegoOstuni | 0:de13951f30f6 | 245 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 246 | } |
DiegoOstuni | 0:de13951f30f6 | 247 | if(*pVcardStruct->HomeTel != '\0') |
DiegoOstuni | 0:de13951f30f6 | 248 | { |
DiegoOstuni | 0:de13951f30f6 | 249 | /* "TEL;HOME:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 250 | PayloadSize += HOME_TEL_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 251 | PayloadSize += strlen( pVcardStruct->HomeTel ); |
DiegoOstuni | 0:de13951f30f6 | 252 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 253 | } |
DiegoOstuni | 0:de13951f30f6 | 254 | if(*pVcardStruct->WorkTel != '\0') |
DiegoOstuni | 0:de13951f30f6 | 255 | { |
DiegoOstuni | 0:de13951f30f6 | 256 | /* "TEL;WORK:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 257 | PayloadSize += WORK_TEL_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 258 | PayloadSize += strlen( pVcardStruct->WorkTel ); |
DiegoOstuni | 0:de13951f30f6 | 259 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 260 | } |
DiegoOstuni | 0:de13951f30f6 | 261 | if(*pVcardStruct->CellTel != '\0') |
DiegoOstuni | 0:de13951f30f6 | 262 | { |
DiegoOstuni | 0:de13951f30f6 | 263 | /* "TEL;CELL:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 264 | PayloadSize += CELL_TEL_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 265 | PayloadSize += strlen( pVcardStruct->CellTel ); |
DiegoOstuni | 0:de13951f30f6 | 266 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 267 | } |
DiegoOstuni | 0:de13951f30f6 | 268 | if(*pVcardStruct->HomeEmail != '\0') |
DiegoOstuni | 0:de13951f30f6 | 269 | { |
DiegoOstuni | 0:de13951f30f6 | 270 | /* "EMAIL;HOME:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 271 | PayloadSize += HOME_EMAIL_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 272 | PayloadSize += strlen( pVcardStruct->HomeEmail ); |
DiegoOstuni | 0:de13951f30f6 | 273 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 274 | } |
DiegoOstuni | 0:de13951f30f6 | 275 | if(*pVcardStruct->WorkEmail != '\0') |
DiegoOstuni | 0:de13951f30f6 | 276 | { |
DiegoOstuni | 0:de13951f30f6 | 277 | /* "EMAIL;WORK:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 278 | PayloadSize += WORK_EMAIL_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 279 | PayloadSize += strlen( pVcardStruct->WorkEmail ); |
DiegoOstuni | 0:de13951f30f6 | 280 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 281 | } |
DiegoOstuni | 0:de13951f30f6 | 282 | /* "END:VCARD\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 283 | PayloadSize += END_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 284 | PayloadSize += VCARD_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 285 | /* PayloadSize += LIMIT_STRING_SIZE;*/ |
DiegoOstuni | 0:de13951f30f6 | 286 | |
DiegoOstuni | 0:de13951f30f6 | 287 | return PayloadSize; |
DiegoOstuni | 0:de13951f30f6 | 288 | |
DiegoOstuni | 0:de13951f30f6 | 289 | } |
DiegoOstuni | 0:de13951f30f6 | 290 | |
DiegoOstuni | 0:de13951f30f6 | 291 | /** |
DiegoOstuni | 0:de13951f30f6 | 292 | * @brief This function write the NDEF file with the Vcard data given in the structure. |
DiegoOstuni | 0:de13951f30f6 | 293 | * @param pVcardStruct : pointer on structure that contain the Vcard information. |
DiegoOstuni | 0:de13951f30f6 | 294 | * @param pNDEFMessage : pointer on the NDEF message. |
DiegoOstuni | 0:de13951f30f6 | 295 | * @param size : to store the size of the NDEF message generated. |
DiegoOstuni | 0:de13951f30f6 | 296 | */ |
DiegoOstuni | 0:de13951f30f6 | 297 | void NDEF_PrepareVcardMessage( sVcardInfo *pVcardStruct, uint8_t *pNDEFMessage, uint16_t *size ) |
DiegoOstuni | 0:de13951f30f6 | 298 | { |
DiegoOstuni | 0:de13951f30f6 | 299 | |
DiegoOstuni | 0:de13951f30f6 | 300 | uint32_t PayloadSize = 0; |
DiegoOstuni | 0:de13951f30f6 | 301 | |
DiegoOstuni | 0:de13951f30f6 | 302 | /* Vcard Record Header */ |
DiegoOstuni | 0:de13951f30f6 | 303 | /************************************/ |
DiegoOstuni | 0:de13951f30f6 | 304 | /* 7 | 6 | 5 | 4 | 3 | 2 1 0 */ |
DiegoOstuni | 0:de13951f30f6 | 305 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 306 | /* MB ME CF SR IL TNF */ /* <---- CF=0, IL=0 and SR=0 TNF=2 NFC Forum Media type*/ |
DiegoOstuni | 0:de13951f30f6 | 307 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 308 | /* TYPE LENGTH */ |
DiegoOstuni | 0:de13951f30f6 | 309 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 310 | /* PAYLOAD LENGTH 3 */ |
DiegoOstuni | 0:de13951f30f6 | 311 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 312 | /* PAYLOAD LENGTH 2 */ |
DiegoOstuni | 0:de13951f30f6 | 313 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 314 | /* PAYLOAD LENGTH 1 */ |
DiegoOstuni | 0:de13951f30f6 | 315 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 316 | /* PAYLOAD LENGTH 0 */ |
DiegoOstuni | 0:de13951f30f6 | 317 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 318 | /* ID LENGTH */ /* <---- Not Used */ |
DiegoOstuni | 0:de13951f30f6 | 319 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 320 | /* TYPE */ |
DiegoOstuni | 0:de13951f30f6 | 321 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 322 | /* ID */ /* <---- Not Used */ |
DiegoOstuni | 0:de13951f30f6 | 323 | /************************************/ |
DiegoOstuni | 0:de13951f30f6 | 324 | |
DiegoOstuni | 0:de13951f30f6 | 325 | /* As we don't have embedded a jpeg encoder/decoder in this firmware */ |
DiegoOstuni | 0:de13951f30f6 | 326 | /* We have made the choice to manage only string content of the vCard */ |
DiegoOstuni | 0:de13951f30f6 | 327 | /* For demonstration purpose in order to fill the 8kB of the M24SR */ |
DiegoOstuni | 0:de13951f30f6 | 328 | /* We have embedded a NDEF vCard in the STM32 to be able to fill M24SR */ |
DiegoOstuni | 0:de13951f30f6 | 329 | |
DiegoOstuni | 0:de13951f30f6 | 330 | /* fill record header */ |
DiegoOstuni | 0:de13951f30f6 | 331 | uint32_t length = NDEF_GetVcardLength(pVcardStruct); |
DiegoOstuni | 0:de13951f30f6 | 332 | if(length >= 0xFF) |
DiegoOstuni | 0:de13951f30f6 | 333 | { |
DiegoOstuni | 0:de13951f30f6 | 334 | pNDEFMessage[0] = 0xC2; /* Record Flag */ |
DiegoOstuni | 0:de13951f30f6 | 335 | pNDEFMessage[1] = XVCARD_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 336 | pNDEFMessage[5] = length & 0xff; |
DiegoOstuni | 0:de13951f30f6 | 337 | pNDEFMessage[4] = (length>>8) & 0xff; |
DiegoOstuni | 0:de13951f30f6 | 338 | pNDEFMessage[3] = (length>>16) & 0xff; |
DiegoOstuni | 0:de13951f30f6 | 339 | pNDEFMessage[2] = length>>24; |
DiegoOstuni | 0:de13951f30f6 | 340 | memcpy( &pNDEFMessage[6], XVCARD_TYPE_STRING, XVCARD_TYPE_STRING_LENGTH ); |
DiegoOstuni | 0:de13951f30f6 | 341 | |
DiegoOstuni | 0:de13951f30f6 | 342 | /* Payload is positionned in the NDEF after record header */ |
DiegoOstuni | 0:de13951f30f6 | 343 | PayloadSize = 6 + XVCARD_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 344 | } else { |
DiegoOstuni | 0:de13951f30f6 | 345 | pNDEFMessage[0] = 0xD2; /* Record Flag */ |
DiegoOstuni | 0:de13951f30f6 | 346 | pNDEFMessage[1] = XVCARD_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 347 | pNDEFMessage[2] = length; |
DiegoOstuni | 0:de13951f30f6 | 348 | memcpy( &pNDEFMessage[3], XVCARD_TYPE_STRING, XVCARD_TYPE_STRING_LENGTH ); |
DiegoOstuni | 0:de13951f30f6 | 349 | |
DiegoOstuni | 0:de13951f30f6 | 350 | /* Payload is positionned in the NDEF after record header */ |
DiegoOstuni | 0:de13951f30f6 | 351 | PayloadSize = 3 + XVCARD_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 352 | } |
DiegoOstuni | 0:de13951f30f6 | 353 | |
DiegoOstuni | 0:de13951f30f6 | 354 | /* "BEGIN:VCARD\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 355 | memcpy( &pNDEFMessage[PayloadSize], BEGIN, BEGIN_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 356 | PayloadSize += BEGIN_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 357 | memcpy( &pNDEFMessage[PayloadSize], VCARD,VCARD_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 358 | PayloadSize += VCARD_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 359 | memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 360 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 361 | |
DiegoOstuni | 0:de13951f30f6 | 362 | /* "VERSION:2.1\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 363 | memcpy( &pNDEFMessage[PayloadSize], VERSION, VERSION_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 364 | PayloadSize += VERSION_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 365 | memcpy( &pNDEFMessage[PayloadSize], VCARD_VERSION_2_1, VCARD_VERSION_2_1_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 366 | PayloadSize += VCARD_VERSION_2_1_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 367 | memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 368 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 369 | |
DiegoOstuni | 0:de13951f30f6 | 370 | /* "N:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 371 | if(*pVcardStruct->Name != '\0') |
DiegoOstuni | 0:de13951f30f6 | 372 | { |
DiegoOstuni | 0:de13951f30f6 | 373 | memcpy( &pNDEFMessage[PayloadSize], VCARD_NAME, VCARD_NAME_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 374 | PayloadSize += VCARD_NAME_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 375 | memcpy( &pNDEFMessage[PayloadSize], pVcardStruct->Name, strlen(pVcardStruct->Name) ); |
DiegoOstuni | 0:de13951f30f6 | 376 | PayloadSize += strlen( pVcardStruct->Name ); |
DiegoOstuni | 0:de13951f30f6 | 377 | memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 378 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 379 | } |
DiegoOstuni | 0:de13951f30f6 | 380 | /* "FN:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 381 | if(*pVcardStruct->FirstName != '\0') |
DiegoOstuni | 0:de13951f30f6 | 382 | { |
DiegoOstuni | 0:de13951f30f6 | 383 | memcpy( &pNDEFMessage[PayloadSize], FIRSTNAME, FIRSTNAME_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 384 | PayloadSize += FIRSTNAME_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 385 | memcpy( &pNDEFMessage[PayloadSize], pVcardStruct->FirstName, strlen(pVcardStruct->FirstName) ); |
DiegoOstuni | 0:de13951f30f6 | 386 | PayloadSize += strlen( pVcardStruct->FirstName ); |
DiegoOstuni | 0:de13951f30f6 | 387 | memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 388 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 389 | } |
DiegoOstuni | 0:de13951f30f6 | 390 | if(*pVcardStruct->HomeTel != '\0') |
DiegoOstuni | 0:de13951f30f6 | 391 | { |
DiegoOstuni | 0:de13951f30f6 | 392 | |
DiegoOstuni | 0:de13951f30f6 | 393 | /* "TEL;HOME:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 394 | memcpy( &pNDEFMessage[PayloadSize], HOME_TEL, HOME_TEL_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 395 | PayloadSize += HOME_TEL_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 396 | memcpy( &pNDEFMessage[PayloadSize], pVcardStruct->HomeTel, strlen(pVcardStruct->HomeTel) ); |
DiegoOstuni | 0:de13951f30f6 | 397 | PayloadSize += strlen( pVcardStruct->HomeTel ); |
DiegoOstuni | 0:de13951f30f6 | 398 | memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 399 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 400 | } |
DiegoOstuni | 0:de13951f30f6 | 401 | if(*pVcardStruct->WorkTel != '\0') |
DiegoOstuni | 0:de13951f30f6 | 402 | { |
DiegoOstuni | 0:de13951f30f6 | 403 | |
DiegoOstuni | 0:de13951f30f6 | 404 | /* "TEL;WORK:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 405 | memcpy( &pNDEFMessage[PayloadSize], WORK_TEL, WORK_TEL_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 406 | PayloadSize += WORK_TEL_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 407 | memcpy( &pNDEFMessage[PayloadSize], pVcardStruct->WorkTel, strlen(pVcardStruct->WorkTel) ); |
DiegoOstuni | 0:de13951f30f6 | 408 | PayloadSize += strlen( pVcardStruct->WorkTel ); |
DiegoOstuni | 0:de13951f30f6 | 409 | memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 410 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 411 | } |
DiegoOstuni | 0:de13951f30f6 | 412 | if(*pVcardStruct->CellTel != '\0') |
DiegoOstuni | 0:de13951f30f6 | 413 | { |
DiegoOstuni | 0:de13951f30f6 | 414 | |
DiegoOstuni | 0:de13951f30f6 | 415 | /* "TEL;CELL:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 416 | memcpy( &pNDEFMessage[PayloadSize], CELL_TEL, CELL_TEL_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 417 | PayloadSize += CELL_TEL_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 418 | memcpy( &pNDEFMessage[PayloadSize], pVcardStruct->CellTel, strlen(pVcardStruct->CellTel) ); |
DiegoOstuni | 0:de13951f30f6 | 419 | PayloadSize += strlen( pVcardStruct->CellTel ); |
DiegoOstuni | 0:de13951f30f6 | 420 | memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 421 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 422 | } |
DiegoOstuni | 0:de13951f30f6 | 423 | if(*pVcardStruct->HomeEmail != '\0') |
DiegoOstuni | 0:de13951f30f6 | 424 | { |
DiegoOstuni | 0:de13951f30f6 | 425 | |
DiegoOstuni | 0:de13951f30f6 | 426 | /* "EMAIL;HOME:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 427 | memcpy( &pNDEFMessage[PayloadSize], HOME_EMAIL, HOME_EMAIL_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 428 | PayloadSize += HOME_EMAIL_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 429 | memcpy( &pNDEFMessage[PayloadSize], pVcardStruct->HomeEmail, strlen(pVcardStruct->HomeEmail) ); |
DiegoOstuni | 0:de13951f30f6 | 430 | PayloadSize += strlen( pVcardStruct->HomeEmail ); |
DiegoOstuni | 0:de13951f30f6 | 431 | memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 432 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 433 | } |
DiegoOstuni | 0:de13951f30f6 | 434 | if(*pVcardStruct->WorkEmail != '\0') |
DiegoOstuni | 0:de13951f30f6 | 435 | { |
DiegoOstuni | 0:de13951f30f6 | 436 | |
DiegoOstuni | 0:de13951f30f6 | 437 | /* "EMAIL;WORK:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 438 | memcpy( &pNDEFMessage[PayloadSize], WORK_EMAIL, WORK_EMAIL_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 439 | PayloadSize += WORK_EMAIL_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 440 | memcpy( &pNDEFMessage[PayloadSize], pVcardStruct->WorkEmail, strlen(pVcardStruct->WorkEmail) ); |
DiegoOstuni | 0:de13951f30f6 | 441 | PayloadSize += strlen( pVcardStruct->WorkEmail ); |
DiegoOstuni | 0:de13951f30f6 | 442 | memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 443 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 444 | } |
DiegoOstuni | 0:de13951f30f6 | 445 | if(*pVcardStruct->HomeAddress != '\0') |
DiegoOstuni | 0:de13951f30f6 | 446 | { |
DiegoOstuni | 0:de13951f30f6 | 447 | |
DiegoOstuni | 0:de13951f30f6 | 448 | /* "ADR;HOME:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 449 | memcpy( &pNDEFMessage[PayloadSize], HOME_ADDRESS, HOME_ADDRESS_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 450 | PayloadSize += HOME_ADDRESS_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 451 | memcpy( &pNDEFMessage[PayloadSize], pVcardStruct->HomeAddress, strlen(pVcardStruct->HomeAddress) ); |
DiegoOstuni | 0:de13951f30f6 | 452 | PayloadSize += strlen( pVcardStruct->HomeAddress ); |
DiegoOstuni | 0:de13951f30f6 | 453 | memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 454 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 455 | } |
DiegoOstuni | 0:de13951f30f6 | 456 | if(*pVcardStruct->WorkAddress != '\0') |
DiegoOstuni | 0:de13951f30f6 | 457 | { |
DiegoOstuni | 0:de13951f30f6 | 458 | |
DiegoOstuni | 0:de13951f30f6 | 459 | /* "ADR;WORK:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 460 | memcpy( &pNDEFMessage[PayloadSize], WORK_ADDRESS, WORK_ADDRESS_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 461 | PayloadSize += WORK_ADDRESS_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 462 | memcpy( &pNDEFMessage[PayloadSize], pVcardStruct->WorkAddress, strlen(pVcardStruct->WorkAddress) ); |
DiegoOstuni | 0:de13951f30f6 | 463 | PayloadSize += strlen( pVcardStruct->WorkAddress ); |
DiegoOstuni | 0:de13951f30f6 | 464 | memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 465 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 466 | } |
DiegoOstuni | 0:de13951f30f6 | 467 | if(*pVcardStruct->Org != '\0') |
DiegoOstuni | 0:de13951f30f6 | 468 | { |
DiegoOstuni | 0:de13951f30f6 | 469 | |
DiegoOstuni | 0:de13951f30f6 | 470 | /* "ORG:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 471 | memcpy( &pNDEFMessage[PayloadSize], ORG, ORG_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 472 | PayloadSize += ORG_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 473 | memcpy( &pNDEFMessage[PayloadSize], pVcardStruct->Org, strlen(pVcardStruct->Org) ); |
DiegoOstuni | 0:de13951f30f6 | 474 | PayloadSize += strlen( pVcardStruct->Org ); |
DiegoOstuni | 0:de13951f30f6 | 475 | memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 476 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 477 | } |
DiegoOstuni | 0:de13951f30f6 | 478 | if(*pVcardStruct->Title != '\0') |
DiegoOstuni | 0:de13951f30f6 | 479 | { |
DiegoOstuni | 0:de13951f30f6 | 480 | /* "TITLE:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 481 | memcpy( &pNDEFMessage[PayloadSize], TITLE, TITLE_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 482 | PayloadSize += TITLE_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 483 | memcpy( &pNDEFMessage[PayloadSize], pVcardStruct->Title, strlen(pVcardStruct->Title) ); |
DiegoOstuni | 0:de13951f30f6 | 484 | PayloadSize += strlen( pVcardStruct->Title ); |
DiegoOstuni | 0:de13951f30f6 | 485 | memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 486 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 487 | } |
DiegoOstuni | 0:de13951f30f6 | 488 | if(*pVcardStruct->Url != '\0') |
DiegoOstuni | 0:de13951f30f6 | 489 | { |
DiegoOstuni | 0:de13951f30f6 | 490 | /* "URL:\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 491 | memcpy( &pNDEFMessage[PayloadSize], URL, URL_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 492 | PayloadSize += URL_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 493 | memcpy( &pNDEFMessage[PayloadSize], pVcardStruct->Url, strlen(pVcardStruct->Url) ); |
DiegoOstuni | 0:de13951f30f6 | 494 | PayloadSize += strlen( pVcardStruct->Url ); |
DiegoOstuni | 0:de13951f30f6 | 495 | memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 496 | PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 497 | } |
DiegoOstuni | 0:de13951f30f6 | 498 | |
DiegoOstuni | 0:de13951f30f6 | 499 | /* "END:VCARD\r\n" */ |
DiegoOstuni | 0:de13951f30f6 | 500 | memcpy( &pNDEFMessage[PayloadSize], END, END_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 501 | PayloadSize += END_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 502 | memcpy( &pNDEFMessage[PayloadSize], VCARD, VCARD_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 503 | PayloadSize += VCARD_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 504 | // memcpy( &pNDEFMessage[PayloadSize], LIMIT, LIMIT_STRING_SIZE ); |
DiegoOstuni | 0:de13951f30f6 | 505 | // PayloadSize += LIMIT_STRING_SIZE; |
DiegoOstuni | 0:de13951f30f6 | 506 | |
DiegoOstuni | 0:de13951f30f6 | 507 | *size = (uint16_t)(PayloadSize); /* Must not count the 2 byte that represent the NDEF size */ |
DiegoOstuni | 0:de13951f30f6 | 508 | /* |
DiegoOstuni | 0:de13951f30f6 | 509 | PayloadSize -= 6 + VCARD_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 510 | |
DiegoOstuni | 0:de13951f30f6 | 511 | pNDEFMessage[2] = (PayloadSize & 0xFF000000) >> 24; |
DiegoOstuni | 0:de13951f30f6 | 512 | pNDEFMessage[3] = (PayloadSize & 0x00FF0000) >> 16; |
DiegoOstuni | 0:de13951f30f6 | 513 | pNDEFMessage[4] = (PayloadSize & 0x0000FF00) >> 8; |
DiegoOstuni | 0:de13951f30f6 | 514 | pNDEFMessage[5] = PayloadSize & 0x000000FF; |
DiegoOstuni | 0:de13951f30f6 | 515 | */ |
DiegoOstuni | 0:de13951f30f6 | 516 | } |
DiegoOstuni | 0:de13951f30f6 | 517 | |
DiegoOstuni | 0:de13951f30f6 | 518 | |
DiegoOstuni | 0:de13951f30f6 | 519 | /** |
DiegoOstuni | 0:de13951f30f6 | 520 | * @brief This function extracts binary data from a base64 representation. |
DiegoOstuni | 0:de13951f30f6 | 521 | * @param input64 : pointer on the input data in base64. |
DiegoOstuni | 0:de13951f30f6 | 522 | * @param binary : returned binary data. |
DiegoOstuni | 0:de13951f30f6 | 523 | * @return Updated pointer on the input64 buffer (normal increment is 4 base64 char for 3 bytes of binary data, but special char are ignored) |
DiegoOstuni | 0:de13951f30f6 | 524 | */ |
DiegoOstuni | 0:de13951f30f6 | 525 | static uint8_t* from_base64(uint8_t *input64, uint32_t* binary) |
DiegoOstuni | 0:de13951f30f6 | 526 | { |
DiegoOstuni | 0:de13951f30f6 | 527 | /* Read 4 base64 character & translate them into 3 bytes binary */ |
DiegoOstuni | 0:de13951f30f6 | 528 | *binary = 0; |
DiegoOstuni | 0:de13951f30f6 | 529 | uint8_t base64_6bits; |
DiegoOstuni | 0:de13951f30f6 | 530 | int i = 0; |
DiegoOstuni | 0:de13951f30f6 | 531 | while(i<4) |
DiegoOstuni | 0:de13951f30f6 | 532 | { |
DiegoOstuni | 0:de13951f30f6 | 533 | |
DiegoOstuni | 0:de13951f30f6 | 534 | if((*input64 >= 'A') && (*input64 <= 'Z')) |
DiegoOstuni | 0:de13951f30f6 | 535 | { |
DiegoOstuni | 0:de13951f30f6 | 536 | base64_6bits = *(input64++) - 'A'; |
DiegoOstuni | 0:de13951f30f6 | 537 | } else if ((*input64 >= 'a') && (*input64 <= 'z')) |
DiegoOstuni | 0:de13951f30f6 | 538 | { |
DiegoOstuni | 0:de13951f30f6 | 539 | base64_6bits = *(input64++) - 'a' + 26; |
DiegoOstuni | 0:de13951f30f6 | 540 | } else if ((*input64 >= '0') && (*input64 <= '9')) { |
DiegoOstuni | 0:de13951f30f6 | 541 | base64_6bits = *(input64++) - '0' + 52; |
DiegoOstuni | 0:de13951f30f6 | 542 | } else if (*input64 == '+') |
DiegoOstuni | 0:de13951f30f6 | 543 | { |
DiegoOstuni | 0:de13951f30f6 | 544 | base64_6bits = 62; |
DiegoOstuni | 0:de13951f30f6 | 545 | input64++; |
DiegoOstuni | 0:de13951f30f6 | 546 | } else if (*input64 == '/') |
DiegoOstuni | 0:de13951f30f6 | 547 | { |
DiegoOstuni | 0:de13951f30f6 | 548 | base64_6bits = 63; |
DiegoOstuni | 0:de13951f30f6 | 549 | input64++; |
DiegoOstuni | 0:de13951f30f6 | 550 | } else if (*input64 == '=') { |
DiegoOstuni | 0:de13951f30f6 | 551 | base64_6bits = 0; |
DiegoOstuni | 0:de13951f30f6 | 552 | input64++; |
DiegoOstuni | 0:de13951f30f6 | 553 | } else { |
DiegoOstuni | 0:de13951f30f6 | 554 | input64++; |
DiegoOstuni | 0:de13951f30f6 | 555 | continue; |
DiegoOstuni | 0:de13951f30f6 | 556 | } |
DiegoOstuni | 0:de13951f30f6 | 557 | |
DiegoOstuni | 0:de13951f30f6 | 558 | *binary |= base64_6bits << (6*(3-i)); |
DiegoOstuni | 0:de13951f30f6 | 559 | i++; |
DiegoOstuni | 0:de13951f30f6 | 560 | } |
DiegoOstuni | 0:de13951f30f6 | 561 | *binary = ((*binary & 0xFF0000)>>16) | ((*binary & 0xFF)<<16) | (*binary & 0xFF00); |
DiegoOstuni | 0:de13951f30f6 | 562 | return input64; |
DiegoOstuni | 0:de13951f30f6 | 563 | } |
DiegoOstuni | 0:de13951f30f6 | 564 | |
DiegoOstuni | 0:de13951f30f6 | 565 | |
DiegoOstuni | 0:de13951f30f6 | 566 | /** |
DiegoOstuni | 0:de13951f30f6 | 567 | * @brief This function return the picture stored in a VCARD. |
DiegoOstuni | 0:de13951f30f6 | 568 | * @param pPayload : pointer on the payload data of the NDEF message. |
DiegoOstuni | 0:de13951f30f6 | 569 | * @param PayloadSize : number of data in the payload. |
DiegoOstuni | 0:de13951f30f6 | 570 | * @param pPict : Pointer on the dpicture buffer (must be big enough to contain the picture - warning: no check is done in the function). |
DiegoOstuni | 0:de13951f30f6 | 571 | */ |
DiegoOstuni | 0:de13951f30f6 | 572 | int NDEF_getVcardPicture( uint8_t* pPayload, uint32_t PayloadSize, uint8_t* pPict ) |
DiegoOstuni | 0:de13951f30f6 | 573 | { |
DiegoOstuni | 0:de13951f30f6 | 574 | uint8_t* pSrcPict; |
DiegoOstuni | 0:de13951f30f6 | 575 | |
DiegoOstuni | 0:de13951f30f6 | 576 | |
DiegoOstuni | 0:de13951f30f6 | 577 | /* Let's find the picture */ |
DiegoOstuni | 0:de13951f30f6 | 578 | pSrcPict = pPayload; |
DiegoOstuni | 0:de13951f30f6 | 579 | while( memcmp( pSrcPict, JPEG, JPEG_STRING_SIZE ) && (pSrcPict < (pPayload + PayloadSize)) ) |
DiegoOstuni | 0:de13951f30f6 | 580 | { |
DiegoOstuni | 0:de13951f30f6 | 581 | pSrcPict++; |
DiegoOstuni | 0:de13951f30f6 | 582 | } |
DiegoOstuni | 0:de13951f30f6 | 583 | while( (*pSrcPict != ':') && (pSrcPict < (pPayload + PayloadSize)) ) |
DiegoOstuni | 0:de13951f30f6 | 584 | { |
DiegoOstuni | 0:de13951f30f6 | 585 | pSrcPict++; |
DiegoOstuni | 0:de13951f30f6 | 586 | } |
DiegoOstuni | 0:de13951f30f6 | 587 | /* Picture start at next char */ |
DiegoOstuni | 0:de13951f30f6 | 588 | pSrcPict++; |
DiegoOstuni | 0:de13951f30f6 | 589 | |
DiegoOstuni | 0:de13951f30f6 | 590 | |
DiegoOstuni | 0:de13951f30f6 | 591 | /* Word found */ |
DiegoOstuni | 0:de13951f30f6 | 592 | while( memcmp( pSrcPict, LIMIT, LIMIT_STRING_SIZE ) && (pSrcPict < (pPayload + PayloadSize) ) ) |
DiegoOstuni | 0:de13951f30f6 | 593 | { |
DiegoOstuni | 0:de13951f30f6 | 594 | uint32_t binary24; |
DiegoOstuni | 0:de13951f30f6 | 595 | pSrcPict = from_base64(pSrcPict, &binary24); |
DiegoOstuni | 0:de13951f30f6 | 596 | /* copy the 3 bytes read from the base64 data */ |
DiegoOstuni | 0:de13951f30f6 | 597 | memcpy( pPict, &binary24, 3); |
DiegoOstuni | 0:de13951f30f6 | 598 | pPict += 3; |
DiegoOstuni | 0:de13951f30f6 | 599 | /* Ignore any line breaks */ |
DiegoOstuni | 0:de13951f30f6 | 600 | while (*pSrcPict == 0x0A) |
DiegoOstuni | 0:de13951f30f6 | 601 | { |
DiegoOstuni | 0:de13951f30f6 | 602 | pSrcPict++; |
DiegoOstuni | 0:de13951f30f6 | 603 | } |
DiegoOstuni | 0:de13951f30f6 | 604 | } |
DiegoOstuni | 0:de13951f30f6 | 605 | |
DiegoOstuni | 0:de13951f30f6 | 606 | if(pSrcPict >= (pPayload + PayloadSize)) |
DiegoOstuni | 0:de13951f30f6 | 607 | { |
DiegoOstuni | 0:de13951f30f6 | 608 | /* problem when parsing the picture */ |
DiegoOstuni | 0:de13951f30f6 | 609 | return 1; |
DiegoOstuni | 0:de13951f30f6 | 610 | } else { |
DiegoOstuni | 0:de13951f30f6 | 611 | /* picture found */ |
DiegoOstuni | 0:de13951f30f6 | 612 | return 0; |
DiegoOstuni | 0:de13951f30f6 | 613 | } |
DiegoOstuni | 0:de13951f30f6 | 614 | } |
DiegoOstuni | 0:de13951f30f6 | 615 | |
DiegoOstuni | 0:de13951f30f6 | 616 | /** |
DiegoOstuni | 0:de13951f30f6 | 617 | * @} |
DiegoOstuni | 0:de13951f30f6 | 618 | */ |
DiegoOstuni | 0:de13951f30f6 | 619 | |
DiegoOstuni | 0:de13951f30f6 | 620 | /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/ |