• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_RAW_FRAME_EVT,
42 
43   CE_T4T_NDEF_UPDATE_START_EVT = CE_T4T_FIRST_EVT,
44   CE_T4T_NDEF_UPDATE_CPLT_EVT,
45   CE_T4T_NDEF_UPDATE_ABORT_EVT,
46   CE_T4T_RAW_FRAME_EVT
47 };
48 
49 typedef uint8_t tCE_EVENT;
50 
51 typedef struct {
52   tNFC_STATUS status;
53   uint8_t* p_data;
54   bool b_updated;
55   uint32_t length;
56 } tCE_UPDATE_INFO;
57 
58 typedef struct {
59   tNFC_STATUS status;
60   uint8_t aid_handle;
61   NFC_HDR* p_data;
62 } tCE_RAW_FRAME;
63 
64 typedef union {
65   tNFC_STATUS status;
66   tCE_UPDATE_INFO update_info;
67   tCE_RAW_FRAME raw_frame;
68 } tCE_DATA;
69 
70 typedef void(tCE_CBACK)(tCE_EVENT event, tCE_DATA* p_data);
71 
72 /* T4T definitions */
73 typedef uint8_t tCE_T4T_AID_HANDLE; /* Handle for AID registration  */
74 /* Invalid tCE_T4T_AID_HANDLE               */
75 #define CE_T4T_AID_HANDLE_INVALID 0xFF
76 /* reserved handle for wildcard aid */
77 #define CE_T4T_WILDCARD_AID_HANDLE (CE_T4T_MAX_REG_AID)
78 
79 /*******************************************************************************
80 **
81 ** Function         CE_T3tSetLocalNDEFMsg
82 **
83 ** Description      Initialise CE Type 3 Tag with mandatory NDEF message
84 **
85 ** Returns          NFC_STATUS_OK if success
86 **
87 *******************************************************************************/
88 extern tNFC_STATUS CE_T3tSetLocalNDEFMsg(bool read_only, uint32_t size_max,
89                                          uint32_t size_current, uint8_t* p_buf,
90                                          uint8_t* p_scratch_buf);
91 
92 /*******************************************************************************
93 **
94 ** Function         CE_T3tSetLocalNDefParams
95 **
96 ** Description      Sets T3T-specific NDEF parameters. (Optional - if not
97 **                  called, then CE will use default parameters)
98 **
99 ** Returns          NFC_STATUS_OK if success
100 **
101 *******************************************************************************/
102 extern tNFC_STATUS CE_T3tSetLocalNDefParams(uint8_t nbr, uint8_t nbw);
103 
104 /*******************************************************************************
105 **
106 ** Function         CE_T3tSendCheckRsp
107 **
108 ** Description      Send CHECK response message
109 **
110 ** Returns          NFC_STATUS_OK if success
111 **
112 *******************************************************************************/
113 extern tNFC_STATUS CE_T3tSendCheckRsp(uint8_t status1, uint8_t status2,
114                                       uint8_t num_blocks,
115                                       uint8_t* p_block_data);
116 
117 /*******************************************************************************
118 **
119 ** Function         CE_T3tSendUpdateRsp
120 **
121 ** Description      Send UPDATE response message
122 **
123 ** Returns          NFC_STATUS_OK if success
124 **
125 *******************************************************************************/
126 extern tNFC_STATUS CE_T3tSendUpdateRsp(uint8_t status1, uint8_t status2);
127 
128 /*******************************************************************************
129 **
130 ** Function         CE_T4tSetLocalNDEFMsg
131 **
132 ** Description      Initialise CE Type 4 Tag with mandatory NDEF message
133 **
134 **                  The following event may be returned
135 **                      CE_T4T_UPDATE_START_EVT for starting update
136 **                      CE_T4T_UPDATE_CPLT_EVT for complete update
137 **                      CE_T4T_UPDATE_ABORT_EVT for failure of update
138 **                      CE_T4T_RAW_FRAME_EVT for raw frame
139 **
140 **                  read_only:      TRUE if read only
141 **                  ndef_msg_max:   Max NDEF message size
142 **                  ndef_msg_len:   NDEF message size
143 **                  p_ndef_msg:     NDEF message (excluding NLEN)
144 **                  p_scratch_buf:  temp storage for update
145 **
146 ** Returns          NFC_STATUS_OK if success
147 **
148 *******************************************************************************/
149 extern tNFC_STATUS CE_T4tSetLocalNDEFMsg(bool read_only, uint16_t ndef_msg_max,
150                                          uint16_t ndef_msg_len,
151                                          uint8_t* p_ndef_msg,
152                                          uint8_t* p_scratch_buf);
153 
154 /*******************************************************************************
155 **
156 ** Function         CE_T4tRegisterAID
157 **
158 ** Description      Register AID in CE T4T
159 **
160 **                  aid_len: length of AID (up to NFC_MAX_AID_LEN)
161 **                  p_aid:   AID
162 **                  p_cback: Raw frame will be forwarded with CE_RAW_FRAME_EVT
163 **
164 ** Returns          tCE_T4T_AID_HANDLE if successful,
165 **                  CE_T4T_AID_HANDLE_INVALID otherwisse
166 **
167 *******************************************************************************/
168 extern tCE_T4T_AID_HANDLE CE_T4tRegisterAID(uint8_t aid_len, uint8_t* p_aid,
169                                             tCE_CBACK* p_cback);
170 
171 /*******************************************************************************
172 **
173 ** Function         CE_T4tDeregisterAID
174 **
175 ** Description      Deregister AID in CE T4T
176 **
177 **                  aid_len: length of AID (up to NFC_MAX_AID_LEN)
178 **                  p_aid:   AID
179 **
180 ** Returns          NFC_STATUS_OK if success
181 **
182 *******************************************************************************/
183 extern void CE_T4tDeregisterAID(tCE_T4T_AID_HANDLE aid_handle);
184 
185 /*******************************************************************************
186 **
187 ** Function         CE_SendRawFrame
188 **
189 ** Description      This function sends a raw frame to the peer device.
190 **
191 ** Returns          tNFC_STATUS
192 **
193 *******************************************************************************/
194 extern tNFC_STATUS CE_SendRawFrame(uint8_t* p_raw_data, uint16_t data_len);
195 
196 /*******************************************************************************
197 **
198 ** Function         CE_SetActivatedTagType
199 **
200 ** Description      This function selects the tag type for Reader/Writer mode.
201 **
202 ** Returns          tNFC_STATUS
203 **
204 *******************************************************************************/
205 extern tNFC_STATUS CE_SetActivatedTagType(tNFC_ACTIVATE_DEVT* p_activate_params,
206                                           uint16_t t3t_system_code,
207                                           tCE_CBACK* p_cback);
208 #endif /* CE_API_H */
209