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 | * NFA interface for device management |
| 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 "ndef_utils.h" |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 30 | #include "nfa_api.h" |
| 31 | #include "nfa_ce_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 | /***************************************************************************** |
| 38 | ** Constants |
| 39 | *****************************************************************************/ |
| 40 | |
| 41 | /***************************************************************************** |
| 42 | ** APIs |
| 43 | *****************************************************************************/ |
| 44 | /******************************************************************************* |
| 45 | ** |
| 46 | ** Function NFA_Init |
| 47 | ** |
| 48 | ** Description This function initializes control blocks for NFA |
| 49 | ** |
| 50 | ** p_hal_entry_tbl points to a table of HAL entry points |
| 51 | ** |
| 52 | ** NOTE: the buffer that p_hal_entry_tbl points must be |
| 53 | ** persistent until NFA is disabled. |
| 54 | ** |
| 55 | ** Returns none |
| 56 | ** |
| 57 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 58 | void NFA_Init(tHAL_NFC_ENTRY* p_hal_entry_tbl) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 59 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 60 | nfa_sys_init(); |
| 61 | nfa_dm_init(); |
| 62 | nfa_p2p_init(); |
| 63 | nfa_snep_init(false); |
| 64 | nfa_rw_init(); |
| 65 | nfa_ce_init(); |
| 66 | nfa_ee_init(); |
| 67 | if (nfa_ee_max_ee_cfg != 0) { |
| 68 | nfa_dm_cb.get_max_ee = p_hal_entry_tbl->get_max_ee; |
| 69 | nfa_hci_init(); |
| 70 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 71 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 72 | /* Initialize NFC module */ |
| 73 | NFC_Init(p_hal_entry_tbl); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /******************************************************************************* |
| 77 | ** |
| 78 | ** Function NFA_Enable |
| 79 | ** |
| 80 | ** Description This function enables NFC. Prior to calling NFA_Enable, |
| 81 | ** the NFCC must be powered up, and ready to receive commands. |
| 82 | ** This function enables the tasks needed by NFC, opens the NCI |
| 83 | ** transport, resets the NFC controller, downloads patches to |
| 84 | ** the NFCC (if necessary), and initializes the NFC subsystems. |
| 85 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 86 | ** This function should only be called once - typically when |
| 87 | ** NFC is enabled during boot-up, or when NFC is enabled from a |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 88 | ** settings UI. Subsequent calls to NFA_Enable while NFA is |
| 89 | ** enabling or enabled will be ignored. When the NFC startup |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 90 | ** procedure is completed, an NFA_DM_ENABLE_EVT is returned to |
| 91 | ** the application using the tNFA_DM_CBACK. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 92 | ** |
| 93 | ** Returns NFA_STATUS_OK if successfully initiated |
| 94 | ** NFA_STATUS_FAILED otherwise |
| 95 | ** |
| 96 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 97 | tNFA_STATUS NFA_Enable(tNFA_DM_CBACK* p_dm_cback, |
| 98 | tNFA_CONN_CBACK* p_conn_cback) { |
| 99 | tNFA_DM_API_ENABLE* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 100 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 101 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 102 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 103 | /* Validate parameters */ |
| 104 | if ((!p_dm_cback) || (!p_conn_cback)) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 105 | LOG(ERROR) << StringPrintf("error null callback"); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 106 | return (NFA_STATUS_FAILED); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 109 | p_msg = (tNFA_DM_API_ENABLE*)GKI_getbuf(sizeof(tNFA_DM_API_ENABLE)); |
| 110 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 111 | p_msg->hdr.event = NFA_DM_API_ENABLE_EVT; |
| 112 | p_msg->p_dm_cback = p_dm_cback; |
| 113 | p_msg->p_conn_cback = p_conn_cback; |
| 114 | |
| 115 | nfa_sys_sendmsg(p_msg); |
| 116 | |
| 117 | return (NFA_STATUS_OK); |
| 118 | } |
| 119 | |
| 120 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /******************************************************************************* |
| 124 | ** |
| 125 | ** Function NFA_Disable |
| 126 | ** |
| 127 | ** Description This function is called to shutdown NFC. The tasks for NFC |
| 128 | ** are terminated, and clean up routines are performed. This |
| 129 | ** function is typically called during platform shut-down, or |
| 130 | ** when NFC is disabled from a settings UI. When the NFC |
| 131 | ** shutdown procedure is completed, an NFA_DM_DISABLE_EVT is |
| 132 | ** returned to the application using the tNFA_DM_CBACK. |
| 133 | ** |
| 134 | ** The platform should wait until the NFC_DISABLE_REVT is |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 135 | ** received before powering down the NFC chip and NCI |
| 136 | ** transport. This is required to so that NFA can gracefully |
| 137 | ** shut down any open connections. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 138 | ** |
| 139 | ** Returns NFA_STATUS_OK if successfully initiated |
| 140 | ** NFA_STATUS_FAILED otherwise |
| 141 | ** |
| 142 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 143 | tNFA_STATUS NFA_Disable(bool graceful) { |
| 144 | tNFA_DM_API_DISABLE* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 145 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 146 | DLOG_IF(INFO, nfc_debug_enabled) |
| 147 | << StringPrintf("NFA_Disable (graceful=%i)", graceful); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 148 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 149 | p_msg = (tNFA_DM_API_DISABLE*)GKI_getbuf(sizeof(tNFA_DM_API_DISABLE)); |
| 150 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 151 | p_msg->hdr.event = NFA_DM_API_DISABLE_EVT; |
| 152 | p_msg->graceful = graceful; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 153 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 154 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 155 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 156 | return (NFA_STATUS_OK); |
| 157 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 158 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 159 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 160 | } |
Love Khanna | 81e4f81 | 2017-06-02 17:50:19 +0530 | [diff] [blame] | 161 | |
| 162 | /******************************************************************************* |
| 163 | ** |
| 164 | ** Function NFA_GetNCIVersion |
| 165 | ** |
| 166 | ** Description Returns the NCI version of the NFCC to upper layer |
| 167 | ** |
| 168 | ** |
| 169 | ** Returns NCI version NCI2.0 / NCI1.0 |
| 170 | ** |
| 171 | *******************************************************************************/ |
| 172 | uint8_t NFA_GetNCIVersion() { return NFC_GetNCIVersion(); } |
| 173 | |
Love Khanna | 5e4b4d7 | 2017-04-14 18:23:55 +0530 | [diff] [blame] | 174 | /******************************************************************************* |
| 175 | ** |
| 176 | ** Function NFA_SetPowerSubStateForScreenState |
| 177 | ** |
| 178 | ** Description Update the power sub-state as per current screen state to |
| 179 | ** NFCC. |
| 180 | ** |
| 181 | ** Returns NFA_STATUS_OK if successfully initiated |
| 182 | ** NFA_STATUS_FAILED otherwise |
| 183 | ** |
| 184 | *******************************************************************************/ |
| 185 | tNFA_STATUS NFA_SetPowerSubStateForScreenState(uint8_t screenState) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 186 | DLOG_IF(INFO, nfc_debug_enabled) |
| 187 | << StringPrintf("%s: state:0x%X", __func__, screenState); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 188 | |
Love Khanna | 5e4b4d7 | 2017-04-14 18:23:55 +0530 | [diff] [blame] | 189 | uint8_t nci_scren_state = 0xFF; |
| 190 | uint16_t buf_size = sizeof(tNFA_DM_API_SET_POWER_SUB_STATE); |
| 191 | tNFA_DM_API_SET_POWER_SUB_STATE* p_msg = |
| 192 | (tNFA_DM_API_SET_POWER_SUB_STATE*)GKI_getbuf(buf_size); |
| 193 | |
| 194 | if (p_msg != NULL) { |
| 195 | p_msg->hdr.event = NFA_DM_API_SET_POWER_SUB_STATE_EVT; |
| 196 | switch (screenState) { |
| 197 | case NFA_SCREEN_STATE_ON_UNLOCKED: |
| 198 | nci_scren_state = SCREEN_STATE_ON_UNLOCKED; |
| 199 | break; |
| 200 | case NFA_SCREEN_STATE_OFF_UNLOCKED: |
| 201 | nci_scren_state = SCREEN_STATE_OFF_UNLOCKED; |
| 202 | break; |
| 203 | case NFA_SCREEN_STATE_ON_LOCKED: |
| 204 | nci_scren_state = SCREEN_STATE_ON_LOCKED; |
| 205 | break; |
| 206 | case NFA_SCREEN_STATE_OFF_LOCKED: |
| 207 | nci_scren_state = SCREEN_STATE_OFF_LOCKED; |
| 208 | break; |
| 209 | |
| 210 | default: |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 211 | DLOG_IF(INFO, nfc_debug_enabled) |
| 212 | << StringPrintf("%s, unknown screen state", __func__); |
Love Khanna | 5e4b4d7 | 2017-04-14 18:23:55 +0530 | [diff] [blame] | 213 | break; |
| 214 | } |
| 215 | |
| 216 | p_msg->screen_state = nci_scren_state; |
| 217 | |
| 218 | nfa_sys_sendmsg(p_msg); |
| 219 | return (NFA_STATUS_OK); |
| 220 | } |
| 221 | return (NFA_STATUS_FAILED); |
| 222 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 223 | /******************************************************************************* |
| 224 | ** |
| 225 | ** Function NFA_SetConfig |
| 226 | ** |
| 227 | ** Description Set the configuration parameters to NFCC. The result is |
| 228 | ** reported with an NFA_DM_SET_CONFIG_EVT in the tNFA_DM_CBACK |
| 229 | ** callback. |
| 230 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 231 | ** Note: If RF discovery is started, |
| 232 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 233 | ** happen before calling this function. Most Configuration |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 234 | ** parameters are related to RF discovery. |
| 235 | ** |
| 236 | ** Returns NFA_STATUS_OK if successfully initiated |
| 237 | ** NFA_STATUS_BUSY if previous setting is on-going |
| 238 | ** NFA_STATUS_FAILED otherwise |
| 239 | ** |
| 240 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 241 | tNFA_STATUS NFA_SetConfig(tNFA_PMID param_id, uint8_t length, uint8_t* p_data) { |
| 242 | tNFA_DM_API_SET_CONFIG* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 243 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 244 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("param_id:0x%X", param_id); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 245 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 246 | p_msg = (tNFA_DM_API_SET_CONFIG*)GKI_getbuf( |
| 247 | (uint16_t)(sizeof(tNFA_DM_API_SET_CONFIG) + length)); |
| 248 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 249 | p_msg->hdr.event = NFA_DM_API_SET_CONFIG_EVT; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 250 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 251 | p_msg->param_id = param_id; |
| 252 | p_msg->length = length; |
| 253 | p_msg->p_data = (uint8_t*)(p_msg + 1); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 254 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 255 | /* Copy parameter data */ |
| 256 | memcpy(p_msg->p_data, p_data, length); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 257 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 258 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 259 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 260 | return (NFA_STATUS_OK); |
| 261 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 262 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 263 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /******************************************************************************* |
| 267 | ** |
| 268 | ** Function NFA_GetConfig |
| 269 | ** |
| 270 | ** Description Get the configuration parameters from NFCC. The result is |
| 271 | ** reported with an NFA_DM_GET_CONFIG_EVT in the tNFA_DM_CBACK |
| 272 | ** callback. |
| 273 | ** |
| 274 | ** Returns NFA_STATUS_OK if successfully initiated |
| 275 | ** NFA_STATUS_FAILED otherwise |
| 276 | ** |
| 277 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 278 | tNFA_STATUS NFA_GetConfig(uint8_t num_ids, tNFA_PMID* p_param_ids) { |
| 279 | tNFA_DM_API_GET_CONFIG* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 280 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 281 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("num_ids: %i", num_ids); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 282 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 283 | p_msg = (tNFA_DM_API_GET_CONFIG*)GKI_getbuf( |
| 284 | (uint16_t)(sizeof(tNFA_DM_API_GET_CONFIG) + num_ids)); |
| 285 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 286 | p_msg->hdr.event = NFA_DM_API_GET_CONFIG_EVT; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 287 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 288 | p_msg->num_ids = num_ids; |
| 289 | p_msg->p_pmids = (tNFA_PMID*)(p_msg + 1); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 290 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 291 | /* Copy the param IDs */ |
| 292 | memcpy(p_msg->p_pmids, p_param_ids, num_ids); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 293 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 294 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 295 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 296 | return (NFA_STATUS_OK); |
| 297 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 298 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 299 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /******************************************************************************* |
| 303 | ** |
| 304 | ** Function NFA_RequestExclusiveRfControl |
| 305 | ** |
| 306 | ** Description Request exclusive control of NFC. |
| 307 | ** - Previous behavior (polling/tag reading, DH card emulation) |
| 308 | ** will be suspended . |
| 309 | ** - Polling and listening will be done based on the specified |
| 310 | ** params |
| 311 | ** |
| 312 | ** The NFA_EXCLUSIVE_RF_CONTROL_STARTED_EVT event of |
| 313 | ** tNFA_CONN_CBACK indicates the status of the operation. |
| 314 | ** |
| 315 | ** NFA_ACTIVATED_EVT and NFA_DEACTIVATED_EVT indicates link |
| 316 | ** activation/deactivation. |
| 317 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 318 | ** NFA_SendRawFrame is used to send data to the peer. |
| 319 | ** NFA_DATA_EVT indicates data from the peer. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 320 | ** |
| 321 | ** If a tag is activated, then the NFA_RW APIs may be used to |
| 322 | ** send commands to the tag. Incoming NDEF messages are sent to |
| 323 | ** the NDEF callback. |
| 324 | ** |
| 325 | ** Once exclusive RF control has started, NFA will not activate |
| 326 | ** LLCP internally. The application has exclusive control of |
| 327 | ** the link. |
| 328 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 329 | ** Note: If RF discovery is started, |
| 330 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 331 | ** happen before calling this function |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 332 | ** |
| 333 | ** Returns NFA_STATUS_OK if successfully initiated |
| 334 | ** NFA_STATUS_FAILED otherwise |
| 335 | ** |
| 336 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 337 | tNFA_STATUS NFA_RequestExclusiveRfControl(tNFA_TECHNOLOGY_MASK poll_mask, |
| 338 | tNFA_LISTEN_CFG* p_listen_cfg, |
| 339 | tNFA_CONN_CBACK* p_conn_cback, |
| 340 | tNFA_NDEF_CBACK* p_ndef_cback) { |
| 341 | tNFA_DM_API_REQ_EXCL_RF_CTRL* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 342 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 343 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("poll_mask=0x%x", poll_mask); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 344 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 345 | if (!p_conn_cback) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 346 | LOG(ERROR) << StringPrintf("error null callback"); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 347 | return (NFA_STATUS_FAILED); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 348 | } |
| 349 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 350 | p_msg = (tNFA_DM_API_REQ_EXCL_RF_CTRL*)GKI_getbuf( |
| 351 | sizeof(tNFA_DM_API_REQ_EXCL_RF_CTRL)); |
| 352 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 353 | p_msg->hdr.event = NFA_DM_API_REQUEST_EXCL_RF_CTRL_EVT; |
| 354 | p_msg->poll_mask = poll_mask; |
| 355 | p_msg->p_conn_cback = p_conn_cback; |
| 356 | p_msg->p_ndef_cback = p_ndef_cback; |
| 357 | |
| 358 | if (p_listen_cfg) |
| 359 | memcpy(&p_msg->listen_cfg, p_listen_cfg, sizeof(tNFA_LISTEN_CFG)); |
| 360 | else |
| 361 | memset(&p_msg->listen_cfg, 0x00, sizeof(tNFA_LISTEN_CFG)); |
| 362 | |
| 363 | nfa_sys_sendmsg(p_msg); |
| 364 | |
| 365 | return (NFA_STATUS_OK); |
| 366 | } |
| 367 | |
| 368 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /******************************************************************************* |
| 372 | ** |
| 373 | ** Function NFA_ReleaseExclusiveRfControl |
| 374 | ** |
| 375 | ** Description Release exclusive control of NFC. Once released, behavior |
| 376 | ** prior to obtaining exclusive RF control will resume. |
| 377 | ** |
| 378 | ** Returns NFA_STATUS_OK if successfully initiated |
| 379 | ** NFA_STATUS_FAILED otherwise |
| 380 | ** |
| 381 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 382 | tNFA_STATUS NFA_ReleaseExclusiveRfControl(void) { |
| 383 | NFC_HDR* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 384 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 385 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 386 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 387 | if (!nfa_dm_cb.p_excl_conn_cback) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 388 | LOG(ERROR) << StringPrintf( |
| 389 | "Exclusive rf control is not in " |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 390 | "progress"); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 391 | return (NFA_STATUS_FAILED); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 392 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 393 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 394 | p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR)); |
| 395 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 396 | p_msg->event = NFA_DM_API_RELEASE_EXCL_RF_CTRL_EVT; |
| 397 | nfa_sys_sendmsg(p_msg); |
| 398 | return (NFA_STATUS_OK); |
| 399 | } |
| 400 | |
| 401 | return (NFA_STATUS_FAILED); |
| 402 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 403 | |
| 404 | /******************************************************************************* |
| 405 | ** |
| 406 | ** Function NFA_EnablePolling |
| 407 | ** |
| 408 | ** Description Enable polling for technologies specified by poll_mask. |
| 409 | ** |
| 410 | ** The following events (notified using the connection |
| 411 | ** callback registered with NFA_Enable) are generated during |
| 412 | ** polling: |
| 413 | ** |
| 414 | ** - NFA_POLL_ENABLED_EVT indicates whether or not polling |
| 415 | ** successfully enabled. |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 416 | ** - NFA_DISC_RESULT_EVT indicates there are more than one |
| 417 | ** devices, so application must select one of tags by calling |
| 418 | ** NFA_Select(). |
| 419 | ** - NFA_SELECT_RESULT_EVT indicates whether previous selection |
| 420 | ** was successful or not. If it was failed then application |
| 421 | ** must select again or deactivate by calling |
| 422 | ** NFA_Deactivate(). |
| 423 | ** - NFA_ACTIVATED_EVT is generated when an NFC link is |
| 424 | ** activated. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 425 | ** - NFA_NDEF_DETECT_EVT is generated if tag is activated |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 426 | ** - NFA_LLCP_ACTIVATED_EVT/NFA_LLCP_DEACTIVATED_EVT is |
| 427 | ** generated if NFC-DEP is activated |
| 428 | ** - NFA_DEACTIVATED_EVT will be returned after deactivating |
| 429 | ** NFC link. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 430 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 431 | ** Note: If RF discovery is started, |
| 432 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 433 | ** happen before calling this function |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 434 | ** |
| 435 | ** Returns NFA_STATUS_OK if successfully initiated |
| 436 | ** NFA_STATUS_FAILED otherwise |
| 437 | ** |
| 438 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 439 | tNFA_STATUS NFA_EnablePolling(tNFA_TECHNOLOGY_MASK poll_mask) { |
| 440 | tNFA_DM_API_ENABLE_POLL* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 441 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 442 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("0x%X", poll_mask); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 443 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 444 | p_msg = (tNFA_DM_API_ENABLE_POLL*)GKI_getbuf(sizeof(tNFA_DM_API_ENABLE_POLL)); |
| 445 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 446 | p_msg->hdr.event = NFA_DM_API_ENABLE_POLLING_EVT; |
| 447 | p_msg->poll_mask = poll_mask; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 448 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 449 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 450 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 451 | return (NFA_STATUS_OK); |
| 452 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 453 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 454 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | /******************************************************************************* |
| 458 | ** |
| 459 | ** Function NFA_DisablePolling |
| 460 | ** |
| 461 | ** Description Disable polling |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 462 | ** NFA_POLL_DISABLED_EVT will be returned after stopping |
| 463 | ** polling. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 464 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 465 | ** Note: If RF discovery is started, |
| 466 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 467 | ** happen before calling this function |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 468 | ** |
| 469 | ** Returns NFA_STATUS_OK if successfully initiated |
| 470 | ** NFA_STATUS_FAILED otherwise |
| 471 | ** |
| 472 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 473 | tNFA_STATUS NFA_DisablePolling(void) { |
| 474 | NFC_HDR* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 475 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 476 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 477 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 478 | p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR)); |
| 479 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 480 | p_msg->event = NFA_DM_API_DISABLE_POLLING_EVT; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 481 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 482 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 483 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 484 | return (NFA_STATUS_OK); |
| 485 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 486 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 487 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | /******************************************************************************* |
| 491 | ** |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 492 | ** Function NFA_EnableListening |
| 493 | ** |
| 494 | ** Description Enable listening. |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 495 | ** NFA_LISTEN_ENABLED_EVT will be returned after listening is |
| 496 | ** allowed. |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 497 | ** |
| 498 | ** The actual listening technologies are specified by other NFA |
| 499 | ** API functions. Such functions include (but not limited to) |
| 500 | ** NFA_CeConfigureUiccListenTech. |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 501 | ** If NFA_DisableListening () is called to ignore the listening |
| 502 | ** technologies, NFA_EnableListening () is called to restore |
| 503 | ** the listening technologies set by these functions. |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 504 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 505 | ** Note: If RF discovery is started, |
| 506 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 507 | ** happen before calling this function |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 508 | ** |
| 509 | ** Returns NFA_STATUS_OK if successfully initiated |
| 510 | ** NFA_STATUS_FAILED otherwise |
| 511 | ** |
| 512 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 513 | tNFA_STATUS NFA_EnableListening(void) { |
| 514 | NFC_HDR* p_msg; |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 515 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 516 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 517 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 518 | p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR)); |
| 519 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 520 | p_msg->event = NFA_DM_API_ENABLE_LISTENING_EVT; |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 521 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 522 | nfa_sys_sendmsg(p_msg); |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 523 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 524 | return (NFA_STATUS_OK); |
| 525 | } |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 526 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 527 | return (NFA_STATUS_FAILED); |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | /******************************************************************************* |
| 531 | ** |
| 532 | ** Function NFA_DisableListening |
| 533 | ** |
| 534 | ** Description Disable listening |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 535 | ** NFA_LISTEN_DISABLED_EVT will be returned after stopping |
| 536 | ** listening. This function is called to exclude listen at RF |
| 537 | ** discovery. |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 538 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 539 | ** Note: If RF discovery is started, |
| 540 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 541 | ** happen before calling this function |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 542 | ** |
| 543 | ** Returns NFA_STATUS_OK if successfully initiated |
| 544 | ** NFA_STATUS_FAILED otherwise |
| 545 | ** |
| 546 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 547 | tNFA_STATUS NFA_DisableListening(void) { |
| 548 | NFC_HDR* p_msg; |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 549 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 550 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 551 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 552 | p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR)); |
| 553 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 554 | p_msg->event = NFA_DM_API_DISABLE_LISTENING_EVT; |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 555 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 556 | nfa_sys_sendmsg(p_msg); |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 557 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 558 | return (NFA_STATUS_OK); |
| 559 | } |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 560 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 561 | return (NFA_STATUS_FAILED); |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | /******************************************************************************* |
| 565 | ** |
| 566 | ** Function NFA_PauseP2p |
| 567 | ** |
| 568 | ** Description Pause P2P services. |
| 569 | ** NFA_P2P_PAUSED_EVT will be returned after P2P services are |
| 570 | ** disabled. |
| 571 | ** |
| 572 | ** The P2P services enabled by NFA_P2p* API functions are not |
| 573 | ** available. NFA_ResumeP2p() is called to resume the P2P |
| 574 | ** services. |
| 575 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 576 | ** Note: If RF discovery is started, |
| 577 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 578 | ** happen before calling this function |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 579 | ** |
| 580 | ** Returns NFA_STATUS_OK if successfully initiated |
| 581 | ** NFA_STATUS_FAILED otherwise |
| 582 | ** |
| 583 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 584 | tNFA_STATUS NFA_PauseP2p(void) { |
| 585 | NFC_HDR* p_msg; |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 586 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 587 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 588 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 589 | p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR)); |
| 590 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 591 | p_msg->event = NFA_DM_API_PAUSE_P2P_EVT; |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 592 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 593 | nfa_sys_sendmsg(p_msg); |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 594 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 595 | return (NFA_STATUS_OK); |
| 596 | } |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 597 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 598 | return (NFA_STATUS_FAILED); |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /******************************************************************************* |
| 602 | ** |
| 603 | ** Function NFA_ResumeP2p |
| 604 | ** |
| 605 | ** Description Resume P2P services. |
| 606 | ** NFA_P2P_RESUMED_EVT will be returned after P2P services are. |
| 607 | ** enables again. |
| 608 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 609 | ** Note: If RF discovery is started, |
| 610 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 611 | ** happen before calling this function |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 612 | ** |
| 613 | ** Returns NFA_STATUS_OK if successfully initiated |
| 614 | ** NFA_STATUS_FAILED otherwise |
| 615 | ** |
| 616 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 617 | tNFA_STATUS NFA_ResumeP2p(void) { |
| 618 | NFC_HDR* p_msg; |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 619 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 620 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 621 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 622 | p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR)); |
| 623 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 624 | p_msg->event = NFA_DM_API_RESUME_P2P_EVT; |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 625 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 626 | nfa_sys_sendmsg(p_msg); |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 627 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 628 | return (NFA_STATUS_OK); |
| 629 | } |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 630 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 631 | return (NFA_STATUS_FAILED); |
Evan Chu | 67aef6c | 2013-08-29 13:02:54 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | /******************************************************************************* |
| 635 | ** |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 636 | ** Function NFA_SetP2pListenTech |
| 637 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 638 | ** Description This function is called to set listen technology for |
| 639 | ** NFC-DEP. This funtion may be called before or after starting |
| 640 | ** any server on NFA P2P/CHO/SNEP. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 641 | ** If there is no technology for NFC-DEP, P2P listening will be |
| 642 | ** stopped. |
| 643 | ** |
| 644 | ** NFA_SET_P2P_LISTEN_TECH_EVT without data will be returned. |
| 645 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 646 | ** Note: If RF discovery is started, |
| 647 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 648 | ** happen before calling this function |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 649 | ** |
| 650 | ** Returns NFA_STATUS_OK if successfully initiated |
| 651 | ** NFA_STATUS_FAILED otherwise |
| 652 | ** |
| 653 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 654 | tNFA_STATUS NFA_SetP2pListenTech(tNFA_TECHNOLOGY_MASK tech_mask) { |
| 655 | tNFA_DM_API_SET_P2P_LISTEN_TECH* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 656 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 657 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("tech_mask:0x%X", tech_mask); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 658 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 659 | p_msg = (tNFA_DM_API_SET_P2P_LISTEN_TECH*)GKI_getbuf( |
| 660 | sizeof(tNFA_DM_API_SET_P2P_LISTEN_TECH)); |
| 661 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 662 | p_msg->hdr.event = NFA_DM_API_SET_P2P_LISTEN_TECH_EVT; |
| 663 | p_msg->tech_mask = tech_mask; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 664 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 665 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 666 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 667 | return (NFA_STATUS_OK); |
| 668 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 669 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 670 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /******************************************************************************* |
| 674 | ** |
| 675 | ** Function NFA_StartRfDiscovery |
| 676 | ** |
| 677 | ** Description Start RF discovery |
| 678 | ** RF discovery parameters shall be set by other APIs. |
| 679 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 680 | ** An NFA_RF_DISCOVERY_STARTED_EVT indicates whether starting |
| 681 | ** was successful or not. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 682 | ** |
| 683 | ** Returns NFA_STATUS_OK if successfully initiated |
| 684 | ** NFA_STATUS_FAILED otherwise |
| 685 | ** |
| 686 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 687 | tNFA_STATUS NFA_StartRfDiscovery(void) { |
| 688 | NFC_HDR* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 689 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 690 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 691 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 692 | p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR)); |
| 693 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 694 | p_msg->event = NFA_DM_API_START_RF_DISCOVERY_EVT; |
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 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 697 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 698 | return (NFA_STATUS_OK); |
| 699 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 700 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 701 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /******************************************************************************* |
| 705 | ** |
| 706 | ** Function NFA_StopRfDiscovery |
| 707 | ** |
| 708 | ** Description Stop RF discovery |
| 709 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 710 | ** An NFA_RF_DISCOVERY_STOPPED_EVT indicates whether stopping |
| 711 | ** was successful or not. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 712 | ** |
| 713 | ** Returns NFA_STATUS_OK if successfully initiated |
| 714 | ** NFA_STATUS_FAILED otherwise |
| 715 | ** |
| 716 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 717 | tNFA_STATUS NFA_StopRfDiscovery(void) { |
| 718 | NFC_HDR* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 719 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 720 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 721 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 722 | p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR)); |
| 723 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 724 | p_msg->event = NFA_DM_API_STOP_RF_DISCOVERY_EVT; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 725 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 726 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 727 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 728 | return (NFA_STATUS_OK); |
| 729 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 730 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 731 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | /******************************************************************************* |
| 735 | ** |
| 736 | ** Function NFA_SetRfDiscoveryDuration |
| 737 | ** |
| 738 | ** Description Set the duration of the single discovery period in [ms]. |
| 739 | ** Allowable range: 0 ms to 0xFFFF ms. |
| 740 | ** |
| 741 | ** If discovery is already started, the application should |
| 742 | ** call NFA_StopRfDiscovery prior to calling |
| 743 | ** NFA_SetRfDiscoveryDuration, and then call |
| 744 | ** NFA_StartRfDiscovery afterwards to restart discovery using |
| 745 | ** the new duration. |
| 746 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 747 | ** Note: If RF discovery is started, |
| 748 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 749 | ** happen before calling this function |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 750 | ** |
| 751 | ** Returns: |
| 752 | ** NFA_STATUS_OK, if command accepted |
| 753 | ** NFA_STATUS_FAILED: otherwise |
| 754 | ** |
| 755 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 756 | tNFA_STATUS NFA_SetRfDiscoveryDuration(uint16_t discovery_period_ms) { |
| 757 | tNFA_DM_API_SET_RF_DISC_DUR* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 758 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 759 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 760 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 761 | /* Post the API message */ |
Love Khanna | 1d06277 | 2018-04-10 21:10:02 +0530 | [diff] [blame^] | 762 | p_msg = (tNFA_DM_API_SET_RF_DISC_DUR*)GKI_getbuf(sizeof(NFC_HDR)); |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 763 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 764 | p_msg->hdr.event = NFA_DM_API_SET_RF_DISC_DURATION_EVT; |
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 | /* Set discovery duration */ |
| 767 | p_msg->rf_disc_dur_ms = discovery_period_ms; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 768 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 769 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 770 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 771 | return (NFA_STATUS_OK); |
| 772 | } |
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 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | /******************************************************************************* |
| 778 | ** |
| 779 | ** Function NFA_Select |
| 780 | ** |
| 781 | ** Description Select one from detected devices during discovery |
| 782 | ** (from NFA_DISC_RESULT_EVTs). The application should wait for |
| 783 | ** the final NFA_DISC_RESULT_EVT before selecting. |
| 784 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 785 | ** An NFA_SELECT_RESULT_EVT indicates whether selection was |
| 786 | ** successful or not. If failed then application must select |
| 787 | ** again or deactivate by NFA_Deactivate(). |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 788 | ** |
| 789 | ** Returns NFA_STATUS_OK if successfully initiated |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 790 | ** NFA_STATUS_INVALID_PARAM if RF interface is not matched |
| 791 | ** protocol |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 792 | ** NFA_STATUS_FAILED otherwise |
| 793 | ** |
| 794 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 795 | tNFA_STATUS NFA_Select(uint8_t rf_disc_id, tNFA_NFC_PROTOCOL protocol, |
| 796 | tNFA_INTF_TYPE rf_interface) { |
| 797 | tNFA_DM_API_SELECT* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 798 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 799 | DLOG_IF(INFO, nfc_debug_enabled) |
| 800 | << StringPrintf("rf_disc_id:0x%X, protocol:0x%X, rf_interface:0x%X", |
| 801 | rf_disc_id, protocol, rf_interface); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 802 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 803 | if (((rf_interface == NFA_INTERFACE_ISO_DEP) && |
| 804 | (protocol != NFA_PROTOCOL_ISO_DEP)) || |
| 805 | ((rf_interface == NFA_INTERFACE_NFC_DEP) && |
| 806 | (protocol != NFA_PROTOCOL_NFC_DEP))) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 807 | LOG(ERROR) << StringPrintf("RF interface is not matched protocol"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 808 | return (NFA_STATUS_INVALID_PARAM); |
| 809 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 810 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 811 | p_msg = |
| 812 | (tNFA_DM_API_SELECT*)GKI_getbuf((uint16_t)(sizeof(tNFA_DM_API_SELECT))); |
| 813 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 814 | p_msg->hdr.event = NFA_DM_API_SELECT_EVT; |
| 815 | p_msg->rf_disc_id = rf_disc_id; |
| 816 | p_msg->protocol = protocol; |
| 817 | p_msg->rf_interface = rf_interface; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 818 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 819 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 820 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 821 | return (NFA_STATUS_OK); |
| 822 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 823 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 824 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | /******************************************************************************* |
| 828 | ** |
| 829 | ** Function NFA_UpdateRFCommParams |
| 830 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 831 | ** Description This function is called to update RF Communication |
| 832 | ** parameters once the Frame RF Interface has been activated. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 833 | ** |
| 834 | ** An NFA_UPDATE_RF_PARAM_RESULT_EVT indicates whether updating |
| 835 | ** was successful or not. |
| 836 | ** |
| 837 | ** Returns NFA_STATUS_OK if successfully initiated |
| 838 | ** NFA_STATUS_FAILED otherwise |
| 839 | ** |
| 840 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 841 | tNFA_STATUS NFA_UpdateRFCommParams(tNFA_RF_COMM_PARAMS* p_params) { |
| 842 | tNFA_DM_API_UPDATE_RF_PARAMS* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 843 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 844 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 845 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 846 | p_msg = (tNFA_DM_API_UPDATE_RF_PARAMS*)GKI_getbuf( |
| 847 | (uint16_t)(sizeof(tNFA_DM_API_UPDATE_RF_PARAMS))); |
| 848 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 849 | p_msg->hdr.event = NFA_DM_API_UPDATE_RF_PARAMS_EVT; |
| 850 | memcpy(&p_msg->params, p_params, sizeof(tNFA_RF_COMM_PARAMS)); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 851 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 852 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 853 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 854 | return (NFA_STATUS_OK); |
| 855 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 856 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 857 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | /******************************************************************************* |
| 861 | ** |
| 862 | ** Function NFA_Deactivate |
| 863 | ** |
| 864 | ** Description |
| 865 | ** If sleep_mode=TRUE: |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 866 | ** Deselect the activated device by deactivating into sleep |
| 867 | ** mode. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 868 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 869 | ** An NFA_DEACTIVATE_FAIL_EVT indicates that selection was |
| 870 | ** not successful. Application can select another |
| 871 | ** discovered device or deactivate by NFA_Deactivate() |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 872 | ** after receiving NFA_DEACTIVATED_EVT. |
| 873 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 874 | ** Deactivating to sleep mode is not allowed when NFCC is |
| 875 | ** in wait-for-host-select mode, or in listen-sleep states; |
| 876 | ** NFA will deactivate to idle or discovery state for these |
| 877 | ** cases respectively. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 878 | ** |
| 879 | ** |
| 880 | ** If sleep_mode=FALSE: |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 881 | ** Deactivate the connection (e.g. as a result of presence |
| 882 | ** check failure) NFA_DEACTIVATED_EVT will indicate that |
| 883 | ** link is deactivated. Polling/listening will resume |
| 884 | ** (unless the nfcc is in wait_for-all-discoveries state) |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 885 | ** |
| 886 | ** |
| 887 | ** Returns NFA_STATUS_OK if successfully initiated |
| 888 | ** NFA_STATUS_FAILED otherwise |
| 889 | ** |
| 890 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 891 | extern tNFA_STATUS NFA_Deactivate(bool sleep_mode) { |
| 892 | tNFA_DM_API_DEACTIVATE* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 893 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 894 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("sleep_mode:%i", sleep_mode); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 895 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 896 | p_msg = (tNFA_DM_API_DEACTIVATE*)GKI_getbuf( |
| 897 | (uint16_t)(sizeof(tNFA_DM_API_DEACTIVATE))); |
| 898 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 899 | p_msg->hdr.event = NFA_DM_API_DEACTIVATE_EVT; |
| 900 | p_msg->sleep_mode = sleep_mode; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 901 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 902 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 903 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 904 | return (NFA_STATUS_OK); |
| 905 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 906 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 907 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | /******************************************************************************* |
| 911 | ** |
| 912 | ** Function NFA_SendRawFrame |
| 913 | ** |
| 914 | ** Description Send a raw frame over the activated interface with the NFCC. |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 915 | ** This function can only be called after NFC link is |
| 916 | ** activated. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 917 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 918 | ** If the activated interface is a tag and auto-presence check |
| 919 | ** is enabled then presence_check_start_delay can be used to |
| 920 | ** indicate the delay in msec after which the next auto |
| 921 | ** presence check command can be sent. |
| 922 | ** NFA_DM_DEFAULT_PRESENCE_CHECK_START_DELAY can be used as the |
| 923 | ** default value for the delay. |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 924 | ** |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 925 | ** Returns NFA_STATUS_OK if successfully initiated |
| 926 | ** NFA_STATUS_FAILED otherwise |
| 927 | ** |
| 928 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 929 | tNFA_STATUS NFA_SendRawFrame(uint8_t* p_raw_data, uint16_t data_len, |
| 930 | uint16_t presence_check_start_delay) { |
| 931 | NFC_HDR* p_msg; |
| 932 | uint16_t size; |
| 933 | uint8_t* p; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 934 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 935 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("data_len:%d", data_len); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 936 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 937 | /* Validate parameters */ |
| 938 | if ((data_len == 0) || (p_raw_data == NULL)) |
| 939 | return (NFA_STATUS_INVALID_PARAM); |
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 | size = NFC_HDR_SIZE + NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE + data_len; |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 942 | p_msg = (NFC_HDR*)GKI_getbuf(size); |
| 943 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 944 | p_msg->event = NFA_DM_API_RAW_FRAME_EVT; |
| 945 | p_msg->layer_specific = presence_check_start_delay; |
| 946 | p_msg->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 947 | p_msg->len = data_len; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 948 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 949 | p = (uint8_t*)(p_msg + 1) + p_msg->offset; |
| 950 | memcpy(p, p_raw_data, data_len); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 951 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 952 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 953 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 954 | return (NFA_STATUS_OK); |
| 955 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 956 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 957 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | /******************************************************************************* |
| 961 | ** NDEF Handler APIs |
| 962 | *******************************************************************************/ |
| 963 | |
| 964 | /******************************************************************************* |
| 965 | ** |
| 966 | ** Function NFA_RegisterNDefTypeHandler |
| 967 | ** |
| 968 | ** Description This function allows the applications to register for |
| 969 | ** specific types of NDEF records. When NDEF records are |
| 970 | ** received, NFA will parse the record-type field, and pass |
| 971 | ** the record to the registered tNFA_NDEF_CBACK. |
| 972 | ** |
| 973 | ** For records types which were not registered, the record will |
| 974 | ** be sent to the default handler. A default type-handler may |
| 975 | ** be registered by calling this NFA_RegisterNDefTypeHandler |
| 976 | ** with tnf=NFA_TNF_DEFAULT. In this case, all un-registered |
| 977 | ** record types will be sent to the callback. Only one default |
| 978 | ** handler may be registered at a time. |
| 979 | ** |
| 980 | ** An NFA_NDEF_REGISTER_EVT will be sent to the tNFA_NDEF_CBACK |
| 981 | ** to indicate that registration was successful, and provide a |
| 982 | ** handle for this record type. |
| 983 | ** |
| 984 | ** Returns NFA_STATUS_OK if successfully initiated |
| 985 | ** NFA_STATUS_FAILED otherwise |
| 986 | ** |
| 987 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 988 | tNFA_STATUS NFA_RegisterNDefTypeHandler(bool handle_whole_message, tNFA_TNF tnf, |
| 989 | uint8_t* p_type_name, |
| 990 | uint8_t type_name_len, |
| 991 | tNFA_NDEF_CBACK* p_ndef_cback) { |
| 992 | tNFA_DM_API_REG_NDEF_HDLR* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 993 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 994 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 995 | "handle whole ndef message: %i, " |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 996 | "tnf=0x%02x", |
| 997 | handle_whole_message, tnf); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 998 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 999 | /* Check for NULL callback */ |
| 1000 | if (!p_ndef_cback) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1001 | LOG(ERROR) << StringPrintf("error - null callback"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1002 | return (NFA_STATUS_INVALID_PARAM); |
| 1003 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1004 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 1005 | p_msg = (tNFA_DM_API_REG_NDEF_HDLR*)GKI_getbuf( |
| 1006 | (uint16_t)(sizeof(tNFA_DM_API_REG_NDEF_HDLR) + type_name_len)); |
| 1007 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1008 | p_msg->hdr.event = NFA_DM_API_REG_NDEF_HDLR_EVT; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1009 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1010 | p_msg->flags = |
| 1011 | (handle_whole_message ? NFA_NDEF_FLAGS_HANDLE_WHOLE_MESSAGE : 0); |
| 1012 | p_msg->tnf = tnf; |
| 1013 | p_msg->name_len = type_name_len; |
| 1014 | p_msg->p_ndef_cback = p_ndef_cback; |
| 1015 | memcpy(p_msg->name, p_type_name, type_name_len); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1016 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1017 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1018 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1019 | return (NFA_STATUS_OK); |
| 1020 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1021 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1022 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | /******************************************************************************* |
| 1026 | ** |
| 1027 | ** Function NFA_RegisterNDefUriHandler |
| 1028 | ** |
| 1029 | ** Description This API is a special-case of NFA_RegisterNDefTypeHandler |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 1030 | ** with TNF=NFA_TNF_WKT, and type_name='U' (URI record); and |
| 1031 | ** allows registering for specific URI types (e.g. 'tel:' or |
| 1032 | ** 'mailto:'). |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1033 | ** |
| 1034 | ** An NFA_NDEF_REGISTER_EVT will be sent to the tNFA_NDEF_CBACK |
| 1035 | ** to indicate that registration was successful, and provide a |
| 1036 | ** handle for this registration. |
| 1037 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 1038 | ** If uri_id=NFA_NDEF_URI_ID_ABSOLUTE, then p_abs_uri contains |
| 1039 | ** the unabridged URI. For all other uri_id values, |
| 1040 | ** the p_abs_uri parameter is ignored (i.e the URI prefix is |
| 1041 | ** implied by uri_id). See [NFC RTD URI] for more information. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1042 | ** |
| 1043 | ** Returns NFA_STATUS_OK if successfully initiated |
| 1044 | ** NFA_STATUS_FAILED otherwise |
| 1045 | ** |
| 1046 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1047 | extern tNFA_STATUS NFA_RegisterNDefUriHandler(bool handle_whole_message, |
| 1048 | tNFA_NDEF_URI_ID uri_id, |
| 1049 | uint8_t* p_abs_uri, |
| 1050 | uint8_t uri_id_len, |
| 1051 | tNFA_NDEF_CBACK* p_ndef_cback) { |
| 1052 | tNFA_DM_API_REG_NDEF_HDLR* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1053 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1054 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 1055 | "handle whole ndef message: %i, " |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1056 | "uri_id=0x%02x", |
| 1057 | handle_whole_message, uri_id); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1058 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1059 | /* Check for NULL callback */ |
| 1060 | if (!p_ndef_cback) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1061 | LOG(ERROR) << StringPrintf("error - null callback"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1062 | return (NFA_STATUS_INVALID_PARAM); |
| 1063 | } |
| 1064 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 1065 | p_msg = (tNFA_DM_API_REG_NDEF_HDLR*)GKI_getbuf( |
| 1066 | (uint16_t)(sizeof(tNFA_DM_API_REG_NDEF_HDLR) + uri_id_len)); |
| 1067 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1068 | p_msg->hdr.event = NFA_DM_API_REG_NDEF_HDLR_EVT; |
| 1069 | |
| 1070 | p_msg->flags = NFA_NDEF_FLAGS_WKT_URI; |
| 1071 | |
| 1072 | if (handle_whole_message) { |
| 1073 | p_msg->flags |= NFA_NDEF_FLAGS_HANDLE_WHOLE_MESSAGE; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1074 | } |
| 1075 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1076 | /* abs_uri is only valid fir uri_id=NFA_NDEF_URI_ID_ABSOLUTE */ |
| 1077 | if (uri_id != NFA_NDEF_URI_ID_ABSOLUTE) { |
| 1078 | uri_id_len = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1079 | } |
| 1080 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1081 | p_msg->tnf = NFA_TNF_WKT; |
| 1082 | p_msg->uri_id = uri_id; |
| 1083 | p_msg->name_len = uri_id_len; |
| 1084 | p_msg->p_ndef_cback = p_ndef_cback; |
| 1085 | memcpy(p_msg->name, p_abs_uri, uri_id_len); |
| 1086 | |
| 1087 | nfa_sys_sendmsg(p_msg); |
| 1088 | |
| 1089 | return (NFA_STATUS_OK); |
| 1090 | } |
| 1091 | |
| 1092 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | /******************************************************************************* |
| 1096 | ** |
| 1097 | ** Function NFA_DeregisterNDefTypeHandler |
| 1098 | ** |
| 1099 | ** Description Deregister NDEF record type handler. |
| 1100 | ** |
| 1101 | ** Returns NFA_STATUS_OK if successfully initiated |
| 1102 | ** NFA_STATUS_FAILED otherwise |
| 1103 | ** |
| 1104 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1105 | extern tNFA_STATUS NFA_DeregisterNDefTypeHandler(tNFA_HANDLE ndef_type_handle) { |
| 1106 | tNFA_DM_API_DEREG_NDEF_HDLR* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1107 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1108 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1109 | << StringPrintf("handle 0x%08x", ndef_type_handle); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1110 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 1111 | p_msg = (tNFA_DM_API_DEREG_NDEF_HDLR*)GKI_getbuf( |
| 1112 | (uint16_t)(sizeof(tNFA_DM_API_DEREG_NDEF_HDLR))); |
| 1113 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1114 | p_msg->hdr.event = NFA_DM_API_DEREG_NDEF_HDLR_EVT; |
| 1115 | p_msg->ndef_type_handle = ndef_type_handle; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1116 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1117 | nfa_sys_sendmsg(p_msg); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1118 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1119 | return (NFA_STATUS_OK); |
| 1120 | } |
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 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | /******************************************************************************* |
| 1126 | ** |
| 1127 | ** Function NFA_PowerOffSleepMode |
| 1128 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 1129 | ** Description This function is called to enter or leave NFCC Power Off |
| 1130 | ** Sleep mode NFA_DM_PWR_MODE_CHANGE_EVT will be sent to |
| 1131 | ** indicate status. |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1132 | ** |
| 1133 | ** start_stop : TRUE if entering Power Off Sleep mode |
| 1134 | ** FALSE if leaving Power Off Sleep mode |
| 1135 | ** |
| 1136 | ** Returns NFA_STATUS_OK if successfully initiated |
| 1137 | ** NFA_STATUS_FAILED otherwise |
| 1138 | ** |
| 1139 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1140 | tNFA_STATUS NFA_PowerOffSleepMode(bool start_stop) { |
| 1141 | NFC_HDR* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1142 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1143 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("start_stop=%d", start_stop); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1144 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1145 | if (nfa_dm_cb.flags & NFA_DM_FLAGS_SETTING_PWR_MODE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1146 | LOG(ERROR) << StringPrintf("NFA DM is busy to update power mode"); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1147 | return (NFA_STATUS_FAILED); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1148 | } else { |
| 1149 | nfa_dm_cb.flags |= NFA_DM_FLAGS_SETTING_PWR_MODE; |
| 1150 | } |
| 1151 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 1152 | p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR)); |
| 1153 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1154 | p_msg->event = NFA_DM_API_POWER_OFF_SLEEP_EVT; |
| 1155 | p_msg->layer_specific = start_stop; |
| 1156 | |
| 1157 | nfa_sys_sendmsg(p_msg); |
| 1158 | |
| 1159 | return (NFA_STATUS_OK); |
| 1160 | } |
| 1161 | |
| 1162 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | /******************************************************************************* |
| 1166 | ** |
| 1167 | ** Function NFA_RegVSCback |
| 1168 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 1169 | ** Description This function is called to register or de-register a |
| 1170 | ** callback function to receive Proprietary NCI response and |
| 1171 | ** notification events. The maximum number of callback |
| 1172 | ** functions allowed is NFC_NUM_VS_CBACKS |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1173 | ** |
| 1174 | ** Returns tNFC_STATUS |
| 1175 | ** |
| 1176 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1177 | tNFC_STATUS NFA_RegVSCback(bool is_register, tNFA_VSC_CBACK* p_cback) { |
| 1178 | tNFA_DM_API_REG_VSC* p_msg; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1179 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1180 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1181 | << StringPrintf("is_register=%d", is_register); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1182 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1183 | if (p_cback == NULL) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1184 | LOG(ERROR) << StringPrintf("requires a valid callback function"); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1185 | return (NFA_STATUS_FAILED); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1186 | } |
| 1187 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 1188 | p_msg = (tNFA_DM_API_REG_VSC*)GKI_getbuf(sizeof(tNFA_DM_API_REG_VSC)); |
| 1189 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1190 | p_msg->hdr.event = NFA_DM_API_REG_VSC_EVT; |
| 1191 | p_msg->is_register = is_register; |
| 1192 | p_msg->p_cback = p_cback; |
| 1193 | |
| 1194 | nfa_sys_sendmsg(p_msg); |
| 1195 | |
| 1196 | return (NFA_STATUS_OK); |
| 1197 | } |
| 1198 | |
| 1199 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | /******************************************************************************* |
| 1203 | ** |
| 1204 | ** Function NFA_SendVsCommand |
| 1205 | ** |
| 1206 | ** Description This function is called to send an NCI Vendor Specific |
| 1207 | ** command to NFCC. |
| 1208 | ** |
| 1209 | ** oid - The opcode of the VS command. |
| 1210 | ** cmd_params_len - The command parameter len |
| 1211 | ** p_cmd_params - The command parameter |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 1212 | ** p_cback - The callback function to receive the |
| 1213 | ** command status |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1214 | ** |
| 1215 | ** Returns NFA_STATUS_OK if successfully initiated |
| 1216 | ** NFA_STATUS_FAILED otherwise |
| 1217 | ** |
| 1218 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1219 | tNFA_STATUS NFA_SendVsCommand(uint8_t oid, uint8_t cmd_params_len, |
| 1220 | uint8_t* p_cmd_params, tNFA_VSC_CBACK* p_cback) { |
| 1221 | tNFA_DM_API_SEND_VSC* p_msg; |
| 1222 | uint16_t size = sizeof(tNFA_DM_API_SEND_VSC) + cmd_params_len; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1223 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1224 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("oid=0x%x", oid); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1225 | |
Ruchi Kandoi | 0c515ae | 2017-01-30 17:48:41 -0800 | [diff] [blame] | 1226 | p_msg = (tNFA_DM_API_SEND_VSC*)GKI_getbuf(size); |
| 1227 | if (p_msg != NULL) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1228 | p_msg->hdr.event = NFA_DM_API_SEND_VSC_EVT; |
| 1229 | p_msg->oid = oid; |
| 1230 | p_msg->p_cback = p_cback; |
| 1231 | if (cmd_params_len && p_cmd_params) { |
| 1232 | p_msg->cmd_params_len = cmd_params_len; |
| 1233 | p_msg->p_cmd_params = (uint8_t*)(p_msg + 1); |
| 1234 | memcpy(p_msg->p_cmd_params, p_cmd_params, cmd_params_len); |
| 1235 | } else { |
| 1236 | p_msg->cmd_params_len = 0; |
| 1237 | p_msg->p_cmd_params = NULL; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1238 | } |
| 1239 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1240 | nfa_sys_sendmsg(p_msg); |
| 1241 | |
| 1242 | return (NFA_STATUS_OK); |
| 1243 | } |
| 1244 | |
| 1245 | return (NFA_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | /******************************************************************************* |
| 1249 | ** |
Love Khanna | d7852c9 | 2017-06-02 19:55:05 +0530 | [diff] [blame] | 1250 | ** Function NFA_SendRawVsCommand |
| 1251 | ** |
| 1252 | ** Description This function is called to send raw Vendor Specific |
| 1253 | ** command to NFCC. |
| 1254 | ** |
| 1255 | ** cmd_params_len - The command parameter len |
| 1256 | ** p_cmd_params - The command parameter |
| 1257 | ** p_cback - The callback function to receive the |
| 1258 | ** command |
| 1259 | ** |
| 1260 | ** Returns NFA_STATUS_OK if successfully initiated |
| 1261 | ** NFA_STATUS_FAILED otherwise |
| 1262 | ** |
| 1263 | *******************************************************************************/ |
| 1264 | tNFA_STATUS NFA_SendRawVsCommand(uint8_t cmd_params_len, uint8_t* p_cmd_params, |
| 1265 | tNFA_VSC_CBACK* p_cback) { |
| 1266 | if (cmd_params_len == 0x00 || p_cmd_params == NULL || p_cback == NULL) { |
| 1267 | return NFA_STATUS_INVALID_PARAM; |
| 1268 | } |
| 1269 | uint16_t size = sizeof(tNFA_DM_API_SEND_VSC) + cmd_params_len; |
| 1270 | tNFA_DM_API_SEND_VSC* p_msg = (tNFA_DM_API_SEND_VSC*)GKI_getbuf(size); |
| 1271 | |
| 1272 | if (p_msg != NULL) { |
| 1273 | p_msg->hdr.event = NFA_DM_API_SEND_RAW_VS_EVT; |
| 1274 | p_msg->p_cback = p_cback; |
| 1275 | if (cmd_params_len && p_cmd_params) { |
| 1276 | p_msg->cmd_params_len = cmd_params_len; |
| 1277 | p_msg->p_cmd_params = (uint8_t*)(p_msg + 1); |
| 1278 | memcpy(p_msg->p_cmd_params, p_cmd_params, cmd_params_len); |
| 1279 | } else { |
| 1280 | p_msg->cmd_params_len = 0; |
| 1281 | p_msg->p_cmd_params = NULL; |
| 1282 | } |
| 1283 | |
| 1284 | nfa_sys_sendmsg(p_msg); |
| 1285 | |
| 1286 | return NFA_STATUS_OK; |
| 1287 | } |
| 1288 | |
| 1289 | return NFA_STATUS_FAILED; |
| 1290 | } |
| 1291 | |
| 1292 | /******************************************************************************* |
| 1293 | ** |
Love Khanna | d7852c9 | 2017-06-02 19:55:05 +0530 | [diff] [blame] | 1294 | ** Function: NFA_EnableDtamode |
| 1295 | ** |
| 1296 | ** Description: Enable DTA Mode |
| 1297 | ** |
| 1298 | ** Returns: none: |
| 1299 | ** |
| 1300 | *******************************************************************************/ |
| 1301 | void NFA_EnableDtamode(tNFA_eDtaModes eDtaMode) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1302 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1303 | << StringPrintf("%s: 0x%x ", __func__, eDtaMode); |
Love Khanna | d7852c9 | 2017-06-02 19:55:05 +0530 | [diff] [blame] | 1304 | appl_dta_mode_flag = 0x01; |
| 1305 | nfa_dm_cb.eDtaMode = eDtaMode; |
| 1306 | } |