1 /*
2  * Copyright (C) 2015 The Android Open Source Project
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 #ifndef _PHNXPEXTNS_CUSTOM_H_
18 #define _PHNXPEXTNS_CUSTOM_H_
19 
20 #include <errno.h>
21 #include <nfa_api.h>
22 #include <phNfcStatus.h>
23 #include <sys/types.h>
24 
25 /*
26  * TLV structure
27  * For simple TLV, type[0] == 0x00
28  * For extended TLV, type[0] == 0xA0
29  */
30 typedef struct {
31   uint8_t type[2];
32   uint8_t len;
33   uint8_t* val;
34 } tlv_t;
35 
36 typedef enum {
37   passive_106 = 0x01,
38   passive_212 = 0x02,
39   passive_424 = 0x04,
40   active_106 = 0x10,
41   active_212 = 0x20,
42   active_424 = 0x40,
43 } p2p_speed_t;
44 
45 typedef enum {
46   NO_SE,
47   UICC,
48   eSE,
49 } SE_t;
50 
51 typedef enum {
52   ReaderMode = 0x01,
53   P2PMode = 0x02,
54   CEMode = 0x04,
55 } PollMode_t;
56 
57 /*******************************************************************************
58  **
59  ** Function         phNxpExtns_get_version
60  **
61  ** Description      Function to get the HW, FW and SW versions.
62  **
63  ** Returns          NFCSTATUS_SUCCESS if successful,otherwise NFCSTATUS_FAILED.
64  **
65  ** NOTE: Internally this function will use phNxpNciHal_get_version from HAL.
66  *******************************************************************************/
67 
68 NFCSTATUS phNxpExtns_get_version(uint32_t* hw_ver, uint32_t* fw_ver,
69                                  uint32_t* sw_ver);
70 
71 /*******************************************************************************
72  **
73  ** Function         phNxpNciHal_read_tlv
74  **
75  ** Description      Function to read simple TLV and extended TLV.
76  **                  Memory for TLV and fields are allocated and freed by
77  *calling
78  **                  function. Input is type and len. Response is provied in
79  **val.
80  **
81  ** Returns          NFCSTATUS_SUCCESS if successful,otherwise NFCSTATUS_FAILED.
82  **
83  ** NOTE: Internally this function will use NFA_GetConfig for simple TLV.
84  **       For extended TLV, it will use NFA_SendRawFrame.
85  *******************************************************************************/
86 
87 NFCSTATUS phNxpNciHal_read_tlv(tlv_t* tlv);
88 
89 /*******************************************************************************
90  **
91  ** Function         phNxpNciHal_write_tlv
92  **
93  ** Description      Function to write simple TLV and extended TLV.
94  **                  Memory for TLV and fields are allocated and freed by
95  *calling
96  **                  function. Input is type, len, *val.
97  **
98  ** Returns          NFCSTATUS_SUCCESS if successful,otherwise NFCSTATUS_FAILED.
99  **
100  ** NOTE: Internally this function will use NFA_SetConfig for simple TLV.
101  **       For extended TLV, it will use NFA_SendRawFrame.
102  *******************************************************************************/
103 
104 NFCSTATUS phNxpNciHal_write_tlv(tlv_t* tlv);
105 
106 /*******************************************************************************
107  **
108  ** Function        phNxpExtns_select_poll_tech
109  **
110  ** Description     This function selects the polling technology for starting
111  **                 polling loop. This function does not start polling loop.
112  **                 It is just a setting for polling technology.
113  **
114  ** Returns         NFCSTATUS_SUCCESS if operation successful,
115  **                 otherwise NFCSTATUS_FAILED.
116  **
117  ** NOTE: Internally this function is using NFA_EnablePolling function.
118  *******************************************************************************/
119 
120 NFCSTATUS phNxpExtns_select_poll_tech(tNFA_TECHNOLOGY_MASK tech_mask);
121 
122 /*******************************************************************************
123  **
124  ** Function        phNxpExtns_select_ce_listen_tech
125  **
126  ** Description     This function set the listen tech for card emulation.
127  **                 This function does not include routing.
128  **                 This function does not start polling loop.
129  **
130  ** Returns         NFCSTATUS_SUCCESS if operation successful,
131  **                 otherwise NFCSTATUS_FAILED.
132  **
133  ** NOTE: Internally this function is using NFA_CeConfigureUiccListenTech.
134  **       Not sure which handle to use, from UICC or eSE.
135  *******************************************************************************/
136 
137 NFCSTATUS phNxpExtns_select_ce_listen_tech(tNFA_TECHNOLOGY_MASK tech_mask);
138 
139 /*******************************************************************************
140  **
141  ** Function        phNxpExtns_select_p2p_poll_speed
142  **
143  ** Description     This function will select the P2P polling speed.
144  **                 phNxpExtns_select_poll_tech overwrite the settings of poll
145  *if
146  **                 reader mode is enabled.
147  **                 There is only one active poll phase but device can use one
148  **                 active speed and can move to higher speed if target
149  *supports.
150  **
151  ** Returns         NFCSTATUS_SUCCESS if operation successful,
152  **                 otherwise NFCSTATUS_FAILED.
153  **
154  ** NOTE: Internally this function will use NFA_EnablePolling and NFA_SetConfig
155  *******************************************************************************/
156 
157 NFCSTATUS phNxpExtns_select_p2p_poll_speed(p2p_speed_t p2p_initiator_speed);
158 
159 /*******************************************************************************
160  **
161  ** Function        phNxpExtns_select_p2p_listen_speed
162  **
163  ** Description     This function will select the listen mode
164  **                 This function does not include routing.
165  **                 This function does not start polling loop.
166  **
167  ** Returns         NFCSTATUS_SUCCESS if operation successful,
168  **                 otherwise NFCSTATUS_FAILED.
169  **
170  ** NOTE: Internally this function will use NFA_SetP2pListenTech and
171  *NFA_SetConfig
172  *******************************************************************************/
173 
174 NFCSTATUS phNxpExtns_select_p2p_listen_speed(p2p_speed_t p2p_target_speed);
175 
176 /*******************************************************************************
177  **
178  ** Function        phNxpExtns_select_se
179  **
180  ** Description     This function will set the routing of the traffic to
181  *selected
182  **                 SE. This function also does not start polling loop.
183  **
184  ** Returns         NFCSTATUS_SUCCESS if operation successful,
185  **                 otherwise NFCSTATUS_FAILED.
186  **
187  ** NOTE:
188  *******************************************************************************/
189 
190 NFCSTATUS phNxpExtns_select_se(SE_t se);
191 
192 /*******************************************************************************
193  **
194  ** Function        phNxpExtns_set_poll_mode
195  **
196  ** Description     This function selects which mode to enable for polling loop.
197  **                 This function do not start polling loop.
198  **
199  ** Returns         NFCSTATUS_SUCCESS if operation successful,
200  **                 otherwise NFCSTATUS_FAILED.
201  **
202  ** NOTE:
203  *******************************************************************************/
204 
205 NFCSTATUS phNxpExtns_set_poll_mode(PollMode_t poll_mode);
206 
207 /*******************************************************************************
208  **
209  ** Function        phNxpExtns_start_poll
210  **
211  ** Description     This function starts polling loop based on the configuration
212  **                 of the previous calls. If no configuration done through
213  *other
214  **                 function call then it uses the default configuration from
215  **                 configuration files.
216  **                 This function internally stops the polling loop if it is
217  **                 already running.
218  **
219  ** Returns         NFCSTATUS_SUCCESS if operation successful,
220  **                 otherwise NFCSTATUS_FAILED.
221  **
222  ** NOTE: Internally this function uses NFA_StartRfDiscovery.
223  *******************************************************************************/
224 
225 NFCSTATUS phNxpExtns_start_poll(void);
226 
227 /*******************************************************************************
228  **
229  ** Function        phNxpExtns_stop_poll
230  **
231  ** Description     This function stops the polling loop if it is running.
232  **
233  ** Returns          NFCSTATUS_SUCCESS if operation successful,
234  **                  otherwise NFCSTATUS_FAILED.
235  **
236  ** NOTE:Internally this function uses NFA_StopRfDiscovery.
237  *******************************************************************************/
238 
239 NFCSTATUS phNxpExtns_stop_poll(void);
240 
241 /*******************************************************************************
242  **
243  ** Function        phNxpExtns_enable_Felica_CLT
244  **
245  ** Description     This function enables or disable Felica CLT feature.
246  **
247  ** Returns         NFCSTATUS_SUCCESS if operation successful,
248  **                 otherwise NFCSTATUS_FAILED.
249  **
250  ** NOTE:
251  *******************************************************************************/
252 
253 NFCSTATUS phNxpExtns_enable_Felica_CLT(bool enable);
254 
255 /*******************************************************************************
256  **
257  ** Function        phNxpExtns_enable_Mifare_CLT
258  **
259  ** Description     This function enables or disable Mifare CLT feature.
260  **
261  ** Returns         NFCSTATUS_SUCCESS if operation successful,
262  **                 otherwise NFCSTATUS_FAILED.
263  **
264  ** NOTE:
265  *******************************************************************************/
266 
267 NFCSTATUS phNxpExtns_enable_Mifare_CLT(bool enable);
268 
269 #endif /* _PHNXPEXTNS_CUSTOM_H_ */
270