blob: f7bfb226b3554e8b168685dd3140d8a2ab13cc71 [file] [log] [blame]
nxpandroidc7611652015-09-23 16:42:05 +05301/******************************************************************************
2 *
3 * Copyright (C) 2010-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 *
nxf24591c1cbeab2018-02-21 17:32:26 +053020 * The original Work has been changed by NXP.
nxpandroidc7611652015-09-23 16:42:05 +053021 *
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
25 *
26 * http://www.apache.org/licenses/LICENSE-2.0
27 *
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
33 *
nxf24591c1cbeab2018-02-21 17:32:26 +053034 * Copyright 2018 NXP
35 *
nxpandroidc7611652015-09-23 16:42:05 +053036 ******************************************************************************/
37/******************************************************************************
38 *
39 * NFA interface to HCI
40 *
41 ******************************************************************************/
nxf24591c1cbeab2018-02-21 17:32:26 +053042#include <android-base/stringprintf.h>
43#include <base/logging.h>
44
nxpandroidc7611652015-09-23 16:42:05 +053045#include "nfa_hci_api.h"
nxpandroidc7611652015-09-23 16:42:05 +053046#include "nfa_hci_defs.h"
nxf24591c1cbeab2018-02-21 17:32:26 +053047#include "nfa_hci_int.h"
48
49using android::base::StringPrintf;
50
51extern bool nfc_debug_enabled;
nxpandroidc7611652015-09-23 16:42:05 +053052
53/*******************************************************************************
54**
55** Function NFA_HciRegister
56**
57** Description This function will register an application with hci and
58** returns an application handle and provides a mechanism to
nxpandroid8f6d0532017-07-12 18:25:30 +053059** register a callback with HCI to receive NFA HCI event
60** notification. When the application is registered (or if an
61** error occurs), the app will be notified with
62** NFA_HCI_REGISTER_EVT. Previous session information including
63** allocated gates, created pipes and pipes states will be
64** returned as part of tNFA_HCI_REGISTER data.
nxpandroidc7611652015-09-23 16:42:05 +053065**
66** Returns NFA_STATUS_OK if successfully initiated
67** NFA_STATUS_FAILED otherwise
68**
69*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +053070tNFA_STATUS NFA_HciRegister(char* p_app_name, tNFA_HCI_CBACK* p_cback,
71 bool b_send_conn_evts) {
72 tNFA_HCI_API_REGISTER_APP* p_msg;
73 uint8_t app_name_len;
nxpandroidc7611652015-09-23 16:42:05 +053074
nxpandroid8f6d0532017-07-12 18:25:30 +053075 if (p_app_name == NULL) {
nxf24591c1cbeab2018-02-21 17:32:26 +053076 DLOG_IF(INFO, nfc_debug_enabled)
77 << StringPrintf("Invalid Application name");
nxpandroidc7611652015-09-23 16:42:05 +053078 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +053079 }
80
81 if (p_cback == NULL) {
nxf24591c1cbeab2018-02-21 17:32:26 +053082 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
83 "Application should provide callback function to "
nxpandroid8f6d0532017-07-12 18:25:30 +053084 "register!");
85 return (NFA_STATUS_FAILED);
86 }
87
nxf24591c1cbeab2018-02-21 17:32:26 +053088 DLOG_IF(INFO, nfc_debug_enabled)
89 << StringPrintf("Application Name: %s", p_app_name);
nxpandroid8f6d0532017-07-12 18:25:30 +053090
91 app_name_len = (uint8_t)strlen(p_app_name);
92
93 /* Register the application with HCI */
94 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
95 (p_app_name != NULL) && (app_name_len <= NFA_MAX_HCI_APP_NAME_LEN) &&
96 ((p_msg = (tNFA_HCI_API_REGISTER_APP*)GKI_getbuf(
97 sizeof(tNFA_HCI_API_REGISTER_APP))) != NULL)) {
98 p_msg->hdr.event = NFA_HCI_API_REGISTER_APP_EVT;
99
100 /* Save application name and callback */
101 memset(p_msg->app_name, 0, sizeof(p_msg->app_name));
102 strncpy(p_msg->app_name, p_app_name, NFA_MAX_HCI_APP_NAME_LEN);
103 p_msg->p_cback = p_cback;
104 p_msg->b_send_conn_evts = b_send_conn_evts;
105
106 nfa_sys_sendmsg(p_msg);
107 return (NFA_STATUS_OK);
108 }
109
110 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530111}
112
113/*******************************************************************************
114**
115** Function NFA_HciGetGateAndPipeList
116**
117** Description This function will get the list of gates allocated to the
118** application and list of dynamic pipes created by the
119** application. The app will be notified with
120** NFA_HCI_GET_GATE_PIPE_LIST_EVT. List of allocated dynamic
121** gates to the application and list of pipes created by the
122** application will be returned as part of
123** tNFA_HCI_GET_GATE_PIPE_LIST data.
124**
125** Returns NFA_STATUS_OK if successfully initiated
126** NFA_STATUS_FAILED otherwise
127**
128*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530129tNFA_STATUS NFA_HciGetGateAndPipeList(tNFA_HANDLE hci_handle) {
130 tNFA_HCI_API_GET_APP_GATE_PIPE* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530131
nxpandroid8f6d0532017-07-12 18:25:30 +0530132 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530133 DLOG_IF(INFO, nfc_debug_enabled)
134 << StringPrintf("Invalid hci_handle:0x%04x", hci_handle);
nxpandroidc7611652015-09-23 16:42:05 +0530135 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +0530136 }
137
nxf24591c1cbeab2018-02-21 17:32:26 +0530138 DLOG_IF(INFO, nfc_debug_enabled)
139 << StringPrintf("hci_handle:0x%04x", hci_handle);
nxpandroid8f6d0532017-07-12 18:25:30 +0530140
141 /* Register the application with HCI */
142 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
143 ((p_msg = (tNFA_HCI_API_GET_APP_GATE_PIPE*)GKI_getbuf(
144 sizeof(tNFA_HCI_API_GET_APP_GATE_PIPE))) != NULL)) {
145 p_msg->hdr.event = NFA_HCI_API_GET_APP_GATE_PIPE_EVT;
146 p_msg->hci_handle = hci_handle;
147
148 nfa_sys_sendmsg(p_msg);
149 return (NFA_STATUS_OK);
150 }
151
152 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530153}
154
155/*******************************************************************************
156**
157** Function NFA_HciDeregister
158**
159** Description This function is called to deregister an application
160** from HCI. The app will be notified by NFA_HCI_DEREGISTER_EVT
nxpandroid8f6d0532017-07-12 18:25:30 +0530161** after deleting all the pipes owned by the app and
162** deallocating all the gates allocated to the app or if an
163** error occurs. Even if deregistration fails, the app has to
164** register again to provide a new cback function.
nxpandroidc7611652015-09-23 16:42:05 +0530165**
nxpandroid8f6d0532017-07-12 18:25:30 +0530166** Returns NFA_STATUS_OK if the application is deregistered
167** successfully
nxpandroidc7611652015-09-23 16:42:05 +0530168** NFA_STATUS_FAILED otherwise
169
170*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530171tNFA_STATUS NFA_HciDeregister(char* p_app_name) {
172 tNFA_HCI_API_DEREGISTER_APP* p_msg;
173 int xx;
174 uint8_t app_name_len;
nxpandroidc7611652015-09-23 16:42:05 +0530175
nxpandroid8f6d0532017-07-12 18:25:30 +0530176 if (p_app_name == NULL) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530177 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("Invalid Application");
nxpandroidc7611652015-09-23 16:42:05 +0530178 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +0530179 }
180
nxf24591c1cbeab2018-02-21 17:32:26 +0530181 DLOG_IF(INFO, nfc_debug_enabled)
182 << StringPrintf("Application Name: %s", p_app_name);
nxpandroid8f6d0532017-07-12 18:25:30 +0530183 app_name_len = (uint8_t)strlen(p_app_name);
184
185 if (app_name_len > NFA_MAX_HCI_APP_NAME_LEN) return (NFA_STATUS_FAILED);
186
187 /* Find the application registration */
188 for (xx = 0; xx < NFA_HCI_MAX_APP_CB; xx++) {
189 if ((nfa_hci_cb.cfg.reg_app_names[xx][0] != 0) &&
190 (!strncmp(p_app_name, &nfa_hci_cb.cfg.reg_app_names[xx][0],
191 app_name_len)))
192 break;
193 }
194
195 if (xx == NFA_HCI_MAX_APP_CB) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530196 LOG(ERROR) << StringPrintf("Application Name: %s NOT FOUND", p_app_name);
nxpandroid8f6d0532017-07-12 18:25:30 +0530197 return (NFA_STATUS_FAILED);
198 }
199
200 /* Deregister the application with HCI */
201 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
202 ((p_msg = (tNFA_HCI_API_DEREGISTER_APP*)GKI_getbuf(
203 sizeof(tNFA_HCI_API_DEREGISTER_APP))) != NULL)) {
204 p_msg->hdr.event = NFA_HCI_API_DEREGISTER_APP_EVT;
205
206 memset(p_msg->app_name, 0, sizeof(p_msg->app_name));
207 strncpy(p_msg->app_name, p_app_name, NFA_MAX_HCI_APP_NAME_LEN);
208
209 nfa_sys_sendmsg(p_msg);
210 return (NFA_STATUS_OK);
211 }
212
213 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530214}
215
216/*******************************************************************************
217**
218** Function NFA_HciAllocGate
219**
220** Description This function will allocate the gate if any specified or an
221** available generic gate for the app to provide an entry point
222** for a particular service to other host or to establish
223** communication with other host. When the gate is
224** allocated (or if an error occurs), the app will be notified
nxpandroid8f6d0532017-07-12 18:25:30 +0530225** with NFA_HCI_ALLOCATE_GATE_EVT with the gate id. The
226** allocated Gate information will be stored in non volatile
227** memory.
nxpandroidc7611652015-09-23 16:42:05 +0530228**
229** Returns NFA_STATUS_OK if this API started
230** NFA_STATUS_FAILED if no generic gate is available
231**
232*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530233tNFA_STATUS NFA_HciAllocGate(tNFA_HANDLE hci_handle, uint8_t gate) {
234 tNFA_HCI_API_ALLOC_GATE* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530235
nxpandroid8f6d0532017-07-12 18:25:30 +0530236 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530237 DLOG_IF(INFO, nfc_debug_enabled)
238 << StringPrintf("Invalid hci_handle:0x%04x", hci_handle);
nxpandroidc7611652015-09-23 16:42:05 +0530239 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +0530240 }
241
242 if ((gate) && ((gate < NFA_HCI_FIRST_HOST_SPECIFIC_GENERIC_GATE) ||
243 (gate > NFA_HCI_LAST_PROP_GATE) ||
244 (gate == NFA_HCI_CONNECTIVITY_GATE))) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530245 DLOG_IF(INFO, nfc_debug_enabled)
246 << StringPrintf("Cannot allocate gate:0x%02x", gate);
nxpandroid8f6d0532017-07-12 18:25:30 +0530247 return (NFA_STATUS_FAILED);
248 }
249
nxf24591c1cbeab2018-02-21 17:32:26 +0530250 DLOG_IF(INFO, nfc_debug_enabled)
251 << StringPrintf("hci_handle:0x%04x, Gate:0x%02x", hci_handle, gate);
nxpandroid8f6d0532017-07-12 18:25:30 +0530252
253 /* Request HCI to allocate gate to the application */
254 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
255 ((p_msg = (tNFA_HCI_API_ALLOC_GATE*)GKI_getbuf(
256 sizeof(tNFA_HCI_API_ALLOC_GATE))) != NULL)) {
257 p_msg->hdr.event = NFA_HCI_API_ALLOC_GATE_EVT;
258 p_msg->hci_handle = hci_handle;
259 p_msg->gate = gate;
260
261 nfa_sys_sendmsg(p_msg);
262 return (NFA_STATUS_OK);
263 }
264 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530265}
266
267/*******************************************************************************
268**
269** Function NFA_HciDeallocGate
270**
271** Description This function will release the specified gate that was
272** previously allocated to the application. When the generic
273** gate is released (or if an error occurs), the app will be
274** notified with NFA_HCI_DEALLOCATE_GATE_EVT with the gate id.
275**
276** Returns NFA_STATUS_OK if successfully initiated
277** NFA_STATUS_FAILED otherwise
278**
279*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530280tNFA_STATUS NFA_HciDeallocGate(tNFA_HANDLE hci_handle, uint8_t gate) {
281 tNFA_HCI_API_DEALLOC_GATE* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530282
nxpandroid8f6d0532017-07-12 18:25:30 +0530283 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530284 DLOG_IF(INFO, nfc_debug_enabled)
285 << StringPrintf("Invalid hci_handle:0x%04x", hci_handle);
nxpandroidc7611652015-09-23 16:42:05 +0530286 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +0530287 }
288
289 if ((gate < NFA_HCI_FIRST_HOST_SPECIFIC_GENERIC_GATE) ||
290 (gate > NFA_HCI_LAST_PROP_GATE) || (gate == NFA_HCI_CONNECTIVITY_GATE)) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530291 DLOG_IF(INFO, nfc_debug_enabled)
292 << StringPrintf("Cannot deallocate the gate:0x%02x", gate);
nxpandroid8f6d0532017-07-12 18:25:30 +0530293 return (NFA_STATUS_FAILED);
294 }
295
nxf24591c1cbeab2018-02-21 17:32:26 +0530296 DLOG_IF(INFO, nfc_debug_enabled)
297 << StringPrintf("hci_handle:0x%04x, gate:0x%02X", hci_handle, gate);
nxpandroid8f6d0532017-07-12 18:25:30 +0530298
299 /* Request HCI to deallocate the gate that was previously allocated to the
300 * application */
301 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
302 ((p_msg = (tNFA_HCI_API_DEALLOC_GATE*)GKI_getbuf(
303 sizeof(tNFA_HCI_API_DEALLOC_GATE))) != NULL)) {
304 p_msg->hdr.event = NFA_HCI_API_DEALLOC_GATE_EVT;
305 p_msg->hci_handle = hci_handle;
306 p_msg->gate = gate;
307
308 nfa_sys_sendmsg(p_msg);
309 return (NFA_STATUS_OK);
310 }
311 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530312}
313
314/*******************************************************************************
315**
316** Function NFA_HciGetHostList
317**
318** Description This function will request the host controller to return the
319** list of hosts that are present in the host network. When
320** host controller responds with the host list (or if an error
321** occurs), the app will be notified with NFA_HCI_HOST_LIST_EVT
322**
323** Returns NFA_STATUS_OK if successfully initiated
324** NFA_STATUS_FAILED otherwise
325**
326*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530327tNFA_STATUS NFA_HciGetHostList(tNFA_HANDLE hci_handle) {
328 tNFA_HCI_API_GET_HOST_LIST* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530329
nxpandroid8f6d0532017-07-12 18:25:30 +0530330 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530331 DLOG_IF(INFO, nfc_debug_enabled)
332 << StringPrintf("Invalid hci_handle:0x%04x", hci_handle);
nxpandroidc7611652015-09-23 16:42:05 +0530333 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +0530334 }
335
nxf24591c1cbeab2018-02-21 17:32:26 +0530336 DLOG_IF(INFO, nfc_debug_enabled)
337 << StringPrintf("hci_handle:0x%04x", hci_handle);
nxpandroid8f6d0532017-07-12 18:25:30 +0530338
339 /* Request HCI to get list of host in the hci network */
340 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
341 ((p_msg = (tNFA_HCI_API_GET_HOST_LIST*)GKI_getbuf(
342 sizeof(tNFA_HCI_API_GET_HOST_LIST))) != NULL)) {
343 p_msg->hdr.event = NFA_HCI_API_GET_HOST_LIST_EVT;
344 p_msg->hci_handle = hci_handle;
345
346 nfa_sys_sendmsg(p_msg);
347 return (NFA_STATUS_OK);
348 }
349
350 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530351}
352
353/*******************************************************************************
354**
355** Function NFA_HciCreatePipe
356**
357** Description This function is called to create a dynamic pipe with the
358** specified host. When the dynamic pipe is created (or
359** if an error occurs), the app will be notified with
360** NFA_HCI_CREATE_PIPE_EVT with the pipe id. If a pipe exists
361** between the two gates passed as argument and if it was
362** created earlier by the calling application then the pipe
363** id of the existing pipe will be returned and a new pipe
364** will not be created. After successful creation of pipe,
365** registry entry will be created for the dynamic pipe and
366** all information related to the pipe will be stored in non
367** volatile memory.
368**
369** Returns NFA_STATUS_OK if successfully initiated
370** NFA_STATUS_FAILED otherwise
371**
372*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530373tNFA_STATUS NFA_HciCreatePipe(tNFA_HANDLE hci_handle, uint8_t source_gate_id,
374 uint8_t dest_host, uint8_t dest_gate) {
375 tNFA_HCI_API_CREATE_PIPE_EVT* p_msg;
376 uint8_t xx;
nxpandroidc7611652015-09-23 16:42:05 +0530377
nxf24591c1cbeab2018-02-21 17:32:26 +0530378 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
379 "hci_handle:0x%04x, source gate:0x%02X, "
nxpandroid8f6d0532017-07-12 18:25:30 +0530380 "destination host:0x%02X , destination gate:0x%02X",
381 hci_handle, source_gate_id, dest_host, dest_gate);
nxpandroidc7611652015-09-23 16:42:05 +0530382
nxpandroid8f6d0532017-07-12 18:25:30 +0530383 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530384 DLOG_IF(INFO, nfc_debug_enabled)
385 << StringPrintf("Invalid hci_handle:0x%04x", hci_handle);
nxpandroidc7611652015-09-23 16:42:05 +0530386 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +0530387 }
388
389 if ((source_gate_id < NFA_HCI_FIRST_HOST_SPECIFIC_GENERIC_GATE) ||
390 (source_gate_id > NFA_HCI_LAST_PROP_GATE)) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530391 DLOG_IF(INFO, nfc_debug_enabled)
392 << StringPrintf("Invalid local Gate:0x%02x", source_gate_id);
nxpandroid8f6d0532017-07-12 18:25:30 +0530393 return (NFA_STATUS_FAILED);
394 }
395
396 if (((dest_gate < NFA_HCI_FIRST_HOST_SPECIFIC_GENERIC_GATE) &&
397 (dest_gate != NFA_HCI_LOOP_BACK_GATE) &&
398 (dest_gate != NFA_HCI_IDENTITY_MANAGEMENT_GATE)) ||
399 (dest_gate > NFA_HCI_LAST_PROP_GATE)) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530400 DLOG_IF(INFO, nfc_debug_enabled)
401 << StringPrintf("Invalid Destination Gate:0x%02x", dest_gate);
nxpandroid8f6d0532017-07-12 18:25:30 +0530402 return (NFA_STATUS_FAILED);
403 }
404
405 for (xx = 0; xx < NFA_HCI_MAX_HOST_IN_NETWORK; xx++)
nxf24591c1cbeab2018-02-21 17:32:26 +0530406#if(NXP_EXTNS == TRUE)
407 if (nfa_hci_cb.active_host[xx] == dest_host) break;
408
409 if (xx == NFA_HCI_MAX_HOST_IN_NETWORK) {
410#else
nxpandroid8f6d0532017-07-12 18:25:30 +0530411 if (nfa_hci_cb.inactive_host[xx] == dest_host) break;
412
413 if (xx != NFA_HCI_MAX_HOST_IN_NETWORK) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530414#endif
415 DLOG_IF(INFO, nfc_debug_enabled)
416 << StringPrintf("NFA_HciCreatePipe (): Host not active:0x%02x", dest_host);
nxpandroid8f6d0532017-07-12 18:25:30 +0530417 return (NFA_STATUS_FAILED);
418 }
419
420 /* Request HCI to create a pipe between two specified gates */
421 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
422 (!nfa_hci_cb.b_low_power_mode) &&
423 ((p_msg = (tNFA_HCI_API_CREATE_PIPE_EVT*)GKI_getbuf(
424 sizeof(tNFA_HCI_API_CREATE_PIPE_EVT))) != NULL)) {
425 p_msg->hdr.event = NFA_HCI_API_CREATE_PIPE_EVT;
426 p_msg->hci_handle = hci_handle;
427 p_msg->source_gate = source_gate_id;
428 p_msg->dest_host = dest_host; /* Host id of the destination host */
429 p_msg->dest_gate = dest_gate; /* Gate id of the destination gate */
430
431 nfa_sys_sendmsg(p_msg);
432 return (NFA_STATUS_OK);
433 }
434 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530435}
436
437/*******************************************************************************
438**
439** Function NFA_HciOpenPipe
440**
441** Description This function is called to open a dynamic pipe.
442** When the dynamic pipe is opened (or
443** if an error occurs), the app will be notified with
444** NFA_HCI_OPEN_PIPE_EVT with the pipe id.
445**
446** Returns NFA_STATUS_OK if successfully initiated
447** NFA_STATUS_FAILED otherwise
448**
449*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530450tNFA_STATUS NFA_HciOpenPipe(tNFA_HANDLE hci_handle, uint8_t pipe) {
451 tNFA_HCI_API_OPEN_PIPE_EVT* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530452
nxpandroid8f6d0532017-07-12 18:25:30 +0530453 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530454 DLOG_IF(INFO, nfc_debug_enabled)
455 << StringPrintf("Invalid hci_handle:0x%04x", hci_handle);
nxpandroidc7611652015-09-23 16:42:05 +0530456 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +0530457 }
458
459 if ((pipe < NFA_HCI_FIRST_DYNAMIC_PIPE) ||
460 (pipe > NFA_HCI_LAST_DYNAMIC_PIPE)) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530461 DLOG_IF(INFO, nfc_debug_enabled)
462 << StringPrintf("Invalid Pipe:0x%02x", pipe);
nxpandroid8f6d0532017-07-12 18:25:30 +0530463 return (NFA_STATUS_FAILED);
464 }
465
nxf24591c1cbeab2018-02-21 17:32:26 +0530466 DLOG_IF(INFO, nfc_debug_enabled)
467 << StringPrintf("hci_handle:0x%04x, pipe:0x%02X", hci_handle, pipe);
nxpandroid8f6d0532017-07-12 18:25:30 +0530468
469 /* Request HCI to open a pipe if it is in closed state */
470 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
471 (!nfa_hci_cb.b_low_power_mode) &&
472 ((p_msg = (tNFA_HCI_API_OPEN_PIPE_EVT*)GKI_getbuf(
473 sizeof(tNFA_HCI_API_OPEN_PIPE_EVT))) != NULL)) {
474 p_msg->hdr.event = NFA_HCI_API_OPEN_PIPE_EVT;
475 p_msg->hci_handle = hci_handle;
476 p_msg->pipe = pipe; /* Pipe ID of the pipe to open */
477
478 nfa_sys_sendmsg(p_msg);
479 return (NFA_STATUS_OK);
480 }
481 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530482}
483
484/*******************************************************************************
485**
486** Function NFA_HciGetRegistry
487**
488** Description This function requests a peer host to return the desired
489** registry field value for the gate that the pipe is on.
490**
491** When the peer host responds,the app is notified with
492** NFA_HCI_GET_REG_RSP_EVT or
493** if an error occurs in sending the command the app will be
494** notified by NFA_HCI_CMD_SENT_EVT
495**
496** Returns NFA_STATUS_OK if successfully initiated
497** NFA_STATUS_FAILED otherwise
498**
499*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530500tNFA_STATUS NFA_HciGetRegistry(tNFA_HANDLE hci_handle, uint8_t pipe,
501 uint8_t reg_inx) {
502 tNFA_HCI_API_GET_REGISTRY* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530503
nxpandroid8f6d0532017-07-12 18:25:30 +0530504 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530505 DLOG_IF(INFO, nfc_debug_enabled)
506 << StringPrintf("Invalid hci_handle:0x%04x", hci_handle);
nxpandroidc7611652015-09-23 16:42:05 +0530507 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +0530508 }
509
510 if (pipe < NFA_HCI_FIRST_DYNAMIC_PIPE) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530511 DLOG_IF(INFO, nfc_debug_enabled)
512 << StringPrintf("Invalid Pipe:0x%02x", pipe);
nxpandroid8f6d0532017-07-12 18:25:30 +0530513 return (NFA_STATUS_FAILED);
514 }
515
nxf24591c1cbeab2018-02-21 17:32:26 +0530516 DLOG_IF(INFO, nfc_debug_enabled)
517 << StringPrintf("hci_handle:0x%04x Pipe: 0x%02x", hci_handle, pipe);
nxpandroid8f6d0532017-07-12 18:25:30 +0530518
519 /* Request HCI to get list of gates supported by the specified host */
520 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
521 ((p_msg = (tNFA_HCI_API_GET_REGISTRY*)GKI_getbuf(
522 sizeof(tNFA_HCI_API_GET_REGISTRY))) != NULL)) {
523 p_msg->hdr.event = NFA_HCI_API_GET_REGISTRY_EVT;
524 p_msg->hci_handle = hci_handle;
525 p_msg->pipe = pipe;
526 p_msg->reg_inx = reg_inx;
527
528 nfa_sys_sendmsg(p_msg);
529 return (NFA_STATUS_OK);
530 }
531
532 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530533}
534
535/*******************************************************************************
536**
nxpandroidc7611652015-09-23 16:42:05 +0530537** Function NFA_HciSendCommand
538**
539** Description This function is called to send a command on a pipe created
540** by the application.
541** The app will be notified by NFA_HCI_CMD_SENT_EVT if an error
542** occurs.
543** When the peer host responds,the app is notified with
544** NFA_HCI_RSP_RCVD_EVT
545**
546** Returns NFA_STATUS_OK if successfully initiated
547** NFA_STATUS_FAILED otherwise
548**
549*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530550tNFA_STATUS NFA_HciSendCommand(tNFA_HANDLE hci_handle, uint8_t pipe,
551 uint8_t cmd_code, uint16_t cmd_size,
552 uint8_t* p_data) {
553 tNFA_HCI_API_SEND_CMD_EVT* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530554
nxpandroid8f6d0532017-07-12 18:25:30 +0530555 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530556 DLOG_IF(INFO, nfc_debug_enabled)
557 << StringPrintf("Invalid hci_handle:0x%04x", hci_handle);
nxpandroidc7611652015-09-23 16:42:05 +0530558 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +0530559 }
560
561 if (pipe < NFA_HCI_FIRST_DYNAMIC_PIPE) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530562 DLOG_IF(INFO, nfc_debug_enabled)
563 << StringPrintf("Invalid Pipe:0x%02x", pipe);
nxpandroid8f6d0532017-07-12 18:25:30 +0530564 return (NFA_STATUS_FAILED);
565 }
566
567 if ((cmd_size && (p_data == NULL)) || (cmd_size > NFA_MAX_HCI_CMD_LEN)) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530568 DLOG_IF(INFO, nfc_debug_enabled)
569 << StringPrintf("Invalid cmd size:0x%02x", cmd_size);
nxpandroid8f6d0532017-07-12 18:25:30 +0530570 return (NFA_STATUS_FAILED);
571 }
572
nxf24591c1cbeab2018-02-21 17:32:26 +0530573 DLOG_IF(INFO, nfc_debug_enabled)
574 << StringPrintf("hci_handle:0x%04x, pipe:0x%02x Code: 0x%02x",
575 hci_handle, pipe, cmd_code);
nxpandroid8f6d0532017-07-12 18:25:30 +0530576
577 /* Request HCI to post event data on a particular pipe */
578 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
579 ((p_msg = (tNFA_HCI_API_SEND_CMD_EVT*)GKI_getbuf(
580 sizeof(tNFA_HCI_API_SEND_CMD_EVT))) != NULL)) {
581 p_msg->hdr.event = NFA_HCI_API_SEND_CMD_EVT;
582 p_msg->hci_handle = hci_handle;
583 p_msg->pipe = pipe;
584 p_msg->cmd_code = cmd_code;
585 p_msg->cmd_len = cmd_size;
586
587 if (cmd_size) memcpy(p_msg->data, p_data, cmd_size);
588
589 nfa_sys_sendmsg(p_msg);
590 return (NFA_STATUS_OK);
591 }
592
593 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530594}
595
596/*******************************************************************************
597**
nxpandroidc7611652015-09-23 16:42:05 +0530598** Function NFA_HciSendEvent
599**
600** Description This function is called to send any event on a pipe created
601** by the application.
602** The app will be notified by NFA_HCI_EVENT_SENT_EVT
603** after successfully sending the event on the specified pipe
604** or if an error occurs. The application should wait for this
605** event before releasing event buffer passed as argument.
606** If the app is expecting a response to the event then it can
607** provide response buffer for collecting the response. If it
608** provides a response buffer it can also provide response
609** timeout indicating maximum timeout for the response.
610** Maximum of NFA_MAX_HCI_EVENT_LEN bytes APDU can be received
611** using internal buffer if no response buffer is provided by
612** the application. The app will be notified by
613** NFA_HCI_EVENT_RCVD_EVT after receiving the response event
614** or on timeout if app provided response buffer and response
615** timeout. If response buffer and response timeout is provided
616** by the application, it should wait for this event before
617** releasing the response buffer. If the application did not
618** provide response timeout then it should not release the
619** response buffer until it receives NFA_HCI_EVENT_RCVD_EVT or
620** after timeout it sends next event on the same pipe
621** and receives NFA_HCI_EVENT_SENT_EVT for that event.
622**
623** Returns NFA_STATUS_OK if successfully initiated
624** NFA_STATUS_FAILED otherwise
625**
626*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530627tNFA_STATUS NFA_HciSendEvent(tNFA_HANDLE hci_handle, uint8_t pipe,
628 uint8_t evt_code, uint16_t evt_size,
629 uint8_t* p_data, uint16_t rsp_size,
nxf24591c1cbeab2018-02-21 17:32:26 +0530630 uint8_t* p_rsp_buf, uint16_t rsp_timeout) {
nxpandroid8f6d0532017-07-12 18:25:30 +0530631 tNFA_HCI_API_SEND_EVENT_EVT* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530632
nxf24591c1cbeab2018-02-21 17:32:26 +0530633 DLOG_IF(INFO, nfc_debug_enabled)
634 << StringPrintf("hci_handle:0x%04x, pipe:0x%02x Code: 0x%02x",
635 hci_handle, pipe, evt_code);
nxpandroidc7611652015-09-23 16:42:05 +0530636
nxpandroid8f6d0532017-07-12 18:25:30 +0530637 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530638 DLOG_IF(INFO, nfc_debug_enabled)
639 << StringPrintf("Invalid hci_handle:0x%04x", hci_handle);
nxpandroidc7611652015-09-23 16:42:05 +0530640 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +0530641 }
642
643 if (pipe < NFA_HCI_FIRST_DYNAMIC_PIPE) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530644 DLOG_IF(INFO, nfc_debug_enabled)
645 << StringPrintf("Invalid Pipe:0x%02x", pipe);
nxpandroid8f6d0532017-07-12 18:25:30 +0530646 return (NFA_STATUS_FAILED);
647 }
648
649 if (evt_size && (p_data == NULL)) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530650 DLOG_IF(INFO, nfc_debug_enabled)
651 << StringPrintf("Invalid Event size:0x%02x", evt_size);
nxpandroid8f6d0532017-07-12 18:25:30 +0530652 return (NFA_STATUS_FAILED);
653 }
654
655 if (rsp_size && (p_rsp_buf == NULL)) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530656 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
657 "No Event buffer, but invalid event buffer size "
nxpandroid8f6d0532017-07-12 18:25:30 +0530658 ":%u",
659 rsp_size);
660 return (NFA_STATUS_FAILED);
661 }
662
663 /* Request HCI to post event data on a particular pipe */
664 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
665 ((p_msg = (tNFA_HCI_API_SEND_EVENT_EVT*)GKI_getbuf(
666 sizeof(tNFA_HCI_API_SEND_EVENT_EVT))) != NULL)) {
667 p_msg->hdr.event = NFA_HCI_API_SEND_EVENT_EVT;
668 p_msg->hci_handle = hci_handle;
669 p_msg->pipe = pipe;
670 p_msg->evt_code = evt_code;
671 p_msg->evt_len = evt_size;
672 p_msg->p_evt_buf = p_data;
673 p_msg->rsp_len = rsp_size;
674 p_msg->p_rsp_buf = p_rsp_buf;
675 p_msg->rsp_timeout = rsp_timeout;
676
677 nfa_sys_sendmsg(p_msg);
678 return (NFA_STATUS_OK);
679 }
680
681 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530682}
683
684/*******************************************************************************
685**
686** Function NFA_HciClosePipe
687**
688** Description This function is called to close a dynamic pipe.
689** When the dynamic pipe is closed (or
690** if an error occurs), the app will be notified with
691** NFA_HCI_CLOSE_PIPE_EVT with the pipe id.
692**
693** Returns NFA_STATUS_OK if successfully initiated
694** NFA_STATUS_FAILED otherwise
695**
696*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530697tNFA_STATUS NFA_HciClosePipe(tNFA_HANDLE hci_handle, uint8_t pipe) {
698 tNFA_HCI_API_CLOSE_PIPE_EVT* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530699
nxf24591c1cbeab2018-02-21 17:32:26 +0530700 DLOG_IF(INFO, nfc_debug_enabled)
701 << StringPrintf("hci_handle:0x%04x, pipe:0x%02X", hci_handle, pipe);
nxpandroidc7611652015-09-23 16:42:05 +0530702
nxpandroid8f6d0532017-07-12 18:25:30 +0530703 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530704 DLOG_IF(INFO, nfc_debug_enabled)
705 << StringPrintf("Invalid hci_handle:0x%04x", hci_handle);
nxpandroidc7611652015-09-23 16:42:05 +0530706 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +0530707 }
708
709 if ((pipe < NFA_HCI_FIRST_DYNAMIC_PIPE) ||
710 (pipe > NFA_HCI_LAST_DYNAMIC_PIPE)) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530711 DLOG_IF(INFO, nfc_debug_enabled)
712 << StringPrintf("Invalid Pipe:0x%02x", pipe);
nxpandroid8f6d0532017-07-12 18:25:30 +0530713 return (NFA_STATUS_FAILED);
714 }
715
716 /* Request HCI to close a pipe if it is in opened state */
717 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
718 (!nfa_hci_cb.b_low_power_mode) &&
719 ((p_msg = (tNFA_HCI_API_CLOSE_PIPE_EVT*)GKI_getbuf(
720 sizeof(tNFA_HCI_API_CLOSE_PIPE_EVT))) != NULL)) {
721 p_msg->hdr.event = NFA_HCI_API_CLOSE_PIPE_EVT;
722 p_msg->hci_handle = hci_handle;
723 p_msg->pipe = pipe;
724
725 nfa_sys_sendmsg(p_msg);
726 return (NFA_STATUS_OK);
727 }
728 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530729}
730
731/*******************************************************************************
732**
733** Function NFA_HciDeletePipe
734**
735** Description This function is called to delete a particular dynamic pipe.
736** When the dynamic pipe is deleted (or if an error occurs),
737** the app will be notified with NFA_HCI_DELETE_PIPE_EVT with
738** the pipe id. After successful deletion of pipe, registry
739** entry will be deleted for the dynamic pipe and all
740** information related to the pipe will be deleted from non
741** volatile memory.
742**
743** Returns NFA_STATUS_OK if successfully initiated
744** NFA_STATUS_FAILED otherwise
745**
746*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530747tNFA_STATUS NFA_HciDeletePipe(tNFA_HANDLE hci_handle, uint8_t pipe) {
748 tNFA_HCI_API_DELETE_PIPE_EVT* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530749
nxpandroid8f6d0532017-07-12 18:25:30 +0530750 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530751 DLOG_IF(INFO, nfc_debug_enabled)
752 << StringPrintf("Invalid hci_handle:0x%04x", hci_handle);
nxpandroidc7611652015-09-23 16:42:05 +0530753 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +0530754 }
nxpandroidc7611652015-09-23 16:42:05 +0530755
nxpandroid8f6d0532017-07-12 18:25:30 +0530756 if ((pipe < NFA_HCI_FIRST_DYNAMIC_PIPE) ||
757 (pipe > NFA_HCI_LAST_DYNAMIC_PIPE)) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530758 DLOG_IF(INFO, nfc_debug_enabled)
759 << StringPrintf("Invalid Pipe:0x%02x", pipe);
nxpandroid8f6d0532017-07-12 18:25:30 +0530760 return (NFA_STATUS_FAILED);
761 }
762
nxf24591c1cbeab2018-02-21 17:32:26 +0530763 DLOG_IF(INFO, nfc_debug_enabled)
764 << StringPrintf("hci_handle:0x%04x, pipe:0x%02X", hci_handle, pipe);
nxpandroid8f6d0532017-07-12 18:25:30 +0530765
766 /* Request HCI to delete a pipe created by the application identified by hci
767 * handle */
768 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
769 (!nfa_hci_cb.b_low_power_mode) &&
770 ((p_msg = (tNFA_HCI_API_DELETE_PIPE_EVT*)GKI_getbuf(
771 sizeof(tNFA_HCI_API_DELETE_PIPE_EVT))) != NULL)) {
772 p_msg->hdr.event = NFA_HCI_API_DELETE_PIPE_EVT;
773 p_msg->hci_handle = hci_handle;
774 p_msg->pipe = pipe;
775
776 nfa_sys_sendmsg(p_msg);
777 return (NFA_STATUS_OK);
778 }
779 return (NFA_STATUS_FAILED);
780}
nxpandroidc7611652015-09-23 16:42:05 +0530781
782/*******************************************************************************
783**
784** Function NFA_HciAddStaticPipe
785**
786** Description This function is called to add a static pipe for sending
nxpandroid8f6d0532017-07-12 18:25:30 +0530787** 7816 APDUs. When the static pipe is added (or if an error
788** occurs), the app will be notified with
789** NFA_HCI_ADD_STATIC_PIPE_EVT with the status.
790**
nxpandroidc7611652015-09-23 16:42:05 +0530791** Returns NFA_STATUS_OK if successfully initiated
792** NFA_STATUS_FAILED otherwise
793**
794*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530795tNFA_STATUS NFA_HciAddStaticPipe(tNFA_HANDLE hci_handle, uint8_t host,
796 uint8_t gate, uint8_t pipe) {
797 tNFA_HCI_API_ADD_STATIC_PIPE_EVT* p_msg;
798 uint8_t xx;
nxpandroidc7611652015-09-23 16:42:05 +0530799
nxpandroid8f6d0532017-07-12 18:25:30 +0530800 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530801 DLOG_IF(INFO, nfc_debug_enabled)
802 << StringPrintf("Invalid hci_handle:0x%04x", hci_handle);
nxpandroidc7611652015-09-23 16:42:05 +0530803 return (NFA_STATUS_FAILED);
nxpandroid8f6d0532017-07-12 18:25:30 +0530804 }
805
806 for (xx = 0; xx < NFA_HCI_MAX_HOST_IN_NETWORK; xx++)
nxf24591c1cbeab2018-02-21 17:32:26 +0530807#if(NXP_EXTNS == TRUE)
808 if (nfa_hci_cb.active_host[xx] == host) break;
809
810 if (xx == NFA_HCI_MAX_HOST_IN_NETWORK) {
811#else
812
nxpandroid8f6d0532017-07-12 18:25:30 +0530813 if (nfa_hci_cb.inactive_host[xx] == host) break;
814
815 if (xx != NFA_HCI_MAX_HOST_IN_NETWORK) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530816#endif
817 DLOG_IF(INFO, nfc_debug_enabled)
818 << StringPrintf("NFA_HciAddStaticPipe (): Host not active:0x%02x", host);
nxpandroid8f6d0532017-07-12 18:25:30 +0530819 return (NFA_STATUS_FAILED);
820 }
821
nxf24591c1cbeab2018-02-21 17:32:26 +0530822 if (gate <= NFA_HCI_LAST_HOST_SPECIFIC_GATE) {
823 DLOG_IF(INFO, nfc_debug_enabled)
824 << StringPrintf("Invalid Gate:0x%02x", gate);
nxpandroid8f6d0532017-07-12 18:25:30 +0530825 return (NFA_STATUS_FAILED);
826 }
nxf24591c1cbeab2018-02-21 17:32:26 +0530827
nxpandroid8f6d0532017-07-12 18:25:30 +0530828 if (pipe <= NFA_HCI_LAST_DYNAMIC_PIPE) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530829 DLOG_IF(INFO, nfc_debug_enabled)
830 << StringPrintf("Invalid Pipe:0x%02x", pipe);
nxpandroid8f6d0532017-07-12 18:25:30 +0530831 return (NFA_STATUS_FAILED);
832 }
nxf24591c1cbeab2018-02-21 17:32:26 +0530833
834 DLOG_IF(INFO, nfc_debug_enabled)
835 << StringPrintf("hci_handle:0x%04x, pipe:0x%02X", hci_handle, pipe);
nxpandroid8f6d0532017-07-12 18:25:30 +0530836
837 /* Request HCI to delete a pipe created by the application identified by hci
838 * handle */
839 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
840 ((p_msg = (tNFA_HCI_API_ADD_STATIC_PIPE_EVT*)GKI_getbuf(
841 sizeof(tNFA_HCI_API_ADD_STATIC_PIPE_EVT))) != NULL)) {
842 p_msg->hdr.event = NFA_HCI_API_ADD_STATIC_PIPE_EVT;
843 p_msg->hci_handle = hci_handle;
844 p_msg->host = host;
845 p_msg->gate = gate;
846 p_msg->pipe = pipe;
847
848 nfa_sys_sendmsg(p_msg);
849 return (NFA_STATUS_OK);
850 }
851 /* Unable to add static pipe */
852 return (NFA_STATUS_FAILED);
nxpandroidc7611652015-09-23 16:42:05 +0530853}
854
855/*******************************************************************************
856**
857** Function NFA_HciDebug
858**
859** Description Debug function.
860**
861*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530862void NFA_HciDebug(uint8_t action, uint8_t size, uint8_t* p_data) {
863 int xx;
864 tNFA_HCI_DYN_GATE* pg = nfa_hci_cb.cfg.dyn_gates;
865 tNFA_HCI_DYN_PIPE* pp = nfa_hci_cb.cfg.dyn_pipes;
866 NFC_HDR* p_msg;
867 uint8_t* p;
nxpandroidc7611652015-09-23 16:42:05 +0530868
nxpandroid8f6d0532017-07-12 18:25:30 +0530869 switch (action) {
nxpandroidc7611652015-09-23 16:42:05 +0530870 case NFA_HCI_DEBUG_DISPLAY_CB:
nxf24591c1cbeab2018-02-21 17:32:26 +0530871 DLOG_IF(INFO, nfc_debug_enabled)
872 << StringPrintf("NFA_HciDebug Host List:");
nxpandroid8f6d0532017-07-12 18:25:30 +0530873 for (xx = 0; xx < NFA_HCI_MAX_APP_CB; xx++) {
874 if (nfa_hci_cb.cfg.reg_app_names[xx][0] != 0) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530875 DLOG_IF(INFO, nfc_debug_enabled)
876 << StringPrintf(" Host Inx: %u Name: %s", xx,
877 &nfa_hci_cb.cfg.reg_app_names[xx][0]);
nxpandroidc7611652015-09-23 16:42:05 +0530878 }
nxpandroid8f6d0532017-07-12 18:25:30 +0530879 }
nxpandroidc7611652015-09-23 16:42:05 +0530880
nxf24591c1cbeab2018-02-21 17:32:26 +0530881 DLOG_IF(INFO, nfc_debug_enabled)
882 << StringPrintf("NFA_HciDebug Gate List:");
nxpandroid8f6d0532017-07-12 18:25:30 +0530883 for (xx = 0; xx < NFA_HCI_MAX_GATE_CB; xx++, pg++) {
884 if (pg->gate_id != 0) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530885 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
nxpandroid8f6d0532017-07-12 18:25:30 +0530886 " Gate Inx: %x ID: 0x%02x Owner: 0x%04x "
887 "PipeInxMask: 0x%08x",
888 xx, pg->gate_id, pg->gate_owner, pg->pipe_inx_mask);
nxpandroidc7611652015-09-23 16:42:05 +0530889 }
nxpandroid8f6d0532017-07-12 18:25:30 +0530890 }
nxpandroidc7611652015-09-23 16:42:05 +0530891
nxf24591c1cbeab2018-02-21 17:32:26 +0530892 DLOG_IF(INFO, nfc_debug_enabled)
893 << StringPrintf("NFA_HciDebug Pipe List:");
nxpandroid8f6d0532017-07-12 18:25:30 +0530894 for (xx = 0; xx < NFA_HCI_MAX_PIPE_CB; xx++, pp++) {
895 if (pp->pipe_id != 0) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530896 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
897 " Pipe Inx: %x ID: 0x%02x State: %u "
898 "LocalGate: "
nxpandroid8f6d0532017-07-12 18:25:30 +0530899 "0x%02x Dest Gate: 0x%02x Host: 0x%02x",
900 xx, pp->pipe_id, pp->pipe_state, pp->local_gate, pp->dest_gate,
901 pp->dest_host);
nxpandroidc7611652015-09-23 16:42:05 +0530902 }
nxpandroid8f6d0532017-07-12 18:25:30 +0530903 }
904 break;
nxpandroidc7611652015-09-23 16:42:05 +0530905
906 case NFA_HCI_DEBUG_SIM_HCI_EVENT:
nxpandroid8f6d0532017-07-12 18:25:30 +0530907 p_msg = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID);
908 if (p_msg != NULL) {
909 p = (uint8_t*)(p_msg + 1);
nxpandroidc7611652015-09-23 16:42:05 +0530910
nxpandroid8f6d0532017-07-12 18:25:30 +0530911 p_msg->event = NFA_HCI_CHECK_QUEUE_EVT;
912 p_msg->len = size;
913 p_msg->offset = 0;
nxpandroidc7611652015-09-23 16:42:05 +0530914
nxpandroid8f6d0532017-07-12 18:25:30 +0530915 memcpy(p, p_data, size);
nxpandroidc7611652015-09-23 16:42:05 +0530916
nxpandroid8f6d0532017-07-12 18:25:30 +0530917 nfa_sys_sendmsg(p_msg);
918 }
919 break;
nxpandroidc7611652015-09-23 16:42:05 +0530920
921 case NFA_HCI_DEBUG_ENABLE_LOOPBACK:
nxf24591c1cbeab2018-02-21 17:32:26 +0530922 DLOG_IF(INFO, nfc_debug_enabled)
923 << StringPrintf("NFA_HciDebug HCI_LOOPBACK_DEBUG = TRUE");
924 HCI_LOOPBACK_DEBUG = NFA_HCI_DEBUG_ON;
nxpandroid8f6d0532017-07-12 18:25:30 +0530925 break;
nxpandroidc7611652015-09-23 16:42:05 +0530926
927 case NFA_HCI_DEBUG_DISABLE_LOOPBACK:
nxf24591c1cbeab2018-02-21 17:32:26 +0530928 DLOG_IF(INFO, nfc_debug_enabled)
929 << StringPrintf("NFA_HciDebug HCI_LOOPBACK_DEBUG = FALSE");
930 HCI_LOOPBACK_DEBUG = NFA_HCI_DEBUG_OFF;
nxpandroid8f6d0532017-07-12 18:25:30 +0530931 break;
932 }
nxpandroidc7611652015-09-23 16:42:05 +0530933}
nxpandroid84a71e02017-08-14 11:58:25 +0530934
nxpandroidc7611652015-09-23 16:42:05 +0530935/*******************************************************************************
936**
nxf24591c1cbeab2018-02-21 17:32:26 +0530937** Function NFA_HciSetRegistry
nxpandroidc7611652015-09-23 16:42:05 +0530938**
nxf24591c1cbeab2018-02-21 17:32:26 +0530939** Description This function requests a peer host to set the desired
940** registry field value for the gate that the pipe is on.
nxpandroid3e4012e2016-08-01 19:09:55 +0530941**
942** When the peer host responds,the app is notified with
nxf24591c1cbeab2018-02-21 17:32:26 +0530943** NFA_HCI_SET_REG_RSP_EVT or
944** if an error occurs in sending the command the app will be
945** notified by NFA_HCI_CMD_SENT_EVT
nxpandroid3e4012e2016-08-01 19:09:55 +0530946**
947** Returns NFA_STATUS_OK if successfully initiated
948** NFA_STATUS_FAILED otherwise
949**
950*******************************************************************************/
nxf24591c1cbeab2018-02-21 17:32:26 +0530951extern tNFA_STATUS NFA_HciSetRegistry(tNFA_HANDLE hci_handle, uint8_t pipe,
952 uint8_t reg_inx, uint8_t data_size,
953 uint8_t* p_data) {
954 tNFA_HCI_API_SET_REGISTRY* p_msg;
nxpandroid3e4012e2016-08-01 19:09:55 +0530955
nxf24591c1cbeab2018-02-21 17:32:26 +0530956 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI) {
957 DLOG_IF(INFO, nfc_debug_enabled)
958 << StringPrintf("NFA_HciSetRegistry (): Invalid hci_handle:0x%04x",
959 hci_handle);
960 return (NFA_STATUS_FAILED);
961 }
962
963 if (pipe < NFA_HCI_FIRST_DYNAMIC_PIPE) {
964 DLOG_IF(INFO, nfc_debug_enabled)
965 << StringPrintf("NFA_HciSetRegistry (): Invalid Pipe:0x%02x", pipe);
966 return (NFA_STATUS_FAILED);
967 }
968
969 if ((data_size == 0) || (p_data == NULL) ||
970 (data_size > NFA_MAX_HCI_CMD_LEN)) {
971 DLOG_IF(INFO, nfc_debug_enabled)
972 << StringPrintf("NFA_HciSetRegistry (): Invalid data size:0x%02x",
973 data_size);
974 return (NFA_STATUS_FAILED);
975 }
976
977 DLOG_IF(INFO, nfc_debug_enabled)
978 << StringPrintf("NFA_HciSetRegistry (): hci_handle:0x%04x Pipe: 0x%02x",
979 hci_handle, pipe);
980
981 /* Request HCI to get list of gates supported by the specified host */
nxpandroid8f6d0532017-07-12 18:25:30 +0530982 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
nxf24591c1cbeab2018-02-21 17:32:26 +0530983 ((p_msg = (tNFA_HCI_API_SET_REGISTRY*)GKI_getbuf(
984 sizeof(tNFA_HCI_API_SET_REGISTRY))) != NULL)) {
985 p_msg->hdr.event = NFA_HCI_API_SET_REGISTRY_EVT;
986 p_msg->hci_handle = hci_handle;
987 p_msg->pipe = pipe;
988 p_msg->reg_inx = reg_inx;
989 p_msg->size = data_size;
990
991 memcpy(p_msg->data, p_data, data_size);
nxpandroid8f6d0532017-07-12 18:25:30 +0530992 nfa_sys_sendmsg(p_msg);
993 return (NFA_STATUS_OK);
994 }
nxpandroid3e4012e2016-08-01 19:09:55 +0530995
nxpandroid8f6d0532017-07-12 18:25:30 +0530996 return (NFA_STATUS_FAILED);
nxpandroid3e4012e2016-08-01 19:09:55 +0530997}
nxf24591c1cbeab2018-02-21 17:32:26 +0530998/*******************************************************************************
999**
1000** Function NFA_HciSendResponse
1001**
1002** Description This function is called to send a response on a pipe created
1003** by the application.
1004** The app will be notified by NFA_HCI_RSP_SENT_EVT if an error
1005** occurs.
1006**
1007** Returns NFA_STATUS_OK if successfully initiated
1008** NFA_STATUS_FAILED otherwise
1009**
1010*******************************************************************************/
1011extern tNFA_STATUS NFA_HciSendResponse(tNFA_HANDLE hci_handle, uint8_t pipe,
1012 uint8_t response, uint8_t data_size,
1013 uint8_t* p_data) {
1014 tNFA_HCI_API_SEND_RSP_EVT* p_msg;
1015
1016 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI) {
1017 DLOG_IF(INFO, nfc_debug_enabled)
1018 << StringPrintf("NFA_HciSendResponse (): Invalid hci_handle:0x%04x",
1019 hci_handle);
1020 return (NFA_STATUS_FAILED);
1021 }
1022
1023 if (pipe < NFA_HCI_FIRST_DYNAMIC_PIPE) {
1024 DLOG_IF(INFO, nfc_debug_enabled)
1025 << StringPrintf("NFA_HciSendResponse (): Invalid Pipe:0x%02x", pipe);
1026 return (NFA_STATUS_FAILED);
1027 }
1028
1029 if ((data_size && (p_data == NULL)) || (data_size > NFA_MAX_HCI_RSP_LEN)) {
1030 DLOG_IF(INFO, nfc_debug_enabled)
1031 << StringPrintf("NFA_HciSendResponse (): Invalid data size:0x%02x",
1032 data_size);
1033 return (NFA_STATUS_FAILED);
1034 }
1035
1036 DLOG_IF(INFO, nfc_debug_enabled)
1037 << StringPrintf(
1038 "NFA_HciSendResponse (): hci_handle:0x%04x Pipe: 0x%02x Response: "
1039 "0x%02x",
1040 hci_handle, pipe, response);
1041
1042 /* Request HCI to get list of gates supported by the specified host */
1043 if ((nfa_hci_cb.hci_state != NFA_HCI_STATE_DISABLED) &&
1044 ((p_msg = (tNFA_HCI_API_SEND_RSP_EVT*)GKI_getbuf(
1045 sizeof(tNFA_HCI_API_SEND_RSP_EVT))) != NULL)) {
1046 p_msg->hdr.event = NFA_HCI_API_SEND_RSP_EVT;
1047 p_msg->hci_handle = hci_handle;
1048 p_msg->response = response;
1049 p_msg->size = data_size;
1050
1051 if (data_size) memcpy(p_msg->data, p_data, data_size);
1052
1053 nfa_sys_sendmsg(p_msg);
1054 return (NFA_STATUS_OK);
1055 }
1056
1057 return (NFA_STATUS_FAILED);
1058}
1059
1060#if(NXP_EXTNS == TRUE)
1061/*******************************************************************************
1062**
1063** Function NFA_HciSendApdu
1064**
1065** Description This function is called to send APDU commands to one of
1066** the host that acts as a server APDU host and to receive
1067** response from that host on APDU pipe.
1068**
1069** The application will be notified by NFA_HCI_CMD_APDU_SENT_EVT
1070** after successfully sending the APDU command on APDU pipe of
1071** the specified host or if an error occurs. The application
1072** should wait for this event before releasing APDU command
1073** buffer passed as an argument. The application should provide
1074** response APDU buffer for collecting the response APDU.
1075** The application will be notified by NFA_HCI_RSP_APDU_RCVD_EVT
1076** after receiving the response APDU or on timeout if timeout
1077** can be automatically detected on the pipe (If APDU Pipe is
1078** connected to APDU Gate implemented as per spec ETSI TS 102
1079** 622 V12.1.0) on destination host.
1080** If a response buffer is provided by the application, it
1081** should wait for NFA_HCI_RSP_APDU_RCVD_EVT event or call
1082** NFA_HciAbortApdu and wait for NFA_HCI_APDU_ABORTED_EVT
1083** before releasing the response APDU buffer.
1084**
1085** Returns NFA_STATUS_OK if successfully initiated
1086** NFA_STATUS_FAILED otherwise
1087**
1088*******************************************************************************/
1089tNFC_STATUS NFA_HciSendApdu (tNFA_HANDLE hci_handle,
1090 uint8_t host_id,
1091 uint16_t cmd_apdu_len,
1092 uint8_t *p_cmd_apdu,
1093 uint16_t rsp_apdu_buf_size,
1094 uint8_t *p_rsp_apdu_buf,
1095 uint32_t rsp_timeout)
1096{
1097 tNFA_HCI_API_SEND_APDU_EVT *p_msg;
1098
1099 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI)
1100 {
1101 DLOG_IF(INFO, nfc_debug_enabled)
1102 << StringPrintf ("NFA_HciSendApdu (): Invalid hci_handle:0x%04x", hci_handle);
1103 return (NFA_STATUS_FAILED);
1104 }
1105 if (!nfa_hciu_is_active_host (host_id))
1106 {
1107 DLOG_IF(INFO, nfc_debug_enabled)
1108 << StringPrintf ("NFA_HciAbortApdu (): Host not active:0x%02x", host_id);
1109 return (NFA_STATUS_FAILED);
1110 }
1111
1112 if (!cmd_apdu_len || (p_cmd_apdu == NULL))
1113 {
1114 DLOG_IF(INFO, nfc_debug_enabled)
1115 << StringPrintf ("NFA_HciSendApdu (): Invalid Command APDU size:0x%02x", cmd_apdu_len);
1116 return (NFA_STATUS_FAILED);
1117 }
1118
1119 if (rsp_apdu_buf_size && (p_rsp_apdu_buf == NULL))
1120 {
1121 DLOG_IF(INFO, nfc_debug_enabled)
1122 << StringPrintf ("NFA_HciSendApdu (): No Rsp APDU buf, but invalid Rsp APDU buf size :%u",
1123 rsp_apdu_buf_size);
1124
1125 return (NFA_STATUS_FAILED);
1126 }
1127
1128 if (nfa_hci_cb.hci_state == NFA_HCI_STATE_DISABLED)
1129 {
1130 DLOG_IF(INFO, nfc_debug_enabled)
1131 << StringPrintf ("NFA_HciSendApdu (): Invalid HCI State[0x%02x]", nfa_hci_cb.hci_state);
1132 return (NFA_STATUS_FAILED);
1133 }
1134
1135 DLOG_IF(INFO, nfc_debug_enabled)
1136 << StringPrintf ("NFA_HciSendApdu(): hci_handle:0x%04x, Server APDU host:0x%02x",
1137 hci_handle, host_id);
1138
1139 p_msg = (tNFA_HCI_API_SEND_APDU_EVT *) GKI_getbuf (sizeof (tNFA_HCI_API_SEND_APDU_EVT));
1140
1141
1142 /* Request HCI to Send data on APDU pipe connected to specified UICC host */
1143 if (p_msg != NULL)
1144 {
1145 p_msg->hdr.event = NFA_HCI_API_SEND_APDU_EVT;
1146 p_msg->hci_handle = hci_handle;
1147 p_msg->host_id = host_id;
1148 p_msg->cmd_apdu_len = cmd_apdu_len;
1149 p_msg->p_cmd_apdu = p_cmd_apdu;
1150 p_msg->rsp_apdu_buf_size = rsp_apdu_buf_size;
1151 p_msg->p_rsp_apdu_buf = p_rsp_apdu_buf;
1152 p_msg->rsp_timeout = rsp_timeout;
1153
1154 nfa_sys_sendmsg (p_msg);
1155 return (NFA_STATUS_OK);
1156 }
1157
1158 return (NFA_STATUS_FAILED);
1159}
1160
1161/*******************************************************************************
1162**
1163** Function NFA_HciAbortApdu
1164**
1165** Description This function is called to stop waiting for response APDU
1166** for the command APDU sent by the application on the APDU pipe
1167** of the specified host. The application will be notified by
1168** NFA_HCI_APDU_ABORTED_EVT after releasing response buffer
1169** provided with NFA_HciSendApdu for collecting the response
1170** APDU and releasing the APDU pipe for sending next command
1171** APDU on the pipe.
1172** If APDU server host supports EVT_ABORT then the server host
1173** is also notified to Abort the APDU command and wait for
1174** it to confirm with EVT_ATR that it stopped processing the
1175** command APDU before releasing the response buffer and
1176** reporting NFA_HCI_APDU_ABORTED_EVT to the application
1177**
1178** Returns NFA_STATUS_OK if successfully initiated
1179** NFA_STATUS_FAILED otherwise
1180**
1181*******************************************************************************/
1182tNFC_STATUS NFA_HciAbortApdu (tNFA_HANDLE hci_handle, uint8_t host_id, uint32_t rsp_timeout)
1183{
1184 tNFA_HCI_API_ABORT_APDU_EVT *p_msg;
1185
1186 if ((NFA_HANDLE_GROUP_MASK & hci_handle) != NFA_HANDLE_GROUP_HCI)
1187 {
1188 DLOG_IF(INFO, nfc_debug_enabled)
1189 << StringPrintf ("NFA_HciAbortApdu (): Invalid hci_handle:0x%04x", hci_handle);
1190 return (NFA_STATUS_FAILED);
1191 }
1192
1193 if (!nfa_hciu_is_active_host (host_id))
1194 {
1195 DLOG_IF(INFO, nfc_debug_enabled)
1196 << StringPrintf ("NFA_HciAbortApdu (): Host not active:0x%02x", host_id);
1197 return (NFA_STATUS_FAILED);
1198 }
1199
1200 if (nfa_hci_cb.hci_state == NFA_HCI_STATE_DISABLED)
1201 {
1202 DLOG_IF(INFO, nfc_debug_enabled)
1203 << StringPrintf ("NFA_HciAbortApdu (): Invalid HCI State[0x%02x]", nfa_hci_cb.hci_state);
1204 return (NFA_STATUS_FAILED);
1205 }
1206
1207 DLOG_IF(INFO, nfc_debug_enabled)
1208 << StringPrintf ("NFA_HciAbortApdu (): hci_handle:0x%04x, host:0x%02X", hci_handle, host_id);
1209
1210 p_msg = (tNFA_HCI_API_ABORT_APDU_EVT *) GKI_getbuf (sizeof (tNFA_HCI_API_ABORT_APDU_EVT));
1211
1212 /* Request HCI to Abort the command APDU sent on APDU pipe */
1213 if (p_msg != NULL)
1214 {
1215 p_msg->hdr.event = NFA_HCI_API_ABORT_APDU_EVT;
1216 p_msg->hci_handle = hci_handle;
1217 p_msg->host_id = host_id;
1218 p_msg->rsp_timeout = rsp_timeout;
1219 nfa_sys_sendmsg (p_msg);
1220 return (NFA_STATUS_OK);
1221 }
1222 /* Unable to Abort command APDU */
1223 return (NFA_STATUS_FAILED);
1224}
1225#endif