15d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*
25d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Copyright (C) 2010 NXP Semiconductors
35d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
45d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Licensed under the Apache License, Version 2.0 (the "License");
55d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * you may not use this file except in compliance with the License.
65d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * You may obtain a copy of the License at
75d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
85d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *      http://www.apache.org/licenses/LICENSE-2.0
95d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Unless required by applicable law or agreed to in writing, software
115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * distributed under the License is distributed on an "AS IS" BASIS,
125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * See the License for the specific language governing permissions and
145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * limitations under the License.
155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \file  phFriNfc_LlcpUtils.h
195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief NFC LLCP utils
205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Project: NFC-FRI
225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef PHFRINFC_LLCPUTILS_H
265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define PHFRINFC_LLCPUTILS_H
275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*include files*/
295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phNfcHalTypes.h>
305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phNfcTypes.h>
315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phNfcStatus.h>
325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phFriNfc.h>
335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phFriNfc_Llcp.h>
345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \name NFC Forum Logical Link Control Protocol Utils
375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * File: \ref phFriNfc_LlcpUtils.h
395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * UTIL_FIFO_BUFFER - A Cyclic FIFO buffer
445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * If pIn == pOut the buffer is empty.
455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellytypedef struct UTIL_FIFO_BUFFER
475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   uint8_t          *pBuffStart;    /* Points to first valid location in buffer */
495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   uint8_t          *pBuffEnd;      /* Points to last valid location in buffer */
505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   volatile uint8_t *pIn;           /* Points to 1 before where the next TU1 will enter buffer */
515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   volatile uint8_t *pOut;          /* Points to 1 before where the next TU1 will leave buffer */
525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   volatile bool_t  bFull;         /* TRUE if buffer is full */
535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}UTIL_FIFO_BUFFER, *P_UTIL_FIFO_BUFFER;
545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** \defgroup grp_fri_nfc_llcp NFC Forum Logical Link Control Protocol Component
575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *  TODO
595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_Llcp_DecodeTLV( phNfc_sData_t  *psRawData,
635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                   uint32_t       *pOffset,
645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                   uint8_t        *pType,
655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                   phNfc_sData_t  *psValueBuffer );
665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_Llcp_EncodeTLV( phNfc_sData_t  *psValueBuffer,
685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                   uint32_t       *pOffset,
695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                   uint8_t        type,
705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                   uint8_t        length,
715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                   uint8_t        *pValue);
725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
737b187e70a5f0ffc021cc06a9f1a2bf2c0f8f8767Sunil JogiNFCSTATUS phFriNfc_Llcp_AppendTLV( phNfc_sData_t  *psValueBuffer,
747b187e70a5f0ffc021cc06a9f1a2bf2c0f8f8767Sunil Jogi                                   uint32_t       nTlvOffset,
757b187e70a5f0ffc021cc06a9f1a2bf2c0f8f8767Sunil Jogi                                   uint32_t       *pCurrentOffset,
767b187e70a5f0ffc021cc06a9f1a2bf2c0f8f8767Sunil Jogi                                   uint8_t        length,
777b187e70a5f0ffc021cc06a9f1a2bf2c0f8f8767Sunil Jogi                                   uint8_t        *pValue);
787b187e70a5f0ffc021cc06a9f1a2bf2c0f8f8767Sunil Jogi
79e1c9fcfb918da43ab24f95c9341da3b6bf3b1250Jeff Hamiltonvoid phFriNfc_Llcp_EncodeMIUX(uint16_t pMiux,
80e1c9fcfb918da43ab24f95c9341da3b6bf3b1250Jeff Hamilton                              uint8_t* pMiuxEncoded);
815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid phFriNfc_Llcp_EncodeRW(uint8_t *pRw);
835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Initializes a Fifo Cyclic Buffer to point to some allocated memory.
865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid phFriNfc_Llcp_CyclicFifoInit(P_UTIL_FIFO_BUFFER     sUtilFifo,
885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                  const uint8_t        *pBuffStart,
895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                  uint32_t             buffLength);
905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Clears the Fifo Cyclic Buffer - loosing any data that was in it.
935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid phFriNfc_Llcp_CyclicFifoClear(P_UTIL_FIFO_BUFFER sUtilFifo);
955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Attempts to write dataLength bytes to the specified Fifo Cyclic Buffer.
995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
1005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyuint32_t phFriNfc_Llcp_CyclicFifoWrite(P_UTIL_FIFO_BUFFER     sUtilFifo,
1015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                       uint8_t              *pData,
1025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                       uint32_t             dataLength);
1035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
1055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Attempts to read dataLength bytes from the specified  Fifo Cyclic Buffer.
1065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
1075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyuint32_t phFriNfc_Llcp_CyclicFifoFifoRead(P_UTIL_FIFO_BUFFER     sUtilFifo,
1085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                          uint8_t              *pBuffer,
1095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                          uint32_t             dataLength);
1105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
1125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Returns the number of bytes currently stored in Fifo Cyclic Buffer.
1135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
1145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyuint32_t phFriNfc_Llcp_CyclicFifoUsage(P_UTIL_FIFO_BUFFER sUtilFifo);
1155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
1175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Returns the available room for writing in Fifo Cyclic Buffer.
1185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
1195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyuint32_t phFriNfc_Llcp_CyclicFifoAvailable(P_UTIL_FIFO_BUFFER sUtilFifo);
1205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyuint32_t phFriNfc_Llcp_Header2Buffer( phFriNfc_Llcp_sPacketHeader_t *psHeader,
1225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                      uint8_t *pBuffer,
1235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                      uint32_t nOffset );
1245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyuint32_t phFriNfc_Llcp_Sequence2Buffer( phFriNfc_Llcp_sPacketSequence_t *psSequence,
1265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        uint8_t *pBuffer,
1275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        uint32_t nOffset );
1285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyuint32_t phFriNfc_Llcp_Buffer2Header( uint8_t *pBuffer,
1305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                      uint32_t nOffset,
1315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                      phFriNfc_Llcp_sPacketHeader_t *psHeader );
1325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyuint32_t phFriNfc_Llcp_Buffer2Sequence( uint8_t *pBuffer,
1345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        uint32_t nOffset,
1355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        phFriNfc_Llcp_sPacketSequence_t *psSequence );
1365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* PHFRINFC_LLCPUTILS_H */
139