nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2010-2014 Broadcom Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | /****************************************************************************** |
| 19 | * |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 20 | * The original Work has been changed by NXP. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 21 | * |
| 22 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 23 | * you may not use this file except in compliance with the License. |
| 24 | * You may obtain a copy of the License at |
| 25 | * |
| 26 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 27 | * |
| 28 | * Unless required by applicable law or agreed to in writing, software |
| 29 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 31 | * See the License for the specific language governing permissions and |
| 32 | * limitations under the License. |
| 33 | * |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 34 | * Copyright 2018 NXP |
| 35 | * |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 36 | ******************************************************************************/ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 37 | /****************************************************************************** |
| 38 | * |
| 39 | * NFA interface to NFCEE - API functions |
| 40 | * |
| 41 | ******************************************************************************/ |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 42 | #include <android-base/stringprintf.h> |
| 43 | #include <base/logging.h> |
| 44 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 45 | #include "nfa_dm_int.h" |
Suraj Uday Kotharkar | 6f7757b | 2018-05-10 15:58:29 +0530 | [diff] [blame] | 46 | #include "nfa_ee_api.h" |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 47 | #include "nfa_ee_int.h" |
Suraj Uday Kotharkar | 6f7757b | 2018-05-10 15:58:29 +0530 | [diff] [blame] | 48 | #include "nfc_int.h" |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 49 | |
| 50 | using android::base::StringPrintf; |
| 51 | |
| 52 | extern bool nfc_debug_enabled; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 53 | |
| 54 | /***************************************************************************** |
| 55 | ** APIs |
| 56 | *****************************************************************************/ |
| 57 | /******************************************************************************* |
| 58 | ** |
| 59 | ** Function NFA_EeDiscover |
| 60 | ** |
| 61 | ** Description This function retrieves the NFCEE information from NFCC. |
| 62 | ** The NFCEE information is reported in NFA_EE_DISCOVER_EVT. |
| 63 | ** |
| 64 | ** This function may be called when a system supports removable |
| 65 | ** NFCEEs, |
| 66 | ** |
| 67 | ** Returns NFA_STATUS_OK if information is retrieved successfully |
| 68 | ** NFA_STATUS_FAILED If wrong state (retry later) |
| 69 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 70 | ** |
| 71 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 72 | tNFA_STATUS NFA_EeDiscover(tNFA_EE_CBACK* p_cback) { |
| 73 | tNFA_EE_API_DISCOVER* p_msg; |
| 74 | tNFA_STATUS status = NFA_STATUS_FAILED; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 75 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 76 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 77 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 78 | if (nfa_ee_cb.em_state != NFA_EE_EM_STATE_INIT_DONE) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 79 | LOG(ERROR) << StringPrintf("NFA_EeDiscover bad em state: %d", |
| 80 | nfa_ee_cb.em_state); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 81 | status = NFA_STATUS_FAILED; |
| 82 | } else if ((nfa_ee_cb.p_ee_disc_cback != NULL) || (p_cback == NULL)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 83 | LOG(ERROR) << StringPrintf("in progress or NULL callback function"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 84 | status = NFA_STATUS_INVALID_PARAM; |
| 85 | } else { |
| 86 | p_msg = (tNFA_EE_API_DISCOVER*)GKI_getbuf(sizeof(tNFA_EE_API_DISCOVER)); |
| 87 | if (p_msg != NULL) { |
| 88 | p_msg->hdr.event = NFA_EE_API_DISCOVER_EVT; |
| 89 | p_msg->p_cback = p_cback; |
| 90 | |
| 91 | nfa_sys_sendmsg(p_msg); |
| 92 | |
| 93 | status = NFA_STATUS_OK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 94 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 95 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 96 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 97 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /******************************************************************************* |
| 101 | ** |
| 102 | ** Function NFA_EeGetInfo |
| 103 | ** |
| 104 | ** Description This function retrieves the NFCEE information from NFA. |
| 105 | ** The actual number of NFCEE is returned in p_num_nfcee |
| 106 | ** and NFCEE information is returned in p_info |
| 107 | ** |
| 108 | ** Returns NFA_STATUS_OK if information is retrieved successfully |
| 109 | ** NFA_STATUS_FAILED If wrong state (retry later) |
| 110 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 111 | ** |
| 112 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 113 | tNFA_STATUS NFA_EeGetInfo(uint8_t* p_num_nfcee, tNFA_EE_INFO* p_info) { |
| 114 | int xx, ret = nfa_ee_cb.cur_ee; |
| 115 | tNFA_EE_ECB* p_cb = nfa_ee_cb.ecb; |
| 116 | uint8_t max_ret; |
| 117 | uint8_t num_ret = 0; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 118 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 119 | DLOG_IF(INFO, nfc_debug_enabled) |
| 120 | << StringPrintf("NFA_EeGetInfo em_state:%d cur_ee:%d", nfa_ee_cb.em_state, |
| 121 | nfa_ee_cb.cur_ee); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 122 | /* validate parameters */ |
| 123 | if (p_info == NULL || p_num_nfcee == NULL) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 124 | LOG(ERROR) << StringPrintf("NFA_EeGetInfo bad parameter"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 125 | return (NFA_STATUS_INVALID_PARAM); |
| 126 | } |
| 127 | max_ret = *p_num_nfcee; |
| 128 | *p_num_nfcee = 0; |
| 129 | if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_INIT) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 130 | LOG(ERROR) << StringPrintf("NFA_EeGetInfo bad em state: %d", |
| 131 | nfa_ee_cb.em_state); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 132 | return (NFA_STATUS_FAILED); |
| 133 | } |
| 134 | |
| 135 | /* compose output */ |
| 136 | for (xx = 0; (xx < ret) && (num_ret < max_ret); xx++, p_cb++) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 137 | DLOG_IF(INFO, nfc_debug_enabled) |
| 138 | << StringPrintf("xx:%d max_ret:%d, num_ret:%d ee_status:0x%x", xx, |
| 139 | max_ret, num_ret, p_cb->ee_status); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 140 | if ((p_cb->ee_status & NFA_EE_STATUS_INT_MASK) || |
| 141 | (p_cb->ee_status == NFA_EE_STATUS_REMOVED)) { |
| 142 | continue; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 143 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 144 | p_info->ee_handle = NFA_HANDLE_GROUP_EE | (tNFA_HANDLE)p_cb->nfcee_id; |
| 145 | p_info->ee_status = p_cb->ee_status; |
| 146 | p_info->num_interface = p_cb->num_interface; |
| 147 | p_info->num_tlvs = p_cb->num_tlvs; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 148 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 149 | #if (NXP_EXTNS == TRUE) |
| 150 | p_info->la_protocol = p_cb->la_protocol; |
| 151 | p_info->lb_protocol = p_cb->lb_protocol; |
| 152 | p_info->lf_protocol = p_cb->lf_protocol; |
| 153 | p_info->lbp_protocol = p_cb->lbp_protocol; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 154 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 155 | memcpy(p_info->ee_interface, p_cb->ee_interface, p_cb->num_interface); |
| 156 | memcpy(p_info->ee_tlv, p_cb->ee_tlv, p_cb->num_tlvs * sizeof(tNFA_EE_TLV)); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 157 | p_info->ee_power_supply_status = p_cb->ee_power_supply_status; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 158 | p_info++; |
| 159 | num_ret++; |
| 160 | } |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 161 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("num_ret:%d", num_ret); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 162 | *p_num_nfcee = num_ret; |
| 163 | return (NFA_STATUS_OK); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 164 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 165 | #if (NXP_EXTNS == TRUE) |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 166 | /******************************************************************************* |
| 167 | ** |
| 168 | ** Function NFA_AllEeGetInfo |
| 169 | ** |
| 170 | ** Description This function retrieves the NFCEE information from NFA. |
| 171 | ** The actual number of NFCEE independent of their status |
| 172 | ** is returned in p_num_nfcee and NFCEE information is returned |
| 173 | ** in p_info |
| 174 | ** |
| 175 | ** Returns NFA_STATUS_OK if information is retrieved successfully |
| 176 | ** NFA_STATUS_FAILED If wrong state (retry later) |
| 177 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 178 | ** |
| 179 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 180 | tNFA_STATUS NFA_AllEeGetInfo(uint8_t* p_num_nfcee, tNFA_EE_INFO* p_info) { |
| 181 | int xx, ret = nfa_ee_cb.cur_ee; |
| 182 | tNFA_EE_ECB* p_cb = nfa_ee_cb.ecb; |
| 183 | uint8_t max_ret; |
| 184 | uint8_t num_ret = 0; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 185 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 186 | DLOG_IF(INFO, nfc_debug_enabled) |
| 187 | << StringPrintf("NFA_AllEeGetInfo em_state:%d cur_ee:%d", nfa_ee_cb.em_state, |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 188 | nfa_ee_cb.cur_ee); |
| 189 | /* validate parameters */ |
| 190 | if (p_info == NULL || p_num_nfcee == NULL) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 191 | LOG(ERROR) << StringPrintf("NFA_AllEeGetInfo bad parameter"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 192 | return (NFA_STATUS_INVALID_PARAM); |
| 193 | } |
| 194 | max_ret = *p_num_nfcee; |
| 195 | *p_num_nfcee = 0; |
| 196 | if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_INIT) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 197 | LOG(ERROR) << StringPrintf("NFA_AllEeGetInfo bad em state: %d", nfa_ee_cb.em_state); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 198 | return (NFA_STATUS_FAILED); |
| 199 | } |
| 200 | |
| 201 | /* compose output */ |
| 202 | for (xx = 0; (xx < ret) && (num_ret < max_ret); xx++, p_cb++) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 203 | DLOG_IF(INFO, nfc_debug_enabled) |
| 204 | << StringPrintf("xx:%d max_ret:%d, num_ret:%d ee_status:0x%x num_interface :%d p_cb->nfcee_id : %d", xx, max_ret, |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 205 | num_ret, p_cb->ee_status, p_cb->num_interface, p_cb->nfcee_id); |
| 206 | if (p_cb->ee_status & NFA_EE_STATUS_INT_MASK) { |
| 207 | continue; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 208 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 209 | p_info->ee_handle = NFA_HANDLE_GROUP_EE | (tNFA_HANDLE)p_cb->nfcee_id; |
| 210 | p_info->ee_status = p_cb->ee_status; |
| 211 | p_info->num_interface = p_cb->num_interface; |
| 212 | p_info->num_tlvs = p_cb->num_tlvs; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 213 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 214 | p_info->la_protocol = p_cb->la_protocol; |
| 215 | p_info->lb_protocol = p_cb->lb_protocol; |
| 216 | p_info->lf_protocol = p_cb->lf_protocol; |
| 217 | p_info->lbp_protocol = p_cb->lbp_protocol; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 218 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 219 | memcpy(p_info->ee_interface, p_cb->ee_interface, p_cb->num_interface); |
nxpandroid | 6154b73 | 2016-01-14 20:39:23 +0530 | [diff] [blame] | 220 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 221 | memcpy(p_info->ee_tlv, p_cb->ee_tlv, p_cb->num_tlvs * sizeof(tNFA_EE_TLV)); |
| 222 | p_info++; |
| 223 | num_ret++; |
| 224 | } |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 225 | DLOG_IF(INFO, nfc_debug_enabled) |
| 226 | << StringPrintf("num_ret:%d", num_ret); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 227 | *p_num_nfcee = num_ret; |
| 228 | return (NFA_STATUS_OK); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 229 | } |
| 230 | #endif |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 231 | /******************************************************************************* |
| 232 | ** |
| 233 | ** Function NFA_EeRegister |
| 234 | ** |
| 235 | ** Description This function registers a callback function to receive the |
| 236 | ** events from NFA-EE module. |
| 237 | ** |
| 238 | ** Returns NFA_STATUS_OK if successfully initiated |
| 239 | ** NFA_STATUS_FAILED otherwise |
| 240 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 241 | ** |
| 242 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 243 | tNFA_STATUS NFA_EeRegister(tNFA_EE_CBACK* p_cback) { |
| 244 | tNFA_EE_API_REGISTER* p_msg; |
| 245 | tNFA_STATUS status = NFA_STATUS_FAILED; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 246 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 247 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 248 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 249 | if (p_cback == NULL) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 250 | LOG(ERROR) << StringPrintf("with NULL callback function"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 251 | status = NFA_STATUS_INVALID_PARAM; |
| 252 | } else { |
| 253 | p_msg = (tNFA_EE_API_REGISTER*)GKI_getbuf(sizeof(tNFA_EE_API_REGISTER)); |
| 254 | if (p_msg != NULL) { |
| 255 | p_msg->hdr.event = NFA_EE_API_REGISTER_EVT; |
| 256 | p_msg->p_cback = p_cback; |
| 257 | |
| 258 | nfa_sys_sendmsg(p_msg); |
| 259 | |
| 260 | status = NFA_STATUS_OK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 261 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 262 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 263 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 264 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /******************************************************************************* |
| 268 | ** |
| 269 | ** Function NFA_EeDeregister |
| 270 | ** |
| 271 | ** Description This function de-registers the callback function |
| 272 | ** |
| 273 | ** Returns NFA_STATUS_OK if successfully initiated |
| 274 | ** NFA_STATUS_FAILED otherwise |
| 275 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 276 | ** |
| 277 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 278 | tNFA_STATUS NFA_EeDeregister(tNFA_EE_CBACK* p_cback) { |
| 279 | tNFA_EE_API_DEREGISTER* p_msg; |
| 280 | tNFA_STATUS status = NFA_STATUS_INVALID_PARAM; |
| 281 | int index = NFA_EE_MAX_CBACKS; |
| 282 | int xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 283 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 284 | for (xx = 0; xx < NFA_EE_MAX_CBACKS; xx++) { |
| 285 | if (nfa_ee_cb.p_ee_cback[xx] == p_cback) { |
| 286 | index = xx; |
| 287 | status = NFA_STATUS_FAILED; |
| 288 | break; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 289 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 290 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 291 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 292 | DLOG_IF(INFO, nfc_debug_enabled) |
| 293 | << StringPrintf("%d, status:%d", index, status); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 294 | if ((status != NFA_STATUS_INVALID_PARAM) && |
| 295 | (p_msg = (tNFA_EE_API_DEREGISTER*)GKI_getbuf( |
| 296 | sizeof(tNFA_EE_API_DEREGISTER))) != NULL) { |
| 297 | p_msg->hdr.event = NFA_EE_API_DEREGISTER_EVT; |
| 298 | p_msg->index = index; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 299 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 300 | nfa_sys_sendmsg(p_msg); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 301 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 302 | status = NFA_STATUS_OK; |
| 303 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 304 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 305 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 306 | } |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 307 | #if (NXP_EXTNS == TRUE) |
nxpandroid | fb16096 | 2017-09-13 16:09:09 +0530 | [diff] [blame] | 308 | /******************************************************************************* |
| 309 | ** |
| 310 | ** Function NFA_SendPowerLinkCommand |
| 311 | ** |
| 312 | ** Description This function is called to send an NCI Vendor Specific |
| 313 | ** command to NFCC. |
| 314 | ** |
| 315 | ** nfcee_id - The NFCEE id. |
| 316 | ** cfg_value - The config value |
| 317 | ** |
| 318 | ** Returns NFA_STATUS_OK if successfully initiated |
| 319 | ** NFA_STATUS_FAILED otherwise |
| 320 | ** |
| 321 | *******************************************************************************/ |
| 322 | tNFA_STATUS NFA_SendPowerLinkCommand(uint8_t nfcee_id, uint8_t cfg_value) { |
| 323 | tNFA_EE_API_POWER_LINK_EVT* p_msg; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 324 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 325 | DLOG_IF(INFO, nfc_debug_enabled) |
| 326 | << StringPrintf("NFA_SendPowerLinkCommand() nfcee_id=0x%x", nfcee_id); |
nxpandroid | fb16096 | 2017-09-13 16:09:09 +0530 | [diff] [blame] | 327 | |
| 328 | if ((p_msg = (tNFA_EE_API_POWER_LINK_EVT*)GKI_getbuf(sizeof(tNFA_EE_API_POWER_LINK_EVT))) != NULL) { |
| 329 | p_msg->hdr.event = NFA_EE_NCI_PWR_LNK_CTRL_SET_EVT; |
| 330 | p_msg->nfcee_id= nfcee_id; |
| 331 | p_msg->cfg_value = cfg_value; |
| 332 | |
| 333 | nfa_sys_sendmsg(p_msg); |
| 334 | |
| 335 | return (NFA_STATUS_OK); |
| 336 | } |
| 337 | |
| 338 | return (NFA_STATUS_FAILED); |
| 339 | } |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 340 | #endif |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 341 | /******************************************************************************* |
| 342 | ** |
| 343 | ** Function NFA_EeModeSet |
| 344 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 345 | ** Description This function is called to activate |
| 346 | ** (mode = NFA_EE_MD_ACTIVATE) or deactivate |
| 347 | ** (mode = NFA_EE_MD_DEACTIVATE) the NFCEE identified by the |
| 348 | ** given ee_handle. The result of this operation is reported |
| 349 | ** with the NFA_EE_MODE_SET_EVT. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 350 | ** |
| 351 | ** Returns NFA_STATUS_OK if successfully initiated |
| 352 | ** NFA_STATUS_FAILED otherwise |
| 353 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 354 | ** |
| 355 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 356 | tNFA_STATUS NFA_EeModeSet(tNFA_HANDLE ee_handle, tNFA_EE_MD mode) { |
| 357 | tNFA_EE_API_MODE_SET* p_msg; |
| 358 | tNFA_STATUS status = NFA_STATUS_FAILED; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 359 | tNFA_EE_ECB *p_cb, *p_found = NULL; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 360 | uint32_t xx; |
| 361 | uint8_t nfcee_id = (ee_handle & 0xFF); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 362 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 363 | p_cb = nfa_ee_cb.ecb; |
| 364 | for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++) { |
| 365 | if (nfcee_id == p_cb->nfcee_id) { |
| 366 | p_found = p_cb; |
| 367 | break; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 368 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 369 | } |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 370 | DLOG_IF(INFO, nfc_debug_enabled) |
| 371 | << StringPrintf("handle:<0x%x>, mode:0x%02X", ee_handle, mode); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 372 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 373 | if (p_found == NULL) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 374 | LOG(ERROR) << StringPrintf("invalid NFCEE:0x%04x", ee_handle); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 375 | status = NFA_STATUS_INVALID_PARAM; |
| 376 | } else { |
| 377 | p_msg = (tNFA_EE_API_MODE_SET*)GKI_getbuf(sizeof(tNFA_EE_API_MODE_SET)); |
| 378 | if (p_msg != NULL) { |
| 379 | p_msg->hdr.event = NFA_EE_API_MODE_SET_EVT; |
| 380 | p_msg->nfcee_id = nfcee_id; |
| 381 | p_msg->mode = mode; |
| 382 | p_msg->p_cb = p_found; |
| 383 | |
| 384 | nfa_sys_sendmsg(p_msg); |
| 385 | |
| 386 | status = NFA_STATUS_OK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 387 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 388 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 389 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 390 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 391 | } |
| 392 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 393 | /******************************************************************************* |
| 394 | ** |
| 395 | ** Function NFA_EeSetDefaultTechRouting |
| 396 | ** |
| 397 | ** Description This function is called to add, change or remove the |
| 398 | ** default routing based on RF technology in the listen mode |
| 399 | ** routing table for the given ee_handle. The status of this |
| 400 | ** operation is reported as the NFA_EE_SET_TECH_CFG_EVT. |
| 401 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 402 | ** Note: If RF discovery is started, |
| 403 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 404 | ** happen before calling this function |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 405 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 406 | ** Note: NFA_EeUpdateNow() should be called after last NFA-EE |
| 407 | ** function to change the listen mode routing is called. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 408 | ** |
| 409 | ** Returns NFA_STATUS_OK if successfully initiated |
| 410 | ** NFA_STATUS_FAILED otherwise |
| 411 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 412 | ** |
| 413 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 414 | tNFA_STATUS NFA_EeSetDefaultTechRouting( |
| 415 | tNFA_HANDLE ee_handle, tNFA_TECHNOLOGY_MASK technologies_switch_on, |
| 416 | tNFA_TECHNOLOGY_MASK technologies_switch_off, |
Suraj Uday Kotharkar | 1e7b99a | 2018-05-10 16:14:37 +0530 | [diff] [blame] | 417 | tNFA_TECHNOLOGY_MASK technologies_battery_off, |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 418 | tNFA_TECHNOLOGY_MASK technologies_screen_lock, |
| 419 | tNFA_TECHNOLOGY_MASK technologies_screen_off, |
Suraj Uday Kotharkar | 1e7b99a | 2018-05-10 16:14:37 +0530 | [diff] [blame] | 420 | tNFA_TECHNOLOGY_MASK technologies_screen_off_lock) { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 421 | tNFA_EE_API_SET_TECH_CFG* p_msg; |
| 422 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 423 | uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF); |
| 424 | tNFA_EE_ECB* p_cb; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 425 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 426 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 427 | "" |
Suraj Uday Kotharkar | 1e7b99a | 2018-05-10 16:14:37 +0530 | [diff] [blame] | 428 | "handle:<0x%x>technology_mask:<0x%x>/<0x%x>/<0x%x><0x%x><0x%x><0x%x>", |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 429 | ee_handle, technologies_switch_on, technologies_switch_off, |
Suraj Uday Kotharkar | 1e7b99a | 2018-05-10 16:14:37 +0530 | [diff] [blame] | 430 | technologies_battery_off, technologies_screen_lock, |
| 431 | technologies_screen_off, technologies_screen_off_lock); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 432 | p_cb = nfa_ee_find_ecb(nfcee_id); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 433 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 434 | if (p_cb == NULL) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 435 | LOG(ERROR) << StringPrintf("Bad ee_handle"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 436 | status = NFA_STATUS_INVALID_PARAM; |
| 437 | } else { |
| 438 | p_msg = |
| 439 | (tNFA_EE_API_SET_TECH_CFG*)GKI_getbuf(sizeof(tNFA_EE_API_SET_TECH_CFG)); |
| 440 | if (p_msg != NULL) { |
| 441 | p_msg->hdr.event = NFA_EE_API_SET_TECH_CFG_EVT; |
| 442 | p_msg->nfcee_id = nfcee_id; |
| 443 | p_msg->p_cb = p_cb; |
| 444 | p_msg->technologies_switch_on = technologies_switch_on; |
| 445 | p_msg->technologies_switch_off = technologies_switch_off; |
| 446 | p_msg->technologies_battery_off = technologies_battery_off; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 447 | p_msg->technologies_screen_lock = technologies_screen_lock; |
| 448 | p_msg->technologies_screen_off = technologies_screen_off; |
| 449 | p_msg->technologies_screen_off_lock = technologies_screen_off_lock; |
Suraj Uday Kotharkar | 1e7b99a | 2018-05-10 16:14:37 +0530 | [diff] [blame] | 450 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 451 | nfa_sys_sendmsg(p_msg); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 452 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 453 | status = NFA_STATUS_OK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 454 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 455 | } |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 456 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 457 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /******************************************************************************* |
| 461 | ** |
| 462 | ** Function NFA_EeSetDefaultProtoRouting |
| 463 | ** |
| 464 | ** Description This function is called to add, change or remove the |
| 465 | ** default routing based on Protocol in the listen mode routing |
| 466 | ** table for the given ee_handle. The status of this |
| 467 | ** operation is reported as the NFA_EE_SET_PROTO_CFG_EVT. |
| 468 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 469 | ** Note: If RF discovery is started, |
| 470 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 471 | ** happen before calling this function |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 472 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 473 | ** Note: NFA_EeUpdateNow() should be called after last NFA-EE |
| 474 | ** function to change the listen mode routing is called. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 475 | ** |
| 476 | ** Returns NFA_STATUS_OK if successfully initiated |
| 477 | ** NFA_STATUS_FAILED otherwise |
| 478 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 479 | ** |
| 480 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 481 | tNFA_STATUS NFA_EeSetDefaultProtoRouting( |
| 482 | tNFA_HANDLE ee_handle, tNFA_PROTOCOL_MASK protocols_switch_on, |
| 483 | tNFA_PROTOCOL_MASK protocols_switch_off, |
Suraj Uday Kotharkar | 1e7b99a | 2018-05-10 16:14:37 +0530 | [diff] [blame] | 484 | tNFA_PROTOCOL_MASK protocols_battery_off, |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 485 | tNFA_PROTOCOL_MASK protocols_screen_lock, |
| 486 | tNFA_PROTOCOL_MASK protocols_screen_off, |
Suraj Uday Kotharkar | 1e7b99a | 2018-05-10 16:14:37 +0530 | [diff] [blame] | 487 | tNFA_PROTOCOL_MASK protocols_screen_off_lock) { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 488 | tNFA_EE_API_SET_PROTO_CFG* p_msg; |
| 489 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 490 | uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF); |
| 491 | tNFA_EE_ECB* p_cb; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 492 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 493 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
Suraj Uday Kotharkar | 1e7b99a | 2018-05-10 16:14:37 +0530 | [diff] [blame] | 494 | "handle:<0x%x>protocol_mask:<0x%x>/<0x%x>/<0x%x><0x%x><0x%x><0x%x>", |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 495 | ee_handle, protocols_switch_on, protocols_switch_off, |
Suraj Uday Kotharkar | 1e7b99a | 2018-05-10 16:14:37 +0530 | [diff] [blame] | 496 | protocols_battery_off, protocols_screen_lock, protocols_screen_off, |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 497 | protocols_screen_off_lock); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 498 | p_cb = nfa_ee_find_ecb(nfcee_id); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 499 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 500 | if (p_cb == NULL) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 501 | LOG(ERROR) << StringPrintf("Bad ee_handle"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 502 | status = NFA_STATUS_INVALID_PARAM; |
| 503 | } else { |
| 504 | p_msg = (tNFA_EE_API_SET_PROTO_CFG*)GKI_getbuf( |
| 505 | sizeof(tNFA_EE_API_SET_PROTO_CFG)); |
| 506 | if (p_msg != NULL) { |
| 507 | p_msg->hdr.event = NFA_EE_API_SET_PROTO_CFG_EVT; |
| 508 | p_msg->nfcee_id = nfcee_id; |
| 509 | p_msg->p_cb = p_cb; |
| 510 | p_msg->protocols_switch_on = protocols_switch_on; |
| 511 | p_msg->protocols_switch_off = protocols_switch_off; |
| 512 | p_msg->protocols_battery_off = protocols_battery_off; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 513 | p_msg->protocols_screen_lock = protocols_screen_lock; |
| 514 | p_msg->protocols_screen_off = protocols_screen_off; |
| 515 | p_msg->protocols_screen_off_lock = protocols_screen_off_lock; |
Suraj Uday Kotharkar | 1e7b99a | 2018-05-10 16:14:37 +0530 | [diff] [blame] | 516 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 517 | nfa_sys_sendmsg(p_msg); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 518 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 519 | status = NFA_STATUS_OK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 520 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 521 | } |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 522 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 523 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | /******************************************************************************* |
| 527 | ** |
| 528 | ** Function NFA_EeAddAidRouting |
| 529 | ** |
| 530 | ** Description This function is called to add an AID entry in the |
| 531 | ** listen mode routing table in NFCC. The status of this |
| 532 | ** operation is reported as the NFA_EE_ADD_AID_EVT. |
| 533 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 534 | ** Note: If RF discovery is started, |
| 535 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 536 | ** happen before calling this function |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 537 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 538 | ** Note: NFA_EeUpdateNow() should be called after last NFA-EE |
| 539 | ** function to change the listen mode routing is called. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 540 | ** |
| 541 | ** Returns NFA_STATUS_OK if successfully initiated |
| 542 | ** NFA_STATUS_FAILED otherwise |
| 543 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 544 | ** |
| 545 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 546 | tNFA_STATUS NFA_EeAddAidRouting(tNFA_HANDLE ee_handle, uint8_t aid_len, |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 547 | uint8_t* p_aid, tNFA_EE_PWR_STATE power_state, |
| 548 | uint8_t aidInfo) { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 549 | tNFA_EE_API_ADD_AID* p_msg; |
| 550 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 551 | uint16_t size = sizeof(tNFA_EE_API_ADD_AID) + aid_len; |
| 552 | uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF); |
| 553 | tNFA_EE_ECB* p_cb; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 554 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 555 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("handle:<0x%x>", ee_handle); |
| 556 | p_cb = nfa_ee_find_ecb(nfcee_id); |
| 557 | #if (NXP_EXTNS == TRUE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 558 | /* validate parameters - make sure the AID is in valid length range */ |
nxpandroid | 601c474 | 2017-09-13 16:10:30 +0530 | [diff] [blame] | 559 | if ((p_cb == NULL) || ((NFA_GetNCIVersion() == NCI_VERSION_2_0) && (aid_len != 0) && (p_aid == NULL)) || |
| 560 | ((NFA_GetNCIVersion() != NCI_VERSION_2_0) && |
| 561 | ((aid_len == 0) || (p_aid == NULL) || (aid_len < NFA_MIN_AID_LEN))) || |
| 562 | (aid_len > NFA_MAX_AID_LEN)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 563 | #else |
| 564 | if ((p_cb == NULL) || (aid_len == 0) || (p_aid == NULL) || |
| 565 | (aid_len < NFA_MIN_AID_LEN) || (aid_len > NFA_MAX_AID_LEN)) { |
| 566 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 567 | status = NFA_STATUS_INVALID_PARAM; |
| 568 | } else { |
| 569 | p_msg = (tNFA_EE_API_ADD_AID*)GKI_getbuf(size); |
| 570 | if (p_msg != NULL) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 571 | #if (NXP_EXTNS != TRUE) |
| 572 | DLOG_IF(INFO, nfc_debug_enabled) |
| 573 | << StringPrintf("aid:<%02x%02x>", p_aid[0], p_aid[1]); |
| 574 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 575 | p_msg->hdr.event = NFA_EE_API_ADD_AID_EVT; |
| 576 | p_msg->nfcee_id = nfcee_id; |
| 577 | p_msg->p_cb = p_cb; |
| 578 | p_msg->aid_len = aid_len; |
| 579 | p_msg->power_state = power_state; |
| 580 | p_msg->p_aid = (uint8_t*)(p_msg + 1); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 581 | p_msg->aidInfo = aidInfo; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 582 | #if (NXP_EXTNS == TRUE) |
nxpandroid | 601c474 | 2017-09-13 16:10:30 +0530 | [diff] [blame] | 583 | if(p_aid != NULL) { |
nxpandroid | 6154b73 | 2016-01-14 20:39:23 +0530 | [diff] [blame] | 584 | #endif |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 585 | memcpy(p_msg->p_aid, p_aid, aid_len); |
| 586 | #if (NXP_EXTNS == TRUE) |
| 587 | DLOG_IF(INFO, nfc_debug_enabled) |
| 588 | << StringPrintf("aid:<%02x%02x>", p_aid[0], p_aid[1]); |
| 589 | } |
| 590 | #endif |
| 591 | nfa_sys_sendmsg(p_msg); |
| 592 | |
| 593 | status = NFA_STATUS_OK; |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | return status; |
| 598 | } |
Suraj Uday Kotharkar | 11ae20f | 2018-07-20 23:29:36 +0530 | [diff] [blame] | 599 | #if(NXP_EXTNS == TRUE) |
| 600 | /******************************************************************************* |
| 601 | ** |
| 602 | ** Function NFA_EeAddApduPatternRouting |
| 603 | ** |
| 604 | ** Description This function is called to add an APDU pattern entry in the |
| 605 | ** listen mode routing table in NFCC. The status of this |
| 606 | ** operation is reported as the NFA_EE_ADD_APDU_EVT. |
| 607 | ** |
| 608 | ** Note: If RF discovery is started, |
| 609 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 610 | ** happen before calling this function |
| 611 | ** |
| 612 | ** Note: NFA_EeUpdateNow() should be called after last NFA-EE |
| 613 | ** function to change the listen mode routing is called. |
| 614 | ** |
| 615 | ** Returns NFA_STATUS_OK if successfully initiated |
| 616 | ** NFA_STATUS_FAILED otherwise |
| 617 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 618 | ** |
| 619 | *******************************************************************************/ |
| 620 | tNFA_STATUS NFA_EeAddApduPatternRouting(uint8_t apdu_data_len,uint8_t* apdu_data, uint8_t apdu_mask_len, |
| 621 | uint8_t* apdu_mask, tNFA_HANDLE ee_handle, uint8_t power_state) { |
| 622 | tNFA_EE_API_ADD_APDU* p_msg; |
| 623 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 624 | tNFA_EE_ECB* p_cb; |
| 625 | uint16_t size = sizeof(tNFA_EE_API_ADD_AID) + apdu_data_len + apdu_mask_len; |
| 626 | uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 627 | |
Suraj Uday Kotharkar | 11ae20f | 2018-07-20 23:29:36 +0530 | [diff] [blame] | 628 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf |
| 629 | ("NFA_EeAddApduRouting(): handle:<0x%x>", ee_handle); |
| 630 | p_cb = nfa_ee_find_ecb(nfcee_id); |
| 631 | if(p_cb == NULL || apdu_data_len == 0 || apdu_mask_len == 0 || apdu_data == NULL |
| 632 | || apdu_mask == NULL || apdu_data_len > NFC_MAX_APDU_DATA_LEN |
| 633 | || apdu_mask_len > NFC_MAX_APDU_MASK_LEN || apdu_data_len != apdu_mask_len) { |
| 634 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf |
| 635 | ("Bad ee_handle or AID (len=%d)", apdu_data_len+apdu_mask_len); |
| 636 | status = NFA_STATUS_INVALID_PARAM; |
| 637 | } else { |
| 638 | p_msg = (tNFA_EE_API_ADD_APDU*)GKI_getbuf(size); |
| 639 | p_msg->hdr.event = NFA_EE_API_ADD_APDU_EVT; |
| 640 | p_msg->apdu_len = apdu_data_len; |
| 641 | p_msg->mask_len = apdu_mask_len; |
| 642 | p_msg->power_state = power_state; |
| 643 | p_msg->nfcee_id = nfcee_id; |
| 644 | p_msg->p_cb = p_cb; |
| 645 | p_msg->p_apdu = (uint8_t*)(p_msg + 1); |
| 646 | memcpy(p_msg->p_apdu, apdu_data, apdu_data_len); |
| 647 | p_msg->p_mask = (uint8_t*)(p_msg->p_apdu + apdu_data_len); |
| 648 | memcpy(p_msg->p_mask, apdu_mask, apdu_mask_len); |
| 649 | nfa_sys_sendmsg(p_msg); |
| 650 | status = NFA_STATUS_OK; |
| 651 | } |
| 652 | return status; |
| 653 | } |
| 654 | |
| 655 | /******************************************************************************* |
| 656 | ** |
| 657 | ** Function NFA_EeRemoveApduPatternRouting |
| 658 | ** |
| 659 | ** Description This function is called to remove the given APDU entry from |
| 660 | ** the listen mode routing table. If the entry configures VS, |
| 661 | ** it is also removed. The status of this operation is reported |
| 662 | ** as the NFA_EE_REMOVE_APDU_EVT. |
| 663 | ** |
| 664 | ** Note: If RF discovery is started, |
| 665 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 666 | ** happen before calling this function |
| 667 | ** |
| 668 | ** Note: NFA_EeUpdateNow() should be called after last NFA-EE |
| 669 | ** function to change the listen mode routing is called. |
| 670 | ** |
| 671 | ** Returns NFA_STATUS_OK if successfully initiated |
| 672 | ** NFA_STATUS_FAILED otherwise |
| 673 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 674 | ** |
| 675 | *******************************************************************************/ |
| 676 | tNFA_STATUS NFA_EeRemoveApduPatternRouting(uint8_t apdu_len, uint8_t* p_apdu) { |
| 677 | tNFA_EE_API_REMOVE_APDU* p_msg; |
| 678 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 679 | uint16_t size = sizeof(tNFA_EE_API_REMOVE_APDU) + apdu_len; |
| 680 | |
| 681 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("NFA_EeRemoveApduPatternRouting()"); |
| 682 | if ((apdu_len == 0) || (p_apdu == NULL) || (apdu_len > NFC_MAX_APDU_DATA_LEN)) { |
| 683 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("Bad handle"); |
| 684 | status = NFA_STATUS_INVALID_PARAM; |
| 685 | } else { |
| 686 | p_msg = (tNFA_EE_API_REMOVE_APDU*)GKI_getbuf(size); |
| 687 | if (p_msg != NULL) { |
| 688 | p_msg->hdr.event = NFA_EE_API_REMOVE_APDU_EVT; |
| 689 | p_msg->apdu_len = apdu_len; |
| 690 | p_msg->p_apdu = (uint8_t*)(p_msg + 1); |
| 691 | memcpy(p_msg->p_apdu, p_apdu, apdu_len); |
| 692 | |
| 693 | nfa_sys_sendmsg(p_msg); |
| 694 | |
| 695 | status = NFA_STATUS_OK; |
| 696 | } |
| 697 | } |
| 698 | return status; |
| 699 | } |
| 700 | #endif |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 701 | /******************************************************************************* |
| 702 | ** |
| 703 | ** Function NFA_EeRemoveAidRouting |
| 704 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 705 | ** Description This function is called to remove the given AID entry from |
| 706 | ** the listen mode routing table. If the entry configures VS, |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 707 | ** it is also removed. The status of this operation is reported |
| 708 | ** as the NFA_EE_REMOVE_AID_EVT. |
| 709 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 710 | ** Note: If RF discovery is started, |
| 711 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 712 | ** happen before calling this function |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 713 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 714 | ** Note: NFA_EeUpdateNow() should be called after last NFA-EE |
| 715 | ** function to change the listen mode routing is called. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 716 | ** |
| 717 | ** Returns NFA_STATUS_OK if successfully initiated |
| 718 | ** NFA_STATUS_FAILED otherwise |
| 719 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 720 | ** |
| 721 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 722 | tNFA_STATUS NFA_EeRemoveAidRouting(uint8_t aid_len, uint8_t* p_aid) { |
| 723 | tNFA_EE_API_REMOVE_AID* p_msg; |
| 724 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 725 | uint16_t size = sizeof(tNFA_EE_API_REMOVE_AID) + aid_len; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 726 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 727 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 728 | if ((aid_len == 0) || (p_aid == NULL) || (aid_len > NFA_MAX_AID_LEN)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 729 | LOG(ERROR) << StringPrintf("Bad AID"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 730 | status = NFA_STATUS_INVALID_PARAM; |
| 731 | } else { |
| 732 | p_msg = (tNFA_EE_API_REMOVE_AID*)GKI_getbuf(size); |
| 733 | if (p_msg != NULL) { |
| 734 | p_msg->hdr.event = NFA_EE_API_REMOVE_AID_EVT; |
| 735 | p_msg->aid_len = aid_len; |
| 736 | p_msg->p_aid = (uint8_t*)(p_msg + 1); |
| 737 | memcpy(p_msg->p_aid, p_aid, aid_len); |
| 738 | |
| 739 | nfa_sys_sendmsg(p_msg); |
| 740 | |
| 741 | status = NFA_STATUS_OK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 742 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 743 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 744 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 745 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | /******************************************************************************* |
| 749 | ** |
Suraj Uday Kotharkar | 6f7757b | 2018-05-10 15:58:29 +0530 | [diff] [blame] | 750 | ** Function NFA_EeAddSystemCodeRouting |
| 751 | ** |
| 752 | ** Description This function is called to add an system code entry in the |
| 753 | ** listen mode routing table in NFCC. The status of this |
| 754 | ** operation is reported as the NFA_EE_ADD_SYSCODE_EVT. |
| 755 | ** |
| 756 | ** Note: If RF discovery is started, |
| 757 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 758 | ** happen before calling this function |
| 759 | ** |
| 760 | ** Note: NFA_EeUpdateNow() should be called after last NFA-EE |
| 761 | ** function to change the listen mode routing is called. |
| 762 | ** |
| 763 | ** Returns NFA_STATUS_OK if successfully initiated |
| 764 | ** NFA_STATUS_FAILED otherwise |
| 765 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 766 | ** |
| 767 | *******************************************************************************/ |
| 768 | tNFA_STATUS NFA_EeAddSystemCodeRouting(uint16_t systemcode, |
| 769 | tNFA_HANDLE ee_handle, |
| 770 | tNFA_EE_PWR_STATE power_state) { |
| 771 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 772 | uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF); |
| 773 | DLOG_IF(INFO, nfc_debug_enabled) |
| 774 | << StringPrintf("NFA_EeAddSystemCodeRouting(): handle:<0x%x>", ee_handle); |
| 775 | tNFA_EE_ECB* p_cb = nfa_ee_find_ecb(nfcee_id); |
| 776 | |
| 777 | if (p_cb == NULL || systemcode == 0) { |
| 778 | LOG(ERROR) << StringPrintf("Bad ee_handle or System Code"); |
| 779 | status = NFA_STATUS_INVALID_PARAM; |
| 780 | } else if ((NFA_GetNCIVersion() != NCI_VERSION_2_0) && |
| 781 | (nfc_cb.isScbrSupported == false)) { |
| 782 | LOG(ERROR) << StringPrintf("Invalid NCI Version/SCBR not supported"); |
| 783 | status = NFA_STATUS_NOT_SUPPORTED; |
| 784 | } else { |
| 785 | tNFA_EE_API_ADD_SYSCODE* p_msg = |
| 786 | (tNFA_EE_API_ADD_SYSCODE*)GKI_getbuf(sizeof(tNFA_EE_API_ADD_SYSCODE)); |
| 787 | if (p_msg != NULL) { |
| 788 | p_msg->hdr.event = NFA_EE_API_ADD_SYSCODE_EVT; |
| 789 | p_msg->power_state = power_state; |
| 790 | p_msg->nfcee_id = nfcee_id; |
| 791 | p_msg->p_cb = p_cb; |
| 792 | // adjust endianness of syscode |
| 793 | p_msg->syscode = (systemcode & 0x00FF) << 8 | (systemcode & 0xFF00) >> 8; |
| 794 | nfa_sys_sendmsg(p_msg); |
| 795 | status = NFA_STATUS_OK; |
| 796 | } |
| 797 | } |
| 798 | return status; |
| 799 | } |
| 800 | |
| 801 | /******************************************************************************* |
| 802 | ** |
| 803 | ** Function NFA_EeRemoveSystemCodeRouting |
| 804 | ** |
| 805 | ** Description This function is called to remove the given System Code |
| 806 | ** based entry from the listen mode routing table. The status |
| 807 | ** of this operation is reported as the |
| 808 | ** NFA_EE_REMOVE_SYSCODE_EVT. |
| 809 | ** |
| 810 | ** Note: If RF discovery is started, |
| 811 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 812 | ** happen before calling this function |
| 813 | ** |
| 814 | ** Note: NFA_EeUpdateNow() should be called after last NFA-EE |
| 815 | ** function to change the listen mode routing is called. |
| 816 | ** |
| 817 | ** Returns NFA_STATUS_OK if successfully initiated |
| 818 | ** NFA_STATUS_FAILED otherwise |
| 819 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 820 | ** |
| 821 | *******************************************************************************/ |
| 822 | tNFA_STATUS NFA_EeRemoveSystemCodeRouting(uint16_t systemcode) { |
| 823 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 824 | |
| 825 | if (systemcode == 0) { |
| 826 | LOG(ERROR) << "Bad ee_handle or System Code"; |
| 827 | status = NFA_STATUS_INVALID_PARAM; |
| 828 | } else if ((NFA_GetNCIVersion() != NCI_VERSION_2_0) && |
| 829 | (nfc_cb.isScbrSupported == false)) { |
| 830 | LOG(ERROR) << "Invalid NCI Version/SCBR Not supported"; |
| 831 | status = NFA_STATUS_NOT_SUPPORTED; |
| 832 | } else { |
| 833 | tNFA_EE_API_REMOVE_SYSCODE* p_msg = (tNFA_EE_API_REMOVE_SYSCODE*)GKI_getbuf( |
| 834 | sizeof(tNFA_EE_API_REMOVE_SYSCODE)); |
| 835 | if (p_msg != NULL) { |
| 836 | p_msg->hdr.event = NFA_EE_API_REMOVE_SYSCODE_EVT; |
| 837 | p_msg->syscode = (systemcode & 0x00FF) << 8 | (systemcode & 0xFF00) >> 8; |
| 838 | nfa_sys_sendmsg(p_msg); |
| 839 | status = NFA_STATUS_OK; |
| 840 | } |
| 841 | } |
| 842 | return status; |
| 843 | } |
| 844 | |
| 845 | /******************************************************************************* |
| 846 | ** |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 847 | ** Function NFA_EeGetLmrtRemainingSize |
| 848 | ** |
| 849 | ** Description This function is called to get remaining size of the |
| 850 | ** Listen Mode Routing Table. |
| 851 | ** The remaining size is reported in NFA_EE_REMAINING_SIZE_EVT |
| 852 | ** |
| 853 | ** Returns NFA_STATUS_OK if successfully initiated |
| 854 | ** NFA_STATUS_FAILED otherwise |
| 855 | ** |
| 856 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 857 | tNFA_STATUS NFA_EeGetLmrtRemainingSize(void) { |
| 858 | tNFA_EE_API_LMRT_SIZE* p_msg; |
| 859 | tNFA_STATUS status = NFA_STATUS_FAILED; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 860 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 861 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 862 | p_msg = (tNFA_EE_API_LMRT_SIZE*)GKI_getbuf(sizeof(tNFA_EE_API_LMRT_SIZE)); |
| 863 | if (p_msg != NULL) { |
| 864 | p_msg->event = NFA_EE_API_LMRT_SIZE_EVT; |
| 865 | nfa_sys_sendmsg(p_msg); |
| 866 | status = NFA_STATUS_OK; |
| 867 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 868 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 869 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | /****************************************************************************** |
| 873 | ** |
| 874 | ** Function NFA_EeUpdateNow |
| 875 | ** |
| 876 | ** Description This function is called to send the current listen mode |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 877 | ** routing table and VS configuration to the NFCC (without |
| 878 | ** waiting for NFA_EE_ROUT_TIMEOUT_VAL). |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 879 | ** |
| 880 | ** The status of this operation is |
| 881 | ** reported with the NFA_EE_UPDATED_EVT. |
| 882 | ** |
| 883 | ** Returns NFA_STATUS_OK if successfully initiated |
| 884 | ** NFA_STATUS_SEMANTIC_ERROR is update is currently in progress |
| 885 | ** NFA_STATUS_FAILED otherwise |
| 886 | ** |
| 887 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 888 | tNFA_STATUS NFA_EeUpdateNow(void) { |
| 889 | NFC_HDR* p_msg; |
| 890 | tNFA_STATUS status = NFA_STATUS_FAILED; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 891 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 892 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 893 | if (nfa_ee_cb.ee_wait_evt & NFA_EE_WAIT_UPDATE_ALL) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 894 | LOG(ERROR) << StringPrintf("update in progress"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 895 | status = NFA_STATUS_SEMANTIC_ERROR; |
| 896 | } else { |
| 897 | p_msg = (NFC_HDR*)GKI_getbuf(NFC_HDR_SIZE); |
| 898 | if (p_msg != NULL) { |
| 899 | p_msg->event = NFA_EE_API_UPDATE_NOW_EVT; |
| 900 | |
| 901 | nfa_sys_sendmsg(p_msg); |
| 902 | |
| 903 | status = NFA_STATUS_OK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 904 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 905 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 906 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 907 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 908 | } |
| 909 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 910 | /******************************************************************************* |
| 911 | ** |
| 912 | ** Function NFA_EeConnect |
| 913 | ** |
| 914 | ** Description Open connection to an NFCEE attached to the NFCC |
| 915 | ** |
| 916 | ** The status of this operation is |
| 917 | ** reported with the NFA_EE_CONNECT_EVT. |
| 918 | ** |
| 919 | ** Returns NFA_STATUS_OK if successfully initiated |
| 920 | ** NFA_STATUS_FAILED otherwise |
| 921 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 922 | ** |
| 923 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 924 | tNFA_STATUS NFA_EeConnect(tNFA_HANDLE ee_handle, uint8_t ee_interface, |
| 925 | tNFA_EE_CBACK* p_cback) { |
| 926 | tNFA_EE_API_CONNECT* p_msg; |
| 927 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 928 | uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF); |
| 929 | tNFA_EE_ECB* p_cb; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 930 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 931 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 932 | "handle:<0x%x> ee_interface:0x%x", ee_handle, ee_interface); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 933 | p_cb = nfa_ee_find_ecb(nfcee_id); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 934 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 935 | if ((p_cb == NULL) || (p_cback == NULL)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 936 | LOG(ERROR) << StringPrintf("Bad ee_handle or NULL callback function"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 937 | status = NFA_STATUS_INVALID_PARAM; |
| 938 | } else { |
| 939 | p_msg = (tNFA_EE_API_CONNECT*)GKI_getbuf(sizeof(tNFA_EE_API_CONNECT)); |
| 940 | if (p_msg != NULL) { |
| 941 | p_msg->hdr.event = NFA_EE_API_CONNECT_EVT; |
| 942 | p_msg->nfcee_id = nfcee_id; |
| 943 | p_msg->p_cb = p_cb; |
| 944 | p_msg->ee_interface = ee_interface; |
| 945 | p_msg->p_cback = p_cback; |
| 946 | |
| 947 | nfa_sys_sendmsg(p_msg); |
| 948 | |
| 949 | status = NFA_STATUS_OK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 950 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 951 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 952 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 953 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | /******************************************************************************* |
| 957 | ** |
| 958 | ** Function NFA_EeSendData |
| 959 | ** |
| 960 | ** Description Send data to the given NFCEE. |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 961 | ** This function shall be called after NFA_EE_CONNECT_EVT is |
| 962 | ** reported and before NFA_EeDisconnect is called on the given |
| 963 | ** ee_handle. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 964 | ** |
| 965 | ** Returns NFA_STATUS_OK if successfully initiated |
| 966 | ** NFA_STATUS_FAILED otherwise |
| 967 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 968 | ** |
| 969 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 970 | tNFA_STATUS NFA_EeSendData(tNFA_HANDLE ee_handle, uint16_t data_len, |
| 971 | uint8_t* p_data) { |
| 972 | tNFA_EE_API_SEND_DATA* p_msg; |
| 973 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 974 | uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF); |
| 975 | tNFA_EE_ECB* p_cb; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 976 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 977 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("handle:<0x%x>", ee_handle); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 978 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 979 | p_cb = nfa_ee_find_ecb(nfcee_id); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 980 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 981 | if ((p_cb == NULL) || (p_cb->conn_st != NFA_EE_CONN_ST_CONN) || |
| 982 | (p_data == NULL)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 983 | LOG(ERROR) << StringPrintf("Bad ee_handle or NULL data"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 984 | status = NFA_STATUS_INVALID_PARAM; |
| 985 | } else { |
| 986 | p_msg = (tNFA_EE_API_SEND_DATA*)GKI_getbuf( |
| 987 | (uint16_t)(sizeof(tNFA_EE_API_SEND_DATA) + data_len)); |
| 988 | if (p_msg != NULL) { |
| 989 | p_msg->hdr.event = NFA_EE_API_SEND_DATA_EVT; |
| 990 | p_msg->nfcee_id = nfcee_id; |
| 991 | p_msg->p_cb = p_cb; |
| 992 | p_msg->data_len = data_len; |
| 993 | p_msg->p_data = (uint8_t*)(p_msg + 1); |
| 994 | memcpy(p_msg->p_data, p_data, data_len); |
| 995 | |
| 996 | nfa_sys_sendmsg(p_msg); |
| 997 | |
| 998 | status = NFA_STATUS_OK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 999 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1000 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1001 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1002 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | /******************************************************************************* |
| 1006 | ** |
| 1007 | ** Function NFA_EeDisconnect |
| 1008 | ** |
| 1009 | ** Description Disconnect (if a connection is currently open) from an |
| 1010 | ** NFCEE interface. The result of this operation is reported |
| 1011 | ** with the NFA_EE_DISCONNECT_EVT. |
| 1012 | ** |
| 1013 | ** Returns NFA_STATUS_OK if successfully initiated |
| 1014 | ** NFA_STATUS_FAILED otherwise |
| 1015 | ** NFA_STATUS_INVALID_PARAM If bad parameter |
| 1016 | ** |
| 1017 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1018 | tNFA_STATUS NFA_EeDisconnect(tNFA_HANDLE ee_handle) { |
| 1019 | tNFA_EE_API_DISCONNECT* p_msg; |
| 1020 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 1021 | uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF); |
| 1022 | tNFA_EE_ECB* p_cb; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1023 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1024 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("handle:<0x%x>", ee_handle); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1025 | p_cb = nfa_ee_find_ecb(nfcee_id); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1026 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1027 | if ((p_cb == NULL) || (p_cb->conn_st != NFA_EE_CONN_ST_CONN)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1028 | LOG(ERROR) << StringPrintf("Bad ee_handle"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1029 | status = NFA_STATUS_INVALID_PARAM; |
| 1030 | } else { |
| 1031 | p_msg = (tNFA_EE_API_DISCONNECT*)GKI_getbuf(sizeof(tNFA_EE_API_DISCONNECT)); |
| 1032 | if (p_msg != NULL) { |
| 1033 | p_msg->hdr.event = NFA_EE_API_DISCONNECT_EVT; |
| 1034 | p_msg->nfcee_id = nfcee_id; |
| 1035 | p_msg->p_cb = p_cb; |
| 1036 | |
| 1037 | nfa_sys_sendmsg(p_msg); |
| 1038 | |
| 1039 | status = NFA_STATUS_OK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1040 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1041 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1042 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1043 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1044 | } |
Ravishinde | 26233bb | 2018-08-06 22:16:08 +0530 | [diff] [blame^] | 1045 | #if (NXP_EXTNS == TRUE) |
| 1046 | /******************************************************************************* |
| 1047 | ** |
| 1048 | ** Function NFA_GetAidTableSize |
| 1049 | ** |
| 1050 | ** Description This function is called to get the Maximum AID routing table |
| 1051 | *size. |
| 1052 | ** |
| 1053 | ** Returns AID routing table maximum size |
| 1054 | ** |
| 1055 | *******************************************************************************/ |
| 1056 | uint16_t NFA_GetAidTableSize() { |
| 1057 | return NFA_EE_MAX_AID_CFG_LEN; |
| 1058 | } |
| 1059 | |
| 1060 | /******************************************************************************* |
| 1061 | ** |
| 1062 | ** Function NFA_GetRemainingAidTableSize |
| 1063 | ** |
| 1064 | ** Description This function is called to get the remaining AID routing |
| 1065 | ** table size. |
| 1066 | ** |
| 1067 | ** Returns Remaining AID routing table size. |
| 1068 | ** |
| 1069 | *******************************************************************************/ |
| 1070 | uint16_t NFA_GetRemainingAidTableSize() { |
| 1071 | uint16_t size = 0; |
| 1072 | size = NFA_EE_MAX_AID_CFG_LEN - nfa_ee_lmrt_size(); |
| 1073 | return size; |
| 1074 | } |
| 1075 | #endif |