1a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly/* 2a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * Copyright (C) 2010 NXP Semiconductors 3a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 4a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * Licensed under the Apache License, Version 2.0 (the "License"); 5a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * you may not use this file except in compliance with the License. 6a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * You may obtain a copy of the License at 7a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 8a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * http://www.apache.org/licenses/LICENSE-2.0 9a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 10a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * Unless required by applicable law or agreed to in writing, software 11a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * distributed under the License is distributed on an "AS IS" BASIS, 12a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * See the License for the specific language governing permissions and 14a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * limitations under the License. 15a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly */ 16a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 17a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly/*! 18a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \file phFriNfc_NdefRecord.c 19a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \brief NFC Ndef Record component file. 20a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 21a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * Project: NFC-FRI 22a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 23a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * $Date: Thu Jun 25 11:01:24 2009 $ 24a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * $Author: ing07336 $ 25a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * $Revision: 1.4 $ 26a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * $Aliases: NFC_FRI1.1_WK926_R28_1,NFC_FRI1.1_WK928_R29_1,NFC_FRI1.1_WK930_R30_1,NFC_FRI1.1_WK934_PREP_1,NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $ 27a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 28a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly */ 29a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 30a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 31a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly/*! \ingroup grp_file_attributes 32a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \name \name NDEF Record Tools Header 33a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 34a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * File: \ref phFriNfc_NdefRecord.h 35a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 36a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly */ 37a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly/*@{*/ 38a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly#define PHFRINFCNDEFRECORD_FILEREVISION "$Revision: 1.4 $" 39a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly#define PHFRINFCNDEFRECORD_FILEALIASES "$Aliases: NFC_FRI1.1_WK926_R28_1,NFC_FRI1.1_WK928_R29_1,NFC_FRI1.1_WK930_R30_1,NFC_FRI1.1_WK934_PREP_1,NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $" 40a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly/*@}*/ 41a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 42a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly#include <phFriNfc_NdefRecord.h> 43a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly#include <phNfcCompId.h> 44a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly#include <stdlib.h> 45a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 46a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly/* Harsha: To Fix: 0000358: phFriNfc_NdefRecord.h: includes should be moved */ 47a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly#include <string.h> 48a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 49a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 50a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly/*! 51a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 52a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * Get a specific NDEF record from the data, provided by the caller. The data is a buffer holding 53a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * one or more (nested) NDEF records within a NDEF packet (received via the NFC link, for example). 54a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 55a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \param[in] Buffer The data buffer holding the NDEF Message, as provided by the caller. 56a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \param[in] BufferLength The data length, as provided by the caller. 57a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \param[in,out] RawRecords Array of pointers, receiving the references to the found Ndef Records 58a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * in the Message. The caller has to provide the array of pointers. 59a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * The array is filled with valid pointers up to the number of records 60a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * found or the array size if the number of found records exceeds the size. 61a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * If the value is NULL the function only yields the number of records 62a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * without filling in pointers. 63a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \param[in] IsChunked This boolean tells the user that the record of a certain position within 64a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * an array has the CHUNKED flag set (is a partial record). The number 65a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * of caller-provided array positions has to be the same as "NumberOfRawRecords". 66a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * In case that this parameter is NULL the function ignores it. 67a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \param[in,out] NumberOfRawRecords Length of the Record pointer array. The caller has to provide 68a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * the number of pointers provided in the NDEF Type array. \n 69a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * The value is set by the extracting function to the actual number of 70a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * records found in the data. If the user specifies 0 (zero) the function 71a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * only yields the number of records without filling in pointers.\n 72a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * The value of NULL is invalid. 73a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 74a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \retval NFCSTATUS_SUCCESS Operation successful. 75a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid. 76a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 77a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \note The correct number of found records is returned by the function also in case that: 78a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * - The "RawRecords" array is too short to hold all values: It is filled up to the allowed maximum. 79a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * - The "RawRecords" array is NULL: Only the number is returned. 80a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * - The "NumberOfRawRecords" parameter is 0 (zero): The array is not filled, just the number is returned. 81a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * . 82a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * This can be exploited for targeted memory allocation: Specify NULL for "RawRecords" and/or 83a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 0 (zero) for "NumberOfRawRecords" and the function yields the correct array size to allocate 84a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * for a second call. 85a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 86a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly */ 87a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS phFriNfc_NdefRecord_GetRecords( uint8_t *Buffer, 88a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint32_t BufferLength, 89a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t *RawRecords[], 90a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t IsChunked[], 91a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint32_t *NumberOfRawRecords) 92a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly{ 93a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS Status = NFCSTATUS_SUCCESS; 94a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t PayloadLengthByte = 0, 95a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly TypeLengthByte = 0, 96a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly TypeLength = 0, 97a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly IDLengthByte = 0, 98a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NoOfRecordsReturnFlag = 0, 99a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly IDLength = 0; 100a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint32_t Count = 0, 101a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PayloadLength = 0, 102a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly BytesTraversed = 0; 103a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 104a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Validate the input parameters */ 105a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (Buffer == NULL || BufferLength == 0 || NumberOfRawRecords == NULL) 106a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 107a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 108a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_PARAMETER); 109a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 110a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 111a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 112a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if((*NumberOfRawRecords) > 0) 113a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 114a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* The number of caller-provided array positions for the array IsChunked 115a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly has to be the same as NumberOfRawRecords. Hence, 116a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if NumberOfRawRecords > 0, the array IsChunked cannot be null */ 117a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(IsChunked == NULL) 118a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 119a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 120a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_PARAMETER); 121a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 122a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 123a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 124a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 125a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check Raw Records input is NULL and Number of Raw records is 0*/ 126a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ( RawRecords == NULL || *NumberOfRawRecords == 0) 127a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 128a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* This flag is set, to return only number of records 129a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly this is done when the Raw Records is NULL or 130a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Number of Raw records is 0 */ 131a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NoOfRecordsReturnFlag = 1; 132a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 133a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 134a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check for the MB bit*/ 135a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Buffer & PH_FRINFC_NDEFRECORD_FLAGS_MB) != 136a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_FLAGS_MB ) 137a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 138a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* MB Error */ 139a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 140a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 141a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 142a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Number of valid records found in the message is 0 */ 143a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *NumberOfRawRecords = 0; 144a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 145a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 146a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 147a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check for Tnf bits 0x07 is reserved for future use */ 148a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Buffer & PH_FRINFC_NDEFRECORD_TNFBYTE_MASK) == 149a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_TNF_RESERVED) 150a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 151a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* TNF 07 Error */ 152a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 153a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 154a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Number of valid records found in the message is 0 */ 155a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *NumberOfRawRecords = 0; 156a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 157a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 158a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 159a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check the First Record(MB = 0) for TNF = 0x06(Unchanged) */ 160a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Buffer & PH_FRINFC_NDEFRECORD_FLAGS_MB) == PH_FRINFC_NDEFRECORD_FLAGS_MB && 161a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly (*Buffer & PH_FRINFC_NDEFRECORD_TNF_UNCHANGED) == PH_FRINFC_NDEFRECORD_TNF_UNCHANGED) 162a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 163a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 164a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 165a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Number of valid records found in the message is 0 */ 166a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *NumberOfRawRecords = 0; 167a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 168a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 169a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 170a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* First Record i.e., MB = 1, TNF != 0x05 and TypeLength = 0 */ 171a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ( (*Buffer & PH_FRINFC_NDEFRECORD_FLAGS_MB) == PH_FRINFC_NDEFRECORD_FLAGS_MB && 172a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly (*Buffer & PH_FRINFC_NDEFRECORD_TNFBYTE_MASK) != PH_FRINFC_NDEFRECORD_TNF_UNKNOWN && 173a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly (*Buffer & PH_FRINFC_NDEFRECORD_TNFBYTE_MASK) != PH_FRINFC_NDEFRECORD_TNF_EMPTY && 174a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *(Buffer + 1) == 0) 175a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 176a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 177a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 178a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Number of valid records found in the message is 0 */ 179a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *NumberOfRawRecords = 0; 180a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 181a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 182a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 183a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check till Buffer Length exceeds */ 184a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly while ( BytesTraversed < BufferLength ) 185a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 186a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (Buffer == NULL) 187a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 188a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 189a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 190a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 191a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* For Each Record Check whether it contains the ME bit set and CF bit Set 192a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if YES return ERROR*/ 193a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Buffer & PH_FRINFC_NDEFRECORD_FLAGS_CF) == 194a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_FLAGS_CF && 195a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly (*Buffer & PH_FRINFC_NDEFRECORD_FLAGS_ME) == 196a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_FLAGS_ME) 197a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 198a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* CF and ME Error */ 199a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 200a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 201a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 202a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 203a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 204a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (NoOfRecordsReturnFlag == 0) 205a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 206a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Harsha: Fix for 0000241: [gk], NDEF Tools: GetRecords() overshoots 207a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly a given array boundary if the number of records != 0. */ 208a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Actual Number of Records should not exceed Number of records 209a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly required by caller*/ 210a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(Count >= *NumberOfRawRecords) 211a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 212a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 213a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 214a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* To fix the mantis entry 0388 */ 215a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if((Buffer != NULL)&&(RawRecords!=NULL))/*QMOR FIX*/ 216a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 217a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly RawRecords[Count] = Buffer; 218a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 219a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 220a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 221a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 222a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_PARAMETER); 223a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 224a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 225a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 226a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 227a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* To Calculate the IDLength and PayloadLength for 228a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly short or normal record */ 229a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = phFriNfc_NdefRecord_RecordIDCheck ( Buffer, 230a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly &TypeLength, 231a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly &TypeLengthByte, 232a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly &PayloadLengthByte, 233a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly &PayloadLength, 234a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly &IDLengthByte, 235a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly &IDLength); 236a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (Status != NFCSTATUS_SUCCESS) 237a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 238a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 239a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 240a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 241a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check for the Chunk Flag */ 242a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (NoOfRecordsReturnFlag == 0) 243a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 244a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* If NoOfRecordsReturnFlag = 0, that means we have enough space */ 245a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* in the array IsChunked, to write */ 246a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Buffer & PH_FRINFC_NDEFRECORD_FLAGS_CF) == 247a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_FLAGS_CF) 248a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 249a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly IsChunked [Count] = PHFRINFCNDEFRECORD_CHUNKBIT_SET; 250a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 251a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 252a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 253a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly IsChunked [Count] = PHFRINFCNDEFRECORD_CHUNKBIT_SET_ZERO; 254a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 255a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 256a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 257a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check the record is not the first record */ 258a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (Count > 0) 259a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 260a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Not a first record, if chunk record is present and IL bit is set 261a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly also if the MB bit is set */ 262a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(((*Buffer & PH_FRINFC_NDEFRECORD_FLAGS_CF) == PH_FRINFC_NDEFRECORD_FLAGS_CF && 263a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly (*Buffer & PH_FRINFC_NDEFRECORD_FLAGS_IL) == PH_FRINFC_NDEFRECORD_FLAGS_IL && 264a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly (*Buffer & PH_FRINFC_NDEFRECORD_TNFBYTE_MASK) == PH_FRINFC_NDEFRECORD_TNF_UNCHANGED) || 265a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly (*Buffer & PH_FRINFC_NDEFRECORD_FLAGS_MB) == PH_FRINFC_NDEFRECORD_FLAGS_MB) 266a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 267a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* IL or MB Error */ 268a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 269a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 270a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 271a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 272a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 273a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check for the Chunk Flag */ 274a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (NoOfRecordsReturnFlag == 0) 275a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 276a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* If NoOfRecordsReturnFlag = 0, that means the array IsChunked 277a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly contains valid values. So, cannot check the value 278a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly of IsChunked if NoOfRecordsReturnFlag = 1. */ 279a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 280a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check whether the previous record has the chunk flag and 281a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly TNF of present record is not 0x06 */ 282a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (IsChunked [Count - 1] == PHFRINFCNDEFRECORD_CHUNKBIT_SET && 283a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly (*Buffer & PH_FRINFC_NDEFRECORD_TNFBYTE_MASK) != 284a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_TNF_UNCHANGED) 285a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 286a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* CF or TNF Error */ 287a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 288a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 289a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 290a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 291a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 292a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check whether the previous record doesnot have the chunk flag and 293a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly TNF of present record is 0x06 */ 294a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (IsChunked [Count - 1] == PHFRINFCNDEFRECORD_CHUNKBIT_SET_ZERO && 295a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly (*Buffer & PH_FRINFC_NDEFRECORD_TNFBYTE_MASK) == 296a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_TNF_UNCHANGED) 297a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 298a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* CF or TNF Error */ 299a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 300a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 301a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 302a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 303a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 304a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check for the last chunk */ 305a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (IsChunked [Count - 1] == PHFRINFCNDEFRECORD_CHUNKBIT_SET && 306a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly IsChunked [Count] == PHFRINFCNDEFRECORD_CHUNKBIT_SET_ZERO) 307a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 308a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check for the TypeLength, IDLength = 0 */ 309a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (TypeLength != 0 || IDLength != 0) 310a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 311a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* last chunk record Error */ 312a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 313a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 314a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 315a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 316a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 317a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } /* if (NoOfRecordsReturnFlag == 0) */ 318a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } /* if (Count > 0) */ 319a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 320a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Calculate the bytes already traversed. */ 321a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly BytesTraversed = (BytesTraversed + PayloadLengthByte + IDLengthByte + TypeLength 322a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly + IDLength + TypeLengthByte + PayloadLength 323a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly + PH_FRINFC_NDEFRECORD_BUF_INC1); 324a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 325a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(BytesTraversed == BufferLength) 326a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 327a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* We have reached the last record, and everything is fine. */ 328a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check for the ME Byte */ 329a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Buffer & PH_FRINFC_NDEFRECORD_FLAGS_ME) == 330a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_FLAGS_ME) 331a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 332a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Count++; 333a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 334a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 335a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 336a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 337a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Each message must have ME flag in the last record, Since 338a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly ME is not set raise an error */ 339a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 340a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 341a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 342a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 343a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 344a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 345a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 346a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Buffer Overshoot: Inconsistency in the message length 347a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly and actual value of the bytes in the message detected. 348a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Report error.*/ 349a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(BytesTraversed > BufferLength) 350a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 351a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 352a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 353a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 354a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 355a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 356a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* For Each Record Check whether it contains the ME bit set 357a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if YES return*/ 358a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Buffer & PH_FRINFC_NDEFRECORD_FLAGS_ME) == 359a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_FLAGS_ME) 360a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 361a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Count++; 362a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 363a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 364a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 365a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* +1 is for first byte */ 366a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Buffer = (Buffer + PayloadLengthByte + IDLengthByte + TypeLength 367a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly + TypeLengthByte + IDLength + PayloadLength 368a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly + PH_FRINFC_NDEFRECORD_BUF_INC1); 369a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 370a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Increment the number of valid records found in the message */ 371a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Count++; 372a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 373a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 374a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Whatever is the error, update the NumberOfRawRecords with the number 375a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly of proper records found till the error was detected in the message. */ 376a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *NumberOfRawRecords = Count; 377a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 378a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly} 379a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 380a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly/* to check the bitfields in the Flags Byte and return the status flag */ 381a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pellystatic uint8_t phFriNfc_NdefRecord_NdefFlag(uint8_t Flags,uint8_t Mask) 382a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly{ 383a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t check_flag = 0x00; 384a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly check_flag = Flags & Mask; 385a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return check_flag; 386a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly} 387a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 388a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pellyuint32_t phFriNfc_NdefRecord_GetLength(phFriNfc_NdefRecord_t *Record) 389a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly{ 390a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint32_t RecordLength=1; 391a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t FlagCheck=0; 392a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 393a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly FlagCheck=phFriNfc_NdefRecord_NdefFlag(Record->Tnf,PH_FRINFC_NDEFRECORD_TNFBYTE_MASK); 394a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Type length is present only for following TNF 395a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_TNF_NFCWELLKNOWN 396a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_TNF_MEDIATYPE 397a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_TNF_ABSURI 398a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_TNF_NFCEXT 399a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly */ 400a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 401a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* ++ is for the Type Length Byte */ 402a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly RecordLength++; 403a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if( FlagCheck != PH_FRINFC_NDEFRECORD_TNF_EMPTY && 404a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly FlagCheck != PH_FRINFC_NDEFRECORD_TNF_UNKNOWN && 405a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly FlagCheck != PH_FRINFC_NDEFRECORD_TNF_UNCHANGED ) 406a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 407a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly RecordLength += Record->TypeLength; 408a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 409a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 410a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* to check if payloadlength is 8bit or 32bit*/ 411a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly FlagCheck=phFriNfc_NdefRecord_NdefFlag(Record->Flags,PH_FRINFC_NDEFRECORD_FLAGS_SR); 412a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(FlagCheck!=0) 413a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 414a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* ++ is for the Payload Length Byte */ 415a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly RecordLength++;/* for short record*/ 416a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 417a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 418a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 419a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* + PHFRINFCNDEFRECORD_NORMAL_RECORD_BYTE is for the Payload Length Byte */ 420a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly RecordLength += PHFRINFCNDEFRECORD_NORMAL_RECORD_BYTE;/* for normal record*/ 421a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 422a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 423a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* for non empty record */ 424a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly FlagCheck=phFriNfc_NdefRecord_NdefFlag(Record->Tnf,PH_FRINFC_NDEFRECORD_TNFBYTE_MASK); 425a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(FlagCheck != PH_FRINFC_NDEFRECORD_TNF_EMPTY) 426a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 427a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly RecordLength += Record->PayloadLength; 428a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 429a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 430a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* ID and IDlength are present only if IL flag is set*/ 431a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly FlagCheck=phFriNfc_NdefRecord_NdefFlag(Record->Flags,PH_FRINFC_NDEFRECORD_FLAGS_IL); 432a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(FlagCheck!=0) 433a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 434a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly RecordLength +=Record->IdLength; 435a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* ++ is for the ID Length Byte */ 436a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly RecordLength ++; 437a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 438a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return RecordLength; 439a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly} 440a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 441a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly/*! 442a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 443a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * Extract a specific NDEF record from the data, provided by the caller. The data is a buffer holding 444a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * at least the entire NDEF record (received via the NFC link, for example). 445a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 446a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \param[out] Record The NDEF record structure. The storage for the structure has to be provided by the 447a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * caller matching the requirements for \b Extraction, as described in the compound 448a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * documentation. 449a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \param[in] RawRecord The Pointer to the buffer, selected out of the array returned by 450a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * the \ref phFriNfc_NdefRecord_GetRecords function. 451a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 452a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \retval NFCSTATUS_SUCCESS Operation successful. 453a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid. 454a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 455a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \note There are some caveats: 456a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * - The "RawRecord" Data buffer must exist at least as long as the function execution time plus the time 457a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * needed by the caller to evaluate the extracted information. No copying of the contained data is done. 458a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * - Using the "RawRecord" and "RawRecordMaxSize" parameters the function internally checks whether the 459a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * data to extract are within the bounds of the buffer. 460a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 461a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 462a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly */ 463a5086a29ed4333070c7488765c22b6d3a8eef296Nick PellyNFCSTATUS phFriNfc_NdefRecord_Parse(phFriNfc_NdefRecord_t *Record, 464a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t *RawRecord) 465a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly{ 466a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS Status = NFCSTATUS_SUCCESS; 467a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t PayloadLengthByte = 0, 468a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly TypeLengthByte = 0, 469a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly TypeLength = 0, 470a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly IDLengthByte = 0, 471a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly IDLength = 0, 472a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Tnf = 0; 473a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint32_t PayloadLength = 0; 474a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 475a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (Record == NULL || RawRecord == NULL) 476a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 477a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 478a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_PARAMETER); 479a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 480a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 481a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 482a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 483a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 484a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Calculate the Flag Value */ 485a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Record->Flags = phFriNfc_NdefRecord_RecordFlag ( RawRecord); 486a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 487a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Calculate the Type Namr format of the record */ 488a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Tnf = phFriNfc_NdefRecord_TypeNameFormat( RawRecord); 489a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(Tnf != 0xFF) 490a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 491a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Record->Tnf = Tnf; 492a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* To Calculate the IDLength and PayloadLength for short or normal record */ 493a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = phFriNfc_NdefRecord_RecordIDCheck ( RawRecord, 494a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly &TypeLength, 495a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly &TypeLengthByte, 496a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly &PayloadLengthByte, 497a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly &PayloadLength, 498a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly &IDLengthByte, 499a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly &IDLength); 500a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Record->TypeLength = TypeLength; 501a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Record->PayloadLength = PayloadLength; 502a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Record->IdLength = IDLength; 503a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly RawRecord = (RawRecord + PayloadLengthByte + IDLengthByte + TypeLengthByte + PH_FRINFC_NDEFRECORD_BUF_INC1); 504a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Record->Type = RawRecord; 505a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 506a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly RawRecord = (RawRecord + Record->TypeLength); 507a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 508a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (Record->IdLength != 0) 509a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 510a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Record->Id = RawRecord; 511a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 512a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 513a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly RawRecord = RawRecord + Record->IdLength; 514a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Record->PayloadData = RawRecord; 515a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 516a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 517a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 518a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 519a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_PARAMETER); 520a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 521a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 522a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 523a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly} 524a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 525a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 526a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 527a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly/*! 528a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * The function writes one NDEF record to a specified memory location. Called within a loop, it is possible to 529a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * write more records into a contiguous buffer, in each cycle advancing by the number of bytes written for 530a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * each record. 531a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 532a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \param[in] Record The Array of NDEF record structures to append. The structures 533a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * have to be filled by the caller matching the requirements for 534a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \b Composition, as described in the documentation of 535a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * the \ref phFriNfc_NdefRecord_t "NDEF Record" structure. 536a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \param[in] Buffer The pointer to the buffer. 537a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \param[in] MaxBufferSize The data buffer's maximum size, provided by the caller. 538a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \param[out] BytesWritten The actual number of bytes written to the buffer. This can be used by 539a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * the caller to serialise more than one record into the same buffer before 540a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * handing it over to another instance. 541a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 542a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \retval NFCSTATUS_SUCCESS Operation successful. 543a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid. 544a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * \retval NFCSTATUS_BUFFER_TOO_SMALL The data buffer, provided by the caller is to small to 545a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * hold the composed NDEF record. The existing content is not changed. 546a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly * 547a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly */ 548a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS phFriNfc_NdefRecord_Generate(phFriNfc_NdefRecord_t *Record, 549a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t *Buffer, 550a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint32_t MaxBufferSize, 551a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint32_t *BytesWritten) 552a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly{ 553a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t FlagCheck, 554a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly TypeCheck=0, 555a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *temp, 556a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly i; 557a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint32_t i_data=0; 558a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 559a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(Record==NULL ||Buffer==NULL||BytesWritten==NULL||MaxBufferSize == 0) 560a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 561a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return (PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, NFCSTATUS_INVALID_PARAMETER)); 562a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 563a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 564a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (Record->Tnf == PH_FRINFC_NDEFRECORD_TNF_RESERVED) 565a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 566a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return (PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, NFCSTATUS_INVALID_FORMAT)); 567a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 568a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 569a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* calculate the length of the record and check with the buffersize if it exceeds return */ 570a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly i_data=phFriNfc_NdefRecord_GetLength(Record); 571a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(i_data > MaxBufferSize) 572a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 573a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return (PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, NFCSTATUS_BUFFER_TOO_SMALL)); 574a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 575a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *BytesWritten = i_data; 576a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 577a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /*fill the first byte of the message(all the flags) */ 578a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /*increment the buffer*/ 579a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *Buffer = ( (Record->Flags & PH_FRINFC_NDEFRECORD_FLAG_MASK) | (Record->Tnf & PH_FRINFC_NDEFRECORD_TNFBYTE_MASK)); 580a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Buffer++; 581a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 582a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* check the TypeNameFlag for PH_FRINFC_NDEFRECORD_TNF_EMPTY */ 583a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly FlagCheck=phFriNfc_NdefRecord_NdefFlag(Record->Tnf,PH_FRINFC_NDEFRECORD_TNFBYTE_MASK); 584a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(FlagCheck == PH_FRINFC_NDEFRECORD_TNF_EMPTY) 585a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 586a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* fill the typelength idlength and payloadlength with zero(empty message)*/ 587a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly for(i=0;i<3;i++) 588a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 589a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *Buffer=PH_FRINFC_NDEFRECORD_BUF_TNF_VALUE; 590a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Buffer++; 591a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 592a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return (PHNFCSTVAL(CID_NFC_NONE, NFCSTATUS_SUCCESS)); 593a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 594a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 595a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* check the TypeNameFlag for PH_FRINFC_NDEFRECORD_TNF_RESERVED */ 596a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* TNF should not be reserved one*/ 597a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly FlagCheck=phFriNfc_NdefRecord_NdefFlag(Record->Tnf,PH_FRINFC_NDEFRECORD_TNFBYTE_MASK); 598a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(FlagCheck == PH_FRINFC_NDEFRECORD_TNF_RESERVED) 599a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 600a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return (PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, NFCSTATUS_INVALID_PARAMETER)); 601a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 602a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 603a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* check for TNF Unknown or Unchanged */ 604a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly FlagCheck=phFriNfc_NdefRecord_NdefFlag(Record->Tnf,PH_FRINFC_NDEFRECORD_TNFBYTE_MASK); 605a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(FlagCheck == PH_FRINFC_NDEFRECORD_TNF_UNKNOWN || \ 606a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly FlagCheck == PH_FRINFC_NDEFRECORD_TNF_UNCHANGED) 607a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 608a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *Buffer = PH_FRINFC_NDEFRECORD_BUF_TNF_VALUE; 609a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Buffer++; 610a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 611a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 612a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 613a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *Buffer = Record->TypeLength; 614a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Buffer++; 615a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly TypeCheck=1; 616a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 617a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 618a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* check for the short record bit if it is then payloadlength is only one byte */ 619a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly FlagCheck=phFriNfc_NdefRecord_NdefFlag(Record->Flags,PH_FRINFC_NDEFRECORD_FLAGS_SR); 620a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(FlagCheck!=0) 621a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 622a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *Buffer = (uint8_t)(Record->PayloadLength & 0x000000ff); 623a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Buffer++; 624a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 625a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 626a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 627a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* if it is normal record payloadlength is 4 byte(32 bit)*/ 628a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *Buffer = (uint8_t)((Record->PayloadLength & 0xff000000) >> PHNFCSTSHL24); 629a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Buffer++; 630a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *Buffer = (uint8_t)((Record->PayloadLength & 0x00ff0000) >> PHNFCSTSHL16); 631a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Buffer++; 632a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *Buffer = (uint8_t)((Record->PayloadLength & 0x0000ff00) >> PHNFCSTSHL8); 633a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Buffer++; 634a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *Buffer = (uint8_t)((Record->PayloadLength & 0x000000ff)); 635a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Buffer++; 636a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 637a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 638a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /*check for IL bit set(Flag), if so then IDlength is present*/ 639a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly FlagCheck=phFriNfc_NdefRecord_NdefFlag(Record->Flags,PH_FRINFC_NDEFRECORD_FLAGS_IL); 640a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(FlagCheck!=0) 641a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 642a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *Buffer=Record->IdLength; 643a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Buffer++; 644a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 645a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 646a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /*check for TNF and fill the Type*/ 647a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly temp=Record->Type; 648a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(TypeCheck!=0) 649a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 650a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly for(i=0;i<(Record->TypeLength);i++) 651a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 652a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *Buffer = *temp; 653a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Buffer++; 654a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly temp++; 655a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 656a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 657a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 658a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /*check for IL bit set(Flag), if so then IDlength is present and fill the ID*/ 659a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly FlagCheck=phFriNfc_NdefRecord_NdefFlag(Record->Flags,PH_FRINFC_NDEFRECORD_FLAGS_IL); 660a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly temp=Record->Id; 661a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if(FlagCheck!=0) 662a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 663a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly for(i=0;i<(Record->IdLength);i++) 664a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 665a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *Buffer = *temp; 666a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Buffer++; 667a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly temp++; 668a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 669a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 670a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 671a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly temp=Record->PayloadData; 672a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /*check for SR bit and then correspondingly use the payload length*/ 673a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly FlagCheck=phFriNfc_NdefRecord_NdefFlag(Record->Flags,PH_FRINFC_NDEFRECORD_FLAGS_SR); 674a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly for(i_data=0;i_data < (Record->PayloadLength) ;i_data++) 675a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 676a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *Buffer = *temp; 677a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Buffer++; 678a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly temp++; 679a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 680a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 681a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return (PHNFCSTVAL(CID_NFC_NONE, NFCSTATUS_SUCCESS)); 682a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly} 683a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 684a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly/* Calculate the Flags of the record */ 685a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pellystatic uint8_t phFriNfc_NdefRecord_RecordFlag ( uint8_t *Record) 686a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly{ 687a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t flag = 0; 688a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 689a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Record & PH_FRINFC_NDEFRECORD_FLAGS_MB) == PH_FRINFC_NDEFRECORD_FLAGS_MB ) 690a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 691a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly flag = flag | PH_FRINFC_NDEFRECORD_FLAGS_MB; 692a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 693a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Record & PH_FRINFC_NDEFRECORD_FLAGS_ME) == PH_FRINFC_NDEFRECORD_FLAGS_ME ) 694a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 695a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly flag = flag | PH_FRINFC_NDEFRECORD_FLAGS_ME; 696a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 697a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Record & PH_FRINFC_NDEFRECORD_FLAGS_CF) == PH_FRINFC_NDEFRECORD_FLAGS_CF ) 698a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 699a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly flag = flag | PH_FRINFC_NDEFRECORD_FLAGS_CF; 700a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 701a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Record & PH_FRINFC_NDEFRECORD_FLAGS_SR) == PH_FRINFC_NDEFRECORD_FLAGS_SR ) 702a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 703a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly flag = flag | PH_FRINFC_NDEFRECORD_FLAGS_SR; 704a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 705a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Record & PH_FRINFC_NDEFRECORD_FLAGS_IL) == PH_FRINFC_NDEFRECORD_FLAGS_IL ) 706a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 707a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly flag = flag | PH_FRINFC_NDEFRECORD_FLAGS_IL; 708a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 709a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return flag; 710a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly} 711a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 712a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly/* Calculate the Type Name Format for the record */ 713a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pellystatic uint8_t phFriNfc_NdefRecord_TypeNameFormat ( uint8_t *Record) 714a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly{ 715a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t tnf = 0; 716a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 717a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly switch (*Record & PH_FRINFC_NDEFRECORD_TNFBYTE_MASK) 718a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 719a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly case PH_FRINFC_NDEFRECORD_TNF_EMPTY: 720a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly tnf = PH_FRINFC_NDEFRECORD_TNF_EMPTY; 721a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 722a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 723a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly case PH_FRINFC_NDEFRECORD_TNF_NFCWELLKNOWN: 724a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly tnf = PH_FRINFC_NDEFRECORD_TNF_NFCWELLKNOWN; 725a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 726a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 727a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly case PH_FRINFC_NDEFRECORD_TNF_MEDIATYPE: 728a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly tnf = PH_FRINFC_NDEFRECORD_TNF_MEDIATYPE; 729a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 730a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 731a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly case PH_FRINFC_NDEFRECORD_TNF_ABSURI: 732a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly tnf = PH_FRINFC_NDEFRECORD_TNF_ABSURI; 733a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 734a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 735a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly case PH_FRINFC_NDEFRECORD_TNF_NFCEXT: 736a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly tnf = PH_FRINFC_NDEFRECORD_TNF_NFCEXT; 737a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 738a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 739a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly case PH_FRINFC_NDEFRECORD_TNF_UNKNOWN: 740a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly tnf = PH_FRINFC_NDEFRECORD_TNF_UNKNOWN; 741a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 742a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 743a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly case PH_FRINFC_NDEFRECORD_TNF_UNCHANGED: 744a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly tnf = PH_FRINFC_NDEFRECORD_TNF_UNCHANGED; 745a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 746a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 747a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly case PH_FRINFC_NDEFRECORD_TNF_RESERVED: 748a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly tnf = PH_FRINFC_NDEFRECORD_TNF_RESERVED; 749a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 750a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly default : 751a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly tnf = 0xFF; 752a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly break; 753a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 754a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 755a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return tnf; 756a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly} 757a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 758a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 759a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pellystatic NFCSTATUS phFriNfc_NdefRecord_RecordIDCheck ( uint8_t *Record, 760a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t *TypeLength, 761a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t *TypeLengthByte, 762a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t *PayloadLengthByte, 763a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint32_t *PayloadLength, 764a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t *IDLengthByte, 765a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly uint8_t *IDLength) 766a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly{ 767a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS Status = NFCSTATUS_SUCCESS; 768a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 769a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check for Tnf bits 0x07 is reserved for future use */ 770a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Record & PH_FRINFC_NDEFRECORD_TNFBYTE_MASK) == 771a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_TNF_RESERVED) 772a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 773a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* TNF 07 Error */ 774a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 775a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 776a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 777a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 778a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 779a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check for Type Name Format depending on the TNF, Type Length value is set*/ 780a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Record & PH_FRINFC_NDEFRECORD_TNFBYTE_MASK)== 781a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_TNF_EMPTY) 782a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 783a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *TypeLength = *(Record + PH_FRINFC_NDEFRECORD_BUF_INC1); 784a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 785a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (*(Record + PH_FRINFC_NDEFRECORD_BUF_INC1) != 0) 786a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 787a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Type Length Error */ 788a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 789a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 790a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 791a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 792a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 793a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *TypeLengthByte = 1; 794a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 795a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check for Short Record */ 796a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Record & PH_FRINFC_NDEFRECORD_FLAGS_SR) == PH_FRINFC_NDEFRECORD_FLAGS_SR) 797a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 798a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* For Short Record, Payload Length Byte is 1 */ 799a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *PayloadLengthByte = 1; 800a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* 1 for Header byte */ 801a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *PayloadLength = *(Record + *TypeLengthByte + 1); 802a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (*PayloadLength != 0) 803a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 804a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* PayloadLength Error */ 805a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 806a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 807a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 808a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 809a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 810a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 811a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 812a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* For Normal Record, Payload Length Byte is 4 */ 813a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *PayloadLengthByte = PHFRINFCNDEFRECORD_NORMAL_RECORD_BYTE; 814a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *PayloadLength = ((((uint32_t)(*(Record + PH_FRINFC_NDEFRECORD_BUF_INC2))) << PHNFCSTSHL24) + 815a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly (((uint32_t)(*(Record + PH_FRINFC_NDEFRECORD_BUF_INC3))) << PHNFCSTSHL16) + 816a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly (((uint32_t)(*(Record + PH_FRINFC_NDEFRECORD_BUF_INC4))) << PHNFCSTSHL8) + 817a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *(Record + PH_FRINFC_NDEFRECORD_BUF_INC5)); 818a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (*PayloadLength != 0) 819a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 820a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* PayloadLength Error */ 821a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 822a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 823a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 824a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 825a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 826a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 827a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check for ID Length existence */ 828a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Record & PH_FRINFC_NDEFRECORD_FLAGS_IL) == PH_FRINFC_NDEFRECORD_FLAGS_IL) 829a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 830a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Length Byte exists and it is 1 byte */ 831a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *IDLengthByte = 1; 832a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* 1 for Header byte */ 833a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *IDLength = (uint8_t)*(Record + *PayloadLengthByte + *TypeLengthByte + PH_FRINFC_NDEFRECORD_BUF_INC1); 834a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (*IDLength != 0) 835a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 836a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* IDLength Error */ 837a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 838a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 839a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 840a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 841a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 842a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 843a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 844a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *IDLengthByte = 0; 845a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *IDLength = 0; 846a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 847a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 848a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 849a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 850a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Record & PH_FRINFC_NDEFRECORD_TNFBYTE_MASK)== PH_FRINFC_NDEFRECORD_TNF_UNKNOWN 851a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly || (*Record & PH_FRINFC_NDEFRECORD_TNFBYTE_MASK) == 852a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_TNF_UNCHANGED) 853a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 854a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if (*(Record + PH_FRINFC_NDEFRECORD_BUF_INC1) != 0) 855a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 856a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Type Length Error */ 857a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_RECORD, 858a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly NFCSTATUS_INVALID_FORMAT); 859a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 860a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 861a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *TypeLength = 0; 862a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *TypeLengthByte = 1; 863a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 864a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 865a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 866a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* 1 for Header byte */ 867a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *TypeLength = *(Record + PH_FRINFC_NDEFRECORD_BUF_INC1); 868a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *TypeLengthByte = 1; 869a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 870a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 871a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check for Short Record */ 872a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Record & PH_FRINFC_NDEFRECORD_FLAGS_SR) == 873a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_FLAGS_SR) 874a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 875a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* For Short Record, Payload Length Byte is 1 */ 876a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *PayloadLengthByte = 1; 877a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* 1 for Header byte */ 878a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *PayloadLength = *(Record + *TypeLengthByte + PH_FRINFC_NDEFRECORD_BUF_INC1); 879a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 880a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 881a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 882a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* For Normal Record, Payload Length Byte is 4 */ 883a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *PayloadLengthByte = PHFRINFCNDEFRECORD_NORMAL_RECORD_BYTE; 884a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *PayloadLength = ((((uint32_t)(*(Record + PH_FRINFC_NDEFRECORD_BUF_INC2))) << PHNFCSTSHL24) + 885a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly (((uint32_t)(*(Record + PH_FRINFC_NDEFRECORD_BUF_INC3))) << PHNFCSTSHL16) + 886a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly (((uint32_t)(*(Record + PH_FRINFC_NDEFRECORD_BUF_INC4))) << PHNFCSTSHL8) + 887a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *(Record + PH_FRINFC_NDEFRECORD_BUF_INC5)); 888a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 889a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 890a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* Check for ID Length existence */ 891a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly if ((*Record & PH_FRINFC_NDEFRECORD_FLAGS_IL) == 892a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly PH_FRINFC_NDEFRECORD_FLAGS_IL) 893a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 894a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *IDLengthByte = 1; 895a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly /* 1 for Header byte */ 896a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *IDLength = (uint8_t)*(Record + *PayloadLengthByte + *TypeLengthByte + PH_FRINFC_NDEFRECORD_BUF_INC1); 897a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 898a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly else 899a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly { 900a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *IDLengthByte = 0; 901a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly *IDLength = 0; 902a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 903a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly } 904a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly return Status; 905a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly} 906a5086a29ed4333070c7488765c22b6d3a8eef296Nick Pelly 907