1 /******************************************************************************
2  *
3  *  Copyright (C) 2009-2014 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  This file contains the Near Field Communication (NFC) Card Emulation
22  *  mode related API function external definitions.
23  *
24  ******************************************************************************/
25 
26 #ifndef CE_API_H
27 #define CE_API_H
28 
29 #include <stdbool.h>
30 #include "nfc_api.h"
31 #include "nfc_types.h"
32 #include "tags_defs.h"
33 
34 #define CE_T3T_FIRST_EVT 0x60
35 #define CE_T4T_FIRST_EVT 0x80
36 
37 enum {
38   CE_T3T_NDEF_UPDATE_START_EVT = CE_T3T_FIRST_EVT,
39   CE_T3T_NDEF_UPDATE_CPLT_EVT,
40   CE_T3T_UPDATE_EVT,
41   CE_T3T_CHECK_EVT,
42   CE_T3T_RAW_FRAME_EVT,
43   CE_T3T_MAX_EVT,
44 
45   CE_T4T_NDEF_UPDATE_START_EVT = CE_T4T_FIRST_EVT,
46   CE_T4T_NDEF_UPDATE_CPLT_EVT,
47   CE_T4T_NDEF_UPDATE_ABORT_EVT,
48   CE_T4T_RAW_FRAME_EVT,
49   CE_T4T_MAX_EVT
50 };
51 
52 #define CE_RAW_FRAME_EVT 0xFF
53 
54 typedef uint8_t tCE_EVENT;
55 
56 typedef struct {
57   tNFC_STATUS status;
58   NFC_HDR* p_data;
59 } tCE_T2T_DATA;
60 
61 typedef struct {
62   tNFC_STATUS status;
63   uint8_t* p_data;
64   bool b_updated;
65   uint32_t length;
66 } tCE_UPDATE_INFO;
67 
68 typedef struct {
69   tNFC_STATUS status;
70   uint8_t aid_handle;
71   NFC_HDR* p_data;
72 } tCE_RAW_FRAME;
73 
74 typedef union {
75   tNFC_STATUS status;
76   tCE_UPDATE_INFO update_info;
77   tCE_RAW_FRAME raw_frame;
78 } tCE_DATA;
79 
80 typedef void(tCE_CBACK)(tCE_EVENT event, tCE_DATA* p_data);
81 
82 /* T4T definitions */
83 typedef uint8_t tCE_T4T_AID_HANDLE; /* Handle for AID registration  */
84 /* Invalid tCE_T4T_AID_HANDLE               */
85 #define CE_T4T_AID_HANDLE_INVALID 0xFF
86 /* reserved handle for wildcard aid */
87 #define CE_T4T_WILDCARD_AID_HANDLE (CE_T4T_MAX_REG_AID)
88 
89 /*******************************************************************************
90 **
91 ** Function         CE_T3tSetLocalNDEFMsg
92 **
93 ** Description      Initialise CE Type 3 Tag with mandatory NDEF message
94 **
95 ** Returns          NFC_STATUS_OK if success
96 **
97 *******************************************************************************/
98 extern tNFC_STATUS CE_T3tSetLocalNDEFMsg(bool read_only, uint32_t size_max,
99                                          uint32_t size_current, uint8_t* p_buf,
100                                          uint8_t* p_scratch_buf);
101 
102 /*******************************************************************************
103 **
104 ** Function         CE_T3tSetLocalNDefParams
105 **
106 ** Description      Sets T3T-specific NDEF parameters. (Optional - if not
107 **                  called, then CE will use default parameters)
108 **
109 ** Returns          NFC_STATUS_OK if success
110 **
111 *******************************************************************************/
112 extern tNFC_STATUS CE_T3tSetLocalNDefParams(uint8_t nbr, uint8_t nbw);
113 
114 /*******************************************************************************
115 **
116 ** Function         CE_T3tSendCheckRsp
117 **
118 ** Description      Send CHECK response message
119 **
120 ** Returns          NFC_STATUS_OK if success
121 **
122 *******************************************************************************/
123 extern tNFC_STATUS CE_T3tSendCheckRsp(uint8_t status1, uint8_t status2,
124                                       uint8_t num_blocks,
125                                       uint8_t* p_block_data);
126 
127 /*******************************************************************************
128 **
129 ** Function         CE_T3tSendUpdateRsp
130 **
131 ** Description      Send UPDATE response message
132 **
133 ** Returns          NFC_STATUS_OK if success
134 **
135 *******************************************************************************/
136 extern tNFC_STATUS CE_T3tSendUpdateRsp(uint8_t status1, uint8_t status2);
137 
138 /*******************************************************************************
139 **
140 ** Function         CE_T4tSetLocalNDEFMsg
141 **
142 ** Description      Initialise CE Type 4 Tag with mandatory NDEF message
143 **
144 **                  The following event may be returned
145 **                      CE_T4T_UPDATE_START_EVT for starting update
146 **                      CE_T4T_UPDATE_CPLT_EVT for complete update
147 **                      CE_T4T_UPDATE_ABORT_EVT for failure of update
148 **                      CE_T4T_RAW_FRAME_EVT for raw frame
149 **
150 **                  read_only:      TRUE if read only
151 **                  ndef_msg_max:   Max NDEF message size
152 **                  ndef_msg_len:   NDEF message size
153 **                  p_ndef_msg:     NDEF message (excluding NLEN)
154 **                  p_scratch_buf:  temp storage for update
155 **
156 ** Returns          NFC_STATUS_OK if success
157 **
158 *******************************************************************************/
159 extern tNFC_STATUS CE_T4tSetLocalNDEFMsg(bool read_only, uint16_t ndef_msg_max,
160                                          uint16_t ndef_msg_len,
161                                          uint8_t* p_ndef_msg,
162                                          uint8_t* p_scratch_buf);
163 
164 /*******************************************************************************
165 **
166 ** Function         CE_T4tRegisterAID
167 **
168 ** Description      Register AID in CE T4T
169 **
170 **                  aid_len: length of AID (up to NFC_MAX_AID_LEN)
171 **                  p_aid:   AID
172 **                  p_cback: Raw frame will be forwarded with CE_RAW_FRAME_EVT
173 **
174 ** Returns          tCE_T4T_AID_HANDLE if successful,
175 **                  CE_T4T_AID_HANDLE_INVALID otherwisse
176 **
177 *******************************************************************************/
178 extern tCE_T4T_AID_HANDLE CE_T4tRegisterAID(uint8_t aid_len, uint8_t* p_aid,
179                                             tCE_CBACK* p_cback);
180 
181 /*******************************************************************************
182 **
183 ** Function         CE_T4tDeregisterAID
184 **
185 ** Description      Deregister AID in CE T4T
186 **
187 **                  aid_len: length of AID (up to NFC_MAX_AID_LEN)
188 **                  p_aid:   AID
189 **
190 ** Returns          NFC_STATUS_OK if success
191 **
192 *******************************************************************************/
193 extern void CE_T4tDeregisterAID(tCE_T4T_AID_HANDLE aid_handle);
194 
195 /*******************************************************************************
196 **
197 ** Function         CE_T4TTestSetCC
198 **
199 ** Description      Set fields in Capability Container File for testing
200 **
201 ** Returns          NFC_STATUS_OK if success
202 **
203 *******************************************************************************/
204 extern tNFC_STATUS CE_T4TTestSetCC(uint16_t cc_len, uint8_t version,
205                                    uint16_t max_le, uint16_t max_lc);
206 
207 /*******************************************************************************
208 **
209 ** Function         CE_T4TTestSetNDEFCtrlTLV
210 **
211 ** Description      Set fields in NDEF File Control TLV for testing
212 **
213 ** Returns          NFC_STATUS_OK if success
214 **
215 *******************************************************************************/
216 extern tNFC_STATUS CE_T4TTestSetNDEFCtrlTLV(uint8_t type, uint8_t length,
217                                             uint16_t file_id,
218                                             uint16_t max_file_size,
219                                             uint8_t read_access,
220                                             uint8_t write_access);
221 
222 /*******************************************************************************
223 **
224 ** Function         CE_SendRawFrame
225 **
226 ** Description      This function sends a raw frame to the peer device.
227 **
228 ** Returns          tNFC_STATUS
229 **
230 *******************************************************************************/
231 extern tNFC_STATUS CE_SendRawFrame(uint8_t* p_raw_data, uint16_t data_len);
232 
233 /*******************************************************************************
234 **
235 ** Function         CE_SetActivatedTagType
236 **
237 ** Description      This function selects the tag type for Reader/Writer mode.
238 **
239 ** Returns          tNFC_STATUS
240 **
241 *******************************************************************************/
242 extern tNFC_STATUS CE_SetActivatedTagType(tNFC_ACTIVATE_DEVT* p_activate_params,
243                                           uint16_t t3t_system_code,
244                                           tCE_CBACK* p_cback);
245 
246 /*******************************************************************************
247 **
248 ** Function         CE_SetTraceLevel
249 **
250 ** Description      This function sets the trace level for Card Emulation mode.
251 **                  If called with a value of 0xFF,
252 **                  it simply returns the current trace level.
253 **
254 ** Returns          The new or current trace level
255 **
256 *******************************************************************************/
257 extern uint8_t CE_SetTraceLevel(uint8_t new_level);
258 
259 #endif /* CE_API_H */
260