The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Evan Chu | e9629ba | 2014-01-31 11:18:47 -0500 | [diff] [blame] | 3 | * Copyright (C) 2010-2014 Broadcom Corporation |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
| 19 | /****************************************************************************** |
| 20 | * |
| 21 | * This file contains the action functions for NFA-EE |
| 22 | * |
| 23 | ******************************************************************************/ |
| 24 | #include <string.h> |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 25 | |
| 26 | #include <android-base/stringprintf.h> |
| 27 | #include <base/logging.h> |
| 28 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 29 | #include "nfa_api.h" |
| 30 | #include "nfa_dm_int.h" |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 31 | #include "nfa_ee_int.h" |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 32 | |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 33 | using android::base::StringPrintf; |
| 34 | |
| 35 | extern bool nfc_debug_enabled; |
| 36 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 37 | /* 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 42 | #define NFA_EE_ROUT_TIMEOUT_VAL 1000 |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 43 | #endif |
| 44 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 45 | #define NFA_EE_ROUT_BUF_SIZE 540 |
| 46 | #define NFA_EE_ROUT_MAX_TLV_SIZE 0xFD |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 47 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 48 | /* 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 |
| 51 | const 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 53 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 54 | const 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 56 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 57 | /* 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 Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 60 | |
Arach MOHAMMED BRAHIM | 2f08f7a | 2017-07-12 10:20:10 +0200 | [diff] [blame] | 61 | static void add_route_tech_proto_tlv(uint8_t** pp, uint8_t tlv_type, |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 62 | uint8_t nfcee_id, uint8_t pwr_cfg, |
| 63 | uint8_t tech_proto) { |
Arach MOHAMMED BRAHIM | 2f08f7a | 2017-07-12 10:20:10 +0200 | [diff] [blame] | 64 | *(*pp)++ = tlv_type; |
| 65 | *(*pp)++ = 3; |
| 66 | *(*pp)++ = nfcee_id; |
| 67 | *(*pp)++ = pwr_cfg; |
| 68 | *(*pp)++ = tech_proto; |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 69 | } |
| 70 | |
Arach MOHAMMED BRAHIM | 2f08f7a | 2017-07-12 10:20:10 +0200 | [diff] [blame] | 71 | static void add_route_aid_tlv(uint8_t** pp, uint8_t* pa, uint8_t nfcee_id, |
Love Khanna | f3c018a | 2017-05-11 18:34:32 +0530 | [diff] [blame] | 72 | uint8_t pwr_cfg, uint8_t tag) { |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 73 | pa++; /* EMV tag */ |
| 74 | uint8_t len = *pa++; /* aid_len */ |
Arach MOHAMMED BRAHIM | 2f08f7a | 2017-07-12 10:20:10 +0200 | [diff] [blame] | 75 | *(*pp)++ = tag; |
| 76 | *(*pp)++ = len + 2; |
| 77 | *(*pp)++ = nfcee_id; |
| 78 | *(*pp)++ = pwr_cfg; |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 79 | /* copy the AID */ |
Arach MOHAMMED BRAHIM | 2f08f7a | 2017-07-12 10:20:10 +0200 | [diff] [blame] | 80 | memcpy(*pp, pa, len); |
| 81 | *pp += len; |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 82 | } |
| 83 | |
Love Khanna | 1d06277 | 2018-04-10 21:10:02 +0530 | [diff] [blame] | 84 | static 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 96 | const 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 99 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 100 | const 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 103 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 104 | static void nfa_ee_report_discover_req_evt(void); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 105 | static void nfa_ee_build_discover_req_evt(tNFA_EE_DISCOVER_REQ* p_evt_data); |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 106 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 108 | /******************************************************************************* |
| 109 | ** |
Paul Chaisson | f23dcad | 2013-11-25 16:51:23 -0500 | [diff] [blame] | 110 | ** Function nfa_ee_trace_aid |
| 111 | ** |
| 112 | ** Description trace AID |
| 113 | ** |
| 114 | ** Returns void |
| 115 | ** |
| 116 | *******************************************************************************/ |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 117 | static void nfa_ee_trace_aid(std::string p_str, uint8_t id, uint8_t aid_len, |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 118 | uint8_t* p) { |
| 119 | int len = aid_len; |
| 120 | int xx, yy = 0; |
| 121 | char buff[100]; |
Paul Chaisson | f23dcad | 2013-11-25 16:51:23 -0500 | [diff] [blame] | 122 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 123 | buff[0] = 0; |
| 124 | if (aid_len > NFA_MAX_AID_LEN) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 125 | LOG(ERROR) << StringPrintf("aid_len: %d exceeds max(%d)", aid_len, |
| 126 | NFA_MAX_AID_LEN); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 127 | len = NFA_MAX_AID_LEN; |
| 128 | } |
| 129 | for (xx = 0; xx < len; xx++) { |
| 130 | yy += sprintf(&buff[yy], "%02x ", *p); |
| 131 | p++; |
| 132 | } |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 133 | 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 Chaisson | f23dcad | 2013-11-25 16:51:23 -0500 | [diff] [blame] | 135 | } |
Sherry Smith | 43ef645 | 2013-12-02 15:44:52 -0800 | [diff] [blame] | 136 | |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 147 | static void nfa_ee_update_route_size(tNFA_EE_ECB* p_cb) { |
| 148 | int xx; |
| 149 | uint8_t power_cfg = 0; |
Sherry Smith | 43ef645 | 2013-12-02 15:44:52 -0800 | [diff] [blame] | 150 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 151 | 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 Khanna | 514a14b | 2018-03-23 00:19:13 +0530 | [diff] [blame] | 161 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 170 | if (power_cfg) { |
Love Khanna | 514a14b | 2018-03-23 00:19:13 +0530 | [diff] [blame] | 171 | /* 5 = 1 (tag) + 1 (len) + 1(nfcee_id) + 1(power cfg) + 1 (technology) */ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 172 | p_cb->size_mask += 5; |
Sherry Smith | 43ef645 | 2013-12-02 15:44:52 -0800 | [diff] [blame] | 173 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 174 | } |
Sherry Smith | 43ef645 | 2013-12-02 15:44:52 -0800 | [diff] [blame] | 175 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 176 | /* 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 Khanna | 514a14b | 2018-03-23 00:19:13 +0530 | [diff] [blame] | 185 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 194 | if (power_cfg) { |
| 195 | /* 5 = 1 (tag) + 1 (len) + 1(nfcee_id) + 1(power cfg) + 1 (protocol) */ |
| 196 | p_cb->size_mask += 5; |
Sherry Smith | 43ef645 | 2013-12-02 15:44:52 -0800 | [diff] [blame] | 197 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 198 | } |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 199 | 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 Smith | 43ef645 | 2013-12-02 15:44:52 -0800 | [diff] [blame] | 202 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 214 | static 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 Smith | 43ef645 | 2013-12-02 15:44:52 -0800 | [diff] [blame] | 218 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 219 | 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 Smith | 43ef645 | 2013-12-02 15:44:52 -0800 | [diff] [blame] | 233 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 234 | } |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 235 | 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 Smith | 43ef645 | 2013-12-02 15:44:52 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /******************************************************************************* |
| 241 | ** |
Love Khanna | 1d06277 | 2018-04-10 21:10:02 +0530 | [diff] [blame] | 242 | ** 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 | *******************************************************************************/ |
| 250 | static 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 Smith | 43ef645 | 2013-12-02 15:44:52 -0800 | [diff] [blame] | 268 | ** Function nfa_ee_total_lmrt_size |
| 269 | ** |
| 270 | ** Description the total listen mode routing table size |
| 271 | ** |
Ruchi Kandoi | 512ee63 | 2017-01-03 13:59:10 -0800 | [diff] [blame] | 272 | ** Returns uint16_t |
Sherry Smith | 43ef645 | 2013-12-02 15:44:52 -0800 | [diff] [blame] | 273 | ** |
| 274 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 275 | static uint16_t nfa_ee_total_lmrt_size(void) { |
| 276 | int xx; |
| 277 | uint16_t lmrt_size = 0; |
| 278 | tNFA_EE_ECB* p_cb; |
Sherry Smith | 43ef645 | 2013-12-02 15:44:52 -0800 | [diff] [blame] | 279 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 280 | 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 Khanna | 1d06277 | 2018-04-10 21:10:02 +0530 | [diff] [blame] | 283 | lmrt_size += p_cb->size_sys_code; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 284 | 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 Khanna | 1d06277 | 2018-04-10 21:10:02 +0530 | [diff] [blame] | 289 | lmrt_size += p_cb->size_sys_code; |
Sherry Smith | 43ef645 | 2013-12-02 15:44:52 -0800 | [diff] [blame] | 290 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 291 | } |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 292 | DLOG_IF(INFO, nfc_debug_enabled) |
| 293 | << StringPrintf("nfa_ee_total_lmrt_size size:%d", lmrt_size); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 294 | return lmrt_size; |
Sherry Smith | 43ef645 | 2013-12-02 15:44:52 -0800 | [diff] [blame] | 295 | } |
| 296 | |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 297 | static 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 Khanna | 514a14b | 2018-03-23 00:19:13 +0530 | [diff] [blame] | 311 | 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 Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 320 | if (power_cfg) { |
Arach MOHAMMED BRAHIM | 2f08f7a | 2017-07-12 10:20:10 +0200 | [diff] [blame] | 321 | add_route_tech_proto_tlv(&pp, NFC_ROUTE_TAG_TECH, p_cb->nfcee_id, |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 322 | 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 | |
| 335 | static 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 Khanna | c6bd78b | 2017-04-14 16:19:12 +0530 | [diff] [blame] | 342 | uint8_t power_cfg = 0, proto_tag = 0; |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 343 | 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 Khanna | c6bd78b | 2017-04-14 16:19:12 +0530 | [diff] [blame] | 350 | /* 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 Khanna | 7e5f88f | 2017-07-11 19:46:27 +0530 | [diff] [blame] | 354 | |
| 355 | /* Enable screen on lock power state for ISO-DEP protocol to |
| 356 | enable HCE screen lock */ |
Love Khanna | 514a14b | 2018-03-23 00:19:13 +0530 | [diff] [blame] | 357 | 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 Khanna | c6bd78b | 2017-04-14 16:19:12 +0530 | [diff] [blame] | 366 | } else { |
| 367 | proto_tag = NFC_ROUTE_TAG_PROTO; |
| 368 | } |
| 369 | |
Arach MOHAMMED BRAHIM | 2f08f7a | 2017-07-12 10:20:10 +0200 | [diff] [blame] | 370 | add_route_tech_proto_tlv(&pp, proto_tag, p_cb->nfcee_id, power_cfg, |
Love Khanna | c6bd78b | 2017-04-14 16:19:12 +0530 | [diff] [blame] | 371 | nfa_ee_proto_list[xx]); |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 372 | 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 BRAHIM | 2f08f7a | 2017-07-12 10:20:10 +0200 | [diff] [blame] | 380 | add_route_tech_proto_tlv(&pp, NFC_ROUTE_TAG_PROTO, NFC_DH_ID, |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 381 | NCI_ROUTE_PWR_STATE_ON, NFC_PROTOCOL_NFC_DEP); |
| 382 | |
| 383 | num_tlv++; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 384 | DLOG_IF(INFO, nfc_debug_enabled) |
| 385 | << StringPrintf("%s - NFC DEP added for DH!!!", __func__); |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 386 | } |
| 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 | |
| 393 | static 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 Khanna | f3c018a | 2017-05-11 18:34:32 +0530 | [diff] [blame] | 404 | uint8_t route_qual = 0; |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 405 | 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 Khanna | f3c018a | 2017-05-11 18:34:32 +0530 | [diff] [blame] | 410 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 411 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 412 | "%s - p_cb->aid_info%x", __func__, p_cb->aid_info[xx]); |
Love Khanna | f3c018a | 2017-05-11 18:34:32 +0530 | [diff] [blame] | 413 | if (p_cb->aid_info[xx] & NCI_ROUTE_QUAL_LONG_SELECT) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 414 | DLOG_IF(INFO, nfc_debug_enabled) |
| 415 | << StringPrintf("%s - %x", __func__, |
| 416 | p_cb->aid_info[xx] & NCI_ROUTE_QUAL_LONG_SELECT); |
Love Khanna | f3c018a | 2017-05-11 18:34:32 +0530 | [diff] [blame] | 417 | route_qual |= NCI_ROUTE_QUAL_LONG_SELECT; |
| 418 | } |
| 419 | if (p_cb->aid_info[xx] & NCI_ROUTE_QUAL_SHORT_SELECT) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 420 | DLOG_IF(INFO, nfc_debug_enabled) |
| 421 | << StringPrintf("%s - %x", __func__, |
| 422 | p_cb->aid_info[xx] & NCI_ROUTE_QUAL_SHORT_SELECT); |
Love Khanna | f3c018a | 2017-05-11 18:34:32 +0530 | [diff] [blame] | 423 | 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 BRAHIM | 2f08f7a | 2017-07-12 10:20:10 +0200 | [diff] [blame] | 429 | add_route_aid_tlv(&pp, pa, p_cb->nfcee_id, p_cb->aid_pwr_cfg[xx], tag); |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 430 | } |
| 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 450 | DLOG_IF(INFO, nfc_debug_enabled) |
| 451 | << StringPrintf("%s - No AID entries available", __func__); |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | |
Love Khanna | 1d06277 | 2018-04-10 21:10:02 +0530 | [diff] [blame] | 455 | static 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 Chaisson | f23dcad | 2013-11-25 16:51:23 -0500 | [diff] [blame] | 508 | /******************************************************************************* |
| 509 | ** |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 510 | ** Function nfa_ee_conn_cback |
| 511 | ** |
| 512 | ** Description process connection callback event from stack |
| 513 | ** |
| 514 | ** Returns void |
| 515 | ** |
| 516 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 517 | static void nfa_ee_conn_cback(uint8_t conn_id, tNFC_CONN_EVT event, |
| 518 | tNFC_CONN* p_data) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 519 | tNFA_EE_NCI_CONN cbk; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 520 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 521 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 523 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 524 | 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 Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 532 | tNFA_EE_MSG nfa_ee_msg; |
| 533 | nfa_ee_msg.conn = cbk; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 534 | |
Myles Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 535 | nfa_ee_evt_hdlr(&nfa_ee_msg.hdr); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 536 | } |
| 537 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 538 | /******************************************************************************* |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 547 | int nfa_ee_find_total_aid_len(tNFA_EE_ECB* p_cb, int start_entry) { |
| 548 | int len = 0, xx; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 549 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 550 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 553 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 554 | } |
| 555 | return len; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 556 | } |
| 557 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 558 | /******************************************************************************* |
| 559 | ** |
Love Khanna | 1d06277 | 2018-04-10 21:10:02 +0530 | [diff] [blame] | 560 | ** 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 | *******************************************************************************/ |
| 568 | int 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 | *******************************************************************************/ |
| 588 | int 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 599 | ** 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 607 | tNFA_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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 611 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 612 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 625 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 626 | offset += p_ecb->aid_len[xx]; |
| 627 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 628 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 629 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /******************************************************************************* |
Love Khanna | 1d06277 | 2018-04-10 21:10:02 +0530 | [diff] [blame] | 641 | ** |
| 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 | *******************************************************************************/ |
| 651 | tNFA_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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 684 | ** |
| 685 | ** Function nfa_ee_report_event |
| 686 | ** |
| 687 | ** Description report the given event to the callback |
| 688 | ** |
| 689 | ** Returns void |
| 690 | ** |
| 691 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 692 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 695 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 696 | /* 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 705 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 706 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 707 | } |
| 708 | /******************************************************************************* |
| 709 | ** |
| 710 | ** Function nfa_ee_start_timer |
| 711 | ** |
| 712 | ** Description start the de-bounce timer |
| 713 | ** |
| 714 | ** Returns void |
| 715 | ** |
| 716 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 717 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | /******************************************************************************* |
| 724 | ** |
| 725 | ** Function nfa_ee_api_discover |
| 726 | ** |
| 727 | ** Description process discover command from user |
| 728 | ** |
| 729 | ** Returns void |
| 730 | ** |
| 731 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 732 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 735 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 736 | DLOG_IF(INFO, nfc_debug_enabled) |
| 737 | << StringPrintf("in_use:%d", nfa_ee_cb.discv_timer.in_use); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 738 | if (nfa_ee_cb.discv_timer.in_use) { |
| 739 | nfa_sys_stop_timer(&nfa_ee_cb.discv_timer); |
Love Khanna | 81e4f81 | 2017-06-02 17:50:19 +0530 | [diff] [blame] | 740 | if (NFA_GetNCIVersion() != NCI_VERSION_2_0) NFC_NfceeDiscover(false); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 741 | } |
| 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | /******************************************************************************* |
| 752 | ** |
| 753 | ** Function nfa_ee_api_register |
| 754 | ** |
| 755 | ** Description process register command from user |
| 756 | ** |
| 757 | ** Returns void |
| 758 | ** |
| 759 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 760 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 765 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 766 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 773 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 774 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 775 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 776 | /* 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 784 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 785 | } |
| 786 | /* This callback is verified (not NULL) in NFA_EeRegister() */ |
| 787 | (*p_cback)(NFA_EE_REGISTER_EVT, &evt_data); |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 788 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 789 | /* 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 792 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 803 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 807 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 808 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("nfa_ee_api_deregister"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 809 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 812 | } |
| 813 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 814 | /******************************************************************************* |
| 815 | ** |
| 816 | ** Function nfa_ee_api_mode_set |
| 817 | ** |
| 818 | ** Description process mode set command from user |
| 819 | ** |
| 820 | ** Returns void |
| 821 | ** |
| 822 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 823 | void nfa_ee_api_mode_set(tNFA_EE_MSG* p_data) { |
| 824 | tNFA_EE_ECB* p_cb = p_data->cfg_hdr.p_cb; |
Love Khanna | 81e4f81 | 2017-06-02 17:50:19 +0530 | [diff] [blame] | 825 | tNFA_EE_MODE_SET mode_set; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 826 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 827 | "handle:0x%02x mode:%d", p_cb->nfcee_id, p_data->mode_set.mode); |
Love Khanna | 81e4f81 | 2017-06-02 17:50:19 +0530 | [diff] [blame] | 828 | 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 Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 833 | 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 Khanna | 81e4f81 | 2017-06-02 17:50:19 +0530 | [diff] [blame] | 836 | return; |
| 837 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 838 | /* 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 848 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 849 | } |
| 850 | /* report the NFA_EE_MODE_SET_EVT status on the response from NFCC */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 851 | } |
| 852 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 853 | /******************************************************************************* |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 864 | void 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 Khanna | 514a14b | 2018-03-23 00:19:13 +0530 | [diff] [blame] | 870 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 873 | uint8_t old_size_mask = p_cb->size_mask; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 874 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 875 | 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 Khanna | 514a14b | 2018-03-23 00:19:13 +0530 | [diff] [blame] | 877 | (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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 882 | /* 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 Liao | ea8730a | 2015-06-17 09:59:41 -0700 | [diff] [blame] | 887 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 888 | 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 Khanna | 514a14b | 2018-03-23 00:19:13 +0530 | [diff] [blame] | 891 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 894 | nfa_ee_update_route_size(p_cb); |
| 895 | if (nfa_ee_total_lmrt_size() > NFC_GetLmrtSize()) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 896 | LOG(ERROR) << StringPrintf("nfa_ee_api_set_tech_cfg Exceed LMRT size"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 897 | 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 Khanna | 514a14b | 2018-03-23 00:19:13 +0530 | [diff] [blame] | 901 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 904 | p_cb->size_mask = old_size_mask; |
| 905 | } else { |
| 906 | p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_TECH; |
Love Khanna | 514a14b | 2018-03-23 00:19:13 +0530 | [diff] [blame] | 907 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 910 | /* 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 913 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 914 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 917 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 930 | void 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 Khanna | 514a14b | 2018-03-23 00:19:13 +0530 | [diff] [blame] | 936 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 939 | uint8_t old_size_mask = p_cb->size_mask; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 940 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 941 | 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 Khanna | 514a14b | 2018-03-23 00:19:13 +0530 | [diff] [blame] | 943 | (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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 948 | /* 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 Liao | ea8730a | 2015-06-17 09:59:41 -0700 | [diff] [blame] | 953 | |
Jizhou Liao | 4250f7b | 2018-05-11 11:45:38 -0700 | [diff] [blame^] | 954 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 960 | nfa_ee_update_route_size(p_cb); |
| 961 | if (nfa_ee_total_lmrt_size() > NFC_GetLmrtSize()) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 962 | LOG(ERROR) << StringPrintf("nfa_ee_api_set_proto_cfg Exceed LMRT size"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 963 | 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 Khanna | 514a14b | 2018-03-23 00:19:13 +0530 | [diff] [blame] | 967 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 970 | 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 Khanna | 514a14b | 2018-03-23 00:19:13 +0530 | [diff] [blame] | 974 | p_cb->proto_battery_off | p_cb->proto_screen_lock | |
| 975 | p_cb->proto_screen_off | p_cb->proto_screen_off_lock) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 976 | /* 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 979 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 980 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 983 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 996 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1005 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1006 | 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1011 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1012 | "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 Khanna | f3c018a | 2017-05-11 18:34:32 +0530 | [diff] [blame] | 1015 | p_cb->aid_info[entry] = p_add->aidInfo; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1016 | new_size = nfa_ee_total_lmrt_size(); |
| 1017 | if (new_size > NFC_GetLmrtSize()) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1018 | LOG(ERROR) << StringPrintf("Exceed LMRT size:%d (add ROUTE)", new_size); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1019 | 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1025 | LOG(ERROR) << StringPrintf( |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1026 | "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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1030 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1031 | } else { |
| 1032 | /* Find the total length so far */ |
| 1033 | len = nfa_ee_find_total_aid_len(p_cb, 0); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1034 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1035 | /* 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1037 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1038 | if ((len_needed + len) > NFA_EE_MAX_AID_CFG_LEN) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1039 | LOG(ERROR) << StringPrintf( |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1040 | "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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1048 | LOG(ERROR) << StringPrintf("Exceed LMRT size:%d", new_size); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1049 | 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 Khanna | f3c018a | 2017-05-11 18:34:32 +0530 | [diff] [blame] | 1053 | p_cb->aid_info[p_cb->aid_entries] = p_add->aidInfo; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1054 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1061 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1062 | p_cb->aid_len[p_cb->aid_entries++] = (uint8_t)(p - p_start); |
| 1063 | } |
| 1064 | } else { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1065 | LOG(ERROR) << StringPrintf("Exceed NFA_EE_MAX_AID_ENTRIES:%d", |
| 1066 | NFA_EE_MAX_AID_ENTRIES); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1067 | evt_data.status = NFA_STATUS_BUFFER_FULL; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1068 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1069 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1070 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1071 | 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1078 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 1079 | "status:%d ee_cfged:0x%02x ", evt_data.status, nfa_ee_cb.ee_cfged); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1080 | /* 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1082 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1095 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1101 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1102 | 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1107 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 1108 | "aid_rt_info[%d]: 0x%02x", entry, p_cb->aid_rt_info[entry]); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1109 | /* 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1112 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1113 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1115 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1116 | /* 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1121 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1122 | len = p_cb->aid_len[entry]; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1123 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 1124 | "nfa_ee_api_remove_aid len:%d, rest_len:%d", len, rest_len); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1125 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1133 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1134 | /* 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1142 | LOG(ERROR) << StringPrintf( |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1143 | "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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | /******************************************************************************* |
Love Khanna | 1d06277 | 2018-04-10 21:10:02 +0530 | [diff] [blame] | 1150 | ** |
| 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 | *******************************************************************************/ |
| 1160 | void 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 | *******************************************************************************/ |
| 1261 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1324 | ** |
Sherry Smith | ca0bff4 | 2014-01-22 15:15:54 -0800 | [diff] [blame] | 1325 | ** 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 Kandoi | 9ba6d24 | 2017-10-13 16:07:01 -0700 | [diff] [blame] | 1332 | void nfa_ee_api_lmrt_size(__attribute__((unused)) tNFA_EE_MSG* p_data) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1333 | tNFA_EE_CBACK_DATA evt_data = {0}; |
| 1334 | uint16_t total_size = NFC_GetLmrtSize(); |
Sherry Smith | ca0bff4 | 2014-01-22 15:15:54 -0800 | [diff] [blame] | 1335 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1336 | evt_data.size = total_size - nfa_ee_total_lmrt_size(); |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1337 | 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 Smith | ca0bff4 | 2014-01-22 15:15:54 -0800 | [diff] [blame] | 1340 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1341 | nfa_ee_report_event(NULL, NFA_EE_REMAINING_SIZE_EVT, &evt_data); |
Sherry Smith | ca0bff4 | 2014-01-22 15:15:54 -0800 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | /******************************************************************************* |
| 1345 | ** |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1346 | ** Function nfa_ee_api_update_now |
| 1347 | ** |
| 1348 | ** Description Initiates connection creation process to the given NFCEE |
| 1349 | ** |
| 1350 | ** Returns void |
| 1351 | ** |
| 1352 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1353 | void nfa_ee_api_update_now(tNFA_EE_MSG* p_data) { |
| 1354 | tNFA_EE_CBACK_DATA evt_data; |
Sherry Smith | 40e67c9 | 2014-01-16 10:10:29 -0800 | [diff] [blame] | 1355 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1356 | if (nfa_ee_cb.ee_wait_evt & NFA_EE_WAIT_UPDATE_ALL) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1357 | LOG(ERROR) << StringPrintf( |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1358 | "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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1368 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1379 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1383 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1384 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1397 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1398 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1399 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1400 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1407 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1418 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1425 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1426 | 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 Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 1435 | tNFA_EE_CBACK_DATA nfa_ee_cback_data; |
| 1436 | nfa_ee_cback_data.status = status; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1437 | nfa_ee_report_event(p_cb->p_ee_cback, NFA_EE_NO_MEM_ERR_EVT, |
Myles Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 1438 | &nfa_ee_cback_data); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1439 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1440 | } else { |
Myles Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 1441 | tNFA_EE_CBACK_DATA nfa_ee_cback_data; |
| 1442 | nfa_ee_cback_data.status = status; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1443 | nfa_ee_report_event(p_cb->p_ee_cback, NFA_EE_NO_CB_ERR_EVT, |
Myles Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 1444 | &nfa_ee_cback_data); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1445 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1446 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1457 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1460 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1461 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1467 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1478 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1481 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1482 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 1483 | "em_state:%d num_ee_expecting:%d " |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1484 | "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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1498 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1499 | |
| 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1510 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1521 | bool nfa_ee_restore_ntf_done(void) { |
| 1522 | tNFA_EE_ECB* p_cb; |
| 1523 | bool is_done = true; |
| 1524 | int xx; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1525 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1526 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1532 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1533 | } |
| 1534 | return is_done; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1535 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1546 | static 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1551 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1552 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1559 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1560 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1561 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1562 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1565 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1573 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1574 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1580 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1581 | } |
| 1582 | nfa_ee_cb.cur_ee -= (uint8_t)num_removed; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1583 | } |
| 1584 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1585 | /******************************************************************************* |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1594 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1600 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1601 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1604 | switch (nfa_ee_cb.em_state) { |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1605 | case NFA_EE_EM_STATE_INIT: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1606 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1613 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1614 | } |
| 1615 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1616 | |
| 1617 | case NFA_EE_EM_STATE_INIT_DONE: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1618 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1630 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1631 | nfa_ee_cb.cur_ee = num_nfcee; |
| 1632 | } |
| 1633 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1634 | |
| 1635 | case NFA_EE_EM_STATE_RESTORING: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1636 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1642 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1643 | } |
| 1644 | break; |
| 1645 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1646 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1647 | 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1650 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1653 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1654 | } |
| 1655 | nfa_ee_report_disc_done(notify_enable_done); |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1656 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1659 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1670 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1678 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1679 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 1680 | "em_state:%d ee_flags:0x%x cur_ee:%d " |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1681 | "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 Khanna | 81e4f81 | 2017-06-02 17:50:19 +0530 | [diff] [blame] | 1689 | if (NFA_GetNCIVersion() != NCI_VERSION_2_0) NFC_NfceeDiscover(false); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1690 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1691 | } |
| 1692 | switch (nfa_ee_cb.em_state) { |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1693 | case NFA_EE_EM_STATE_INIT: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1694 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1698 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1699 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1705 | |
| 1706 | case NFA_EE_EM_STATE_INIT_DONE: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1707 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1715 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1716 | } 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1720 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1723 | } |
| 1724 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1725 | |
| 1726 | case NFA_EE_EM_STATE_RESTORING: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1727 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1735 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1736 | } |
| 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1742 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1743 | } |
| 1744 | break; |
| 1745 | } |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1746 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1748 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1749 | 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 Khanna | 81e4f81 | 2017-06-02 17:50:19 +0530 | [diff] [blame] | 1756 | if (NFA_GetNCIVersion() == NCI_VERSION_2_0) |
| 1757 | p_cb->ee_power_supply_status = p_ee->nfcee_power_ctrl; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1758 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1767 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1768 | /* else wait for NFA-HCI module to restore the HCI network information |
| 1769 | * before enabling the NFCEE */ |
| 1770 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1771 | } |
| 1772 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1773 | 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 Khanna | 81e4f81 | 2017-06-02 17:50:19 +0530 | [diff] [blame] | 1785 | if (NFA_GetNCIVersion() == NCI_VERSION_2_0) |
| 1786 | p_info->ee_power_supply_status = p_cb->ee_power_supply_status; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1787 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1791 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1792 | if (p_cb->ecb_flags & NFA_EE_ECB_FLAGS_ORDER) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1793 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1794 | << StringPrintf("NFA_EE_ECB_FLAGS_ORDER"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1795 | p_cb->ecb_flags &= ~NFA_EE_ECB_FLAGS_ORDER; |
| 1796 | nfa_ee_report_discover_req_evt(); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1797 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1798 | } |
| 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 Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 1810 | nfa_ee_evt_hdlr(&p_data->hdr); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1811 | } |
| 1812 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1813 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1826 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1830 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1831 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1840 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1841 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1842 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1843 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1844 | "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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1851 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1852 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | /******************************************************************************* |
| 1858 | ** |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 1859 | ** 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1866 | static 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 Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 1870 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1871 | if (!p_evt_data) return; |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 1872 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1873 | p_evt_data->num_ee = 0; |
| 1874 | p_cb = nfa_ee_cb.ecb; |
| 1875 | p_info = p_evt_data->ee_disc_info; |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 1876 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1877 | 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 Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 1882 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1883 | 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 Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 1890 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1891 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1892 | "[%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 Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | /******************************************************************************* |
| 1901 | ** |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1902 | ** 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1909 | static void nfa_ee_report_discover_req_evt(void) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1910 | if (nfa_ee_cb.p_enable_cback) |
| 1911 | (*nfa_ee_cb.p_enable_cback)(NFA_EE_DISC_STS_REQ); |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 1912 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1913 | /* if this is restoring NFCC */ |
| 1914 | if (!nfa_dm_is_active()) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1915 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1916 | << StringPrintf("nfa_ee_report_discover_req_evt DM is not active"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1917 | return; |
| 1918 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1919 | |
Myles Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 1920 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1923 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1934 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1938 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1939 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 1940 | "%s handle:0x%02x mode:%d", __func__, p_rsp->nfcee_id, p_rsp->mode); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1941 | p_cb = nfa_ee_find_ecb(p_rsp->nfcee_id); |
| 1942 | if (p_cb == NULL) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1943 | LOG(ERROR) << StringPrintf("%s Can not find cb for handle:0x%02x", __func__, |
| 1944 | p_rsp->nfcee_id); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1945 | return; |
| 1946 | } |
| 1947 | |
| 1948 | /* update routing table and vs on mode change */ |
| 1949 | nfa_ee_start_timer(); |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1950 | LOG(ERROR) << StringPrintf("%s p_rsp->status:0x%02x", __func__, |
| 1951 | p_rsp->status); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1952 | 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1964 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1965 | << StringPrintf("deactivating/still configured. Force update"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1966 | } |
| 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1972 | } |
Love Khanna | 81e4f81 | 2017-06-02 17:50:19 +0530 | [diff] [blame] | 1973 | } else if (p_rsp->mode == NFA_EE_MD_ACTIVATE) { |
| 1974 | p_cb->ee_status = NFC_NFCEE_STATUS_REMOVED; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1975 | } |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1976 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1979 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1989 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1990 | } 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1994 | |
Myles Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 1995 | tNFA_EE_CBACK_DATA nfa_ee_cback_data; |
| 1996 | nfa_ee_cback_data.mode_set = mode_set; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1997 | nfa_ee_report_event(p_cb->p_ee_cback, NFA_EE_MODE_SET_EVT, |
Myles Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 1998 | &nfa_ee_cback_data); |
Paul Chaisson | afb70e8 | 2014-01-02 16:29:32 -0500 | [diff] [blame] | 1999 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2000 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2004 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2005 | } |
Love Khanna | 81e4f81 | 2017-06-02 17:50:19 +0530 | [diff] [blame] | 2006 | if (nfa_ee_cb.p_enable_cback) |
| 2007 | (*nfa_ee_cb.p_enable_cback)(NFA_EE_MODE_SET_COMPLETE); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | /******************************************************************************* |
| 2011 | ** |
Sherry Smith | 40e67c9 | 2014-01-16 10:10:29 -0800 | [diff] [blame] | 2012 | ** 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2019 | void nfa_ee_report_update_evt(void) { |
| 2020 | tNFA_EE_CBACK_DATA evt_data; |
Sherry Smith | 40e67c9 | 2014-01-16 10:10:29 -0800 | [diff] [blame] | 2021 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2022 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2025 | if (nfa_ee_cb.wait_rsp == 0) { |
| 2026 | nfa_ee_cb.ee_wait_evt &= ~NFA_EE_WAIT_UPDATE_RSP; |
Sherry Smith | 40e67c9 | 2014-01-16 10:10:29 -0800 | [diff] [blame] | 2027 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2028 | 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 Smith | 40e67c9 | 2014-01-16 10:10:29 -0800 | [diff] [blame] | 2033 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2034 | } |
Sherry Smith | 40e67c9 | 2014-01-16 10:10:29 -0800 | [diff] [blame] | 2035 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2046 | void nfa_ee_nci_wait_rsp(tNFA_EE_MSG* p_data) { |
| 2047 | tNFA_EE_NCI_WAIT_RSP* p_rsp = &p_data->wait_rsp; |
Sherry Smith | 40e67c9 | 2014-01-16 10:10:29 -0800 | [diff] [blame] | 2048 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2049 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2052 | 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 Smith | 40e67c9 | 2014-01-16 10:10:29 -0800 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | /******************************************************************************* |
| 2059 | ** |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2060 | ** Function nfa_ee_nci_conn |
| 2061 | ** |
| 2062 | ** Description process the connection callback events |
| 2063 | ** |
| 2064 | ** Returns void |
| 2065 | ** |
| 2066 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2067 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2075 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2076 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2082 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2083 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2093 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2094 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2103 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2104 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2133 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2134 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2135 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2139 | |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2149 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2152 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2153 | 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 Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 2157 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2160 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2171 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2177 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2178 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2180 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2181 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2183 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2184 | p_cb = nfa_ee_find_ecb(p_cbk->info[xx].nfcee_id); |
| 2185 | if (!p_cb) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2186 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 2187 | "Cannot find cb for NFCEE: 0x%x", p_cbk->info[xx].nfcee_id); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2188 | 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2193 | LOG(ERROR) << StringPrintf("Cannot allocate cb for NFCEE: 0x%x", |
| 2194 | p_cbk->info[xx].nfcee_id); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2195 | continue; |
| 2196 | } |
| 2197 | } else { |
| 2198 | report_ntf |= nfa_ee_ecb_to_mask(p_cb); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2199 | } |
| 2200 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2201 | 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2213 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2214 | "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 Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 2231 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2232 | /* Report NFA_EE_DISCOVER_REQ_EVT for all active NFCEE */ |
| 2233 | if (report_ntf) nfa_ee_report_discover_req_evt(); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2234 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2245 | bool 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2249 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2250 | if ((NFA_HANDLE_GROUP_MASK & nfcee_id) == NFA_HANDLE_GROUP_EE) |
| 2251 | nfcee_id &= NFA_HANDLE_MASK; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2252 | |
Love Khanna | 1d06277 | 2018-04-10 21:10:02 +0530 | [diff] [blame] | 2253 | if (nfcee_id == NFC_DH_ID) return true; |
| 2254 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2255 | /* 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2262 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2263 | } |
| 2264 | return is_active; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | /******************************************************************************* |
| 2268 | ** |
| 2269 | ** Function nfa_ee_get_tech_route |
| 2270 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 2271 | ** Description Given a power state, find the technology routing |
| 2272 | ** destination. The result is filled in the given p_handles |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2273 | ** in the order of A, B, F, Bprime |
| 2274 | ** |
| 2275 | ** Returns None |
| 2276 | ** |
| 2277 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2278 | void 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2284 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2285 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%d", power_state); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2286 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2287 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2305 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2306 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2307 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2308 | } |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2309 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | /******************************************************************************* |
| 2315 | ** |
Sherry Smith | a96095b | 2013-12-17 18:09:29 -0800 | [diff] [blame] | 2316 | ** Function nfa_ee_check_set_routing |
| 2317 | ** |
| 2318 | ** Description If the new size exceeds the capacity of next block, |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 2319 | ** send the routing command now and reset the related |
| 2320 | ** parameters. |
Sherry Smith | a96095b | 2013-12-17 18:09:29 -0800 | [diff] [blame] | 2321 | ** |
| 2322 | ** Returns void |
| 2323 | ** |
| 2324 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2325 | void 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 Smith | a96095b | 2013-12-17 18:09:29 -0800 | [diff] [blame] | 2330 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2331 | 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 Smith | a96095b | 2013-12-17 18:09:29 -0800 | [diff] [blame] | 2334 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2335 | /* 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 Smith | a96095b | 2013-12-17 18:09:29 -0800 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | /******************************************************************************* |
| 2348 | ** |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2349 | ** 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 | *******************************************************************************/ |
| 2356 | void 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2363 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2364 | "%s - max_len:%d, cur_offset:%d, more:%d, num_tlv:%d,rout_type:- %d", |
Love Khanna | f3c018a | 2017-05-11 18:34:32 +0530 | [diff] [blame] | 2365 | __func__, *p_max_len, *p_cur_offset, more, num_tlv, rout_type); |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2366 | 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 Khanna | 1d06277 | 2018-04-10 21:10:02 +0530 | [diff] [blame] | 2381 | 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 Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2385 | default: { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2386 | DLOG_IF(INFO, nfc_debug_enabled) |
| 2387 | << StringPrintf("%s - Route type - NA:- %d", __func__, rout_type); |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2388 | } |
| 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2401 | 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 Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2403 | |
| 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2412 | DLOG_IF(INFO, nfc_debug_enabled) |
| 2413 | << StringPrintf("%s : set routing num_tlv:%d tlv_size:%d", __func__, |
| 2414 | num_tlv, tlv_size); |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2415 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2431 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2432 | /******************************************************************************* |
| 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 Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 2439 | ** The algorithm for the NFCEE configuration handling is as |
| 2440 | ** follows: |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2441 | ** |
| 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 Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 2444 | ** that changes routing/VS is invoked. This ecb_flags is |
| 2445 | ** cleared at the end of nfa_ee_update_rout(). |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2446 | ** |
| 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 Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 2449 | ** nfa_ee_cb.ee_cfged is cleared and re-calculated at the end |
| 2450 | ** of nfa_ee_update_rout(). |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2451 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 2452 | ** 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2458 | ** |
| 2459 | ** Returns TRUE if any configuration is changed |
| 2460 | ** |
| 2461 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2462 | static 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2467 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2468 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2471 | /* 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2479 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 2480 | "%d: ecb_flags : 0x%02x, mask: 0x%02x", xx, p_cb->ecb_flags, mask); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2481 | if ((p_cb->ecb_flags) && (nfa_ee_cb.ee_cfged & mask)) { |
| 2482 | needed = true; |
| 2483 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2484 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2485 | p_cb = &nfa_ee_cb.ecb[xx]; |
| 2486 | mask = 1 << xx; |
| 2487 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2488 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2489 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2490 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2491 | return needed; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2492 | } |
| 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 Kandoi | 9ba6d24 | 2017-10-13 16:07:01 -0700 | [diff] [blame] | 2505 | void nfa_ee_rout_timeout(__attribute__((unused)) tNFA_EE_MSG* p_data) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2506 | uint8_t ee_cfged = nfa_ee_cb.ee_cfged; |
Sherry Smith | 40e67c9 | 2014-01-16 10:10:29 -0800 | [diff] [blame] | 2507 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2508 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2509 | if (nfa_ee_need_recfg()) { |
| 2510 | /* discovery is not started */ |
| 2511 | nfa_ee_update_rout(); |
| 2512 | } |
Sherry Smith | c2ae269 | 2014-02-05 11:59:23 -0800 | [diff] [blame] | 2513 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2514 | 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 Smith | 40e67c9 | 2014-01-16 10:10:29 -0800 | [diff] [blame] | 2520 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2521 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | /******************************************************************************* |
| 2525 | ** |
| 2526 | ** Function nfa_ee_discv_timeout |
| 2527 | ** |
| 2528 | ** Description |
| 2529 | ** |
| 2530 | ** |
| 2531 | ** |
| 2532 | ** Returns void |
| 2533 | ** |
| 2534 | *******************************************************************************/ |
Ruchi Kandoi | 9ba6d24 | 2017-10-13 16:07:01 -0700 | [diff] [blame] | 2535 | void nfa_ee_discv_timeout(__attribute__((unused)) tNFA_EE_MSG* p_data) { |
Love Khanna | 81e4f81 | 2017-06-02 17:50:19 +0530 | [diff] [blame] | 2536 | if (NFA_GetNCIVersion() != NCI_VERSION_2_0) NFC_NfceeDiscover(false); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2537 | if (nfa_ee_cb.p_enable_cback) |
| 2538 | (*nfa_ee_cb.p_enable_cback)(NFA_EE_DISC_STS_OFF); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2539 | } |
| 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 Kandoi | 9ba6d24 | 2017-10-13 16:07:01 -0700 | [diff] [blame] | 2551 | void nfa_ee_lmrt_to_nfcc(__attribute__((unused)) tNFA_EE_MSG* p_data) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2552 | int xx; |
| 2553 | tNFA_EE_ECB* p_cb; |
| 2554 | uint8_t* p = NULL; |
| 2555 | bool more = true; |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2556 | bool check = true; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2557 | uint8_t last_active = NFA_EE_INVALID; |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2558 | int max_len; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2559 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 2560 | int cur_offset; |
| 2561 | uint8_t max_tlv; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2562 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2563 | /* update routing table: DH and the activated NFCEEs */ |
| 2564 | p = (uint8_t*)GKI_getbuf(NFA_EE_ROUT_BUF_SIZE); |
| 2565 | if (p == NULL) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2566 | LOG(ERROR) << StringPrintf("no buffer to send routing info."); |
Myles Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 2567 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2570 | 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 Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2579 | DLOG_IF(INFO, nfc_debug_enabled) |
| 2580 | << StringPrintf("last_active: 0x%x", last_active); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2581 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2582 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2583 | } |
| 2584 | if (last_active == NFA_EE_INVALID) { |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2585 | check = false; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2586 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2587 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2588 | 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 Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2595 | for (int rt = NCI_ROUTE_ORDER_AID; rt <= NCI_ROUTE_ORDER_TECHNOLOGY; rt++) { |
| 2596 | /* add the routing entries for NFCEEs */ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2597 | p_cb = &nfa_ee_cb.ecb[0]; |
Love Khanna | 1d06277 | 2018-04-10 21:10:02 +0530 | [diff] [blame] | 2598 | |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2599 | for (xx = 0; (xx < nfa_ee_cb.cur_ee) && check; xx++, p_cb++) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2600 | if (p_cb->ee_status == NFC_NFCEE_STATUS_ACTIVE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2601 | DLOG_IF(INFO, nfc_debug_enabled) |
| 2602 | << StringPrintf("%s --add the routing for NFCEEs!!", __func__); |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2603 | nfa_ee_route_add_one_ecb_by_route_order(p_cb, rt, &max_len, more, p, |
| 2604 | &cur_offset); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2605 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2606 | } |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2607 | if (rt == NCI_ROUTE_ORDER_TECHNOLOGY) more = false; |
| 2608 | /* add the routing entries for DH */ |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2609 | DLOG_IF(INFO, nfc_debug_enabled) |
| 2610 | << StringPrintf("%s --add the routing for DH!!", __func__); |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2611 | 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2613 | } |
Love Khanna | b4ac88d | 2017-04-06 16:25:36 +0530 | [diff] [blame] | 2614 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2615 | GKI_freebuf(p); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2616 | } |
| 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 Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2628 | void nfa_ee_update_rout(void) { |
| 2629 | int xx; |
| 2630 | tNFA_EE_ECB* p_cb; |
| 2631 | uint8_t mask; |
Myles Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 2632 | tNFA_EE_MSG nfa_ee_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2633 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2634 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2636 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2637 | /* use action function to send routing and VS configuration to NFCC */ |
Myles Watson | 1361d52 | 2017-09-26 13:39:54 -0700 | [diff] [blame] | 2638 | nfa_ee_msg.hdr.event = NFA_EE_CFG_TO_NFCC_EVT; |
| 2639 | nfa_ee_evt_hdlr(&nfa_ee_msg.hdr); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2640 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2641 | /* 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 Khanna | 1d06277 | 2018-04-10 21:10:02 +0530 | [diff] [blame] | 2650 | p_cb->proto_battery_off | p_cb->aid_entries | |
| 2651 | p_cb->sys_code_cfg_entries) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2652 | /* this entry has routing configuration. mark it configured */ |
| 2653 | nfa_ee_cb.ee_cfged |= mask; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2654 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2655 | } |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2656 | 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 Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2659 | } |