NFC NDEF library
Dependents: Nucleo_NFC_Example I2C_NFC_Master Print_Entire_Nucleo_NFC01A1_Memory
Fork of lib_NDEF by
Revision 0:3b093bd0819e, committed 2014-12-15
- Comitter:
- EnricoG
- Date:
- Mon Dec 15 19:41:36 2014 +0000
- Commit message:
- Initial commit
Changed in this revision
diff -r 000000000000 -r 3b093bd0819e lib_ISO7816_Password.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_ISO7816_Password.c Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,184 @@ +/** + ****************************************************************************** + * @file lib_ISO7816_Password.c + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage password in the ISO7816 context. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "lib_ISO7816_Password.h" + +/** @addtogroup NFC_libraries + * @{ + * @brief <b>This is the library used to manage the content of the TAG (data) + * But also the specific feature of the tag, for instance + * password, gpo... </b> + */ + + +/** @addtogroup libISO7816 + * @{ + * @brief This part of the library help to manage TAG with ISO7816 feature. + */ + + +/** @defgroup libPassword_Private_Functions + * @{ + */ + +/** + * @} + */ + +/** @defgroup libPassword_Public_Functions + * @{ + * @brief This file is used to manage password with NDEF file + */ + +/** + * @brief This fonction activate the need of a password for next read access + * @param pCurrentWritePassword : Write password is needed to have the right to enable Read Password + * @param pNewPassword : The password that will be requiered for next read access + * @retval SUCCESS : Read password is activated + * @retval ERROR : operation does not complete + */ +uint16_t ISO7816_EnableReadPwd(uint8_t* pCurrentWritePassword, uint8_t* pNewPassword) +{ + uint16_t status; + uint16_t FileId; + + /* Before using Verify command NDEF file must be selected */ + GetNDEFFileId(&FileId); + OpenNDEFSession(FileId, ASK_FOR_SESSION); + + status = EnableReadPassword( pCurrentWritePassword, pNewPassword); + + CloseNDEFSession(FileId); + + return status; +} + +/** + * @brief This fonction desactivate the need of a password for next read access + * @param pCurrentWritePassword : Write password is needed to have the right to disable Read Password + * @retval SUCCESS : Read password is desactivated + * @retval ERROR : operation does not complete + */ +uint16_t ISO7816_DisableReadPwd(uint8_t* pCurrentWritePassword ) +{ + uint16_t status; + uint16_t FileId; + + /* Before using Verify command NDEF file must be selected */ + GetNDEFFileId(&FileId); + OpenNDEFSession(FileId, ASK_FOR_SESSION); + + status = DisableReadPassword( pCurrentWritePassword ); + + CloseNDEFSession(FileId); + + return status; +} + +/** + * @brief This fonction activate the need of a password for next write access + * @param pCurrentWritePassword : Write password must be prensented to have the right to modify write Password + * @param pNewPassword : The password that will be requiered for next write access + * @retval SUCCESS : Write password is activated + * @retval ERROR : operation does not complete + */ +uint16_t ISO7816_EnableWritePwd(uint8_t* pCurrentWritePassword, uint8_t* pNewPassword) +{ + uint16_t status; + uint16_t FileId; + + /* Before using Verify command NDEF file must be selected */ + GetNDEFFileId(&FileId); + OpenNDEFSession(FileId, ASK_FOR_SESSION); + + status = EnableWritePassword( pCurrentWritePassword, pNewPassword); + + CloseNDEFSession(FileId); + + return status; +} + +/** + * @brief This fonction desactivate the need of a password for next write access + * @param pCurrentWritePassword : Write password must be prensented to have the right to disable it + * @retval SUCCESS : Write password is desactivated + * @retval ERROR : operation does not complete + */ +uint16_t ISO7816_DisableWritePwd(uint8_t* pCurrentWritePassword) +{ + uint16_t status; + uint16_t FileId; + + /* Before using Verify command NDEF file must be selected */ + GetNDEFFileId(&FileId); + OpenNDEFSession(FileId, ASK_FOR_SESSION); + + status = DisableWritePassword( pCurrentWritePassword); + + CloseNDEFSession(FileId); + + return status; +} + +/** + * @brief This fonction desactivate the need of read and write password for next access + * @param pSuperUserPassword : I2C super user password to overwrite read and write password + * @retval SUCCESS : M24SR access is now free (no password needed) + * @retval ERROR : operation does not complete + */ +uint16_t ISO7816_DisableAllPassword(uint8_t* pSuperUserPassword) +{ + uint16_t status; + uint16_t FileId; + + /* Before using Verify command NDEF file must be selected */ + GetNDEFFileId(&FileId); + OpenNDEFSession(FileId, TAKE_SESSION); + + status = DisableAllPassword( pSuperUserPassword); + + CloseNDEFSession(FileId); + + return status; +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/ +
diff -r 000000000000 -r 3b093bd0819e lib_ISO7816_Password.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_ISO7816_Password.h Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,42 @@ +/** + ****************************************************************************** + * @file lib_ISO7816_Password.h + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage password. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LIB_ISO7816_PASSWORD_H +#define __LIB_ISO7816_PASSWORD_H + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF.h" + +uint16_t ISO7816_EnableReadPwd(uint8_t* pCurrentWritePassword, uint8_t* pNewPassword); +uint16_t ISO7816_DisableReadPwd(uint8_t* pCurrentWritePassword); +uint16_t ISO7816_EnableWritePwd(uint8_t* pCurrentWritePassword, uint8_t* pNewPassword); +uint16_t ISO7816_DisableWritePwd(uint8_t* pCurrentWritePassword); +uint16_t ISO7816_DisableAllPassword(uint8_t* pSuperUserPassword); +#endif /* __LIB_ISO7816_PASSWORD_H */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 3b093bd0819e lib_NDEF.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF.c Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,526 @@ +/** + ****************************************************************************** + * @file lib_NDEF.c + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage NDEF file, to parse and identify them. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF.h" + +/** @addtogroup NFC_libraries + * @{ + * @brief <b>This is the library used to manage the content of the TAG (data) + * But also the specific feature of the tag, for instance + * password, gpo... </b> + */ + + +/** @addtogroup libNFC_FORUM + * @{ + * @brief This part of the library manage data which follow NFC forum organisation. + */ + +/** @defgroup libNDEF_Private_Functions + * @{ + */ + + +static uint16_t NDEF_IsNDEFPresent ( void ); +static uint16_t NDEF_ParseRecordHeader ( sRecordInfo *pRecordStruct ); +static void NDEF_ParseWellKnownType ( sRecordInfo *pRecordStruct ); +static void NDEF_ParseMediaType ( sRecordInfo *pRecordStruct ); +static void NDEF_ParseForumExternalType ( sRecordInfo *pRecordStruct ); +static void NDEF_ParseURI(sRecordInfo *pRecordStruct); +static void NDEF_ParseSP(sRecordInfo *pRecordStruct); +static uint16_t NDEF_IdentifySPRecord ( sRecordInfo *pRecordStruct, uint8_t* pPayload ); + +/* In case of smart Poster composed with different record, 3 records supported so far */ +sRecordInfo SPRecordStruct1, SPRecordStruct2, SPRecordStruct3; +uint32_t SPRecordStructAdd[SP_MAX_RECORD] = { (uint32_t)&SPRecordStruct1, (uint32_t)&SPRecordStruct2, (uint32_t)&SPRecordStruct3 }; + +/** + * @brief This fonction check that the tag contain a NDEF message + * @param None : + * @retval SUCCESS : There is a NDEF file stored in tag + * @retval ERROR : No NDEF in the tag. + */ +static uint16_t NDEF_IsNDEFPresent ( void ) +{ + uint16_t FileSize; + uint8_t uM24SR_NDEFHeader [0x2]; + + /* Check NDEF existence */ + ReadData ( NDEF_SIZE_OFFSET , 2 , uM24SR_NDEFHeader); + FileSize = (uint16_t) ((uM24SR_NDEFHeader[0x00]<<8) | uM24SR_NDEFHeader[0x01]); + + if( FileSize != 0) + return SUCCESS; + else + return ERROR; +} + +/** + * @brief This fonction identify the type of record + * @param pRecordStruct : pointer on the record structure to fill + * @param pPayload : pointer on the payload + * @retval Status : Status of the operation. + */ +static uint16_t NDEF_IdentifySPRecord ( sRecordInfo *pRecordStruct, uint8_t* pPayload ) +{ + uint16_t status = ERROR; + uint16_t SizeOfRecordHeader, TypeNbByte, PayloadLengthField, IDLengthField, IDNbByte; + + /* Is ID length field present */ + if( (*pPayload)&IL_Mask) + { + IDLengthField = ID_LENGTH_FIELD; + } + else + { + IDLengthField = 0; + } + + /* it's a SR */ + if( (*pPayload)&SR_Mask) + { + TypeNbByte = pPayload[1]; + PayloadLengthField = 1; + if( IDLengthField == ID_LENGTH_FIELD) + IDNbByte = pPayload[3]; + else + IDNbByte = 0; + } + else + { + TypeNbByte = pPayload[1]; + PayloadLengthField = 4; + if( IDLengthField == ID_LENGTH_FIELD) + IDNbByte = pPayload[6]; + else + IDNbByte = 0; + } + + SizeOfRecordHeader = RECORD_FLAG_FIELD + TYPE_LENGTH_FIELD + PayloadLengthField + IDLengthField + TypeNbByte + IDNbByte; + + /* it's a SR */ + if( pPayload[0]&SR_Mask) + { + pRecordStruct->RecordFlags = pPayload[0]; + pRecordStruct->TypeLength = TypeNbByte; + pRecordStruct->PayloadLength3 = 0; + pRecordStruct->PayloadLength2 = 0; + pRecordStruct->PayloadLength1 = 0; + pRecordStruct->PayloadLength0 = pPayload[2]; + pRecordStruct->IDLength = IDNbByte; + memcpy(pRecordStruct->Type, &pPayload[3+IDNbByte] , TypeNbByte); + memcpy(pRecordStruct->ID, &pPayload[3+IDNbByte+TypeNbByte] , IDNbByte); + pRecordStruct->PayloadOffset = SizeOfRecordHeader; + } + else + { + pRecordStruct->RecordFlags = pPayload[0]; + pRecordStruct->TypeLength = TypeNbByte; + pRecordStruct->PayloadLength3 = pPayload[2]; + pRecordStruct->PayloadLength2 = pPayload[3]; + pRecordStruct->PayloadLength1 = pPayload[4]; + pRecordStruct->PayloadLength0 = pPayload[5]; + pRecordStruct->IDLength = IDNbByte; + memcpy(pRecordStruct->Type, &pPayload[6+IDNbByte] , TypeNbByte); + memcpy(pRecordStruct->ID, &pPayload[6+IDNbByte+TypeNbByte] , IDNbByte); + pRecordStruct->PayloadOffset = SizeOfRecordHeader; + } + + pRecordStruct->PayloadBufferAdd = (uint32_t)(pPayload+SizeOfRecordHeader); + + status = NDEF_ParseRecordHeader(pRecordStruct); + + return status; +} + +/** + * @brief This fonction parse the record header and dispatch regarding TNF value + * @param pRecordStruct : pointer on the record structure to fill + * @retval SUCCESS : record identified and structure filled + * @retval ERROR : Not supported + */ +static uint16_t NDEF_ParseRecordHeader ( sRecordInfo *pRecordStruct ) +{ + uint16_t status = SUCCESS; + + switch( (pRecordStruct->RecordFlags&TNF_Mask)) + { + case TNF_WellKnown: + NDEF_ParseWellKnownType ( pRecordStruct ); + break; + + case TNF_MediaType: + NDEF_ParseMediaType ( pRecordStruct ); + break; + + case TNF_NFCForumExternal: + NDEF_ParseForumExternalType ( pRecordStruct); + break; + + default: + /* currently not supported or unknown*/ + pRecordStruct->NDEF_Type = UNKNOWN_TYPE; + status = ERROR; + } + return status; +} + +/** + * @brief This fonction parse the Well Known type record + * @param pRecordStruct : pointer on the record structure to fill + * @retval None + */ +static void NDEF_ParseWellKnownType ( sRecordInfo *pRecordStruct ) +{ + uint8_t* pPayload; + + pPayload = (uint8_t*)(pRecordStruct->PayloadBufferAdd); + + if( !memcmp( &(pRecordStruct->Type), SMART_POSTER_TYPE_STRING, pRecordStruct->TypeLength)) + { + /* special case where we have to parse others records */ + pRecordStruct->NDEF_Type = SMARTPOSTER_TYPE; + NDEF_ParseSP(pRecordStruct); + } + + else if( !memcmp( &(pRecordStruct->Type), URI_TYPE_STRING, pRecordStruct->TypeLength)) + { + /* it's an URI Type check if it's an URL or SMS or ... */ + /* check identifier */ + if( *pPayload == URI_ID_0x00) + { + NDEF_ParseURI(pRecordStruct); + } + else if ( *pPayload > URI_ID_0x00 && *pPayload < URI_RFU ) + { + /* email special case */ + if ( *pPayload == (uint8_t) URI_ID_0x06) + { + pRecordStruct->NDEF_Type = URI_EMAIL_TYPE; + } + else + { + pRecordStruct->NDEF_Type = WELL_KNOWN_ABRIDGED_URI_TYPE; + } + } + else + { + pRecordStruct->NDEF_Type = UNKNOWN_TYPE; + } + } + + else if( !memcmp( &(pRecordStruct->Type), TEXT_TYPE_STRING, pRecordStruct->TypeLength)) + { + pRecordStruct->NDEF_Type = TEXT_TYPE; + } + else + pRecordStruct->NDEF_Type = UNKNOWN_TYPE; + +} + +/** + * @brief This fonction parse the Media type record + * @param pRecordStruct : pointer on the record structure to fill + * @retval None + */ +static void NDEF_ParseMediaType ( sRecordInfo *pRecordStruct ) +{ + if( !memcmp( &(pRecordStruct->Type), VCARD_TYPE_STRING, pRecordStruct->TypeLength)) + pRecordStruct->NDEF_Type = VCARD_TYPE; + else if( !memcmp( &(pRecordStruct->Type), XVCARD_TYPE_STRING, pRecordStruct->TypeLength)) + pRecordStruct->NDEF_Type = VCARD_TYPE; + else + pRecordStruct->NDEF_Type = UNKNOWN_TYPE; +} + +/** + * @brief This fonction parse the Forum External type record + * @param pRecordStruct : pointer on the record structure to fill + * @retval None + */ +static void NDEF_ParseForumExternalType ( sRecordInfo *pRecordStruct ) +{ + if( !memcmp( &(pRecordStruct->Type), M24SR_DISCOVERY_APP_STRING, pRecordStruct->TypeLength)) + pRecordStruct->NDEF_Type = M24SR_DISCOVERY_APP_TYPE; + else + pRecordStruct->NDEF_Type = UNKNOWN_TYPE; +} + +/** + * @brief This fonction parse the URI type record + * @param pRecordStruct : pointer on the record structure to fill + * @retval None + */ +static void NDEF_ParseURI(sRecordInfo *pRecordStruct) +{ + uint8_t* pPayload; + + pPayload = (uint8_t*)(pRecordStruct->PayloadBufferAdd); + pPayload ++; /* to skip URI identifier first URI payload byte */ + + if( !memcmp( pPayload, SMS_TYPE_STRING, strlen(SMS_TYPE_STRING)) ) + { + pRecordStruct->NDEF_Type = URI_SMS_TYPE; + } + else if( !memcmp( pPayload, GEO_TYPE_STRING, strlen(GEO_TYPE_STRING)) ) + { + pRecordStruct->NDEF_Type = URI_GEO_TYPE; + } + else + pRecordStruct->NDEF_Type = UNKNOWN_TYPE; + +} + +/** + * @brief This fonction parse the Smart Poster + * @param pRecordStruct : pointer on the record structure to fill + * @retval None + */ +static void NDEF_ParseSP(sRecordInfo *pRecordStruct) +{ + uint8_t* pPayload; + uint32_t PayloadSize = 0; + uint32_t SPPayloadSize = 0; + uint32_t OffsetInSPPayload =0; + uint32_t RecordPosition = 0; + sRecordInfo *pSPRecordStruct; + + /* initialize variable with size of the payload and poiter on data */ + PayloadSize = ((uint32_t)(pRecordStruct->PayloadLength3)<<24) | ((uint32_t)(pRecordStruct->PayloadLength2)<<16) | + ((uint32_t)(pRecordStruct->PayloadLength1)<<8) | pRecordStruct->PayloadLength0; + + pPayload = (uint8_t*)(pRecordStruct->PayloadBufferAdd); + + pSPRecordStruct = (sRecordInfo *)SPRecordStructAdd[0]; + + /* Initailize the number of record find in the SP payload */ + pRecordStruct->NbOfRecordInSPPayload = 0; + + do + { + pSPRecordStruct = (sRecordInfo *)SPRecordStructAdd[RecordPosition]; + /* identify the 1st record in the SP payload */ + if( NDEF_IdentifySPRecord ( pSPRecordStruct, pPayload )) + { + /* store add of structure that will contain the other record information */ + pRecordStruct->NbOfRecordInSPPayload ++; + pRecordStruct->SPRecordStructAdd[RecordPosition] = (uint32_t) pSPRecordStruct; + + /* After SPRecord + First Record check if we are at the end of NDEF file */ + SPPayloadSize = ((uint32_t)(pSPRecordStruct->PayloadLength3)<<24) | ((uint32_t)(pSPRecordStruct->PayloadLength2)<<16) | + ((uint32_t)(pSPRecordStruct->PayloadLength1)<<8) | pSPRecordStruct->PayloadLength0; + + OffsetInSPPayload += pSPRecordStruct->PayloadOffset + SPPayloadSize; + pPayload += OffsetInSPPayload; + RecordPosition++; + } + } + while( OffsetInSPPayload < PayloadSize && RecordPosition<SP_MAX_RECORD); /* there is another record */ + +} + +/** + * @} + */ + +/** @defgroup libNDEF_Public_Functions + * @{ + */ + + +/** + * @brief This fonction identify the NDEF message stored in tag + * @param pRecordStruct : Structure to fill with record information + * @param pNDEF : pointer on the NDEF message data + * @retval SUCCESS : record struct filled + * @retval ERROR : record struct not updated + */ + +uint16_t NDEF_IdentifyNDEF ( sRecordInfo *pRecordStruct, uint8_t* pNDEF ) +{ + uint16_t status = ERROR; + uint16_t SizeOfRecordHeader, TypeNbByte, PayloadLengthField, IDLengthField, IDNbByte; + uint32_t PayloadSize; + + /* check NDEF present */ + if(NDEF_IsNDEFPresent() != SUCCESS) + { + return ERROR; + } + + /* Analyse record layout */ + ReadData ( FIRST_RECORD_OFFSET , 1 , pNDEF); + + /* Is ID length field present */ + if( (*pNDEF)&IL_Mask) + { + IDLengthField = ID_LENGTH_FIELD; + } + else + { + IDLengthField = 0; + } + + /* it's a SR */ + if( (*pNDEF)&SR_Mask) + { + /* Analyse short record layout */ + ReadData ( FIRST_RECORD_OFFSET , 4 , pNDEF); + TypeNbByte = pNDEF[1]; + PayloadLengthField = 1; + if( IDLengthField == ID_LENGTH_FIELD) + IDNbByte = pNDEF[3]; + else + IDNbByte = 0; + } + else + { + /* Analyse normal record layout */ + ReadData ( FIRST_RECORD_OFFSET , 7 , pNDEF); + TypeNbByte = pNDEF[1]; + PayloadLengthField = 4; + if( IDLengthField == ID_LENGTH_FIELD) + IDNbByte = pNDEF[6]; + else + IDNbByte = 0; + } + + SizeOfRecordHeader = RECORD_FLAG_FIELD + TYPE_LENGTH_FIELD + PayloadLengthField + IDLengthField + TypeNbByte + IDNbByte; + + /* Read record header */ + ReadData ( FIRST_RECORD_OFFSET , SizeOfRecordHeader , pNDEF); + /* it's a SR */ + if( pNDEF[0]&SR_Mask) + { + pRecordStruct->RecordFlags = pNDEF[0]; + pRecordStruct->TypeLength = TypeNbByte; + pRecordStruct->PayloadLength3 = 0; + pRecordStruct->PayloadLength2 = 0; + pRecordStruct->PayloadLength1 = 0; + pRecordStruct->PayloadLength0 = pNDEF[2]; + pRecordStruct->IDLength = IDNbByte; + memcpy(pRecordStruct->Type, &pNDEF[3+IDNbByte] , TypeNbByte); + memcpy(pRecordStruct->ID, &pNDEF[3+IDNbByte+TypeNbByte] , IDNbByte); + pRecordStruct->PayloadOffset = SizeOfRecordHeader; + } + else + { + pRecordStruct->RecordFlags = pNDEF[0]; + pRecordStruct->TypeLength = TypeNbByte; + pRecordStruct->PayloadLength3 = pNDEF[2]; + pRecordStruct->PayloadLength2 = pNDEF[3]; + pRecordStruct->PayloadLength1 = pNDEF[4]; + pRecordStruct->PayloadLength0 = pNDEF[5]; + pRecordStruct->IDLength = IDNbByte; + memcpy(pRecordStruct->Type, &pNDEF[6+IDNbByte] , TypeNbByte); + memcpy(pRecordStruct->ID, &pNDEF[6+IDNbByte+TypeNbByte] , IDNbByte); + pRecordStruct->PayloadOffset = SizeOfRecordHeader; + } + + PayloadSize = ((uint32_t)(pRecordStruct->PayloadLength3)<<24) | ((uint32_t)(pRecordStruct->PayloadLength2)<<16) | + ((uint32_t)(pRecordStruct->PayloadLength1)<<8) | pRecordStruct->PayloadLength0; + + /* read Payload */ + status = ReadData ( (uint16_t)((FIRST_RECORD_OFFSET) + pRecordStruct->PayloadOffset) , PayloadSize , pNDEF); + + if( status != NDEF_ACTION_COMPLETED) + return status; + else + pRecordStruct->PayloadBufferAdd = (uint32_t)(pNDEF); + + NDEF_ParseRecordHeader(pRecordStruct); + + return SUCCESS; +} + +/** + * @brief This fonction read the NDEF content of the TAG + * @param pNDEF : pointer on the buffer to store NDEF data + * @retval SUCCESS : NDEF file data retrieve and store in the buffer + * @retval ERROR : not able to read NDEF + */ +uint16_t NDEF_ReadNDEF( uint8_t* pNDEF) +{ + uint16_t status = ERROR; + uint16_t NDEF_Size = 0; + + status = ReadData( 0 , 2 , pNDEF); + + if( status == NDEF_ACTION_COMPLETED) + { + NDEF_Size = (uint16_t) (*pNDEF << 8); + NDEF_Size = NDEF_Size | (uint16_t) (*++pNDEF ); + + status = ReadData( 0 , NDEF_Size+2 , --pNDEF); + } + + if( status == NDEF_ACTION_COMPLETED) + return SUCCESS; + else + return ERROR; + +} + +/** + * @brief This fonction write the NDEF in the TAG + * @param pNDEF : pointer on the buffer containing the NDEF data + * @retval SUCCESS : NDEF file data written in the tag + * @retval ERROR : not able to store NDEF in tag + */ +uint16_t NDEF_WriteNDEF( uint8_t *pNDEF) +{ + uint16_t status = ERROR; + uint16_t NDEF_Size = 0; + + NDEF_Size = (uint16_t) (*pNDEF << 8); + NDEF_Size = NDEF_Size | (uint16_t) (*++pNDEF ); + + status = WriteData( 0 , NDEF_Size+2 , --pNDEF); + + if( status == NDEF_ACTION_COMPLETED) + return SUCCESS; + else + return ERROR; + +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/ +
diff -r 000000000000 -r 3b093bd0819e lib_NDEF.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF.h Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,240 @@ +/** + ****************************************************************************** + * @file lib_NDEF.h + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage NDEF file. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LIB_NDEF_H +#define __LIB_NDEF_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +/* include file which match the HW configuration */ +#include "lib_wrapper.h" + +#ifndef errorchk +#define errorchk(fCall) if (status = (fCall), status != M24SR_ACTION_COMPLETED) \ + {goto Error;} else +#endif + + +#define NDEF_SIZE_OFFSET 0 +#define FIRST_RECORD_OFFSET 2 + +#define RECORD_FLAG_FIELD 1 +#define TYPE_LENGTH_FIELD 1 +#define ID_LENGTH_FIELD 1 + + +#define MB_Mask ((uint8_t)(0x80)) +#define ME_Mask ((uint8_t)(0x40)) +#define CF_Mask ((uint8_t)(0x20)) +#define SR_Mask ((uint8_t)(0x10)) +#define IL_Mask ((uint8_t)(0x08)) +#define TNF_Mask ((uint8_t)(0x07)) + +#define TNF_Empty 0x00 +#define TNF_WellKnown 0x01 +#define TNF_MediaType 0x02 +#define TNF_AbsoluteURI 0x03 +#define TNF_NFCForumExternal 0x04 +#define TNF_Unknown 0x05 +#define TNF_Unchanged 0x06 +#define TNF_Reserved 0x07 + +#define SP_MAX_RECORD 3 + +#define AAR_TYPE_STRING "android.com:pkg" +#define AAR_TYPE_STRING_LENGTH 15 + +#define M24SR_DISCOVERY_APP_STRING "st.com:m24sr_discovery_democtrl" +#define M24SR_DISCOVERY_APP_STRING_LENGTH 31 + +#define VCARD_TYPE_STRING "text/vcard" +#define VCARD_TYPE_STRING_LENGTH 10 + +#define XVCARD_TYPE_STRING "text/x-vCard" +#define XVCARD_TYPE_STRING_LENGTH 12 + +#define SMART_POSTER_TYPE_STRING "Sp" +#define SMART_POSTER_TYPE_STRING_LENGTH 2 + +#define URI_TYPE_STRING "U" +#define URI_TYPE_STRING_LENGTH 1 + +#define SMS_TYPE_STRING "sms:" +#define SMS_TYPE_STRING_LENGTH 4 + +#define GEO_TYPE_STRING "geo:" +#define GEO_TYPE_STRING_LENGTH 4 + +#define URI_LATITUDE_END "," +#define URI_LATITUDE_END_LENGTH 1 + +#define EMAIL_TYPE_STRING "mailto:" +#define EMAIL_TYPE_STRING_LENGTH 7 + +#define URI_FIRST_DATA_END "?" +#define URI_FIRST_DATA_END_LENGTH 1 + +#define SUBJECT_BEGIN_STRING "subject=" +#define SUBJECT_BEGIN_STRING_LENGTH 8 + +#define MESSAGE_BEGIN_STRING "body=" +#define MESSAGE_BEGIN_STRING_LENGTH 5 + +#define URI_SECOND_DATA_END "&" +#define URI_SECOND_DATA_END_LENGTH 1 + +#define TEXT_TYPE_STRING "T" +#define TEXT_TYPE_STRING_LENGTH 1 + +#define ISO_ENGLISH_CODE_STRING "en" +#define ISO_ENGLISH_CODE_STRING_LENGTH 2 + + +#define URI_ID_0x00 0x00 +#define URI_ID_0x01 0x01 +#define URI_ID_0x02 0x02 +#define URI_ID_0x03 0x03 +#define URI_ID_0x04 0x04 +#define URI_ID_0x05 0x05 +#define URI_ID_0x06 0x06 +#define URI_ID_0x07 0x07 +#define URI_ID_0x08 0x08 +#define URI_ID_0x09 0x09 +#define URI_ID_0x0A 0x0A +#define URI_ID_0x0B 0x0B +#define URI_ID_0x0C 0x0C +#define URI_ID_0x0D 0x0D +#define URI_ID_0x0E 0x0E +#define URI_ID_0x0F 0x0F +#define URI_ID_0x10 0x10 +#define URI_ID_0x11 0x11 +#define URI_ID_0x12 0x12 +#define URI_ID_0x13 0x13 +#define URI_ID_0x14 0x14 +#define URI_ID_0x15 0x15 +#define URI_ID_0x16 0x16 +#define URI_ID_0x17 0x17 +#define URI_ID_0x18 0x18 +#define URI_ID_0x19 0x19 +#define URI_ID_0x1A 0x1A +#define URI_ID_0x1B 0x1B +#define URI_ID_0x1C 0x1C +#define URI_ID_0x1D 0x1D +#define URI_ID_0x1E 0x1E +#define URI_ID_0x1F 0x1F +#define URI_ID_0x20 0x20 +#define URI_ID_0x21 0x21 +#define URI_ID_0x22 0x22 +#define URI_ID_0x23 0x23 +#define URI_RFU 0x24 + +#define URI_ID_0x01_STRING "http://www.\0" +#define URI_ID_0x02_STRING "https://www.\0" +#define URI_ID_0x03_STRING "http://\0" +#define URI_ID_0x04_STRING "https://\0" +#define URI_ID_0x05_STRING "tel:\0" +#define URI_ID_0x06_STRING "mailto:\0" +#define URI_ID_0x07_STRING "ftp://anonymous:anonymous@\0" +#define URI_ID_0x08_STRING "ftp://ftp.\0" +#define URI_ID_0x09_STRING "ftps://\0" +#define URI_ID_0x0A_STRING "sftp://\0" +#define URI_ID_0x0B_STRING "smb://\0" +#define URI_ID_0x0C_STRING "nfs://\0" +#define URI_ID_0x0D_STRING "ftp://\0" +#define URI_ID_0x0E_STRING "dav://\0" +#define URI_ID_0x0F_STRING "news:\0" +#define URI_ID_0x10_STRING "telnet://\0" +#define URI_ID_0x11_STRING "imap:\0" +#define URI_ID_0x12_STRING "rtsp://\0" +#define URI_ID_0x13_STRING "urn:\0" +#define URI_ID_0x14_STRING "pop:\0" +#define URI_ID_0x15_STRING "sip:\0" +#define URI_ID_0x16_STRING "sips:\0" +#define URI_ID_0x17_STRING "tftp:\0" +#define URI_ID_0x18_STRING "btspp://\0" +#define URI_ID_0x19_STRING "btl2cap://\0" +#define URI_ID_0x1A_STRING "btgoep://\0" +#define URI_ID_0x1B_STRING "tcpobex://\0" +#define URI_ID_0x1C_STRING "irdaobex://\0" +#define URI_ID_0x1D_STRING "file://\0" +#define URI_ID_0x1E_STRING "urn:epc:id:\0" +#define URI_ID_0x1F_STRING "urn:epc:tag\0" +#define URI_ID_0x20_STRING "urn:epc:pat:\0" +#define URI_ID_0x21_STRING "urn:epc:raw:\0" +#define URI_ID_0x22_STRING "urn:epc:\0" +#define URI_ID_0x23_STRING "urn:nfc:\0" + +typedef enum +{ + UNKNOWN_TYPE = 0, + VCARD_TYPE, + WELL_KNOWN_ABRIDGED_URI_TYPE, + URI_SMS_TYPE, + URI_GEO_TYPE, + URI_EMAIL_TYPE, + SMARTPOSTER_TYPE, + URL_TYPE, + TEXT_TYPE, + BT_TYPE, + /* list of "external type" known by this demo, other external type will be addressed as UNKNWON_TYPE */ + M24SR_DISCOVERY_APP_TYPE +} NDEF_TypeDef; + +typedef struct +{ + uint8_t RecordFlags; + uint8_t TypeLength; + uint8_t PayloadLength3; + uint8_t PayloadLength2; + uint8_t PayloadLength1; + uint8_t PayloadLength0; + uint8_t IDLength; + uint8_t Type[0xFF]; + uint8_t ID[0xFF]; + uint16_t PayloadOffset; + uint32_t PayloadBufferAdd; /* add where payload content has been stored */ + NDEF_TypeDef NDEF_Type; /* to store identification ID for application */ + uint32_t SPRecordStructAdd[SP_MAX_RECORD]; /*in case of smart poster array to store add of other sRecordInfo struct */ + uint8_t NbOfRecordInSPPayload; +}sRecordInfo; + + +uint16_t NDEF_IdentifyNDEF ( sRecordInfo *pRecordStruct, uint8_t* pNDEF ); +uint16_t NDEF_ReadNDEF( uint8_t *pNDEF); +uint16_t NDEF_WriteNDEF( uint8_t *pNDEF); + +#ifdef __cplusplus +} +#endif +#endif /* __LIB_NDEF_H */ + + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 3b093bd0819e lib_NDEF_AAR.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF_AAR.c Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,179 @@ +/** + ****************************************************************************** + * @file lib_NDEF_AAR.c + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to add AAR to NDEF file. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF_AAR.h" + +/** @addtogroup NFC_libraries + * @{ + * @brief <b>This is the library used to manage the content of the TAG (data) + * But also the specific feature of the tag, for instance + * password, gpo... </b> + */ + + +/** @addtogroup libNFC_FORUM + * @{ + * @brief This part of the library manage data which follow NFC forum organisation. + */ + +/** + * @brief This buffer contains the data send/received by TAG + */ +extern uint8_t NDEF_Buffer [NDEF_MAX_SIZE]; + +/** @defgroup libAAR_Private_Functions + * @{ + */ + +/** + * @} + */ + +/** @defgroup libAAR_Public_Functions + * @{ + * @brief This file is used to manage AAR (stored or loaded in tag) + */ + + + /** + * @brief This fonction add AAR (Android Application Record) in the tag + * @param pAARStruct : pointer on structure that contain AAR information + * @retval SUCCESS : AAR added + * @retval ERROR : Not able to add AAR + */ +uint16_t NDEF_AddAAR ( sAARInfo *pAARStruct ) +{ + uint16_t status = ERROR; + uint16_t DataSize; + uint16_t Offset=0; + uint32_t AAROffset = 0; + uint16_t NDEF_Size = 0; + uint8_t RecordFlag=0; + uint8_t AARRecordFlag; + + /* AAR: External Type Record Header */ + /************************************/ + /* 7 | 6 | 5 | 4 | 3 | 2 1 0 */ + /*----------------------------------*/ + /* MB ME CF SR IL TNF */ /* <---- IL=0, CF=0 and SR=1 TNF=4 NFC Forum external type*/ + /*----------------------------------*/ + /* TYPE LENGTH */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 3 */ /* <---- Not Used */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 2 */ /* <---- Not Used */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 1 */ /* <---- Not Used */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 0 */ + /*----------------------------------*/ + /* ID LENGTH */ /* <---- Not Used */ + /*----------------------------------*/ + /* TYPE */ /* android.com:pkg */ + /*----------------------------------*/ + /* ID */ /* <---- Not Used */ + /************************************/ + + /* Do we have to add AAR to an existing NDEF message */ + /* retrieve current NDEF size and current record flag*/ + status = ForceReadData( 0 , 3 , NDEF_Buffer); + + if( status == NDEF_ACTION_COMPLETED) + { + NDEF_Size = (uint16_t) (NDEF_Buffer[0] << 8); + NDEF_Size = NDEF_Size | (uint16_t) (NDEF_Buffer[1]); + RecordFlag = NDEF_Buffer[2]; + } + + if( NDEF_Size != 0) + { + AAROffset = NDEF_Size +2; + RecordFlag &= 0xBF; /* remove ME flag on NDEF */ + AARRecordFlag = 0x54; /* don't put MB flag */ + } + else + { + AAROffset = 2; + AARRecordFlag = 0xD4; /* put MB and ME flag */ + } + + /* fill AAR record header */ + Offset = 0; + NDEF_Buffer[Offset++] = AARRecordFlag; /* Record Flag */ + NDEF_Buffer[Offset++] = AAR_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = 0x00; /* Will be filled at the end when payload size is known */ + + memcpy(&NDEF_Buffer[Offset], AAR_TYPE_STRING, AAR_TYPE_STRING_LENGTH); + + /* fill AAR payload */ + memcpy( &NDEF_Buffer[Offset + AAR_TYPE_STRING_LENGTH], pAARStruct->PakageName,strlen(pAARStruct->PakageName)); + + NDEF_Buffer[2] = strlen(pAARStruct->PakageName); + + DataSize = Offset + AAR_TYPE_STRING_LENGTH + strlen(pAARStruct->PakageName); + + /* Write NDEF */ + status = WriteData ( AAROffset , DataSize , NDEF_Buffer); + + /* Write NDEF size to complete*/ + if( status == NDEF_ACTION_COMPLETED) + { + DataSize = NDEF_Size + DataSize; /* Must add to the NDEF size the size of the AAR record*/ + NDEF_Buffer[0] = (DataSize & 0xFF00)>>8; + NDEF_Buffer[1] = (DataSize & 0x00FF); + if( NDEF_Size != 0) + { + NDEF_Buffer[2] = RecordFlag; + status = WriteData ( 0x00 , 3 , NDEF_Buffer); + } + else + status = WriteData ( 0x00 , 2 , NDEF_Buffer); + } + + + if( status == NDEF_ACTION_COMPLETED) + return SUCCESS; + else + return ERROR; +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/ + +
diff -r 000000000000 -r 3b093bd0819e lib_NDEF_AAR.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF_AAR.h Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,54 @@ +/** + ****************************************************************************** + * @file lib_NDEF_AAR.h + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage AAR. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LIB_NDEF_AAR_H +#define __LIB_NDEF_AAR_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF.h" + + +typedef struct +{ + char PakageName[80]; +}sAARInfo; + + +uint16_t NDEF_AddAAR ( sAARInfo *pAARStruct ); + +#ifdef __cplusplus +} +#endif + +#endif /* __LIB_NDEF_AAR_H */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 3b093bd0819e lib_NDEF_Email.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF_Email.c Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,396 @@ +/** + ****************************************************************************** + * @file lib_NDEF_Email.c + * @author MMY Application Team + * @version V1.0.0 + * @date 19-March-2014 + * @brief This file help to manage NDEF file that represent Email. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF_Email.h" + +/** @addtogroup NFC_libraries + * @{ + * @brief <b>This is the library used to manage the content of the TAG (data) + * But also the specific feature of the tag, for instance + * password, gpo... </b> + */ + + +/** @addtogroup libNFC_FORUM + * @{ + * @brief This part of the library manage data which follow NFC forum organisation. + */ + +/** + * @brief This buffer contains the data send/received by TAG + */ +extern uint8_t NDEF_Buffer [NDEF_MAX_SIZE]; + + +/** @defgroup libEmail_Private_Functions + * @{ + */ + + +static void NDEF_FillEmailStruct( uint8_t* pPayload, uint32_t PayloadSize, sEmailInfo *pEmailStruct); +static void NDEF_ReadURI_Email ( sRecordInfo *pRecordStruct, sEmailInfo *pEmailStruct ); + +/** + * @brief This fonction fill Email structure with information of NDEF message + * @param pPayload : pointer on the payload data of the NDEF message + * @param PayloadSize : number of data in the payload + * @param pEmailStruct : pointer on the structure to fill + * @retval NONE + */ +static void NDEF_FillEmailStruct( uint8_t* pPayload, uint32_t PayloadSize, sEmailInfo *pEmailStruct) +{ + uint8_t* pLastByteAdd, *pLook4Word, *pEndString ; + uint32_t SizeOfKeyWord; + + /* First charactere force to NULL in case not matching found */ + *pEmailStruct->EmailAdd = 0; + *pEmailStruct->Subject = 0; + *pEmailStruct->Message = 0; + + /* Interresting information are stored before picture if any */ + /* Moreover picture is not used in this demonstration SW */ + pLastByteAdd = (uint8_t*)(pPayload + PayloadSize); + + /* first byte should be the "mailto:" well know URI type, skip it */ + pLook4Word = ++pPayload; + + pEndString = pLook4Word; + + /* Retrieve email add */ + if( pLook4Word != pLastByteAdd) + { + while( memcmp( pEndString, URI_FIRST_DATA_END, URI_FIRST_DATA_END_LENGTH) && pEndString<pLastByteAdd ) + { + pEndString++; + } + if( pEndString != pLastByteAdd) + { + memcpy( pEmailStruct->EmailAdd, pLook4Word, pEndString-pLook4Word); + /* add end of string charactere */ + pEmailStruct->EmailAdd[pEndString-pLook4Word] = 0; + } + } + + pEndString += URI_FIRST_DATA_END_LENGTH; + pLook4Word = pEndString; + + /* check if e-mail subject is present */ + if(!memcmp( pLook4Word, SUBJECT_BEGIN_STRING, SUBJECT_BEGIN_STRING_LENGTH)) + { + SizeOfKeyWord = SUBJECT_BEGIN_STRING_LENGTH; + + /* Retrieve subject */ + if( pLook4Word != pLastByteAdd) + { + pLook4Word += SizeOfKeyWord; + pEndString = pLook4Word; + while( memcmp( pEndString, URI_SECOND_DATA_END, URI_SECOND_DATA_END_LENGTH) && pEndString<pLastByteAdd ) + { + pEndString++; + } + if( pEndString != pLastByteAdd) + { + memcpy( pEmailStruct->Subject, pLook4Word, pEndString-pLook4Word); + /* add end of string charactere */ + pEmailStruct->Subject[pEndString-pLook4Word] = 0; + } + pEndString += URI_SECOND_DATA_END_LENGTH; + } + } + + pLook4Word = pEndString; + + /* check if e-mail message is present */ + if(!memcmp( pLook4Word, MESSAGE_BEGIN_STRING, MESSAGE_BEGIN_STRING_LENGTH)) + { + pEndString += MESSAGE_BEGIN_STRING_LENGTH; + /* Retrieve message */ + memcpy( pEmailStruct->Message, pEndString, PayloadSize-(pEndString-pPayload+1)); + /* add end of string charactere */ + pEmailStruct->Message[PayloadSize-(pEndString-pPayload+1)] = 0; + } +} + +/** + * @brief This fonction read the Email and store data in a structure + * @param pRecordStruct : Pointer on the record structure + * @param pEmailStruct : pointer on the structure to fill + * @retval NONE + */ +static void NDEF_ReadURI_Email ( sRecordInfo *pRecordStruct, sEmailInfo *pEmailStruct ) +{ + uint8_t* pPayload; + uint32_t PayloadSize; + + PayloadSize = ((uint32_t)(pRecordStruct->PayloadLength3)<<24) | ((uint32_t)(pRecordStruct->PayloadLength2)<<16) | + ((uint32_t)(pRecordStruct->PayloadLength1)<<8) | pRecordStruct->PayloadLength0; + + /* Read record header */ + pPayload = (uint8_t*)(pRecordStruct->PayloadBufferAdd); + + if( pRecordStruct->NDEF_Type == URI_EMAIL_TYPE) + NDEF_FillEmailStruct(pPayload , PayloadSize, pEmailStruct); + +} + +/** + * @} + */ + +/** @defgroup libEmail_Public_Functions + * @{ + * @brief This file is used to manage Email (stored or loaded in tag) + */ + +/** + * @brief This fonction read NDEF and retrieve Eamil information if any + * @param pRecordStruct : Pointer on the record structure + * @param pEmailStruct : pointer on the structure to fill + * @retval SUCCESS : Email information from NDEF have been retrieved + * @retval ERROR : Not able to retrieve Email information + */ +uint16_t NDEF_ReadEmail(sRecordInfo *pRecordStruct, sEmailInfo *pEmailStruct) +{ + uint16_t status = ERROR; + sRecordInfo *pSPRecordStruct; + uint32_t PayloadSize, RecordPosition; + uint8_t* pData; + + + if( pRecordStruct->NDEF_Type == URI_EMAIL_TYPE ) + { + NDEF_ReadURI_Email(pRecordStruct, pEmailStruct ); + status = SUCCESS; + } + else if( pRecordStruct->NDEF_Type == SMARTPOSTER_TYPE) + { + for (RecordPosition = 0; RecordPosition<pRecordStruct->NbOfRecordInSPPayload; RecordPosition++) + { + pSPRecordStruct = (sRecordInfo *)(pRecordStruct->SPRecordStructAdd[RecordPosition]); + if(pSPRecordStruct->NDEF_Type == URI_EMAIL_TYPE ) + { + NDEF_ReadURI_Email(pSPRecordStruct, pEmailStruct ); + status = SUCCESS; + } + if(pSPRecordStruct->NDEF_Type == TEXT_TYPE ) + { + PayloadSize = ((uint32_t)(pSPRecordStruct->PayloadLength3)<<24) | ((uint32_t)(pSPRecordStruct->PayloadLength2)<<16) | + ((uint32_t)(pSPRecordStruct->PayloadLength1)<<8) | pSPRecordStruct->PayloadLength0; + + /* The instruction content the UTF-8 language code that is not used here */ + pData = (uint8_t*)pSPRecordStruct->PayloadBufferAdd; + pData += *pData+1; + + memcpy(pEmailStruct->Information, pData, PayloadSize); + } + } + } + + return status; +} + +/** + * @brief This fonction write the NDEF file with the Email data given in the structure + * @param pEmailStruct : pointer on structure that contain the Email information + * @retval SUCCESS : the function is succesful + * @retval ERROR : Not able to store NDEF file inside tag. + */ +uint16_t NDEF_WriteEmail ( sEmailInfo *pEmailStruct ) +{ + uint16_t status = ERROR; + uint32_t Offset = 0; + uint32_t emailSize, infoSize, totalSize; + + /* Email is an URI but can be included in a smart poster to add text to give instruction to user for instance */ + + /* Email (smart poster) Record Header */ + /************************************/ + /* 7 | 6 | 5 | 4 | 3 | 2 1 0 */ + /*----------------------------------*/ + /* MB ME CF SR IL TNF */ /* <---- CF=0, IL=0 and SR=1 TNF=1 NFC Forum Well-known type*/ + /*----------------------------------*/ + /* TYPE LENGTH */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 3 */ /* <---- Used only if SR=0 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 2 */ /* <---- Used only if SR=0 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 1 */ /* <---- Used only if SR=0 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 0 */ + /*----------------------------------*/ + /* ID LENGTH */ /* <---- Not Used */ + /*----------------------------------*/ + /* TYPE */ + /*----------------------------------*/ + /* ID */ /* <---- Not Used */ + /************************************/ + /* Leave the size of the file empty */ + NDEF_Buffer[0] = 0; + NDEF_Buffer[1] = 0; + Offset = FIRST_RECORD_OFFSET; + infoSize = 0; + + /* Email : 1+@+1+subject+1+message */ + 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); + + /* Check if a Smart poster is needed */ + if (pEmailStruct->Information[0] != '\0') + { + /* Info : 1+2+info */ + infoSize = 1+ISO_ENGLISH_CODE_STRING_LENGTH+strlen(pEmailStruct->Information); + /* Total */ + totalSize = 4+emailSize+4+infoSize; + if (emailSize > 255) totalSize+=3; /* Normal Email size */ + if (infoSize > 255) totalSize+=3; /* Normal Info size */ + + /* SmartPoster header */ + if (totalSize > 255) + { + NDEF_Buffer[Offset++] = 0xC1; + NDEF_Buffer[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (totalSize & 0xFF000000)>>24; + NDEF_Buffer[Offset++] = (totalSize & 0x00FF0000)>>16; + NDEF_Buffer[Offset++] = (totalSize & 0x0000FF00)>>8; + NDEF_Buffer[Offset++] = (totalSize & 0x000000FF); + } + else + { + NDEF_Buffer[Offset++] = 0xD1; + NDEF_Buffer[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (uint8_t)totalSize; + } + memcpy(&NDEF_Buffer[Offset], SMART_POSTER_TYPE_STRING, SMART_POSTER_TYPE_STRING_LENGTH); + Offset+=SMART_POSTER_TYPE_STRING_LENGTH; + } + + /* Email header */ + NDEF_Buffer[Offset] = 0x81; + if (emailSize < 256) NDEF_Buffer[Offset] |= 0x10; // Set the SR bit + if (pEmailStruct->Information[0] == '\0') NDEF_Buffer[Offset] |= 0x40; // Set the ME bit + Offset++; + + NDEF_Buffer[Offset++] = URI_TYPE_STRING_LENGTH; + if (emailSize > 255) + { + NDEF_Buffer[Offset++] = (emailSize & 0xFF000000)>>24; + NDEF_Buffer[Offset++] = (emailSize & 0x00FF0000)>>16; + NDEF_Buffer[Offset++] = (emailSize & 0x0000FF00)>>8; + NDEF_Buffer[Offset++] = (emailSize & 0x000000FF); + } + else + { + NDEF_Buffer[Offset++] = (uint8_t)emailSize; + } + memcpy(&NDEF_Buffer[Offset], URI_TYPE_STRING, URI_TYPE_STRING_LENGTH); + Offset+=URI_TYPE_STRING_LENGTH; + + /* Email payload */ + NDEF_Buffer[Offset++] = URI_ID_0x06; + memcpy( &NDEF_Buffer[Offset], pEmailStruct->EmailAdd,strlen(pEmailStruct->EmailAdd)); + Offset += strlen(pEmailStruct->EmailAdd); + memcpy( &NDEF_Buffer[Offset], URI_FIRST_DATA_END,URI_FIRST_DATA_END_LENGTH); + Offset += URI_FIRST_DATA_END_LENGTH; + + memcpy(&NDEF_Buffer[Offset], SUBJECT_BEGIN_STRING, SUBJECT_BEGIN_STRING_LENGTH); + Offset += SUBJECT_BEGIN_STRING_LENGTH; + memcpy( &NDEF_Buffer[Offset], pEmailStruct->Subject,strlen(pEmailStruct->Subject)); + Offset += strlen(pEmailStruct->Subject); + memcpy( &NDEF_Buffer[Offset], URI_SECOND_DATA_END,URI_SECOND_DATA_END_LENGTH); + Offset += URI_SECOND_DATA_END_LENGTH; + + memcpy( &NDEF_Buffer[Offset], MESSAGE_BEGIN_STRING, MESSAGE_BEGIN_STRING_LENGTH); + Offset += MESSAGE_BEGIN_STRING_LENGTH; + memcpy( &NDEF_Buffer[Offset], pEmailStruct->Message, strlen(pEmailStruct->Message)); + Offset += strlen(pEmailStruct->Message); + + /* Information header */ + if (pEmailStruct->Information[0] != '\0') + { + if (infoSize > 255) + { + NDEF_Buffer[Offset++] = 0x41; + NDEF_Buffer[Offset++] = TEXT_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (infoSize & 0xFF000000)>>24; + NDEF_Buffer[Offset++] = (infoSize & 0x00FF0000)>>16; + NDEF_Buffer[Offset++] = (infoSize & 0x0000FF00)>>8; + NDEF_Buffer[Offset++] = (infoSize & 0x000000FF); + } + else + { + NDEF_Buffer[Offset++] = 0x51; + NDEF_Buffer[Offset++] = TEXT_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (uint8_t)infoSize; + } + + memcpy(&NDEF_Buffer[Offset], TEXT_TYPE_STRING, TEXT_TYPE_STRING_LENGTH); + Offset+=TEXT_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = ISO_ENGLISH_CODE_STRING_LENGTH; /* UTF-8 with x byte language code */ + memcpy(&NDEF_Buffer[Offset], ISO_ENGLISH_CODE_STRING, ISO_ENGLISH_CODE_STRING_LENGTH); + Offset+=ISO_ENGLISH_CODE_STRING_LENGTH; + + /* Information payload */ + memcpy( &NDEF_Buffer[Offset], pEmailStruct->Information,strlen(pEmailStruct->Information)); + Offset += strlen(pEmailStruct->Information); + } + + /* Write NDEF */ + status = WriteData ( 0x00 , Offset , NDEF_Buffer); + + /* Write NDEF size to complete*/ + if( status == NDEF_ACTION_COMPLETED) + { + Offset -= 2; /* Must not count the 2 byte that represent the NDEF size */ + NDEF_Buffer[0] = (Offset & 0xFF00)>>8; + NDEF_Buffer[1] = (Offset & 0x00FF); + + status = WriteData ( 0x00 , 2 , NDEF_Buffer); + } + + if( status == NDEF_ACTION_COMPLETED) + return SUCCESS; + else + return ERROR; +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/ + +
diff -r 000000000000 -r 3b093bd0819e lib_NDEF_Email.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF_Email.h Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,59 @@ +/** + ****************************************************************************** + * @file lib_NDEF_Email.h + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage Email NDEF file. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LIB_NDEF_EMAIL_H +#define __LIB_NDEF_EMAIL_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF.h" + +/* "mailto:customer.service@st.com?subject=M24SR S/N 754FHFGJF46G329 WARRANTY&body=this is an auomatic warranty activation email" */ + +typedef struct +{ + char EmailAdd[64]; + char Subject[100]; + char Message[400]; + char Information[400]; +}sEmailInfo; + + +uint16_t NDEF_ReadEmail(sRecordInfo *pRecordStruct, sEmailInfo *pEmailStruct); +uint16_t NDEF_WriteEmail( sEmailInfo *pEmailStruct ); + +#ifdef __cplusplus +} +#endif + +#endif /* __LIB_NDEF_EMAIL_H */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 3b093bd0819e lib_NDEF_Geo.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF_Geo.c Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,365 @@ +/** + ****************************************************************************** + * @file lib_NDEF_Geo.c + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage NDEF file that represent geolocation. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF_Geo.h" + +/** @addtogroup NFC_libraries + * @{ + * @brief <b>This is the library used to manage the content of the TAG (data) + * But also the specific feature of the tag, for instance + * password, gpo... </b> + */ + + +/** @addtogroup libNFC_FORUM + * @{ + * @brief This part of the library manage data which follow NFC forum organisation. + */ + +/** + * @brief This buffer contains the data send/received by TAG + */ +extern uint8_t NDEF_Buffer [NDEF_MAX_SIZE]; + +/** @defgroup libGeo_Private_Functions + * @{ + */ + +static void NDEF_FillGeoStruct( uint8_t* pPayload, uint32_t PayloadSize, sGeoInfo *pGeoStruct); +static void NDEF_ReadURI_Geo ( sRecordInfo *pRecordStruct, sGeoInfo *pGeoStruct ); + +/** + * @brief This fonction fill Geo structure with information of NDEF message + * @param pPayload : pointer on the payload data of the NDEF message + * @param PayloadSize : number of data in the payload + * @param pGeoStruct : pointer on the structure to fill + * @retval NONE + */ +static void NDEF_FillGeoStruct( uint8_t* pPayload, uint32_t PayloadSize, sGeoInfo *pGeoStruct) +{ + uint8_t* pLastByteAdd, *pLook4Word, *pEndString ; + char* pKeyWord; + uint32_t SizeOfKeyWord; + + pKeyWord = GEO_TYPE_STRING; + SizeOfKeyWord = GEO_TYPE_STRING_LENGTH; + + /* First charactere force to NULL in case not matching found */ + *pGeoStruct->Latitude = 0; + *pGeoStruct->Longitude = 0; + + /* Interresting information are stored before picture if any */ + /* Moreover picture is not used in this demonstration SW */ + pLastByteAdd = (uint8_t*)(pPayload + PayloadSize); + + pLook4Word = pPayload; + while( memcmp( pLook4Word, pKeyWord, SizeOfKeyWord) && pLook4Word<pLastByteAdd ) + { + pLook4Word++; + } + + pEndString = pLook4Word; + + /* Retrieve phone number */ + if( pLook4Word != pLastByteAdd) + { + pLook4Word += SizeOfKeyWord; + while( memcmp( pEndString, URI_LATITUDE_END, URI_LATITUDE_END_LENGTH) && pEndString<pLastByteAdd ) + { + pEndString++; + } + if( pEndString != pLastByteAdd) + { + memcpy( pGeoStruct->Latitude, pLook4Word, pEndString-pLook4Word); + /* add end of string charactere */ + pGeoStruct->Latitude[pEndString-pLook4Word] = 0; + } + } + pEndString += URI_LATITUDE_END_LENGTH; + pLook4Word = pEndString; + + memcpy( pGeoStruct->Longitude, pEndString, PayloadSize-(pEndString-pPayload)); + /* add end of string charactere */ + pGeoStruct->Longitude[PayloadSize-(pEndString-pPayload)] = 0; + +} + +/** + * @brief This fonction read the geoloccation information and store data in a structure + * @param pRecordStruct : Pointer on the record structure + * @param pGeoStruct : pointer on the structure to fill + * @retval NONE + */ +static void NDEF_ReadURI_Geo ( sRecordInfo *pRecordStruct, sGeoInfo *pGeoStruct ) +{ + uint8_t* pPayload; + uint32_t PayloadSize; + + PayloadSize = ((uint32_t)(pRecordStruct->PayloadLength3)<<24) | ((uint32_t)(pRecordStruct->PayloadLength2)<<16) | + ((uint32_t)(pRecordStruct->PayloadLength1)<<8) | pRecordStruct->PayloadLength0; + + /* Read record header */ + pPayload = (uint8_t*)(pRecordStruct->PayloadBufferAdd); + + if( pRecordStruct->NDEF_Type == URI_GEO_TYPE) + NDEF_FillGeoStruct(pPayload , PayloadSize, pGeoStruct); + +} + +/** + * @} + */ + +/** @defgroup libGeo_Public_Functions + * @{ + * @brief This file is used to manage geolocation (stored or loaded in tag) + */ + +/** + * @brief This fonction read NDEF and retrieve Geo information if any + * @param pRecordStruct : Pointer on the record structure + * @param pGeoStruct : pointer on the structure to fill + * @retval SUCCESS : Geolocation information from NDEF have been retrieved + * @retval ERROR : Not able to retrieve geolocation information + */ +uint16_t NDEF_ReadGeo(sRecordInfo *pRecordStruct, sGeoInfo *pGeoStruct) +{ + uint16_t status = ERROR; + uint16_t FileId=0; + sRecordInfo *pSPRecordStruct; + uint32_t PayloadSize, RecordPosition; + uint8_t* pData; + + if( pRecordStruct->NDEF_Type == URI_GEO_TYPE ) + { + NDEF_ReadURI_Geo(pRecordStruct, pGeoStruct ); + status = SUCCESS; + } + else if( pRecordStruct->NDEF_Type == SMARTPOSTER_TYPE) + { + for (RecordPosition = 0; RecordPosition<pRecordStruct->NbOfRecordInSPPayload; RecordPosition++) + { + pSPRecordStruct = (sRecordInfo *)(pRecordStruct->SPRecordStructAdd[RecordPosition]); + if(pSPRecordStruct->NDEF_Type == URI_GEO_TYPE ) + { + NDEF_ReadURI_Geo(pSPRecordStruct, pGeoStruct ); + status = SUCCESS; + } + if(pSPRecordStruct->NDEF_Type == TEXT_TYPE ) + { + PayloadSize = ((uint32_t)(pSPRecordStruct->PayloadLength3)<<24) | ((uint32_t)(pSPRecordStruct->PayloadLength2)<<16) | + ((uint32_t)(pSPRecordStruct->PayloadLength1)<<8) | pSPRecordStruct->PayloadLength0; + + /* The instruction content the UTF-8 language code that is not used here */ + pData = (uint8_t*)pSPRecordStruct->PayloadBufferAdd; + PayloadSize -= *pData+1; /* remove not usefull data */ + pData += *pData+1; /* set pointer on usefull data */ + + memcpy(pGeoStruct->Information, pData, PayloadSize); + /* add end of string charactere */ + pGeoStruct->Information[PayloadSize] = 0; + } + } + } + + CloseNDEFSession(FileId); + + return status; +} + +/** + * @brief This fonction write the NDEF file with the geolocation data given in the structure + * @param pGeoStruct : pointer on structure that contain the geolocation information + * @retval SUCCESS : the function is succesful + * @retval ERROR : Not able to store NDEF file inside tag. + */ +uint16_t NDEF_WriteGeo ( sGeoInfo *pGeoStruct ) +{ + uint16_t status = ERROR; + uint32_t geoSize, infoSize, totalSize, Offset = 0; + + /* GEO is an URI but can be included in a smart poster to add text to give instruction to user for instance */ + + /* GEO (smart poster) Record Header */ + /************************************/ + /* 7 | 6 | 5 | 4 | 3 | 2 1 0 */ + /*----------------------------------*/ + /* MB ME CF SR IL TNF */ /* <---- CF=0, IL=0 and SR=1 TNF=1 NFC Forum Well-known type*/ + /*----------------------------------*/ + /* TYPE LENGTH */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 3 */ /* <---- Used only if SR=0 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 2 */ /* <---- Used only if SR=0 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 1 */ /* <---- Used only if SR=0 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 0 */ + /*----------------------------------*/ + /* ID LENGTH */ /* <---- Not Used */ + /*----------------------------------*/ + /* TYPE */ + /*----------------------------------*/ + /* ID */ /* <---- Not Used */ + /************************************/ + + NDEF_Buffer[0] = 0; + NDEF_Buffer[1] = 0; + Offset = FIRST_RECORD_OFFSET; + infoSize = 0; + + /* GEO : 1+geo:+latitude+1+longitude */ + geoSize = 1+GEO_TYPE_STRING_LENGTH+strlen(pGeoStruct->Latitude)+URI_LATITUDE_END_LENGTH+strlen(pGeoStruct->Longitude); + + /* Check if a Smart poster is needed */ + if (pGeoStruct->Information[0] != '\0') + { + /* Info : 1+2+info */ + infoSize = 1+ISO_ENGLISH_CODE_STRING_LENGTH+strlen(pGeoStruct->Information); + /* Total */ + totalSize = 4+geoSize+4+infoSize; + if (geoSize > 255) totalSize+=3; /* Normal Geo size */ + if (infoSize > 255) totalSize+=3; /* Normal Info size */ + + /* SmartPoster header */ + if (totalSize > 255) + { + NDEF_Buffer[Offset++] = 0xC1; + NDEF_Buffer[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (totalSize & 0xFF000000)>>24; + NDEF_Buffer[Offset++] = (totalSize & 0x00FF0000)>>16; + NDEF_Buffer[Offset++] = (totalSize & 0x0000FF00)>>8; + NDEF_Buffer[Offset++] = (totalSize & 0x000000FF); + } + else + { + NDEF_Buffer[Offset++] = 0xD1; + NDEF_Buffer[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (uint8_t)totalSize; + } + memcpy(&NDEF_Buffer[Offset], SMART_POSTER_TYPE_STRING, SMART_POSTER_TYPE_STRING_LENGTH); + Offset+=SMART_POSTER_TYPE_STRING_LENGTH; + } + + /* GEO header */ + NDEF_Buffer[Offset] = 0x81; + if (geoSize < 256) NDEF_Buffer[Offset] |= 0x10; // Set the SR bit + if (pGeoStruct->Information[0] == '\0') NDEF_Buffer[Offset] |= 0x40; // Set the ME bit + Offset++; + + NDEF_Buffer[Offset++] = URI_TYPE_STRING_LENGTH; + if (geoSize > 255) + { + NDEF_Buffer[Offset++] = (geoSize & 0xFF000000)>>24; + NDEF_Buffer[Offset++] = (geoSize & 0x00FF0000)>>16; + NDEF_Buffer[Offset++] = (geoSize & 0x0000FF00)>>8; + NDEF_Buffer[Offset++] = (geoSize & 0x000000FF); + } + else + { + NDEF_Buffer[Offset++] = (uint8_t)geoSize; + } + memcpy(&NDEF_Buffer[Offset], URI_TYPE_STRING, URI_TYPE_STRING_LENGTH); + Offset+=URI_TYPE_STRING_LENGTH; + + /* GEO payload */ + NDEF_Buffer[Offset++] = URI_ID_0x00; /* URI identifier no abbreviation */ + memcpy(&NDEF_Buffer[Offset], GEO_TYPE_STRING, GEO_TYPE_STRING_LENGTH); + Offset += GEO_TYPE_STRING_LENGTH; + memcpy( &NDEF_Buffer[Offset], pGeoStruct->Latitude,strlen(pGeoStruct->Latitude)); + Offset += strlen(pGeoStruct->Latitude); + memcpy( &NDEF_Buffer[Offset], URI_LATITUDE_END,URI_LATITUDE_END_LENGTH); + Offset += URI_LATITUDE_END_LENGTH; + memcpy( &NDEF_Buffer[Offset], pGeoStruct->Longitude, strlen(pGeoStruct->Longitude)); + Offset += strlen(pGeoStruct->Longitude); + + /* Information header */ + if (pGeoStruct->Information[0] != '\0') + { + if (infoSize > 255) + { + NDEF_Buffer[Offset++] = 0x41; + NDEF_Buffer[Offset++] = TEXT_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (infoSize & 0xFF000000)>>24; + NDEF_Buffer[Offset++] = (infoSize & 0x00FF0000)>>16; + NDEF_Buffer[Offset++] = (infoSize & 0x0000FF00)>>8; + NDEF_Buffer[Offset++] = (infoSize & 0x000000FF); + } + else + { + NDEF_Buffer[Offset++] = 0x51; + NDEF_Buffer[Offset++] = TEXT_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (uint8_t)infoSize; + } + + memcpy(&NDEF_Buffer[Offset], TEXT_TYPE_STRING, TEXT_TYPE_STRING_LENGTH); + Offset+=TEXT_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = ISO_ENGLISH_CODE_STRING_LENGTH; /* UTF-8 with x byte language code */ + memcpy(&NDEF_Buffer[Offset], ISO_ENGLISH_CODE_STRING, ISO_ENGLISH_CODE_STRING_LENGTH); + Offset+=ISO_ENGLISH_CODE_STRING_LENGTH; + + /* Information payload */ + memcpy( &NDEF_Buffer[Offset], pGeoStruct->Information,strlen(pGeoStruct->Information)); + Offset += strlen(pGeoStruct->Information); + } + + /* Write NDEF */ + status = WriteData ( 0x00 , Offset , NDEF_Buffer); + + /* Write NDEF size to complete*/ + if( status == NDEF_ACTION_COMPLETED) + { + Offset -= 2; /* Must not count the 2 byte that represent the NDEF size */ + NDEF_Buffer[0] = (Offset & 0xFF00)>>8; + NDEF_Buffer[1] = (Offset & 0x00FF); + + status = WriteData ( 0x00 , 2 , NDEF_Buffer); + } + + if( status == NDEF_ACTION_COMPLETED) + return SUCCESS; + else + return ERROR; +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/ + +
diff -r 000000000000 -r 3b093bd0819e lib_NDEF_Geo.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF_Geo.h Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,57 @@ +/** + ****************************************************************************** + * @file lib_NDEF_Geo.h + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage Geolocation NDEF file. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LIB_NDEF_GEO_H +#define __LIB_NDEF_GEO_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF.h" + + +typedef struct +{ + char Latitude[20]; + char Longitude[20]; + char Information[100]; +}sGeoInfo; + + +uint16_t NDEF_ReadGeo(sRecordInfo *pRecordStruct, sGeoInfo *pGeoStruct); +uint16_t NDEF_WriteGeo( sGeoInfo *pGeoStruct ); + +#ifdef __cplusplus +} +#endif + +#endif /* __LIB_NDEF_GEO_H */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 3b093bd0819e lib_NDEF_MyApp.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF_MyApp.c Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,289 @@ +/** + ****************************************************************************** + * @file lib_NDEF_MyApp.c + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage the NDEF file of a private application. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF_MyApp.h" + + +/** @addtogroup NFC_libraries + * @{ + * @brief <b>This is the library used to manage the content of the TAG (data) + * But also the specific feature of the tag, for instance + * password, gpio... </b> + */ + + +/** @addtogroup libNFC_FORUM + * @{ + * @brief This part of the library manage data which follow NFC forum organisation. + */ + +/** + * @brief This buffer contains the data send/received by TAG + */ +extern uint8_t NDEF_Buffer [NDEF_MAX_SIZE]; + +/** @defgroup libMyApp_Private_Functions + * @{ + */ + +static void NDEF_Extract_M24SRDiscoveryApp_Input ( sRecordInfo *pRecordStruct, sMyAppInfo *pMyAppStruct ); + +/** + * @brief This fonction read the NDEF file and store application data in a structure + * @param pRecordStruct : Pointer on the record structure + * @param pMyAppStruct : pointer on the structure to fill + * @retval NONE + */ +static void NDEF_Extract_M24SRDiscoveryApp_Input ( sRecordInfo *pRecordStruct, sMyAppInfo *pMyAppStruct ) +{ + uint8_t* pPayload; + uint8_t* pLook4Word; + uint16_t BackGroundColor, FontColor; + uint8_t i; + + /* Read record header */ + pPayload = (uint8_t*)(pRecordStruct->PayloadBufferAdd); + + /* initialize struct in case not matching found */ + for(i=0; i<8; i++) + { + /* Set the Back Color */ + pMyAppStruct->LineX[i].BackGroundColor = 0xFFFF; + /* Set the Text Color */ + pMyAppStruct->LineX[i].FontColor = 0x0000; + /* Set the line number */ + pMyAppStruct->LineX[i].LineNb = i+1; + /* Set the line content */ + memcpy(pMyAppStruct->LineX[i].String , " ",20); + } + + pLook4Word = pPayload; + + for(i=0; i<4; i++) + { + pMyAppStruct->LedBlinkConf.LedConf[i] = *pLook4Word; + pLook4Word++; + } + pMyAppStruct->LedBlinkConf.Speed = *pLook4Word; + pLook4Word++; + + for(i=0; i<8; i++) + { + /* Set the line number */ + pMyAppStruct->LineX[i].LineNb = *pLook4Word; + pLook4Word++; + /* Set the Back Color */ + BackGroundColor = (uint16_t) (*pLook4Word << 8); + BackGroundColor = BackGroundColor | (uint16_t) (*++pLook4Word ); + pMyAppStruct->LineX[i].BackGroundColor = BackGroundColor; + pLook4Word++; + /* Set the Text Color */ + FontColor = (uint16_t) (*pLook4Word << 8); + FontColor = FontColor | (uint16_t) (*++pLook4Word ); + pMyAppStruct->LineX[i].FontColor = FontColor; + pLook4Word++; + /* Set the line content */ + memcpy(pMyAppStruct->LineX[i].String, (char*) pLook4Word, 20); + pLook4Word += 20; + } + +} + +/** + * @} + */ + +/** @defgroup libMyApp_Public_Functions + * @{ + * @brief This file is used to manage proprietary NDEF (stored or loaded in tag) + */ + +/** + * @brief This fonction read NDEF and retrieve Application information if any + * @param pRecordStruct : Pointer on the record structure + * @param pMyAppStruct : pointer on the structure to fill + * @retval SUCCESS : Application information from NDEF have been retrieved + * @retval ERROR : Not able to retrieve Application information + */ +uint16_t NDEF_ReadMyApp(sRecordInfo *pRecordStruct, sMyAppInfo *pMyAppStruct) +{ + uint16_t status = ERROR; + + if( pRecordStruct->NDEF_Type == M24SR_DISCOVERY_APP_TYPE ) + { + NDEF_Extract_M24SRDiscoveryApp_Input(pRecordStruct, pMyAppStruct ); + status = SUCCESS; + } + else + { + status = ERROR; + } + + return status; +} + +/** + * @brief This fonction write the NDEF file with the Application data given in the structure + * @brief Only used for debug purpose in this firmware version + * @param pMyAppStruct : pointer on structure that contain the application information + * @retval SUCCESS : the function is succesful + * @retval ERROR : Not able to store NDEF file inside tag. + */ +uint16_t NDEF_WriteMyApp(sMyAppInfo *pMyAppStruct) +{ + uint16_t status = ERROR; + uint16_t DataSize; + uint32_t PayloadSize; + uint8_t i; + uint8_t* pPayload; + + + /* External Type Record Header */ + /************************************/ + /* 7 | 6 | 5 | 4 | 3 | 2 1 0 */ + /*----------------------------------*/ + /* MB ME CF SR IL TNF */ /* <---- IL=0, CF=0 and SR=1 TNF=4 NFC Forum external type*/ + /*----------------------------------*/ + /* TYPE LENGTH */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 3 */ /* <---- Not Used */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 2 */ /* <---- Not Used */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 1 */ /* <---- Not Used */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 0 */ /* The payload will always be 5 + 25*8=205 bytes for this application */ + /*----------------------------------*/ + /* ID LENGTH */ /* <---- Not Used */ + /*----------------------------------*/ + /* TYPE */ /* st.com:m24sr_discovery_democtrl */ + /*----------------------------------*/ + /* ID */ /* <---- Not Used */ + /************************************/ + + /* NDEF file must be written in 2 phases, first phase NDEF size is Null */ + NDEF_Buffer[NDEF_SIZE_OFFSET] = 0x00; + NDEF_Buffer[NDEF_SIZE_OFFSET+1] = 0x00; + + /* fill URI record header */ + NDEF_Buffer[FIRST_RECORD_OFFSET] = 0xD4; /* Record Flag */ + NDEF_Buffer[FIRST_RECORD_OFFSET+1] = M24SR_DISCOVERY_APP_STRING_LENGTH; + NDEF_Buffer[FIRST_RECORD_OFFSET+2] = 0x00; /* Will be filled at the end when payload size is known */ + + memcpy(&NDEF_Buffer[FIRST_RECORD_OFFSET+3], M24SR_DISCOVERY_APP_STRING, M24SR_DISCOVERY_APP_STRING_LENGTH); + + pPayload = &NDEF_Buffer[FIRST_RECORD_OFFSET+3+M24SR_DISCOVERY_APP_STRING_LENGTH]; + PayloadSize = 0; + + /**************************************************************/ + /* BLINK CONFIG data */ + + /* led 1 blinking */ + *pPayload = 0x03; + pPayload++; + /* led 2 blinking */ + *pPayload = 0x02; + pPayload++; + /* led 3 blinking */ + *pPayload = 0x02; + pPayload++; + /* led 4 blinking */ + *pPayload = 0x03; + pPayload++; + /* speed */ + *pPayload = 0x03; + pPayload++; + + PayloadSize += 5; + + /**************************************************************/ + + /**************************************************************/ + /* SCREEN config data */ + for(i=0; i<8; i++) + { + /* Line number */ + *pPayload = (uint8_t)(i+1); + pPayload++; + /* Background color */ + *pPayload = 0xFF; + pPayload++; + *pPayload = 0xFF; + pPayload++; + /* Font Color */ + *pPayload = 0x00; + pPayload++; + *pPayload = 0x00; + pPayload++; + /* String */ + memcpy(pPayload, "ABCDEFGHIJKLMNOPQRST",20); + pPayload += 20; + + PayloadSize += 25; + + } + + NDEF_Buffer[FIRST_RECORD_OFFSET+2] = (PayloadSize & 0x000000FF); + + DataSize = PayloadSize + 5 + M24SR_DISCOVERY_APP_STRING_LENGTH; + + /* Write NDEF */ + status = WriteData ( 0x00 , DataSize , NDEF_Buffer); + + /* Write NDEF size to complete*/ + if( status == NDEF_ACTION_COMPLETED) + { + DataSize -= 2; /* Must not count the 2 byte that represent the NDEF size */ + NDEF_Buffer[0] = (DataSize & 0xFF00)>>8; + NDEF_Buffer[1] = (DataSize & 0x00FF); + + status = WriteData ( 0x00 , 2 , NDEF_Buffer); + } + + if( status == NDEF_ACTION_COMPLETED) + return SUCCESS; + else + return ERROR; +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/ + +
diff -r 000000000000 -r 3b093bd0819e lib_NDEF_MyApp.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF_MyApp.h Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,85 @@ +/** + ****************************************************************************** + * @file lib_NDEF_MyApp.h + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file illustrate how to use M24SR with a proprietary protocol. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LIB_NDEF_MYAPP_H +#define __LIB_NDEF_MYAPP_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF.h" + +#define BLINK_CONFIG "<BLINK_CONFIG>" +#define BLINK_CONFIG_STRING_SIZE 14 +#define BLINK_CONFIG_END "<\\BLINK_CONFIG>" +#define BLINK_CONFIG_END_STRING_SIZE 15 + +#define LINE_DESCR "<LINE_DESCR>" +#define LINE_DESCR_STRING_SIZE 12 +#define LINE_DESCR_END "<\\LINE_DESCR>" +#define LINE_DESCR_END_STRING_SIZE 13 + +#define BLINKING_NONE 0x00 +#define BLINKING_SLOW 0x01 +#define BLINKING_MEDIUM 0x02 +#define BLINKING_FAST 0x03 + + +typedef struct +{ + uint8_t LedConf[4]; + uint8_t Speed; +}sLedBlinkConfig; + +typedef struct +{ + uint8_t LineNb; + uint16_t BackGroundColor; + uint16_t FontColor; + char String[20]; +}sLineConfig; + +typedef struct +{ + sLedBlinkConfig LedBlinkConf; + sLineConfig LineX[8]; +}sMyAppInfo; + + +uint16_t NDEF_ReadMyApp(sRecordInfo *pRecordStruct, sMyAppInfo *pMyAppStruct); +uint16_t NDEF_WriteMyApp(sMyAppInfo *pMyAppStruct); + +#ifdef __cplusplus +} +#endif + +#endif /* __LIB_NDEF_MYAPP_H */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 3b093bd0819e lib_NDEF_SMS.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF_SMS.c Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,373 @@ +/** + ****************************************************************************** + * @file lib_NDEF_SMS.c + * @author MMY Application Team + * @version V1.0.0 + * @date 19-March-2014 + * @brief This file help to manage NDEF file that represent SMS. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF_SMS.h" + + +/** @addtogroup NFC_libraries + * @{ + * @brief <b>This is the library used to manage the content of the TAG (data) + * But also the specific feature of the tag, for instance + * password, gpo... </b> + */ + + +/** @addtogroup libNFC_FORUM + * @{ + * @brief This part of the library manage data which follow NFC forum organisation. + */ + +/** + * @brief This buffer contains the data send/received by TAG + */ +extern uint8_t NDEF_Buffer [NDEF_MAX_SIZE]; + +/** @defgroup libSMS_Private_Functions + * @{ + */ + +static void NDEF_FillSMSStruct( uint8_t* pPayload, uint32_t PayloadSize, sSMSInfo *pSMSStruct); +static void NDEF_ReadURI_SMS ( sRecordInfo *pRecordStruct, sSMSInfo *pSMSStruct ); + +/** + * @brief This fonction fill SMS structure with information of NDEF message + * @param pPayload : pointer on the payload data of the NDEF message + * @param PayloadSize : number of data in the payload + * @param pSMSStruct : pointer on the structure to fill + * @retval NONE + */ +static void NDEF_FillSMSStruct( uint8_t* pPayload, uint32_t PayloadSize, sSMSInfo *pSMSStruct) +{ + uint8_t* pLastByteAdd, *pLook4Word, *pEndString ; + char* pKeyWord; + uint32_t SizeOfKeyWord; + + pKeyWord = SMS_TYPE_STRING; + SizeOfKeyWord = SMS_TYPE_STRING_LENGTH; + + /* First charactere force to NULL in case not matching found */ + *pSMSStruct->PhoneNumber = 0; + *pSMSStruct->Message = 0; + + /* Interresting information are stored before picture if any */ + /* Moreover picture is not used in this demonstration SW */ + pLastByteAdd = (uint8_t*)(pPayload + PayloadSize); + + pLook4Word = pPayload; + while( memcmp( pLook4Word, pKeyWord, SizeOfKeyWord) && pLook4Word<pLastByteAdd ) + { + pLook4Word++; + } + + pEndString = pLook4Word; + /* Retrieve phone number */ + if( pLook4Word != pLastByteAdd) + { + pLook4Word += SizeOfKeyWord; + while( memcmp( pEndString, URI_FIRST_DATA_END, URI_FIRST_DATA_END_LENGTH) && pEndString<pLastByteAdd ) + { + pEndString++; + } + if( pEndString != pLastByteAdd) + { + memcpy( pSMSStruct->PhoneNumber, pLook4Word, pEndString-pLook4Word); + /* add end of string charactere */ + pSMSStruct->PhoneNumber[pEndString-pLook4Word] = 0; + } + } + pEndString += URI_FIRST_DATA_END_LENGTH; + pLook4Word = pEndString; + + /* check if e-mail subject is present */ + if(!memcmp( pLook4Word, MESSAGE_BEGIN_STRING, MESSAGE_BEGIN_STRING_LENGTH)) + { + pEndString += MESSAGE_BEGIN_STRING_LENGTH; + /* Retrieve message */ + memcpy( pSMSStruct->Message, pEndString, PayloadSize-(pEndString-pPayload)); + /* add end of string charactere */ + pSMSStruct->Message[PayloadSize-(pEndString-pPayload)] = 0; + } +} + +/** + * @brief This fonction read the SMS and store data in a structure + * @param pRecordStruct : Pointer on the record structure + * @param pSMSStruct : pointer on the structure to fill + * @retval NONE + */ +static void NDEF_ReadURI_SMS ( sRecordInfo *pRecordStruct, sSMSInfo *pSMSStruct ) +{ + uint8_t* pPayload; + uint32_t PayloadSize; + + PayloadSize = ((uint32_t)(pRecordStruct->PayloadLength3)<<24) | ((uint32_t)(pRecordStruct->PayloadLength2)<<16) | + ((uint32_t)(pRecordStruct->PayloadLength1)<<8) | pRecordStruct->PayloadLength0; + + /* Read record header */ + pPayload = (uint8_t*)(pRecordStruct->PayloadBufferAdd); + + if( pRecordStruct->NDEF_Type == URI_SMS_TYPE) + NDEF_FillSMSStruct(pPayload , PayloadSize, pSMSStruct); + +} + +/** + * @} + */ + +/** @defgroup libSMS_Public_Functions + * @{ + * @brief This file is used to manage SMS (stored or loaded in tag) + */ + +/** + * @brief This fonction read NDEF and retrieve SMS information if any + * @param pRecordStruct : Pointer on the record structure + * @param pSMSStruct : pointer on the structure to fill + * @retval SUCCESS : SMS information from NDEF have been retrieve + * @retval ERROR : Not able to retrieve SMS information + */ +uint16_t NDEF_ReadSMS(sRecordInfo *pRecordStruct, sSMSInfo *pSMSStruct) +{ + uint16_t status = ERROR; + uint16_t FileId=0; + sRecordInfo *pSPRecordStruct; + uint32_t PayloadSize, RecordPosition; + uint8_t* pData; + + if( pRecordStruct->NDEF_Type == URI_SMS_TYPE ) + { + NDEF_ReadURI_SMS(pRecordStruct, pSMSStruct ); + status = SUCCESS; + } + else if( pRecordStruct->NDEF_Type == SMARTPOSTER_TYPE) + { + for (RecordPosition = 0; RecordPosition<pRecordStruct->NbOfRecordInSPPayload; RecordPosition++) + { + pSPRecordStruct = (sRecordInfo *)(pRecordStruct->SPRecordStructAdd[RecordPosition]); + if(pSPRecordStruct->NDEF_Type == URI_SMS_TYPE ) + { + NDEF_ReadURI_SMS(pSPRecordStruct, pSMSStruct ); + status = SUCCESS; + } + if(pSPRecordStruct->NDEF_Type == TEXT_TYPE ) + { + PayloadSize = ((uint32_t)(pSPRecordStruct->PayloadLength3)<<24) | ((uint32_t)(pSPRecordStruct->PayloadLength2)<<16) | + ((uint32_t)(pSPRecordStruct->PayloadLength1)<<8) | pSPRecordStruct->PayloadLength0; + + /* The instruction content the UTF-8 language code that is not used here */ + pData = (uint8_t*)pSPRecordStruct->PayloadBufferAdd; + PayloadSize -= *pData+1; /* remove not usefull data */ + pData += *pData+1; /* set pointer on usefull data */ + + memcpy(pSMSStruct->Information, pData, PayloadSize); + /* add end of string charactere */ + pSMSStruct->Information[PayloadSize] = 0; + } + } + } + + CloseNDEFSession(FileId); + + return status; +} + +/** + * @brief This fonction write the NDEF file with the SMS data given in the structure + * @param pSMSStruct : pointer on structure that contain the SMS information + * @retval SUCCESS : the function is succesful + * @retval ERROR : Not able to store NDEF file inside tag. + */ +uint16_t NDEF_WriteSMS ( sSMSInfo *pSMSStruct ) +{ + uint16_t status = ERROR; + uint32_t smsSize, infoSize, totalSize, Offset = 0; + + /* SMS is an URI but can be included in a smart poster to add text to give instruction to user for instance */ + + /* SMS (smart poster) Record Header */ + /************************************/ + /* 7 | 6 | 5 | 4 | 3 | 2 1 0 */ + /*----------------------------------*/ + /* MB ME CF SR IL TNF */ /* <---- CF=0, IL=0 and SR=1 TNF=1 NFC Forum Well-known type*/ + /*----------------------------------*/ + /* TYPE LENGTH */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 3 */ /* <---- Used only if SR=0 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 2 */ /* <---- Used only if SR=0 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 1 */ /* <---- Used only if SR=0 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 0 */ + /*----------------------------------*/ + /* ID LENGTH */ /* <---- Not Used */ + /*----------------------------------*/ + /* TYPE */ + /*----------------------------------*/ + /* ID */ /* <---- Not Used */ + /************************************/ + + NDEF_Buffer[0] = 0; + NDEF_Buffer[1] = 0; + Offset = FIRST_RECORD_OFFSET; + infoSize = 0; + + /* SMS : 1+sms:+tel+1+body=+message */ + smsSize = 1+SMS_TYPE_STRING_LENGTH+strlen(pSMSStruct->PhoneNumber)+URI_FIRST_DATA_END_LENGTH+MESSAGE_BEGIN_STRING_LENGTH+strlen(pSMSStruct->Message); + + /* Check if a Smart poster is needed */ + if (pSMSStruct->Information[0] != '\0') + { + /* Info : 1+2+info */ + infoSize = 1+ISO_ENGLISH_CODE_STRING_LENGTH+strlen(pSMSStruct->Information); + /* Total */ + totalSize = 4+smsSize+4+infoSize; + if (smsSize > 255) totalSize+=3; /* Normal SMS size */ + if (infoSize > 255) totalSize+=3; /* Normal Info size */ + + /* SmartPoster header */ + if (totalSize > 255) + { + NDEF_Buffer[Offset++] = 0xC1; + NDEF_Buffer[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (totalSize & 0xFF000000)>>24; + NDEF_Buffer[Offset++] = (totalSize & 0x00FF0000)>>16; + NDEF_Buffer[Offset++] = (totalSize & 0x0000FF00)>>8; + NDEF_Buffer[Offset++] = (totalSize & 0x000000FF); + } + else + { + NDEF_Buffer[Offset++] = 0xD1; + NDEF_Buffer[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (uint8_t)totalSize; + } + memcpy(&NDEF_Buffer[Offset], SMART_POSTER_TYPE_STRING, SMART_POSTER_TYPE_STRING_LENGTH); + Offset+=SMART_POSTER_TYPE_STRING_LENGTH; + } + + /* SMS header */ + NDEF_Buffer[Offset] = 0x81; + if (smsSize < 256) NDEF_Buffer[Offset] |= 0x10; // Set the SR bit + if (pSMSStruct->Information[0] == '\0') NDEF_Buffer[Offset] |= 0x40; // Set the ME bit + Offset++; + + NDEF_Buffer[Offset++] = URI_TYPE_STRING_LENGTH; + if (smsSize > 255) + { + NDEF_Buffer[Offset++] = (smsSize & 0xFF000000)>>24; + NDEF_Buffer[Offset++] = (smsSize & 0x00FF0000)>>16; + NDEF_Buffer[Offset++] = (smsSize & 0x0000FF00)>>8; + NDEF_Buffer[Offset++] = (smsSize & 0x000000FF); + } + else + { + NDEF_Buffer[Offset++] = (uint8_t)smsSize; + } + memcpy(&NDEF_Buffer[Offset], URI_TYPE_STRING, URI_TYPE_STRING_LENGTH); + Offset+=URI_TYPE_STRING_LENGTH; + + /* SMS payload */ + NDEF_Buffer[Offset++] = URI_ID_0x00; /* URI identifier no abbreviation */ + memcpy(&NDEF_Buffer[Offset], SMS_TYPE_STRING, SMS_TYPE_STRING_LENGTH); + Offset += SMS_TYPE_STRING_LENGTH; + memcpy( &NDEF_Buffer[Offset], pSMSStruct->PhoneNumber,strlen(pSMSStruct->PhoneNumber)); + Offset += strlen(pSMSStruct->PhoneNumber); + memcpy( &NDEF_Buffer[Offset], URI_FIRST_DATA_END,URI_FIRST_DATA_END_LENGTH); + Offset += URI_FIRST_DATA_END_LENGTH; + + memcpy( &NDEF_Buffer[Offset], MESSAGE_BEGIN_STRING, MESSAGE_BEGIN_STRING_LENGTH); + Offset += MESSAGE_BEGIN_STRING_LENGTH; + memcpy( &NDEF_Buffer[Offset], pSMSStruct->Message, strlen(pSMSStruct->Message)); + Offset += strlen(pSMSStruct->Message); + + /* Information header */ + if (pSMSStruct->Information[0] != '\0') + { + if (infoSize > 255) + { + NDEF_Buffer[Offset++] = 0x41; + NDEF_Buffer[Offset++] = TEXT_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (infoSize & 0xFF000000)>>24; + NDEF_Buffer[Offset++] = (infoSize & 0x00FF0000)>>16; + NDEF_Buffer[Offset++] = (infoSize & 0x0000FF00)>>8; + NDEF_Buffer[Offset++] = (infoSize & 0x000000FF); + } + else + { + NDEF_Buffer[Offset++] = 0x51; + NDEF_Buffer[Offset++] = TEXT_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (uint8_t)infoSize; + } + + memcpy(&NDEF_Buffer[Offset], TEXT_TYPE_STRING, TEXT_TYPE_STRING_LENGTH); + Offset+=TEXT_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = ISO_ENGLISH_CODE_STRING_LENGTH; /* UTF-8 with x byte language code */ + memcpy(&NDEF_Buffer[Offset], ISO_ENGLISH_CODE_STRING, ISO_ENGLISH_CODE_STRING_LENGTH); + Offset+=ISO_ENGLISH_CODE_STRING_LENGTH; + + /* Information payload */ + memcpy( &NDEF_Buffer[Offset], pSMSStruct->Information,strlen(pSMSStruct->Information)); + Offset += strlen(pSMSStruct->Information); + } + + /* Write NDEF */ + status = WriteData ( 0x00 , Offset , NDEF_Buffer); + + /* Write NDEF size to complete*/ + if( status == NDEF_ACTION_COMPLETED) + { + Offset -= 2; /* Must not count the 2 byte that represent the NDEF size */ + NDEF_Buffer[0] = (Offset & 0xFF00)>>8; + NDEF_Buffer[1] = (Offset & 0x00FF); + + status = WriteData ( 0x00 , 2 , NDEF_Buffer); + } + + if( status == NDEF_ACTION_COMPLETED) + return SUCCESS; + else + return ERROR; +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/ + +
diff -r 000000000000 -r 3b093bd0819e lib_NDEF_SMS.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF_SMS.h Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,59 @@ +/** + ****************************************************************************** + * @file lib_NDEF_SMS.h + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage SMS NDEF file. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LIB_NDEF_SMS_H +#define __LIB_NDEF_SMS_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF.h" + + +typedef struct +{ + char PhoneNumber[16]; + char Message[400]; + char Information[400]; +}sSMSInfo; + + + + +uint16_t NDEF_ReadSMS(sRecordInfo *pRecordStruct, sSMSInfo *pSMSStruct); +uint16_t NDEF_WriteSMS( sSMSInfo *pSMSStruct ); + +#ifdef __cplusplus +} +#endif + +#endif /* __LIB_NDEF_SMS_H */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 3b093bd0819e lib_NDEF_URI.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF_URI.c Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,543 @@ +/** + ****************************************************************************** + * @file lib_NDEF_URI.c + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage NDEF file that represent URI. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF_URI.h" + +/** @addtogroup NFC_libraries + * @{ + * @brief <b>This is the library used to manage the content of the TAG (data) + * But also the specific feature of the tag, for instance + * password, gpo... </b> + */ + + +/** @addtogroup libNFC_FORUM + * @{ + * @brief This part of the library manage data which follow NFC forum organisation. + */ + +/** + * @brief This buffer contains the data send/received by TAG + */ +extern uint8_t NDEF_Buffer [NDEF_MAX_SIZE]; + +/** @defgroup libURI_Private_Functions + * @{ + */ + +static void NDEF_Parse_WellKnowType(sRecordInfo *pRecordStruct, sURI_Info* pURI ); + +/** + * @brief This fonction read the URI information and store data in a structure + * @param pRecordStruct : Pointer on the record structure + * @param pURI : pointer on the structure to fill + * @retval NONE + */ +static void NDEF_Parse_WellKnowType(sRecordInfo *pRecordStruct, sURI_Info* pURI ) +{ + uint32_t PayloadSize; + uint8_t Offset; + uint8_t* pPayload; + + pPayload = (uint8_t*)(pRecordStruct->PayloadBufferAdd); + + switch( *pPayload) + { + case URI_ID_0x01: + memcpy( pURI->protocol, URI_ID_0x01_STRING, strlen(URI_ID_0x01_STRING)); + Offset = strlen(URI_ID_0x01_STRING); + break; + + case URI_ID_0x02: + memcpy( pURI->protocol, URI_ID_0x02_STRING, strlen(URI_ID_0x02_STRING)); + Offset = strlen(URI_ID_0x02_STRING); + break; + + case URI_ID_0x03: + memcpy( pURI->protocol, URI_ID_0x03_STRING, strlen(URI_ID_0x03_STRING)); + Offset = strlen(URI_ID_0x03_STRING); + break; + + case URI_ID_0x04: + memcpy( pURI->protocol, URI_ID_0x04_STRING, strlen(URI_ID_0x04_STRING)); + Offset = strlen(URI_ID_0x04_STRING); + break; + + case URI_ID_0x05: + memcpy( pURI->protocol, URI_ID_0x05_STRING, strlen(URI_ID_0x05_STRING)); + Offset = strlen(URI_ID_0x05_STRING); + break; + + case URI_ID_0x06: + memcpy( pURI->protocol, URI_ID_0x06_STRING, strlen(URI_ID_0x06_STRING)); + Offset = strlen(URI_ID_0x06_STRING); + break; + + case URI_ID_0x07: + memcpy( pURI->protocol, URI_ID_0x07_STRING, strlen(URI_ID_0x07_STRING)); + Offset = strlen(URI_ID_0x07_STRING); + break; + + case URI_ID_0x08: + memcpy( pURI->protocol, URI_ID_0x08_STRING, strlen(URI_ID_0x08_STRING)); + Offset = strlen(URI_ID_0x08_STRING); + break; + + case URI_ID_0x09: + memcpy( pURI->protocol, URI_ID_0x09_STRING, strlen(URI_ID_0x09_STRING)); + Offset = strlen(URI_ID_0x09_STRING); + break; + + case URI_ID_0x0A: + memcpy( pURI->protocol, URI_ID_0x0A_STRING, strlen(URI_ID_0x0A_STRING)); + Offset = strlen(URI_ID_0x0A_STRING); + break; + + case URI_ID_0x0B: + memcpy( pURI->protocol, URI_ID_0x0B_STRING, strlen(URI_ID_0x0B_STRING)); + Offset = strlen(URI_ID_0x0B_STRING); + break; + + case URI_ID_0x0C: + memcpy( pURI->protocol, URI_ID_0x0C_STRING, strlen(URI_ID_0x0C_STRING)); + Offset = strlen(URI_ID_0x0C_STRING); + break; + + case URI_ID_0x0D: + memcpy( pURI->protocol, URI_ID_0x0D_STRING, strlen(URI_ID_0x0D_STRING)); + Offset = strlen(URI_ID_0x0D_STRING); + break; + + case URI_ID_0x0E: + memcpy( pURI->protocol, URI_ID_0x0E_STRING, strlen(URI_ID_0x0E_STRING)); + Offset = strlen(URI_ID_0x0E_STRING); + break; + + case URI_ID_0x0F: + memcpy( pURI->protocol, URI_ID_0x0F_STRING, strlen(URI_ID_0x0F_STRING)); + Offset = strlen(URI_ID_0x0F_STRING); + break; + + case URI_ID_0x10: + memcpy( pURI->protocol, URI_ID_0x10_STRING, strlen(URI_ID_0x10_STRING)); + Offset = strlen(URI_ID_0x10_STRING); + break; + + case URI_ID_0x11: + memcpy( pURI->protocol, URI_ID_0x11_STRING, strlen(URI_ID_0x11_STRING)); + Offset = strlen(URI_ID_0x11_STRING); + break; + + case URI_ID_0x12: + memcpy( pURI->protocol, URI_ID_0x12_STRING, strlen(URI_ID_0x12_STRING)); + Offset = strlen(URI_ID_0x12_STRING); + break; + + case URI_ID_0x13: + memcpy( pURI->protocol, URI_ID_0x13_STRING, strlen(URI_ID_0x13_STRING)); + Offset = strlen(URI_ID_0x13_STRING); + break; + + case URI_ID_0x14: + memcpy( pURI->protocol, URI_ID_0x14_STRING, strlen(URI_ID_0x14_STRING)); + Offset = strlen(URI_ID_0x14_STRING); + break; + + case URI_ID_0x15: + memcpy( pURI->protocol, URI_ID_0x15_STRING, strlen(URI_ID_0x15_STRING)); + Offset = strlen(URI_ID_0x15_STRING); + break; + + case URI_ID_0x16: + memcpy( pURI->protocol, URI_ID_0x16_STRING, strlen(URI_ID_0x16_STRING)); + Offset = strlen(URI_ID_0x16_STRING); + break; + + case URI_ID_0x17: + memcpy( pURI->protocol, URI_ID_0x17_STRING, strlen(URI_ID_0x17_STRING)); + Offset = strlen(URI_ID_0x17_STRING); + break; + + case URI_ID_0x18: + memcpy( pURI->protocol, URI_ID_0x18_STRING, strlen(URI_ID_0x18_STRING)); + Offset = strlen(URI_ID_0x18_STRING); + break; + + case URI_ID_0x19: + memcpy( pURI->protocol, URI_ID_0x19_STRING, strlen(URI_ID_0x19_STRING)); + Offset = strlen(URI_ID_0x19_STRING); + break; + + case URI_ID_0x1A: + memcpy( pURI->protocol, URI_ID_0x1A_STRING, strlen(URI_ID_0x1A_STRING)); + Offset = strlen(URI_ID_0x1A_STRING); + break; + + case URI_ID_0x1B: + memcpy( pURI->protocol, URI_ID_0x1B_STRING, strlen(URI_ID_0x1B_STRING)); + Offset = strlen(URI_ID_0x1B_STRING); + break; + + case URI_ID_0x1C: + memcpy( pURI->protocol, URI_ID_0x1C_STRING, strlen(URI_ID_0x1C_STRING)); + Offset = strlen(URI_ID_0x1C_STRING); + break; + + case URI_ID_0x1D: + memcpy( pURI->protocol, URI_ID_0x1D_STRING, strlen(URI_ID_0x1D_STRING)); + Offset = strlen(URI_ID_0x1D_STRING); + break; + + case URI_ID_0x1E: + memcpy( pURI->protocol, URI_ID_0x1E_STRING, strlen(URI_ID_0x1E_STRING)); + Offset = strlen(URI_ID_0x1E_STRING); + break; + + case URI_ID_0x1F: + memcpy( pURI->protocol, URI_ID_0x1F_STRING, strlen(URI_ID_0x1F_STRING)); + Offset = strlen(URI_ID_0x1F_STRING); + break; + + case URI_ID_0x20: + memcpy( pURI->protocol, URI_ID_0x20_STRING, strlen(URI_ID_0x20_STRING)); + Offset = strlen(URI_ID_0x20_STRING); + break; + + case URI_ID_0x21: + memcpy( pURI->protocol, URI_ID_0x21_STRING, strlen(URI_ID_0x21_STRING)); + Offset = strlen(URI_ID_0x21_STRING); + break; + + case URI_ID_0x22: + memcpy( pURI->protocol, URI_ID_0x22_STRING, strlen(URI_ID_0x22_STRING)); + Offset = strlen(URI_ID_0x22_STRING); + break; + + case URI_ID_0x23: + memcpy( pURI->protocol, URI_ID_0x23_STRING, strlen(URI_ID_0x23_STRING)); + Offset = strlen(URI_ID_0x23_STRING); + break; + + default: + Offset = 0; + /* Should not happened */ + break; + } + /* add end of string charactere */ + pURI->protocol[Offset] = '\0'; + + pPayload++; /* go after well know byte */ + + PayloadSize = ((uint32_t)(pRecordStruct->PayloadLength3)<<24) | ((uint32_t)(pRecordStruct->PayloadLength2)<<16) | + ((uint32_t)(pRecordStruct->PayloadLength1)<<8) | pRecordStruct->PayloadLength0; + + PayloadSize = PayloadSize -1; /* remove well know byte */ + + memcpy( pURI->URI_Message, pPayload, PayloadSize); + /* add end of string charactere */ + pURI->URI_Message[PayloadSize] = '\0'; + +} + +/** + * @} + */ + +/** @defgroup libURI_Public_Functions + * @{ + * @brief This file is used to manage URI (stored or loaded in tag) + */ + +/** + * @brief This fonction read NDEF and retrieve URI information if any + * @param pRecordStruct : Pointer on the record structure + * @param pURI : pointer on the structure to fill + * @retval SUCCESS : URI information from NDEF have been retrieved + * @retval ERROR : Not able to retrieve URI information + */ +uint16_t NDEF_ReadURI(sRecordInfo *pRecordStruct, sURI_Info *pURI) +{ + uint16_t status = ERROR; + sRecordInfo *pSPRecordStruct; + uint32_t PayloadSize, RecordPosition; + uint8_t* pData; + + if( pRecordStruct->NDEF_Type == WELL_KNOWN_ABRIDGED_URI_TYPE ) + { + NDEF_Parse_WellKnowType(pRecordStruct, pURI ); + status = SUCCESS; + } + else if( pRecordStruct->NDEF_Type == SMARTPOSTER_TYPE) + { + for (RecordPosition = 0; RecordPosition<pRecordStruct->NbOfRecordInSPPayload; RecordPosition++) + { + pSPRecordStruct = (sRecordInfo *)(pRecordStruct->SPRecordStructAdd[RecordPosition]); + if(pSPRecordStruct->NDEF_Type == WELL_KNOWN_ABRIDGED_URI_TYPE ) + { + NDEF_Parse_WellKnowType(pSPRecordStruct, pURI ); + status = SUCCESS; + } + if(pSPRecordStruct->NDEF_Type == TEXT_TYPE ) + { + PayloadSize = ((uint32_t)(pSPRecordStruct->PayloadLength3)<<24) | ((uint32_t)(pSPRecordStruct->PayloadLength2)<<16) | + ((uint32_t)(pSPRecordStruct->PayloadLength1)<<8) | pSPRecordStruct->PayloadLength0; + + /* The instruction content the UTF-8 language code that is not used here */ + pData = (uint8_t*)pSPRecordStruct->PayloadBufferAdd; + pData += *pData+1; + + memcpy(pURI->Information, pData, PayloadSize); + } + } + } + else + { + status = ERROR; + } + + return status; +} + +/** + * @brief This fonction write the NDEF file with the URI data given in the structure + * @param pURI : pointer on structure that contain the URI information + * @retval SUCCESS : the function is succesful + * @retval ERROR : Not able to store NDEF file inside tag. + */ +uint16_t NDEF_WriteURI ( sURI_Info *pURI) +{ + uint16_t status = ERROR; + uint32_t uriSize, infoSize, totalSize, Offset = 0; + char type; + + /* GEO is an URI but can be included in a smart poster to add text to give instruction to user for instance */ + + /* GEO (smart poster) Record Header */ + /************************************/ + /* 7 | 6 | 5 | 4 | 3 | 2 1 0 */ + /*----------------------------------*/ + /* MB ME CF SR IL TNF */ /* <---- CF=0, IL=0 and SR=1 TNF=1 NFC Forum Well-known type*/ + /*----------------------------------*/ + /* TYPE LENGTH */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 3 */ /* <---- Used only if SR=0 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 2 */ /* <---- Used only if SR=0 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 1 */ /* <---- Used only if SR=0 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 0 */ + /*----------------------------------*/ + /* ID LENGTH */ /* <---- Not Used */ + /*----------------------------------*/ + /* TYPE */ + /*----------------------------------*/ + /* ID */ /* <---- Not Used */ + /************************************/ + + NDEF_Buffer[0] = 0; + NDEF_Buffer[1] = 0; + Offset = FIRST_RECORD_OFFSET; + infoSize = 0; + + /* We need to know the URI type in order to define if an abreviation is available */ + type = getUriType(pURI->protocol); + + /* URI : 1+URI for abreviate protocol*/ + if (type != URI_ID_0x00) + uriSize = 1+strlen(pURI->URI_Message); + else /*: 1+protocol+URI else*/ + uriSize = 1+strlen(pURI->protocol)+strlen(pURI->URI_Message); + + /* Check if a Smart poster is needed */ + if (pURI->Information[0] != '\0') + { + /* Info : 1+2+info */ + infoSize = 1+ISO_ENGLISH_CODE_STRING_LENGTH+strlen(pURI->Information); + /* Total */ + totalSize = 4+uriSize+4+infoSize; + if (uriSize > 255) totalSize+=3; /* Normal URI size */ + if (infoSize > 255) totalSize+=3; /* Normal Info size */ + + /* SmartPoster header */ + if (totalSize > 255) + { + NDEF_Buffer[Offset++] = 0xC1; + NDEF_Buffer[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (totalSize & 0xFF000000)>>24; + NDEF_Buffer[Offset++] = (totalSize & 0x00FF0000)>>16; + NDEF_Buffer[Offset++] = (totalSize & 0x0000FF00)>>8; + NDEF_Buffer[Offset++] = (totalSize & 0x000000FF); + } + else + { + NDEF_Buffer[Offset++] = 0xD1; + NDEF_Buffer[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (uint8_t)totalSize; + } + memcpy(&NDEF_Buffer[Offset], SMART_POSTER_TYPE_STRING, SMART_POSTER_TYPE_STRING_LENGTH); + Offset+=SMART_POSTER_TYPE_STRING_LENGTH; + } + + /* URI header */ + NDEF_Buffer[Offset] = 0x81; + if (uriSize < 256) NDEF_Buffer[Offset] |= 0x10; // Set the SR bit + if (pURI->Information[0] == '\0') NDEF_Buffer[Offset] |= 0x40; // Set the ME bit + Offset++; + + NDEF_Buffer[Offset++] = URI_TYPE_STRING_LENGTH; + if (uriSize > 255) + { + NDEF_Buffer[Offset++] = (uriSize & 0xFF000000)>>24; + NDEF_Buffer[Offset++] = (uriSize & 0x00FF0000)>>16; + NDEF_Buffer[Offset++] = (uriSize & 0x0000FF00)>>8; + NDEF_Buffer[Offset++] = (uriSize & 0x000000FF); + } + else + { + NDEF_Buffer[Offset++] = (uint8_t)uriSize; + } + memcpy(&NDEF_Buffer[Offset], URI_TYPE_STRING, URI_TYPE_STRING_LENGTH); + Offset+=URI_TYPE_STRING_LENGTH; + + NDEF_Buffer[Offset++]=type; + if (type == URI_ID_0x00) // No abreviation + { + memcpy(&NDEF_Buffer[Offset], pURI->protocol, strlen(pURI->protocol)); + Offset+=strlen(pURI->protocol); + } + + memcpy(&NDEF_Buffer[Offset], pURI->URI_Message, strlen(pURI->URI_Message)); + Offset+=strlen(pURI->URI_Message); + + /* Information header */ + if (pURI->Information[0] != '\0') + { + if (infoSize > 255) + { + NDEF_Buffer[Offset++] = 0x41; + NDEF_Buffer[Offset++] = TEXT_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (infoSize & 0xFF000000)>>24; + NDEF_Buffer[Offset++] = (infoSize & 0x00FF0000)>>16; + NDEF_Buffer[Offset++] = (infoSize & 0x0000FF00)>>8; + NDEF_Buffer[Offset++] = (infoSize & 0x000000FF); + } + else + { + NDEF_Buffer[Offset++] = 0x51; + NDEF_Buffer[Offset++] = TEXT_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = (uint8_t)infoSize; + } + + memcpy(&NDEF_Buffer[Offset], TEXT_TYPE_STRING, TEXT_TYPE_STRING_LENGTH); + Offset+=TEXT_TYPE_STRING_LENGTH; + NDEF_Buffer[Offset++] = ISO_ENGLISH_CODE_STRING_LENGTH; /* UTF-8 with x byte language code */ + memcpy(&NDEF_Buffer[Offset], ISO_ENGLISH_CODE_STRING, ISO_ENGLISH_CODE_STRING_LENGTH); + Offset+=ISO_ENGLISH_CODE_STRING_LENGTH; + + /* Information payload */ + memcpy( &NDEF_Buffer[Offset], pURI->Information,strlen(pURI->Information)); + Offset += strlen(pURI->Information); + } + + /* Write NDEF */ + status = WriteData ( 0x00 , Offset , NDEF_Buffer); + + /* Write NDEF size to complete*/ + if( status == NDEF_ACTION_COMPLETED) + { + Offset -= 2; /* Must not count the 2 byte that represent the NDEF size */ + NDEF_Buffer[0] = (Offset & 0xFF00)>>8; + NDEF_Buffer[1] = (Offset & 0x00FF); + + status = WriteData ( 0x00 , 2 , NDEF_Buffer); + } + + if( status == NDEF_ACTION_COMPLETED) + return SUCCESS; + else + return ERROR; +} + +char getUriType(char *protocol) +{ + if(!memcmp( protocol, URI_ID_0x01_STRING, strlen(URI_ID_0x01_STRING))) return URI_ID_0x01; + else if(!memcmp( protocol, URI_ID_0x02_STRING, strlen(URI_ID_0x02_STRING))) return URI_ID_0x02; + else if(!memcmp( protocol, URI_ID_0x03_STRING, strlen(URI_ID_0x03_STRING))) return URI_ID_0x03; + else if(!memcmp( protocol, URI_ID_0x04_STRING, strlen(URI_ID_0x04_STRING))) return URI_ID_0x04; + else if(!memcmp( protocol, URI_ID_0x05_STRING, strlen(URI_ID_0x05_STRING))) return URI_ID_0x05; + else if(!memcmp( protocol, URI_ID_0x06_STRING, strlen(URI_ID_0x06_STRING))) return URI_ID_0x06; + else if(!memcmp( protocol, URI_ID_0x07_STRING, strlen(URI_ID_0x07_STRING))) return URI_ID_0x07; + else if(!memcmp( protocol, URI_ID_0x08_STRING, strlen(URI_ID_0x08_STRING))) return URI_ID_0x08; + else if(!memcmp( protocol, URI_ID_0x09_STRING, strlen(URI_ID_0x09_STRING))) return URI_ID_0x09; + else if(!memcmp( protocol, URI_ID_0x0A_STRING, strlen(URI_ID_0x0A_STRING))) return URI_ID_0x0A; + else if(!memcmp( protocol, URI_ID_0x0B_STRING, strlen(URI_ID_0x0B_STRING))) return URI_ID_0x0B; + else if(!memcmp( protocol, URI_ID_0x0C_STRING, strlen(URI_ID_0x0C_STRING))) return URI_ID_0x0C; + else if(!memcmp( protocol, URI_ID_0x0D_STRING, strlen(URI_ID_0x0D_STRING))) return URI_ID_0x0D; + else if(!memcmp( protocol, URI_ID_0x0E_STRING, strlen(URI_ID_0x0E_STRING))) return URI_ID_0x0E; + else if(!memcmp( protocol, URI_ID_0x0F_STRING, strlen(URI_ID_0x0F_STRING))) return URI_ID_0x0F; + else if(!memcmp( protocol, URI_ID_0x10_STRING, strlen(URI_ID_0x10_STRING))) return URI_ID_0x10; + else if(!memcmp( protocol, URI_ID_0x11_STRING, strlen(URI_ID_0x11_STRING))) return URI_ID_0x11; + else if(!memcmp( protocol, URI_ID_0x12_STRING, strlen(URI_ID_0x12_STRING))) return URI_ID_0x12; + else if(!memcmp( protocol, URI_ID_0x13_STRING, strlen(URI_ID_0x13_STRING))) return URI_ID_0x13; + else if(!memcmp( protocol, URI_ID_0x14_STRING, strlen(URI_ID_0x14_STRING))) return URI_ID_0x14; + else if(!memcmp( protocol, URI_ID_0x15_STRING, strlen(URI_ID_0x15_STRING))) return URI_ID_0x15; + else if(!memcmp( protocol, URI_ID_0x16_STRING, strlen(URI_ID_0x16_STRING))) return URI_ID_0x16; + else if(!memcmp( protocol, URI_ID_0x17_STRING, strlen(URI_ID_0x17_STRING))) return URI_ID_0x17; + else if(!memcmp( protocol, URI_ID_0x18_STRING, strlen(URI_ID_0x18_STRING))) return URI_ID_0x18; + else if(!memcmp( protocol, URI_ID_0x19_STRING, strlen(URI_ID_0x19_STRING))) return URI_ID_0x19; + else if(!memcmp( protocol, URI_ID_0x1A_STRING, strlen(URI_ID_0x1A_STRING))) return URI_ID_0x1A; + else if(!memcmp( protocol, URI_ID_0x1B_STRING, strlen(URI_ID_0x1B_STRING))) return URI_ID_0x1B; + else if(!memcmp( protocol, URI_ID_0x1C_STRING, strlen(URI_ID_0x1C_STRING))) return URI_ID_0x1C; + else if(!memcmp( protocol, URI_ID_0x1D_STRING, strlen(URI_ID_0x1D_STRING))) return URI_ID_0x1D; + else if(!memcmp( protocol, URI_ID_0x1E_STRING, strlen(URI_ID_0x1E_STRING))) return URI_ID_0x1E; + else if(!memcmp( protocol, URI_ID_0x1F_STRING, strlen(URI_ID_0x1F_STRING))) return URI_ID_0x1F; + else if(!memcmp( protocol, URI_ID_0x20_STRING, strlen(URI_ID_0x20_STRING))) return URI_ID_0x20; + else if(!memcmp( protocol, URI_ID_0x21_STRING, strlen(URI_ID_0x21_STRING))) return URI_ID_0x21; + else if(!memcmp( protocol, URI_ID_0x22_STRING, strlen(URI_ID_0x22_STRING))) return URI_ID_0x22; + else if(!memcmp( protocol, URI_ID_0x23_STRING, strlen(URI_ID_0x23_STRING))) return URI_ID_0x23; + else return URI_ID_0x00; // No abreviation for this protocol +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/ + + + +
diff -r 000000000000 -r 3b093bd0819e lib_NDEF_URI.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF_URI.h Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,56 @@ +/** + ****************************************************************************** + * @file lib_NDEF_URI.h + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage URI NDEF file. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LIB_NDEF_URI_H +#define __LIB_NDEF_URI_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF.h" + +typedef struct +{ + char protocol[80]; + char URI_Message[200]; + char Information[200]; +}sURI_Info; + +uint16_t NDEF_ReadURI(sRecordInfo *pRecordStruct, sURI_Info *pURI); +uint16_t NDEF_WriteURI(sURI_Info *pURI); +char getUriType(char *protocol); + +#ifdef __cplusplus +} +#endif + +#endif /* __LIB_NDEF_URI_H */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 3b093bd0819e lib_NDEF_Vcard.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF_Vcard.c Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,384 @@ +/** + ****************************************************************************** + * @file lib_NDEF_Vcard.c + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage NDEF file that represent Vcard. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF_Vcard.h" + +/** @addtogroup NFC_libraries + * @{ + * @brief <b>This is the library used to manage the content of the TAG (data) + * But also the specific feature of the tag, for instance + * password, gpo... </b> + */ + + +/** @addtogroup libNFC_FORUM + * @{ + * @brief This part of the library manage data which follow NFC forum organisation. + */ + +/** + * @brief This buffer contains the data send/received by TAG + */ +extern uint8_t NDEF_Buffer [NDEF_MAX_SIZE]; + +/** @defgroup libVcard_Private_Functions + * @{ + */ + + +static void NDEF_FillVcardStruct( uint8_t* pPayload, uint32_t PayloadSize, char* pKeyWord, uint32_t SizeOfKeyWord, uint8_t* pString); +static void NDEF_ExtractVcard ( sRecordInfo *pRecordStruct, sVcardInfo *pVcardStruct ); + +/** + * @brief This fonction fill Vcard structure with information of NDEF message + * @param pPayload : pointer on the payload data of the NDEF message + * @param PayloadSize : number of data in the payload + * @param pKeyWord : pointer on the keyword to look for. + * @param SizeOfKeyWord : number of byte of the keyword we are looking for + * @param pString : Pointer on the data string to fill + * @retval NONE + */ +static void NDEF_FillVcardStruct( uint8_t* pPayload, uint32_t PayloadSize, char* pKeyWord, uint32_t SizeOfKeyWord, uint8_t* pString) +{ + uint8_t* pLastByteAdd, *pLook4Word, *pEndString ; + + /* First charactere force to NULL in case not matching found */ + *pString = 0; + + /* Interresting information are stored before picture if any */ + /* Moreover picture is not used in this demonstration SW */ + pLastByteAdd = pPayload; + while( memcmp( pLastByteAdd, JPEG, JPEG_STRING_SIZE) && pLastByteAdd<(pPayload+PayloadSize) ) + { + pLastByteAdd++; + } + + pLook4Word = pPayload; + while( memcmp( pLook4Word, pKeyWord, SizeOfKeyWord) && pLook4Word<pLastByteAdd ) + { + pLook4Word++; + } + + /* Word found */ + if( pLook4Word != pLastByteAdd) + { + pLook4Word += SizeOfKeyWord; + pEndString = pLook4Word; + while( memcmp( pEndString, LIMIT, LIMIT_STRING_SIZE) && pEndString<pLastByteAdd ) + { + pEndString++; + } + if( pEndString != pLastByteAdd) + { + memcpy( pString, pLook4Word, pEndString-pLook4Word); + /* add end of string charactere */ + pString += pEndString-pLook4Word; + *pString = '\0'; + } + } +} + +/** + * @brief This fonction read the Vcard and store data in a structure + * @param pRecordStruct : Pointer on the record structure + * @param pSMSStruct : pointer on the structure to fill + * @retval NONE + */ +static void NDEF_ExtractVcard ( sRecordInfo *pRecordStruct, sVcardInfo *pVcardStruct ) +{ + uint32_t PayloadSize; + uint8_t* pPayload; + + + PayloadSize = ((uint32_t)(pRecordStruct->PayloadLength3)<<24) | ((uint32_t)(pRecordStruct->PayloadLength2)<<16) | + ((uint32_t)(pRecordStruct->PayloadLength1)<<8) | pRecordStruct->PayloadLength0; + + /* Read record header */ + pPayload = (uint8_t*)(pRecordStruct->PayloadBufferAdd); + + NDEF_FillVcardStruct(pPayload , PayloadSize,VERSION, VERSION_STRING_SIZE, (uint8_t*)(pVcardStruct->Version)); + if( !memcmp(pVcardStruct->Version, VCARD_VERSION_2_1, VCARD_VERSION_2_1_SIZE)) + { + NDEF_FillVcardStruct(pPayload , PayloadSize,FIRSTNAME, FIRSTNAME_STRING_SIZE, (uint8_t*)(pVcardStruct->FirstName)); + NDEF_FillVcardStruct(pPayload , PayloadSize,TITLE, TITLE_STRING_SIZE, (uint8_t*)(pVcardStruct->Title)); + NDEF_FillVcardStruct(pPayload , PayloadSize,ORG, ORG_STRING_SIZE, (uint8_t*)(pVcardStruct->Org)); + NDEF_FillVcardStruct(pPayload , PayloadSize,HOME_ADDRESS, HOME_ADDRESS_STRING_SIZE, (uint8_t*)(pVcardStruct->HomeAddress)); + NDEF_FillVcardStruct(pPayload , PayloadSize,WORK_ADDRESS, WORK_ADDRESS_STRING_SIZE, (uint8_t*)(pVcardStruct->WorkAddress)); + NDEF_FillVcardStruct(pPayload , PayloadSize,HOME_TEL, HOME_TEL_STRING_SIZE, (uint8_t*)(pVcardStruct->HomeTel)); + NDEF_FillVcardStruct(pPayload , PayloadSize,WORK_TEL, WORK_TEL_STRING_SIZE, (uint8_t*)(pVcardStruct->WorkTel)); + NDEF_FillVcardStruct(pPayload , PayloadSize,CELL_TEL, CELL_TEL_STRING_SIZE, (uint8_t*)(pVcardStruct->CellTel)); + NDEF_FillVcardStruct(pPayload , PayloadSize,HOME_EMAIL, HOME_EMAIL_STRING_SIZE, (uint8_t*)(pVcardStruct->HomeEmail)); + NDEF_FillVcardStruct(pPayload , PayloadSize,WORK_EMAIL, WORK_EMAIL_STRING_SIZE, (uint8_t*)(pVcardStruct->WorkEmail)); + } + else if( !memcmp(pVcardStruct->Version, VCARD_VERSION_3_0, VCARD_VERSION_3_0_SIZE)) + { + /* need to be implemented */ + } + else + { + /* maybe new version but not supported in this sw */ + } + +} + +/** + * @} + */ + +/** @defgroup libVcard_Public_Functions + * @{ + * @brief This file is used to manage Vcard (stored or loaded in tag) + */ + +/** + * @brief This fonction read NDEF and retrieve Vcard information if any + * @param pRecordStruct : Pointer on the record structure + * @param pVcardStruct : pointer on the structure to fill + * @retval SUCCESS : Vcard information from NDEF have been retrieved + * @retval ERROR : Not able to retrieve Vcard information + */ +uint16_t NDEF_ReadVcard ( sRecordInfo *pRecordStruct, sVcardInfo *pVcardStruct ) +{ + uint16_t status = ERROR; + + if( pRecordStruct->NDEF_Type == VCARD_TYPE) + { + NDEF_ExtractVcard(pRecordStruct, pVcardStruct ); + status = SUCCESS; + } + + return status; +} + +/** + * @brief This fonction write the NDEF file with the Vcard data given in the structure + * @param pVcardStruct : pointer on structure that contain the Vcard information + * @retval SUCCESS : the function is succesful + * @retval ERROR : Not able to store NDEF file inside tag. + */ +uint16_t NDEF_WriteVcard ( sVcardInfo *pVcardStruct ) +{ + uint16_t status = ERROR; + uint16_t DataSize; + uint32_t PayloadSize = 0; + + /* Vcard Record Header */ + /************************************/ + /* 7 | 6 | 5 | 4 | 3 | 2 1 0 */ + /*----------------------------------*/ + /* MB ME CF SR IL TNF */ /* <---- CF=0, IL=0 and SR=0 TNF=2 NFC Forum Media type*/ + /*----------------------------------*/ + /* TYPE LENGTH */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 3 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 2 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 1 */ + /*----------------------------------*/ + /* PAYLOAD LENGTH 0 */ + /*----------------------------------*/ + /* ID LENGTH */ /* <---- Not Used */ + /*----------------------------------*/ + /* TYPE */ + /*----------------------------------*/ + /* ID */ /* <---- Not Used */ + /************************************/ + + /* As we don't have embedded a jpeg encoder/decoder in this firmware */ + /* We have made the choice to manage only string content of the vCard */ + /* For demonstration purpose in order to fill the 8kB of the M24SR */ + /* We have embedded a NDEF vCard in the STM32 to be able to fill M24SR */ + + + /* NDEF file must be written in 2 phases, first phase NDEF size is Null */ + NDEF_Buffer[NDEF_SIZE_OFFSET] = 0x00; + NDEF_Buffer[NDEF_SIZE_OFFSET+1] = 0x00; + + /* fill record header */ + NDEF_Buffer[FIRST_RECORD_OFFSET] = 0xC2; /* Record Flag */ + NDEF_Buffer[FIRST_RECORD_OFFSET+1] = VCARD_TYPE_STRING_LENGTH; + NDEF_Buffer[FIRST_RECORD_OFFSET+2] = 0x00; /* Will be filled at the end when payload size is known */ + NDEF_Buffer[FIRST_RECORD_OFFSET+3] = 0x00; + NDEF_Buffer[FIRST_RECORD_OFFSET+4] = 0x00; + NDEF_Buffer[FIRST_RECORD_OFFSET+5] = 0x00; + memcpy(&NDEF_Buffer[FIRST_RECORD_OFFSET+6], VCARD_TYPE_STRING, VCARD_TYPE_STRING_LENGTH); + + /* Payload is positionned in the NDEF after record header */ + PayloadSize = FIRST_RECORD_OFFSET+6+VCARD_TYPE_STRING_LENGTH; + + /* "BEGIN:VCARD\r\n" */ + memcpy(&NDEF_Buffer[PayloadSize], BEGIN, BEGIN_STRING_SIZE); + PayloadSize += BEGIN_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], VCARD,VCARD_STRING_SIZE); + PayloadSize += VCARD_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], LIMIT, LIMIT_STRING_SIZE); + PayloadSize += LIMIT_STRING_SIZE; + + /* "VERSION:2.1\r\n" */ + memcpy(&NDEF_Buffer[PayloadSize], VERSION, VERSION_STRING_SIZE); + PayloadSize += VERSION_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], VCARD_VERSION_2_1,VCARD_VERSION_2_1_SIZE); + PayloadSize += VCARD_VERSION_2_1_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], LIMIT, LIMIT_STRING_SIZE); + PayloadSize += LIMIT_STRING_SIZE; + + /* "FN:\r\n" */ + memcpy(&NDEF_Buffer[PayloadSize], FIRSTNAME, FIRSTNAME_STRING_SIZE); + PayloadSize += FIRSTNAME_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], pVcardStruct->FirstName,strlen(pVcardStruct->FirstName)); + PayloadSize += strlen(pVcardStruct->FirstName); + memcpy( &NDEF_Buffer[PayloadSize], LIMIT, LIMIT_STRING_SIZE); + PayloadSize += LIMIT_STRING_SIZE; + + /* "TITLE:\r\n" */ + memcpy(&NDEF_Buffer[PayloadSize], TITLE,TITLE_STRING_SIZE); + PayloadSize += TITLE_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], pVcardStruct->Title,strlen(pVcardStruct->Title)); + PayloadSize += strlen(pVcardStruct->Title); + memcpy( &NDEF_Buffer[PayloadSize], LIMIT, LIMIT_STRING_SIZE); + PayloadSize += LIMIT_STRING_SIZE; + + /* "ORG:\r\n" */ + memcpy(&NDEF_Buffer[PayloadSize], ORG,ORG_STRING_SIZE); + PayloadSize += ORG_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], pVcardStruct->Org,strlen(pVcardStruct->Org)); + PayloadSize += strlen(pVcardStruct->Org); + memcpy( &NDEF_Buffer[PayloadSize], LIMIT, LIMIT_STRING_SIZE); + PayloadSize += LIMIT_STRING_SIZE; + + /* "ADR;HOME:\r\n" */ + memcpy(&NDEF_Buffer[PayloadSize], HOME_ADDRESS,HOME_ADDRESS_STRING_SIZE); + PayloadSize += HOME_ADDRESS_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], pVcardStruct->HomeAddress,strlen(pVcardStruct->HomeAddress)); + PayloadSize += strlen(pVcardStruct->HomeAddress); + memcpy( &NDEF_Buffer[PayloadSize], LIMIT, LIMIT_STRING_SIZE); + PayloadSize += LIMIT_STRING_SIZE; + + /* "ADR;WORK:\r\n" */ + memcpy(&NDEF_Buffer[PayloadSize], WORK_ADDRESS,WORK_ADDRESS_STRING_SIZE); + PayloadSize += WORK_ADDRESS_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], pVcardStruct->WorkAddress,strlen(pVcardStruct->WorkAddress)); + PayloadSize += strlen(pVcardStruct->WorkAddress); + memcpy( &NDEF_Buffer[PayloadSize], LIMIT, LIMIT_STRING_SIZE); + PayloadSize += LIMIT_STRING_SIZE; + + /* "TEL;HOME:\r\n" */ + memcpy(&NDEF_Buffer[PayloadSize], HOME_TEL, HOME_TEL_STRING_SIZE); + PayloadSize += HOME_TEL_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], pVcardStruct->HomeTel,strlen(pVcardStruct->HomeTel)); + PayloadSize += strlen(pVcardStruct->HomeTel); + memcpy( &NDEF_Buffer[PayloadSize], LIMIT, LIMIT_STRING_SIZE); + PayloadSize += LIMIT_STRING_SIZE; + + /* "TEL;WORK:\r\n" */ + memcpy(&NDEF_Buffer[PayloadSize], WORK_TEL, WORK_TEL_STRING_SIZE); + PayloadSize += WORK_TEL_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], pVcardStruct->WorkTel,strlen(pVcardStruct->WorkTel)); + PayloadSize += strlen(pVcardStruct->WorkTel); + memcpy( &NDEF_Buffer[PayloadSize], LIMIT, LIMIT_STRING_SIZE); + PayloadSize += LIMIT_STRING_SIZE; + + /* "TEL;CELL:\r\n" */ + memcpy(&NDEF_Buffer[PayloadSize], CELL_TEL, CELL_TEL_STRING_SIZE); + PayloadSize += CELL_TEL_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], pVcardStruct->CellTel,strlen(pVcardStruct->CellTel)); + PayloadSize += strlen(pVcardStruct->CellTel); + memcpy( &NDEF_Buffer[PayloadSize], LIMIT, LIMIT_STRING_SIZE); + PayloadSize += LIMIT_STRING_SIZE; + + /* "EMAIL;HOME:\r\n" */ + memcpy(&NDEF_Buffer[PayloadSize], HOME_EMAIL, HOME_EMAIL_STRING_SIZE); + PayloadSize += HOME_EMAIL_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], pVcardStruct->HomeEmail,strlen(pVcardStruct->HomeEmail)); + PayloadSize += strlen(pVcardStruct->HomeEmail); + memcpy( &NDEF_Buffer[PayloadSize], LIMIT, LIMIT_STRING_SIZE); + PayloadSize += LIMIT_STRING_SIZE; + + /* "EMAIL;WORK:\r\n" */ + memcpy(&NDEF_Buffer[PayloadSize], WORK_EMAIL, WORK_EMAIL_STRING_SIZE); + PayloadSize += WORK_EMAIL_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], pVcardStruct->WorkEmail,strlen(pVcardStruct->WorkEmail)); + PayloadSize += strlen(pVcardStruct->WorkEmail); + memcpy( &NDEF_Buffer[PayloadSize], LIMIT, LIMIT_STRING_SIZE); + PayloadSize += LIMIT_STRING_SIZE; + + /* "END:VCARD\r\n" */ + memcpy(&NDEF_Buffer[PayloadSize], END,END_STRING_SIZE); + PayloadSize += END_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], VCARD,VCARD_STRING_SIZE); + PayloadSize += VCARD_STRING_SIZE; + memcpy( &NDEF_Buffer[PayloadSize], LIMIT, LIMIT_STRING_SIZE); + PayloadSize += LIMIT_STRING_SIZE; + + DataSize = (uint16_t)(PayloadSize); /* Must not count the 2 byte that represent the NDEF size */ + PayloadSize -= FIRST_RECORD_OFFSET+6+VCARD_TYPE_STRING_LENGTH; + + NDEF_Buffer[FIRST_RECORD_OFFSET+2] = (PayloadSize & 0xFF000000)>>24; + NDEF_Buffer[FIRST_RECORD_OFFSET+3] = (PayloadSize & 0x00FF0000)>>16; + NDEF_Buffer[FIRST_RECORD_OFFSET+4] = (PayloadSize & 0x0000FF00)>>8; + NDEF_Buffer[FIRST_RECORD_OFFSET+5] = (PayloadSize & 0x000000FF); + + + /* Write NDEF */ + status = WriteData ( 0x00 , DataSize , NDEF_Buffer); + + /* Write NDEF size to complete*/ + if( status == NDEF_ACTION_COMPLETED) + { + DataSize -= 2; /* Must not count the 2 byte that represent the NDEF size */ + NDEF_Buffer[0] = (DataSize & 0xFF00)>>8; + NDEF_Buffer[1] = (DataSize & 0x00FF); + + status = WriteData ( 0x00 , 2 , NDEF_Buffer); + } + + + if( status == NDEF_ACTION_COMPLETED) + return SUCCESS; + else + return ERROR; +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/ + + +
diff -r 000000000000 -r 3b093bd0819e lib_NDEF_Vcard.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_NDEF_Vcard.h Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,111 @@ +/** + ****************************************************************************** + * @file lib_NDEF_Vcard.h + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage Vcard NDEF file. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LIB_NDEF_VCARD_H +#define __LIB_NDEF_VCARD_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF.h" + + +#define VCARD_VERSION_2_1 "2.1" +#define VCARD_VERSION_2_1_SIZE 3 + +#define VCARD_VERSION_3_0 "3.0" +#define VCARD_VERSION_3_0_SIZE 3 + + +#define BEGIN "BEGIN:" +#define VCARD "VCARD" +#define VERSION "VERSION:" +#define FIRSTNAME "FN:" +#define HOME_TEL "TEL;HOME:" +#define WORK_TEL "TEL;WORK:" +#define CELL_TEL "TEL;CELL:" +#define HOME_EMAIL "EMAIL;HOME:" +#define WORK_EMAIL "EMAIL;WORK:" +#define HOME_ADDRESS "ADR;HOME:" +#define WORK_ADDRESS "ADR;WORK:" +#define TITLE "TITLE:" +#define ORG "ORG:" +#define END "END:" +#define JPEG "JPEG" + +#define LIMIT "\r\n" + +#define BEGIN_STRING_SIZE 6 +#define VCARD_STRING_SIZE 5 +#define VERSION_STRING_SIZE 8 +#define FIRSTNAME_STRING_SIZE 3 +#define HOME_TEL_STRING_SIZE 9 +#define WORK_TEL_STRING_SIZE 9 +#define CELL_TEL_STRING_SIZE 9 +#define HOME_EMAIL_STRING_SIZE 11 +#define WORK_EMAIL_STRING_SIZE 11 +#define HOME_ADDRESS_STRING_SIZE 9 +#define WORK_ADDRESS_STRING_SIZE 9 +#define TITLE_STRING_SIZE 6 +#define ORG_STRING_SIZE 4 +#define END_STRING_SIZE 4 +#define JPEG_STRING_SIZE 4 + +#define LIMIT_STRING_SIZE 2 + +typedef struct +{ + char Version [10]; + char FirstName[80]; + char Title[80]; + char Org[80]; + char HomeAddress[80]; + char WorkAddress[80]; + char HomeTel[40]; + char WorkTel[40]; + char CellTel[40]; + char HomeEmail[80]; + char WorkEmail[80]; +}sVcardInfo; + + + + +uint16_t NDEF_ReadVcard ( sRecordInfo *pRecordStruct, sVcardInfo *pVcardStruct ); +uint16_t NDEF_WriteVcard ( sVcardInfo *pVcardStruct ); + +#ifdef __cplusplus +} +#endif + +#endif /* __LIB_NDEF_VCARD_H */ + + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 3b093bd0819e lib_STProprietary_feature.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_STProprietary_feature.c Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,182 @@ +/** + ****************************************************************************** + * @file lib_STProprietary_feature.c + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage some proprietary feature. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "lib_STProprietary_feature.h" + +/** @addtogroup NFC_libraries + * @{ + * @brief <b>This is the library used to manage the content of the TAG (data) + * But also the specific feature of the tag, for instance + * password, gpo... </b> + */ + + +/** @addtogroup libSTProprietary + * @{ + * @brief This part of the library help to manage TAG with proprietary feature. + */ + + +/** @defgroup libSpecialFeature_Private_Functions + * @{ + */ + + +/** + * @} + */ + + +/** @defgroup libSpecialFeature_Public_Functions + * @{ + * @brief This file is used to manage private feature of the tag + */ + +/** + * @brief This fonction enable read only mode + * @param pCurrentWritePassword : Write password is needed to have right to enable read only mode + * @retval SUCCESS : M24SR access is now forbidden in write mode + * @retval ERROR : operation does not complete + */ +uint16_t STProprietary_EnableReadOnly(uint8_t* pCurrentWritePassword) +{ + uint16_t status; + uint16_t FileId; + + /* Before using Verify command NDEF file must be selected */ + GetNDEFFileId(&FileId); + OpenNDEFSession(FileId, ASK_FOR_SESSION); + + status = EnableReadOnly( pCurrentWritePassword); + + CloseNDEFSession(FileId); + + return status; +} + +/** + * @brief This fonction disable read only mode + * @param pCurrentWritePassword : Write password is needed to have right to disable read only mode + * @retval SUCCESS : M24SR write access is now allowed + * @retval ERROR : operation does not complete + */ +uint16_t STProprietary_DisableReadOnly(uint8_t* pCurrentWritePassword ) +{ + uint16_t status; + uint16_t FileId; + + /* Before using Verify command NDEF file must be selected */ + GetNDEFFileId(&FileId); + OpenNDEFSession(FileId, ASK_FOR_SESSION); + + status = DisableReadOnly( pCurrentWritePassword ); + + CloseNDEFSession(FileId); + + return status; +} + +/** + * @brief This fonction enable write only mode + * @param pCurrentWritePassword : Write password is needed to have right to enable write only mode + * @retval SUCCESS : M24SR access is now forbidden in read mode + * @retval ERROR : operation does not complete + */ +uint16_t STProprietary_EnableWriteOnly(uint8_t* pCurrentWritePassword) +{ + uint16_t status; + uint16_t FileId; + + /* Before using Verify command NDEF file must be selected */ + GetNDEFFileId(&FileId); + OpenNDEFSession(FileId, ASK_FOR_SESSION); + + status = EnableWriteOnly( pCurrentWritePassword); + + CloseNDEFSession(FileId); + + return status; +} + +/** + * @brief This fonction disable write only mode + * @param pCurrentWritePassword : Write password is needed to have right to disable write only mode + * @retval SUCCESS : M24SR read access is now allowed + * @retval ERROR : operation does not complete + */ +uint16_t STProprietary_DisableWriteOnly(uint8_t* pCurrentWritePassword) +{ + uint16_t status; + uint16_t FileId; + + /* Before using Verify command NDEF file must be selected */ + GetNDEFFileId(&FileId); + OpenNDEFSession(FileId, ASK_FOR_SESSION); + + status = DisableWriteOnly( pCurrentWritePassword); + + CloseNDEFSession(FileId); + + return status; +} + +/** + * @brief This function configure GPO purpose for RF or I2C session + * @param GPO_config: GPO configuration to set + * @param mode: select RF or I2C, GPO config to update + * @retval Status : Status of the operation. + */ +uint16_t STProprietary_GPOConfig(uc8 GPO_config, uc8 mode) +{ + uint16_t status; + uint16_t FileId; + + /* Before using Verify command NDEF file must be selected */ + GetNDEFFileId(&FileId); + OpenNDEFSession(FileId, ASK_FOR_SESSION); + status = GPO_Config(GPO_config, mode); + CloseNDEFSession(FileId); + + return status; +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/ +
diff -r 000000000000 -r 3b093bd0819e lib_STProprietary_feature.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_STProprietary_feature.h Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,43 @@ +/** + ****************************************************************************** + * @file lib_STProprietary_feature.h + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage some special feature embedded by target + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LIB_STPROPRIETARY_FEATURE_H +#define __LIB_STPROPRIETARY_FEATURE_H + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF.h" + +uint16_t STProprietary_EnableReadOnly(uint8_t* pCurrentWritePassword); +uint16_t STProprietary_DisableReadOnly(uint8_t* pCurrentWritePassword); +uint16_t STProprietary_EnableWriteOnly(uint8_t* pCurrentWritePassword); +uint16_t STProprietary_DisableWriteOnly(uint8_t* pCurrentWritePassword); +uint16_t STProprietary_GPOConfig(uc8 GPO_RFconfig, uc8 mode); + +#endif /* __LIB_STPROPRIETARY_FEATURE_H */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 3b093bd0819e lib_TagType4.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_TagType4.c Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,485 @@ +/** + ****************************************************************************** + * @file lib_TagType4.c + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage TagType4. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "lib_TagType4.h" + +/** @addtogroup NFC_libraries + * @{ + * @brief <b>This is the library used to manage the content of the TAG (data) + * But also the specific feature of the tag, for instance + * password, gpo... </b> + */ + + +/** @addtogroup libNFC_FORUM + * @{ + * @brief This part of the library manage data which follow NFC forum organisation. + */ + + +/** + * @brief This buffer contains the data send/received by TAG + */ +uint8_t NDEF_Buffer [NDEF_MAX_SIZE]; + +/** + * @brief This structure contains the data of the CC file + */ +sCCFileInfo CCFileStruct; + +/** + * @brief This structure contains the information encapsuled in the record header + * with few more for SW purpose + */ +sRecordInfo RecordStruct; + +/** @defgroup libTT4_Private_Functions + * @{ + */ + +/** + * @} + */ + + +/** @defgroup libTT4_Public_Functions + * @{ + * @brief This file is used to access tag type 4. + */ + +/** + * @brief This fonction initialize Tag Type 4 + * @param None + * @retval SUCCESS : Initialization done + */ +uint16_t TT4_Init (void) +{ + uint16_t status = SUCCESS; + uint8_t CCBuffer[15]; + sCCFileInfo *pCCFile; + + pCCFile = &CCFileStruct; + + status = TagT4Init( CCBuffer, sizeof(CCBuffer)); + + if( status == SUCCESS) + { + pCCFile->NumberCCByte = (uint16_t) ((CCBuffer[0x00]<<8) | CCBuffer[0x01]); + pCCFile->Version = CCBuffer[0x02]; + pCCFile->MaxReadByte = (uint16_t) ((CCBuffer[0x03]<<8) | CCBuffer[0x04]); + pCCFile->MaxWriteByte = (uint16_t) ((CCBuffer[0x05]<<8) | CCBuffer[0x06]); + pCCFile->TField = CCBuffer[0x07]; + pCCFile->LField = CCBuffer[0x08]; + pCCFile->FileID = (uint16_t) ((CCBuffer[0x09]<<8) | CCBuffer[0x0A]); + pCCFile->NDEFFileMaxSize = (uint16_t) ((CCBuffer[0x0B]<<8) | CCBuffer[0x0C]); + pCCFile->ReadAccess = CCBuffer[0x0D]; + pCCFile->WriteAccess = CCBuffer[0x0E]; + } + + return status; +} + +/** + * @brief This fonction read NDEF file + * @param pNDEF : pointer on buffer to fill with NDEF data + * @retval SUCCESS : NDEF file data have been retrieve + * @retval ERROR : Not able to get NDEF file data + */ +uint16_t TT4_ReadNDEF(uint8_t *pNDEF) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + + pCCFile = &CCFileStruct; + + if(OpenNDEFSession(pCCFile->FileID, ASK_FOR_SESSION) == SUCCESS) + { + status = NDEF_ReadNDEF(pNDEF); + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + +/** + * @brief This fonction write NDEF file + * @param pNDEF : pointer on buffer that contain the NDEF data + * @retval SUCCESS : NDEF file data have been stored + * @retval ERROR : Not able to store NDEF file + */ +uint16_t TT4_WriteNDEF(uint8_t *pNDEF) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + + pCCFile = &CCFileStruct; + + if(OpenNDEFSession(pCCFile->FileID, ASK_FOR_SESSION) == SUCCESS) + { + status = NDEF_WriteNDEF( pNDEF); + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + +/** + * @brief This fonction read NDEF file if NDEF is identified as URI + * @param pURI : pointer on URI structure to fill with read data + * @retval SUCCESS : URI structure has been updated + * @retval ERROR : Not able to fill URI structure + */ +uint16_t TT4_ReadURI(sURI_Info *pURI) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + sRecordInfo *pRecordStruct; + + pCCFile = &CCFileStruct; + pRecordStruct = &RecordStruct; + + + if(OpenNDEFSession(pCCFile->FileID, ASK_FOR_SESSION) == SUCCESS) + { + if(NDEF_IdentifyNDEF( pRecordStruct, NDEF_Buffer) == SUCCESS) + { + status = NDEF_ReadURI(pRecordStruct, pURI); + } + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + +/** + * @brief This fonction write NDEF file from data given in the URI structure + * @param pURI : pointer on URI structure to prepare NDEF + * @retval SUCCESS : NDEF URI stored + * @retval ERROR : Not able to store NDEF URI + */ +uint16_t TT4_WriteURI(sURI_Info *pURI) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + + pCCFile = &CCFileStruct; + + if(OpenNDEFSession(pCCFile->FileID, ASK_FOR_SESSION) == SUCCESS) + { + status = NDEF_WriteURI ( pURI ); + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + +/** + * @brief This fonction read NDEF file if NDEF is identified as SMS + * @param pSMS : pointer on SMS structure to fill with read data + * @retval SUCCESS : SMS structure has been updated + * @retval ERROR : Not able to fill MS structure + */ +uint16_t TT4_ReadSMS(sSMSInfo *pSMS) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + sRecordInfo *pRecordStruct; + + pCCFile = &CCFileStruct; + pRecordStruct = &RecordStruct; + + if(OpenNDEFSession(pCCFile->FileID, ASK_FOR_SESSION) == SUCCESS) + { + if(NDEF_IdentifyNDEF( pRecordStruct, NDEF_Buffer) == SUCCESS) + { + status = NDEF_ReadSMS(pRecordStruct, pSMS); + } + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + +/** + * @brief This fonction write NDEF file from data given in the SMS structure + * @param pSMS : pointer on SMS structure to prepare NDEF + * @retval SUCCESS : NDEF SMS stored + * @retval ERROR : Not able to store NDEF SMS + */ +uint16_t TT4_WriteSMS(sSMSInfo *pSMS) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + + pCCFile = &CCFileStruct; + + if(OpenNDEFSession(pCCFile->FileID, ASK_FOR_SESSION) == SUCCESS) + { + status = NDEF_WriteSMS ( pSMS ); + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + +/** + * @brief This fonction read NDEF file if NDEF is identified as eMail + * @param pEmailStruct : pointer on eMail structure to fill with read data + * @retval SUCCESS : eMail structure has been updated + * @retval ERROR : Not able to fill eMail structure + */ +uint16_t TT4_ReadEmail (sEmailInfo *pEmailStruct) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + sRecordInfo *pRecordStruct; + + pCCFile = &CCFileStruct; + pRecordStruct = &RecordStruct; + + + if(OpenNDEFSession(pCCFile->FileID, ASK_FOR_SESSION) == SUCCESS) + { + if(NDEF_IdentifyNDEF( pRecordStruct, NDEF_Buffer) == SUCCESS) + { + status = NDEF_ReadEmail(pRecordStruct, pEmailStruct); + } + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + +/** + * @brief This fonction write NDEF file from data given in the eMail structure + * @param pEmailStruct : pointer on eMail structure to prepare NDEF + * @retval SUCCESS : NDEF eMail stored + * @retval ERROR : Not able to store NDEF eMail + */ +uint16_t TT4_WriteEmail(sEmailInfo *pEmailStruct) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + + pCCFile = &CCFileStruct; + + if(OpenNDEFSession(pCCFile->FileID, ASK_FOR_SESSION) == SUCCESS) + { + status = NDEF_WriteEmail ( pEmailStruct ); + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + +/** + * @brief This fonction read NDEF file if NDEF is identified as Vcard + * @param pVcard : pointer on Vcard structure to fill with read data + * @retval SUCCESS : Vcard structure has been updated + * @retval ERROR : Not able to fill Vcard structure + */ +uint16_t TT4_ReadVcard(sVcardInfo *pVcard) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + sRecordInfo *pRecordStruct; + + pCCFile = &CCFileStruct; + pRecordStruct = &RecordStruct; + + + if(OpenNDEFSession(pCCFile->FileID, ASK_FOR_SESSION) == SUCCESS) + { + if(NDEF_IdentifyNDEF( pRecordStruct, NDEF_Buffer) == SUCCESS) + { + status = NDEF_ReadVcard(pRecordStruct, pVcard); + } + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + +/** + * @brief This fonction write NDEF file from data given in the Vcard structure + * @param pVcard : pointer on Vcard structure to prepare NDEF + * @retval SUCCESS : NDEF Vcard stored + * @retval ERROR : Not able to store NDEF Vcard + */ +uint16_t TT4_WriteVcard(sVcardInfo *pVcard) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + + pCCFile = &CCFileStruct; + + if(OpenNDEFSession(pCCFile->FileID, ASK_FOR_SESSION) == SUCCESS) + { + status = NDEF_WriteVcard ( pVcard ); + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + +/** + * @brief This fonction read NDEF file if NDEF is identified as geolocation information + * @param pGeo : pointer on geo structure to fill with read data + * @retval SUCCESS : geo structure has been updated + * @retval ERROR : Not able to fill geo structure + */ +uint16_t TT4_ReadGeo(sGeoInfo *pGeo) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + sRecordInfo *pRecordStruct; + + pCCFile = &CCFileStruct; + pRecordStruct = &RecordStruct; + + if(OpenNDEFSession(pCCFile->FileID, ASK_FOR_SESSION) == SUCCESS) + { + if(NDEF_IdentifyNDEF( pRecordStruct, NDEF_Buffer) == SUCCESS) + { + status = NDEF_ReadGeo(pRecordStruct, pGeo); + } + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + +/** + * @brief This fonction write NDEF file from data given in the geo structure + * @param pGeo : pointer on geo structure to prepare NDEF + * @retval SUCCESS : NDEF geo stored + * @retval ERROR : Not able to store NDEF geo + */ +uint16_t TT4_WriteGeo(sGeoInfo *pGeo) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + + pCCFile = &CCFileStruct; + + if(OpenNDEFSession(pCCFile->FileID, ASK_FOR_SESSION) == SUCCESS) + { + status = NDEF_WriteGeo ( pGeo ); + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + +/** + * @brief This fonction read NDEF file if NDEF is identified as expected private application + * @param pMyAppStruct : pointer on structure to fill with read data + * @retval SUCCESS : structure has been updated + * @retval ERROR : Not able to fill structure + */ +uint16_t TT4_ReadMyApp(sMyAppInfo *pMyAppStruct) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + sRecordInfo *pRecordStruct; + + pCCFile = &CCFileStruct; + pRecordStruct = &RecordStruct; + + + if(OpenNDEFSession(pCCFile->FileID, TAKE_SESSION) == SUCCESS) + { + if(NDEF_IdentifyNDEF( pRecordStruct, NDEF_Buffer) == SUCCESS) + { + status = NDEF_ReadMyApp(pRecordStruct, pMyAppStruct); + } + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + +/** + * @brief This fonction write NDEF file from data given in the structure + * @param pMyAppStruct : pointer on structure to prepare NDEF + * @retval SUCCESS : NDEF stored + * @retval ERROR : Not able to store NDEF + */ +uint16_t TT4_WriteMyApp(sMyAppInfo *pMyAppStruct) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + + pCCFile = &CCFileStruct; + + if(OpenNDEFSession(pCCFile->FileID, ASK_FOR_SESSION) == SUCCESS) + { + status = NDEF_WriteMyApp ( pMyAppStruct ); + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + +/** + * @brief This fonction add AAR (Android Application Record) in the tag + * @param pAAR : pointer on structure that contain AAR information + * @retval SUCCESS : AAR added + * @retval ERROR : Not able to add AAR + */ +uint16_t TT4_AddAAR(sAARInfo *pAAR) +{ + uint16_t status = ERROR; + sCCFileInfo *pCCFile; + + pCCFile = &CCFileStruct; + + if(OpenNDEFSession(pCCFile->FileID, ASK_FOR_SESSION) == SUCCESS) + { + status = NDEF_AddAAR ( pAAR ); + CloseNDEFSession(pCCFile->FileID); + } + + return status; +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/ +
diff -r 000000000000 -r 3b093bd0819e lib_TagType4.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_TagType4.h Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,97 @@ +/** + ****************************************************************************** + * @file lib_TagType4.h + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to manage TagType4. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> + * + * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LIB_TAGTYPE4_H +#define __LIB_TAGTYPE4_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "lib_NDEF_URI.h" +#include "lib_NDEF_SMS.h" +#include "lib_NDEF_Email.h" +#include "lib_NDEF_Vcard.h" +#include "lib_NDEF_Geo.h" +#include "lib_NDEF_MyApp.h" +#include "lib_NDEF_AAR.h" + +typedef struct +{ + uint16_t NumberCCByte; + uint8_t Version; + uint16_t MaxReadByte; + uint16_t MaxWriteByte; + uint8_t TField; + uint8_t LField; + uint16_t FileID; + uint16_t NDEFFileMaxSize; + uint8_t ReadAccess; + uint8_t WriteAccess; +}sCCFileInfo; + +typedef enum +{ + UNKNOWN_TAG = 0, + VCARD_TAG, + URI_TAG, + SMS_TAG, + GEO_TAG, + EMAIL_TAG, + TEXT_TAG, + BT_TAG, + WIFI_TAG +} Tag_TypeDef; + + +uint16_t TT4_Init( void ); +uint16_t TT4_ReadNDEF(uint8_t *pNDEF); +uint16_t TT4_WriteNDEF(uint8_t *pNDEF); +uint16_t TT4_ReadURI(sURI_Info *pURI); +uint16_t TT4_WriteURI(sURI_Info *pURI); +uint16_t TT4_ReadSMS(sSMSInfo *pSMS); +uint16_t TT4_WriteSMS(sSMSInfo *pSMS); +uint16_t TT4_ReadEmail(sEmailInfo *pEmailStruct); +uint16_t TT4_WriteEmail(sEmailInfo *pEmailStruct); +uint16_t TT4_ReadVcard(sVcardInfo *pVcard); +uint16_t TT4_WriteVcard(sVcardInfo *pVcard); +uint16_t TT4_ReadGeo(sGeoInfo *pGeo); +uint16_t TT4_WriteGeo(sGeoInfo *pGeo); +uint16_t TT4_ReadMyApp(sMyAppInfo *pMyAppStruct); +uint16_t TT4_WriteMyApp(sMyAppInfo *pMyAppStruct); +uint16_t TT4_AddAAR(sAARInfo *pAAR); + +#ifdef __cplusplus +} +#endif + +#endif /* __LIB_TAGTYPE4_H */ + + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r 3b093bd0819e lib_wrapper.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_wrapper.h Mon Dec 15 19:41:36 2014 +0000 @@ -0,0 +1,63 @@ +/** + ****************************************************************************** + * @file lib_wrapper.h + * @author MMY Application Team + * @version V1.0.0 + * @date 20-November-2013 + * @brief This file help to have upper layer independent from HW + ****************************************************************************** + * @attention + * + * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS + * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE + * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY + * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING + * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + * + * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2> + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LIB_WRAPPER_H +#define __LIB_WRAPPER_H + +/* Includes ------------------------------------------------------------------*/ +#include "lib_M24SR.h" + + +/* The maximum size of a NDEF will be 64kBits with M24SR64 */ +/* if smaller memory used update this define to save space */ +#define NDEF_MAX_SIZE M24SR16_NDEF_MAX_SIZE + +#define NDEF_ACTION_COMPLETED M24SR_ACTION_COMPLETED + + +/* Wrapper to have upper layer independent from HW */ +#define TagT4Init M24SR_Initialization + +#define GetNDEFFileId M24SR_GetNDEFFileId +#define OpenNDEFSession M24SR_OpenNDEFSession +#define CloseNDEFSession M24SR_CloseNDEFSession + +#define ReadData M24SR_ReadData +#define ForceReadData M24SR_ForceReadData +#define WriteData M24SR_WriteData + +#define EnableReadPassword M24SR_EnableReadPassword +#define DisableReadPassword M24SR_DisableReadPassword +#define EnableWritePassword M24SR_EnableWritePassword +#define DisableWritePassword M24SR_DisableWritePassword +#define DisableAllPassword M24SR_DisableAllPassword + +#define EnableReadOnly M24SR_EnableReadOnly +#define DisableReadOnly M24SR_DisableReadOnly +#define EnableWriteOnly M24SR_EnableWriteOnly +#define DisableWriteOnly M24SR_DisableWriteOnly +#define GPO_Config M24SR_ManageGPO + +#endif /* __LIB_WRAPPER_H */ + + +/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/