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_IntNdef.c
     19  * \brief NFC Ndef Internal Mapping File.
     20  *
     21  * Project: NFC-FRI
     22  *
     23  * $Date: Mon Sep 15 15:09:33 2008 $
     24  * $Author: ing08205 $
     25  * $Revision: 1.5 $
     26  * $Aliases: NFC_FRI1.1_WK838_R9_PREP2,NFC_FRI1.1_WK838_R9_1,NFC_FRI1.1_WK840_R10_PREP1,NFC_FRI1.1_WK840_R10_1,NFC_FRI1.1_WK842_R11_PREP1,NFC_FRI1.1_WK842_R11_PREP2,NFC_FRI1.1_WK842_R11_1,NFC_FRI1.1_WK844_PREP1,NFC_FRI1.1_WK844_R12_1,NFC_FRI1.1_WK846_PREP1,NFC_FRI1.1_WK846_R13_1,NFC_FRI1.1_WK848_PREP1,NFC_FRI1.1_WK848_R14_1,NFC_FRI1.1_WK850_PACK1,NFC_FRI1.1_WK851_PREP1,NFC_FRI1.1_WK850_R15_1,NFC_FRI1.1_WK902_PREP1,NFC_FRI1.1_WK902_R16_1,NFC_FRI1.1_WK904_PREP1,NFC_FRI1.1_WK904_R17_1,NFC_FRI1.1_WK906_R18_1,NFC_FRI1.1_WK908_PREP1,NFC_FRI1.1_WK908_R19_1,NFC_FRI1.1_WK910_PREP1,NFC_FRI1.1_WK910_R20_1,NFC_FRI1.1_WK912_PREP1,NFC_FRI1.1_WK912_R21_1,NFC_FRI1.1_WK914_PREP1,NFC_FRI1.1_WK914_R22_1,NFC_FRI1.1_WK914_R22_2,NFC_FRI1.1_WK916_R23_1,NFC_FRI1.1_WK918_R24_1,NFC_FRI1.1_WK920_PREP1,NFC_FRI1.1_WK920_R25_1,NFC_FRI1.1_WK922_PREP1,NFC_FRI1.1_WK922_R26_1,NFC_FRI1.1_WK924_PREP1,NFC_FRI1.1_WK924_R27_1,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 $
     27  *
     28  */
     29 
     30 #include <phFriNfc_NdefMap.h>
     31 #include <phFriNfc_IntNdefMap.h>
     32 
     33 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
     34 #include <phFriNfc_MifareULMap.h>
     35 #endif  /* PH_FRINFC_MAP_MIFAREUL_DISABLED*/
     36 
     37 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
     38 #include <phFriNfc_MifareStdMap.h>
     39 #endif  /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
     40 
     41 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
     42 #include <phFriNfc_DesfireMap.h>
     43 #endif  /* PH_FRINFC_MAP_DESFIRE_DISABLED */
     44 
     45 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
     46 #include <phFriNfc_FelicaMap.h>
     47 #endif  /* PH_FRINFC_MAP_FELICA_DISABLED */
     48 
     49 #include <phFriNfc_OvrHal.h>
     50 
     51 /*! \ingroup grp_file_attributes
     52  *  \name NDEF Mapping
     53  *
     54  * File: \ref phFri_IntNdefMap.c
     55  *       This file has functions which are used common across all the
     56  *       typ1/type2/type3/type4 tags.
     57  *
     58  */
     59 /*@{*/
     60 #define PHFRINFCNDEFMAP_FILEREVISION "$Revision: 1.5 $"
     61 #define PHFRINFCNDEFMAP_FILEALIASES  "$Aliases: NFC_FRI1.1_WK838_R9_PREP2,NFC_FRI1.1_WK838_R9_1,NFC_FRI1.1_WK840_R10_PREP1,NFC_FRI1.1_WK840_R10_1,NFC_FRI1.1_WK842_R11_PREP1,NFC_FRI1.1_WK842_R11_PREP2,NFC_FRI1.1_WK842_R11_1,NFC_FRI1.1_WK844_PREP1,NFC_FRI1.1_WK844_R12_1,NFC_FRI1.1_WK846_PREP1,NFC_FRI1.1_WK846_R13_1,NFC_FRI1.1_WK848_PREP1,NFC_FRI1.1_WK848_R14_1,NFC_FRI1.1_WK850_PACK1,NFC_FRI1.1_WK851_PREP1,NFC_FRI1.1_WK850_R15_1,NFC_FRI1.1_WK902_PREP1,NFC_FRI1.1_WK902_R16_1,NFC_FRI1.1_WK904_PREP1,NFC_FRI1.1_WK904_R17_1,NFC_FRI1.1_WK906_R18_1,NFC_FRI1.1_WK908_PREP1,NFC_FRI1.1_WK908_R19_1,NFC_FRI1.1_WK910_PREP1,NFC_FRI1.1_WK910_R20_1,NFC_FRI1.1_WK912_PREP1,NFC_FRI1.1_WK912_R21_1,NFC_FRI1.1_WK914_PREP1,NFC_FRI1.1_WK914_R22_1,NFC_FRI1.1_WK914_R22_2,NFC_FRI1.1_WK916_R23_1,NFC_FRI1.1_WK918_R24_1,NFC_FRI1.1_WK920_PREP1,NFC_FRI1.1_WK920_R25_1,NFC_FRI1.1_WK922_PREP1,NFC_FRI1.1_WK922_R26_1,NFC_FRI1.1_WK924_PREP1,NFC_FRI1.1_WK924_R27_1,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 $"
     62 /*@}*/
     63 
     64 
     65 /* \note    This function has to be called at the beginning, after creating an
     66  *          instance of \ref phFriNfc_NdefMap_t . Use this function to reset
     67  *          the instance and/or switch to a different underlying device (
     68  *          different NFC device or device mode, or different Remote Device).
     69  */
     70 
     71 
     72 #if 0
     73 NFCSTATUS phFriNfc_ChkAndParseTLV(phFriNfc_NdefMap_t    *NdefMap)
     74 {
     75     NFCSTATUS status = NFCSTATUS_PENDING;
     76 
     77     switch ( NdefMap->CardType )
     78     {
     79         #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
     80             case  PH_FRINFC_NDEFMAP_MIFARE_UL_CARD :
     81 
     82 
     83             break;
     84 #endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED */
     85 
     86 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
     87             case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD :
     88                 status = phFriNfc_Desf_ChkAndParseTLV(NdefMap,PH_FRINFC_NDEFMAP_DESF_TLV_INDEX);
     89                 return (status);
     90 
     91             break;
     92 #endif  /* PH_FRINFC_MAP_DESFIRE_DISABLED */
     93 
     94 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
     95             case  PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD :
     96             case  PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD :
     97 
     98             break;
     99 #endif  /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
    100 
    101 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
    102             case PH_FRINFC_NDEFMAP_FELICA_SMART_CARD :
    103                 ;
    104             break;
    105 #endif  /* PH_FRINFC_MAP_FELICA_DISABLED */
    106 
    107             default :
    108                 /*  Unknown card type. Return error */
    109                 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
    110                         NFCSTATUS_INVALID_REMOTE_DEVICE);
    111 
    112             break;
    113      }
    114 
    115     return ( status);
    116 }
    117 #endif
    118 
    119 NFCSTATUS phFriNfc_NdefMap_SetCardState(phFriNfc_NdefMap_t   *NdefMap,
    120                                         uint16_t             Length)
    121 {
    122     NFCSTATUS   Result = NFCSTATUS_SUCCESS;
    123     if(Length == PH_FRINFC_NDEFMAP_MFUL_VAL0)
    124     {
    125         NdefMap->CardState =(uint8_t) (((NdefMap->CardState ==
    126                         PH_NDEFMAP_CARD_STATE_READ_ONLY) ||
    127                         (NdefMap->CardState ==
    128                         PH_NDEFMAP_CARD_STATE_INVALID))?
    129                         PH_NDEFMAP_CARD_STATE_INVALID:
    130                         NdefMap->CardState);
    131     }
    132     else
    133     {
    134         switch(NdefMap->CardState)
    135         {
    136             case PH_NDEFMAP_CARD_STATE_INITIALIZED:
    137                 NdefMap->CardState =(uint8_t) ((NdefMap->CardState ==
    138                     PH_NDEFMAP_CARD_STATE_INVALID)?
    139                     NdefMap->CardState:
    140                     PH_NDEFMAP_CARD_STATE_READ_WRITE);
    141             break;
    142 
    143             case PH_NDEFMAP_CARD_STATE_READ_ONLY:
    144                 NdefMap->CardState =(uint8_t) ((NdefMap->CardState ==
    145                     PH_NDEFMAP_CARD_STATE_INVALID)?
    146                     NdefMap->CardState:
    147                     PH_NDEFMAP_CARD_STATE_READ_ONLY);
    148             break;
    149 
    150             case PH_NDEFMAP_CARD_STATE_READ_WRITE:
    151                 NdefMap->CardState =(uint8_t) ((NdefMap->CardState ==
    152                     PH_NDEFMAP_CARD_STATE_INVALID)?
    153                     NdefMap->CardState:
    154                     PH_NDEFMAP_CARD_STATE_READ_WRITE);
    155             break;
    156 
    157             default:
    158                 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
    159                 Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
    160                             NFCSTATUS_NO_NDEF_SUPPORT);
    161             break;
    162         }
    163     }
    164     Result = ((NdefMap->CardState ==
    165                 PH_NDEFMAP_CARD_STATE_INVALID)?
    166                 PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
    167                 NFCSTATUS_NO_NDEF_SUPPORT):
    168                 Result);
    169     return Result;
    170 }
    171 
    172 NFCSTATUS   phFriNfc_NdefMap_CheckSpecVersion(phFriNfc_NdefMap_t *NdefMap,
    173                                                       uint8_t VersionIndex)
    174 {
    175     NFCSTATUS status = NFCSTATUS_SUCCESS;
    176 
    177     uint8_t T3TVerNo = NdefMap->SendRecvBuf[VersionIndex];
    178 
    179     if ( T3TVerNo == 0 )
    180     {
    181         /*Return Status Error  Invalid Format*/
    182         status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_FORMAT);
    183     }
    184     else
    185     {
    186         /* calculate the major and minor version number of T3VerNo */
    187         if( (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM ==
    188                 PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(T3TVerNo ) )&&
    189             ( PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM >=
    190                 PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(T3TVerNo))) ||
    191             (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM ==
    192                 PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(T3TVerNo ) )&&
    193             ( PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM <
    194                 PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(T3TVerNo) )))
    195         {
    196             status = PHNFCSTVAL(CID_NFC_NONE,NFCSTATUS_SUCCESS);
    197         }
    198         else
    199         {
    200             if (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM <
    201                     PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(T3TVerNo) ) ||
    202                ( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM >
    203                     PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(T3TVerNo)))
    204             {
    205                 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_FORMAT);
    206             }
    207         }
    208     }
    209     return (status);
    210 }
    211