Initialize Tizen 2.3
[adaptation/devices/nfc-plugin-nxp.git] / src / phFriNfc_FelicaMap.h
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_FelicaMap.h
19  * \brief NFC Ndef Mapping For Felica Smart Card.
20  *
21  * Project: NFC-FRI
22  *
23  * $Date: Wed Apr  8 14:37:05 2009 $
24  * $Author: ing02260 $
25  * $Revision: 1.4 $
26  * $Aliases: 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 #ifndef PHFRINFC_FELICAMAP_H
31 #define PHFRINFC_FELICAMAP_H
32
33 #include <phFriNfc.h>
34 #if !defined PH_HAL4_ENABLE
35 #include <phHalNfc.h>
36 #endif
37 #include <phNfcStatus.h>
38 #include <phNfcTypes.h>
39 #include <phFriNfc_NdefMap.h>
40
41
42 #ifndef PH_FRINFC_EXCLUDE_FROM_TESTFW /* */
43
44 #define PH_FRINFC_NDEFMAP_FELICAMAP_FILEREVISION "$Revision: 1.4 $"
45 #define PH_FRINFC_NDEFMAP_FELLICAMAP_FILEALIASES  "$Aliases: 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 $"
46
47 /* NDEF Mapping - states of the Finite State machine */
48 #define PH_NFCFRI_NDEFMAP_FELI_STATE_SELECT_WILD_CARD           1 /* Select Wild Card State*/
49 #define PH_NFCFRI_NDEFMAP_FELI_STATE_SELECT_NDEF_APP            2 /* Select NFC Forum Application State*/
50 #define PH_FRINFC_NDEFMAP_FELI_STATE_CHK_NDEF                   3 /* Ndef Complient State*/
51 #define PH_NFCFRI_NDEFMAP_FELI_STATE_RD_ATTR                    4 /* Read Attribute Information State*/
52 #define PH_NFCFRI_NDEFMAP_FELI_STATE_RD_BLOCK                   5 /* Read Data state*/
53 #define PH_NFCFRI_NDEFMAP_FELI_STATE_WR_BLOCK                   6 /* Write Data State*/
54 #define PH_NFCFRI_NDEFMAP_FELI_STATE_ATTR_BLK_WR_BEGIN          7 /* Write Attrib Blk for write Begin*/
55 #define PH_NFCFRI_NDEFMAP_FELI_STATE_ATTR_BLK_WR_END            8 /* Write Attrib Blk for write End*/
56 #define PH_NFCFRI_NDEFMAP_FELI_STATE_WR_EMPTY_MSG               9 /* write Empty Ndef Msg*/
57
58
59 #define PH_NFCFRI_NDEFMAP_FELI_WR_RESP_BYTE                     0x09 /* Write Cmd Response Byte*/
60 #define PH_NFCFRI_NDEFMAP_FELI_RD_RESP_BYTE                     0x07 /* Read Cmd Response Byte*/
61
62 #define PH_NFCFRI_NDEFMAP_FELI_NMAXB                            13 /* Nmaxb Identifier*/
63 #define PH_NFCFRI_NDEFMAP_FELI_NBC                              14 /* Nbc Identifier*/    
64
65 #define PH_FRINFC_NDEFMAP_FELI_OP_NONE                          15 /* To Read the attribute information*/
66 #define PH_FRINFC_NDEFMAP_FELI_WR_ATTR_RD_OP                    16 /* To Read the attribute info. while a WR Operationg*/
67 #define PH_FRINFC_NDEFMAP_FELI_RD_ATTR_RD_OP                    17 /* To Read the attribute info. while a RD Operationg*/
68 #define PH_FRINFC_NDEFMAP_FELI_CHK_NDEF_OP                      18 /* To Process the read attribute info. while a ChkNdef Operation*/
69 #define PH_FRINFC_NDEFMAP_FELI_WR_EMPTY_MSG_OP                  19 /* To Process the Empty NDEF Msg while erasing the NDEF data*/
70
71 #define PH_FRINFC_NDEFMAP_FELI_NUM_DEVICE_TO_DETECT             1
72
73 #define PH_NFCFRI_NDEFMAP_FELI_RESP_HEADER_LEN                  13 /* To skip response code, IDm, status flgas and Nb*/
74 #define PH_NFCFRI_NDEFMAP_FELI_VERSION_INDEX                    13 /* Specifies Index of the version in Attribute Resp Buffer*/
75 #define PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX                    0 /* Specifies Index of the Packet Length*/
76
77
78 /* To Handle the EOF staus*/
79 #ifndef TRUE
80 #define TRUE                                                    1
81 #endif /* #ifndef TRUE */
82
83 #ifndef FALSE
84 #define FALSE                                                   0
85 #endif /* #ifndef FALSE */
86
87
88 /* NFC Device Major and Minor Version numbers*/
89 /* !!CAUTION!! these needs to be updated periodically.Major and Minor version numbers
90    should be compatible to the version number of currently implemented mapping document.
91     Example : NFC Device version Number : 1.0 , specifies
92               Major VNo is 1,
93               Minor VNo is 0 */ 
94 #define PH_NFCFRI_NDEFMAP_FELI_NFCDEV_MAJOR_VER_NUM             0x01 
95 #define PH_NFCFRI_NDEFMAP_FELI_NFCDEV_MINOR_VER_NUM             0x00 
96
97 /* Macros to find major and minor T3T version numbers*/
98 #define PH_NFCFRI_NDEFMAP_FELI_GET_MAJOR_T3T_VERNO(a)\
99 do\
100 {\
101     (((a) & (0xf0))>>(4))\
102 }while (0)
103
104 #define PH_NFCFRI_NDEFMAP_FELI_GET_MINOR_T3T_VERNO(a)\
105 do\
106 {\
107     ((a) & (0x0f))\
108 }while (0)
109
110
111 /* Macro for LEN Byte Calculation*/
112 #define PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(Byte1,Byte2,Byte3,DataLen)\
113 do\
114 { \
115     (DataLen) = (Byte1); \
116     (DataLen) = (DataLen) << (16);\
117     (DataLen) += (Byte2);\
118     (DataLen) = (DataLen) << (8);\
119     (DataLen) += (Byte3);\
120 }while(0)
121     
122
123                             
124
125 /* Enum for the data write operations*/
126 typedef enum
127 {
128     FELICA_WRITE_STARTED,
129     FELICA_WRITE_ENDED,
130     FELICA_EOF_REACHED_WR_WITH_BEGIN_OFFSET,
131     FELICA_EOF_REACHED_WR_WITH_CURR_OFFSET,
132     FELICA_RD_WR_EOF_CARD_REACHED,
133     FELICA_WRITE_EMPTY_MSG
134    
135 }phFriNfc_FelicaError_t;
136
137
138
139 /*!
140  * \brief \copydoc page_ovr Initiates Reading of NDEF information from the Remote Device.
141  *
142  * The function initiates the reading of NDEF information from a Remote Device.
143  * It performs a reset of the state and starts the action (state machine).
144  * A periodic call of the \ref phFriNfc_NdefMap_Process has to be done once the action
145  * has been triggered.
146  *
147  * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
148  *                    the component context.
149  *
150  * \param[in] PacketData  Pointer to a location that receives the NDEF Packet.
151  *
152  * \param[in,out] PacketDataLength Pointer to a variable receiving the length of the NDEF packet.
153  *
154  * \param[in] Offset Indicates whether the read operation shall start from the begining of the
155  *            file/card storage \b or continue from the last offset. The last Offset set is stored
156  *            within a context variable (must not be modified by the integration).
157  *            If the caller sets the value to \ref PH_FRINFC_NDEFMAP_SEEK_CUR, the component shall
158  *            start reading from the last offset set (continue where it has stopped before).
159  *            If set to \ref PH_FRINFC_NDEFMAP_SEEK_BEGIN, the component shall start reading
160  *            from the begining of the card (restarted) 
161  *
162  * \retval NFCSTATUS_PENDING                       The action has been successfully triggered.
163  * \retval NFCSTATUS_INVALID_DEVICE_REQUEST        If Previous Operation is Write Ndef and Offset
164  *                                                 is Current then this error is displayed.
165  * \retval NFCSTATUS_EOF_NDEF_CONTAINER_REACHED         No Space in the File to read.
166  * \retval NFCSTATUS_SUCCESS                       Last Byte of the card read.
167  * \retval NFCSTATUS_INVALID_DEVICE                The device has not been opened or has been disconnected
168  *                                                 meanwhile.
169  * \retval NFCSTATUS_CMD_ABORTED                   The caller/driver has aborted the request.
170  * \retval NFCSTATUS_RF_TIMEOUT                    No data has been received within the TIMEOUT period.
171  *
172  */
173
174 NFCSTATUS phFriNfc_Felica_RdNdef(  phFriNfc_NdefMap_t  *NdefMap,
175                                     uint8_t             *PacketData,
176                                     uint32_t            *PacketDataLength,
177                                     uint8_t             Offset);
178
179 /*!
180  * \brief \copydoc page_ovr Initiates Writing of NDEF information to the Remote Device.
181  *
182  * The function initiates the writing of NDEF information to a Remote Device.
183  * It performs a reset of the state and starts the action (state machine).
184  * A periodic call of the \ref phFriNfc_NdefMap_Process has to be done once the action
185  * has been triggered.
186  *
187  * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
188  *                    the component context.
189  *
190  * \param[in] PacketData  Pointer to a location that holds the prepared NDEF Packet.
191  *
192  * \param[in,out] PacketDataLength Variable specifying the length of the prepared NDEF packet.
193  *
194  * \param[in] Offset Indicates whether the write operation shall start from the begining of the
195  *            file/card storage \b or continue from the last offset. The last Offset set is stored
196  *            within a context variable (must not be modified by the integration).
197  *            If the caller sets the value to \ref PH_FRINFC_NDEFMAP_SEEK_CUR, the component shall
198  *            start writing from the last offset set (continue where it has stopped before).
199  *            If set to \ref PH_FRINFC_NDEFMAP_SEEK_BEGIN, the component shall start writing
200  *            from the begining of the card (restarted) 
201  *
202  * \retval NFCSTATUS_PENDING                        The action has been successfully triggered.
203  * \retval NFCSTATUS_INVALID_DEVICE_REQUEST         If Previous Operation is Write Ndef and Offset
204  *                                                  is Current then this error is displayed.
205  * \retval NFCSTATUS_EOF_NDEF_CONTAINER_REACHED               Last byte is written to the card after this
206  *                                                  no further writing is possible.
207  * \retval NFCSTATUS_SUCCESS                        Buffer provided by the user is completely written
208  *                                                  into the card.
209  * \retval NFCSTATUS_INVALID_DEVICE                 The device has not been opened or has been disconnected
210  *                                                  meanwhile.
211  * \retval NFCSTATUS_CMD_ABORTED                    The caller/driver has aborted the request.
212  * \retval NFCSTATUS_RF_TIMEOUT                     No data has been received within the TIMEOUT period.
213  *
214  */
215
216 NFCSTATUS phFriNfc_Felica_WrNdef(  phFriNfc_NdefMap_t  *NdefMap,
217                                     uint8_t             *PacketData,
218                                     uint32_t            *PacketDataLength,
219                                     uint8_t             Offset);
220
221 /*!
222  * \brief \copydoc page_ovr Initiates Writing of Empty NDEF information to the Remote Device.
223  *
224  * The function initiates the erasing of NDEF information to a Remote Device.
225  * It performs a reset of the state and starts the action (state machine).
226  * A periodic call of the \ref phFriNfc_NdefMap_Process has to be done once the action
227  * has been triggered.
228  *
229  * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
230  *                    the component context.
231  *
232  * \retval NFCSTATUS_PENDING                        The action has been successfully triggered.
233  * \retval NFCSTATUS_SUCCESS                        Empty msessage is completely written
234  *                                                  into the card.
235  * \retval NFCSTATUS_INVALID_DEVICE                 The device has not been opened or has been disconnected
236  *                                                  meanwhile.
237  * \retval NFCSTATUS_CMD_ABORTED                    The caller/driver has aborted the request.
238  * \retval NFCSTATUS_RF_TIMEOUT                     No data has been received within the TIMEOUT period.
239  *
240  */
241
242 NFCSTATUS phFriNfc_Felica_EraseNdef(  phFriNfc_NdefMap_t  *NdefMap);
243                                 
244
245 /*!
246  * \brief \copydoc page_ovr Check whether a particulat Remote Device is NDEF compliant.
247  *
248  * The function checks whether the peer device is NDEF compliant.
249  *
250  * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
251  *                    the component context.
252  *
253  * \retval NFCSTATUS_PENDING               The action has been successfully triggered.
254  * \retval NFCSTATUS_INVALID_PARAMETER     At least one parameter of the function is invalid.
255  * \retval NFCSTATUS_INVALID_DEVICE         The device has not been opened or has been disconnected
256  *                                          meanwhile.
257  * \retval NFCSTATUS_CMD_ABORTED            The caller/driver has aborted the request.
258  * \retval NFCSTATUS_RF_TIMEOUT             No data has been received within the TIMEOUT period.
259  *
260  */
261
262 NFCSTATUS phFriNfc_Felica_ChkNdef( phFriNfc_NdefMap_t     *NdefMap);
263
264 /*!
265  * \brief \copydoc page_cb Completion Routine, Processing function, needed to avoid long blocking.
266  *
267  * The function call scheme is according to \ref grp_interact. No State reset is performed during operation.
268  *
269  * \copydoc pphFriNfc_Cr_t
270  *
271  * \note The lower (Overlapped HAL) layer must register a pointer to this function as a Completion
272  *       Routine in order to be able to notify the component that an I/O has finished and data are
273  *       ready to be processed.
274  *
275  */
276
277 void phFriNfc_Felica_Process(void       *Context,
278                              NFCSTATUS   Status);
279
280
281 #endif /* PH_FRINFC_EXCLUDE_FROM_TESTFW */
282
283
284 #endif /* PHFRINFC_FELICAMAP_H */
285
286