blob: 743034d32787adad7fce889ddd11742bc0ecb83a [file] [log] [blame]
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001/******************************************************************************
2 *
Evan Chue9629ba2014-01-31 11:18:47 -05003 * Copyright (C) 2010-2014 Broadcom Corporation
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08004 *
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 action functions for NFA-EE
22 *
23 ******************************************************************************/
24#include <string.h>
Andre Eisenbach8a4edf62017-11-20 14:51:11 -080025
26#include <android-base/stringprintf.h>
27#include <base/logging.h>
28
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080029#include "nfa_api.h"
30#include "nfa_dm_int.h"
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080031#include "nfa_ee_int.h"
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080032
Andre Eisenbach8a4edf62017-11-20 14:51:11 -080033using android::base::StringPrintf;
34
35extern bool nfc_debug_enabled;
36
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080037/* the de-bounce timer:
38 * The NFA-EE API functions are called to set the routing and VS configuration.
39 * When this timer expires, the configuration is sent to NFCC all at once.
40 * This is the timeout value for the de-bounce timer. */
41#ifndef NFA_EE_ROUT_TIMEOUT_VAL
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080042#define NFA_EE_ROUT_TIMEOUT_VAL 1000
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080043#endif
44
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080045#define NFA_EE_ROUT_BUF_SIZE 540
46#define NFA_EE_ROUT_MAX_TLV_SIZE 0xFD
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080047
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080048/* the following 2 tables convert the technology mask in API and control block
49 * to the command for NFCC */
50#define NFA_EE_NUM_TECH 3
51const uint8_t nfa_ee_tech_mask_list[NFA_EE_NUM_TECH] = {
52 NFA_TECHNOLOGY_MASK_A, NFA_TECHNOLOGY_MASK_B, NFA_TECHNOLOGY_MASK_F};
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080053
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080054const uint8_t nfa_ee_tech_list[NFA_EE_NUM_TECH] = {
55 NFC_RF_TECHNOLOGY_A, NFC_RF_TECHNOLOGY_B, NFC_RF_TECHNOLOGY_F};
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080056
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080057/* the following 2 tables convert the protocol mask in API and control block to
58 * the command for NFCC */
59#define NFA_EE_NUM_PROTO 5
Love Khannab4ac88d2017-04-06 16:25:36 +053060
Arach MOHAMMED BRAHIM2f08f7a2017-07-12 10:20:10 +020061static void add_route_tech_proto_tlv(uint8_t** pp, uint8_t tlv_type,
Love Khannab4ac88d2017-04-06 16:25:36 +053062 uint8_t nfcee_id, uint8_t pwr_cfg,
63 uint8_t tech_proto) {
Arach MOHAMMED BRAHIM2f08f7a2017-07-12 10:20:10 +020064 *(*pp)++ = tlv_type;
65 *(*pp)++ = 3;
66 *(*pp)++ = nfcee_id;
67 *(*pp)++ = pwr_cfg;
68 *(*pp)++ = tech_proto;
Love Khannab4ac88d2017-04-06 16:25:36 +053069}
70
Arach MOHAMMED BRAHIM2f08f7a2017-07-12 10:20:10 +020071static void add_route_aid_tlv(uint8_t** pp, uint8_t* pa, uint8_t nfcee_id,
Love Khannaf3c018a2017-05-11 18:34:32 +053072 uint8_t pwr_cfg, uint8_t tag) {
Love Khannab4ac88d2017-04-06 16:25:36 +053073 pa++; /* EMV tag */
74 uint8_t len = *pa++; /* aid_len */
Arach MOHAMMED BRAHIM2f08f7a2017-07-12 10:20:10 +020075 *(*pp)++ = tag;
76 *(*pp)++ = len + 2;
77 *(*pp)++ = nfcee_id;
78 *(*pp)++ = pwr_cfg;
Love Khannab4ac88d2017-04-06 16:25:36 +053079 /* copy the AID */
Arach MOHAMMED BRAHIM2f08f7a2017-07-12 10:20:10 +020080 memcpy(*pp, pa, len);
81 *pp += len;
Love Khannab4ac88d2017-04-06 16:25:36 +053082}
83
Love Khanna1d062772018-04-10 21:10:02 +053084static void add_route_sys_code_tlv(uint8_t** p_buff, uint8_t* p_sys_code_cfg,
85 uint8_t sys_code_rt_loc,
86 uint8_t sys_code_pwr_cfg) {
87 *(*p_buff)++ = NFC_ROUTE_TAG_SYSCODE | nfa_ee_cb.route_block_control;
88 *(*p_buff)++ = NFA_EE_SYSTEM_CODE_LEN + 2;
89 *(*p_buff)++ = sys_code_rt_loc;
90 *(*p_buff)++ = sys_code_pwr_cfg;
91 /* copy the system code */
92 memcpy(*p_buff, p_sys_code_cfg, NFA_EE_SYSTEM_CODE_LEN);
93 *p_buff += NFA_EE_SYSTEM_CODE_LEN;
94}
95
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080096const uint8_t nfa_ee_proto_mask_list[NFA_EE_NUM_PROTO] = {
97 NFA_PROTOCOL_MASK_T1T, NFA_PROTOCOL_MASK_T2T, NFA_PROTOCOL_MASK_T3T,
98 NFA_PROTOCOL_MASK_ISO_DEP, NFA_PROTOCOL_MASK_NFC_DEP};
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080099
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800100const uint8_t nfa_ee_proto_list[NFA_EE_NUM_PROTO] = {
101 NFC_PROTOCOL_T1T, NFC_PROTOCOL_T2T, NFC_PROTOCOL_T3T, NFC_PROTOCOL_ISO_DEP,
102 NFC_PROTOCOL_NFC_DEP};
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800103
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800104static void nfa_ee_report_discover_req_evt(void);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800105static void nfa_ee_build_discover_req_evt(tNFA_EE_DISCOVER_REQ* p_evt_data);
Love Khannab4ac88d2017-04-06 16:25:36 +0530106void nfa_ee_check_set_routing(uint16_t new_size, int* p_max_len, uint8_t* p,
107 int* p_cur_offset);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800108/*******************************************************************************
109**
Paul Chaissonf23dcad2013-11-25 16:51:23 -0500110** Function nfa_ee_trace_aid
111**
112** Description trace AID
113**
114** Returns void
115**
116*******************************************************************************/
Ruchi Kandoi7dab0e52017-08-03 13:09:49 -0700117static void nfa_ee_trace_aid(std::string p_str, uint8_t id, uint8_t aid_len,
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800118 uint8_t* p) {
119 int len = aid_len;
120 int xx, yy = 0;
121 char buff[100];
Paul Chaissonf23dcad2013-11-25 16:51:23 -0500122
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800123 buff[0] = 0;
124 if (aid_len > NFA_MAX_AID_LEN) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700125 LOG(ERROR) << StringPrintf("aid_len: %d exceeds max(%d)", aid_len,
126 NFA_MAX_AID_LEN);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800127 len = NFA_MAX_AID_LEN;
128 }
129 for (xx = 0; xx < len; xx++) {
130 yy += sprintf(&buff[yy], "%02x ", *p);
131 p++;
132 }
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700133 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
134 "%s id:0x%x len=%d aid:%s", p_str.c_str(), id, aid_len, buff);
Paul Chaissonf23dcad2013-11-25 16:51:23 -0500135}
Sherry Smith43ef6452013-12-02 15:44:52 -0800136
137/*******************************************************************************
138**
139** Function nfa_ee_update_route_size
140**
141** Description Update the size required for technology and protocol routing
142** of the given NFCEE ID.
143**
144** Returns void
145**
146*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800147static void nfa_ee_update_route_size(tNFA_EE_ECB* p_cb) {
148 int xx;
149 uint8_t power_cfg = 0;
Sherry Smith43ef6452013-12-02 15:44:52 -0800150
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800151 p_cb->size_mask = 0;
152 /* add the Technology based routing */
153 for (xx = 0; xx < NFA_EE_NUM_TECH; xx++) {
154 power_cfg = 0;
155 if (p_cb->tech_switch_on & nfa_ee_tech_mask_list[xx])
156 power_cfg |= NCI_ROUTE_PWR_STATE_ON;
157 if (p_cb->tech_switch_off & nfa_ee_tech_mask_list[xx])
158 power_cfg |= NCI_ROUTE_PWR_STATE_SWITCH_OFF;
159 if (p_cb->tech_battery_off & nfa_ee_tech_mask_list[xx])
160 power_cfg |= NCI_ROUTE_PWR_STATE_BATT_OFF;
Love Khanna514a14b2018-03-23 00:19:13 +0530161 if ((power_cfg & NCI_ROUTE_PWR_STATE_ON) &&
162 (NFC_GetNCIVersion() == NCI_VERSION_2_0)) {
163 if (p_cb->tech_screen_lock & nfa_ee_tech_mask_list[xx])
164 power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_ON_LOCK();
165 if (p_cb->tech_screen_off & nfa_ee_tech_mask_list[xx])
166 power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_OFF_UNLOCK();
167 if (p_cb->tech_screen_off_lock & nfa_ee_tech_mask_list[xx])
168 power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_OFF_LOCK();
169 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800170 if (power_cfg) {
Love Khanna514a14b2018-03-23 00:19:13 +0530171 /* 5 = 1 (tag) + 1 (len) + 1(nfcee_id) + 1(power cfg) + 1 (technology) */
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800172 p_cb->size_mask += 5;
Sherry Smith43ef6452013-12-02 15:44:52 -0800173 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800174 }
Sherry Smith43ef6452013-12-02 15:44:52 -0800175
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800176 /* add the Protocol based routing */
177 for (xx = 0; xx < NFA_EE_NUM_PROTO; xx++) {
178 power_cfg = 0;
179 if (p_cb->proto_switch_on & nfa_ee_proto_mask_list[xx])
180 power_cfg |= NCI_ROUTE_PWR_STATE_ON;
181 if (p_cb->proto_switch_off & nfa_ee_proto_mask_list[xx])
182 power_cfg |= NCI_ROUTE_PWR_STATE_SWITCH_OFF;
183 if (p_cb->proto_battery_off & nfa_ee_proto_mask_list[xx])
184 power_cfg |= NCI_ROUTE_PWR_STATE_BATT_OFF;
Love Khanna514a14b2018-03-23 00:19:13 +0530185 if ((power_cfg & NCI_ROUTE_PWR_STATE_ON) &&
186 (NFC_GetNCIVersion() == NCI_VERSION_2_0)) {
187 if (p_cb->proto_screen_lock & nfa_ee_proto_mask_list[xx])
188 power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_ON_LOCK();
189 if (p_cb->proto_screen_off & nfa_ee_proto_mask_list[xx])
190 power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_OFF_UNLOCK();
191 if (p_cb->proto_screen_off_lock & nfa_ee_proto_mask_list[xx])
192 power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_OFF_LOCK();
193 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800194 if (power_cfg) {
195 /* 5 = 1 (tag) + 1 (len) + 1(nfcee_id) + 1(power cfg) + 1 (protocol) */
196 p_cb->size_mask += 5;
Sherry Smith43ef6452013-12-02 15:44:52 -0800197 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800198 }
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700199 DLOG_IF(INFO, nfc_debug_enabled)
200 << StringPrintf("nfa_ee_update_route_size nfcee_id:0x%x size_mask:%d",
201 p_cb->nfcee_id, p_cb->size_mask);
Sherry Smith43ef6452013-12-02 15:44:52 -0800202}
203
204/*******************************************************************************
205**
206** Function nfa_ee_update_route_aid_size
207**
208** Description Update the size required for AID routing
209** of the given NFCEE ID.
210**
211** Returns void
212**
213*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800214static void nfa_ee_update_route_aid_size(tNFA_EE_ECB* p_cb) {
215 uint8_t *pa, len;
216 int start_offset;
217 int xx;
Sherry Smith43ef6452013-12-02 15:44:52 -0800218
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800219 p_cb->size_aid = 0;
220 if (p_cb->aid_entries) {
221 start_offset = 0;
222 for (xx = 0; xx < p_cb->aid_entries; xx++) {
223 /* add one AID entry */
224 if (p_cb->aid_rt_info[xx] & NFA_EE_AE_ROUTE) {
225 pa = &p_cb->aid_cfg[start_offset];
226 pa++; /* EMV tag */
227 len = *pa++; /* aid_len */
228 /* 4 = 1 (tag) + 1 (len) + 1(nfcee_id) + 1(power cfg) */
229 p_cb->size_aid += 4;
230 p_cb->size_aid += len;
231 }
232 start_offset += p_cb->aid_len[xx];
Sherry Smith43ef6452013-12-02 15:44:52 -0800233 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800234 }
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700235 DLOG_IF(INFO, nfc_debug_enabled)
236 << StringPrintf("nfa_ee_update_route_aid_size nfcee_id:0x%x size_aid:%d",
237 p_cb->nfcee_id, p_cb->size_aid);
Sherry Smith43ef6452013-12-02 15:44:52 -0800238}
239
240/*******************************************************************************
241**
Love Khanna1d062772018-04-10 21:10:02 +0530242** Function nfa_ee_update_route_sys_code_size
243**
244** Description Update the size required for system code routing
245** of the given NFCEE ID.
246**
247** Returns void
248**
249*******************************************************************************/
250static void nfa_ee_update_route_sys_code_size(tNFA_EE_ECB* p_cb) {
251 p_cb->size_sys_code = 0;
252 if (p_cb->sys_code_cfg_entries) {
253 for (uint8_t xx = 0; xx < p_cb->sys_code_cfg_entries; xx++) {
254 if (p_cb->sys_code_rt_loc_vs_info[xx] & NFA_EE_AE_ROUTE) {
255 /* 4 = 1 (tag) + 1 (len) + 1(nfcee_id) + 1(power cfg) */
256 p_cb->size_sys_code += 4;
257 p_cb->size_sys_code += NFA_EE_SYSTEM_CODE_LEN;
258 }
259 }
260 }
261 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
262 "nfa_ee_update_route_sys_code_size nfcee_id:0x%x size_sys_code:%d",
263 p_cb->nfcee_id, p_cb->size_sys_code);
264}
265
266/*******************************************************************************
267**
Sherry Smith43ef6452013-12-02 15:44:52 -0800268** Function nfa_ee_total_lmrt_size
269**
270** Description the total listen mode routing table size
271**
Ruchi Kandoi512ee632017-01-03 13:59:10 -0800272** Returns uint16_t
Sherry Smith43ef6452013-12-02 15:44:52 -0800273**
274*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800275static uint16_t nfa_ee_total_lmrt_size(void) {
276 int xx;
277 uint16_t lmrt_size = 0;
278 tNFA_EE_ECB* p_cb;
Sherry Smith43ef6452013-12-02 15:44:52 -0800279
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800280 p_cb = &nfa_ee_cb.ecb[NFA_EE_CB_4_DH];
281 lmrt_size += p_cb->size_mask;
282 lmrt_size += p_cb->size_aid;
Love Khanna1d062772018-04-10 21:10:02 +0530283 lmrt_size += p_cb->size_sys_code;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800284 p_cb = &nfa_ee_cb.ecb[nfa_ee_cb.cur_ee - 1];
285 for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb--) {
286 if (p_cb->ee_status == NFC_NFCEE_STATUS_ACTIVE) {
287 lmrt_size += p_cb->size_mask;
288 lmrt_size += p_cb->size_aid;
Love Khanna1d062772018-04-10 21:10:02 +0530289 lmrt_size += p_cb->size_sys_code;
Sherry Smith43ef6452013-12-02 15:44:52 -0800290 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800291 }
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700292 DLOG_IF(INFO, nfc_debug_enabled)
293 << StringPrintf("nfa_ee_total_lmrt_size size:%d", lmrt_size);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800294 return lmrt_size;
Sherry Smith43ef6452013-12-02 15:44:52 -0800295}
296
Love Khannab4ac88d2017-04-06 16:25:36 +0530297static void nfa_ee_add_tech_route_to_ecb(tNFA_EE_ECB* p_cb, uint8_t* pp,
298 uint8_t* p, uint8_t* ps,
299 int* p_cur_offset) {
300 uint8_t num_tlv = *ps;
301
302 /* add the Technology based routing */
303 for (int xx = 0; xx < NFA_EE_NUM_TECH; xx++) {
304 uint8_t power_cfg = 0;
305 if (p_cb->tech_switch_on & nfa_ee_tech_mask_list[xx])
306 power_cfg |= NCI_ROUTE_PWR_STATE_ON;
307 if (p_cb->tech_switch_off & nfa_ee_tech_mask_list[xx])
308 power_cfg |= NCI_ROUTE_PWR_STATE_SWITCH_OFF;
309 if (p_cb->tech_battery_off & nfa_ee_tech_mask_list[xx])
310 power_cfg |= NCI_ROUTE_PWR_STATE_BATT_OFF;
Love Khanna514a14b2018-03-23 00:19:13 +0530311 if ((power_cfg & NCI_ROUTE_PWR_STATE_ON) &&
312 (NFC_GetNCIVersion() == NCI_VERSION_2_0)) {
313 if (p_cb->tech_screen_lock & nfa_ee_tech_mask_list[xx])
314 power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_ON_LOCK();
315 if (p_cb->tech_screen_off & nfa_ee_tech_mask_list[xx])
316 power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_OFF_UNLOCK();
317 if (p_cb->tech_screen_off_lock & nfa_ee_tech_mask_list[xx])
318 power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_OFF_LOCK();
319 }
Love Khannab4ac88d2017-04-06 16:25:36 +0530320 if (power_cfg) {
Arach MOHAMMED BRAHIM2f08f7a2017-07-12 10:20:10 +0200321 add_route_tech_proto_tlv(&pp, NFC_ROUTE_TAG_TECH, p_cb->nfcee_id,
Love Khannab4ac88d2017-04-06 16:25:36 +0530322 power_cfg, nfa_ee_tech_list[xx]);
323 num_tlv++;
324 if (power_cfg != NCI_ROUTE_PWR_STATE_ON)
325 nfa_ee_cb.ee_cfged |= NFA_EE_CFGED_OFF_ROUTING;
326 }
327 }
328
329 /* update the num_tlv and current offset */
330 uint8_t entry_size = (uint8_t)(pp - p);
331 *p_cur_offset += entry_size;
332 *ps = num_tlv;
333}
334
335static void nfa_ee_add_proto_route_to_ecb(tNFA_EE_ECB* p_cb, uint8_t* pp,
336 uint8_t* p, uint8_t* ps,
337 int* p_cur_offset) {
338 uint8_t num_tlv = *ps;
339
340 /* add the Protocol based routing */
341 for (int xx = 0; xx < NFA_EE_NUM_PROTO; xx++) {
Love Khannac6bd78b2017-04-14 16:19:12 +0530342 uint8_t power_cfg = 0, proto_tag = 0;
Love Khannab4ac88d2017-04-06 16:25:36 +0530343 if (p_cb->proto_switch_on & nfa_ee_proto_mask_list[xx])
344 power_cfg |= NCI_ROUTE_PWR_STATE_ON;
345 if (p_cb->proto_switch_off & nfa_ee_proto_mask_list[xx])
346 power_cfg |= NCI_ROUTE_PWR_STATE_SWITCH_OFF;
347 if (p_cb->proto_battery_off & nfa_ee_proto_mask_list[xx])
348 power_cfg |= NCI_ROUTE_PWR_STATE_BATT_OFF;
349 if (power_cfg) {
Love Khannac6bd78b2017-04-14 16:19:12 +0530350 /* Applying Route Block for ISO DEP Protocol, so that AIDs
351 * which are not in the routing table can also be blocked */
352 if (nfa_ee_proto_mask_list[xx] == NFA_PROTOCOL_MASK_ISO_DEP) {
353 proto_tag = NFC_ROUTE_TAG_PROTO | nfa_ee_cb.route_block_control;
Love Khanna7e5f88f2017-07-11 19:46:27 +0530354
355 /* Enable screen on lock power state for ISO-DEP protocol to
356 enable HCE screen lock */
Love Khanna514a14b2018-03-23 00:19:13 +0530357 if ((power_cfg & NCI_ROUTE_PWR_STATE_ON) &&
358 (NFC_GetNCIVersion() == NCI_VERSION_2_0)) {
359 if (p_cb->proto_screen_lock & nfa_ee_proto_mask_list[xx])
360 power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_ON_LOCK();
361 if (p_cb->proto_screen_off & nfa_ee_proto_mask_list[xx])
362 power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_OFF_UNLOCK();
363 if (p_cb->proto_screen_off_lock & nfa_ee_proto_mask_list[xx])
364 power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_OFF_LOCK();
365 }
Love Khannac6bd78b2017-04-14 16:19:12 +0530366 } else {
367 proto_tag = NFC_ROUTE_TAG_PROTO;
368 }
369
Arach MOHAMMED BRAHIM2f08f7a2017-07-12 10:20:10 +0200370 add_route_tech_proto_tlv(&pp, proto_tag, p_cb->nfcee_id, power_cfg,
Love Khannac6bd78b2017-04-14 16:19:12 +0530371 nfa_ee_proto_list[xx]);
Love Khannab4ac88d2017-04-06 16:25:36 +0530372 num_tlv++;
373 if (power_cfg != NCI_ROUTE_PWR_STATE_ON)
374 nfa_ee_cb.ee_cfged |= NFA_EE_CFGED_OFF_ROUTING;
375 }
376 }
377
378 /* add NFC-DEP routing to HOST */
379 if (p_cb->nfcee_id == NFC_DH_ID) {
Arach MOHAMMED BRAHIM2f08f7a2017-07-12 10:20:10 +0200380 add_route_tech_proto_tlv(&pp, NFC_ROUTE_TAG_PROTO, NFC_DH_ID,
Love Khannab4ac88d2017-04-06 16:25:36 +0530381 NCI_ROUTE_PWR_STATE_ON, NFC_PROTOCOL_NFC_DEP);
382
383 num_tlv++;
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700384 DLOG_IF(INFO, nfc_debug_enabled)
385 << StringPrintf("%s - NFC DEP added for DH!!!", __func__);
Love Khannab4ac88d2017-04-06 16:25:36 +0530386 }
387 /* update the num_tlv and current offset */
388 uint8_t entry_size = (uint8_t)(pp - p);
389 *p_cur_offset += entry_size;
390 *ps = num_tlv;
391}
392
393static void nfa_ee_add_aid_route_to_ecb(tNFA_EE_ECB* p_cb, uint8_t* pp,
394 uint8_t* p, uint8_t* ps,
395 int* p_cur_offset, int* p_max_len) {
396 uint8_t num_tlv = *ps;
397
398 /* add the AID routing */
399 if (p_cb->aid_entries) {
400 int start_offset = 0;
401 for (int xx = 0; xx < p_cb->aid_entries; xx++) {
402 /* remember the beginning of this AID routing entry, just in case we
403 * need to put it in next command */
Love Khannaf3c018a2017-05-11 18:34:32 +0530404 uint8_t route_qual = 0;
Love Khannab4ac88d2017-04-06 16:25:36 +0530405 uint8_t* p_start = pp;
406 /* add one AID entry */
407 if (p_cb->aid_rt_info[xx] & NFA_EE_AE_ROUTE) {
408 num_tlv++;
409 uint8_t* pa = &p_cb->aid_cfg[start_offset];
Love Khannaf3c018a2017-05-11 18:34:32 +0530410
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700411 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
412 "%s - p_cb->aid_info%x", __func__, p_cb->aid_info[xx]);
Love Khannaf3c018a2017-05-11 18:34:32 +0530413 if (p_cb->aid_info[xx] & NCI_ROUTE_QUAL_LONG_SELECT) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700414 DLOG_IF(INFO, nfc_debug_enabled)
415 << StringPrintf("%s - %x", __func__,
416 p_cb->aid_info[xx] & NCI_ROUTE_QUAL_LONG_SELECT);
Love Khannaf3c018a2017-05-11 18:34:32 +0530417 route_qual |= NCI_ROUTE_QUAL_LONG_SELECT;
418 }
419 if (p_cb->aid_info[xx] & NCI_ROUTE_QUAL_SHORT_SELECT) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700420 DLOG_IF(INFO, nfc_debug_enabled)
421 << StringPrintf("%s - %x", __func__,
422 p_cb->aid_info[xx] & NCI_ROUTE_QUAL_SHORT_SELECT);
Love Khannaf3c018a2017-05-11 18:34:32 +0530423 route_qual |= NCI_ROUTE_QUAL_SHORT_SELECT;
424 }
425
426 uint8_t tag =
427 NFC_ROUTE_TAG_AID | nfa_ee_cb.route_block_control | route_qual;
428
Arach MOHAMMED BRAHIM2f08f7a2017-07-12 10:20:10 +0200429 add_route_aid_tlv(&pp, pa, p_cb->nfcee_id, p_cb->aid_pwr_cfg[xx], tag);
Love Khannab4ac88d2017-04-06 16:25:36 +0530430 }
431 start_offset += p_cb->aid_len[xx];
432 uint8_t new_size = (uint8_t)(pp - p_start);
433 nfa_ee_check_set_routing(new_size, p_max_len, ps, p_cur_offset);
434 if (*ps == 0) {
435 /* just sent routing command, update local */
436 *ps = 1;
437 num_tlv = *ps;
438 *p_cur_offset = new_size;
439 pp = ps + 1;
440 p = pp;
441 memcpy(p, p_start, new_size);
442 pp += new_size;
443 } else {
444 /* add the new entry */
445 *ps = num_tlv;
446 *p_cur_offset += new_size;
447 }
448 }
449 } else {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700450 DLOG_IF(INFO, nfc_debug_enabled)
451 << StringPrintf("%s - No AID entries available", __func__);
Love Khannab4ac88d2017-04-06 16:25:36 +0530452 }
453}
454
Love Khanna1d062772018-04-10 21:10:02 +0530455static void nfa_ee_add_sys_code_route_to_ecb(tNFA_EE_ECB* p_cb, uint8_t* pp,
456 uint8_t* p, uint8_t* p_buff,
457 int* p_cur_offset,
458 int* p_max_len) {
459 uint8_t num_tlv = *p_buff;
460
461 /* add the SC routing */
462 if (p_cb->sys_code_cfg_entries) {
463 int start_offset = 0;
464 for (int xx = 0; xx < p_cb->sys_code_cfg_entries; xx++) {
465 /* remember the beginning of this SC routing entry, just in case we
466 * need to put it in next command */
467 uint8_t* p_start = pp;
468 /* add one SC entry */
469 if (p_cb->sys_code_rt_loc_vs_info[xx] & NFA_EE_AE_ROUTE) {
470 uint8_t* p_sys_code_cfg = &p_cb->sys_code_cfg[start_offset];
471 if (nfa_ee_is_active(p_cb->sys_code_rt_loc[xx] | NFA_HANDLE_GROUP_EE)) {
472 add_route_sys_code_tlv(&pp, p_sys_code_cfg, p_cb->sys_code_rt_loc[xx],
473 p_cb->sys_code_pwr_cfg[xx]);
474 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_ROUTING;
475 num_tlv++;
476 } else {
477 DLOG_IF(INFO, nfc_debug_enabled)
478 << StringPrintf("%s - ignoring route loc%x", __func__,
479 p_cb->sys_code_rt_loc[xx]);
480 }
481 }
482 start_offset += NFA_EE_SYSTEM_CODE_LEN;
483 uint8_t new_size = (uint8_t)(pp - p_start);
484 nfa_ee_check_set_routing(new_size, p_max_len, p_buff, p_cur_offset);
485 if (*p_buff == 0 && (num_tlv > 0x00)) {
486 /* just sent routing command, update local */
487 *p_buff = 1;
488 num_tlv = *p_buff;
489 *p_cur_offset = new_size;
490 pp = p_buff + 1;
491 p = pp;
492 memcpy(p, p_start, new_size);
493 pp += new_size;
494 } else {
495 /* add the new entry */
496 *p_buff = num_tlv;
497 *p_cur_offset += new_size;
498 }
499 }
500 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
501 "nfa_ee_route_add_one_ecb_by_route_order --num_tlv:- %d", num_tlv);
502 } else {
503 DLOG_IF(INFO, nfc_debug_enabled)
504 << StringPrintf("%s - No SC entries available", __func__);
505 }
506}
507
Paul Chaissonf23dcad2013-11-25 16:51:23 -0500508/*******************************************************************************
509**
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800510** Function nfa_ee_conn_cback
511**
512** Description process connection callback event from stack
513**
514** Returns void
515**
516*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800517static void nfa_ee_conn_cback(uint8_t conn_id, tNFC_CONN_EVT event,
518 tNFC_CONN* p_data) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800519 tNFA_EE_NCI_CONN cbk;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800520
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700521 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
522 "nfa_ee_conn_cback: conn_id: %d, event=0x%02x", conn_id, event);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800523
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800524 cbk.hdr.event = NFA_EE_NCI_CONN_EVT;
525 if (event == NFC_DATA_CEVT) {
526 /* Treat data event specially to avoid potential memory leak */
527 cbk.hdr.event = NFA_EE_NCI_DATA_EVT;
528 }
529 cbk.conn_id = conn_id;
530 cbk.event = event;
531 cbk.p_data = p_data;
Myles Watson1361d522017-09-26 13:39:54 -0700532 tNFA_EE_MSG nfa_ee_msg;
533 nfa_ee_msg.conn = cbk;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800534
Myles Watson1361d522017-09-26 13:39:54 -0700535 nfa_ee_evt_hdlr(&nfa_ee_msg.hdr);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800536}
537
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800538/*******************************************************************************
539**
540** Function nfa_ee_find_total_aid_len
541**
542** Description Find the total len in aid_cfg from start_entry to the last
543**
544** Returns void
545**
546*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800547int nfa_ee_find_total_aid_len(tNFA_EE_ECB* p_cb, int start_entry) {
548 int len = 0, xx;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800549
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800550 if (p_cb->aid_entries > start_entry) {
551 for (xx = start_entry; xx < p_cb->aid_entries; xx++) {
552 len += p_cb->aid_len[xx];
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800553 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800554 }
555 return len;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800556}
557
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800558/*******************************************************************************
559**
Love Khanna1d062772018-04-10 21:10:02 +0530560** Function nfa_ee_find_total_sys_code_len
561**
562** Description Find the total len in sys_code_cfg from start_entry to the
563** last in the given ecb.
564**
565** Returns void
566**
567*******************************************************************************/
568int nfa_ee_find_total_sys_code_len(tNFA_EE_ECB* p_cb, int start_entry) {
569 int len = 0;
570 if (p_cb->sys_code_cfg_entries > start_entry) {
571 for (int xx = start_entry; xx < p_cb->sys_code_cfg_entries; xx++) {
572 len += NFA_EE_SYSTEM_CODE_LEN;
573 }
574 }
575 return len;
576}
577
578/*******************************************************************************
579**
580** Function nfa_all_ee_find_total_sys_code_len
581**
582** Description Find the total len in sys_code_cfg from start_entry to the
583** last for all EE and DH.
584**
585** Returns total length
586**
587*******************************************************************************/
588int nfa_all_ee_find_total_sys_code_len() {
589 int total_len = 0;
590 for (int32_t xx = 0; xx < NFA_EE_NUM_ECBS; xx++) {
591 tNFA_EE_ECB* p_cb = &nfa_ee_cb.ecb[xx];
592 total_len += nfa_ee_find_total_sys_code_len(p_cb, 0);
593 }
594 return total_len;
595}
596
597/*******************************************************************************
598**
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800599** Function nfa_ee_find_aid_offset
600**
601** Description Given the AID, find the associated tNFA_EE_ECB and the
602** offset in aid_cfg[]. *p_entry is the index.
603**
604** Returns void
605**
606*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800607tNFA_EE_ECB* nfa_ee_find_aid_offset(uint8_t aid_len, uint8_t* p_aid,
608 int* p_offset, int* p_entry) {
609 int xx, yy, aid_len_offset, offset;
610 tNFA_EE_ECB *p_ret = NULL, *p_ecb;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800611
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800612 p_ecb = &nfa_ee_cb.ecb[NFA_EE_CB_4_DH];
613 aid_len_offset = 1; /* skip the tag */
614 for (yy = 0; yy < nfa_ee_cb.cur_ee; yy++, p_ecb++) {
615 if (p_ecb->aid_entries) {
616 offset = 0;
617 for (xx = 0; xx < p_ecb->aid_entries; xx++) {
618 if ((p_ecb->aid_cfg[offset + aid_len_offset] == aid_len) &&
619 (memcmp(&p_ecb->aid_cfg[offset + aid_len_offset + 1], p_aid,
620 aid_len) == 0)) {
621 p_ret = p_ecb;
622 if (p_offset) *p_offset = offset;
623 if (p_entry) *p_entry = xx;
624 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800625 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800626 offset += p_ecb->aid_len[xx];
627 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800628
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800629 if (p_ret) {
630 /* found the entry already */
631 break;
632 }
633 }
634 p_ecb = &nfa_ee_cb.ecb[yy];
635 }
636
637 return p_ret;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800638}
639
640/*******************************************************************************
Love Khanna1d062772018-04-10 21:10:02 +0530641 **
642 ** Function nfa_ee_find_sys_code_offset
643 **
644 ** Description Given the System Code, find the associated tNFA_EE_ECB and
645 *the
646 ** offset in sys_code_cfg[]. *p_entry is the index.
647 **
648 ** Returns void
649 **
650 *******************************************************************************/
651tNFA_EE_ECB* nfa_ee_find_sys_code_offset(uint16_t sys_code, int* p_offset,
652 int* p_entry) {
653 tNFA_EE_ECB* p_ret = NULL;
654
655 for (uint8_t xx = 0; xx < NFA_EE_NUM_ECBS; xx++) {
656 tNFA_EE_ECB* p_ecb = &nfa_ee_cb.ecb[xx];
657 uint8_t mask = nfa_ee_ecb_to_mask(p_ecb);
658 if ((nfa_ee_cb.ee_cfged & mask) == 0 || p_ecb->sys_code_cfg_entries == 0) {
659 continue; /*try next ecb*/
660 }
661 if (p_ecb->sys_code_cfg_entries) {
662 uint8_t offset = 0;
663 for (uint8_t yy = 0; yy < p_ecb->sys_code_cfg_entries; yy++) {
664 if ((memcmp(&p_ecb->sys_code_cfg[offset], &sys_code,
665 NFA_EE_SYSTEM_CODE_LEN) == 0)) {
666 p_ret = p_ecb;
667 if (p_offset) *p_offset = offset;
668 if (p_entry) *p_entry = yy;
669 break;
670 }
671 offset += NFA_EE_SYSTEM_CODE_LEN;
672 }
673
674 if (p_ret) {
675 /* found the entry already */
676 return p_ret;
677 }
678 }
679 }
680 return p_ret;
681}
682
683/*******************************************************************************
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800684**
685** Function nfa_ee_report_event
686**
687** Description report the given event to the callback
688**
689** Returns void
690**
691*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800692void nfa_ee_report_event(tNFA_EE_CBACK* p_cback, tNFA_EE_EVT event,
693 tNFA_EE_CBACK_DATA* p_data) {
694 int xx;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800695
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800696 /* use the given callback, if not NULL */
697 if (p_cback) {
698 (*p_cback)(event, p_data);
699 return;
700 }
701 /* if the given is NULL, report to all registered ones */
702 for (xx = 0; xx < NFA_EE_MAX_CBACKS; xx++) {
703 if (nfa_ee_cb.p_ee_cback[xx] != NULL) {
704 (*nfa_ee_cb.p_ee_cback[xx])(event, p_data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800705 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800706 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800707}
708/*******************************************************************************
709**
710** Function nfa_ee_start_timer
711**
712** Description start the de-bounce timer
713**
714** Returns void
715**
716*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800717void nfa_ee_start_timer(void) {
718 if (nfa_dm_is_active())
719 nfa_sys_start_timer(&nfa_ee_cb.timer, NFA_EE_ROUT_TIMEOUT_EVT,
720 NFA_EE_ROUT_TIMEOUT_VAL);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800721}
722
723/*******************************************************************************
724**
725** Function nfa_ee_api_discover
726**
727** Description process discover command from user
728**
729** Returns void
730**
731*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800732void nfa_ee_api_discover(tNFA_EE_MSG* p_data) {
733 tNFA_EE_CBACK* p_cback = p_data->ee_discover.p_cback;
734 tNFA_EE_CBACK_DATA evt_data = {0};
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800735
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700736 DLOG_IF(INFO, nfc_debug_enabled)
737 << StringPrintf("in_use:%d", nfa_ee_cb.discv_timer.in_use);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800738 if (nfa_ee_cb.discv_timer.in_use) {
739 nfa_sys_stop_timer(&nfa_ee_cb.discv_timer);
Love Khanna81e4f812017-06-02 17:50:19 +0530740 if (NFA_GetNCIVersion() != NCI_VERSION_2_0) NFC_NfceeDiscover(false);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800741 }
742 if (nfa_ee_cb.p_ee_disc_cback == NULL &&
743 NFC_NfceeDiscover(true) == NFC_STATUS_OK) {
744 nfa_ee_cb.p_ee_disc_cback = p_cback;
745 } else {
746 evt_data.status = NFA_STATUS_FAILED;
747 nfa_ee_report_event(p_cback, NFA_EE_DISCOVER_EVT, &evt_data);
748 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800749}
750
751/*******************************************************************************
752**
753** Function nfa_ee_api_register
754**
755** Description process register command from user
756**
757** Returns void
758**
759*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800760void nfa_ee_api_register(tNFA_EE_MSG* p_data) {
761 int xx;
762 tNFA_EE_CBACK* p_cback = p_data->ee_register.p_cback;
763 tNFA_EE_CBACK_DATA evt_data = {0};
764 bool found = false;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800765
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800766 evt_data.ee_register = NFA_STATUS_FAILED;
767 /* loop through all entries to see if there's a matching callback */
768 for (xx = 0; xx < NFA_EE_MAX_CBACKS; xx++) {
769 if (nfa_ee_cb.p_ee_cback[xx] == p_cback) {
770 evt_data.ee_register = NFA_STATUS_OK;
771 found = true;
772 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800773 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800774 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800775
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800776 /* If no matching callback, allocated an entry */
777 if (!found) {
778 for (xx = 0; xx < NFA_EE_MAX_CBACKS; xx++) {
779 if (nfa_ee_cb.p_ee_cback[xx] == NULL) {
780 nfa_ee_cb.p_ee_cback[xx] = p_cback;
781 evt_data.ee_register = NFA_STATUS_OK;
782 break;
783 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800784 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800785 }
786 /* This callback is verified (not NULL) in NFA_EeRegister() */
787 (*p_cback)(NFA_EE_REGISTER_EVT, &evt_data);
Martijn Coenen5c65c3a2013-03-27 13:23:36 -0700788
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800789 /* report NFCEE Discovery Request collected during booting up */
790 nfa_ee_build_discover_req_evt(&evt_data.discover_req);
791 (*p_cback)(NFA_EE_DISCOVER_REQ_EVT, &evt_data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800792}
793
794/*******************************************************************************
795**
796** Function nfa_ee_api_deregister
797**
798** Description process de-register command from user
799**
800** Returns void
801**
802*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800803void nfa_ee_api_deregister(tNFA_EE_MSG* p_data) {
804 tNFA_EE_CBACK* p_cback = NULL;
805 int index = p_data->deregister.index;
806 tNFA_EE_CBACK_DATA evt_data = {0};
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800807
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700808 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("nfa_ee_api_deregister");
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800809 p_cback = nfa_ee_cb.p_ee_cback[index];
810 nfa_ee_cb.p_ee_cback[index] = NULL;
811 if (p_cback) (*p_cback)(NFA_EE_DEREGISTER_EVT, &evt_data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800812}
813
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800814/*******************************************************************************
815**
816** Function nfa_ee_api_mode_set
817**
818** Description process mode set command from user
819**
820** Returns void
821**
822*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800823void nfa_ee_api_mode_set(tNFA_EE_MSG* p_data) {
824 tNFA_EE_ECB* p_cb = p_data->cfg_hdr.p_cb;
Love Khanna81e4f812017-06-02 17:50:19 +0530825 tNFA_EE_MODE_SET mode_set;
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700826 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
827 "handle:0x%02x mode:%d", p_cb->nfcee_id, p_data->mode_set.mode);
Love Khanna81e4f812017-06-02 17:50:19 +0530828 mode_set.status = NFC_NfceeModeSet(p_cb->nfcee_id, p_data->mode_set.mode);
829 if (mode_set.status != NFC_STATUS_OK) {
830 /* the api is rejected at NFC layer, report the failure status right away */
831 mode_set.ee_handle = (tNFA_HANDLE)p_cb->nfcee_id | NFA_HANDLE_GROUP_EE;
832 mode_set.ee_status = p_data->mode_set.mode;
Myles Watson1361d522017-09-26 13:39:54 -0700833 tNFA_EE_CBACK_DATA nfa_ee_cback_data;
834 nfa_ee_cback_data.mode_set = mode_set;
835 nfa_ee_report_event(NULL, NFA_EE_MODE_SET_EVT, &nfa_ee_cback_data);
Love Khanna81e4f812017-06-02 17:50:19 +0530836 return;
837 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800838 /* set the NFA_EE_STATUS_PENDING bit to indicate the status is not exactly
839 * active */
840 if (p_data->mode_set.mode == NFC_MODE_ACTIVATE)
841 p_cb->ee_status = NFA_EE_STATUS_PENDING | NFA_EE_STATUS_ACTIVE;
842 else {
843 p_cb->ee_status = NFA_EE_STATUS_INACTIVE;
844 /* DH should release the NCI connection before deactivate the NFCEE */
845 if (p_cb->conn_st == NFA_EE_CONN_ST_CONN) {
846 p_cb->conn_st = NFA_EE_CONN_ST_DISC;
847 NFC_ConnClose(p_cb->conn_id);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800848 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800849 }
850 /* report the NFA_EE_MODE_SET_EVT status on the response from NFCC */
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800851}
852
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800853/*******************************************************************************
854**
855** Function nfa_ee_api_set_tech_cfg
856**
857** Description process set technology routing configuration from user
858** start a 1 second timer. When the timer expires,
859** the configuration collected in control block is sent to NFCC
860**
861** Returns void
862**
863*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800864void nfa_ee_api_set_tech_cfg(tNFA_EE_MSG* p_data) {
865 tNFA_EE_ECB* p_cb = p_data->cfg_hdr.p_cb;
866 tNFA_EE_CBACK_DATA evt_data = {0};
867 tNFA_TECHNOLOGY_MASK old_tech_switch_on = p_cb->tech_switch_on;
868 tNFA_TECHNOLOGY_MASK old_tech_switch_off = p_cb->tech_switch_off;
869 tNFA_TECHNOLOGY_MASK old_tech_battery_off = p_cb->tech_battery_off;
Love Khanna514a14b2018-03-23 00:19:13 +0530870 tNFA_TECHNOLOGY_MASK old_tech_screen_lock = p_cb->tech_screen_lock;
871 tNFA_TECHNOLOGY_MASK old_tech_screen_off = p_cb->tech_screen_off;
872 tNFA_TECHNOLOGY_MASK old_tech_screen_off_lock = p_cb->tech_screen_off_lock;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800873 uint8_t old_size_mask = p_cb->size_mask;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800874
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800875 if ((p_cb->tech_switch_on == p_data->set_tech.technologies_switch_on) &&
876 (p_cb->tech_switch_off == p_data->set_tech.technologies_switch_off) &&
Love Khanna514a14b2018-03-23 00:19:13 +0530877 (p_cb->tech_battery_off == p_data->set_tech.technologies_battery_off) &&
878 (p_cb->tech_screen_lock == p_data->set_tech.technologies_screen_lock) &&
879 (p_cb->tech_screen_off == p_data->set_tech.technologies_screen_off) &&
880 (p_cb->tech_screen_off_lock ==
881 p_data->set_tech.technologies_screen_off_lock)) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800882 /* nothing to change */
883 evt_data.status = NFA_STATUS_OK;
884 nfa_ee_report_event(p_cb->p_ee_cback, NFA_EE_SET_TECH_CFG_EVT, &evt_data);
885 return;
886 }
Jizhou Liaoea8730a2015-06-17 09:59:41 -0700887
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800888 p_cb->tech_switch_on = p_data->set_tech.technologies_switch_on;
889 p_cb->tech_switch_off = p_data->set_tech.technologies_switch_off;
890 p_cb->tech_battery_off = p_data->set_tech.technologies_battery_off;
Love Khanna514a14b2018-03-23 00:19:13 +0530891 p_cb->tech_screen_lock = p_data->set_tech.technologies_screen_lock;
892 p_cb->tech_screen_off = p_data->set_tech.technologies_screen_off;
893 p_cb->tech_screen_off_lock = p_data->set_tech.technologies_screen_off_lock;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800894 nfa_ee_update_route_size(p_cb);
895 if (nfa_ee_total_lmrt_size() > NFC_GetLmrtSize()) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700896 LOG(ERROR) << StringPrintf("nfa_ee_api_set_tech_cfg Exceed LMRT size");
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800897 evt_data.status = NFA_STATUS_BUFFER_FULL;
898 p_cb->tech_switch_on = old_tech_switch_on;
899 p_cb->tech_switch_off = old_tech_switch_off;
900 p_cb->tech_battery_off = old_tech_battery_off;
Love Khanna514a14b2018-03-23 00:19:13 +0530901 p_cb->tech_screen_lock = old_tech_screen_lock;
902 p_cb->tech_screen_off = old_tech_screen_off;
903 p_cb->tech_screen_off_lock = old_tech_screen_off_lock;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800904 p_cb->size_mask = old_size_mask;
905 } else {
906 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_TECH;
Love Khanna514a14b2018-03-23 00:19:13 +0530907 if (p_cb->tech_switch_on | p_cb->tech_switch_off | p_cb->tech_battery_off |
908 p_cb->tech_screen_lock | p_cb->tech_screen_off |
909 p_cb->tech_screen_off_lock) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800910 /* if any technology in any power mode is configured, mark this entry as
911 * configured */
912 nfa_ee_cb.ee_cfged |= nfa_ee_ecb_to_mask(p_cb);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800913 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800914 nfa_ee_start_timer();
915 }
916 nfa_ee_report_event(p_cb->p_ee_cback, NFA_EE_SET_TECH_CFG_EVT, &evt_data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800917}
918
919/*******************************************************************************
920**
921** Function nfa_ee_api_set_proto_cfg
922**
923** Description process set protocol routing configuration from user
924** start a 1 second timer. When the timer expires,
925** the configuration collected in control block is sent to NFCC
926**
927** Returns void
928**
929*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800930void nfa_ee_api_set_proto_cfg(tNFA_EE_MSG* p_data) {
931 tNFA_EE_ECB* p_cb = p_data->cfg_hdr.p_cb;
932 tNFA_EE_CBACK_DATA evt_data = {0};
933 tNFA_PROTOCOL_MASK old_proto_switch_on = p_cb->proto_switch_on;
934 tNFA_PROTOCOL_MASK old_proto_switch_off = p_cb->proto_switch_off;
935 tNFA_PROTOCOL_MASK old_proto_battery_off = p_cb->proto_battery_off;
Love Khanna514a14b2018-03-23 00:19:13 +0530936 tNFA_PROTOCOL_MASK old_proto_screen_lock = p_cb->proto_screen_lock;
937 tNFA_PROTOCOL_MASK old_proto_screen_off = p_cb->proto_screen_off;
938 tNFA_PROTOCOL_MASK old_proto_screen_off_lock = p_cb->proto_screen_off_lock;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800939 uint8_t old_size_mask = p_cb->size_mask;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800940
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800941 if ((p_cb->proto_switch_on == p_data->set_proto.protocols_switch_on) &&
942 (p_cb->proto_switch_off == p_data->set_proto.protocols_switch_off) &&
Love Khanna514a14b2018-03-23 00:19:13 +0530943 (p_cb->proto_battery_off == p_data->set_proto.protocols_battery_off) &&
944 (p_cb->proto_screen_lock == p_data->set_proto.protocols_screen_lock) &&
945 (p_cb->proto_screen_off == p_data->set_proto.protocols_screen_off) &&
946 (p_cb->proto_screen_off_lock ==
947 p_data->set_proto.protocols_screen_off_lock)) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800948 /* nothing to change */
949 evt_data.status = NFA_STATUS_OK;
950 nfa_ee_report_event(p_cb->p_ee_cback, NFA_EE_SET_PROTO_CFG_EVT, &evt_data);
951 return;
952 }
Jizhou Liaoea8730a2015-06-17 09:59:41 -0700953
Jizhou Liao4250f7b2018-05-11 11:45:38 -0700954 p_cb->proto_switch_on |= p_data->set_proto.protocols_switch_on;
955 p_cb->proto_switch_off |= p_data->set_proto.protocols_switch_off;
956 p_cb->proto_battery_off |= p_data->set_proto.protocols_battery_off;
957 p_cb->proto_screen_lock |= p_data->set_proto.protocols_screen_lock;
958 p_cb->proto_screen_off |= p_data->set_proto.protocols_screen_off;
959 p_cb->proto_screen_off_lock |= p_data->set_proto.protocols_screen_off_lock;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800960 nfa_ee_update_route_size(p_cb);
961 if (nfa_ee_total_lmrt_size() > NFC_GetLmrtSize()) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700962 LOG(ERROR) << StringPrintf("nfa_ee_api_set_proto_cfg Exceed LMRT size");
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800963 evt_data.status = NFA_STATUS_BUFFER_FULL;
964 p_cb->proto_switch_on = old_proto_switch_on;
965 p_cb->proto_switch_off = old_proto_switch_off;
966 p_cb->proto_battery_off = old_proto_battery_off;
Love Khanna514a14b2018-03-23 00:19:13 +0530967 p_cb->proto_screen_lock = old_proto_screen_lock;
968 p_cb->proto_screen_off = old_proto_screen_off;
969 p_cb->proto_screen_off_lock = old_proto_screen_off_lock;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800970 p_cb->size_mask = old_size_mask;
971 } else {
972 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_PROTO;
973 if (p_cb->proto_switch_on | p_cb->proto_switch_off |
Love Khanna514a14b2018-03-23 00:19:13 +0530974 p_cb->proto_battery_off | p_cb->proto_screen_lock |
975 p_cb->proto_screen_off | p_cb->proto_screen_off_lock) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800976 /* if any protocol in any power mode is configured, mark this entry as
977 * configured */
978 nfa_ee_cb.ee_cfged |= nfa_ee_ecb_to_mask(p_cb);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800979 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800980 nfa_ee_start_timer();
981 }
982 nfa_ee_report_event(p_cb->p_ee_cback, NFA_EE_SET_PROTO_CFG_EVT, &evt_data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800983}
984
985/*******************************************************************************
986**
987** Function nfa_ee_api_add_aid
988**
989** Description process add an AID routing configuration from user
990** start a 1 second timer. When the timer expires,
991** the configuration collected in control block is sent to NFCC
992**
993** Returns void
994**
995*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800996void nfa_ee_api_add_aid(tNFA_EE_MSG* p_data) {
997 tNFA_EE_API_ADD_AID* p_add = &p_data->add_aid;
998 tNFA_EE_ECB* p_cb = p_data->cfg_hdr.p_cb;
999 tNFA_EE_ECB* p_chk_cb;
1000 uint8_t *p, *p_start;
1001 int len, len_needed;
1002 tNFA_EE_CBACK_DATA evt_data = {0};
1003 int offset = 0, entry = 0;
1004 uint16_t new_size;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001005
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001006 nfa_ee_trace_aid("nfa_ee_api_add_aid", p_cb->nfcee_id, p_add->aid_len,
1007 p_add->p_aid);
1008 p_chk_cb =
1009 nfa_ee_find_aid_offset(p_add->aid_len, p_add->p_aid, &offset, &entry);
1010 if (p_chk_cb) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001011 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001012 "nfa_ee_api_add_aid The AID entry is already in the database");
1013 if (p_chk_cb == p_cb) {
1014 p_cb->aid_rt_info[entry] |= NFA_EE_AE_ROUTE;
Love Khannaf3c018a2017-05-11 18:34:32 +05301015 p_cb->aid_info[entry] = p_add->aidInfo;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001016 new_size = nfa_ee_total_lmrt_size();
1017 if (new_size > NFC_GetLmrtSize()) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001018 LOG(ERROR) << StringPrintf("Exceed LMRT size:%d (add ROUTE)", new_size);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001019 evt_data.status = NFA_STATUS_BUFFER_FULL;
1020 p_cb->aid_rt_info[entry] &= ~NFA_EE_AE_ROUTE;
1021 } else {
1022 p_cb->aid_pwr_cfg[entry] = p_add->power_state;
1023 }
1024 } else {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001025 LOG(ERROR) << StringPrintf(
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001026 "The AID entry is already in the database for different NFCEE "
1027 "ID:0x%02x",
1028 p_chk_cb->nfcee_id);
1029 evt_data.status = NFA_STATUS_SEMANTIC_ERROR;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001030 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001031 } else {
1032 /* Find the total length so far */
1033 len = nfa_ee_find_total_aid_len(p_cb, 0);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001034
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001035 /* make sure the control block has enough room to hold this entry */
1036 len_needed = p_add->aid_len + 2; /* tag/len */
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001037
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001038 if ((len_needed + len) > NFA_EE_MAX_AID_CFG_LEN) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001039 LOG(ERROR) << StringPrintf(
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001040 "Exceed capacity: (len_needed:%d + len:%d) > "
1041 "NFA_EE_MAX_AID_CFG_LEN:%d",
1042 len_needed, len, NFA_EE_MAX_AID_CFG_LEN);
1043 evt_data.status = NFA_STATUS_BUFFER_FULL;
1044 } else if (p_cb->aid_entries < NFA_EE_MAX_AID_ENTRIES) {
1045 /* 4 = 1 (tag) + 1 (len) + 1(nfcee_id) + 1(power cfg) */
1046 new_size = nfa_ee_total_lmrt_size() + 4 + p_add->aid_len;
1047 if (new_size > NFC_GetLmrtSize()) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001048 LOG(ERROR) << StringPrintf("Exceed LMRT size:%d", new_size);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001049 evt_data.status = NFA_STATUS_BUFFER_FULL;
1050 } else {
1051 /* add AID */
1052 p_cb->aid_pwr_cfg[p_cb->aid_entries] = p_add->power_state;
Love Khannaf3c018a2017-05-11 18:34:32 +05301053 p_cb->aid_info[p_cb->aid_entries] = p_add->aidInfo;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001054 p_cb->aid_rt_info[p_cb->aid_entries] = NFA_EE_AE_ROUTE;
1055 p = p_cb->aid_cfg + len;
1056 p_start = p;
1057 *p++ = NFA_EE_AID_CFG_TAG_NAME;
1058 *p++ = p_add->aid_len;
1059 memcpy(p, p_add->p_aid, p_add->aid_len);
1060 p += p_add->aid_len;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001061
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001062 p_cb->aid_len[p_cb->aid_entries++] = (uint8_t)(p - p_start);
1063 }
1064 } else {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001065 LOG(ERROR) << StringPrintf("Exceed NFA_EE_MAX_AID_ENTRIES:%d",
1066 NFA_EE_MAX_AID_ENTRIES);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001067 evt_data.status = NFA_STATUS_BUFFER_FULL;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001068 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001069 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001070
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001071 if (evt_data.status == NFA_STATUS_OK) {
1072 /* mark AID changed */
1073 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_AID;
1074 nfa_ee_cb.ee_cfged |= nfa_ee_ecb_to_mask(p_cb);
1075 nfa_ee_update_route_aid_size(p_cb);
1076 nfa_ee_start_timer();
1077 }
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001078 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
1079 "status:%d ee_cfged:0x%02x ", evt_data.status, nfa_ee_cb.ee_cfged);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001080 /* report the status of this operation */
1081 nfa_ee_report_event(p_cb->p_ee_cback, NFA_EE_ADD_AID_EVT, &evt_data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001082}
1083
1084/*******************************************************************************
1085**
1086** Function nfa_ee_api_remove_aid
1087**
1088** Description process remove an AID routing configuration from user
1089** start a 1 second timer. When the timer expires,
1090** the configuration collected in control block is sent to NFCC
1091**
1092** Returns void
1093**
1094*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001095void nfa_ee_api_remove_aid(tNFA_EE_MSG* p_data) {
1096 tNFA_EE_ECB* p_cb;
1097 tNFA_EE_CBACK_DATA evt_data = {0};
1098 int offset = 0, entry = 0, len;
1099 int rest_len;
1100 tNFA_EE_CBACK* p_cback = NULL;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001101
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001102 nfa_ee_trace_aid("nfa_ee_api_remove_aid", 0, p_data->rm_aid.aid_len,
1103 p_data->rm_aid.p_aid);
1104 p_cb = nfa_ee_find_aid_offset(p_data->rm_aid.aid_len, p_data->rm_aid.p_aid,
1105 &offset, &entry);
1106 if (p_cb && p_cb->aid_entries) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001107 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
1108 "aid_rt_info[%d]: 0x%02x", entry, p_cb->aid_rt_info[entry]);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001109 /* mark routing and VS changed */
1110 if (p_cb->aid_rt_info[entry] & NFA_EE_AE_ROUTE)
1111 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_AID;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001112
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001113 if (p_cb->aid_rt_info[entry] & NFA_EE_AE_VS)
1114 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_VS;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001115
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001116 /* remove the aid */
1117 if ((entry + 1) < p_cb->aid_entries) {
1118 /* not the last entry, move the aid entries in control block */
1119 /* Find the total len from the next entry to the last one */
1120 rest_len = nfa_ee_find_total_aid_len(p_cb, entry + 1);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001121
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001122 len = p_cb->aid_len[entry];
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001123 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
1124 "nfa_ee_api_remove_aid len:%d, rest_len:%d", len, rest_len);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001125 GKI_shiftup(&p_cb->aid_cfg[offset], &p_cb->aid_cfg[offset + len],
1126 rest_len);
1127 rest_len = p_cb->aid_entries - entry;
1128 GKI_shiftup(&p_cb->aid_len[entry], &p_cb->aid_len[entry + 1], rest_len);
1129 GKI_shiftup(&p_cb->aid_pwr_cfg[entry], &p_cb->aid_pwr_cfg[entry + 1],
1130 rest_len);
1131 GKI_shiftup(&p_cb->aid_rt_info[entry], &p_cb->aid_rt_info[entry + 1],
1132 rest_len);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001133 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001134 /* else the last entry, just reduce the aid_entries by 1 */
1135 p_cb->aid_entries--;
1136 nfa_ee_cb.ee_cfged |= nfa_ee_ecb_to_mask(p_cb);
1137 nfa_ee_update_route_aid_size(p_cb);
1138 nfa_ee_start_timer();
1139 /* report NFA_EE_REMOVE_AID_EVT to the callback associated the NFCEE */
1140 p_cback = p_cb->p_ee_cback;
1141 } else {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001142 LOG(ERROR) << StringPrintf(
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001143 "nfa_ee_api_remove_aid The AID entry is not in the database");
1144 evt_data.status = NFA_STATUS_INVALID_PARAM;
1145 }
1146 nfa_ee_report_event(p_cback, NFA_EE_REMOVE_AID_EVT, &evt_data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001147}
1148
1149/*******************************************************************************
Love Khanna1d062772018-04-10 21:10:02 +05301150 **
1151 ** Function nfa_ee_api_add_sys_code
1152 **
1153 ** Description Adds System Code routing configuration from user. When the
1154 ** timer expires, the configuration collected in control block
1155 ** is sent to NFCC
1156 **
1157 ** Returns void
1158 **
1159 *******************************************************************************/
1160void nfa_ee_api_add_sys_code(tNFA_EE_MSG* p_data) {
1161 tNFA_EE_CBACK_DATA evt_data = {0};
1162 tNFA_EE_API_ADD_SYSCODE* p_add = &p_data->add_syscode;
1163 tNFA_EE_ECB* p_cb = p_data->cfg_hdr.p_cb;
1164
1165 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
1166 "%s id:0x%x SC:0x%X ", __func__, p_add->nfcee_id, p_add->syscode);
1167
1168 int offset = 0, entry = 0;
1169 tNFA_EE_ECB* p_chk_cb =
1170 nfa_ee_find_sys_code_offset(p_add->syscode, &offset, &entry);
1171
1172 if (p_chk_cb) {
1173 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
1174 "%s: The SC entry already registered "
1175 "for this NFCEE id:0x%02x",
1176 __func__, p_add->nfcee_id);
1177
1178 if (p_chk_cb == p_cb) {
1179 p_cb->sys_code_rt_loc_vs_info[entry] |= NFA_EE_AE_ROUTE;
1180 uint16_t new_size = nfa_ee_total_lmrt_size();
1181 if (new_size > NFC_GetLmrtSize()) {
1182 LOG(ERROR) << StringPrintf("Exceeded LMRT size:%d (add SYSCODE)",
1183 new_size);
1184 evt_data.status = NFA_STATUS_BUFFER_FULL;
1185 p_cb->sys_code_rt_loc_vs_info[entry] &= ~NFA_EE_AE_ROUTE;
1186 } else {
1187 p_cb->sys_code_pwr_cfg[entry] = p_add->power_state;
1188 }
1189 } else {
1190 LOG(ERROR) << StringPrintf(
1191 "%s: SystemCode entry already registered for different "
1192 "NFCEE id:0x%02x",
1193 __func__, p_chk_cb->nfcee_id);
1194 evt_data.status = NFA_STATUS_REJECTED;
1195 }
1196 } else {
1197 /* Find the total length so far in sys_code_cfg */
1198 int total_sc_len = nfa_all_ee_find_total_sys_code_len();
1199 /* make sure the control block has enough room to hold this entry */
1200 if ((NFA_EE_SYSTEM_CODE_LEN + total_sc_len) >
1201 NFA_EE_MAX_SYSTEM_CODE_CFG_LEN) {
1202 LOG(ERROR) << StringPrintf(
1203 "Exceeded capacity: (NFA_EE_SYSTEM_CODE_LEN:%d + total_sc_len:%d) > "
1204 "NFA_EE_MAX_SYSTEM_CODE_CFG_LEN:%d",
1205 NFA_EE_SYSTEM_CODE_LEN, total_sc_len, NFA_EE_MAX_SYSTEM_CODE_CFG_LEN);
1206 evt_data.status = NFA_STATUS_BUFFER_FULL;
1207 } else if (p_cb->sys_code_cfg_entries < NFA_EE_MAX_SYSTEM_CODE_ENTRIES) {
1208 /* 6 = 1 (tag) + 1 (len) + 1(nfcee_id) + 1(power cfg) + 2(system code)*/
1209 uint16_t new_size =
1210 nfa_ee_total_lmrt_size() + NFA_EE_SYSTEM_CODE_TLV_SIZE;
1211 if (new_size > NFC_GetLmrtSize()) {
1212 LOG(ERROR) << StringPrintf("Exceeded LMRT size:%d", new_size);
1213 evt_data.status = NFA_STATUS_BUFFER_FULL;
1214 } else {
1215 /* add SC entry*/
1216 uint32_t p_cb_sc_len = nfa_ee_find_total_sys_code_len(p_cb, 0);
1217 p_cb->sys_code_pwr_cfg[p_cb->sys_code_cfg_entries] = p_add->power_state;
1218 p_cb->sys_code_rt_loc[p_cb->sys_code_cfg_entries] = p_add->nfcee_id;
1219 p_cb->sys_code_rt_loc_vs_info[p_cb->sys_code_cfg_entries] =
1220 NFA_EE_AE_ROUTE;
1221
1222 uint8_t* p = p_cb->sys_code_cfg + p_cb_sc_len;
1223 memcpy(p, &p_add->syscode, NFA_EE_SYSTEM_CODE_LEN);
1224 p += NFA_EE_SYSTEM_CODE_LEN;
1225
1226 p_cb->sys_code_cfg_entries++;
1227 }
1228 } else {
1229 LOG(ERROR) << StringPrintf("Exceeded NFA_EE_MAX_SYSTEM_CODE_ENTRIES:%d",
1230 NFA_EE_MAX_SYSTEM_CODE_ENTRIES);
1231 evt_data.status = NFA_STATUS_BUFFER_FULL;
1232 }
1233 }
1234
1235 if (evt_data.status == NFA_STATUS_OK) {
1236 /* mark SC changed */
1237 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_SYSCODE;
1238 nfa_ee_cb.ee_cfged |= nfa_ee_ecb_to_mask(p_cb);
1239 nfa_ee_update_route_sys_code_size(p_cb);
1240 nfa_ee_start_timer();
1241 }
1242 DLOG_IF(INFO, nfc_debug_enabled)
1243 << StringPrintf("%s: status:%d ee_cfged:0x%02x ", __func__,
1244 evt_data.status, nfa_ee_cb.ee_cfged);
1245
1246 /* report the status of this operation */
1247 nfa_ee_report_event(p_cb->p_ee_cback, NFA_EE_ADD_SYSCODE_EVT, &evt_data);
1248}
1249
1250/*******************************************************************************
1251**
1252** Function nfa_ee_api_remove_sys_code
1253**
1254** Description process remove an System Code routing configuration from
1255** user start a 1 second timer. When the timer expires,
1256** the configuration collected in control block is sent to NFCC
1257**
1258** Returns void
1259**
1260*******************************************************************************/
1261void nfa_ee_api_remove_sys_code(tNFA_EE_MSG* p_data) {
1262 tNFA_EE_CBACK_DATA evt_data = {0};
1263 tNFA_EE_API_REMOVE_SYSCODE* p_remove = &p_data->rm_syscode;
1264
1265 DLOG_IF(INFO, nfc_debug_enabled)
1266 << StringPrintf("%s SC:0x%x", __func__, p_remove->syscode);
1267
1268 int offset = 0, entry = 0;
1269 tNFA_EE_ECB* p_cb =
1270 nfa_ee_find_sys_code_offset(p_data->rm_syscode.syscode, &offset, &entry);
1271
1272 if (p_cb && p_cb->sys_code_cfg_entries) {
1273 DLOG_IF(INFO, nfc_debug_enabled)
1274 << StringPrintf("sys_code_rt_loc_vs_info[%d]: 0x%02x", entry,
1275 p_cb->sys_code_rt_loc_vs_info[entry]);
1276 /* mark routing and VS changed */
1277 if (p_cb->sys_code_rt_loc_vs_info[entry] & NFA_EE_AE_ROUTE)
1278 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_SYSCODE;
1279
1280 if (p_cb->sys_code_rt_loc_vs_info[entry] & NFA_EE_AE_VS)
1281 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_VS;
1282
1283 /* remove the system code */
1284 if ((entry + 1) < p_cb->sys_code_cfg_entries) {
1285 /* not the last entry, move the SC entries in control block */
1286 /* Find the total len from the next entry to the last one */
1287 int total_len = nfa_ee_find_total_sys_code_len(p_cb, entry + 1);
1288
1289 int rm_len = NFA_EE_SYSTEM_CODE_LEN;
1290
1291 DLOG_IF(INFO, nfc_debug_enabled)
1292 << StringPrintf("nfa_ee_api_remove_sys_code: rm_len:%d, total_len:%d",
1293 rm_len, total_len);
1294
1295 GKI_shiftup(&p_cb->sys_code_cfg[offset],
1296 &p_cb->sys_code_cfg[offset + rm_len], total_len);
1297
1298 total_len = p_cb->sys_code_cfg_entries - entry;
1299
1300 GKI_shiftup(&p_cb->sys_code_pwr_cfg[entry],
1301 &p_cb->sys_code_pwr_cfg[entry + 1], total_len);
1302
1303 GKI_shiftup(&p_cb->sys_code_rt_loc_vs_info[entry],
1304 &p_cb->sys_code_rt_loc_vs_info[entry + 1], total_len);
1305
1306 GKI_shiftup(&p_cb->sys_code_rt_loc[entry],
1307 &p_cb->sys_code_rt_loc[entry + 1], total_len);
1308 }
1309 /* else the last entry, just reduce the aid_entries by 1 */
1310 p_cb->sys_code_cfg_entries--;
1311 nfa_ee_cb.ee_cfged |= nfa_ee_ecb_to_mask(p_cb);
1312 nfa_ee_update_route_sys_code_size(p_cb);
1313 nfa_ee_start_timer();
1314 } else {
1315 LOG(ERROR) << StringPrintf(
1316 "nfa_ee_api_remove_sys_code: The SC entry is not in the database");
1317 evt_data.status = NFA_STATUS_INVALID_PARAM;
1318 }
1319 /* report the status of this operation */
1320 nfa_ee_report_event(p_cb->p_ee_cback, NFA_EE_REMOVE_SYSCODE_EVT, &evt_data);
1321}
1322
1323/*******************************************************************************
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001324**
Sherry Smithca0bff42014-01-22 15:15:54 -08001325** Function nfa_ee_api_lmrt_size
1326**
1327** Description Reports the remaining size in the Listen Mode Routing Table
1328**
1329** Returns void
1330**
1331*******************************************************************************/
Ruchi Kandoi9ba6d242017-10-13 16:07:01 -07001332void nfa_ee_api_lmrt_size(__attribute__((unused)) tNFA_EE_MSG* p_data) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001333 tNFA_EE_CBACK_DATA evt_data = {0};
1334 uint16_t total_size = NFC_GetLmrtSize();
Sherry Smithca0bff42014-01-22 15:15:54 -08001335
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001336 evt_data.size = total_size - nfa_ee_total_lmrt_size();
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001337 DLOG_IF(INFO, nfc_debug_enabled)
1338 << StringPrintf("nfa_ee_api_lmrt_size total size:%d remaining size:%d",
1339 total_size, evt_data.size);
Sherry Smithca0bff42014-01-22 15:15:54 -08001340
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001341 nfa_ee_report_event(NULL, NFA_EE_REMAINING_SIZE_EVT, &evt_data);
Sherry Smithca0bff42014-01-22 15:15:54 -08001342}
1343
1344/*******************************************************************************
1345**
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001346** Function nfa_ee_api_update_now
1347**
1348** Description Initiates connection creation process to the given NFCEE
1349**
1350** Returns void
1351**
1352*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001353void nfa_ee_api_update_now(tNFA_EE_MSG* p_data) {
1354 tNFA_EE_CBACK_DATA evt_data;
Sherry Smith40e67c92014-01-16 10:10:29 -08001355
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001356 if (nfa_ee_cb.ee_wait_evt & NFA_EE_WAIT_UPDATE_ALL) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001357 LOG(ERROR) << StringPrintf(
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001358 "nfa_ee_api_update_now still waiting for update complete "
1359 "ee_wait_evt:0x%x wait_rsp:%d",
1360 nfa_ee_cb.ee_wait_evt, nfa_ee_cb.wait_rsp);
1361 evt_data.status = NFA_STATUS_SEMANTIC_ERROR;
1362 nfa_ee_report_event(NULL, NFA_EE_UPDATED_EVT, &evt_data);
1363 return;
1364 }
1365 nfa_sys_stop_timer(&nfa_ee_cb.timer);
1366 nfa_ee_cb.ee_cfged |= NFA_EE_CFGED_UPDATE_NOW;
1367 nfa_ee_rout_timeout(p_data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001368}
1369
1370/*******************************************************************************
1371**
1372** Function nfa_ee_api_connect
1373**
1374** Description Initiates connection creation process to the given NFCEE
1375**
1376** Returns void
1377**
1378*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001379void nfa_ee_api_connect(tNFA_EE_MSG* p_data) {
1380 tNFA_EE_ECB* p_cb = p_data->connect.p_cb;
1381 int xx;
1382 tNFA_EE_CBACK_DATA evt_data = {0};
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001383
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001384 evt_data.connect.status = NFA_STATUS_FAILED;
1385 if (p_cb->conn_st == NFA_EE_CONN_ST_NONE) {
1386 for (xx = 0; xx < p_cb->num_interface; xx++) {
1387 if (p_data->connect.ee_interface == p_cb->ee_interface[xx]) {
1388 p_cb->p_ee_cback = p_data->connect.p_cback;
1389 p_cb->conn_st = NFA_EE_CONN_ST_WAIT;
1390 p_cb->use_interface = p_data->connect.ee_interface;
1391 evt_data.connect.status =
1392 NFC_ConnCreate(NCI_DEST_TYPE_NFCEE, p_data->connect.nfcee_id,
1393 p_data->connect.ee_interface, nfa_ee_conn_cback);
1394 /* report the NFA_EE_CONNECT_EVT status on the response from NFCC */
1395 break;
1396 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001397 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001398 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001399
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001400 if (evt_data.connect.status != NCI_STATUS_OK) {
1401 evt_data.connect.ee_handle =
1402 (tNFA_HANDLE)p_data->connect.nfcee_id | NFA_HANDLE_GROUP_EE;
1403 evt_data.connect.status = NFA_STATUS_INVALID_PARAM;
1404 evt_data.connect.ee_interface = p_data->connect.ee_interface;
1405 nfa_ee_report_event(p_data->connect.p_cback, NFA_EE_CONNECT_EVT, &evt_data);
1406 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001407}
1408
1409/*******************************************************************************
1410**
1411** Function nfa_ee_api_send_data
1412**
1413** Description Send the given data packet to the given NFCEE
1414**
1415** Returns void
1416**
1417*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001418void nfa_ee_api_send_data(tNFA_EE_MSG* p_data) {
1419 tNFA_EE_ECB* p_cb = p_data->send_data.p_cb;
1420 NFC_HDR* p_pkt;
1421 uint16_t size = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE +
1422 p_data->send_data.data_len + NFC_HDR_SIZE;
1423 uint8_t* p;
1424 tNFA_STATUS status = NFA_STATUS_FAILED;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001425
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001426 if (p_cb->conn_st == NFA_EE_CONN_ST_CONN) {
1427 p_pkt = (NFC_HDR*)GKI_getbuf(size);
1428 if (p_pkt) {
1429 p_pkt->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
1430 p_pkt->len = p_data->send_data.data_len;
1431 p = (uint8_t*)(p_pkt + 1) + p_pkt->offset;
1432 memcpy(p, p_data->send_data.p_data, p_pkt->len);
1433 NFC_SendData(p_cb->conn_id, p_pkt);
1434 } else {
Myles Watson1361d522017-09-26 13:39:54 -07001435 tNFA_EE_CBACK_DATA nfa_ee_cback_data;
1436 nfa_ee_cback_data.status = status;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001437 nfa_ee_report_event(p_cb->p_ee_cback, NFA_EE_NO_MEM_ERR_EVT,
Myles Watson1361d522017-09-26 13:39:54 -07001438 &nfa_ee_cback_data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001439 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001440 } else {
Myles Watson1361d522017-09-26 13:39:54 -07001441 tNFA_EE_CBACK_DATA nfa_ee_cback_data;
1442 nfa_ee_cback_data.status = status;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001443 nfa_ee_report_event(p_cb->p_ee_cback, NFA_EE_NO_CB_ERR_EVT,
Myles Watson1361d522017-09-26 13:39:54 -07001444 &nfa_ee_cback_data);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001445 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001446}
1447
1448/*******************************************************************************
1449**
1450** Function nfa_ee_api_disconnect
1451**
1452** Description Initiates closing of the connection to the given NFCEE
1453**
1454** Returns void
1455**
1456*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001457void nfa_ee_api_disconnect(tNFA_EE_MSG* p_data) {
1458 tNFA_EE_ECB* p_cb = p_data->disconnect.p_cb;
1459 tNFA_EE_CBACK_DATA evt_data = {0};
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001460
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001461 if (p_cb->conn_st == NFA_EE_CONN_ST_CONN) {
1462 p_cb->conn_st = NFA_EE_CONN_ST_DISC;
1463 NFC_ConnClose(p_cb->conn_id);
1464 }
1465 evt_data.handle = (tNFA_HANDLE)p_cb->nfcee_id | NFA_HANDLE_GROUP_EE;
1466 nfa_ee_report_event(p_cb->p_ee_cback, NFA_EE_DISCONNECT_EVT, &evt_data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001467}
1468
1469/*******************************************************************************
1470**
1471** Function nfa_ee_report_disc_done
1472**
1473** Description Process the callback for NFCEE discovery response
1474**
1475** Returns void
1476**
1477*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001478void nfa_ee_report_disc_done(bool notify_enable_done) {
1479 tNFA_EE_CBACK* p_cback;
1480 tNFA_EE_CBACK_DATA evt_data = {0};
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001481
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001482 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
1483 "em_state:%d num_ee_expecting:%d "
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001484 "notify_enable_done:%d",
1485 nfa_ee_cb.em_state, nfa_ee_cb.num_ee_expecting, notify_enable_done);
1486 if (nfa_ee_cb.num_ee_expecting == 0) {
1487 if (notify_enable_done) {
1488 if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_INIT_DONE) {
1489 nfa_sys_cback_notify_enable_complete(NFA_ID_EE);
1490 if (nfa_ee_cb.p_enable_cback)
1491 (*nfa_ee_cb.p_enable_cback)(NFA_EE_DISC_STS_ON);
1492 } else if ((nfa_ee_cb.em_state == NFA_EE_EM_STATE_RESTORING) &&
1493 (nfa_ee_cb.ee_flags & NFA_EE_FLAG_NOTIFY_HCI)) {
1494 nfa_ee_cb.ee_flags &= ~NFA_EE_FLAG_NOTIFY_HCI;
1495 if (nfa_ee_cb.p_enable_cback)
1496 (*nfa_ee_cb.p_enable_cback)(NFA_EE_DISC_STS_ON);
1497 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001498 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001499
1500 if (nfa_ee_cb.p_ee_disc_cback) {
1501 /* notify API callback */
1502 p_cback = nfa_ee_cb.p_ee_disc_cback;
1503 nfa_ee_cb.p_ee_disc_cback = NULL;
1504 evt_data.status = NFA_STATUS_OK;
1505 evt_data.ee_discover.num_ee = NFA_EE_MAX_EE_SUPPORTED;
1506 NFA_EeGetInfo(&evt_data.ee_discover.num_ee, evt_data.ee_discover.ee_info);
1507 nfa_ee_report_event(p_cback, NFA_EE_DISCOVER_EVT, &evt_data);
1508 }
1509 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001510}
1511
1512/*******************************************************************************
1513**
1514** Function nfa_ee_restore_ntf_done
1515**
1516** Description check if any ee_status still has NFA_EE_STATUS_PENDING bit
1517**
1518** Returns TRUE, if all NFA_EE_STATUS_PENDING bits are removed
1519**
1520*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001521bool nfa_ee_restore_ntf_done(void) {
1522 tNFA_EE_ECB* p_cb;
1523 bool is_done = true;
1524 int xx;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001525
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001526 p_cb = nfa_ee_cb.ecb;
1527 for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++) {
1528 if ((p_cb->nfcee_id != NFA_EE_INVALID) &&
1529 (p_cb->ee_old_status & NFA_EE_STATUS_RESTORING)) {
1530 is_done = false;
1531 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001532 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001533 }
1534 return is_done;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001535}
1536
1537/*******************************************************************************
1538**
1539** Function nfa_ee_remove_pending
1540**
1541** Description check if any ee_status still has NFA_EE_STATUS_RESTORING bit
1542**
1543** Returns TRUE, if all NFA_EE_STATUS_RESTORING bits are removed
1544**
1545*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001546static void nfa_ee_remove_pending(void) {
1547 tNFA_EE_ECB* p_cb;
1548 tNFA_EE_ECB *p_cb_n, *p_cb_end;
1549 int xx, num_removed = 0;
1550 int first_removed = NFA_EE_MAX_EE_SUPPORTED;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001551
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001552 p_cb = nfa_ee_cb.ecb;
1553 for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++) {
1554 if ((p_cb->nfcee_id != NFA_EE_INVALID) &&
1555 (p_cb->ee_status & NFA_EE_STATUS_RESTORING)) {
1556 p_cb->nfcee_id = NFA_EE_INVALID;
1557 num_removed++;
1558 if (first_removed == NFA_EE_MAX_EE_SUPPORTED) first_removed = xx;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001559 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001560 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001561
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001562 DLOG_IF(INFO, nfc_debug_enabled)
1563 << StringPrintf("cur_ee:%d, num_removed:%d first_removed:%d",
1564 nfa_ee_cb.cur_ee, num_removed, first_removed);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001565 if (num_removed && (first_removed != (nfa_ee_cb.cur_ee - num_removed))) {
1566 /* if the removes ECB entried are not at the end, move the entries up */
1567 p_cb_end = &nfa_ee_cb.ecb[nfa_ee_cb.cur_ee - 1];
1568 p_cb = &nfa_ee_cb.ecb[first_removed];
1569 for (p_cb_n = p_cb + 1; p_cb_n <= p_cb_end;) {
1570 while ((p_cb_n->nfcee_id == NFA_EE_INVALID) && (p_cb_n <= p_cb_end)) {
1571 p_cb_n++;
1572 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001573
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001574 if (p_cb_n <= p_cb_end) {
1575 memcpy(p_cb, p_cb_n, sizeof(tNFA_EE_ECB));
1576 p_cb_n->nfcee_id = NFA_EE_INVALID;
1577 }
1578 p_cb++;
1579 p_cb_n++;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001580 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001581 }
1582 nfa_ee_cb.cur_ee -= (uint8_t)num_removed;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001583}
1584
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001585/*******************************************************************************
1586**
1587** Function nfa_ee_nci_disc_rsp
1588**
1589** Description Process the callback for NFCEE discovery response
1590**
1591** Returns void
1592**
1593*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001594void nfa_ee_nci_disc_rsp(tNFA_EE_MSG* p_data) {
1595 tNFC_NFCEE_DISCOVER_REVT* p_evt = p_data->disc_rsp.p_data;
1596 tNFA_EE_ECB* p_cb;
1597 uint8_t xx;
1598 uint8_t num_nfcee = p_evt->num_nfcee;
1599 bool notify_enable_done = false;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001600
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001601 DLOG_IF(INFO, nfc_debug_enabled)
1602 << StringPrintf("em_state:%d cur_ee:%d, num_nfcee:%d", nfa_ee_cb.em_state,
1603 nfa_ee_cb.cur_ee, num_nfcee);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001604 switch (nfa_ee_cb.em_state) {
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001605 case NFA_EE_EM_STATE_INIT:
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001606 nfa_ee_cb.cur_ee = 0;
1607 nfa_ee_cb.num_ee_expecting = 0;
1608 if (num_nfcee == 0) {
1609 nfa_ee_cb.em_state = NFA_EE_EM_STATE_INIT_DONE;
1610 notify_enable_done = true;
1611 if (p_evt->status != NFC_STATUS_OK) {
1612 nfa_sys_stop_timer(&nfa_ee_cb.discv_timer);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001613 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001614 }
1615 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001616
1617 case NFA_EE_EM_STATE_INIT_DONE:
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001618 if (num_nfcee) {
1619 /* if this is initiated by api function,
1620 * check if the number of NFCEE expected is more than what's currently
1621 * in CB */
1622 if (num_nfcee > NFA_EE_MAX_EE_SUPPORTED)
1623 num_nfcee = NFA_EE_MAX_EE_SUPPORTED;
1624 if (nfa_ee_cb.cur_ee < num_nfcee) {
1625 p_cb = &nfa_ee_cb.ecb[nfa_ee_cb.cur_ee];
1626 for (xx = nfa_ee_cb.cur_ee; xx < num_nfcee; xx++, p_cb++) {
1627 /* mark the new entries as a new one */
1628 p_cb->nfcee_id = NFA_EE_INVALID;
1629 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001630 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001631 nfa_ee_cb.cur_ee = num_nfcee;
1632 }
1633 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001634
1635 case NFA_EE_EM_STATE_RESTORING:
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001636 if (num_nfcee == 0) {
1637 nfa_ee_cb.em_state = NFA_EE_EM_STATE_INIT_DONE;
1638 nfa_ee_remove_pending();
1639 nfa_ee_check_restore_complete();
1640 if (p_evt->status != NFC_STATUS_OK) {
1641 nfa_sys_stop_timer(&nfa_ee_cb.discv_timer);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001642 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001643 }
1644 break;
1645 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001646
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001647 if (p_evt->status == NFC_STATUS_OK) {
1648 nfa_ee_cb.num_ee_expecting = p_evt->num_nfcee;
1649 if (nfa_ee_cb.num_ee_expecting > NFA_EE_MAX_EE_SUPPORTED) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001650 LOG(ERROR) << StringPrintf("NFA-EE num_ee_expecting:%d > max:%d",
1651 nfa_ee_cb.num_ee_expecting,
1652 NFA_EE_MAX_EE_SUPPORTED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001653 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001654 }
1655 nfa_ee_report_disc_done(notify_enable_done);
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001656 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
1657 "em_state:%d cur_ee:%d num_ee_expecting:%d", nfa_ee_cb.em_state,
1658 nfa_ee_cb.cur_ee, nfa_ee_cb.num_ee_expecting);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001659}
1660
1661/*******************************************************************************
1662**
1663** Function nfa_ee_nci_disc_ntf
1664**
1665** Description Process the callback for NFCEE discovery notification
1666**
1667** Returns void
1668**
1669*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001670void nfa_ee_nci_disc_ntf(tNFA_EE_MSG* p_data) {
1671 tNFC_NFCEE_INFO_REVT* p_ee = p_data->disc_ntf.p_data;
1672 tNFA_EE_ECB* p_cb = NULL;
1673 bool notify_enable_done = false;
1674 bool notify_new_ee = false;
1675 tNFA_EE_CBACK_DATA evt_data = {0};
1676 tNFA_EE_INFO* p_info;
1677 tNFA_EE_EM_STATE new_em_state = NFA_EE_EM_STATE_MAX;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001678
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001679 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
1680 "em_state:%d ee_flags:0x%x cur_ee:%d "
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001681 "num_ee_expecting:%d",
1682 nfa_ee_cb.em_state, nfa_ee_cb.ee_flags, nfa_ee_cb.cur_ee,
1683 nfa_ee_cb.num_ee_expecting);
1684 if (nfa_ee_cb.num_ee_expecting) {
1685 nfa_ee_cb.num_ee_expecting--;
1686 if ((nfa_ee_cb.num_ee_expecting == 0) &&
1687 (nfa_ee_cb.p_ee_disc_cback != NULL)) {
1688 /* Discovery triggered by API function */
Love Khanna81e4f812017-06-02 17:50:19 +05301689 if (NFA_GetNCIVersion() != NCI_VERSION_2_0) NFC_NfceeDiscover(false);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001690 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001691 }
1692 switch (nfa_ee_cb.em_state) {
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001693 case NFA_EE_EM_STATE_INIT:
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001694 if (nfa_ee_cb.cur_ee < NFA_EE_MAX_EE_SUPPORTED) {
1695 /* the cb can collect up to NFA_EE_MAX_EE_SUPPORTED ee_info */
1696 p_cb = &nfa_ee_cb.ecb[nfa_ee_cb.cur_ee++];
1697 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001698
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001699 if (nfa_ee_cb.num_ee_expecting == 0) {
1700 /* notify init_done callback */
1701 nfa_ee_cb.em_state = NFA_EE_EM_STATE_INIT_DONE;
1702 notify_enable_done = true;
1703 }
1704 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001705
1706 case NFA_EE_EM_STATE_INIT_DONE:
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001707 p_cb = nfa_ee_find_ecb(p_ee->nfcee_id);
1708 if (p_cb == NULL) {
1709 /* the NFCEE ID is not in the last NFCEE discovery
1710 * maybe it's a new one */
1711 p_cb = nfa_ee_find_ecb(NFA_EE_INVALID);
1712 if (p_cb) {
1713 nfa_ee_cb.cur_ee++;
1714 notify_new_ee = true;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001715 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001716 } else if (p_cb->ecb_flags & NFA_EE_ECB_FLAGS_ORDER) {
1717 nfa_ee_cb.cur_ee++;
1718 notify_new_ee = true;
1719 } else {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001720 DLOG_IF(INFO, nfc_debug_enabled)
1721 << StringPrintf("cur_ee:%d ecb_flags=0x%02x ee_status=0x%x",
1722 nfa_ee_cb.cur_ee, p_cb->ecb_flags, p_cb->ee_status);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001723 }
1724 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001725
1726 case NFA_EE_EM_STATE_RESTORING:
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001727 p_cb = nfa_ee_find_ecb(p_ee->nfcee_id);
1728 if (p_cb == NULL) {
1729 /* the NFCEE ID is not in the last NFCEE discovery
1730 * maybe it's a new one */
1731 p_cb = nfa_ee_find_ecb(NFA_EE_INVALID);
1732 if (p_cb) {
1733 nfa_ee_cb.cur_ee++;
1734 notify_new_ee = true;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001735 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001736 }
1737 if (nfa_ee_cb.num_ee_expecting == 0) {
1738 /* notify init_done callback */
1739 notify_enable_done = true;
1740 if (nfa_ee_restore_ntf_done()) {
1741 new_em_state = NFA_EE_EM_STATE_INIT_DONE;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001742 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001743 }
1744 break;
1745 }
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001746 DLOG_IF(INFO, nfc_debug_enabled)
1747 << StringPrintf("nfa_ee_nci_disc_ntf cur_ee:%d", nfa_ee_cb.cur_ee);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001748
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001749 if (p_cb) {
1750 p_cb->nfcee_id = p_ee->nfcee_id;
1751 p_cb->ee_status = p_ee->ee_status;
1752 p_cb->num_interface = p_ee->num_interface;
1753 memcpy(p_cb->ee_interface, p_ee->ee_interface, p_ee->num_interface);
1754 p_cb->num_tlvs = p_ee->num_tlvs;
1755 memcpy(p_cb->ee_tlv, p_ee->ee_tlv, p_ee->num_tlvs * sizeof(tNFA_EE_TLV));
Love Khanna81e4f812017-06-02 17:50:19 +05301756 if (NFA_GetNCIVersion() == NCI_VERSION_2_0)
1757 p_cb->ee_power_supply_status = p_ee->nfcee_power_ctrl;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001758 if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_RESTORING) {
1759 /* NCI spec says: An NFCEE_DISCOVER_NTF that contains a Protocol type of
1760 * "HCI Access"
1761 * SHALL NOT contain any other additional Protocol
1762 * i.e. check only first supported NFCEE interface is HCI access */
1763 /* NFA_HCI module handles restoring configurations for HCI access */
1764 if (p_cb->ee_interface[0] != NFC_NFCEE_INTERFACE_HCI_ACCESS) {
1765 if ((nfa_ee_cb.ee_flags & NFA_EE_FLAG_WAIT_HCI) == 0) {
1766 nfa_ee_restore_one_ecb(p_cb);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001767 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001768 /* else wait for NFA-HCI module to restore the HCI network information
1769 * before enabling the NFCEE */
1770 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001771 }
1772
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001773 if ((nfa_ee_cb.p_ee_disc_cback == NULL) && (notify_new_ee == true)) {
1774 if (nfa_dm_is_active() && (p_cb->ee_status != NFA_EE_STATUS_REMOVED)) {
1775 /* report this NFA_EE_NEW_EE_EVT only after NFA_DM_ENABLE_EVT is
1776 * reported */
1777 p_info = &evt_data.new_ee;
1778 p_info->ee_handle = NFA_HANDLE_GROUP_EE | (tNFA_HANDLE)p_cb->nfcee_id;
1779 p_info->ee_status = p_cb->ee_status;
1780 p_info->num_interface = p_cb->num_interface;
1781 p_info->num_tlvs = p_cb->num_tlvs;
1782 memcpy(p_info->ee_interface, p_cb->ee_interface, p_cb->num_interface);
1783 memcpy(p_info->ee_tlv, p_cb->ee_tlv,
1784 p_cb->num_tlvs * sizeof(tNFA_EE_TLV));
Love Khanna81e4f812017-06-02 17:50:19 +05301785 if (NFA_GetNCIVersion() == NCI_VERSION_2_0)
1786 p_info->ee_power_supply_status = p_cb->ee_power_supply_status;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001787 nfa_ee_report_event(NULL, NFA_EE_NEW_EE_EVT, &evt_data);
1788 }
1789 } else
1790 nfa_ee_report_disc_done(notify_enable_done);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001791
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001792 if (p_cb->ecb_flags & NFA_EE_ECB_FLAGS_ORDER) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001793 DLOG_IF(INFO, nfc_debug_enabled)
1794 << StringPrintf("NFA_EE_ECB_FLAGS_ORDER");
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001795 p_cb->ecb_flags &= ~NFA_EE_ECB_FLAGS_ORDER;
1796 nfa_ee_report_discover_req_evt();
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001797 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001798 }
1799
1800 if (new_em_state != NFA_EE_EM_STATE_MAX) {
1801 nfa_ee_cb.em_state = new_em_state;
1802 nfa_ee_check_restore_complete();
1803 }
1804
1805 if ((nfa_ee_cb.cur_ee == nfa_ee_max_ee_cfg) &&
1806 (nfa_ee_cb.em_state == NFA_EE_EM_STATE_INIT_DONE)) {
1807 if (nfa_ee_cb.discv_timer.in_use) {
1808 nfa_sys_stop_timer(&nfa_ee_cb.discv_timer);
1809 p_data->hdr.event = NFA_EE_DISCV_TIMEOUT_EVT;
Myles Watson1361d522017-09-26 13:39:54 -07001810 nfa_ee_evt_hdlr(&p_data->hdr);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001811 }
1812 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001813}
1814
1815/*******************************************************************************
1816**
1817** Function nfa_ee_check_restore_complete
1818**
1819** Description Check if restore the NFA-EE related configuration to the
1820** state prior to low power mode is complete.
1821** If complete, notify sys.
1822**
1823** Returns void
1824**
1825*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001826void nfa_ee_check_restore_complete(void) {
1827 uint32_t xx;
1828 tNFA_EE_ECB* p_cb;
1829 bool proc_complete = true;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001830
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001831 p_cb = nfa_ee_cb.ecb;
1832 for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++) {
1833 if (p_cb->ecb_flags & NFA_EE_ECB_FLAGS_RESTORE) {
1834 /* NFA_HCI module handles restoring configurations for HCI access.
1835 * ignore the restoring status for HCI Access */
1836 if (p_cb->ee_interface[0] != NFC_NFCEE_INTERFACE_HCI_ACCESS) {
1837 proc_complete = false;
1838 break;
1839 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001840 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001841 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001842
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001843 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001844 "nfa_ee_check_restore_complete nfa_ee_cb.ee_cfg_sts:0x%02x "
1845 "proc_complete:%d",
1846 nfa_ee_cb.ee_cfg_sts, proc_complete);
1847 if (proc_complete) {
1848 /* update routing table when NFA_EE_ROUT_TIMEOUT_EVT is received */
1849 if (nfa_ee_cb.ee_cfg_sts & NFA_EE_STS_PREV_ROUTING)
1850 nfa_ee_api_update_now(NULL);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001851
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001852 nfa_ee_cb.em_state = NFA_EE_EM_STATE_INIT_DONE;
1853 nfa_sys_cback_notify_nfcc_power_mode_proc_complete(NFA_ID_EE);
1854 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001855}
1856
1857/*******************************************************************************
1858**
Martijn Coenen5c65c3a2013-03-27 13:23:36 -07001859** Function nfa_ee_build_discover_req_evt
1860**
1861** Description Build NFA_EE_DISCOVER_REQ_EVT for all active NFCEE
1862**
1863** Returns void
1864**
1865*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001866static void nfa_ee_build_discover_req_evt(tNFA_EE_DISCOVER_REQ* p_evt_data) {
1867 tNFA_EE_ECB* p_cb;
1868 tNFA_EE_DISCOVER_INFO* p_info;
1869 uint8_t xx;
Martijn Coenen5c65c3a2013-03-27 13:23:36 -07001870
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001871 if (!p_evt_data) return;
Martijn Coenen5c65c3a2013-03-27 13:23:36 -07001872
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001873 p_evt_data->num_ee = 0;
1874 p_cb = nfa_ee_cb.ecb;
1875 p_info = p_evt_data->ee_disc_info;
Martijn Coenen5c65c3a2013-03-27 13:23:36 -07001876
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001877 for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++) {
1878 if ((p_cb->ee_status & NFA_EE_STATUS_INT_MASK) ||
1879 (p_cb->ee_status != NFA_EE_STATUS_ACTIVE) ||
1880 ((p_cb->ecb_flags & NFA_EE_ECB_FLAGS_DISC_REQ) == 0)) {
1881 continue;
Martijn Coenen5c65c3a2013-03-27 13:23:36 -07001882 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001883 p_info->ee_handle = (tNFA_HANDLE)p_cb->nfcee_id | NFA_HANDLE_GROUP_EE;
1884 p_info->la_protocol = p_cb->la_protocol;
1885 p_info->lb_protocol = p_cb->lb_protocol;
1886 p_info->lf_protocol = p_cb->lf_protocol;
1887 p_info->lbp_protocol = p_cb->lbp_protocol;
1888 p_evt_data->num_ee++;
1889 p_info++;
Martijn Coenen5c65c3a2013-03-27 13:23:36 -07001890
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001891 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001892 "[%d] ee_handle:0x%x, listen protocol A:%d, B:%d, F:%d, BP:%d",
1893 p_evt_data->num_ee, p_cb->nfcee_id, p_cb->la_protocol,
1894 p_cb->lb_protocol, p_cb->lf_protocol, p_cb->lbp_protocol);
1895 }
1896
1897 p_evt_data->status = NFA_STATUS_OK;
Martijn Coenen5c65c3a2013-03-27 13:23:36 -07001898}
1899
1900/*******************************************************************************
1901**
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001902** Function nfa_ee_report_discover_req_evt
1903**
1904** Description Report NFA_EE_DISCOVER_REQ_EVT for all active NFCEE
1905**
1906** Returns void
1907**
1908*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001909static void nfa_ee_report_discover_req_evt(void) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001910 if (nfa_ee_cb.p_enable_cback)
1911 (*nfa_ee_cb.p_enable_cback)(NFA_EE_DISC_STS_REQ);
Martijn Coenen5c65c3a2013-03-27 13:23:36 -07001912
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001913 /* if this is restoring NFCC */
1914 if (!nfa_dm_is_active()) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001915 DLOG_IF(INFO, nfc_debug_enabled)
1916 << StringPrintf("nfa_ee_report_discover_req_evt DM is not active");
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001917 return;
1918 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001919
Myles Watson1361d522017-09-26 13:39:54 -07001920 tNFA_EE_CBACK_DATA nfa_ee_cback_data;
1921 nfa_ee_build_discover_req_evt(&nfa_ee_cback_data.discover_req);
1922 nfa_ee_report_event(NULL, NFA_EE_DISCOVER_REQ_EVT, &nfa_ee_cback_data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001923}
1924
1925/*******************************************************************************
1926**
1927** Function nfa_ee_nci_mode_set_rsp
1928**
1929** Description Process the result for NFCEE ModeSet response
1930**
1931** Returns void
1932**
1933*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001934void nfa_ee_nci_mode_set_rsp(tNFA_EE_MSG* p_data) {
1935 tNFA_EE_ECB* p_cb;
1936 tNFA_EE_MODE_SET mode_set;
1937 tNFC_NFCEE_MODE_SET_REVT* p_rsp = p_data->mode_set_rsp.p_data;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001938
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001939 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
1940 "%s handle:0x%02x mode:%d", __func__, p_rsp->nfcee_id, p_rsp->mode);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001941 p_cb = nfa_ee_find_ecb(p_rsp->nfcee_id);
1942 if (p_cb == NULL) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001943 LOG(ERROR) << StringPrintf("%s Can not find cb for handle:0x%02x", __func__,
1944 p_rsp->nfcee_id);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001945 return;
1946 }
1947
1948 /* update routing table and vs on mode change */
1949 nfa_ee_start_timer();
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001950 LOG(ERROR) << StringPrintf("%s p_rsp->status:0x%02x", __func__,
1951 p_rsp->status);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001952 if (p_rsp->status == NFA_STATUS_OK) {
1953 if (p_rsp->mode == NFA_EE_MD_ACTIVATE) {
1954 p_cb->ee_status = NFC_NFCEE_STATUS_ACTIVE;
1955 } else {
1956 if (p_cb->tech_switch_on | p_cb->tech_switch_off |
1957 p_cb->tech_battery_off | p_cb->proto_switch_on |
1958 p_cb->proto_switch_off | p_cb->proto_battery_off |
1959 p_cb->aid_entries) {
1960 /* this NFCEE still has configuration when deactivated. clear the
1961 * configuration */
1962 nfa_ee_cb.ee_cfged &= ~nfa_ee_ecb_to_mask(p_cb);
1963 nfa_ee_cb.ee_cfg_sts |= NFA_EE_STS_CHANGED_ROUTING;
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001964 DLOG_IF(INFO, nfc_debug_enabled)
1965 << StringPrintf("deactivating/still configured. Force update");
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001966 }
1967 p_cb->tech_switch_on = p_cb->tech_switch_off = p_cb->tech_battery_off = 0;
1968 p_cb->proto_switch_on = p_cb->proto_switch_off = p_cb->proto_battery_off =
1969 0;
1970 p_cb->aid_entries = 0;
1971 p_cb->ee_status = NFC_NFCEE_STATUS_INACTIVE;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001972 }
Love Khanna81e4f812017-06-02 17:50:19 +05301973 } else if (p_rsp->mode == NFA_EE_MD_ACTIVATE) {
1974 p_cb->ee_status = NFC_NFCEE_STATUS_REMOVED;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001975 }
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001976 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
1977 "status:%d ecb_flags :0x%02x ee_cfged:0x%02x ee_status:%d",
1978 p_rsp->status, p_cb->ecb_flags, nfa_ee_cb.ee_cfged, p_cb->ee_status);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001979 if (p_cb->ecb_flags & NFA_EE_ECB_FLAGS_RESTORE) {
1980 if (p_cb->conn_st == NFA_EE_CONN_ST_CONN) {
1981 /* NFA_HCI module handles restoring configurations for HCI access */
1982 if (p_cb->ee_interface[0] != NFC_NFCEE_INTERFACE_HCI_ACCESS) {
1983 NFC_ConnCreate(NCI_DEST_TYPE_NFCEE, p_cb->nfcee_id, p_cb->use_interface,
1984 nfa_ee_conn_cback);
1985 }
1986 } else {
1987 p_cb->ecb_flags &= ~NFA_EE_ECB_FLAGS_RESTORE;
1988 nfa_ee_check_restore_complete();
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001989 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001990 } else {
1991 mode_set.status = p_rsp->status;
1992 mode_set.ee_handle = (tNFA_HANDLE)p_rsp->nfcee_id | NFA_HANDLE_GROUP_EE;
1993 mode_set.ee_status = p_cb->ee_status;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001994
Myles Watson1361d522017-09-26 13:39:54 -07001995 tNFA_EE_CBACK_DATA nfa_ee_cback_data;
1996 nfa_ee_cback_data.mode_set = mode_set;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001997 nfa_ee_report_event(p_cb->p_ee_cback, NFA_EE_MODE_SET_EVT,
Myles Watson1361d522017-09-26 13:39:54 -07001998 &nfa_ee_cback_data);
Paul Chaissonafb70e82014-01-02 16:29:32 -05001999
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002000 if ((p_cb->ee_status == NFC_NFCEE_STATUS_INACTIVE) ||
2001 (p_cb->ee_status == NFC_NFCEE_STATUS_ACTIVE)) {
2002 /* Report NFA_EE_DISCOVER_REQ_EVT for all active NFCEE */
2003 nfa_ee_report_discover_req_evt();
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002004 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002005 }
Love Khanna81e4f812017-06-02 17:50:19 +05302006 if (nfa_ee_cb.p_enable_cback)
2007 (*nfa_ee_cb.p_enable_cback)(NFA_EE_MODE_SET_COMPLETE);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002008}
2009
2010/*******************************************************************************
2011**
Sherry Smith40e67c92014-01-16 10:10:29 -08002012** Function nfa_ee_report_update_evt
2013**
2014** Description Check if need to report NFA_EE_UPDATED_EVT
2015**
2016** Returns void
2017**
2018*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002019void nfa_ee_report_update_evt(void) {
2020 tNFA_EE_CBACK_DATA evt_data;
Sherry Smith40e67c92014-01-16 10:10:29 -08002021
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002022 DLOG_IF(INFO, nfc_debug_enabled)
2023 << StringPrintf("nfa_ee_report_update_evt ee_wait_evt:0x%x wait_rsp:%d",
2024 nfa_ee_cb.ee_wait_evt, nfa_ee_cb.wait_rsp);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002025 if (nfa_ee_cb.wait_rsp == 0) {
2026 nfa_ee_cb.ee_wait_evt &= ~NFA_EE_WAIT_UPDATE_RSP;
Sherry Smith40e67c92014-01-16 10:10:29 -08002027
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002028 if (nfa_ee_cb.ee_wait_evt & NFA_EE_WAIT_UPDATE) {
2029 nfa_ee_cb.ee_wait_evt &= ~NFA_EE_WAIT_UPDATE;
2030 /* finished updating NFCC; report NFA_EE_UPDATED_EVT now */
2031 evt_data.status = NFA_STATUS_OK;
2032 nfa_ee_report_event(NULL, NFA_EE_UPDATED_EVT, &evt_data);
Sherry Smith40e67c92014-01-16 10:10:29 -08002033 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002034 }
Sherry Smith40e67c92014-01-16 10:10:29 -08002035}
2036
2037/*******************************************************************************
2038**
2039** Function nfa_ee_nci_wait_rsp
2040**
2041** Description Process the result for NCI response
2042**
2043** Returns void
2044**
2045*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002046void nfa_ee_nci_wait_rsp(tNFA_EE_MSG* p_data) {
2047 tNFA_EE_NCI_WAIT_RSP* p_rsp = &p_data->wait_rsp;
Sherry Smith40e67c92014-01-16 10:10:29 -08002048
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002049 DLOG_IF(INFO, nfc_debug_enabled)
2050 << StringPrintf("ee_wait_evt:0x%x wait_rsp:%d", nfa_ee_cb.ee_wait_evt,
2051 nfa_ee_cb.wait_rsp);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002052 if (nfa_ee_cb.wait_rsp) {
2053 if (p_rsp->opcode == NCI_MSG_RF_SET_ROUTING) nfa_ee_cb.wait_rsp--;
2054 }
2055 nfa_ee_report_update_evt();
Sherry Smith40e67c92014-01-16 10:10:29 -08002056}
2057
2058/*******************************************************************************
2059**
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002060** Function nfa_ee_nci_conn
2061**
2062** Description process the connection callback events
2063**
2064** Returns void
2065**
2066*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002067void nfa_ee_nci_conn(tNFA_EE_MSG* p_data) {
2068 tNFA_EE_ECB* p_cb;
2069 tNFA_EE_NCI_CONN* p_cbk = &p_data->conn;
2070 tNFC_CONN* p_conn = p_data->conn.p_data;
2071 NFC_HDR* p_pkt = NULL;
2072 tNFA_EE_CBACK_DATA evt_data = {0};
2073 tNFA_EE_EVT event = NFA_EE_INVALID;
2074 tNFA_EE_CBACK* p_cback = NULL;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002075
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002076 if (p_cbk->event == NFC_CONN_CREATE_CEVT) {
2077 p_cb = nfa_ee_find_ecb(p_cbk->p_data->conn_create.id);
2078 } else {
2079 p_cb = nfa_ee_find_ecb_by_conn_id(p_cbk->conn_id);
2080 if (p_cbk->event == NFC_DATA_CEVT) p_pkt = p_conn->data.p_data;
2081 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002082
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002083 if (p_cb) {
2084 p_cback = p_cb->p_ee_cback;
2085 evt_data.handle = (tNFA_HANDLE)p_cb->nfcee_id | NFA_HANDLE_GROUP_EE;
2086 switch (p_cbk->event) {
2087 case NFC_CONN_CREATE_CEVT:
2088 if (p_conn->conn_create.status == NFC_STATUS_OK) {
2089 p_cb->conn_id = p_cbk->conn_id;
2090 p_cb->conn_st = NFA_EE_CONN_ST_CONN;
2091 } else {
2092 p_cb->conn_st = NFA_EE_CONN_ST_NONE;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002093 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002094 if (p_cb->ecb_flags & NFA_EE_ECB_FLAGS_RESTORE) {
2095 p_cb->ecb_flags &= ~NFA_EE_ECB_FLAGS_RESTORE;
2096 nfa_ee_check_restore_complete();
2097 } else {
2098 evt_data.connect.status = p_conn->conn_create.status;
2099 evt_data.connect.ee_interface = p_cb->use_interface;
2100 event = NFA_EE_CONNECT_EVT;
2101 }
2102 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002103
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002104 case NFC_CONN_CLOSE_CEVT:
2105 if (p_cb->conn_st != NFA_EE_CONN_ST_DISC) event = NFA_EE_DISCONNECT_EVT;
2106 p_cb->conn_st = NFA_EE_CONN_ST_NONE;
2107 p_cb->p_ee_cback = NULL;
2108 p_cb->conn_id = 0;
2109 if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_DISABLING) {
2110 if (nfa_ee_cb.ee_flags & NFA_EE_FLAG_WAIT_DISCONN) {
2111 if (nfa_ee_cb.num_ee_expecting) {
2112 nfa_ee_cb.num_ee_expecting--;
2113 }
2114 }
2115 if (nfa_ee_cb.num_ee_expecting == 0) {
2116 nfa_ee_cb.ee_flags &= ~NFA_EE_FLAG_WAIT_DISCONN;
2117 nfa_ee_check_disable();
2118 }
2119 }
2120 break;
2121
2122 case NFC_DATA_CEVT:
2123 if (p_cb->conn_st == NFA_EE_CONN_ST_CONN) {
2124 /* report data event only in connected state */
2125 if (p_cb->p_ee_cback && p_pkt) {
2126 evt_data.data.len = p_pkt->len;
2127 evt_data.data.p_buf = (uint8_t*)(p_pkt + 1) + p_pkt->offset;
2128 event = NFA_EE_DATA_EVT;
2129 p_pkt = NULL; /* so this function does not free this GKI buffer */
2130 }
2131 }
2132 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002133 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002134
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002135 if ((event != NFA_EE_INVALID) && (p_cback)) (*p_cback)(event, &evt_data);
2136 }
2137 if (p_pkt) GKI_freebuf(p_pkt);
2138}
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002139
2140/*******************************************************************************
2141**
2142** Function nfa_ee_nci_action_ntf
2143**
2144** Description process the NFCEE action callback event
2145**
2146** Returns void
2147**
2148*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002149void nfa_ee_nci_action_ntf(tNFA_EE_MSG* p_data) {
2150 tNFC_EE_ACTION_REVT* p_cbk = p_data->act.p_data;
2151 tNFA_EE_ACTION evt_data;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002152
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002153 evt_data.ee_handle = (tNFA_HANDLE)p_cbk->nfcee_id | NFA_HANDLE_GROUP_EE;
2154 evt_data.trigger = p_cbk->act_data.trigger;
2155 memcpy(&(evt_data.param), &(p_cbk->act_data.param),
2156 sizeof(tNFA_EE_ACTION_PARAM));
Myles Watson1361d522017-09-26 13:39:54 -07002157 tNFA_EE_CBACK_DATA nfa_ee_cback_data;
2158 nfa_ee_cback_data.action = evt_data;
2159 nfa_ee_report_event(NULL, NFA_EE_ACTION_EVT, &nfa_ee_cback_data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002160}
2161
2162/*******************************************************************************
2163**
2164** Function nfa_ee_nci_disc_req_ntf
2165**
2166** Description process the NFCEE discover request callback event
2167**
2168** Returns void
2169**
2170*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002171void nfa_ee_nci_disc_req_ntf(tNFA_EE_MSG* p_data) {
2172 tNFC_EE_DISCOVER_REQ_REVT* p_cbk = p_data->disc_req.p_data;
2173 tNFA_HANDLE ee_handle;
2174 tNFA_EE_ECB* p_cb = NULL;
2175 uint8_t report_ntf = 0;
2176 uint8_t xx;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002177
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002178 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
2179 "num_info: %d cur_ee:%d", p_cbk->num_info, nfa_ee_cb.cur_ee);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002180
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002181 for (xx = 0; xx < p_cbk->num_info; xx++) {
2182 ee_handle = NFA_HANDLE_GROUP_EE | p_cbk->info[xx].nfcee_id;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002183
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002184 p_cb = nfa_ee_find_ecb(p_cbk->info[xx].nfcee_id);
2185 if (!p_cb) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002186 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
2187 "Cannot find cb for NFCEE: 0x%x", p_cbk->info[xx].nfcee_id);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002188 p_cb = nfa_ee_find_ecb(NFA_EE_INVALID);
2189 if (p_cb) {
2190 p_cb->nfcee_id = p_cbk->info[xx].nfcee_id;
2191 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_ORDER;
2192 } else {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002193 LOG(ERROR) << StringPrintf("Cannot allocate cb for NFCEE: 0x%x",
2194 p_cbk->info[xx].nfcee_id);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002195 continue;
2196 }
2197 } else {
2198 report_ntf |= nfa_ee_ecb_to_mask(p_cb);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002199 }
2200
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002201 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_DISC_REQ;
2202 if (p_cbk->info[xx].op == NFC_EE_DISC_OP_ADD) {
2203 if (p_cbk->info[xx].tech_n_mode == NFC_DISCOVERY_TYPE_LISTEN_A) {
2204 p_cb->la_protocol = p_cbk->info[xx].protocol;
2205 } else if (p_cbk->info[xx].tech_n_mode == NFC_DISCOVERY_TYPE_LISTEN_B) {
2206 p_cb->lb_protocol = p_cbk->info[xx].protocol;
2207 } else if (p_cbk->info[xx].tech_n_mode == NFC_DISCOVERY_TYPE_LISTEN_F) {
2208 p_cb->lf_protocol = p_cbk->info[xx].protocol;
2209 } else if (p_cbk->info[xx].tech_n_mode ==
2210 NFC_DISCOVERY_TYPE_LISTEN_B_PRIME) {
2211 p_cb->lbp_protocol = p_cbk->info[xx].protocol;
2212 }
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002213 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002214 "nfcee_id=0x%x ee_status=0x%x ecb_flags=0x%x la_protocol=0x%x "
2215 "la_protocol=0x%x la_protocol=0x%x",
2216 p_cb->nfcee_id, p_cb->ee_status, p_cb->ecb_flags, p_cb->la_protocol,
2217 p_cb->lb_protocol, p_cb->lf_protocol);
2218 } else {
2219 if (p_cbk->info[xx].tech_n_mode == NFC_DISCOVERY_TYPE_LISTEN_A) {
2220 p_cb->la_protocol = 0;
2221 } else if (p_cbk->info[xx].tech_n_mode == NFC_DISCOVERY_TYPE_LISTEN_B) {
2222 p_cb->lb_protocol = 0;
2223 } else if (p_cbk->info[xx].tech_n_mode == NFC_DISCOVERY_TYPE_LISTEN_F) {
2224 p_cb->lf_protocol = 0;
2225 } else if (p_cbk->info[xx].tech_n_mode ==
2226 NFC_DISCOVERY_TYPE_LISTEN_B_PRIME) {
2227 p_cb->lbp_protocol = 0;
2228 }
2229 }
2230 }
Martijn Coenen5c65c3a2013-03-27 13:23:36 -07002231
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002232 /* Report NFA_EE_DISCOVER_REQ_EVT for all active NFCEE */
2233 if (report_ntf) nfa_ee_report_discover_req_evt();
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002234}
2235
2236/*******************************************************************************
2237**
2238** Function nfa_ee_is_active
2239**
2240** Description Check if the given NFCEE is active
2241**
2242** Returns TRUE if the given NFCEE is active
2243**
2244*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002245bool nfa_ee_is_active(tNFA_HANDLE nfcee_id) {
2246 bool is_active = false;
2247 int xx;
2248 tNFA_EE_ECB* p_cb = nfa_ee_cb.ecb;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002249
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002250 if ((NFA_HANDLE_GROUP_MASK & nfcee_id) == NFA_HANDLE_GROUP_EE)
2251 nfcee_id &= NFA_HANDLE_MASK;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002252
Love Khanna1d062772018-04-10 21:10:02 +05302253 if (nfcee_id == NFC_DH_ID) return true;
2254
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002255 /* compose output */
2256 for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++) {
2257 if ((tNFA_HANDLE)p_cb->nfcee_id == nfcee_id) {
2258 if (p_cb->ee_status == NFA_EE_STATUS_ACTIVE) {
2259 is_active = true;
2260 }
2261 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002262 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002263 }
2264 return is_active;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002265}
2266
2267/*******************************************************************************
2268**
2269** Function nfa_ee_get_tech_route
2270**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -08002271** Description Given a power state, find the technology routing
2272** destination. The result is filled in the given p_handles
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002273** in the order of A, B, F, Bprime
2274**
2275** Returns None
2276**
2277*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002278void nfa_ee_get_tech_route(uint8_t power_state, uint8_t* p_handles) {
2279 int xx, yy;
2280 tNFA_EE_ECB* p_cb;
2281 uint8_t tech_mask_list[NFA_EE_MAX_TECH_ROUTE] = {
2282 NFA_TECHNOLOGY_MASK_A, NFA_TECHNOLOGY_MASK_B, NFA_TECHNOLOGY_MASK_F,
2283 NFA_TECHNOLOGY_MASK_B_PRIME};
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002284
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002285 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%d", power_state);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002286
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002287 for (xx = 0; xx < NFA_EE_MAX_TECH_ROUTE; xx++) {
2288 p_handles[xx] = NFC_DH_ID;
2289 p_cb = &nfa_ee_cb.ecb[nfa_ee_cb.cur_ee - 1];
2290 for (yy = 0; yy < nfa_ee_cb.cur_ee; yy++, p_cb--) {
2291 if (p_cb->ee_status == NFC_NFCEE_STATUS_ACTIVE) {
2292 switch (power_state) {
2293 case NFA_EE_PWR_STATE_ON:
2294 if (p_cb->tech_switch_on & tech_mask_list[xx])
2295 p_handles[xx] = p_cb->nfcee_id;
2296 break;
2297 case NFA_EE_PWR_STATE_SWITCH_OFF:
2298 if (p_cb->tech_switch_off & tech_mask_list[xx])
2299 p_handles[xx] = p_cb->nfcee_id;
2300 break;
2301 case NFA_EE_PWR_STATE_BATT_OFF:
2302 if (p_cb->tech_battery_off & tech_mask_list[xx])
2303 p_handles[xx] = p_cb->nfcee_id;
2304 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002305 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002306 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002307 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002308 }
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002309 DLOG_IF(INFO, nfc_debug_enabled)
2310 << StringPrintf("0x%x, 0x%x, 0x%x, 0x%x", p_handles[0], p_handles[1],
2311 p_handles[2], p_handles[3]);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002312}
2313
2314/*******************************************************************************
2315**
Sherry Smitha96095b2013-12-17 18:09:29 -08002316** Function nfa_ee_check_set_routing
2317**
2318** Description If the new size exceeds the capacity of next block,
Ruchi Kandoi552f2b72017-01-28 16:22:55 -08002319** send the routing command now and reset the related
2320** parameters.
Sherry Smitha96095b2013-12-17 18:09:29 -08002321**
2322** Returns void
2323**
2324*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002325void nfa_ee_check_set_routing(uint16_t new_size, int* p_max_len, uint8_t* p,
2326 int* p_cur_offset) {
2327 uint8_t max_tlv = (uint8_t)((*p_max_len > NFA_EE_ROUT_MAX_TLV_SIZE)
2328 ? NFA_EE_ROUT_MAX_TLV_SIZE
2329 : *p_max_len);
Sherry Smitha96095b2013-12-17 18:09:29 -08002330
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002331 if (new_size + *p_cur_offset > max_tlv) {
2332 if (NFC_SetRouting(true, *p, *p_cur_offset, p + 1) == NFA_STATUS_OK) {
2333 nfa_ee_cb.wait_rsp++;
Sherry Smitha96095b2013-12-17 18:09:29 -08002334 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002335 /* after the routing command is sent, re-use the same buffer to send the
2336 * next routing command.
2337 * reset the related parameters */
2338 if (*p_max_len > *p_cur_offset)
2339 *p_max_len -= *p_cur_offset; /* the max is reduced */
2340 else
2341 *p_max_len = 0;
2342 *p_cur_offset = 0; /* nothing is in queue any more */
2343 *p = 0; /* num_tlv=0 */
2344 }
Sherry Smitha96095b2013-12-17 18:09:29 -08002345}
2346
2347/*******************************************************************************
2348**
Love Khannab4ac88d2017-04-06 16:25:36 +05302349** Function nfa_ee_route_add_one_ecb_order
2350**
2351** Description Add the routing entries for NFCEE/DH in order defined
2352**
2353** Returns NFA_STATUS_OK, if ok to continue
2354**
2355*******************************************************************************/
2356void nfa_ee_route_add_one_ecb_by_route_order(tNFA_EE_ECB* p_cb, int rout_type,
2357 int* p_max_len, bool more,
2358 uint8_t* ps, int* p_cur_offset) {
2359 nfa_ee_check_set_routing(p_cb->size_mask, p_max_len, ps, p_cur_offset);
2360
2361 /* use the first byte of the buffer (ps) to keep the num_tlv */
2362 uint8_t num_tlv = *ps;
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002363 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
Love Khannab4ac88d2017-04-06 16:25:36 +05302364 "%s - max_len:%d, cur_offset:%d, more:%d, num_tlv:%d,rout_type:- %d",
Love Khannaf3c018a2017-05-11 18:34:32 +05302365 __func__, *p_max_len, *p_cur_offset, more, num_tlv, rout_type);
Love Khannab4ac88d2017-04-06 16:25:36 +05302366 uint8_t* pp = ps + 1 + *p_cur_offset;
2367 uint8_t* p = pp;
2368 uint16_t tlv_size = (uint8_t)*p_cur_offset;
2369
2370 switch (rout_type) {
2371 case NCI_ROUTE_ORDER_TECHNOLOGY: {
2372 nfa_ee_add_tech_route_to_ecb(p_cb, pp, p, ps, p_cur_offset);
2373 } break;
2374
2375 case NCI_ROUTE_ORDER_PROTOCOL: {
2376 nfa_ee_add_proto_route_to_ecb(p_cb, pp, p, ps, p_cur_offset);
2377 } break;
2378 case NCI_ROUTE_ORDER_AID: {
2379 nfa_ee_add_aid_route_to_ecb(p_cb, pp, p, ps, p_cur_offset, p_max_len);
2380 } break;
Love Khanna1d062772018-04-10 21:10:02 +05302381 case NCI_ROUTE_ORDER_SYS_CODE: {
2382 nfa_ee_add_sys_code_route_to_ecb(p_cb, pp, p, ps, p_cur_offset,
2383 p_max_len);
2384 } break;
Love Khannab4ac88d2017-04-06 16:25:36 +05302385 default: {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002386 DLOG_IF(INFO, nfc_debug_enabled)
2387 << StringPrintf("%s - Route type - NA:- %d", __func__, rout_type);
Love Khannab4ac88d2017-04-06 16:25:36 +05302388 }
2389 }
2390
2391 /* update the total number of entries */
2392 num_tlv = *ps;
2393
2394 tlv_size = nfa_ee_total_lmrt_size();
2395 if (tlv_size) {
2396 nfa_ee_cb.ee_cfged |= nfa_ee_ecb_to_mask(p_cb);
2397 }
2398 if (p_cb->ecb_flags & NFA_EE_ECB_FLAGS_ROUTING) {
2399 nfa_ee_cb.ee_cfg_sts |= NFA_EE_STS_CHANGED_ROUTING;
2400 }
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002401 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
2402 "ee_cfg_sts:0x%02x lmrt_size:%d", nfa_ee_cb.ee_cfg_sts, tlv_size);
Love Khannab4ac88d2017-04-06 16:25:36 +05302403
2404 if (more == false) {
2405 /* last entry. update routing table now */
2406 if (nfa_ee_cb.ee_cfg_sts & NFA_EE_STS_CHANGED_ROUTING) {
2407 if (tlv_size) {
2408 nfa_ee_cb.ee_cfg_sts |= NFA_EE_STS_PREV_ROUTING;
2409 } else {
2410 nfa_ee_cb.ee_cfg_sts &= ~NFA_EE_STS_PREV_ROUTING;
2411 }
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002412 DLOG_IF(INFO, nfc_debug_enabled)
2413 << StringPrintf("%s : set routing num_tlv:%d tlv_size:%d", __func__,
2414 num_tlv, tlv_size);
Love Khannab4ac88d2017-04-06 16:25:36 +05302415 if (NFC_SetRouting(more, num_tlv, (uint8_t)(*p_cur_offset), ps + 1) ==
2416 NFA_STATUS_OK) {
2417 nfa_ee_cb.wait_rsp++;
2418 }
2419 } else if (nfa_ee_cb.ee_cfg_sts & NFA_EE_STS_PREV_ROUTING) {
2420 if (tlv_size == 0) {
2421 nfa_ee_cb.ee_cfg_sts &= ~NFA_EE_STS_PREV_ROUTING;
2422 /* indicated routing is configured to NFCC */
2423 nfa_ee_cb.ee_cfg_sts |= NFA_EE_STS_CHANGED_ROUTING;
2424 if (NFC_SetRouting(more, 0, 0, ps + 1) == NFA_STATUS_OK) {
2425 nfa_ee_cb.wait_rsp++;
2426 }
2427 }
2428 }
2429 }
2430}
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002431
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002432/*******************************************************************************
2433**
2434** Function nfa_ee_need_recfg
2435**
2436** Description Check if any API function to configure the routing table or
2437** VS is called since last update
2438**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -08002439** The algorithm for the NFCEE configuration handling is as
2440** follows:
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002441**
2442** Each NFCEE_ID/DH has its own control block - tNFA_EE_ECB
2443** Each control block uses ecb_flags to keep track if an API
Ruchi Kandoi552f2b72017-01-28 16:22:55 -08002444** that changes routing/VS is invoked. This ecb_flags is
2445** cleared at the end of nfa_ee_update_rout().
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002446**
2447** nfa_ee_cb.ee_cfged is the bitmask of the control blocks with
2448** routing/VS configuration and NFA_EE_CFGED_UPDATE_NOW.
Ruchi Kandoi552f2b72017-01-28 16:22:55 -08002449** nfa_ee_cb.ee_cfged is cleared and re-calculated at the end
2450** of nfa_ee_update_rout().
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002451**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -08002452** nfa_ee_cb.ee_cfg_sts is used to check is any status is
2453** changed and the associated command is issued to NFCC.
2454** nfa_ee_cb.ee_cfg_sts is AND with NFA_EE_STS_PREV at the end
2455** of nfa_ee_update_rout() to clear the NFA_EE_STS_CHANGED bits
2456** (except NFA_EE_STS_CHANGED_CANNED_VS is cleared in
2457** nfa_ee_vs_cback)
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002458**
2459** Returns TRUE if any configuration is changed
2460**
2461*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002462static bool nfa_ee_need_recfg(void) {
2463 bool needed = false;
2464 uint32_t xx;
2465 tNFA_EE_ECB* p_cb;
2466 uint8_t mask;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002467
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002468 DLOG_IF(INFO, nfc_debug_enabled)
2469 << StringPrintf("ee_cfged: 0x%02x ee_cfg_sts: 0x%02x", nfa_ee_cb.ee_cfged,
2470 nfa_ee_cb.ee_cfg_sts);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002471 /* if no routing/vs is configured, do not need to send the info to NFCC */
2472 if (nfa_ee_cb.ee_cfged || nfa_ee_cb.ee_cfg_sts) {
2473 if (nfa_ee_cb.ee_cfg_sts & NFA_EE_STS_CHANGED) {
2474 needed = true;
2475 } else {
2476 p_cb = &nfa_ee_cb.ecb[NFA_EE_CB_4_DH];
2477 mask = 1 << NFA_EE_CB_4_DH;
2478 for (xx = 0; xx <= nfa_ee_cb.cur_ee; xx++) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002479 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
2480 "%d: ecb_flags : 0x%02x, mask: 0x%02x", xx, p_cb->ecb_flags, mask);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002481 if ((p_cb->ecb_flags) && (nfa_ee_cb.ee_cfged & mask)) {
2482 needed = true;
2483 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002484 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002485 p_cb = &nfa_ee_cb.ecb[xx];
2486 mask = 1 << xx;
2487 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002488 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002489 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002490
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002491 return needed;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002492}
2493
2494/*******************************************************************************
2495**
2496** Function nfa_ee_rout_timeout
2497**
2498** Description Anytime VS or routing entries are changed,
2499** a 1 second timer is started. This function is called when
2500** the timer expires or NFA_EeUpdateNow() is called.
2501**
2502** Returns void
2503**
2504*******************************************************************************/
Ruchi Kandoi9ba6d242017-10-13 16:07:01 -07002505void nfa_ee_rout_timeout(__attribute__((unused)) tNFA_EE_MSG* p_data) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002506 uint8_t ee_cfged = nfa_ee_cb.ee_cfged;
Sherry Smith40e67c92014-01-16 10:10:29 -08002507
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002508 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002509 if (nfa_ee_need_recfg()) {
2510 /* discovery is not started */
2511 nfa_ee_update_rout();
2512 }
Sherry Smithc2ae2692014-02-05 11:59:23 -08002513
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002514 if (nfa_ee_cb.wait_rsp) nfa_ee_cb.ee_wait_evt |= NFA_EE_WAIT_UPDATE_RSP;
2515 if (ee_cfged & NFA_EE_CFGED_UPDATE_NOW) {
2516 /* need to report NFA_EE_UPDATED_EVT when done updating NFCC */
2517 nfa_ee_cb.ee_wait_evt |= NFA_EE_WAIT_UPDATE;
2518 if (!nfa_ee_cb.wait_rsp) {
2519 nfa_ee_report_update_evt();
Sherry Smith40e67c92014-01-16 10:10:29 -08002520 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002521 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002522}
2523
2524/*******************************************************************************
2525**
2526** Function nfa_ee_discv_timeout
2527**
2528** Description
2529**
2530**
2531**
2532** Returns void
2533**
2534*******************************************************************************/
Ruchi Kandoi9ba6d242017-10-13 16:07:01 -07002535void nfa_ee_discv_timeout(__attribute__((unused)) tNFA_EE_MSG* p_data) {
Love Khanna81e4f812017-06-02 17:50:19 +05302536 if (NFA_GetNCIVersion() != NCI_VERSION_2_0) NFC_NfceeDiscover(false);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002537 if (nfa_ee_cb.p_enable_cback)
2538 (*nfa_ee_cb.p_enable_cback)(NFA_EE_DISC_STS_OFF);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002539}
2540
2541/*******************************************************************************
2542**
2543** Function nfa_ee_lmrt_to_nfcc
2544**
2545** Description This function would set the listen mode routing table
2546** to NFCC.
2547**
2548** Returns void
2549**
2550*******************************************************************************/
Ruchi Kandoi9ba6d242017-10-13 16:07:01 -07002551void nfa_ee_lmrt_to_nfcc(__attribute__((unused)) tNFA_EE_MSG* p_data) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002552 int xx;
2553 tNFA_EE_ECB* p_cb;
2554 uint8_t* p = NULL;
2555 bool more = true;
Love Khannab4ac88d2017-04-06 16:25:36 +05302556 bool check = true;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002557 uint8_t last_active = NFA_EE_INVALID;
Love Khannab4ac88d2017-04-06 16:25:36 +05302558 int max_len;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002559 tNFA_STATUS status = NFA_STATUS_FAILED;
2560 int cur_offset;
2561 uint8_t max_tlv;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002562
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002563 /* update routing table: DH and the activated NFCEEs */
2564 p = (uint8_t*)GKI_getbuf(NFA_EE_ROUT_BUF_SIZE);
2565 if (p == NULL) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002566 LOG(ERROR) << StringPrintf("no buffer to send routing info.");
Myles Watson1361d522017-09-26 13:39:54 -07002567 tNFA_EE_CBACK_DATA nfa_ee_cback_data;
2568 nfa_ee_cback_data.status = status;
2569 nfa_ee_report_event(NULL, NFA_EE_NO_MEM_ERR_EVT, &nfa_ee_cback_data);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002570 return;
2571 }
2572
2573 /* find the last active NFCEE. */
2574 p_cb = &nfa_ee_cb.ecb[nfa_ee_cb.cur_ee - 1];
2575 for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb--) {
2576 if (p_cb->ee_status == NFC_NFCEE_STATUS_ACTIVE) {
2577 if (last_active == NFA_EE_INVALID) {
2578 last_active = p_cb->nfcee_id;
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002579 DLOG_IF(INFO, nfc_debug_enabled)
2580 << StringPrintf("last_active: 0x%x", last_active);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002581 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002582 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002583 }
2584 if (last_active == NFA_EE_INVALID) {
Love Khannab4ac88d2017-04-06 16:25:36 +05302585 check = false;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002586 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002587
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002588 max_len = NFC_GetLmrtSize();
2589 max_tlv =
2590 (uint8_t)((max_len > NFA_EE_ROUT_MAX_TLV_SIZE) ? NFA_EE_ROUT_MAX_TLV_SIZE
2591 : max_len);
2592 cur_offset = 0;
2593 /* use the first byte of the buffer (p) to keep the num_tlv */
2594 *p = 0;
Love Khannab4ac88d2017-04-06 16:25:36 +05302595 for (int rt = NCI_ROUTE_ORDER_AID; rt <= NCI_ROUTE_ORDER_TECHNOLOGY; rt++) {
2596 /* add the routing entries for NFCEEs */
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002597 p_cb = &nfa_ee_cb.ecb[0];
Love Khanna1d062772018-04-10 21:10:02 +05302598
Love Khannab4ac88d2017-04-06 16:25:36 +05302599 for (xx = 0; (xx < nfa_ee_cb.cur_ee) && check; xx++, p_cb++) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002600 if (p_cb->ee_status == NFC_NFCEE_STATUS_ACTIVE) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002601 DLOG_IF(INFO, nfc_debug_enabled)
2602 << StringPrintf("%s --add the routing for NFCEEs!!", __func__);
Love Khannab4ac88d2017-04-06 16:25:36 +05302603 nfa_ee_route_add_one_ecb_by_route_order(p_cb, rt, &max_len, more, p,
2604 &cur_offset);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002605 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002606 }
Love Khannab4ac88d2017-04-06 16:25:36 +05302607 if (rt == NCI_ROUTE_ORDER_TECHNOLOGY) more = false;
2608 /* add the routing entries for DH */
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002609 DLOG_IF(INFO, nfc_debug_enabled)
2610 << StringPrintf("%s --add the routing for DH!!", __func__);
Love Khannab4ac88d2017-04-06 16:25:36 +05302611 nfa_ee_route_add_one_ecb_by_route_order(&nfa_ee_cb.ecb[NFA_EE_CB_4_DH], rt,
2612 &max_len, more, p, &cur_offset);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002613 }
Love Khannab4ac88d2017-04-06 16:25:36 +05302614
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002615 GKI_freebuf(p);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002616}
2617
2618/*******************************************************************************
2619**
2620** Function nfa_ee_update_rout
2621**
2622** Description This function would set the VS and listen mode routing table
2623** to NFCC.
2624**
2625** Returns void
2626**
2627*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002628void nfa_ee_update_rout(void) {
2629 int xx;
2630 tNFA_EE_ECB* p_cb;
2631 uint8_t mask;
Myles Watson1361d522017-09-26 13:39:54 -07002632 tNFA_EE_MSG nfa_ee_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002633
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002634 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
2635 "nfa_ee_update_rout ee_cfg_sts:0x%02x", nfa_ee_cb.ee_cfg_sts);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002636
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002637 /* use action function to send routing and VS configuration to NFCC */
Myles Watson1361d522017-09-26 13:39:54 -07002638 nfa_ee_msg.hdr.event = NFA_EE_CFG_TO_NFCC_EVT;
2639 nfa_ee_evt_hdlr(&nfa_ee_msg.hdr);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002640
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002641 /* all configuration is updated to NFCC, clear the status mask */
2642 nfa_ee_cb.ee_cfg_sts &= NFA_EE_STS_PREV;
2643 nfa_ee_cb.ee_cfged = 0;
2644 p_cb = &nfa_ee_cb.ecb[0];
2645 for (xx = 0; xx < NFA_EE_NUM_ECBS; xx++, p_cb++) {
2646 p_cb->ecb_flags = 0;
2647 mask = (1 << xx);
2648 if (p_cb->tech_switch_on | p_cb->tech_switch_off | p_cb->tech_battery_off |
2649 p_cb->proto_switch_on | p_cb->proto_switch_off |
Love Khanna1d062772018-04-10 21:10:02 +05302650 p_cb->proto_battery_off | p_cb->aid_entries |
2651 p_cb->sys_code_cfg_entries) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002652 /* this entry has routing configuration. mark it configured */
2653 nfa_ee_cb.ee_cfged |= mask;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002654 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08002655 }
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07002656 DLOG_IF(INFO, nfc_debug_enabled)
2657 << StringPrintf("nfa_ee_update_rout ee_cfg_sts:0x%02x ee_cfged:0x%02x",
2658 nfa_ee_cb.ee_cfg_sts, nfa_ee_cb.ee_cfged);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08002659}