Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2010 NXP Semiconductors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /**
     18  * \file  phFriNfc_LlcpUtils.h
     19  * \brief NFC LLCP utils
     20  *
     21  * Project: NFC-FRI
     22  *
     23  */
     24 
     25 #ifndef PHFRINFC_LLCPUTILS_H
     26 #define PHFRINFC_LLCPUTILS_H
     27 
     28 /*include files*/
     29 #include <phNfcHalTypes.h>
     30 #include <phNfcTypes.h>
     31 #include <phNfcStatus.h>
     32 #include <phFriNfc.h>
     33 #include <phFriNfc_Llcp.h>
     34 
     35 /**
     36  * \name NFC Forum Logical Link Control Protocol Utils
     37  *
     38  * File: \ref phFriNfc_LlcpUtils.h
     39  *
     40  */
     41 
     42 /**
     43  * UTIL_FIFO_BUFFER - A Cyclic FIFO buffer
     44  * If pIn == pOut the buffer is empty.
     45  */
     46 typedef struct UTIL_FIFO_BUFFER
     47 {
     48    uint8_t          *pBuffStart;    /* Points to first valid location in buffer */
     49    uint8_t          *pBuffEnd;      /* Points to last valid location in buffer */
     50    volatile uint8_t *pIn;           /* Points to 1 before where the next TU1 will enter buffer */
     51    volatile uint8_t *pOut;          /* Points to 1 before where the next TU1 will leave buffer */
     52    volatile bool_t  bFull;         /* TRUE if buffer is full */
     53 }UTIL_FIFO_BUFFER, *P_UTIL_FIFO_BUFFER;
     54 
     55 
     56 /** \defgroup grp_fri_nfc_llcp NFC Forum Logical Link Control Protocol Component
     57  *
     58  *  TODO
     59  *
     60  */
     61 
     62 NFCSTATUS phFriNfc_Llcp_DecodeTLV( phNfc_sData_t  *psRawData,
     63                                    uint32_t       *pOffset,
     64                                    uint8_t        *pType,
     65                                    phNfc_sData_t  *psValueBuffer );
     66 
     67 NFCSTATUS phFriNfc_Llcp_EncodeTLV( phNfc_sData_t  *psValueBuffer,
     68                                    uint32_t       *pOffset,
     69                                    uint8_t        type,
     70                                    uint8_t        length,
     71                                    uint8_t        *pValue);
     72 
     73 NFCSTATUS phFriNfc_Llcp_AppendTLV( phNfc_sData_t  *psValueBuffer,
     74                                    uint32_t       nTlvOffset,
     75                                    uint32_t       *pCurrentOffset,
     76                                    uint8_t        length,
     77                                    uint8_t        *pValue);
     78 
     79 void phFriNfc_Llcp_EncodeMIUX(uint16_t pMiux,
     80                               uint8_t* pMiuxEncoded);
     81 
     82 void phFriNfc_Llcp_EncodeRW(uint8_t *pRw);
     83 
     84 /**
     85  * Initializes a Fifo Cyclic Buffer to point to some allocated memory.
     86  */
     87 void phFriNfc_Llcp_CyclicFifoInit(P_UTIL_FIFO_BUFFER     sUtilFifo,
     88                                   const uint8_t        *pBuffStart,
     89                                   uint32_t             buffLength);
     90 
     91 /**
     92  * Clears the Fifo Cyclic Buffer - loosing any data that was in it.
     93  */
     94 void phFriNfc_Llcp_CyclicFifoClear(P_UTIL_FIFO_BUFFER sUtilFifo);
     95 
     96 
     97 /**
     98  * Attempts to write dataLength bytes to the specified Fifo Cyclic Buffer.
     99  */
    100 uint32_t phFriNfc_Llcp_CyclicFifoWrite(P_UTIL_FIFO_BUFFER     sUtilFifo,
    101                                        uint8_t              *pData,
    102                                        uint32_t             dataLength);
    103 
    104 /**
    105  * Attempts to read dataLength bytes from the specified  Fifo Cyclic Buffer.
    106  */
    107 uint32_t phFriNfc_Llcp_CyclicFifoFifoRead(P_UTIL_FIFO_BUFFER     sUtilFifo,
    108                                           uint8_t              *pBuffer,
    109                                           uint32_t             dataLength);
    110 
    111 /**
    112  * Returns the number of bytes currently stored in Fifo Cyclic Buffer.
    113  */
    114 uint32_t phFriNfc_Llcp_CyclicFifoUsage(P_UTIL_FIFO_BUFFER sUtilFifo);
    115 
    116 /**
    117  * Returns the available room for writing in Fifo Cyclic Buffer.
    118  */
    119 uint32_t phFriNfc_Llcp_CyclicFifoAvailable(P_UTIL_FIFO_BUFFER sUtilFifo);
    120 
    121 uint32_t phFriNfc_Llcp_Header2Buffer( phFriNfc_Llcp_sPacketHeader_t *psHeader,
    122                                       uint8_t *pBuffer,
    123                                       uint32_t nOffset );
    124 
    125 uint32_t phFriNfc_Llcp_Sequence2Buffer( phFriNfc_Llcp_sPacketSequence_t *psSequence,
    126                                         uint8_t *pBuffer,
    127                                         uint32_t nOffset );
    128 
    129 uint32_t phFriNfc_Llcp_Buffer2Header( uint8_t *pBuffer,
    130                                       uint32_t nOffset,
    131                                       phFriNfc_Llcp_sPacketHeader_t *psHeader );
    132 
    133 uint32_t phFriNfc_Llcp_Buffer2Sequence( uint8_t *pBuffer,
    134                                         uint32_t nOffset,
    135                                         phFriNfc_Llcp_sPacketSequence_t *psSequence );
    136 
    137 
    138 #endif /* PHFRINFC_LLCPUTILS_H */
    139