nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | /****************************************************************************** |
| 17 | * |
| 18 | * The original Work has been changed by NXP Semiconductors. |
| 19 | * |
| 20 | * Copyright (C) 2015 NXP Semiconductors |
| 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 | * |
| 34 | ******************************************************************************/ |
| 35 | #include <semaphore.h> |
| 36 | #include <errno.h> |
| 37 | #include "OverrideLog.h" |
| 38 | #include "NfcJniUtil.h" |
| 39 | #include "NfcAdaptation.h" |
| 40 | #include "SyncEvent.h" |
| 41 | #include "PeerToPeer.h" |
| 42 | #include "SecureElement.h" |
| 43 | #include "RoutingManager.h" |
| 44 | #include "NfcTag.h" |
| 45 | #include "config.h" |
| 46 | #include "PowerSwitch.h" |
| 47 | #include "JavaClassConstants.h" |
| 48 | #include "Pn544Interop.h" |
| 49 | #include <ScopedLocalRef.h> |
| 50 | #include <ScopedUtfChars.h> |
| 51 | #include <sys/time.h> |
| 52 | #include "HciRFParams.h" |
| 53 | #include <pthread.h> |
| 54 | #include <ScopedPrimitiveArray.h> |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 55 | #if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 56 | #include <signal.h> |
| 57 | #include <sys/types.h> |
| 58 | #endif |
| 59 | #include "DwpChannel.h" |
| 60 | extern "C" |
| 61 | { |
| 62 | #include "nfa_api.h" |
| 63 | #include "nfa_p2p_api.h" |
| 64 | #include "rw_api.h" |
| 65 | #include "nfa_ee_api.h" |
| 66 | #include "nfc_brcm_defs.h" |
| 67 | #include "ce_api.h" |
| 68 | #include "phNxpExtns.h" |
| 69 | #include "phNxpConfig.h" |
| 70 | |
| 71 | #if (NFC_NXP_ESE == TRUE) |
| 72 | #include "JcDnld.h" |
| 73 | #include "IChannel.h" |
| 74 | #endif |
| 75 | } |
| 76 | |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 77 | #define SAK_VALUE_AT 17 |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 78 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 79 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 80 | #define UICC_HANDLE 0x402 |
| 81 | #define ESE_HANDLE 0x4C0 |
| 82 | #define RETRY_COUNT 10 |
| 83 | #define default_count 3 |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 84 | extern bool recovery; |
| 85 | static INT32 gNfcInitTimeout; |
| 86 | static INT32 gdisc_timeout; |
| 87 | INT32 gSeDiscoverycount = 0; |
| 88 | INT32 gActualSeCount = 0; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 89 | #if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE) |
| 90 | UINT8 sSelectedUicc = 0; |
| 91 | #endif |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 92 | SyncEvent gNfceeDiscCbEvent; |
| 93 | extern int gUICCVirtualWiredProtectMask; |
| 94 | extern int gEseVirtualWiredProtectMask; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 95 | #endif |
| 96 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 97 | extern const UINT8 nfca_version_string []; |
| 98 | extern const UINT8 nfa_version_string []; |
| 99 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 100 | #if (NFC_NXP_ESE == TRUE && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 101 | extern Rdr_req_ntf_info_t swp_rdr_req_ntf_info; |
| 102 | #endif |
| 103 | |
| 104 | extern tNFA_DM_DISC_FREQ_CFG* p_nfa_dm_rf_disc_freq_cfg; //defined in stack |
| 105 | bool sHCEEnabled = true; // whether HCE is enabled |
| 106 | extern bool gReaderNotificationflag; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 107 | |
| 108 | namespace android |
| 109 | { |
| 110 | extern bool gIsTagDeactivating; |
| 111 | extern bool gIsSelectingRfInterface; |
| 112 | extern void nativeNfcTag_doTransceiveStatus (tNFA_STATUS status, uint8_t * buf, uint32_t buflen); |
| 113 | extern void nativeNfcTag_notifyRfTimeout (); |
| 114 | extern void nativeNfcTag_doConnectStatus (jboolean is_connect_ok); |
| 115 | extern void nativeNfcTag_doDeactivateStatus (int status); |
| 116 | extern void nativeNfcTag_doWriteStatus (jboolean is_write_ok); |
| 117 | extern void nativeNfcTag_doCheckNdefResult (tNFA_STATUS status, uint32_t max_size, uint32_t current_size, uint8_t flags); |
| 118 | extern void nativeNfcTag_doMakeReadonlyResult (tNFA_STATUS status); |
| 119 | extern void nativeNfcTag_doPresenceCheckResult (tNFA_STATUS status); |
| 120 | extern void nativeNfcTag_formatStatus (bool is_ok); |
| 121 | extern void nativeNfcTag_resetPresenceCheck (); |
| 122 | extern void nativeNfcTag_doReadCompleted (tNFA_STATUS status); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 123 | extern void nativeNfcTag_setRfInterface (tNFA_INTF_TYPE rfInterface); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 124 | extern void nativeNfcTag_abortWaits (); |
| 125 | extern void doDwpChannel_ForceExit(); |
| 126 | extern void nativeLlcpConnectionlessSocket_abortWait (); |
| 127 | extern tNFA_STATUS EmvCo_dosetPoll(jboolean enable); |
| 128 | extern void nativeNfcTag_registerNdefTypeHandler (); |
| 129 | extern void nativeLlcpConnectionlessSocket_receiveData (uint8_t* data, uint32_t len, uint32_t remote_sap); |
| 130 | extern tNFA_STATUS SetScreenState(int state); |
| 131 | extern tNFA_STATUS SendAutonomousMode(int state , uint8_t num); |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 132 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 133 | #if((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 134 | extern tNFA_STATUS SendAGCDebugCommand(); |
| 135 | #endif |
| 136 | #endif |
| 137 | //Factory Test Code --start |
| 138 | extern tNFA_STATUS Nxp_SelfTest(uint8_t testcase, uint8_t* param); |
| 139 | extern void SetCbStatus(tNFA_STATUS status); |
| 140 | extern tNFA_STATUS GetCbStatus(void); |
| 141 | static void nfaNxpSelfTestNtfTimerCb (union sigval); |
| 142 | //Factory Test Code --end |
| 143 | extern bool getReconnectState(void); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 144 | extern tNFA_STATUS SetVenConfigValue(jint nfcMode); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 145 | extern tNFA_STATUS SetHfoConfigValue(void); |
| 146 | extern tNFA_STATUS SetUICC_SWPBitRate(bool); |
| 147 | extern tNFA_STATUS GetSwpStausValue(void); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 148 | #if((NXP_EXTNS == TRUE) && (NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE)) |
| 149 | extern tNFA_STATUS Set_EERegisterValue(UINT16 RegAddr, uint8_t bitVal); |
| 150 | extern tNFA_STATUS NxpNfc_Write_Cmd_Common(uint8_t retlen, uint8_t* buffer); |
| 151 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 152 | extern void acquireRfInterfaceMutexLock(); |
| 153 | extern void releaseRfInterfaceMutexLock(); |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 154 | #if(NXP_EXTNS == TRUE && NFC_NXP_NON_STD_CARD == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 155 | extern void nativeNfcTag_cacheNonNciCardDetection(); |
| 156 | extern void nativeNfcTag_handleNonNciCardDetection(tNFA_CONN_EVT_DATA* eventData); |
| 157 | extern void nativeNfcTag_handleNonNciMultiCardDetection(UINT8 connEvent, tNFA_CONN_EVT_DATA* eventData); |
| 158 | extern uint8_t checkTagNtf; |
| 159 | extern uint8_t checkCmdSent; |
| 160 | #endif |
| 161 | } |
| 162 | |
| 163 | |
| 164 | /***************************************************************************** |
| 165 | ** |
| 166 | ** public variables and functions |
| 167 | ** |
| 168 | *****************************************************************************/ |
| 169 | bool gActivated = false; |
| 170 | SyncEvent gDeactivatedEvent; |
| 171 | |
| 172 | namespace android |
| 173 | { |
| 174 | int gGeneralTransceiveTimeout = DEFAULT_GENERAL_TRANS_TIMEOUT; |
| 175 | int gGeneralPowershutDown = 0; |
| 176 | jmethodID gCachedNfcManagerNotifyNdefMessageListeners; |
| 177 | jmethodID gCachedNfcManagerNotifyTransactionListeners; |
| 178 | jmethodID gCachedNfcManagerNotifyConnectivityListeners; |
| 179 | jmethodID gCachedNfcManagerNotifyEmvcoMultiCardDetectedListeners; |
| 180 | jmethodID gCachedNfcManagerNotifyLlcpLinkActivation; |
| 181 | jmethodID gCachedNfcManagerNotifyLlcpLinkDeactivated; |
| 182 | jmethodID gCachedNfcManagerNotifyLlcpFirstPacketReceived; |
| 183 | jmethodID gCachedNfcManagerNotifySeFieldActivated; |
| 184 | jmethodID gCachedNfcManagerNotifySeFieldDeactivated; |
| 185 | jmethodID gCachedNfcManagerNotifySeListenActivated; |
| 186 | jmethodID gCachedNfcManagerNotifySeListenDeactivated; |
| 187 | jmethodID gCachedNfcManagerNotifyHostEmuActivated; |
| 188 | jmethodID gCachedNfcManagerNotifyHostEmuData; |
| 189 | jmethodID gCachedNfcManagerNotifyHostEmuDeactivated; |
| 190 | jmethodID gCachedNfcManagerNotifyRfFieldActivated; |
| 191 | jmethodID gCachedNfcManagerNotifyRfFieldDeactivated; |
| 192 | jmethodID gCachedNfcManagerNotifySWPReaderRequested; |
| 193 | jmethodID gCachedNfcManagerNotifySWPReaderRequestedFail; |
| 194 | jmethodID gCachedNfcManagerNotifySWPReaderActivated; |
| 195 | jmethodID gCachedNfcManagerNotifyAidRoutingTableFull; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 196 | #if(NFC_NXP_ESE == TRUE && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 197 | jmethodID gCachedNfcManagerNotifyETSIReaderModeStartConfig; |
| 198 | jmethodID gCachedNfcManagerNotifyETSIReaderModeStopConfig; |
| 199 | jmethodID gCachedNfcManagerNotifyETSIReaderModeSwpTimeout; |
| 200 | #endif |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 201 | #if((NXP_EXTNS == TRUE) && (NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE)) |
| 202 | jmethodID gCachedNfcManagerNotifyUiccStatusEvent; |
| 203 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 204 | const char* gNativeP2pDeviceClassName = "com/android/nfc/dhimpl/NativeP2pDevice"; |
| 205 | const char* gNativeLlcpServiceSocketClassName = "com/android/nfc/dhimpl/NativeLlcpServiceSocket"; |
| 206 | const char* gNativeLlcpConnectionlessSocketClassName = "com/android/nfc/dhimpl/NativeLlcpConnectionlessSocket"; |
| 207 | const char* gNativeLlcpSocketClassName = "com/android/nfc/dhimpl/NativeLlcpSocket"; |
| 208 | const char* gNativeNfcTagClassName = "com/android/nfc/dhimpl/NativeNfcTag"; |
| 209 | const char* gNativeNfcManagerClassName = "com/android/nfc/dhimpl/NativeNfcManager"; |
| 210 | const char* gNativeNfcSecureElementClassName = "com/android/nfc/dhimpl/NativeNfcSecureElement"; |
| 211 | const char* gNativeNfcAlaClassName = "com/android/nfc/dhimpl/NativeNfcAla"; |
| 212 | void doStartupConfig (); |
| 213 | void startStopPolling (bool isStartPolling); |
| 214 | void startRfDiscovery (bool isStart); |
| 215 | void setUiccIdleTimeout (bool enable); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 216 | void config_swp_reader_mode(bool mode); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 217 | bool isDiscoveryStarted (); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | |
| 221 | /***************************************************************************** |
| 222 | ** |
| 223 | ** private variables and functions |
| 224 | ** |
| 225 | *****************************************************************************/ |
| 226 | namespace android |
| 227 | { |
| 228 | static jint sLastError = ERROR_BUFFER_TOO_SMALL; |
| 229 | static jmethodID sCachedNfcManagerNotifySeApduReceived; |
| 230 | static jmethodID sCachedNfcManagerNotifySeMifareAccess; |
| 231 | static jmethodID sCachedNfcManagerNotifySeEmvCardRemoval; |
| 232 | static jmethodID sCachedNfcManagerNotifyTargetDeselected; |
| 233 | static SyncEvent sNfaEnableEvent; //event for NFA_Enable() |
| 234 | static SyncEvent sNfaDisableEvent; //event for NFA_Disable() |
| 235 | SyncEvent sNfaEnableDisablePollingEvent; //event for NFA_EnablePolling(), NFA_DisablePolling() |
| 236 | SyncEvent sNfaSetConfigEvent; // event for Set_Config.... |
| 237 | SyncEvent sNfaGetConfigEvent; // event for Get_Config.... |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 238 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 239 | SyncEvent sNfaGetRoutingEvent; // event for Get_Routing.... |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 240 | static bool sProvisionMode = false; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 241 | #if((NXP_EXTNS == TRUE) && (NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE)) |
| 242 | SyncEvent sNfceeHciCbEnableEvent; |
| 243 | SyncEvent sNfceeHciCbDisableEvent; |
| 244 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 245 | #endif |
| 246 | |
| 247 | static bool sIsNfaEnabled = false; |
| 248 | static bool sDiscoveryEnabled = false; //is polling or listening |
| 249 | static bool sPollingEnabled = false; //is polling for tag? |
| 250 | static bool sIsDisabling = false; |
| 251 | static bool sRfEnabled = false; // whether RF discovery is enabled |
| 252 | static bool sSeRfActive = false; // whether RF with SE is likely active |
| 253 | static bool sReaderModeEnabled = false; // whether we're only reading tags, not allowing P2p/card emu |
| 254 | static bool sP2pEnabled = false; |
| 255 | static bool sP2pActive = false; // whether p2p was last active |
| 256 | static bool sAbortConnlessWait = false; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 257 | static jint sLfT3tMax = 0; |
| 258 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 259 | static UINT8 sIsSecElemSelected = 0; //has NFC service selected a sec elem |
| 260 | static UINT8 sIsSecElemDetected = 0; //has NFC service deselected a sec elem |
| 261 | static bool sDiscCmdwhleNfcOff = false; |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 262 | #if (NXP_EXTNS == TRUE) |
| 263 | static bool gsNfaPartialEnabled = false; |
| 264 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 265 | |
| 266 | #define CONFIG_UPDATE_TECH_MASK (1 << 1) |
| 267 | #define TRANSACTION_TIMER_VALUE 50 |
| 268 | #define DEFAULT_TECH_MASK (NFA_TECHNOLOGY_MASK_A \ |
| 269 | | NFA_TECHNOLOGY_MASK_B \ |
| 270 | | NFA_TECHNOLOGY_MASK_F \ |
| 271 | | NFA_TECHNOLOGY_MASK_ISO15693 \ |
| 272 | | NFA_TECHNOLOGY_MASK_B_PRIME \ |
| 273 | | NFA_TECHNOLOGY_MASK_A_ACTIVE \ |
| 274 | | NFA_TECHNOLOGY_MASK_F_ACTIVE \ |
| 275 | | NFA_TECHNOLOGY_MASK_KOVIO) |
| 276 | #define DEFAULT_DISCOVERY_DURATION 500 |
| 277 | #define READER_MODE_DISCOVERY_DURATION 200 |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 278 | #if(NXP_EXTNS == TRUE) |
| 279 | #define DUAL_UICC_FEATURE_NOT_AVAILABLE 0xED; |
| 280 | #define STATUS_UNKNOWN_ERROR 0xEF; |
| 281 | #endif |
| 282 | #if((NXP_EXTNS == TRUE) && (NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE)) |
| 283 | enum |
| 284 | { |
| 285 | UICC_CONFIGURED, |
| 286 | UICC_NOT_CONFIGURED |
| 287 | }; |
| 288 | typedef enum dual_uicc_error_states{ |
| 289 | DUAL_UICC_ERROR_NFCC_BUSY = 0x02, |
| 290 | DUAL_UICC_ERROR_SELECT_FAILED, |
| 291 | DUAL_UICC_ERROR_NFC_TURNING_OFF, |
| 292 | DUAL_UICC_ERROR_INVALID_SLOT, |
| 293 | DUAL_UICC_ERROR_STATUS_UNKNOWN |
| 294 | }dual_uicc_error_state_t; |
| 295 | #endif |
| 296 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 297 | static int screenstate = 0; |
| 298 | static bool pendingScreenState = false; |
| 299 | static void nfcManager_doSetScreenState(JNIEnv* e, jobject o, jint state); |
| 300 | static void nfcManager_doSetScreenOrPowerState (JNIEnv* e, jobject o, jint state); |
| 301 | static void StoreScreenState(int state); |
| 302 | int getScreenState(); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 303 | #if(NFC_NXP_ESE == TRUE && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 304 | bool isp2pActivated(); |
| 305 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 306 | static void nfaConnectionCallback (UINT8 event, tNFA_CONN_EVT_DATA *eventData); |
| 307 | static void nfaDeviceManagementCallback (UINT8 event, tNFA_DM_CBACK_DATA *eventData); |
| 308 | static bool isPeerToPeer (tNFA_ACTIVATED& activated); |
| 309 | static bool isListenMode(tNFA_ACTIVATED& activated); |
| 310 | static void setListenMode(); |
| 311 | static void enableDisableLptd (bool enable); |
| 312 | static tNFA_STATUS stopPolling_rfDiscoveryDisabled(); |
| 313 | static tNFA_STATUS startPolling_rfDiscoveryDisabled(tNFA_TECHNOLOGY_MASK tech_mask); |
| 314 | |
| 315 | static int nfcManager_getChipVer(JNIEnv* e, jobject o); |
| 316 | static jbyteArray nfcManager_getFwFileName(JNIEnv* e, jobject o); |
| 317 | static int nfcManager_getNfcInitTimeout(JNIEnv* e, jobject o); |
| 318 | static int nfcManager_doJcosDownload(JNIEnv* e, jobject o); |
| 319 | static void nfcManager_doCommitRouting(JNIEnv* e, jobject o); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 320 | #if(NXP_EXTNS == TRUE) |
| 321 | static void nfcManager_doSetNfcMode (JNIEnv *e, jobject o, jint nfcMode); |
| 322 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 323 | static void nfcManager_doSetVenConfigValue (JNIEnv *e, jobject o, jint venconfig); |
| 324 | static jint nfcManager_getSecureElementTechList(JNIEnv* e, jobject o); |
| 325 | static void nfcManager_setSecureElementListenTechMask(JNIEnv *e, jobject o, jint tech_mask); |
| 326 | static void notifyPollingEventwhileNfcOff(); |
| 327 | |
| 328 | #if (NFC_NXP_ESE == TRUE) |
| 329 | void DWPChannel_init(IChannel_t *DWP); |
| 330 | IChannel_t Dwp; |
| 331 | #endif |
| 332 | static UINT16 sCurrentConfigLen; |
| 333 | static UINT8 sConfig[256]; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 334 | #if((NXP_EXTNS == TRUE) && (NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE)) |
| 335 | typedef struct |
| 336 | { |
| 337 | UINT8 sUicc1Cntx[256]; |
| 338 | UINT16 sUicc1CntxLen; |
| 339 | UINT8 sUicc2Cntx[256]; |
| 340 | UINT16 sUicc2CntxLen; |
| 341 | UINT8 sUicc1TechCapblty[12]; |
| 342 | UINT8 sUicc2TechCapblty[12]; |
| 343 | UINT8 uiccActivStat = 0; |
| 344 | UINT8 uiccConfigStat = 0; |
| 345 | }dual_uicc_info_t; |
| 346 | dual_uicc_info_t dualUiccInfo; |
| 347 | typedef enum |
| 348 | { |
| 349 | UICC_CONNECTED_0, |
| 350 | UICC_CONNECTED_1, |
| 351 | UICC_CONNECTED_2 |
| 352 | }uicc_enumeration_t; |
| 353 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 354 | static UINT8 sLongGuardTime[] = { 0x00, 0x20 }; |
| 355 | static UINT8 sDefaultGuardTime[] = { 0x00, 0x11 }; |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 356 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 357 | /*Proprietary cmd sent to HAL to send reader mode flag |
| 358 | * Last byte of sProprietaryCmdBuf contains ReaderMode flag */ |
| 359 | #define PROPRIETARY_CMD_FELICA_READER_MODE 0xFE |
| 360 | static UINT8 sProprietaryCmdBuf[]={0xFE,0xFE,0xFE,0x00}; |
| 361 | UINT8 felicaReader_Disc_id; |
| 362 | static void NxpResponsePropCmd_Cb(UINT8 event, UINT16 param_len, UINT8 *p_param); |
| 363 | static int sTechMask = 0; // Copy of Tech Mask used in doEnableReaderMode |
| 364 | static SyncEvent sRespCbEvent; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 365 | bool rfActivation = false; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 366 | static void* pollT3TThread(void *arg); |
| 367 | static bool switchP2PToT3TRead(UINT8 disc_id); |
| 368 | typedef enum felicaReaderMode_state |
| 369 | { |
| 370 | STATE_IDLE = 0x00, |
| 371 | STATE_NFCDEP_ACTIVATED_NFCDEP_INTF, |
| 372 | STATE_DEACTIVATED_TO_SLEEP, |
| 373 | STATE_FRAMERF_INTF_SELECTED, |
| 374 | }eFelicaReaderModeState_t; |
| 375 | static eFelicaReaderModeState_t gFelicaReaderState=STATE_IDLE; |
| 376 | |
| 377 | UINT16 sRoutingBuffLen; |
| 378 | static UINT8 sRoutingBuff[MAX_GET_ROUTING_BUFFER_SIZE]; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 379 | static UINT8 sNfceeConfigured; |
| 380 | static UINT8 sCheckNfceeFlag; |
| 381 | void checkforNfceeBuffer(); |
| 382 | void checkforNfceeConfig(); |
| 383 | tNFA_STATUS getUICC_RF_Param_SetSWPBitRate(); |
| 384 | //self test start |
| 385 | static IntervalTimer nfaNxpSelfTestNtfTimer; // notification timer for swp self test |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 386 | #if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE) |
| 387 | static IntervalTimer uiccEventTimer; // notification timer for uicc select |
| 388 | static void notifyUiccEvent (union sigval); |
| 389 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 390 | static SyncEvent sNfaNxpNtfEvent; |
| 391 | static void nfaNxpSelfTestNtfTimerCb (union sigval); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 392 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 393 | static void nfcManager_doSetEEPROM(JNIEnv* e, jobject o, jbyteArray val); |
| 394 | static jint nfcManager_getFwVersion(JNIEnv* e, jobject o); |
| 395 | static jint nfcManager_SWPSelfTest(JNIEnv* e, jobject o, jint ch); |
| 396 | static void nfcManager_doPrbsOff(JNIEnv* e, jobject o); |
| 397 | static void nfcManager_doPrbsOn(JNIEnv* e, jobject o, jint prbs, jint hw_prbs, jint tech, jint rate); |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 398 | static void nfcManager_Enablep2p(JNIEnv* e, jobject o, jboolean p2pFlag); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 399 | //self test end |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 400 | static void nfcManager_setProvisionMode(JNIEnv* e, jobject o, jboolean provisionMode); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 401 | static bool nfcManager_doPartialInitialize (); |
| 402 | static bool nfcManager_doPartialDeInitialize(); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 403 | #if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE) |
| 404 | static int nfcManager_doSelectUicc(JNIEnv* e, jobject o, jint uiccSlot); |
| 405 | static int nfcManager_doGetSelectedUicc(JNIEnv* e, jobject o); |
| 406 | static void getUiccContext(); |
| 407 | static int nfcManager_staticDualUicc_Precondition(int uiccSlot); |
| 408 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 409 | #endif |
| 410 | |
| 411 | |
| 412 | static int nfcManager_doGetSeInterface(JNIEnv* e, jobject o, jint type); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 413 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 414 | #if(NXP_EXTNS == TRUE && NFC_NXP_NON_STD_CARD == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 415 | extern bool scoreGenericNtf; |
| 416 | #endif |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 417 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 418 | tNFC_FW_VERSION get_fw_version(); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 419 | bool isNfcInitializationDone(); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 420 | static UINT16 discDuration = 0x00; |
| 421 | UINT16 getrfDiscoveryDuration(); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 422 | #if((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 423 | typedef struct enableAGC_debug |
| 424 | { |
| 425 | long enableAGC; // config param |
| 426 | bool AGCdebugstarted;// flag to indicate agc ongoing |
| 427 | bool AGCdebugrunning;//flag to indicate agc running or stopped. |
| 428 | }enableAGC_debug_t; |
| 429 | static enableAGC_debug_t menableAGC_debug_t; |
| 430 | void *enableAGCThread(void *arg); |
| 431 | static void nfcManagerEnableAGCDebug(UINT8 connEvent); |
| 432 | void set_AGC_process_state(bool state); |
| 433 | bool get_AGC_process_state(); |
| 434 | #endif |
| 435 | #endif |
| 436 | |
| 437 | void checkforTranscation(UINT8 connEvent ,void * eventData); |
| 438 | void sig_handler(int signo); |
| 439 | void cleanup_timer(); |
| 440 | /* Transaction Events in order */ |
| 441 | typedef enum transcation_events |
| 442 | { |
| 443 | NFA_TRANS_DEFAULT = 0x00, |
| 444 | NFA_TRANS_ACTIVATED_EVT, |
| 445 | NFA_TRANS_EE_ACTION_EVT, |
| 446 | NFA_TRANS_DM_RF_FIELD_EVT, |
| 447 | NFA_TRANS_DM_RF_FIELD_EVT_ON, |
| 448 | NFA_TRANS_DM_RF_TRANS_START, |
| 449 | NFA_TRANS_DM_RF_FIELD_EVT_OFF, |
| 450 | NFA_TRANS_DM_RF_TRANS_PROGRESS, |
| 451 | NFA_TRANS_DM_RF_TRANS_END, |
| 452 | NFA_TRANS_MIFARE_ACT_EVT, |
| 453 | NFA_TRANS_CE_ACTIVATED = 0x18, |
| 454 | NFA_TRANS_CE_DEACTIVATED = 0x19, |
| 455 | }eTranscation_events_t; |
| 456 | |
| 457 | /* Structure to store screen state */ |
| 458 | typedef enum screen_state |
| 459 | { |
| 460 | NFA_SCREEN_STATE_DEFAULT = 0x00, |
| 461 | NFA_SCREEN_STATE_OFF, |
| 462 | NFA_SCREEN_STATE_LOCKED, |
| 463 | NFA_SCREEN_STATE_UNLOCKED |
| 464 | }eScreenState_t; |
| 465 | |
| 466 | typedef enum se_client |
| 467 | { |
| 468 | DEFAULT = 0x00, |
| 469 | LDR_SRVCE, |
| 470 | JCOP_SRVCE, |
| 471 | LTSM_SRVCE |
| 472 | }seClient_t; |
| 473 | |
| 474 | /*Structure to store discovery parameters*/ |
| 475 | typedef struct discovery_Parameters |
| 476 | { |
| 477 | int technologies_mask; |
| 478 | bool enable_lptd; |
| 479 | bool reader_mode; |
| 480 | bool enable_host_routing; |
| 481 | bool enable_p2p; |
| 482 | bool restart; |
| 483 | }discovery_Parameters_t; |
| 484 | |
| 485 | /*Structure to store transcation result*/ |
| 486 | typedef struct Transcation_Check |
| 487 | { |
| 488 | bool trans_in_progress; |
| 489 | char last_request; |
| 490 | eScreenState_t last_screen_state_request; |
| 491 | eTranscation_events_t current_transcation_state; |
| 492 | struct nfc_jni_native_data *transaction_nat; |
| 493 | discovery_Parameters_t discovery_params; |
| 494 | }Transcation_Check_t; |
| 495 | |
| 496 | extern tNFA_INTF_TYPE sCurrentRfInterface; |
| 497 | static Transcation_Check_t transaction_data; |
| 498 | static void nfcManager_enableDiscovery (JNIEnv* e, jobject o, jint technologies_mask, |
| 499 | jboolean enable_lptd, jboolean reader_mode, jboolean enable_host_routing, jboolean enable_p2p, |
| 500 | jboolean restart); |
| 501 | void nfcManager_disableDiscovery (JNIEnv*, jobject); |
| 502 | static bool get_transcation_stat(void); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 503 | static char get_last_request(void); |
| 504 | static void set_last_request(char status, struct nfc_jni_native_data *nat); |
| 505 | static eScreenState_t get_lastScreenStateRequest(void); |
| 506 | static void set_lastScreenStateRequest(eScreenState_t status); |
| 507 | void *enableThread(void *arg); |
| 508 | static IntervalTimer scleanupTimerProc_transaction; |
| 509 | static bool gIsDtaEnabled=false; |
| 510 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 511 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 512 | /***P2P-Prio Logic for Multiprotocol***/ |
| 513 | static UINT8 multiprotocol_flag = 1; |
| 514 | static UINT8 multiprotocol_detected = 0; |
| 515 | void *p2p_prio_logic_multiprotocol(void *arg); |
| 516 | static IntervalTimer multiprotocol_timer; |
| 517 | pthread_t multiprotocol_thread; |
| 518 | void reconfigure_poll_cb(union sigval); |
| 519 | void clear_multiprotocol(); |
| 520 | void multiprotocol_clear_flag(union sigval); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 521 | void set_transcation_stat(bool result); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 522 | #endif |
| 523 | |
| 524 | ///////////////////////////////////////////////////////////// |
| 525 | ///////////////////////////////////////////////////////////// |
| 526 | |
| 527 | /******************************************************************************* |
| 528 | ** |
| 529 | ** Function: getNative |
| 530 | ** |
| 531 | ** Description: Get native data |
| 532 | ** |
| 533 | ** Returns: Native data structure. |
| 534 | ** |
| 535 | *******************************************************************************/ |
| 536 | nfc_jni_native_data *getNative (JNIEnv* e, jobject o) |
| 537 | { |
| 538 | static struct nfc_jni_native_data *sCachedNat = NULL; |
| 539 | if (e) |
| 540 | { |
| 541 | sCachedNat = nfc_jni_get_nat(e, o); |
| 542 | } |
| 543 | return sCachedNat; |
| 544 | } |
| 545 | |
| 546 | |
| 547 | /******************************************************************************* |
| 548 | ** |
| 549 | ** Function: handleRfDiscoveryEvent |
| 550 | ** |
| 551 | ** Description: Handle RF-discovery events from the stack. |
| 552 | ** discoveredDevice: Discovered device. |
| 553 | ** |
| 554 | ** Returns: None |
| 555 | ** |
| 556 | *******************************************************************************/ |
| 557 | static void handleRfDiscoveryEvent (tNFC_RESULT_DEVT* discoveredDevice) |
| 558 | { |
| 559 | int thread_ret; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 560 | if(discoveredDevice->more == NCI_DISCOVER_NTF_MORE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 561 | { |
| 562 | |
| 563 | //there is more discovery notification coming |
| 564 | NfcTag::getInstance ().mNumDiscNtf++; |
| 565 | return; |
| 566 | } |
| 567 | NfcTag::getInstance ().mNumDiscNtf++; |
| 568 | ALOGD("Total Notifications - %d ", NfcTag::getInstance ().mNumDiscNtf); |
| 569 | bool isP2p = NfcTag::getInstance ().isP2pDiscovered (); |
| 570 | if (!sReaderModeEnabled && isP2p) |
| 571 | { |
| 572 | //select the peer that supports P2P |
| 573 | ALOGD(" select P2P"); |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 574 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 575 | if(multiprotocol_detected == 1) |
| 576 | { |
| 577 | multiprotocol_timer.kill(); |
| 578 | } |
| 579 | #endif |
| 580 | NfcTag::getInstance ().selectP2p(); |
| 581 | } |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 582 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 583 | else if(!sReaderModeEnabled && multiprotocol_flag) |
| 584 | { |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 585 | NfcTag::getInstance ().mNumDiscNtf = 0x00; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 586 | multiprotocol_flag = 0; |
| 587 | multiprotocol_detected = 1; |
| 588 | ALOGD("Prio_Logic_multiprotocol Logic"); |
| 589 | thread_ret = pthread_create(&multiprotocol_thread, NULL, p2p_prio_logic_multiprotocol, NULL); |
| 590 | if(thread_ret != 0) |
| 591 | ALOGD("unable to create the thread"); |
| 592 | ALOGD("Prio_Logic_multiprotocol start timer"); |
| 593 | multiprotocol_timer.set (300, reconfigure_poll_cb); |
| 594 | } |
| 595 | #endif |
| 596 | else |
| 597 | { |
| 598 | if (sReaderModeEnabled) |
| 599 | { |
| 600 | NfcTag::getInstance ().mNumDiscNtf = 0; |
| 601 | } |
| 602 | else |
| 603 | { |
| 604 | NfcTag::getInstance ().mNumDiscNtf--; |
| 605 | } |
| 606 | //select the first of multiple tags that is discovered |
| 607 | NfcTag::getInstance ().selectFirstTag(); |
| 608 | multiprotocol_flag = 1; |
| 609 | } |
| 610 | } |
| 611 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 612 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 613 | void *p2p_prio_logic_multiprotocol(void *arg) |
| 614 | { |
| 615 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 616 | tNFA_TECHNOLOGY_MASK tech_mask = 0; |
| 617 | |
| 618 | ALOGD ("%s ", __FUNCTION__); |
| 619 | |
| 620 | if (sRfEnabled) { |
| 621 | // Stop RF discovery to reconfigure |
| 622 | startRfDiscovery(false); |
| 623 | } |
| 624 | |
| 625 | { |
| 626 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 627 | status = NFA_DisablePolling (); |
| 628 | if (status == NFA_STATUS_OK) |
| 629 | { |
| 630 | sNfaEnableDisablePollingEvent.wait (); //wait for NFA_POLL_DISABLED_EVT |
| 631 | }else |
| 632 | ALOGE ("%s: Failed to disable polling; error=0x%X", __FUNCTION__, status); |
| 633 | } |
| 634 | |
| 635 | if(multiprotocol_detected) |
| 636 | { |
| 637 | ALOGD ("Enable Polling for TYPE F"); |
| 638 | tech_mask = NFA_TECHNOLOGY_MASK_F; |
| 639 | } |
| 640 | else |
| 641 | { |
| 642 | ALOGD ("Enable Polling for ALL"); |
| 643 | unsigned long num = 0; |
| 644 | if (GetNumValue(NAME_POLLING_TECH_MASK, &num, sizeof(num))) |
| 645 | tech_mask = num; |
| 646 | else |
| 647 | tech_mask = DEFAULT_TECH_MASK; |
| 648 | } |
| 649 | |
| 650 | { |
| 651 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 652 | status = NFA_EnablePolling (tech_mask); |
| 653 | if (status == NFA_STATUS_OK) |
| 654 | { |
| 655 | ALOGD ("%s: wait for enable event", __FUNCTION__); |
| 656 | sNfaEnableDisablePollingEvent.wait (); //wait for NFA_POLL_ENABLED_EVT |
| 657 | } |
| 658 | else |
| 659 | { |
| 660 | ALOGE ("%s: fail enable polling; error=0x%X", __FUNCTION__, status); |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | /* start polling */ |
| 665 | if (!sRfEnabled) |
| 666 | { |
| 667 | // Start RF discovery to reconfigure |
| 668 | startRfDiscovery(true); |
| 669 | } |
| 670 | return NULL; |
| 671 | } |
| 672 | |
| 673 | void reconfigure_poll_cb(union sigval) |
| 674 | { |
| 675 | ALOGD ("Prio_Logic_multiprotocol timer expire"); |
| 676 | ALOGD ("CallBack Reconfiguring the POLL to Default"); |
| 677 | clear_multiprotocol(); |
| 678 | multiprotocol_timer.set (300, multiprotocol_clear_flag); |
| 679 | } |
| 680 | |
| 681 | void clear_multiprotocol() |
| 682 | { |
| 683 | int thread_ret; |
| 684 | |
| 685 | ALOGD ("clear_multiprotocol"); |
| 686 | multiprotocol_detected = 0; |
| 687 | |
| 688 | thread_ret = pthread_create(&multiprotocol_thread, NULL, p2p_prio_logic_multiprotocol, NULL); |
| 689 | if(thread_ret != 0) |
| 690 | ALOGD("unable to create the thread"); |
| 691 | } |
| 692 | |
| 693 | void multiprotocol_clear_flag(union sigval) |
| 694 | { |
| 695 | ALOGD ("multiprotocol_clear_flag"); |
| 696 | multiprotocol_flag = 1; |
| 697 | } |
| 698 | #endif |
| 699 | |
| 700 | /******************************************************************************* |
| 701 | ** |
| 702 | ** Function: nfaConnectionCallback |
| 703 | ** |
| 704 | ** Description: Receive connection-related events from stack. |
| 705 | ** connEvent: Event code. |
| 706 | ** eventData: Event data. |
| 707 | ** |
| 708 | ** Returns: None |
| 709 | ** |
| 710 | *******************************************************************************/ |
| 711 | static void nfaConnectionCallback (UINT8 connEvent, tNFA_CONN_EVT_DATA* eventData) |
| 712 | { |
| 713 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 714 | static UINT8 prev_more_val = 0x00; |
| 715 | UINT8 cur_more_val=0x00; |
| 716 | ALOGD("%s: event= %u", __FUNCTION__, connEvent); |
| 717 | |
| 718 | switch (connEvent) |
| 719 | { |
| 720 | case NFA_POLL_ENABLED_EVT: // whether polling successfully started |
| 721 | { |
| 722 | ALOGD("%s: NFA_POLL_ENABLED_EVT: status = %u", __FUNCTION__, eventData->status); |
| 723 | |
| 724 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 725 | sNfaEnableDisablePollingEvent.notifyOne (); |
| 726 | } |
| 727 | break; |
| 728 | |
| 729 | case NFA_POLL_DISABLED_EVT: // Listening/Polling stopped |
| 730 | { |
| 731 | ALOGD("%s: NFA_POLL_DISABLED_EVT: status = %u", __FUNCTION__, eventData->status); |
| 732 | |
| 733 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 734 | sNfaEnableDisablePollingEvent.notifyOne (); |
| 735 | } |
| 736 | break; |
| 737 | |
| 738 | case NFA_RF_DISCOVERY_STARTED_EVT: // RF Discovery started |
| 739 | { |
| 740 | ALOGD("%s: NFA_RF_DISCOVERY_STARTED_EVT: status = %u", __FUNCTION__, eventData->status); |
| 741 | |
| 742 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 743 | sNfaEnableDisablePollingEvent.notifyOne (); |
| 744 | } |
| 745 | break; |
| 746 | |
| 747 | case NFA_RF_DISCOVERY_STOPPED_EVT: // RF Discovery stopped event |
| 748 | { |
| 749 | ALOGD("%s: NFA_RF_DISCOVERY_STOPPED_EVT: status = %u", __FUNCTION__, eventData->status); |
| 750 | notifyPollingEventwhileNfcOff(); |
| 751 | if (getReconnectState() == true) |
| 752 | { |
| 753 | eventData->deactivated.type = NFA_DEACTIVATE_TYPE_SLEEP; |
| 754 | NfcTag::getInstance().setDeactivationState (eventData->deactivated); |
| 755 | if (gIsTagDeactivating) |
| 756 | { |
| 757 | NfcTag::getInstance().setActive(false); |
| 758 | nativeNfcTag_doDeactivateStatus(0); |
| 759 | } |
| 760 | } |
| 761 | else |
| 762 | { |
| 763 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 764 | sNfaEnableDisablePollingEvent.notifyOne (); |
| 765 | } |
| 766 | } |
| 767 | break; |
| 768 | |
| 769 | case NFA_DISC_RESULT_EVT: // NFC link/protocol discovery notificaiton |
| 770 | status = eventData->disc_result.status; |
| 771 | cur_more_val = eventData->disc_result.discovery_ntf.more; |
| 772 | ALOGD("%s: NFA_DISC_RESULT_EVT: status = %d", __FUNCTION__, status); |
| 773 | if((cur_more_val == 0x01) && (prev_more_val != 0x02)) |
| 774 | { |
| 775 | ALOGE("NFA_DISC_RESULT_EVT failed"); |
| 776 | status = NFA_STATUS_FAILED; |
| 777 | }else |
| 778 | { |
| 779 | ALOGD("NFA_DISC_RESULT_EVT success"); |
| 780 | status = NFA_STATUS_OK; |
| 781 | prev_more_val = cur_more_val; |
| 782 | } |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 783 | #if(NXP_EXTNS == TRUE && NFC_NXP_NON_STD_CARD == TRUE) |
| 784 | if (gIsSelectingRfInterface) |
| 785 | { |
| 786 | ALOGE("reselect mechanism did not save the modification"); |
| 787 | if(cur_more_val == 0x00) |
| 788 | { |
| 789 | ALOGE("error case select any one tag"); |
| 790 | multiprotocol_flag = 0; |
| 791 | } |
| 792 | } |
| 793 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 794 | if (status != NFA_STATUS_OK) |
| 795 | { |
| 796 | NfcTag::getInstance ().mNumDiscNtf = 0; |
| 797 | ALOGE("%s: NFA_DISC_RESULT_EVT error: status = %d", __FUNCTION__, status); |
| 798 | } |
| 799 | else |
| 800 | { |
| 801 | NfcTag::getInstance().connectionEventHandler(connEvent, eventData); |
| 802 | handleRfDiscoveryEvent(&eventData->disc_result.discovery_ntf); |
| 803 | } |
| 804 | break; |
| 805 | |
| 806 | case NFA_SELECT_RESULT_EVT: // NFC link/protocol discovery select response |
| 807 | ALOGD("%s: NFA_SELECT_RESULT_EVT: status = %d, gIsSelectingRfInterface = %d, sIsDisabling=%d", __FUNCTION__, eventData->status, gIsSelectingRfInterface, sIsDisabling); |
| 808 | |
| 809 | if (sIsDisabling) |
| 810 | break; |
| 811 | |
| 812 | if (eventData->status != NFA_STATUS_OK) |
| 813 | { |
| 814 | if (gIsSelectingRfInterface) |
| 815 | { |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 816 | #if(NXP_EXTNS == TRUE && NFC_NXP_NON_STD_CARD == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 817 | nativeNfcTag_cacheNonNciCardDetection(); |
| 818 | #endif |
| 819 | nativeNfcTag_doConnectStatus(false); |
| 820 | } |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 821 | #if(NXP_EXTNS == TRUE) |
| 822 | NfcTag::getInstance().selectCompleteStatus(false); |
| 823 | NfcTag::getInstance ().mNumDiscNtf = 0x00; |
| 824 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 825 | NfcTag::getInstance().mTechListIndex = 0; |
| 826 | ALOGE("%s: NFA_SELECT_RESULT_EVT error: status = %d", __FUNCTION__, eventData->status); |
| 827 | NFA_Deactivate (FALSE); |
| 828 | } |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 829 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 830 | else if(sReaderModeEnabled && (gFelicaReaderState == STATE_DEACTIVATED_TO_SLEEP)) |
| 831 | { |
| 832 | SyncEventGuard g (sRespCbEvent); |
| 833 | ALOGD("%s: Sending Sem Post for Select Event", __FUNCTION__); |
| 834 | sRespCbEvent.notifyOne (); |
| 835 | gFelicaReaderState = STATE_FRAMERF_INTF_SELECTED; |
| 836 | ALOGD ("%s: FRM NFA_SELECT_RESULT_EVT", __FUNCTION__); |
| 837 | } |
| 838 | #endif |
| 839 | break; |
| 840 | |
| 841 | case NFA_DEACTIVATE_FAIL_EVT: |
| 842 | ALOGD("%s: NFA_DEACTIVATE_FAIL_EVT: status = %d", __FUNCTION__, eventData->status); |
| 843 | { |
| 844 | SyncEventGuard g (gDeactivatedEvent); |
| 845 | gActivated = false; |
| 846 | gDeactivatedEvent.notifyOne (); |
| 847 | } |
| 848 | { |
| 849 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 850 | sNfaEnableDisablePollingEvent.notifyOne (); |
| 851 | } |
| 852 | break; |
| 853 | |
| 854 | case NFA_ACTIVATED_EVT: // NFC link/protocol activated |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 855 | #if(NXP_EXTNS == TRUE) |
| 856 | rfActivation = true; |
| 857 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 858 | checkforTranscation(NFA_ACTIVATED_EVT, (void *)eventData); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 859 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 860 | ALOGD("%s: NFA_ACTIVATED_EVT: gIsSelectingRfInterface=%d, sIsDisabling=%d", __FUNCTION__, gIsSelectingRfInterface, sIsDisabling); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 861 | #if(NXP_EXTNS == TRUE) |
| 862 | NfcTag::getInstance().selectCompleteStatus(true); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 863 | if(eventData->activated.activate_ntf.intf_param.type==NFC_INTERFACE_EE_DIRECT_RF) |
| 864 | { |
| 865 | ALOGD("%s: NFA_ACTIVATED_EVT: gUICCVirtualWiredProtectMask=%d, gEseVirtualWiredProtectMask=%d", __FUNCTION__,gUICCVirtualWiredProtectMask, gEseVirtualWiredProtectMask); |
| 866 | if(gUICCVirtualWiredProtectMask != 0x00 || gEseVirtualWiredProtectMask != 0x00) |
| 867 | { |
| 868 | recovery=TRUE; |
| 869 | } |
| 870 | } |
| 871 | #endif |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 872 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 873 | /***P2P-Prio Logic for Multiprotocol***/ |
| 874 | if( (eventData->activated.activate_ntf.protocol == NFA_PROTOCOL_NFC_DEP) && (multiprotocol_detected == 1) ) |
| 875 | { |
| 876 | ALOGD("Prio_Logic_multiprotocol stop timer"); |
| 877 | multiprotocol_timer.kill(); |
| 878 | } |
| 879 | if( (eventData->activated.activate_ntf.protocol == NFA_PROTOCOL_T3T) && (multiprotocol_detected == 1) ) |
| 880 | { |
| 881 | ALOGD("Prio_Logic_multiprotocol stop timer"); |
| 882 | multiprotocol_timer.kill(); |
| 883 | clear_multiprotocol(); |
| 884 | } |
| 885 | #endif |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 886 | #if (NFC_NXP_ESE == TRUE && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 887 | /* |
| 888 | * Handle Reader over SWP START_READER_EVENT |
| 889 | * */ |
| 890 | if(eventData->activated.activate_ntf.intf_param.type == NCI_INTERFACE_UICC_DIRECT || eventData->activated.activate_ntf.intf_param.type == NCI_INTERFACE_ESE_DIRECT ) |
| 891 | { |
| 892 | SecureElement::getInstance().notifyEEReaderEvent(NFA_RD_SWP_READER_START, eventData->activated.activate_ntf.rf_tech_param.mode); |
| 893 | gReaderNotificationflag = true; |
| 894 | break; |
| 895 | } |
| 896 | #endif |
| 897 | if((eventData->activated.activate_ntf.protocol != NFA_PROTOCOL_NFC_DEP) && (!isListenMode(eventData->activated))) |
| 898 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 899 | nativeNfcTag_setRfInterface ((tNFA_INTF_TYPE) eventData->activated.activate_ntf.intf_param.type); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | if (EXTNS_GetConnectFlag() == TRUE) |
| 903 | { |
| 904 | NfcTag::getInstance().setActivationState (); |
| 905 | nativeNfcTag_doConnectStatus(true); |
| 906 | break; |
| 907 | } |
| 908 | NfcTag::getInstance().setActive(true); |
| 909 | if (sIsDisabling || !sIsNfaEnabled) |
| 910 | break; |
| 911 | gActivated = true; |
| 912 | |
| 913 | NfcTag::getInstance().setActivationState (); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 914 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 915 | if (gIsSelectingRfInterface) |
| 916 | { |
| 917 | nativeNfcTag_doConnectStatus(true); |
| 918 | if (NfcTag::getInstance ().isCashBeeActivated() == true || NfcTag::getInstance ().isEzLinkTagActivated() == true) |
| 919 | { |
| 920 | NfcTag::getInstance().connectionEventHandler (NFA_ACTIVATED_UPDATE_EVT, eventData); |
| 921 | } |
| 922 | break; |
| 923 | } |
| 924 | |
| 925 | nativeNfcTag_resetPresenceCheck(); |
| 926 | if (isPeerToPeer(eventData->activated)) |
| 927 | { |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 928 | if (sReaderModeEnabled) |
| 929 | { |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 930 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 931 | /*if last transaction is complete or prev state is Idle |
| 932 | *then proceed to nxt state*/ |
| 933 | if((gFelicaReaderState == STATE_IDLE) || |
| 934 | (gFelicaReaderState == STATE_FRAMERF_INTF_SELECTED)) |
| 935 | { |
| 936 | ALOGD("%s: Activating Reader Mode in P2P ", __FUNCTION__); |
| 937 | gFelicaReaderState = STATE_NFCDEP_ACTIVATED_NFCDEP_INTF; |
| 938 | switchP2PToT3TRead(eventData->activated.activate_ntf.rf_disc_id); |
| 939 | } |
| 940 | else |
| 941 | { |
| 942 | ALOGD("%s: Invalid FelicaReaderState : %d ", __FUNCTION__,gFelicaReaderState); |
| 943 | gFelicaReaderState = STATE_IDLE; |
| 944 | #endif |
| 945 | ALOGD("%s: ignoring peer target in reader mode.", __FUNCTION__); |
| 946 | NFA_Deactivate (FALSE); |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 947 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 948 | } |
| 949 | #endif |
| 950 | break; |
| 951 | } |
| 952 | sP2pActive = true; |
| 953 | ALOGD("%s: NFA_ACTIVATED_EVT; is p2p", __FUNCTION__); |
| 954 | // Disable RF field events in case of p2p |
| 955 | // UINT8 nfa_disable_rf_events[] = { 0x00 }; /*commented to eliminate unused variable warning*/ |
| 956 | ALOGD ("%s: Disabling RF field events", __FUNCTION__); |
| 957 | #if 0 |
| 958 | status = NFA_SetConfig(NCI_PARAM_ID_RF_FIELD_INFO, sizeof(nfa_disable_rf_events), |
| 959 | &nfa_disable_rf_events[0]); |
| 960 | if (status == NFA_STATUS_OK) { |
| 961 | ALOGD ("%s: Disabled RF field events", __FUNCTION__); |
| 962 | } else { |
| 963 | ALOGE ("%s: Failed to disable RF field events", __FUNCTION__); |
| 964 | } |
| 965 | #endif |
| 966 | // For the SE, consider the field to be on while p2p is active. |
| 967 | SecureElement::getInstance().notifyRfFieldEvent (true); |
| 968 | } |
| 969 | else if (pn544InteropIsBusy() == false) |
| 970 | { |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 971 | #if(NXP_EXTNS == TRUE && NFC_NXP_NON_STD_CARD == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 972 | nativeNfcTag_handleNonNciMultiCardDetection(connEvent, eventData); |
| 973 | ALOGD("%s: scoreGenericNtf = 0x%x", __FUNCTION__ ,scoreGenericNtf); |
| 974 | if(scoreGenericNtf == true) |
| 975 | { |
| 976 | if( (eventData->activated.activate_ntf.intf_param.type == NFC_INTERFACE_ISO_DEP) && (eventData->activated.activate_ntf.protocol == NFC_PROTOCOL_ISO_DEP) ) |
| 977 | { |
| 978 | nativeNfcTag_handleNonNciCardDetection(eventData); |
| 979 | } |
| 980 | scoreGenericNtf = false; |
| 981 | } |
| 982 | |
| 983 | #else |
| 984 | NfcTag::getInstance().connectionEventHandler (connEvent, eventData); |
| 985 | if(NfcTag::getInstance ().mNumDiscNtf) |
| 986 | { |
| 987 | NFA_Deactivate (TRUE); |
| 988 | } |
| 989 | #endif |
| 990 | |
| 991 | // We know it is not activating for P2P. If it activated in |
| 992 | // listen mode then it is likely for an SE transaction. |
| 993 | // Send the RF Event. |
| 994 | if (isListenMode(eventData->activated)) |
| 995 | { |
| 996 | sSeRfActive = true; |
| 997 | SecureElement::getInstance().notifyListenModeState (true); |
| 998 | } |
| 999 | } |
| 1000 | break; |
| 1001 | |
| 1002 | case NFA_DEACTIVATED_EVT: // NFC link/protocol deactivated |
| 1003 | ALOGD("%s: NFA_DEACTIVATED_EVT Type: %u, gIsTagDeactivating: %d", __FUNCTION__, eventData->deactivated.type,gIsTagDeactivating); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1004 | #if(NXP_EXTNS == TRUE) |
| 1005 | rfActivation = false; |
| 1006 | #endif |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 1007 | #if(NFC_NXP_CHIP_TYPE == PN547C2 && NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1008 | if(eventData->deactivated.type == NFA_DEACTIVATE_TYPE_IDLE) |
| 1009 | { |
| 1010 | checkforTranscation(NFA_DEACTIVATED_EVT, (void *)eventData); |
| 1011 | } |
| 1012 | #endif |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 1013 | #if(NXP_EXTNS == TRUE && NFC_NXP_NON_STD_CARD == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1014 | if(checkCmdSent == 1 && eventData->deactivated.type == 0) |
| 1015 | { |
| 1016 | ALOGD("%s: NFA_DEACTIVATED_EVT setting check flag to one", __FUNCTION__); |
| 1017 | checkTagNtf = 1; |
| 1018 | } |
| 1019 | #endif |
| 1020 | notifyPollingEventwhileNfcOff(); |
| 1021 | if (true == getReconnectState()) |
| 1022 | { |
| 1023 | ALOGD("Reconnect in progress : Do nothing"); |
| 1024 | break; |
| 1025 | } |
| 1026 | gReaderNotificationflag = false; |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 1027 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1028 | /***P2P-Prio Logic for Multiprotocol***/ |
| 1029 | if( (multiprotocol_detected == 1) && (sP2pActive == 1) ) |
| 1030 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1031 | NfcTag::getInstance ().mNumDiscNtf = 0;//reset if any notifications are not cleared |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1032 | clear_multiprotocol(); |
| 1033 | multiprotocol_flag = 1; |
| 1034 | } |
| 1035 | #endif |
| 1036 | NfcTag::getInstance().setDeactivationState (eventData->deactivated); |
| 1037 | if(NfcTag::getInstance ().mNumDiscNtf) |
| 1038 | { |
| 1039 | NfcTag::getInstance ().mNumDiscNtf--; |
| 1040 | NfcTag::getInstance().selectNextTag(); |
| 1041 | } |
| 1042 | if (eventData->deactivated.type != NFA_DEACTIVATE_TYPE_SLEEP) |
| 1043 | { |
| 1044 | { |
| 1045 | SyncEventGuard g (gDeactivatedEvent); |
| 1046 | gActivated = false; //guard this variable from multi-threaded access |
| 1047 | gDeactivatedEvent.notifyOne (); |
| 1048 | } |
| 1049 | NfcTag::getInstance ().mNumDiscNtf = 0; |
| 1050 | NfcTag::getInstance ().mTechListIndex =0; |
| 1051 | nativeNfcTag_resetPresenceCheck(); |
| 1052 | NfcTag::getInstance().connectionEventHandler (connEvent, eventData); |
| 1053 | nativeNfcTag_abortWaits(); |
| 1054 | NfcTag::getInstance().abort (); |
| 1055 | } |
| 1056 | else if (gIsTagDeactivating) |
| 1057 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1058 | NfcTag::getInstance ().setActive (false); |
| 1059 | nativeNfcTag_doDeactivateStatus (0); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1060 | } |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1061 | else if (EXTNS_GetDeactivateFlag () == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1062 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1063 | NfcTag::getInstance ().setActive (false); |
| 1064 | nativeNfcTag_doDeactivateStatus (0); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | // If RF is activated for what we think is a Secure Element transaction |
| 1068 | // and it is deactivated to either IDLE or DISCOVERY mode, notify w/event. |
| 1069 | if ((eventData->deactivated.type == NFA_DEACTIVATE_TYPE_IDLE) |
| 1070 | || (eventData->deactivated.type == NFA_DEACTIVATE_TYPE_DISCOVERY)) |
| 1071 | { |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 1072 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1073 | if(RoutingManager::getInstance().is_ee_recovery_ongoing()) |
| 1074 | { |
| 1075 | recovery=FALSE; |
| 1076 | SyncEventGuard guard (SecureElement::getInstance().mEEdatapacketEvent); |
| 1077 | SecureElement::getInstance().mEEdatapacketEvent.notifyOne(); |
| 1078 | } |
| 1079 | #endif |
| 1080 | if (sSeRfActive) { |
| 1081 | sSeRfActive = false; |
| 1082 | if (!sIsDisabling && sIsNfaEnabled) |
| 1083 | SecureElement::getInstance().notifyListenModeState (false); |
| 1084 | } else if (sP2pActive) { |
| 1085 | sP2pActive = false; |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 1086 | SecureElement::getInstance().notifyRfFieldEvent (false); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1087 | // Make sure RF field events are re-enabled |
| 1088 | ALOGD("%s: NFA_DEACTIVATED_EVT; is p2p", __FUNCTION__); |
| 1089 | // Disable RF field events in case of p2p |
| 1090 | // UINT8 nfa_enable_rf_events[] = { 0x01 }; /*commented to eliminate unused variable warning*/ |
| 1091 | /* |
| 1092 | if (!sIsDisabling && sIsNfaEnabled) |
| 1093 | { |
| 1094 | ALOGD ("%s: Enabling RF field events", __FUNCTION__); |
| 1095 | status = NFA_SetConfig(NCI_PARAM_ID_RF_FIELD_INFO, sizeof(nfa_enable_rf_events), |
| 1096 | &nfa_enable_rf_events[0]); |
| 1097 | if (status == NFA_STATUS_OK) { |
| 1098 | ALOGD ("%s: Enabled RF field events", __FUNCTION__); |
| 1099 | } else { |
| 1100 | ALOGE ("%s: Failed to enable RF field events", __FUNCTION__); |
| 1101 | } |
| 1102 | // Consider the field to be off at this point |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1103 | } |
| 1104 | */ |
| 1105 | } |
| 1106 | } |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 1107 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1108 | if (sReaderModeEnabled && (eventData->deactivated.type == NFA_DEACTIVATE_TYPE_SLEEP)) |
| 1109 | { |
| 1110 | if(gFelicaReaderState == STATE_NFCDEP_ACTIVATED_NFCDEP_INTF) |
| 1111 | { |
| 1112 | SyncEventGuard g (sRespCbEvent); |
| 1113 | ALOGD("%s: Sending Sem Post for Deactivated", __FUNCTION__); |
| 1114 | sRespCbEvent.notifyOne (); |
| 1115 | ALOGD("Switching to T3T\n"); |
| 1116 | gFelicaReaderState = STATE_DEACTIVATED_TO_SLEEP; |
| 1117 | } |
| 1118 | else |
| 1119 | { |
| 1120 | ALOGD("%s: FelicaReaderState Invalid", __FUNCTION__); |
| 1121 | gFelicaReaderState = STATE_IDLE; |
| 1122 | } |
| 1123 | } |
| 1124 | #endif |
| 1125 | break; |
| 1126 | |
| 1127 | case NFA_TLV_DETECT_EVT: // TLV Detection complete |
| 1128 | status = eventData->tlv_detect.status; |
| 1129 | ALOGD("%s: NFA_TLV_DETECT_EVT: status = %d, protocol = %d, num_tlvs = %d, num_bytes = %d", |
| 1130 | __FUNCTION__, status, eventData->tlv_detect.protocol, |
| 1131 | eventData->tlv_detect.num_tlvs, eventData->tlv_detect.num_bytes); |
| 1132 | if (status != NFA_STATUS_OK) |
| 1133 | { |
| 1134 | ALOGE("%s: NFA_TLV_DETECT_EVT error: status = %d", __FUNCTION__, status); |
| 1135 | } |
| 1136 | break; |
| 1137 | |
| 1138 | case NFA_NDEF_DETECT_EVT: // NDEF Detection complete; |
| 1139 | //if status is failure, it means the tag does not contain any or valid NDEF data; |
| 1140 | //pass the failure status to the NFC Service; |
| 1141 | status = eventData->ndef_detect.status; |
| 1142 | ALOGD("%s: NFA_NDEF_DETECT_EVT: status = 0x%X, protocol = %u, " |
| 1143 | "max_size = %lu, cur_size = %lu, flags = 0x%X", __FUNCTION__, |
| 1144 | status, |
| 1145 | eventData->ndef_detect.protocol, eventData->ndef_detect.max_size, |
| 1146 | eventData->ndef_detect.cur_size, eventData->ndef_detect.flags); |
| 1147 | NfcTag::getInstance().connectionEventHandler (connEvent, eventData); |
| 1148 | nativeNfcTag_doCheckNdefResult(status, |
| 1149 | eventData->ndef_detect.max_size, eventData->ndef_detect.cur_size, |
| 1150 | eventData->ndef_detect.flags); |
| 1151 | break; |
| 1152 | |
| 1153 | case NFA_DATA_EVT: // Data message received (for non-NDEF reads) |
| 1154 | ALOGD("%s: NFA_DATA_EVT: status = 0x%X, len = %d", __FUNCTION__, eventData->status, eventData->data.len); |
| 1155 | nativeNfcTag_doTransceiveStatus(eventData->status, eventData->data.p_data, eventData->data.len); |
| 1156 | break; |
| 1157 | case NFA_RW_INTF_ERROR_EVT: |
| 1158 | ALOGD("%s: NFC_RW_INTF_ERROR_EVT", __FUNCTION__); |
| 1159 | nativeNfcTag_notifyRfTimeout(); |
| 1160 | nativeNfcTag_doReadCompleted (NFA_STATUS_TIMEOUT); |
| 1161 | break; |
| 1162 | case NFA_SELECT_CPLT_EVT: // Select completed |
| 1163 | status = eventData->status; |
| 1164 | ALOGD("%s: NFA_SELECT_CPLT_EVT: status = %d", __FUNCTION__, status); |
| 1165 | if (status != NFA_STATUS_OK) |
| 1166 | { |
| 1167 | ALOGE("%s: NFA_SELECT_CPLT_EVT error: status = %d", __FUNCTION__, status); |
| 1168 | } |
| 1169 | break; |
| 1170 | |
| 1171 | case NFA_READ_CPLT_EVT: // NDEF-read or tag-specific-read completed |
| 1172 | ALOGD("%s: NFA_READ_CPLT_EVT: status = 0x%X", __FUNCTION__, eventData->status); |
| 1173 | nativeNfcTag_doReadCompleted (eventData->status); |
| 1174 | NfcTag::getInstance().connectionEventHandler (connEvent, eventData); |
| 1175 | break; |
| 1176 | |
| 1177 | case NFA_WRITE_CPLT_EVT: // Write completed |
| 1178 | ALOGD("%s: NFA_WRITE_CPLT_EVT: status = %d", __FUNCTION__, eventData->status); |
| 1179 | nativeNfcTag_doWriteStatus (eventData->status == NFA_STATUS_OK); |
| 1180 | break; |
| 1181 | |
| 1182 | case NFA_SET_TAG_RO_EVT: // Tag set as Read only |
| 1183 | ALOGD("%s: NFA_SET_TAG_RO_EVT: status = %d", __FUNCTION__, eventData->status); |
| 1184 | nativeNfcTag_doMakeReadonlyResult(eventData->status); |
| 1185 | break; |
| 1186 | |
| 1187 | case NFA_CE_NDEF_WRITE_START_EVT: // NDEF write started |
| 1188 | ALOGD("%s: NFA_CE_NDEF_WRITE_START_EVT: status: %d", __FUNCTION__, eventData->status); |
| 1189 | |
| 1190 | if (eventData->status != NFA_STATUS_OK) |
| 1191 | ALOGE("%s: NFA_CE_NDEF_WRITE_START_EVT error: status = %d", __FUNCTION__, eventData->status); |
| 1192 | break; |
| 1193 | |
| 1194 | case NFA_CE_NDEF_WRITE_CPLT_EVT: // NDEF write completed |
| 1195 | ALOGD("%s: FA_CE_NDEF_WRITE_CPLT_EVT: len = %lu", __FUNCTION__, eventData->ndef_write_cplt.len); |
| 1196 | break; |
| 1197 | |
| 1198 | case NFA_LLCP_ACTIVATED_EVT: // LLCP link is activated |
| 1199 | ALOGD("%s: NFA_LLCP_ACTIVATED_EVT: is_initiator: %d remote_wks: %d, remote_lsc: %d, remote_link_miu: %d, local_link_miu: %d", |
| 1200 | __FUNCTION__, |
| 1201 | eventData->llcp_activated.is_initiator, |
| 1202 | eventData->llcp_activated.remote_wks, |
| 1203 | eventData->llcp_activated.remote_lsc, |
| 1204 | eventData->llcp_activated.remote_link_miu, |
| 1205 | eventData->llcp_activated.local_link_miu); |
| 1206 | |
| 1207 | PeerToPeer::getInstance().llcpActivatedHandler (getNative(0, 0), eventData->llcp_activated); |
| 1208 | break; |
| 1209 | |
| 1210 | case NFA_LLCP_DEACTIVATED_EVT: // LLCP link is deactivated |
| 1211 | ALOGD("%s: NFA_LLCP_DEACTIVATED_EVT", __FUNCTION__); |
| 1212 | PeerToPeer::getInstance().llcpDeactivatedHandler (getNative(0, 0), eventData->llcp_deactivated); |
| 1213 | break; |
| 1214 | case NFA_LLCP_FIRST_PACKET_RECEIVED_EVT: // Received first packet over llcp |
| 1215 | ALOGD("%s: NFA_LLCP_FIRST_PACKET_RECEIVED_EVT", __FUNCTION__); |
| 1216 | PeerToPeer::getInstance().llcpFirstPacketHandler (getNative(0, 0)); |
| 1217 | break; |
| 1218 | case NFA_PRESENCE_CHECK_EVT: |
| 1219 | ALOGD("%s: NFA_PRESENCE_CHECK_EVT", __FUNCTION__); |
| 1220 | nativeNfcTag_doPresenceCheckResult (eventData->status); |
| 1221 | break; |
| 1222 | case NFA_FORMAT_CPLT_EVT: |
| 1223 | ALOGD("%s: NFA_FORMAT_CPLT_EVT: status=0x%X", __FUNCTION__, eventData->status); |
| 1224 | nativeNfcTag_formatStatus (eventData->status == NFA_STATUS_OK); |
| 1225 | break; |
| 1226 | |
| 1227 | case NFA_I93_CMD_CPLT_EVT: |
| 1228 | ALOGD("%s: NFA_I93_CMD_CPLT_EVT: status=0x%X", __FUNCTION__, eventData->status); |
| 1229 | break; |
| 1230 | |
| 1231 | case NFA_CE_UICC_LISTEN_CONFIGURED_EVT : |
| 1232 | ALOGD("%s: NFA_CE_UICC_LISTEN_CONFIGURED_EVT : status=0x%X", __FUNCTION__, eventData->status); |
| 1233 | SecureElement::getInstance().connectionEventHandler (connEvent, eventData); |
| 1234 | break; |
| 1235 | |
| 1236 | case NFA_CE_ESE_LISTEN_CONFIGURED_EVT : |
| 1237 | ALOGD("%s: NFA_CE_ESE_LISTEN_CONFIGURED_EVT : status=0x%X", __FUNCTION__, eventData->status); |
| 1238 | SecureElement::getInstance().connectionEventHandler (connEvent, eventData); |
| 1239 | break; |
| 1240 | |
| 1241 | case NFA_SET_P2P_LISTEN_TECH_EVT: |
| 1242 | ALOGD("%s: NFA_SET_P2P_LISTEN_TECH_EVT", __FUNCTION__); |
| 1243 | PeerToPeer::getInstance().connectionEventHandler (connEvent, eventData); |
| 1244 | break; |
| 1245 | case NFA_CE_LOCAL_TAG_CONFIGURED_EVT: |
| 1246 | ALOGD("%s: NFA_CE_LOCAL_TAG_CONFIGURED_EVT", __FUNCTION__); |
| 1247 | break; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1248 | #if(NFC_NXP_ESE == TRUE && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1249 | case NFA_RECOVERY_EVT: |
| 1250 | ALOGD("%s: NFA_RECOVERY_EVT", __FUNCTION__); |
| 1251 | ALOGD("%s: Discovery Started in lower layer : Updating status in JNI", __FUNCTION__); |
| 1252 | if(RoutingManager::getInstance().getEtsiReaederState() == STATE_SE_RDR_MODE_STOP_IN_PROGRESS) |
| 1253 | { |
| 1254 | ALOGD("%s: Reset the Etsi Reader State to STATE_SE_RDR_MODE_STOPPED", __FUNCTION__); |
| 1255 | |
| 1256 | RoutingManager::getInstance().setEtsiReaederState(STATE_SE_RDR_MODE_STOPPED); |
| 1257 | } |
| 1258 | |
| 1259 | break; |
| 1260 | #endif |
| 1261 | default: |
| 1262 | ALOGE("%s: unknown event ????", __FUNCTION__); |
| 1263 | break; |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | |
| 1268 | /******************************************************************************* |
| 1269 | ** |
| 1270 | ** Function: nfcManager_initNativeStruc |
| 1271 | ** |
| 1272 | ** Description: Initialize variables. |
| 1273 | ** e: JVM environment. |
| 1274 | ** o: Java object. |
| 1275 | ** |
| 1276 | ** Returns: True if ok. |
| 1277 | ** |
| 1278 | *******************************************************************************/ |
| 1279 | static jboolean nfcManager_initNativeStruc (JNIEnv* e, jobject o) |
| 1280 | { |
| 1281 | ALOGD ("%s: enter", __FUNCTION__); |
| 1282 | |
| 1283 | nfc_jni_native_data* nat = (nfc_jni_native_data*)malloc(sizeof(struct nfc_jni_native_data)); |
| 1284 | if (nat == NULL) |
| 1285 | { |
| 1286 | ALOGE ("%s: fail allocate native data", __FUNCTION__); |
| 1287 | return JNI_FALSE; |
| 1288 | } |
| 1289 | |
| 1290 | memset (nat, 0, sizeof(*nat)); |
| 1291 | e->GetJavaVM(&(nat->vm)); |
| 1292 | nat->env_version = e->GetVersion(); |
| 1293 | nat->manager = e->NewGlobalRef(o); |
| 1294 | |
| 1295 | ScopedLocalRef<jclass> cls(e, e->GetObjectClass(o)); |
| 1296 | jfieldID f = e->GetFieldID(cls.get(), "mNative", "J"); |
| 1297 | e->SetLongField(o, f, (jlong)nat); |
| 1298 | |
| 1299 | /* Initialize native cached references */ |
| 1300 | gCachedNfcManagerNotifyNdefMessageListeners = e->GetMethodID(cls.get(), |
| 1301 | "notifyNdefMessageListeners", "(Lcom/android/nfc/dhimpl/NativeNfcTag;)V"); |
| 1302 | gCachedNfcManagerNotifyTransactionListeners = e->GetMethodID(cls.get(), |
| 1303 | "notifyTransactionListeners", "([B[BI)V"); |
| 1304 | gCachedNfcManagerNotifyConnectivityListeners = e->GetMethodID(cls.get(), |
| 1305 | "notifyConnectivityListeners", "(I)V"); |
| 1306 | gCachedNfcManagerNotifyEmvcoMultiCardDetectedListeners = e->GetMethodID(cls.get(), |
| 1307 | "notifyEmvcoMultiCardDetectedListeners", "()V"); |
| 1308 | gCachedNfcManagerNotifyLlcpLinkActivation = e->GetMethodID(cls.get(), |
| 1309 | "notifyLlcpLinkActivation", "(Lcom/android/nfc/dhimpl/NativeP2pDevice;)V"); |
| 1310 | gCachedNfcManagerNotifyLlcpLinkDeactivated = e->GetMethodID(cls.get(), |
| 1311 | "notifyLlcpLinkDeactivated", "(Lcom/android/nfc/dhimpl/NativeP2pDevice;)V"); |
| 1312 | gCachedNfcManagerNotifyLlcpFirstPacketReceived = e->GetMethodID(cls.get(), |
| 1313 | "notifyLlcpLinkFirstPacketReceived", "(Lcom/android/nfc/dhimpl/NativeP2pDevice;)V"); |
| 1314 | sCachedNfcManagerNotifyTargetDeselected = e->GetMethodID(cls.get(), |
| 1315 | "notifyTargetDeselected","()V"); |
| 1316 | gCachedNfcManagerNotifySeFieldActivated = e->GetMethodID(cls.get(), |
| 1317 | "notifySeFieldActivated", "()V"); |
| 1318 | gCachedNfcManagerNotifySeFieldDeactivated = e->GetMethodID(cls.get(), |
| 1319 | "notifySeFieldDeactivated", "()V"); |
| 1320 | gCachedNfcManagerNotifySeListenActivated = e->GetMethodID(cls.get(), |
| 1321 | "notifySeListenActivated", "()V"); |
| 1322 | gCachedNfcManagerNotifySeListenDeactivated = e->GetMethodID(cls.get(), |
| 1323 | "notifySeListenDeactivated", "()V"); |
| 1324 | |
| 1325 | gCachedNfcManagerNotifyHostEmuActivated = e->GetMethodID(cls.get(), |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1326 | "notifyHostEmuActivated", "(I)V"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1327 | |
| 1328 | gCachedNfcManagerNotifyAidRoutingTableFull = e->GetMethodID(cls.get(), |
| 1329 | "notifyAidRoutingTableFull", "()V"); |
| 1330 | |
| 1331 | gCachedNfcManagerNotifyHostEmuData = e->GetMethodID(cls.get(), |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1332 | "notifyHostEmuData", "(I[B)V"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1333 | |
| 1334 | gCachedNfcManagerNotifyHostEmuDeactivated = e->GetMethodID(cls.get(), |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1335 | "notifyHostEmuDeactivated", "(I)V"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1336 | |
| 1337 | gCachedNfcManagerNotifyRfFieldActivated = e->GetMethodID(cls.get(), |
| 1338 | "notifyRfFieldActivated", "()V"); |
| 1339 | gCachedNfcManagerNotifyRfFieldDeactivated = e->GetMethodID(cls.get(), |
| 1340 | "notifyRfFieldDeactivated", "()V"); |
| 1341 | |
| 1342 | sCachedNfcManagerNotifySeApduReceived = e->GetMethodID(cls.get(), |
| 1343 | "notifySeApduReceived", "([B)V"); |
| 1344 | |
| 1345 | sCachedNfcManagerNotifySeMifareAccess = e->GetMethodID(cls.get(), |
| 1346 | "notifySeMifareAccess", "([B)V"); |
| 1347 | |
| 1348 | sCachedNfcManagerNotifySeEmvCardRemoval = e->GetMethodID(cls.get(), |
| 1349 | "notifySeEmvCardRemoval", "()V"); |
| 1350 | |
| 1351 | gCachedNfcManagerNotifySWPReaderRequested = e->GetMethodID (cls.get(), |
| 1352 | "notifySWPReaderRequested", "(ZZ)V"); |
| 1353 | |
| 1354 | gCachedNfcManagerNotifySWPReaderRequestedFail= e->GetMethodID (cls.get(), |
| 1355 | "notifySWPReaderRequestedFail", "(I)V"); |
| 1356 | |
| 1357 | |
| 1358 | gCachedNfcManagerNotifySWPReaderActivated = e->GetMethodID (cls.get(), |
| 1359 | "notifySWPReaderActivated", "()V"); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1360 | #if(NFC_NXP_ESE == TRUE && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1361 | gCachedNfcManagerNotifyETSIReaderModeStartConfig = e->GetMethodID (cls.get(), |
| 1362 | "notifyonETSIReaderModeStartConfig", "(I)V"); |
| 1363 | |
| 1364 | gCachedNfcManagerNotifyETSIReaderModeStopConfig = e->GetMethodID (cls.get(), |
| 1365 | "notifyonETSIReaderModeStopConfig", "(I)V"); |
| 1366 | |
| 1367 | gCachedNfcManagerNotifyETSIReaderModeSwpTimeout = e->GetMethodID (cls.get(), |
| 1368 | "notifyonETSIReaderModeSwpTimeout", "(I)V"); |
| 1369 | #endif |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1370 | #if((NXP_EXTNS == TRUE) && (NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE)) |
| 1371 | gCachedNfcManagerNotifyUiccStatusEvent= e->GetMethodID (cls.get(), |
| 1372 | "notifyUiccStatusEvent", "(I)V"); |
| 1373 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1374 | if (nfc_jni_cache_object(e, gNativeNfcTagClassName, &(nat->cached_NfcTag)) == -1) |
| 1375 | { |
| 1376 | ALOGE ("%s: fail cache NativeNfcTag", __FUNCTION__); |
| 1377 | return JNI_FALSE; |
| 1378 | } |
| 1379 | |
| 1380 | if (nfc_jni_cache_object(e, gNativeP2pDeviceClassName, &(nat->cached_P2pDevice)) == -1) |
| 1381 | { |
| 1382 | ALOGE ("%s: fail cache NativeP2pDevice", __FUNCTION__); |
| 1383 | return JNI_FALSE; |
| 1384 | } |
| 1385 | |
| 1386 | ALOGD ("%s: exit", __FUNCTION__); |
| 1387 | return JNI_TRUE; |
| 1388 | } |
| 1389 | |
| 1390 | |
| 1391 | /******************************************************************************* |
| 1392 | ** |
| 1393 | ** Function: nfaDeviceManagementCallback |
| 1394 | ** |
| 1395 | ** Description: Receive device management events from stack. |
| 1396 | ** dmEvent: Device-management event ID. |
| 1397 | ** eventData: Data associated with event ID. |
| 1398 | ** |
| 1399 | ** Returns: None |
| 1400 | ** |
| 1401 | *******************************************************************************/ |
| 1402 | void nfaDeviceManagementCallback (UINT8 dmEvent, tNFA_DM_CBACK_DATA* eventData) |
| 1403 | { |
| 1404 | ALOGD ("%s: enter; event=0x%X", __FUNCTION__, dmEvent); |
| 1405 | |
| 1406 | switch (dmEvent) |
| 1407 | { |
| 1408 | case NFA_DM_ENABLE_EVT: /* Result of NFA_Enable */ |
| 1409 | { |
| 1410 | SyncEventGuard guard (sNfaEnableEvent); |
| 1411 | ALOGD ("%s: NFA_DM_ENABLE_EVT; status=0x%X", |
| 1412 | __FUNCTION__, eventData->status); |
| 1413 | sIsNfaEnabled = eventData->status == NFA_STATUS_OK; |
| 1414 | sIsDisabling = false; |
| 1415 | sNfaEnableEvent.notifyOne (); |
| 1416 | } |
| 1417 | break; |
| 1418 | |
| 1419 | case NFA_DM_DISABLE_EVT: /* Result of NFA_Disable */ |
| 1420 | { |
| 1421 | SyncEventGuard guard (sNfaDisableEvent); |
| 1422 | ALOGD ("%s: NFA_DM_DISABLE_EVT", __FUNCTION__); |
| 1423 | sIsNfaEnabled = false; |
| 1424 | sIsDisabling = false; |
| 1425 | sNfaDisableEvent.notifyOne (); |
| 1426 | } |
| 1427 | break; |
| 1428 | |
| 1429 | case NFA_DM_SET_CONFIG_EVT: //result of NFA_SetConfig |
| 1430 | ALOGD ("%s: NFA_DM_SET_CONFIG_EVT", __FUNCTION__); |
| 1431 | { |
| 1432 | SyncEventGuard guard (sNfaSetConfigEvent); |
| 1433 | sNfaSetConfigEvent.notifyOne(); |
| 1434 | } |
| 1435 | break; |
| 1436 | |
| 1437 | case NFA_DM_GET_CONFIG_EVT: /* Result of NFA_GetConfig */ |
| 1438 | ALOGD ("%s: NFA_DM_GET_CONFIG_EVT", __FUNCTION__); |
| 1439 | { |
| 1440 | HciRFParams::getInstance().connectionEventHandler(dmEvent,eventData); |
| 1441 | SyncEventGuard guard (sNfaGetConfigEvent); |
| 1442 | if (eventData->status == NFA_STATUS_OK && |
| 1443 | eventData->get_config.tlv_size <= sizeof(sConfig)) |
| 1444 | { |
| 1445 | sCurrentConfigLen = eventData->get_config.tlv_size; |
| 1446 | memcpy(sConfig, eventData->get_config.param_tlvs, eventData->get_config.tlv_size); |
| 1447 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 1448 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1449 | if(sCheckNfceeFlag) |
| 1450 | checkforNfceeBuffer(); |
| 1451 | #endif |
| 1452 | } |
| 1453 | else |
| 1454 | { |
| 1455 | ALOGE("%s: NFA_DM_GET_CONFIG failed", __FUNCTION__); |
| 1456 | sCurrentConfigLen = 0; |
| 1457 | } |
| 1458 | sNfaGetConfigEvent.notifyOne(); |
| 1459 | } |
| 1460 | break; |
| 1461 | |
| 1462 | case NFA_DM_RF_FIELD_EVT: |
| 1463 | checkforTranscation(NFA_TRANS_DM_RF_FIELD_EVT, (void *)eventData); |
| 1464 | ALOGD ("%s: NFA_DM_RF_FIELD_EVT; status=0x%X; field status=%u", __FUNCTION__, |
| 1465 | eventData->rf_field.status, eventData->rf_field.rf_field_status); |
| 1466 | if (sIsDisabling || !sIsNfaEnabled) |
| 1467 | break; |
| 1468 | |
| 1469 | if (!sP2pActive && eventData->rf_field.status == NFA_STATUS_OK) |
| 1470 | { |
| 1471 | SecureElement::getInstance().notifyRfFieldEvent ( |
| 1472 | eventData->rf_field.rf_field_status == NFA_DM_RF_FIELD_ON); |
| 1473 | struct nfc_jni_native_data *nat = getNative(NULL, NULL); |
| 1474 | JNIEnv* e = NULL; |
| 1475 | ScopedAttach attach(nat->vm, &e); |
| 1476 | if (e == NULL) |
| 1477 | { |
| 1478 | ALOGE ("jni env is null"); |
| 1479 | return; |
| 1480 | } |
| 1481 | if (eventData->rf_field.rf_field_status == NFA_DM_RF_FIELD_ON) |
| 1482 | e->CallVoidMethod (nat->manager, android::gCachedNfcManagerNotifyRfFieldActivated); |
| 1483 | else |
| 1484 | e->CallVoidMethod (nat->manager, android::gCachedNfcManagerNotifyRfFieldDeactivated); |
| 1485 | } |
| 1486 | break; |
| 1487 | |
| 1488 | case NFA_DM_NFCC_TRANSPORT_ERR_EVT: |
| 1489 | case NFA_DM_NFCC_TIMEOUT_EVT: |
| 1490 | { |
| 1491 | if (dmEvent == NFA_DM_NFCC_TIMEOUT_EVT) |
| 1492 | ALOGE ("%s: NFA_DM_NFCC_TIMEOUT_EVT; abort", __FUNCTION__); |
| 1493 | else if (dmEvent == NFA_DM_NFCC_TRANSPORT_ERR_EVT) |
| 1494 | ALOGE ("%s: NFA_DM_NFCC_TRANSPORT_ERR_EVT; abort", __FUNCTION__); |
| 1495 | NFA_HciW4eSETransaction_Complete(Wait); |
| 1496 | nativeNfcTag_abortWaits(); |
| 1497 | NfcTag::getInstance().abort (); |
| 1498 | sAbortConnlessWait = true; |
| 1499 | nativeLlcpConnectionlessSocket_abortWait(); |
| 1500 | { |
| 1501 | ALOGD ("%s: aborting sNfaEnableDisablePollingEvent", __FUNCTION__); |
| 1502 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 1503 | sNfaEnableDisablePollingEvent.notifyOne(); |
| 1504 | } |
| 1505 | { |
| 1506 | ALOGD ("%s: aborting sNfaEnableEvent", __FUNCTION__); |
| 1507 | SyncEventGuard guard (sNfaEnableEvent); |
| 1508 | sNfaEnableEvent.notifyOne(); |
| 1509 | } |
| 1510 | { |
| 1511 | ALOGD ("%s: aborting sNfaDisableEvent", __FUNCTION__); |
| 1512 | SyncEventGuard guard (sNfaDisableEvent); |
| 1513 | sNfaDisableEvent.notifyOne(); |
| 1514 | } |
| 1515 | sDiscoveryEnabled = false; |
| 1516 | sPollingEnabled = false; |
| 1517 | PowerSwitch::getInstance ().abort (); |
| 1518 | |
| 1519 | if (!sIsDisabling && sIsNfaEnabled) |
| 1520 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1521 | EXTNS_Close (); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1522 | NFA_Disable(FALSE); |
| 1523 | sIsDisabling = true; |
| 1524 | } |
| 1525 | else |
| 1526 | { |
| 1527 | sIsNfaEnabled = false; |
| 1528 | sIsDisabling = false; |
| 1529 | } |
| 1530 | PowerSwitch::getInstance ().initialize (PowerSwitch::UNKNOWN_LEVEL); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1531 | #if(NXP_EXTNS == TRUE) |
| 1532 | if(eventData->status == NFA_STATUS_FAILED) |
| 1533 | { |
| 1534 | ALOGE ("%s: Disabling NFC service", __FUNCTION__); |
| 1535 | } |
| 1536 | else |
| 1537 | { |
| 1538 | #endif |
| 1539 | ALOGE ("%s: crash NFC service", __FUNCTION__); |
| 1540 | ////////////////////////////////////////////// |
| 1541 | //crash the NFC service process so it can restart automatically |
| 1542 | abort (); |
| 1543 | ////////////////////////////////////////////// |
| 1544 | #if(NXP_EXTNS == TRUE) |
| 1545 | } |
| 1546 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1547 | } |
| 1548 | break; |
| 1549 | |
| 1550 | case NFA_DM_PWR_MODE_CHANGE_EVT: |
| 1551 | PowerSwitch::getInstance ().deviceManagementCallback (dmEvent, eventData); |
| 1552 | break; |
| 1553 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 1554 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1555 | case NFA_DM_SET_ROUTE_CONFIG_REVT: |
| 1556 | ALOGD ("%s: NFA_DM_SET_ROUTE_CONFIG_REVT; status=0x%X", |
| 1557 | __FUNCTION__, eventData->status); |
| 1558 | if(eventData->status != NFA_STATUS_OK) |
| 1559 | { |
| 1560 | ALOGD("AID Routing table configuration Failed!!!"); |
| 1561 | } |
| 1562 | else |
| 1563 | { |
| 1564 | ALOGD("AID Routing Table configured."); |
| 1565 | } |
| 1566 | RoutingManager::getInstance().mLmrtEvent.notifyOne(); |
| 1567 | break; |
| 1568 | |
| 1569 | case NFA_DM_GET_ROUTE_CONFIG_REVT: |
| 1570 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1571 | RoutingManager::getInstance().processGetRoutingRsp(eventData,sRoutingBuff); |
| 1572 | if (eventData->status == NFA_STATUS_OK) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1573 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1574 | SyncEventGuard guard (sNfaGetRoutingEvent); |
| 1575 | sNfaGetRoutingEvent.notifyOne(); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1576 | } |
| 1577 | break; |
| 1578 | } |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1579 | #if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE) |
| 1580 | case NFA_DM_EE_HCI_DISABLE: |
| 1581 | { |
| 1582 | ALOGD("NFA_DM_EE_HCI_DISABLE wait releasing"); |
| 1583 | sNfceeHciCbDisableEvent.notifyOne(); |
| 1584 | ALOGD("NFA_DM_EE_HCI_DISABLE wait released"); |
| 1585 | break; |
| 1586 | } |
| 1587 | case NFA_DM_EE_HCI_ENABLE: |
| 1588 | { |
| 1589 | ALOGD("NFA_DM_EE_HCI_ENABLE wait releasing"); |
| 1590 | sNfceeHciCbEnableEvent.notifyOne(); |
| 1591 | ALOGD("NFA_DM_EE_HCI_ENABLE wait released"); |
| 1592 | break; |
| 1593 | } |
| 1594 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1595 | #endif |
| 1596 | |
| 1597 | case NFA_DM_EMVCO_PCD_COLLISION_EVT: |
| 1598 | ALOGD("STATUS_EMVCO_PCD_COLLISION - Multiple card detected"); |
| 1599 | SecureElement::getInstance().notifyEmvcoMultiCardDetectedListeners(); |
| 1600 | break; |
| 1601 | |
| 1602 | default: |
| 1603 | ALOGD ("%s: unhandled event", __FUNCTION__); |
| 1604 | break; |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | /******************************************************************************* |
| 1609 | ** |
| 1610 | ** Function: nfcManager_sendRawFrame |
| 1611 | ** |
| 1612 | ** Description: Send a raw frame. |
| 1613 | ** e: JVM environment. |
| 1614 | ** o: Java object. |
| 1615 | ** |
| 1616 | ** Returns: True if ok. |
| 1617 | ** |
| 1618 | *******************************************************************************/ |
| 1619 | static jboolean nfcManager_sendRawFrame (JNIEnv* e, jobject, jbyteArray data) |
| 1620 | { |
| 1621 | ScopedByteArrayRO bytes(e, data); |
| 1622 | uint8_t* buf = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&bytes[0])); |
| 1623 | size_t bufLen = bytes.size(); |
| 1624 | tNFA_STATUS status = NFA_SendRawFrame (buf, bufLen, 0); |
| 1625 | |
| 1626 | return (status == NFA_STATUS_OK); |
| 1627 | } |
| 1628 | |
| 1629 | /******************************************************************************* |
| 1630 | ** |
| 1631 | ** Function: nfcManager_routeAid |
| 1632 | ** |
| 1633 | ** Description: Route an AID to an EE |
| 1634 | ** e: JVM environment. |
| 1635 | ** o: Java object. |
| 1636 | ** |
| 1637 | ** Returns: True if ok. |
| 1638 | ** |
| 1639 | *******************************************************************************/ |
| 1640 | static jboolean nfcManager_routeAid (JNIEnv* e, jobject, jbyteArray aid, jint route, jint power, jboolean isprefix) |
| 1641 | { |
| 1642 | ScopedByteArrayRO bytes(e, aid); |
| 1643 | uint8_t* buf = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&bytes[0])); |
| 1644 | size_t bufLen = bytes.size(); |
| 1645 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 1646 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1647 | bool result = RoutingManager::getInstance().addAidRouting(buf, bufLen, route, power, isprefix); |
| 1648 | #else |
| 1649 | bool result = RoutingManager::getInstance().addAidRouting(buf, bufLen, route); |
| 1650 | |
| 1651 | #endif |
| 1652 | return result; |
| 1653 | } |
| 1654 | |
| 1655 | /******************************************************************************* |
| 1656 | ** |
| 1657 | ** Function: nfcManager_unrouteAid |
| 1658 | ** |
| 1659 | ** Description: Remove a AID routing |
| 1660 | ** e: JVM environment. |
| 1661 | ** o: Java object. |
| 1662 | ** |
| 1663 | ** Returns: True if ok. |
| 1664 | ** |
| 1665 | *******************************************************************************/ |
| 1666 | static jboolean nfcManager_unrouteAid (JNIEnv* e, jobject, jbyteArray aid) |
| 1667 | { |
| 1668 | ScopedByteArrayRO bytes(e, aid); |
| 1669 | uint8_t* buf = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&bytes[0])); |
| 1670 | size_t bufLen = bytes.size(); |
| 1671 | bool result = RoutingManager::getInstance().removeAidRouting(buf, bufLen); |
| 1672 | return result; |
| 1673 | } |
| 1674 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 1675 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1676 | /******************************************************************************* |
| 1677 | ** |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1678 | ** Function: nfcManager_setRoutingEntry |
| 1679 | ** |
| 1680 | ** Description: Set the routing entry in routing table |
| 1681 | ** e: JVM environment. |
| 1682 | ** o: Java object. |
| 1683 | ** type: technology or protocol routing |
| 1684 | ** 0x01 - Technology |
| 1685 | ** 0x02 - Protocol |
| 1686 | ** value: technology /protocol value |
| 1687 | ** route: routing destination |
| 1688 | ** 0x00 : Device Host |
| 1689 | ** 0x01 : ESE |
| 1690 | ** 0x02 : UICC |
| 1691 | ** power: power state for the routing entry |
| 1692 | *******************************************************************************/ |
| 1693 | |
| 1694 | static jboolean nfcManager_setRoutingEntry (JNIEnv*, jobject, jint type, jint value, jint route, jint power) |
| 1695 | { |
| 1696 | jboolean result = FALSE; |
| 1697 | |
| 1698 | result = RoutingManager::getInstance().setRoutingEntry(type, value, route, power); |
| 1699 | return result; |
| 1700 | } |
| 1701 | |
| 1702 | static jint nfcManager_routeNfcid2 (JNIEnv* e, jobject, jbyteArray nfcid2, jbyteArray syscode, jbyteArray optparam) |
| 1703 | { |
| 1704 | ScopedByteArrayRO nfcid2bytes(e, nfcid2); |
| 1705 | uint8_t* nfcid2buf = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&nfcid2bytes[0])); |
| 1706 | size_t nfcid2Len = 0; |
| 1707 | if(nfcid2 != NULL) |
| 1708 | { |
| 1709 | nfcid2Len = nfcid2bytes.size(); |
| 1710 | } |
| 1711 | ScopedByteArrayRO syscodebytes(e, syscode); |
| 1712 | uint8_t* syscodebuf = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&syscodebytes[0])); |
| 1713 | |
| 1714 | size_t syscodelen = 0; |
| 1715 | if(syscode != NULL) |
| 1716 | { |
| 1717 | syscodelen = syscodebytes.size(); |
| 1718 | } |
| 1719 | /* Will be used in NCI1.1 */ |
| 1720 | // ScopedByteArrayRO optparambytes(e, optparam); |
| 1721 | // uint8_t* optparambuf = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&optparambytes[0])); |
| 1722 | // size_t optparamlen = optparambytes.size(); |
| 1723 | |
| 1724 | int result = RoutingManager::getInstance().addNfcid2Routing(nfcid2buf, nfcid2Len,syscodebuf,syscodelen, |
| 1725 | NULL, -1); |
| 1726 | |
| 1727 | return result; |
| 1728 | } |
| 1729 | |
| 1730 | static jboolean nfcManager_unrouteNfcid2 (JNIEnv* e, jobject, jbyteArray nfcID2) |
| 1731 | { |
| 1732 | |
| 1733 | ScopedByteArrayRO nfcid2bytes(e, nfcID2); |
| 1734 | uint8_t* nfcid2buf = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&nfcid2bytes[0])); |
| 1735 | size_t nfcid2Len = 0; |
| 1736 | if(nfcID2 != NULL) |
| 1737 | { |
| 1738 | nfcid2Len = nfcid2bytes.size(); |
| 1739 | } |
| 1740 | return RoutingManager::getInstance().removeNfcid2Routing(nfcid2buf); |
| 1741 | } |
| 1742 | /******************************************************************************* |
| 1743 | ** |
| 1744 | ** Function: nfcManager_clearRoutingEntry |
| 1745 | ** |
| 1746 | ** Description: Set the routing entry in routing table |
| 1747 | ** e: JVM environment. |
| 1748 | ** o: Java object. |
| 1749 | ** type:technology/protocol/aid clear routing |
| 1750 | ** |
| 1751 | *******************************************************************************/ |
| 1752 | |
| 1753 | static jboolean nfcManager_clearRoutingEntry (JNIEnv*, jobject, jint type) |
| 1754 | { |
| 1755 | jboolean result = FALSE; |
| 1756 | |
| 1757 | result = RoutingManager::getInstance().clearRoutingEntry(type); |
| 1758 | return result; |
| 1759 | } |
| 1760 | #endif |
| 1761 | |
| 1762 | /******************************************************************************* |
| 1763 | ** |
| 1764 | ** Function: nfcManager_setDefaultRoute |
| 1765 | ** |
| 1766 | ** Description: Set the default route in routing table |
| 1767 | ** e: JVM environment. |
| 1768 | ** o: Java object. |
| 1769 | ** |
| 1770 | *******************************************************************************/ |
| 1771 | |
| 1772 | static jboolean nfcManager_setDefaultRoute (JNIEnv*, jobject, jint defaultRouteEntry, jint defaultProtoRouteEntry, jint defaultTechRouteEntry) |
| 1773 | { |
| 1774 | jboolean result = FALSE; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1775 | ALOGD ("%s : enter", __FUNCTION__); |
| 1776 | if (sRfEnabled) |
| 1777 | { |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1778 | // Stop RF discovery to reconfigure |
| 1779 | startRfDiscovery(false); |
| 1780 | } |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1781 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 1782 | #if (NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1783 | result = RoutingManager::getInstance().setDefaultRoute(defaultRouteEntry, defaultProtoRouteEntry, defaultTechRouteEntry); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1784 | if(result) |
| 1785 | result = RoutingManager::getInstance().commitRouting(); |
| 1786 | else |
| 1787 | ALOGD ("%s : Commit routing failed ", __FUNCTION__); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 1788 | #else |
| 1789 | result = RoutingManager::getInstance().setDefaultRouting(); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1790 | #endif |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 1791 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1792 | startRfDiscovery(true); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1793 | ALOGD ("%s : exit", __FUNCTION__); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1794 | return result; |
| 1795 | } |
| 1796 | |
| 1797 | /******************************************************************************* |
| 1798 | ** |
| 1799 | ** Function: nfcManager_getAidTableSize |
| 1800 | ** Description: Get the maximum supported size for AID routing table. |
| 1801 | ** |
| 1802 | ** e: JVM environment. |
| 1803 | ** o: Java object. |
| 1804 | ** |
| 1805 | *******************************************************************************/ |
| 1806 | static jint nfcManager_getAidTableSize (JNIEnv*, jobject ) |
| 1807 | { |
| 1808 | return NFA_GetAidTableSize(); |
| 1809 | } |
| 1810 | |
| 1811 | /******************************************************************************* |
| 1812 | ** |
| 1813 | ** Function: nfcManager_getRemainingAidTableSize |
| 1814 | ** Description: Get the remaining size of AID routing table. |
| 1815 | ** |
| 1816 | ** e: JVM environment. |
| 1817 | ** o: Java object. |
| 1818 | ** |
| 1819 | *******************************************************************************/ |
| 1820 | static jint nfcManager_getRemainingAidTableSize (JNIEnv* , jobject ) |
| 1821 | { |
| 1822 | return NFA_GetRemainingAidTableSize(); |
| 1823 | } |
| 1824 | /******************************************************************************* |
| 1825 | ** |
| 1826 | ** Function: nfcManager_clearAidTable |
| 1827 | ** |
| 1828 | ** Description: Clean all AIDs in routing table |
| 1829 | ** e: JVM environment. |
| 1830 | ** o: Java object. |
| 1831 | ** |
| 1832 | *******************************************************************************/ |
| 1833 | static bool nfcManager_clearAidTable (JNIEnv*, jobject) |
| 1834 | { |
| 1835 | return RoutingManager::getInstance().clearAidTable(); |
| 1836 | } |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1837 | /******************************************************************************* |
| 1838 | ** |
| 1839 | ** Function: nfcManager_doRegisterT3tIdentifier |
| 1840 | ** |
| 1841 | ** Description: Registers LF_T3T_IDENTIFIER for NFC-F. |
| 1842 | ** e: JVM environment. |
| 1843 | ** o: Java object. |
| 1844 | ** t3tIdentifier: LF_T3T_IDENTIFIER value (10 or 18 bytes) |
| 1845 | ** |
| 1846 | ** Returns: Handle retrieve from RoutingManager. |
| 1847 | ** |
| 1848 | *******************************************************************************/ |
| 1849 | static jint nfcManager_doRegisterT3tIdentifier(JNIEnv* e, jobject, jbyteArray t3tIdentifier) |
| 1850 | { |
| 1851 | ALOGD ("%s: enter", __FUNCTION__); |
| 1852 | ScopedByteArrayRO bytes(e, t3tIdentifier); |
| 1853 | uint8_t* buf = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&bytes[0])); |
| 1854 | size_t bufLen = bytes.size(); |
| 1855 | int handle = RoutingManager::getInstance().registerT3tIdentifier(buf, bufLen); |
| 1856 | ALOGD ("%s: exit", __FUNCTION__); |
| 1857 | return handle; |
| 1858 | } |
| 1859 | |
| 1860 | /******************************************************************************* |
| 1861 | ** |
| 1862 | ** Function: nfcManager_doDeregisterT3tIdentifier |
| 1863 | ** |
| 1864 | ** Description: Deregisters LF_T3T_IDENTIFIER for NFC-F. |
| 1865 | ** e: JVM environment. |
| 1866 | ** o: Java object. |
| 1867 | ** handle: Handle retrieve from libnfc-nci. |
| 1868 | ** |
| 1869 | ** Returns: None |
| 1870 | ** |
| 1871 | *******************************************************************************/ |
| 1872 | static void nfcManager_doDeregisterT3tIdentifier(JNIEnv*, jobject, jint handle) |
| 1873 | { |
| 1874 | ALOGD ("%s: enter", __FUNCTION__); |
| 1875 | RoutingManager::getInstance().deregisterT3tIdentifier(handle); |
| 1876 | ALOGD ("%s: exit", __FUNCTION__); |
| 1877 | } |
| 1878 | |
| 1879 | /******************************************************************************* |
| 1880 | ** |
| 1881 | ** Function: nfcManager_getLfT3tMax |
| 1882 | ** |
| 1883 | ** Description: Returns LF_T3T_MAX value. |
| 1884 | ** e: JVM environment. |
| 1885 | ** o: Java object. |
| 1886 | ** |
| 1887 | ** Returns: LF_T3T_MAX value. |
| 1888 | ** |
| 1889 | *******************************************************************************/ |
| 1890 | static jint nfcManager_getLfT3tMax(JNIEnv*, jobject) |
| 1891 | { |
| 1892 | return sLfT3tMax; |
| 1893 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1894 | |
| 1895 | /******************************************************************************* |
| 1896 | ** |
| 1897 | ** Function: nfcManager_doInitialize |
| 1898 | ** |
| 1899 | ** Description: Turn on NFC. |
| 1900 | ** e: JVM environment. |
| 1901 | ** o: Java object. |
| 1902 | ** |
| 1903 | ** Returns: True if ok. |
| 1904 | ** |
| 1905 | *******************************************************************************/ |
| 1906 | static jboolean nfcManager_doInitialize (JNIEnv* e, jobject o) |
| 1907 | { |
| 1908 | tNFA_MW_VERSION mwVer; |
| 1909 | gSeDiscoverycount = 0; |
| 1910 | gActualSeCount = 0; |
| 1911 | UINT8 configData = 0; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1912 | UINT8 switchToUiccSlot = 0; |
| 1913 | unsigned long uicc_active_state = 0; |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 1914 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1915 | rfActivation = false; |
| 1916 | tNFA_PMID ven_config_addr[] = {0xA0, 0x07}; |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 1917 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1918 | ALOGD ("%s: enter; ver=%s nfa=%s NCI_VERSION=0x%02X", |
| 1919 | __FUNCTION__, nfca_version_string, nfa_version_string, NCI_VERSION); |
| 1920 | mwVer= NFA_GetMwVersion(); |
| 1921 | ALOGD ("%s: MW Version: NFC_NCIHALx_AR%X.%x.%x.%x", |
| 1922 | __FUNCTION__, mwVer.validation, mwVer.android_version, |
| 1923 | mwVer.major_version,mwVer.minor_version); |
| 1924 | |
| 1925 | tNFA_STATUS stat = NFA_STATUS_OK; |
| 1926 | NfcTag::getInstance ().mNfcDisableinProgress = false; |
| 1927 | PowerSwitch & powerSwitch = PowerSwitch::getInstance (); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 1928 | #if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1929 | struct sigaction sig; |
| 1930 | |
| 1931 | memset(&sig, 0, sizeof(struct sigaction)); |
| 1932 | sig.sa_sigaction = spi_prio_signal_handler; |
| 1933 | sig.sa_flags = SA_SIGINFO; |
| 1934 | if(sigaction(SIG_NFC, &sig, NULL) < 0) |
| 1935 | { |
| 1936 | ALOGE("Failed to register spi prio session signal handeler"); |
| 1937 | } |
| 1938 | #endif |
| 1939 | if (sIsNfaEnabled) |
| 1940 | { |
| 1941 | ALOGD ("%s: already enabled", __FUNCTION__); |
| 1942 | goto TheEnd; |
| 1943 | } |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 1944 | #if(NXP_EXTNS == TRUE) |
| 1945 | if(gsNfaPartialEnabled) |
| 1946 | { |
| 1947 | ALOGD ("%s: already partial enable calling deinitialize", __FUNCTION__); |
| 1948 | nfcManager_doPartialDeInitialize(); |
| 1949 | } |
| 1950 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1951 | if ((signal(SIGABRT, sig_handler) == SIG_ERR) && |
| 1952 | (signal(SIGSEGV, sig_handler) == SIG_ERR)) |
| 1953 | { |
| 1954 | ALOGE("Failed to register signal handeler"); |
| 1955 | } |
| 1956 | |
| 1957 | powerSwitch.initialize (PowerSwitch::FULL_POWER); |
| 1958 | |
| 1959 | { |
| 1960 | unsigned long num = 0; |
| 1961 | |
| 1962 | NfcAdaptation& theInstance = NfcAdaptation::GetInstance(); |
| 1963 | theInstance.Initialize(); //start GKI, NCI task, NFC task |
| 1964 | |
| 1965 | { |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 1966 | #if(NXP_EXTNS == TRUE) |
| 1967 | NFA_SetBootMode(NFA_NORMAL_BOOT_MODE); |
| 1968 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1969 | SyncEventGuard guard (sNfaEnableEvent); |
| 1970 | tHAL_NFC_ENTRY* halFuncEntries = theInstance.GetHalEntryFuncs (); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1971 | NFA_Init (halFuncEntries); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1972 | stat = NFA_Enable (nfaDeviceManagementCallback, nfaConnectionCallback); |
| 1973 | if (stat == NFA_STATUS_OK) |
| 1974 | { |
| 1975 | num = initializeGlobalAppLogLevel (); |
| 1976 | CE_SetTraceLevel (num); |
| 1977 | LLCP_SetTraceLevel (num); |
| 1978 | NFC_SetTraceLevel (num); |
| 1979 | RW_SetTraceLevel (num); |
| 1980 | NFA_SetTraceLevel (num); |
| 1981 | NFA_P2pSetTraceLevel (num); |
| 1982 | sNfaEnableEvent.wait(); //wait for NFA command to finish |
| 1983 | } |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 1984 | EXTNS_Init (nfaDeviceManagementCallback, nfaConnectionCallback); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | if (stat == NFA_STATUS_OK ) |
| 1988 | { |
| 1989 | //sIsNfaEnabled indicates whether stack started successfully |
| 1990 | if (sIsNfaEnabled) |
| 1991 | { |
| 1992 | SecureElement::getInstance().initialize (getNative(e, o)); |
| 1993 | //setListenMode(); |
| 1994 | RoutingManager::getInstance().initialize(getNative(e, o)); |
| 1995 | HciRFParams::getInstance().initialize (); |
| 1996 | sIsSecElemSelected = (SecureElement::getInstance().getActualNumEe() - 1 ); |
| 1997 | sIsSecElemDetected = sIsSecElemSelected; |
| 1998 | nativeNfcTag_registerNdefTypeHandler (); |
| 1999 | NfcTag::getInstance().initialize (getNative(e, o)); |
| 2000 | PeerToPeer::getInstance().initialize (); |
| 2001 | PeerToPeer::getInstance().handleNfcOnOff (true); |
| 2002 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 2003 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2004 | ALOGD("gSeDiscoverycount = %d", gSeDiscoverycount); |
| 2005 | if (NFA_STATUS_OK == GetSwpStausValue()) |
| 2006 | { |
| 2007 | if (gSeDiscoverycount < gActualSeCount) |
| 2008 | { |
| 2009 | ALOGD("Wait for ESE to discover, gdisc_timeout = %d", gdisc_timeout); |
| 2010 | SyncEventGuard g(gNfceeDiscCbEvent); |
| 2011 | if(gNfceeDiscCbEvent.wait(gdisc_timeout) == false) |
| 2012 | { |
| 2013 | ALOGE ("%s: timeout waiting for nfcee dis event", __FUNCTION__); |
| 2014 | } |
| 2015 | } |
| 2016 | else |
| 2017 | { |
| 2018 | ALOGD("All ESE are discovered "); |
| 2019 | } |
| 2020 | } |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 2021 | |
| 2022 | #if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE) |
| 2023 | GetNxpNumValue (NAME_NXP_DUAL_UICC_ENABLE, (void*)&uicc_active_state, sizeof(uicc_active_state)); |
| 2024 | if(uicc_active_state == 0x01) |
| 2025 | { |
| 2026 | dualUiccInfo.uiccActivStat = 0x00; |
| 2027 | if(SecureElement::getInstance().getEeStatus(UICC_HANDLE)!=NFC_NFCEE_STATUS_REMOVED) |
| 2028 | { |
| 2029 | dualUiccInfo.uiccActivStat = (sSelectedUicc & 0x0F); |
| 2030 | getUiccContext(); |
| 2031 | } |
| 2032 | switchToUiccSlot = ((sSelectedUicc & 0x0F) == 0x01) ? 0x02 : 0x01; |
| 2033 | nfcManager_doSelectUicc(e,o,switchToUiccSlot); |
| 2034 | if(SecureElement::getInstance().getEeStatus(UICC_HANDLE)!=NFC_NFCEE_STATUS_REMOVED) |
| 2035 | { |
| 2036 | dualUiccInfo.uiccActivStat |= (sSelectedUicc & 0x0F); |
| 2037 | } |
| 2038 | uiccEventTimer.set (1, notifyUiccEvent); |
| 2039 | } |
| 2040 | else |
| 2041 | #endif |
| 2042 | checkforNfceeConfig(); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2043 | #endif |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 2044 | #if((NFC_NXP_ESE_VER == JCOP_VER_3_3)&& (NXP_EXTNS == TRUE)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2045 | if(isNxpConfigModified()) |
| 2046 | { |
| 2047 | ALOGD("Set JCOP CP Timeout"); |
| 2048 | SecureElement::getInstance().setCPTimeout(); |
| 2049 | } |
| 2050 | else |
| 2051 | { |
| 2052 | ALOGD("No Need to set JCOP CP Timeout "); |
| 2053 | } |
| 2054 | #endif |
| 2055 | ///////////////////////////////////////////////////////////////////////////////// |
| 2056 | // Add extra configuration here (work-arounds, etc.) |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 2057 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2058 | set_transcation_stat(false); |
| 2059 | pendingScreenState = false; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 2060 | { |
| 2061 | SyncEventGuard guard (android::sNfaGetConfigEvent); |
| 2062 | stat = NFA_GetConfig(0x01,ven_config_addr); |
| 2063 | if(stat == NFA_STATUS_OK) |
| 2064 | { |
| 2065 | android::sNfaGetConfigEvent.wait(); |
| 2066 | } |
| 2067 | /*sCurrentConfigLen should be > 4 (num_tlv:1 + addr:2 + value:1) and |
| 2068 | *pos 4 gives the current eeprom value*/ |
| 2069 | if((sCurrentConfigLen > 4)&&(sConfig[4] == 0x03)) |
| 2070 | { |
| 2071 | ALOGD ("%s: No need to update VEN_CONFIG. Already set to 0x%02x", __FUNCTION__,sConfig[4]); |
| 2072 | } |
| 2073 | else |
| 2074 | { |
| 2075 | SetVenConfigValue(NFC_MODE_ON); |
| 2076 | if (stat != NFA_STATUS_OK) |
| 2077 | { |
| 2078 | ALOGE ("%s: fail enable SetVenConfigValue; error=0x%X", __FUNCTION__, stat); |
| 2079 | } |
| 2080 | } |
| 2081 | gGeneralPowershutDown = 0; |
| 2082 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2083 | if(gIsDtaEnabled == true){ |
| 2084 | configData = 0x01; /**< Poll NFC-DEP : Highest Available Bit Rates */ |
| 2085 | NFA_SetConfig(NFC_PMID_BITR_NFC_DEP, sizeof(UINT8), &configData); |
| 2086 | configData = 0x0B; /**< Listen NFC-DEP : Waiting Time */ |
| 2087 | NFA_SetConfig(NFC_PMID_WT, sizeof(UINT8), &configData); |
| 2088 | configData = 0x0F; /**< Specific Parameters for NFC-DEP RF Interface */ |
| 2089 | NFA_SetConfig(NFC_PMID_NFC_DEP_OP, sizeof(UINT8), &configData); |
| 2090 | } |
| 2091 | |
| 2092 | #endif |
| 2093 | struct nfc_jni_native_data *nat = getNative(e, o); |
| 2094 | |
| 2095 | if ( nat ) |
| 2096 | { |
| 2097 | if (GetNumValue(NAME_POLLING_TECH_MASK, &num, sizeof(num))) |
| 2098 | nat->tech_mask = num; |
| 2099 | else |
| 2100 | nat->tech_mask = DEFAULT_TECH_MASK; |
| 2101 | ALOGD ("%s: tag polling tech mask=0x%X", __FUNCTION__, nat->tech_mask); |
| 2102 | } |
| 2103 | |
| 2104 | // if this value exists, set polling interval. |
| 2105 | if (GetNumValue(NAME_NFA_DM_DISC_DURATION_POLL, &num, sizeof(num))) |
| 2106 | nat->discovery_duration = num; |
| 2107 | else |
| 2108 | nat->discovery_duration = DEFAULT_DISCOVERY_DURATION; |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 2109 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2110 | discDuration = nat->discovery_duration; |
| 2111 | #endif |
| 2112 | NFA_SetRfDiscoveryDuration(nat->discovery_duration); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 2113 | |
| 2114 | // get LF_T3T_MAX |
| 2115 | { |
| 2116 | SyncEventGuard guard (sNfaGetConfigEvent); |
| 2117 | tNFA_PMID configParam[1] = {NCI_PARAM_ID_LF_T3T_MAX}; |
| 2118 | stat = NFA_GetConfig(1, configParam); |
| 2119 | if (stat == NFA_STATUS_OK) |
| 2120 | { |
| 2121 | sNfaGetConfigEvent.wait (); |
| 2122 | if (sCurrentConfigLen >= 4 || sConfig[1] == NCI_PARAM_ID_LF_T3T_MAX) { |
| 2123 | ALOGD("%s: lfT3tMax=%d", __FUNCTION__, sConfig[3]); |
| 2124 | sLfT3tMax = sConfig[3]; |
| 2125 | } |
| 2126 | } |
| 2127 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2128 | if (GetNxpNumValue (NAME_NXP_CE_ROUTE_STRICT_DISABLE, (void*)&num, sizeof(num)) == false) |
| 2129 | num = 0x01; // default value |
| 2130 | |
| 2131 | //TODO: Check this in L_OSP_EXT[PN547C2] |
| 2132 | // NFA_SetCEStrictDisable(num); |
| 2133 | RoutingManager::getInstance().setCeRouteStrictDisable(num); |
| 2134 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 2135 | #if(NXP_EXTNS != TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2136 | // Do custom NFCA startup configuration. |
| 2137 | doStartupConfig(); |
| 2138 | #endif |
| 2139 | goto TheEnd; |
| 2140 | } |
| 2141 | } |
| 2142 | |
| 2143 | ALOGE ("%s: fail nfa enable; error=0x%X", __FUNCTION__, stat); |
| 2144 | |
| 2145 | if (sIsNfaEnabled) |
| 2146 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 2147 | EXTNS_Close (); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2148 | stat = NFA_Disable (FALSE /* ungraceful */); |
| 2149 | } |
| 2150 | |
| 2151 | theInstance.Finalize(); |
| 2152 | } |
| 2153 | |
| 2154 | TheEnd: |
| 2155 | if (sIsNfaEnabled) |
| 2156 | PowerSwitch::getInstance ().setLevel (PowerSwitch::LOW_POWER); |
| 2157 | ALOGD ("%s: exit", __FUNCTION__); |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 2158 | #if (NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2159 | if (isNxpConfigModified()) |
| 2160 | { |
| 2161 | updateNxpConfigTimestamp(); |
| 2162 | } |
| 2163 | #endif |
| 2164 | return sIsNfaEnabled ? JNI_TRUE : JNI_FALSE; |
| 2165 | } |
| 2166 | |
| 2167 | /******************************************************************************* |
| 2168 | ** |
| 2169 | ** Function: nfcManager_doEnableDtaMode |
| 2170 | ** |
| 2171 | ** Description: Enable the DTA mode in NFC service. |
| 2172 | ** e: JVM environment. |
| 2173 | ** o: Java object. |
| 2174 | ** |
| 2175 | ** Returns: None |
| 2176 | ** |
| 2177 | *******************************************************************************/ |
| 2178 | static void nfcManager_doEnableDtaMode (JNIEnv* e, jobject o) |
| 2179 | { |
| 2180 | gIsDtaEnabled = true; |
| 2181 | } |
| 2182 | |
| 2183 | /******************************************************************************* |
| 2184 | ** |
| 2185 | ** Function: nfcManager_doDisableDtaMode |
| 2186 | ** |
| 2187 | ** Description: Disable the DTA mode in NFC service. |
| 2188 | ** e: JVM environment. |
| 2189 | ** o: Java object. |
| 2190 | ** |
| 2191 | ** Returns: None |
| 2192 | ** |
| 2193 | *******************************************************************************/ |
| 2194 | static void nfcManager_doDisableDtaMode(JNIEnv* e, jobject o) |
| 2195 | { |
| 2196 | gIsDtaEnabled = false; |
| 2197 | } |
| 2198 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 2199 | #if(NXP_EXTNS == TRUE) |
| 2200 | /******************************************************************************* |
| 2201 | ** |
| 2202 | ** Function: nfcManager_Enablep2p |
| 2203 | ** |
| 2204 | ** Description: enable P2P |
| 2205 | ** e: JVM environment. |
| 2206 | ** o: Java object. |
| 2207 | ** |
| 2208 | ** Returns: None. |
| 2209 | ** |
| 2210 | *******************************************************************************/ |
| 2211 | static void nfcManager_Enablep2p(JNIEnv* e, jobject o, jboolean p2pFlag) |
| 2212 | { |
| 2213 | ALOGD ("Enter :%s p2pFlag = %d", __FUNCTION__, p2pFlag); |
| 2214 | /* if another transaction is already in progress, store this request */ |
| 2215 | if(get_transcation_stat() == true) |
| 2216 | { |
| 2217 | ALOGD("Transcation is in progress store the request"); |
| 2218 | set_last_request(3, NULL); |
| 2219 | transaction_data.discovery_params.enable_p2p = p2pFlag; |
| 2220 | return; |
| 2221 | } |
| 2222 | if(sRfEnabled && p2pFlag) |
| 2223 | { |
| 2224 | /* Stop discovery if already ON */ |
| 2225 | startRfDiscovery(false); |
| 2226 | } |
| 2227 | |
| 2228 | /* if already Polling, change to listen Mode */ |
| 2229 | if (sPollingEnabled) |
| 2230 | { |
| 2231 | if (p2pFlag && !sP2pEnabled) |
| 2232 | { |
| 2233 | /* enable P2P listening, if we were not already listening */ |
| 2234 | sP2pEnabled = true; |
| 2235 | PeerToPeer::getInstance().enableP2pListening (true); |
| 2236 | } |
| 2237 | } |
| 2238 | /* Beam ON - Discovery ON */ |
| 2239 | if(p2pFlag) |
| 2240 | { |
| 2241 | NFA_ResumeP2p(); |
| 2242 | startRfDiscovery (p2pFlag); |
| 2243 | } |
| 2244 | } |
| 2245 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2246 | /******************************************************************************* |
| 2247 | ** |
| 2248 | ** Function: nfcManager_enableDiscovery |
| 2249 | ** |
| 2250 | ** Description: Start polling and listening for devices. |
| 2251 | ** e: JVM environment. |
| 2252 | ** o: Java object. |
| 2253 | ** technologies_mask: the bitmask of technologies for which to enable discovery |
| 2254 | ** enable_lptd: whether to enable low power polling (default: false) |
| 2255 | ** |
| 2256 | ** Returns: None |
| 2257 | ** |
| 2258 | *******************************************************************************/ |
| 2259 | static void nfcManager_enableDiscovery (JNIEnv* e, jobject o, jint technologies_mask, |
| 2260 | jboolean enable_lptd, jboolean reader_mode, jboolean enable_host_routing, jboolean enable_p2p, |
| 2261 | jboolean restart) |
| 2262 | { |
| 2263 | tNFA_STATUS status = NFA_STATUS_OK; |
| 2264 | tNFA_TECHNOLOGY_MASK tech_mask = DEFAULT_TECH_MASK; |
| 2265 | unsigned long num = 0; |
| 2266 | unsigned long p2p_listen_mask = 0; |
| 2267 | tNFA_HANDLE handle = NFA_HANDLE_INVALID; |
| 2268 | struct nfc_jni_native_data *nat = NULL; |
| 2269 | |
| 2270 | tNFA_STATUS stat = NFA_STATUS_OK; |
| 2271 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 2272 | #if(NFC_NXP_ESE == TRUE && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2273 | tNFA_TECHNOLOGY_MASK etsi_tech_mask = 0; |
| 2274 | #endif |
| 2275 | if(e == NULL && o == NULL) |
| 2276 | { |
| 2277 | nat = transaction_data.transaction_nat; |
| 2278 | } |
| 2279 | else |
| 2280 | { |
| 2281 | nat = getNative(e, o); |
| 2282 | } |
| 2283 | |
| 2284 | if(get_transcation_stat() == true) |
| 2285 | { |
| 2286 | ALOGD("Transcation is in progress store the requst"); |
| 2287 | set_last_request(1, nat); |
| 2288 | transaction_data.discovery_params.technologies_mask = technologies_mask; |
| 2289 | transaction_data.discovery_params.enable_lptd = enable_lptd; |
| 2290 | transaction_data.discovery_params.reader_mode = reader_mode; |
| 2291 | transaction_data.discovery_params.enable_host_routing = enable_host_routing; |
| 2292 | transaction_data.discovery_params.enable_p2p = enable_p2p; |
| 2293 | transaction_data.discovery_params.restart = restart; |
| 2294 | return; |
| 2295 | } |
| 2296 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 2297 | #if(NFC_NXP_ESE == TRUE && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2298 | if(RoutingManager::getInstance().getEtsiReaederState() == STATE_SE_RDR_MODE_STARTED) |
| 2299 | { |
| 2300 | ALOGD ("%s: enter STATE_SE_RDR_MODE_START_CONFIG", __FUNCTION__); |
| 2301 | Rdr_req_ntf_info_t mSwp_info = RoutingManager::getInstance().getSwpRrdReqInfo(); |
| 2302 | { |
| 2303 | SyncEventGuard guard (android::sNfaEnableDisablePollingEvent); |
| 2304 | ALOGD ("%s: disable polling", __FUNCTION__); |
| 2305 | status = NFA_DisablePolling (); |
| 2306 | if (status == NFA_STATUS_OK) |
| 2307 | { |
| 2308 | android::sNfaEnableDisablePollingEvent.wait (); //wait for NFA_POLL_DISABLED_EVT |
| 2309 | } |
| 2310 | else |
| 2311 | { |
| 2312 | ALOGE ("%s: fail disable polling; error=0x%X", __FUNCTION__, status); |
| 2313 | } |
| 2314 | |
| 2315 | } |
| 2316 | |
| 2317 | if(mSwp_info.swp_rd_req_info.tech_mask & NFA_TECHNOLOGY_MASK_A) |
| 2318 | etsi_tech_mask |= NFA_TECHNOLOGY_MASK_A; |
| 2319 | if(mSwp_info.swp_rd_req_info.tech_mask & NFA_TECHNOLOGY_MASK_B) |
| 2320 | etsi_tech_mask |= NFA_TECHNOLOGY_MASK_B; |
| 2321 | |
| 2322 | |
| 2323 | { |
| 2324 | SyncEventGuard guard (android::sNfaEnableDisablePollingEvent); |
| 2325 | status = NFA_EnablePolling (etsi_tech_mask); |
| 2326 | if (status == NFA_STATUS_OK) |
| 2327 | { |
| 2328 | ALOGD ("%s: wait for enable event", __FUNCTION__); |
| 2329 | android::sNfaEnableDisablePollingEvent.wait (); //wait for NFA_POLL_ENABLED_EVT |
| 2330 | } |
| 2331 | else |
| 2332 | { |
| 2333 | ALOGE ("%s: fail enable polling; error=0x%X", __FUNCTION__, status); |
| 2334 | } |
| 2335 | } |
| 2336 | startRfDiscovery (true); |
| 2337 | set_transcation_stat(true); |
| 2338 | goto TheEnd; |
| 2339 | } |
| 2340 | #endif |
| 2341 | |
| 2342 | if (technologies_mask == -1 && nat) |
| 2343 | tech_mask = (tNFA_TECHNOLOGY_MASK)nat->tech_mask; |
| 2344 | else if (technologies_mask != -1) |
| 2345 | tech_mask = (tNFA_TECHNOLOGY_MASK) technologies_mask; |
| 2346 | ALOGD ("%s: enter; tech_mask = %02x", __FUNCTION__, tech_mask); |
| 2347 | |
| 2348 | if( sDiscoveryEnabled && !restart) |
| 2349 | { |
| 2350 | ALOGE ("%s: already discovering", __FUNCTION__); |
| 2351 | return; |
| 2352 | } |
| 2353 | |
| 2354 | ALOGD ("%s: sIsSecElemSelected=%u", __FUNCTION__, sIsSecElemSelected); |
| 2355 | acquireRfInterfaceMutexLock(); |
| 2356 | PowerSwitch::getInstance ().setLevel (PowerSwitch::FULL_POWER); |
| 2357 | |
| 2358 | if (sRfEnabled) { |
| 2359 | // Stop RF discovery to reconfigure |
| 2360 | startRfDiscovery(false); |
| 2361 | } |
| 2362 | |
| 2363 | if ((GetNumValue(NAME_UICC_LISTEN_TECH_MASK, &num, sizeof(num)))) |
| 2364 | { |
| 2365 | ALOGE ("%s:UICC_LISTEN_MASK=0x0%d;", __FUNCTION__, num); |
| 2366 | } |
| 2367 | |
| 2368 | |
| 2369 | // Check polling configuration |
| 2370 | if (tech_mask != 0) |
| 2371 | { |
| 2372 | ALOGD ("%s: Disable p2pListening", __FUNCTION__); |
| 2373 | PeerToPeer::getInstance().enableP2pListening (false); |
| 2374 | stopPolling_rfDiscoveryDisabled(); |
| 2375 | enableDisableLptd(enable_lptd); |
| 2376 | startPolling_rfDiscoveryDisabled(tech_mask); |
| 2377 | |
| 2378 | // Start P2P listening if tag polling was enabled |
| 2379 | if (sPollingEnabled) |
| 2380 | { |
| 2381 | ALOGD ("%s: Enable p2pListening", __FUNCTION__); |
| 2382 | |
| 2383 | if (enable_p2p && !sP2pEnabled) { |
| 2384 | sP2pEnabled = true; |
| 2385 | PeerToPeer::getInstance().enableP2pListening (true); |
| 2386 | NFA_ResumeP2p(); |
| 2387 | } else if (!enable_p2p && sP2pEnabled) { |
| 2388 | sP2pEnabled = false; |
| 2389 | PeerToPeer::getInstance().enableP2pListening (false); |
| 2390 | NFA_PauseP2p(); |
| 2391 | } |
| 2392 | |
| 2393 | if (reader_mode && !sReaderModeEnabled) |
| 2394 | { |
| 2395 | sReaderModeEnabled = true; |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 2396 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 2397 | NFA_SetReaderMode(true,0); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2398 | /*Send the state of readmode flag to Hal using proprietary command*/ |
| 2399 | sProprietaryCmdBuf[3]=0x01; |
| 2400 | status |= NFA_SendNxpNciCommand(sizeof(sProprietaryCmdBuf),sProprietaryCmdBuf,NxpResponsePropCmd_Cb); |
| 2401 | if (status == NFA_STATUS_OK) |
| 2402 | { |
| 2403 | SyncEventGuard guard (sNfaNxpNtfEvent); |
| 2404 | sNfaNxpNtfEvent.wait(500); //wait for callback |
| 2405 | } |
| 2406 | else |
| 2407 | { |
| 2408 | ALOGE ("%s: Failed NFA_SendNxpNciCommand", __FUNCTION__); |
| 2409 | } |
| 2410 | ALOGD ("%s: FRM Enable", __FUNCTION__); |
| 2411 | #endif |
| 2412 | NFA_DisableListening(); |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 2413 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2414 | sTechMask = tech_mask; |
| 2415 | |
| 2416 | discDuration = READER_MODE_DISCOVERY_DURATION; |
| 2417 | #endif |
| 2418 | NFA_SetRfDiscoveryDuration(READER_MODE_DISCOVERY_DURATION); |
| 2419 | } |
| 2420 | else if (!reader_mode && sReaderModeEnabled) |
| 2421 | { |
| 2422 | struct nfc_jni_native_data *nat = getNative(e, o); |
| 2423 | sReaderModeEnabled = false; |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 2424 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 2425 | NFA_SetReaderMode(false,0); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2426 | gFelicaReaderState = STATE_IDLE; |
| 2427 | /*Send the state of readmode flag to Hal using proprietary command*/ |
| 2428 | sProprietaryCmdBuf[3]=0x00; |
| 2429 | status |= NFA_SendNxpNciCommand(sizeof(sProprietaryCmdBuf),sProprietaryCmdBuf,NxpResponsePropCmd_Cb); |
| 2430 | if (status == NFA_STATUS_OK) |
| 2431 | { |
| 2432 | SyncEventGuard guard (sNfaNxpNtfEvent); |
| 2433 | sNfaNxpNtfEvent.wait(500); //wait for callback |
| 2434 | } |
| 2435 | else |
| 2436 | { |
| 2437 | ALOGE ("%s: Failed NFA_SendNxpNciCommand", __FUNCTION__); |
| 2438 | } |
| 2439 | ALOGD ("%s: FRM Disable", __FUNCTION__); |
| 2440 | #endif |
| 2441 | NFA_EnableListening(); |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 2442 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2443 | discDuration = nat->discovery_duration; |
| 2444 | #endif |
| 2445 | NFA_SetRfDiscoveryDuration(nat->discovery_duration); |
| 2446 | } |
| 2447 | else |
| 2448 | { |
| 2449 | { |
| 2450 | ALOGD ("%s: restart UICC listen mode (%02X)", __FUNCTION__, (num & 0xC7)); |
| 2451 | handle = SecureElement::getInstance().getEseHandleFromGenericId(SecureElement::UICC_ID); |
| 2452 | SyncEventGuard guard (SecureElement::getInstance().mUiccListenEvent); |
| 2453 | stat = NFA_CeConfigureUiccListenTech (handle, 0x00); |
| 2454 | if(stat == NFA_STATUS_OK) |
| 2455 | { |
| 2456 | SecureElement::getInstance().mUiccListenEvent.wait (); |
| 2457 | } |
| 2458 | else |
| 2459 | ALOGE ("fail to stop UICC listen"); |
| 2460 | } |
| 2461 | { |
| 2462 | SyncEventGuard guard (SecureElement::getInstance().mUiccListenEvent); |
| 2463 | stat = NFA_CeConfigureUiccListenTech (handle, (num & 0xC7)); |
| 2464 | if(stat == NFA_STATUS_OK) |
| 2465 | { |
| 2466 | SecureElement::getInstance().mUiccListenEvent.wait (); |
| 2467 | } |
| 2468 | else |
| 2469 | ALOGE ("fail to start UICC listen"); |
| 2470 | } |
| 2471 | } |
| 2472 | } |
| 2473 | } |
| 2474 | else |
| 2475 | { |
| 2476 | // No technologies configured, stop polling |
| 2477 | stopPolling_rfDiscoveryDisabled(); |
| 2478 | } |
| 2479 | //FIXME: Added in L, causing routing table update for screen on/off. Need to check. |
| 2480 | #if 0 |
| 2481 | // Check listen configuration |
| 2482 | if (enable_host_routing) |
| 2483 | { |
| 2484 | RoutingManager::getInstance().enableRoutingToHost(); |
| 2485 | RoutingManager::getInstance().commitRouting(); |
| 2486 | } |
| 2487 | else |
| 2488 | { |
| 2489 | RoutingManager::getInstance().disableRoutingToHost(); |
| 2490 | RoutingManager::getInstance().commitRouting(); |
| 2491 | } |
| 2492 | #endif |
| 2493 | // Start P2P listening if tag polling was enabled or the mask was 0. |
| 2494 | if (sDiscoveryEnabled || (tech_mask == 0)) |
| 2495 | { |
| 2496 | handle = SecureElement::getInstance().getEseHandleFromGenericId(SecureElement::UICC_ID); |
| 2497 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 2498 | #if(NXP_EXTNS == TRUE) |
| 2499 | if((getScreenState() == NFA_SCREEN_STATE_UNLOCKED) || sProvisionMode) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2500 | { |
| 2501 | ALOGD ("%s: Enable p2pListening", __FUNCTION__); |
| 2502 | PeerToPeer::getInstance().enableP2pListening (true); |
| 2503 | } |
| 2504 | else |
| 2505 | { |
| 2506 | ALOGD ("%s: Disable p2pListening", __FUNCTION__); |
| 2507 | PeerToPeer::getInstance().enableP2pListening (false); |
| 2508 | } |
| 2509 | #endif |
| 2510 | |
| 2511 | { |
| 2512 | SyncEventGuard guard (SecureElement::getInstance().mUiccListenEvent); |
| 2513 | stat = NFA_CeConfigureUiccListenTech (handle, 0x00); |
| 2514 | if(stat == NFA_STATUS_OK) |
| 2515 | { |
| 2516 | SecureElement::getInstance().mUiccListenEvent.wait (); |
| 2517 | } |
| 2518 | else |
| 2519 | ALOGE ("fail to start UICC listen"); |
| 2520 | } |
| 2521 | |
| 2522 | { |
| 2523 | SyncEventGuard guard (SecureElement::getInstance().mUiccListenEvent); |
| 2524 | stat = NFA_CeConfigureUiccListenTech (handle, (num & 0xC7)); |
| 2525 | if(stat == NFA_STATUS_OK) |
| 2526 | { |
| 2527 | SecureElement::getInstance().mUiccListenEvent.wait (); |
| 2528 | } |
| 2529 | else |
| 2530 | ALOGE ("fail to start UICC listen"); |
| 2531 | } |
| 2532 | } |
| 2533 | // Actually start discovery. |
| 2534 | startRfDiscovery (true); |
| 2535 | sDiscoveryEnabled = true; |
| 2536 | |
| 2537 | PowerSwitch::getInstance ().setModeOn (PowerSwitch::DISCOVERY); |
| 2538 | releaseRfInterfaceMutexLock(); |
| 2539 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 2540 | #if(NFC_NXP_ESE == TRUE && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2541 | TheEnd: |
| 2542 | #endif |
| 2543 | |
| 2544 | ALOGD ("%s: exit", __FUNCTION__); |
| 2545 | } |
| 2546 | |
| 2547 | |
| 2548 | /******************************************************************************* |
| 2549 | ** |
| 2550 | ** Function: nfcManager_disableDiscovery |
| 2551 | ** |
| 2552 | ** Description: Stop polling and listening for devices. |
| 2553 | ** e: JVM environment. |
| 2554 | ** o: Java object. |
| 2555 | ** |
| 2556 | ** Returns: None |
| 2557 | ** |
| 2558 | *******************************************************************************/ |
| 2559 | void nfcManager_disableDiscovery (JNIEnv* e, jobject o) |
| 2560 | { |
| 2561 | (void)e; |
| 2562 | (void)o; |
| 2563 | tNFA_STATUS status = NFA_STATUS_OK; |
| 2564 | unsigned long num = 0; |
| 2565 | unsigned long p2p_listen_mask =0; |
| 2566 | tNFA_HANDLE handle = NFA_HANDLE_INVALID; |
| 2567 | ALOGD ("%s: enter;", __FUNCTION__); |
| 2568 | |
| 2569 | if(get_transcation_stat() == true) |
| 2570 | { |
| 2571 | ALOGD("Transcatin is in progress store the request"); |
| 2572 | set_last_request(2, NULL); |
| 2573 | return; |
| 2574 | } |
| 2575 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 2576 | #if(NFC_NXP_ESE == TRUE && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2577 | if(RoutingManager::getInstance().getEtsiReaederState() == STATE_SE_RDR_MODE_START_IN_PROGRESS) |
| 2578 | { |
| 2579 | Rdr_req_ntf_info_t mSwp_info = RoutingManager::getInstance().getSwpRrdReqInfo(); |
| 2580 | // if(android::isDiscoveryStarted() == true) |
| 2581 | |
| 2582 | android::startRfDiscovery(false); |
| 2583 | |
| 2584 | PeerToPeer::getInstance().enableP2pListening (false); |
| 2585 | { |
| 2586 | SyncEventGuard guard ( SecureElement::getInstance().mUiccListenEvent); |
| 2587 | status = NFA_CeConfigureUiccListenTech (mSwp_info.swp_rd_req_info.src, 0x00); |
| 2588 | if (status == NFA_STATUS_OK) |
| 2589 | { |
| 2590 | SecureElement::getInstance().mUiccListenEvent.wait (); |
| 2591 | } |
| 2592 | else |
| 2593 | { |
| 2594 | ALOGE ("fail to stop listen"); |
| 2595 | } |
| 2596 | } |
| 2597 | |
| 2598 | goto TheEnd; |
| 2599 | } |
| 2600 | else if(RoutingManager::getInstance().getEtsiReaederState() == STATE_SE_RDR_MODE_STOP_IN_PROGRESS) |
| 2601 | { |
| 2602 | android::startRfDiscovery(false); |
| 2603 | goto TheEnd; |
| 2604 | } |
| 2605 | #endif |
| 2606 | |
| 2607 | pn544InteropAbortNow (); |
| 2608 | if (sDiscoveryEnabled == false) |
| 2609 | { |
| 2610 | ALOGD ("%s: already disabled", __FUNCTION__); |
| 2611 | goto TheEnd; |
| 2612 | } |
| 2613 | acquireRfInterfaceMutexLock(); |
| 2614 | // Stop RF Discovery. |
| 2615 | startRfDiscovery (false); |
| 2616 | |
| 2617 | if (sPollingEnabled) |
| 2618 | status = stopPolling_rfDiscoveryDisabled(); |
| 2619 | sDiscoveryEnabled = false; |
| 2620 | |
| 2621 | if ((GetNumValue(NAME_UICC_LISTEN_TECH_MASK, &num, sizeof(num)))) |
| 2622 | { |
| 2623 | ALOGE ("%s:UICC_LISTEN_MASK=0x0%d;", __FUNCTION__, num); |
| 2624 | } |
| 2625 | if ((GetNumValue("P2P_LISTEN_TECH_MASK", &p2p_listen_mask, sizeof(p2p_listen_mask)))) |
| 2626 | { |
| 2627 | ALOGE ("%s:P2P_LISTEN_MASK=0x0%d;", __FUNCTION__, p2p_listen_mask); |
| 2628 | } |
| 2629 | |
| 2630 | PeerToPeer::getInstance().enableP2pListening (false); |
| 2631 | #if 0 //EEPROM Init optimization |
| 2632 | { |
| 2633 | UINT8 sel_info = 0x20; |
| 2634 | UINT8 lf_protocol = 0x00; |
| 2635 | { |
| 2636 | SyncEventGuard guard (android::sNfaSetConfigEvent); |
| 2637 | status = NFA_SetConfig(NCI_PARAM_ID_LA_SEL_INFO, sizeof(UINT8), &sel_info); |
| 2638 | if (status == NFA_STATUS_OK) |
| 2639 | sNfaSetConfigEvent.wait (); |
| 2640 | else |
| 2641 | ALOGE ("%s: Could not able to configure sel_info", __FUNCTION__); |
| 2642 | } |
| 2643 | |
| 2644 | { |
| 2645 | SyncEventGuard guard (android::sNfaSetConfigEvent); |
| 2646 | status = NFA_SetConfig(NCI_PARAM_ID_LF_PROTOCOL, sizeof(UINT8), &lf_protocol); |
| 2647 | if (status == NFA_STATUS_OK) |
| 2648 | sNfaSetConfigEvent.wait (); |
| 2649 | else |
| 2650 | ALOGE ("%s: Could not able to configure lf_protocol", __FUNCTION__); |
| 2651 | } |
| 2652 | } |
| 2653 | |
| 2654 | #endif //EEPROM Init optimization |
| 2655 | /* |
| 2656 | { |
| 2657 | StoreScreenState(1); |
| 2658 | status = SetScreenState(1); |
| 2659 | if (status != NFA_STATUS_OK) |
| 2660 | { |
| 2661 | ALOGE ("%s: fail disable SetScreenState; error=0x%X", __FUNCTION__, status); |
| 2662 | } |
| 2663 | }*/ |
| 2664 | |
| 2665 | //To support card emulation in screen off state. |
| 2666 | // if (SecureElement::getInstance().isBusy() == true ) |
| 2667 | if (sIsSecElemSelected /*&& (sHCEEnabled == false )*/) |
| 2668 | { |
| 2669 | handle = SecureElement::getInstance().getEseHandleFromGenericId(SecureElement::UICC_ID); |
| 2670 | { |
| 2671 | SyncEventGuard guard (SecureElement::getInstance().mUiccListenEvent); |
| 2672 | status = NFA_CeConfigureUiccListenTech (handle, 0x00); |
| 2673 | if (status == NFA_STATUS_OK) |
| 2674 | { |
| 2675 | SecureElement::getInstance().mUiccListenEvent.wait (); |
| 2676 | } |
| 2677 | else |
| 2678 | ALOGE ("fail to start UICC listen"); |
| 2679 | } |
| 2680 | |
| 2681 | { |
| 2682 | SyncEventGuard guard (SecureElement::getInstance().mUiccListenEvent); |
| 2683 | status = NFA_CeConfigureUiccListenTech (handle, (num & 0x07)); |
| 2684 | if(status == NFA_STATUS_OK) |
| 2685 | { |
| 2686 | SecureElement::getInstance().mUiccListenEvent.wait (); |
| 2687 | } |
| 2688 | else |
| 2689 | ALOGE ("fail to start UICC listen"); |
| 2690 | } |
| 2691 | #if 0 |
| 2692 | { |
| 2693 | ALOGE ("%s: configure lf_protocol", __FUNCTION__); |
| 2694 | UINT8 lf_protocol = 0x00; |
| 2695 | |
| 2696 | SyncEventGuard guard (android::sNfaSetConfigEvent); |
| 2697 | status = NFA_SetConfig(NCI_PARAM_ID_LF_PROTOCOL, sizeof(UINT8), &lf_protocol); |
| 2698 | if (status == NFA_STATUS_OK) |
| 2699 | sNfaSetConfigEvent.wait (); |
| 2700 | else |
| 2701 | ALOGE ("%s: Could not able to configure lf_protocol", __FUNCTION__); |
| 2702 | } |
| 2703 | { |
| 2704 | ALOGE ("%s: configure sel_info", __FUNCTION__); |
| 2705 | |
| 2706 | UINT8 sel_info = 0x00; |
| 2707 | SyncEventGuard guard (android::sNfaSetConfigEvent); |
| 2708 | status = NFA_SetConfig(NCI_PARAM_ID_LA_SEL_INFO, sizeof(UINT8), &sel_info); |
| 2709 | if (status == NFA_STATUS_OK) |
| 2710 | sNfaSetConfigEvent.wait (); |
| 2711 | else |
| 2712 | ALOGE ("%s: Could not able to configure sel_info", __FUNCTION__); |
| 2713 | } |
| 2714 | |
| 2715 | #endif |
| 2716 | //PeerToPeer::getInstance().setP2pListenMask(p2p_listen_mask & 0x05); |
| 2717 | //PeerToPeer::getInstance().enableP2pListening (true); |
| 2718 | PeerToPeer::getInstance().enableP2pListening (false); |
| 2719 | startRfDiscovery (true); |
| 2720 | } |
| 2721 | |
| 2722 | sP2pEnabled = false; |
| 2723 | //if nothing is active after this, then tell the controller to power down |
| 2724 | //if (! PowerSwitch::getInstance ().setModeOff (PowerSwitch::DISCOVERY)) |
| 2725 | //PowerSwitch::getInstance ().setLevel (PowerSwitch::LOW_POWER); |
| 2726 | |
| 2727 | // We may have had RF field notifications that did not cause |
| 2728 | // any activate/deactive events. For example, caused by wireless |
| 2729 | // charging orbs. Those may cause us to go to sleep while the last |
| 2730 | // field event was indicating a field. To prevent sticking in that |
| 2731 | // state, always reset the rf field status when we disable discovery. |
| 2732 | SecureElement::getInstance().resetRfFieldStatus(); |
| 2733 | releaseRfInterfaceMutexLock(); |
| 2734 | TheEnd: |
| 2735 | ALOGD ("%s: exit", __FUNCTION__); |
| 2736 | } |
| 2737 | |
| 2738 | void enableDisableLongGuardTime (bool enable) |
| 2739 | { |
| 2740 | // TODO |
| 2741 | // This is basically a work-around for an issue |
| 2742 | // in BCM20791B5: if a reader is configured as follows |
| 2743 | // 1) Only polls for NFC-A |
| 2744 | // 2) Cuts field between polls |
| 2745 | // 3) Has a short guard time (~5ms) |
| 2746 | // the BCM20791B5 doesn't wake up when such a reader |
| 2747 | // is polling it. Unfortunately the default reader |
| 2748 | // mode configuration on Android matches those |
| 2749 | // criteria. To avoid the issue, increase the guard |
| 2750 | // time when in reader mode. |
| 2751 | // |
| 2752 | // Proper fix is firmware patch for B5 controllers. |
| 2753 | SyncEventGuard guard(sNfaSetConfigEvent); |
| 2754 | tNFA_STATUS stat = NFA_SetConfig(NCI_PARAM_ID_T1T_RDR_ONLY, 2, |
| 2755 | enable ? sLongGuardTime : sDefaultGuardTime); |
| 2756 | if (stat == NFA_STATUS_OK) |
| 2757 | sNfaSetConfigEvent.wait (); |
| 2758 | else |
| 2759 | ALOGE("%s: Could not configure longer guard time", __FUNCTION__); |
| 2760 | return; |
| 2761 | } |
| 2762 | |
| 2763 | void enableDisableLptd (bool enable) |
| 2764 | { |
| 2765 | // This method is *NOT* thread-safe. Right now |
| 2766 | // it is only called from the same thread so it's |
| 2767 | // not an issue. |
| 2768 | static bool sCheckedLptd = false; |
| 2769 | static bool sHasLptd = false; |
| 2770 | |
| 2771 | tNFA_STATUS stat = NFA_STATUS_OK; |
| 2772 | if (!sCheckedLptd) |
| 2773 | { |
| 2774 | sCheckedLptd = true; |
| 2775 | SyncEventGuard guard (sNfaGetConfigEvent); |
| 2776 | tNFA_PMID configParam[1] = {NCI_PARAM_ID_TAGSNIFF_CFG}; |
| 2777 | stat = NFA_GetConfig(1, configParam); |
| 2778 | if (stat != NFA_STATUS_OK) |
| 2779 | { |
| 2780 | ALOGE("%s: NFA_GetConfig failed", __FUNCTION__); |
| 2781 | return; |
| 2782 | } |
| 2783 | sNfaGetConfigEvent.wait (); |
| 2784 | if (sCurrentConfigLen < 4 || sConfig[1] != NCI_PARAM_ID_TAGSNIFF_CFG) { |
| 2785 | ALOGE("%s: Config TLV length %d returned is too short", __FUNCTION__, |
| 2786 | sCurrentConfigLen); |
| 2787 | return; |
| 2788 | } |
| 2789 | if (sConfig[3] == 0) { |
| 2790 | ALOGE("%s: LPTD is disabled, not enabling in current config", __FUNCTION__); |
| 2791 | return; |
| 2792 | } |
| 2793 | sHasLptd = true; |
| 2794 | } |
| 2795 | // Bail if we checked and didn't find any LPTD config before |
| 2796 | if (!sHasLptd) return; |
| 2797 | UINT8 enable_byte = enable ? 0x01 : 0x00; |
| 2798 | |
| 2799 | SyncEventGuard guard(sNfaSetConfigEvent); |
| 2800 | |
| 2801 | stat = NFA_SetConfig(NCI_PARAM_ID_TAGSNIFF_CFG, 1, &enable_byte); |
| 2802 | if (stat == NFA_STATUS_OK) |
| 2803 | sNfaSetConfigEvent.wait (); |
| 2804 | else |
| 2805 | ALOGE("%s: Could not configure LPTD feature", __FUNCTION__); |
| 2806 | return; |
| 2807 | } |
| 2808 | |
| 2809 | void setUiccIdleTimeout (bool enable) |
| 2810 | { |
| 2811 | // This method is *NOT* thread-safe. Right now |
| 2812 | // it is only called from the same thread so it's |
| 2813 | // not an issue. |
| 2814 | tNFA_STATUS stat = NFA_STATUS_OK; |
| 2815 | UINT8 swp_cfg_byte0 = 0x00; |
| 2816 | { |
| 2817 | SyncEventGuard guard (sNfaGetConfigEvent); |
| 2818 | tNFA_PMID configParam[1] = {0xC2}; |
| 2819 | stat = NFA_GetConfig(1, configParam); |
| 2820 | if (stat != NFA_STATUS_OK) |
| 2821 | { |
| 2822 | ALOGE("%s: NFA_GetConfig failed", __FUNCTION__); |
| 2823 | return; |
| 2824 | } |
| 2825 | sNfaGetConfigEvent.wait (); |
| 2826 | if (sCurrentConfigLen < 4 || sConfig[1] != 0xC2) { |
| 2827 | ALOGE("%s: Config TLV length %d returned is too short", __FUNCTION__, |
| 2828 | sCurrentConfigLen); |
| 2829 | return; |
| 2830 | } |
| 2831 | swp_cfg_byte0 = sConfig[3]; |
| 2832 | } |
| 2833 | SyncEventGuard guard(sNfaSetConfigEvent); |
| 2834 | if (enable) |
| 2835 | swp_cfg_byte0 |= 0x01; |
| 2836 | else |
| 2837 | swp_cfg_byte0 &= ~0x01; |
| 2838 | |
| 2839 | stat = NFA_SetConfig(0xC2, 1, &swp_cfg_byte0); |
| 2840 | if (stat == NFA_STATUS_OK) |
| 2841 | sNfaSetConfigEvent.wait (); |
| 2842 | else |
| 2843 | ALOGE("%s: Could not configure UICC idle timeout feature", __FUNCTION__); |
| 2844 | return; |
| 2845 | } |
| 2846 | |
| 2847 | |
| 2848 | /******************************************************************************* |
| 2849 | ** |
| 2850 | ** Function: nfcManager_doCreateLlcpServiceSocket |
| 2851 | ** |
| 2852 | ** Description: Create a new LLCP server socket. |
| 2853 | ** e: JVM environment. |
| 2854 | ** o: Java object. |
| 2855 | ** nSap: Service access point. |
| 2856 | ** sn: Service name |
| 2857 | ** miu: Maximum information unit. |
| 2858 | ** rw: Receive window size. |
| 2859 | ** linearBufferLength: Max buffer size. |
| 2860 | ** |
| 2861 | ** Returns: NativeLlcpServiceSocket Java object. |
| 2862 | ** |
| 2863 | *******************************************************************************/ |
| 2864 | static jobject nfcManager_doCreateLlcpServiceSocket (JNIEnv* e, jobject, jint nSap, jstring sn, jint miu, jint rw, jint linearBufferLength) |
| 2865 | { |
| 2866 | PeerToPeer::tJNI_HANDLE jniHandle = PeerToPeer::getInstance().getNewJniHandle (); |
| 2867 | |
| 2868 | ScopedUtfChars serviceName(e, sn); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 2869 | if (serviceName.c_str() == NULL) |
| 2870 | { |
| 2871 | ALOGE ("%s: service name can not be null error", __FUNCTION__); |
| 2872 | return NULL; |
| 2873 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2874 | |
| 2875 | ALOGD ("%s: enter: sap=%i; name=%s; miu=%i; rw=%i; buffLen=%i", __FUNCTION__, nSap, serviceName.c_str(), miu, rw, linearBufferLength); |
| 2876 | |
| 2877 | /* Create new NativeLlcpServiceSocket object */ |
| 2878 | jobject serviceSocket = NULL; |
| 2879 | if (nfc_jni_cache_object_local(e, gNativeLlcpServiceSocketClassName, &(serviceSocket)) == -1) |
| 2880 | { |
| 2881 | ALOGE ("%s: Llcp socket object creation error", __FUNCTION__); |
| 2882 | return NULL; |
| 2883 | } |
| 2884 | |
| 2885 | /* Get NativeLlcpServiceSocket class object */ |
| 2886 | ScopedLocalRef<jclass> clsNativeLlcpServiceSocket(e, e->GetObjectClass(serviceSocket)); |
| 2887 | if (e->ExceptionCheck()) |
| 2888 | { |
| 2889 | e->ExceptionClear(); |
| 2890 | ALOGE("%s: Llcp Socket get object class error", __FUNCTION__); |
| 2891 | return NULL; |
| 2892 | } |
| 2893 | |
| 2894 | if (!PeerToPeer::getInstance().registerServer (jniHandle, serviceName.c_str())) |
| 2895 | { |
| 2896 | ALOGE("%s: RegisterServer error", __FUNCTION__); |
| 2897 | return NULL; |
| 2898 | } |
| 2899 | |
| 2900 | jfieldID f; |
| 2901 | |
| 2902 | /* Set socket handle to be the same as the NfaHandle*/ |
| 2903 | f = e->GetFieldID(clsNativeLlcpServiceSocket.get(), "mHandle", "I"); |
| 2904 | e->SetIntField(serviceSocket, f, (jint) jniHandle); |
| 2905 | ALOGD ("%s: socket Handle = 0x%X", __FUNCTION__, jniHandle); |
| 2906 | |
| 2907 | /* Set socket linear buffer length */ |
| 2908 | f = e->GetFieldID(clsNativeLlcpServiceSocket.get(), "mLocalLinearBufferLength", "I"); |
| 2909 | e->SetIntField(serviceSocket, f,(jint)linearBufferLength); |
| 2910 | ALOGD ("%s: buffer length = %d", __FUNCTION__, linearBufferLength); |
| 2911 | |
| 2912 | /* Set socket MIU */ |
| 2913 | f = e->GetFieldID(clsNativeLlcpServiceSocket.get(), "mLocalMiu", "I"); |
| 2914 | e->SetIntField(serviceSocket, f,(jint)miu); |
| 2915 | ALOGD ("%s: MIU = %d", __FUNCTION__, miu); |
| 2916 | |
| 2917 | /* Set socket RW */ |
| 2918 | f = e->GetFieldID(clsNativeLlcpServiceSocket.get(), "mLocalRw", "I"); |
| 2919 | e->SetIntField(serviceSocket, f,(jint)rw); |
| 2920 | ALOGD ("%s: RW = %d", __FUNCTION__, rw); |
| 2921 | |
| 2922 | sLastError = 0; |
| 2923 | ALOGD ("%s: exit", __FUNCTION__); |
| 2924 | return serviceSocket; |
| 2925 | } |
| 2926 | |
| 2927 | |
| 2928 | /******************************************************************************* |
| 2929 | ** |
| 2930 | ** Function: nfcManager_doGetLastError |
| 2931 | ** |
| 2932 | ** Description: Get the last error code. |
| 2933 | ** e: JVM environment. |
| 2934 | ** o: Java object. |
| 2935 | ** |
| 2936 | ** Returns: Last error code. |
| 2937 | ** |
| 2938 | *******************************************************************************/ |
| 2939 | static jint nfcManager_doGetLastError(JNIEnv*, jobject) |
| 2940 | { |
| 2941 | ALOGD ("%s: last error=%i", __FUNCTION__, sLastError); |
| 2942 | return sLastError; |
| 2943 | } |
| 2944 | |
| 2945 | |
| 2946 | /******************************************************************************* |
| 2947 | ** |
| 2948 | ** Function: nfcManager_doDeinitialize |
| 2949 | ** |
| 2950 | ** Description: Turn off NFC. |
| 2951 | ** e: JVM environment. |
| 2952 | ** o: Java object. |
| 2953 | ** |
| 2954 | ** Returns: True if ok. |
| 2955 | ** |
| 2956 | *******************************************************************************/ |
| 2957 | static jboolean nfcManager_doDeinitialize (JNIEnv*, jobject) |
| 2958 | { |
| 2959 | ALOGD ("%s: enter", __FUNCTION__); |
| 2960 | sIsDisabling = true; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 2961 | #if(NXP_EXTNS == TRUE) |
| 2962 | rfActivation = false; |
| 2963 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2964 | doDwpChannel_ForceExit(); |
| 2965 | NFA_HciW4eSETransaction_Complete(Wait); |
| 2966 | pn544InteropAbortNow (); |
| 2967 | |
| 2968 | RoutingManager::getInstance().onNfccShutdown(); |
| 2969 | SecureElement::getInstance().finalize (); |
| 2970 | PowerSwitch::getInstance ().initialize (PowerSwitch::UNKNOWN_LEVEL); |
| 2971 | //Stop the discovery before calling NFA_Disable. |
| 2972 | if(sRfEnabled) |
| 2973 | startRfDiscovery(false); |
| 2974 | tNFA_STATUS stat = NFA_STATUS_OK; |
| 2975 | |
| 2976 | if (sIsNfaEnabled) |
| 2977 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 2978 | stat = SetVenConfigValue(NFC_MODE_OFF); |
| 2979 | if (stat != NFA_STATUS_OK) |
| 2980 | { |
| 2981 | ALOGE ("%s: fail enable SetVenConfigValue; error=0x%X", __FUNCTION__, stat); |
| 2982 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2983 | SyncEventGuard guard (sNfaDisableEvent); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 2984 | EXTNS_Close (); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 2985 | stat = NFA_Disable (TRUE /* graceful */); |
| 2986 | if (stat == NFA_STATUS_OK) |
| 2987 | { |
| 2988 | ALOGD ("%s: wait for completion", __FUNCTION__); |
| 2989 | sNfaDisableEvent.wait (); //wait for NFA command to finish |
| 2990 | PeerToPeer::getInstance ().handleNfcOnOff (false); |
| 2991 | } |
| 2992 | else |
| 2993 | { |
| 2994 | ALOGE ("%s: fail disable; error=0x%X", __FUNCTION__, stat); |
| 2995 | } |
| 2996 | } |
| 2997 | NfcTag::getInstance ().mNfcDisableinProgress = true; |
| 2998 | nativeNfcTag_abortWaits(); |
| 2999 | NfcTag::getInstance().abort (); |
| 3000 | sAbortConnlessWait = true; |
| 3001 | nativeLlcpConnectionlessSocket_abortWait(); |
| 3002 | sIsNfaEnabled = false; |
| 3003 | sDiscoveryEnabled = false; |
| 3004 | sIsDisabling = false; |
| 3005 | sPollingEnabled = false; |
| 3006 | // sIsSecElemSelected = false; |
| 3007 | sIsSecElemSelected = 0; |
| 3008 | gActivated = false; |
| 3009 | sP2pEnabled = false; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 3010 | sLfT3tMax = 0; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 3011 | { |
| 3012 | //unblock NFA_EnablePolling() and NFA_DisablePolling() |
| 3013 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 3014 | sNfaEnableDisablePollingEvent.notifyOne (); |
| 3015 | } |
| 3016 | |
| 3017 | NfcAdaptation& theInstance = NfcAdaptation::GetInstance(); |
| 3018 | theInstance.Finalize(); |
| 3019 | |
| 3020 | ALOGD ("%s: exit", __FUNCTION__); |
| 3021 | return JNI_TRUE; |
| 3022 | } |
| 3023 | |
| 3024 | |
| 3025 | /******************************************************************************* |
| 3026 | ** |
| 3027 | ** Function: nfcManager_doCreateLlcpSocket |
| 3028 | ** |
| 3029 | ** Description: Create a LLCP connection-oriented socket. |
| 3030 | ** e: JVM environment. |
| 3031 | ** o: Java object. |
| 3032 | ** nSap: Service access point. |
| 3033 | ** miu: Maximum information unit. |
| 3034 | ** rw: Receive window size. |
| 3035 | ** linearBufferLength: Max buffer size. |
| 3036 | ** |
| 3037 | ** Returns: NativeLlcpSocket Java object. |
| 3038 | ** |
| 3039 | *******************************************************************************/ |
| 3040 | static jobject nfcManager_doCreateLlcpSocket (JNIEnv* e, jobject, jint nSap, jint miu, jint rw, jint linearBufferLength) |
| 3041 | { |
| 3042 | ALOGD ("%s: enter; sap=%d; miu=%d; rw=%d; buffer len=%d", __FUNCTION__, nSap, miu, rw, linearBufferLength); |
| 3043 | |
| 3044 | PeerToPeer::tJNI_HANDLE jniHandle = PeerToPeer::getInstance().getNewJniHandle (); |
| 3045 | PeerToPeer::getInstance().createClient (jniHandle, miu, rw); |
| 3046 | |
| 3047 | /* Create new NativeLlcpSocket object */ |
| 3048 | jobject clientSocket = NULL; |
| 3049 | if (nfc_jni_cache_object_local(e, gNativeLlcpSocketClassName, &(clientSocket)) == -1) |
| 3050 | { |
| 3051 | ALOGE ("%s: fail Llcp socket creation", __FUNCTION__); |
| 3052 | return clientSocket; |
| 3053 | } |
| 3054 | |
| 3055 | /* Get NativeConnectionless class object */ |
| 3056 | ScopedLocalRef<jclass> clsNativeLlcpSocket(e, e->GetObjectClass(clientSocket)); |
| 3057 | if (e->ExceptionCheck()) |
| 3058 | { |
| 3059 | e->ExceptionClear(); |
| 3060 | ALOGE ("%s: fail get class object", __FUNCTION__); |
| 3061 | return clientSocket; |
| 3062 | } |
| 3063 | |
| 3064 | jfieldID f; |
| 3065 | |
| 3066 | /* Set socket SAP */ |
| 3067 | f = e->GetFieldID (clsNativeLlcpSocket.get(), "mSap", "I"); |
| 3068 | e->SetIntField (clientSocket, f, (jint) nSap); |
| 3069 | |
| 3070 | /* Set socket handle */ |
| 3071 | f = e->GetFieldID (clsNativeLlcpSocket.get(), "mHandle", "I"); |
| 3072 | e->SetIntField (clientSocket, f, (jint) jniHandle); |
| 3073 | |
| 3074 | /* Set socket MIU */ |
| 3075 | f = e->GetFieldID (clsNativeLlcpSocket.get(), "mLocalMiu", "I"); |
| 3076 | e->SetIntField (clientSocket, f, (jint) miu); |
| 3077 | |
| 3078 | /* Set socket RW */ |
| 3079 | f = e->GetFieldID (clsNativeLlcpSocket.get(), "mLocalRw", "I"); |
| 3080 | e->SetIntField (clientSocket, f, (jint) rw); |
| 3081 | |
| 3082 | ALOGD ("%s: exit", __FUNCTION__); |
| 3083 | return clientSocket; |
| 3084 | } |
| 3085 | |
| 3086 | |
| 3087 | /******************************************************************************* |
| 3088 | ** |
| 3089 | ** Function: nfcManager_doCreateLlcpConnectionlessSocket |
| 3090 | ** |
| 3091 | ** Description: Create a connection-less socket. |
| 3092 | ** e: JVM environment. |
| 3093 | ** o: Java object. |
| 3094 | ** nSap: Service access point. |
| 3095 | ** sn: Service name. |
| 3096 | ** |
| 3097 | ** Returns: NativeLlcpConnectionlessSocket Java object. |
| 3098 | ** |
| 3099 | *******************************************************************************/ |
| 3100 | static jobject nfcManager_doCreateLlcpConnectionlessSocket (JNIEnv *, jobject, jint nSap, jstring /*sn*/) |
| 3101 | { |
| 3102 | ALOGD ("%s: nSap=0x%X", __FUNCTION__, nSap); |
| 3103 | return NULL; |
| 3104 | } |
| 3105 | |
| 3106 | |
| 3107 | /******************************************************************************* |
| 3108 | ** |
| 3109 | ** Function: nfcManager_doGetSecureElementList |
| 3110 | ** |
| 3111 | ** Description: Get a list of secure element handles. |
| 3112 | ** e: JVM environment. |
| 3113 | ** o: Java object. |
| 3114 | ** |
| 3115 | ** Returns: List of secure element handles. |
| 3116 | ** |
| 3117 | *******************************************************************************/ |
| 3118 | static jintArray nfcManager_doGetSecureElementList(JNIEnv* e, jobject) |
| 3119 | { |
| 3120 | ALOGD ("%s", __FUNCTION__); |
| 3121 | return SecureElement::getInstance().getListOfEeHandles(e); |
| 3122 | } |
| 3123 | |
| 3124 | /******************************************************************************* |
| 3125 | ** |
| 3126 | ** Function: setListenMode |
| 3127 | ** |
| 3128 | ** Description: NFC controller starts routing data in listen mode. |
| 3129 | ** e: JVM environment. |
| 3130 | ** o: Java object. |
| 3131 | ** |
| 3132 | ** Returns: None |
| 3133 | ** |
| 3134 | *******************************************************************************/ |
| 3135 | inline static void setListenMode() /*defined as inline to eliminate warning defined but not used*/ |
| 3136 | { |
| 3137 | ALOGD ("%s: enter", __FUNCTION__); |
| 3138 | tNFA_HANDLE ee_handleList[NFA_EE_MAX_EE_SUPPORTED]; |
| 3139 | UINT8 i, seId, count; |
| 3140 | |
| 3141 | PowerSwitch::getInstance ().setLevel (PowerSwitch::FULL_POWER); |
| 3142 | |
| 3143 | if (sRfEnabled) { |
| 3144 | // Stop RF Discovery if we were polling |
| 3145 | startRfDiscovery (false); |
| 3146 | } |
| 3147 | SecureElement::getInstance().getEeHandleList(ee_handleList, &count); |
| 3148 | if (count > NFA_EE_MAX_EE_SUPPORTED) { |
| 3149 | count = NFA_EE_MAX_EE_SUPPORTED; |
| 3150 | ALOGD ("Count is more than NFA_EE_MAX_EE_SUPPORTED ,Forcing to NFA_EE_MAX_EE_SUPPORTED"); |
| 3151 | } |
| 3152 | for ( i = 0; i < count; i++) |
| 3153 | { |
| 3154 | seId = SecureElement::getInstance().getGenericEseId(ee_handleList[i]); |
| 3155 | SecureElement::getInstance().activate (seId); |
| 3156 | sIsSecElemSelected++; |
| 3157 | } |
| 3158 | |
| 3159 | startRfDiscovery (true); |
| 3160 | PowerSwitch::getInstance ().setModeOn (PowerSwitch::SE_ROUTING); |
| 3161 | //TheEnd: /*commented to eliminate warning label defined but not used*/ |
| 3162 | ALOGD ("%s: exit", __FUNCTION__); |
| 3163 | } |
| 3164 | |
| 3165 | |
| 3166 | /******************************************************************************* |
| 3167 | ** |
| 3168 | ** Function: nfcManager_doSelectSecureElement |
| 3169 | ** |
| 3170 | ** Description: NFC controller starts routing data in listen mode. |
| 3171 | ** e: JVM environment. |
| 3172 | ** o: Java object. |
| 3173 | ** |
| 3174 | ** Returns: None |
| 3175 | ** |
| 3176 | *******************************************************************************/ |
| 3177 | static void nfcManager_doSelectSecureElement(JNIEnv *e, jobject o, jint seId) |
| 3178 | { |
| 3179 | (void)e; |
| 3180 | (void)o; |
| 3181 | ALOGD ("%s: enter", __FUNCTION__); |
| 3182 | bool stat = true; |
| 3183 | |
| 3184 | if (sIsSecElemSelected >= sIsSecElemDetected) |
| 3185 | { |
| 3186 | ALOGD ("%s: already selected", __FUNCTION__); |
| 3187 | goto TheEnd; |
| 3188 | } |
| 3189 | |
| 3190 | PowerSwitch::getInstance ().setLevel (PowerSwitch::FULL_POWER); |
| 3191 | |
| 3192 | if (sRfEnabled) { |
| 3193 | // Stop RF Discovery if we were polling |
| 3194 | startRfDiscovery (false); |
| 3195 | } |
| 3196 | |
| 3197 | stat = SecureElement::getInstance().activate (seId); |
| 3198 | if (stat) |
| 3199 | { |
| 3200 | SecureElement::getInstance().routeToSecureElement (); |
| 3201 | sIsSecElemSelected++; |
| 3202 | // if(sHCEEnabled == false) |
| 3203 | // { |
| 3204 | // RoutingManager::getInstance().setRouting(false); |
| 3205 | // } |
| 3206 | } |
| 3207 | // sIsSecElemSelected = true; |
| 3208 | |
| 3209 | startRfDiscovery (true); |
| 3210 | PowerSwitch::getInstance ().setModeOn (PowerSwitch::SE_ROUTING); |
| 3211 | TheEnd: |
| 3212 | ALOGD ("%s: exit", __FUNCTION__); |
| 3213 | } |
| 3214 | |
| 3215 | /******************************************************************************* |
| 3216 | ** |
| 3217 | ** Function: nfcManager_doSetSEPowerOffState |
| 3218 | ** |
| 3219 | ** Description: NFC controller enable/disabe card emulation in power off |
| 3220 | ** state from EE. |
| 3221 | ** e: JVM environment. |
| 3222 | ** o: Java object. |
| 3223 | ** |
| 3224 | ** Returns: None |
| 3225 | ** |
| 3226 | *******************************************************************************/ |
| 3227 | static void nfcManager_doSetSEPowerOffState(JNIEnv *e, jobject o, jint seId, jboolean enable) |
| 3228 | { |
| 3229 | (void)e; |
| 3230 | (void)o; |
| 3231 | tNFA_HANDLE ee_handle; |
| 3232 | UINT8 power_state_mask = ~NFA_EE_PWR_STATE_SWITCH_OFF; |
| 3233 | |
| 3234 | if(enable == true) |
| 3235 | { |
| 3236 | power_state_mask = NFA_EE_PWR_STATE_SWITCH_OFF; |
| 3237 | } |
| 3238 | |
| 3239 | ee_handle = SecureElement::getInstance().getEseHandleFromGenericId(seId); |
| 3240 | |
| 3241 | if (sRfEnabled) { |
| 3242 | // Stop RF Discovery if we were polling |
| 3243 | startRfDiscovery (false); |
| 3244 | } |
| 3245 | |
| 3246 | tNFA_STATUS status = NFA_AddEePowerState(ee_handle,power_state_mask); |
| 3247 | |
| 3248 | |
| 3249 | // Commit the routing configuration |
| 3250 | status |= NFA_EeUpdateNow(); |
| 3251 | |
| 3252 | if (status != NFA_STATUS_OK) |
| 3253 | ALOGE("Failed to commit routing configuration"); |
| 3254 | |
| 3255 | startRfDiscovery (true); |
| 3256 | |
| 3257 | // TheEnd: /*commented to eliminate warning label defined but not used*/ |
| 3258 | ALOGD ("%s: exit", __FUNCTION__); |
| 3259 | |
| 3260 | } |
| 3261 | |
| 3262 | |
| 3263 | /******************************************************************************* |
| 3264 | ** |
| 3265 | ** Function: nfcManager_GetDefaultSE |
| 3266 | ** |
| 3267 | ** Description: Get default Secure Element. |
| 3268 | ** |
| 3269 | ** |
| 3270 | ** Returns: Returns 0. |
| 3271 | ** |
| 3272 | *******************************************************************************/ |
| 3273 | static jint nfcManager_GetDefaultSE(JNIEnv *e, jobject o) |
| 3274 | { |
| 3275 | (void)e; |
| 3276 | (void)o; |
| 3277 | unsigned long num; |
| 3278 | GetNxpNumValue (NAME_NXP_DEFAULT_SE, (void*)&num, sizeof(num)); |
| 3279 | ALOGD ("%lu: nfcManager_GetDefaultSE", num); |
| 3280 | return num; |
| 3281 | |
| 3282 | } |
| 3283 | |
| 3284 | |
| 3285 | static jint nfcManager_getSecureElementTechList(JNIEnv *e, jobject o) |
| 3286 | { |
| 3287 | (void)e; |
| 3288 | (void)o; |
| 3289 | uint8_t sak; |
| 3290 | jint tech = 0x00; |
| 3291 | ALOGD ("nfcManager_getSecureElementTechList -Enter"); |
| 3292 | sak = HciRFParams::getInstance().getESeSak(); |
| 3293 | bool isTypeBPresent = HciRFParams::getInstance().isTypeBSupported(); |
| 3294 | |
| 3295 | ALOGD ("nfcManager_getSecureElementTechList - sak is %0x", sak); |
| 3296 | |
| 3297 | if(sak & 0x08) |
| 3298 | { |
| 3299 | tech |= TARGET_TYPE_MIFARE_CLASSIC; |
| 3300 | } |
| 3301 | |
| 3302 | if( sak & 0x20 ) |
| 3303 | { |
| 3304 | tech |= NFA_TECHNOLOGY_MASK_A; |
| 3305 | } |
| 3306 | |
| 3307 | if( isTypeBPresent == true) |
| 3308 | { |
| 3309 | tech |= NFA_TECHNOLOGY_MASK_B; |
| 3310 | } |
| 3311 | ALOGD ("nfcManager_getSecureElementTechList - tech is %0x", tech); |
| 3312 | return tech; |
| 3313 | |
| 3314 | } |
| 3315 | |
| 3316 | static jintArray nfcManager_getActiveSecureElementList(JNIEnv *e, jobject o) |
| 3317 | { |
| 3318 | (void)e; |
| 3319 | (void)o; |
| 3320 | return SecureElement::getInstance().getActiveSecureElementList(e); |
| 3321 | } |
| 3322 | |
| 3323 | static void nfcManager_setSecureElementListenTechMask(JNIEnv *e, jobject o, jint tech_mask) |
| 3324 | { |
| 3325 | (void)e; |
| 3326 | (void)o; |
| 3327 | ALOGD ("%s: ENTER", __FUNCTION__); |
| 3328 | // tNFA_STATUS status; /*commented to eliminate unused variable warning*/ |
| 3329 | |
| 3330 | if (sRfEnabled) { |
| 3331 | // Stop RF Discovery if we were polling |
| 3332 | startRfDiscovery (false); |
| 3333 | } |
| 3334 | SecureElement::getInstance().setEseListenTechMask(tech_mask); |
| 3335 | |
| 3336 | startRfDiscovery (true); |
| 3337 | |
| 3338 | ALOGD ("%s: EXIT", __FUNCTION__); |
| 3339 | } |
| 3340 | |
| 3341 | |
| 3342 | static jbyteArray nfcManager_getSecureElementUid(JNIEnv *e, jobject o) |
| 3343 | { |
| 3344 | unsigned long num=0; |
| 3345 | jbyteArray jbuff = NULL; |
| 3346 | uint8_t bufflen = 0; |
| 3347 | uint8_t buf[16] = {0,}; |
| 3348 | |
| 3349 | ALOGD ("nfcManager_getSecureElementUid -Enter"); |
| 3350 | HciRFParams::getInstance().getESeUid(&buf[0], &bufflen); |
| 3351 | if(bufflen > 0) |
| 3352 | { |
| 3353 | jbuff = e->NewByteArray (bufflen); |
| 3354 | e->SetByteArrayRegion (jbuff, 0, bufflen, (jbyte*) buf); |
| 3355 | } |
| 3356 | return jbuff; |
| 3357 | } |
| 3358 | |
| 3359 | static tNFA_STATUS nfcManager_setEmvCoPollProfile(JNIEnv *e, jobject o, |
| 3360 | jboolean enable, jint route) |
| 3361 | { |
| 3362 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 3363 | tNFA_TECHNOLOGY_MASK tech_mask = 0; |
| 3364 | |
| 3365 | ALOGE("In nfcManager_setEmvCoPollProfile enable = 0x%x route = 0x%x", enable, route); |
| 3366 | /* Stop polling */ |
| 3367 | if ( isDiscoveryStarted()) |
| 3368 | { |
| 3369 | // Stop RF discovery to reconfigure |
| 3370 | startRfDiscovery(false); |
| 3371 | } |
| 3372 | |
| 3373 | status = EmvCo_dosetPoll(enable); |
| 3374 | if (status != NFA_STATUS_OK) |
| 3375 | { |
| 3376 | ALOGE ("%s: fail enable polling; error=0x%X", __FUNCTION__, status); |
| 3377 | goto TheEnd; |
| 3378 | } |
| 3379 | |
| 3380 | if (enable) |
| 3381 | { |
| 3382 | if (route == 0x00) |
| 3383 | { |
| 3384 | /* DH enable polling for A and B*/ |
| 3385 | tech_mask = NFA_TECHNOLOGY_MASK_A | NFA_TECHNOLOGY_MASK_B; |
| 3386 | } |
| 3387 | else if(route == 0x01) |
| 3388 | { |
| 3389 | /* UICC is end-point at present not supported by FW */ |
| 3390 | /* TBD : Get eeinfo (use handle appropirately, depending up |
| 3391 | * on it enable the polling */ |
| 3392 | } |
| 3393 | else if(route == 0x02) |
| 3394 | { |
| 3395 | /* ESE is end-point at present not supported by FW */ |
| 3396 | /* TBD : Get eeinfo (use handle appropirately, depending up |
| 3397 | * on it enable the polling */ |
| 3398 | } |
| 3399 | else |
| 3400 | { |
| 3401 | |
| 3402 | } |
| 3403 | } |
| 3404 | else |
| 3405 | { |
| 3406 | unsigned long num = 0; |
| 3407 | if (GetNumValue(NAME_POLLING_TECH_MASK, &num, sizeof(num))) |
| 3408 | tech_mask = num; |
| 3409 | } |
| 3410 | |
| 3411 | ALOGD ("%s: enable polling", __FUNCTION__); |
| 3412 | { |
| 3413 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 3414 | status = NFA_EnablePolling (tech_mask); |
| 3415 | if (status == NFA_STATUS_OK) |
| 3416 | { |
| 3417 | ALOGD ("%s: wait for enable event", __FUNCTION__); |
| 3418 | sNfaEnableDisablePollingEvent.wait (); //wait for NFA_POLL_ENABLED_EVT |
| 3419 | } |
| 3420 | else |
| 3421 | { |
| 3422 | ALOGE ("%s: fail enable polling; error=0x%X", __FUNCTION__, status); |
| 3423 | } |
| 3424 | } |
| 3425 | |
| 3426 | TheEnd: |
| 3427 | /* start polling */ |
| 3428 | if ( !isDiscoveryStarted()) |
| 3429 | { |
| 3430 | // Start RF discovery to reconfigure |
| 3431 | startRfDiscovery(true); |
| 3432 | } |
| 3433 | return status; |
| 3434 | |
| 3435 | } |
| 3436 | |
| 3437 | /******************************************************************************* |
| 3438 | ** |
| 3439 | ** Function: nfcManager_doDeselectSecureElement |
| 3440 | ** |
| 3441 | ** Description: NFC controller stops routing data in listen mode. |
| 3442 | ** e: JVM environment. |
| 3443 | ** o: Java object. |
| 3444 | ** |
| 3445 | ** Returns: None |
| 3446 | ** |
| 3447 | *******************************************************************************/ |
| 3448 | static void nfcManager_doDeselectSecureElement(JNIEnv *e, jobject o, jint seId) |
| 3449 | { |
| 3450 | (void)e; |
| 3451 | (void)o; |
| 3452 | ALOGD ("%s: enter", __FUNCTION__); |
| 3453 | bool stat = false; |
| 3454 | bool bRestartDiscovery = false; |
| 3455 | |
| 3456 | if (! sIsSecElemSelected) |
| 3457 | { |
| 3458 | ALOGE ("%s: already deselected", __FUNCTION__); |
| 3459 | goto TheEnd2; |
| 3460 | } |
| 3461 | |
| 3462 | if (PowerSwitch::getInstance ().getLevel() == PowerSwitch::LOW_POWER) |
| 3463 | { |
| 3464 | ALOGD ("%s: do not deselect while power is OFF", __FUNCTION__); |
| 3465 | // sIsSecElemSelected = false; |
| 3466 | sIsSecElemSelected--; |
| 3467 | goto TheEnd; |
| 3468 | } |
| 3469 | |
| 3470 | if (sRfEnabled) { |
| 3471 | // Stop RF Discovery if we were polling |
| 3472 | startRfDiscovery (false); |
| 3473 | bRestartDiscovery = true; |
| 3474 | } |
| 3475 | //sIsSecElemSelected = false; |
| 3476 | //sIsSecElemSelected--; |
| 3477 | |
| 3478 | //if controller is not routing to sec elems AND there is no pipe connected, |
| 3479 | //then turn off the sec elems |
| 3480 | if (SecureElement::getInstance().isBusy() == false) |
| 3481 | { |
| 3482 | //SecureElement::getInstance().deactivate (0xABCDEF); |
| 3483 | stat = SecureElement::getInstance().deactivate (seId); |
| 3484 | if(stat) |
| 3485 | { |
| 3486 | sIsSecElemSelected--; |
| 3487 | // RoutingManager::getInstance().commitRouting(); |
| 3488 | } |
| 3489 | } |
| 3490 | |
| 3491 | TheEnd: |
| 3492 | /* |
| 3493 | * conditional check is added to avoid multiple dicovery cmds |
| 3494 | * at the time of NFC OFF in progress |
| 3495 | */ |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 3496 | if ((gGeneralPowershutDown != NFC_MODE_OFF) && bRestartDiscovery) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 3497 | startRfDiscovery (true); |
| 3498 | |
| 3499 | //if nothing is active after this, then tell the controller to power down |
| 3500 | if (! PowerSwitch::getInstance ().setModeOff (PowerSwitch::SE_ROUTING)) |
| 3501 | PowerSwitch::getInstance ().setLevel (PowerSwitch::LOW_POWER); |
| 3502 | |
| 3503 | TheEnd2: |
| 3504 | ALOGD ("%s: exit", __FUNCTION__); |
| 3505 | } |
| 3506 | |
| 3507 | /******************************************************************************* |
| 3508 | ** |
| 3509 | ** Function: nfcManager_getDefaultAidRoute |
| 3510 | ** |
| 3511 | ** Description: Get the default Aid Route Entry. |
| 3512 | ** e: JVM environment. |
| 3513 | ** o: Java object. |
| 3514 | ** mode: Not used. |
| 3515 | ** |
| 3516 | ** Returns: None |
| 3517 | ** |
| 3518 | *******************************************************************************/ |
| 3519 | static jint nfcManager_getDefaultAidRoute (JNIEnv* e, jobject o) |
| 3520 | { |
| 3521 | unsigned long num = 0; |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 3522 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 3523 | GetNxpNumValue(NAME_DEFAULT_AID_ROUTE, &num, sizeof(num)); |
| 3524 | #endif |
| 3525 | return num; |
| 3526 | } |
| 3527 | /******************************************************************************* |
| 3528 | ** |
| 3529 | ** Function: nfcManager_getDefaultDesfireRoute |
| 3530 | ** |
| 3531 | ** Description: Get the default Desfire Route Entry. |
| 3532 | ** e: JVM environment. |
| 3533 | ** o: Java object. |
| 3534 | ** mode: Not used. |
| 3535 | ** |
| 3536 | ** Returns: None |
| 3537 | ** |
| 3538 | *******************************************************************************/ |
| 3539 | static jint nfcManager_getDefaultDesfireRoute (JNIEnv* e, jobject o) |
| 3540 | { |
| 3541 | unsigned long num = 0; |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 3542 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 3543 | GetNxpNumValue(NAME_DEFAULT_DESFIRE_ROUTE, (void*)&num, sizeof(num)); |
| 3544 | ALOGD ("%s: enter; NAME_DEFAULT_DESFIRE_ROUTE = %02x", __FUNCTION__, num); |
| 3545 | #endif |
| 3546 | return num; |
| 3547 | } |
| 3548 | /******************************************************************************* |
| 3549 | ** |
| 3550 | ** Function: nfcManager_getDefaultMifareCLTRoute |
| 3551 | ** |
| 3552 | ** Description: Get the default mifare CLT Route Entry. |
| 3553 | ** e: JVM environment. |
| 3554 | ** o: Java object. |
| 3555 | ** mode: Not used. |
| 3556 | ** |
| 3557 | ** Returns: None |
| 3558 | ** |
| 3559 | *******************************************************************************/ |
| 3560 | static jint nfcManager_getDefaultMifareCLTRoute (JNIEnv* e, jobject o) |
| 3561 | { |
| 3562 | unsigned long num = 0; |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 3563 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 3564 | GetNxpNumValue(NAME_DEFAULT_MIFARE_CLT_ROUTE, &num, sizeof(num)); |
| 3565 | #endif |
| 3566 | return num; |
| 3567 | } |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 3568 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 3569 | /******************************************************************************* |
| 3570 | ** |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 3571 | ** Function: nfcManager_getDefaultAidPowerState |
| 3572 | ** |
| 3573 | ** Description: Get the default Desfire Power States. |
| 3574 | ** e: JVM environment. |
| 3575 | ** o: Java object. |
| 3576 | ** |
| 3577 | ** Returns: Power State |
| 3578 | ** |
| 3579 | *******************************************************************************/ |
| 3580 | static jint nfcManager_getDefaultAidPowerState (JNIEnv* e, jobject o) |
| 3581 | { |
| 3582 | unsigned long num = 0; |
| 3583 | GetNxpNumValue(NAME_DEFAULT_AID_PWR_STATE, &num, sizeof(num)); |
| 3584 | return num; |
| 3585 | } |
| 3586 | |
| 3587 | /******************************************************************************* |
| 3588 | ** |
| 3589 | ** Function: nfcManager_getDefaultDesfirePowerState |
| 3590 | ** |
| 3591 | ** Description: Get the default Desfire Power States. |
| 3592 | ** e: JVM environment. |
| 3593 | ** o: Java object. |
| 3594 | ** |
| 3595 | ** Returns: Power State |
| 3596 | ** |
| 3597 | *******************************************************************************/ |
| 3598 | static jint nfcManager_getDefaultDesfirePowerState (JNIEnv* e, jobject o) |
| 3599 | { |
| 3600 | unsigned long num = 0; |
| 3601 | GetNxpNumValue(NAME_DEFAULT_DESFIRE_PWR_STATE, &num, sizeof(num)); |
| 3602 | return num; |
| 3603 | } |
| 3604 | /******************************************************************************* |
| 3605 | ** |
| 3606 | ** Function: nfcManager_getDefaultMifareCLTPowerState |
| 3607 | ** |
| 3608 | ** Description: Get the default mifare CLT Power States. |
| 3609 | ** e: JVM environment. |
| 3610 | ** o: Java object. |
| 3611 | ** |
| 3612 | ** Returns: Power State |
| 3613 | ** |
| 3614 | *******************************************************************************/ |
| 3615 | static jint nfcManager_getDefaultMifareCLTPowerState (JNIEnv* e, jobject o) |
| 3616 | { |
| 3617 | unsigned long num = 0; |
| 3618 | GetNxpNumValue(NAME_DEFAULT_MIFARE_CLT_PWR_STATE, &num, sizeof(num)); |
| 3619 | return num; |
| 3620 | } |
| 3621 | /******************************************************************************* |
| 3622 | ** |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 3623 | ** Function: nfcManager_setDefaultTechRoute |
| 3624 | ** |
| 3625 | ** Description: Setting Default Technology Routing |
| 3626 | ** e: JVM environment. |
| 3627 | ** o: Java object. |
| 3628 | ** seId: SecureElement Id |
| 3629 | ** tech_swithon: technology switch_on |
| 3630 | ** tech_switchoff: technology switch_off |
| 3631 | ** |
| 3632 | ** Returns: None |
| 3633 | ** |
| 3634 | *******************************************************************************/ |
| 3635 | static void nfcManager_setDefaultTechRoute(JNIEnv *e, jobject o, jint seId, |
| 3636 | jint tech_switchon, jint tech_switchoff) |
| 3637 | { |
| 3638 | (void)e; |
| 3639 | (void)o; |
| 3640 | ALOGD ("%s: ENTER", __FUNCTION__); |
| 3641 | // tNFA_STATUS status; /*commented to eliminate unused variable warning*/ |
| 3642 | |
| 3643 | if (sRfEnabled) { |
| 3644 | // Stop RF Discovery if we were polling |
| 3645 | startRfDiscovery (false); |
| 3646 | } |
| 3647 | RoutingManager::getInstance().setDefaultTechRouting (seId, tech_switchon, tech_switchoff); |
| 3648 | // start discovery. |
| 3649 | startRfDiscovery (true); |
| 3650 | } |
| 3651 | |
| 3652 | /******************************************************************************* |
| 3653 | ** |
| 3654 | ** Function: nfcManager_setDefaultProtoRoute |
| 3655 | ** |
| 3656 | ** Description: Setting Default Protocol Routing |
| 3657 | ** |
| 3658 | ** e: JVM environment. |
| 3659 | ** o: Java object. |
| 3660 | ** seId: SecureElement Id |
| 3661 | ** proto_swithon: Protocol switch_on |
| 3662 | ** proto_switchoff: Protocol switch_off |
| 3663 | ** |
| 3664 | ** Returns: None |
| 3665 | ** |
| 3666 | *******************************************************************************/ |
| 3667 | static void nfcManager_setDefaultProtoRoute(JNIEnv *e, jobject o, jint seId, |
| 3668 | jint proto_switchon, jint proto_switchoff) |
| 3669 | { |
| 3670 | (void)e; |
| 3671 | (void)o; |
| 3672 | ALOGD ("%s: ENTER", __FUNCTION__); |
| 3673 | // tNFA_STATUS status; /*commented to eliminate unused variable warning*/ |
| 3674 | // if (sRfEnabled) { |
| 3675 | // // Stop RF Discovery if we were polling |
| 3676 | // startRfDiscovery (false); |
| 3677 | // } |
| 3678 | RoutingManager::getInstance().setDefaultProtoRouting (seId, proto_switchon, proto_switchoff); |
| 3679 | // start discovery. |
| 3680 | // startRfDiscovery (true); |
| 3681 | } |
| 3682 | |
| 3683 | /******************************************************************************* |
| 3684 | ** |
| 3685 | ** Function: nfcManager_isVzwFeatureEnabled |
| 3686 | ** |
| 3687 | ** Description: Check vzw feature is enabled or not |
| 3688 | ** |
| 3689 | ** Returns: True if the VZW_FEATURE_ENABLE is set. |
| 3690 | ** |
| 3691 | *******************************************************************************/ |
| 3692 | static bool nfcManager_isVzwFeatureEnabled (JNIEnv *e, jobject o) |
| 3693 | { |
| 3694 | unsigned int num = 0; |
| 3695 | bool mStat = false; |
| 3696 | |
| 3697 | if (GetNxpNumValue("VZW_FEATURE_ENABLE", &num, sizeof(num))) |
| 3698 | { |
| 3699 | if(num == 0x01) |
| 3700 | { |
| 3701 | mStat = true; |
| 3702 | } |
| 3703 | else |
| 3704 | { |
| 3705 | mStat = false; |
| 3706 | } |
| 3707 | } |
| 3708 | else{ |
| 3709 | mStat = false; |
| 3710 | } |
| 3711 | return mStat; |
| 3712 | } |
| 3713 | #endif |
| 3714 | /******************************************************************************* |
| 3715 | ** |
| 3716 | ** Function: isPeerToPeer |
| 3717 | ** |
| 3718 | ** Description: Whether the activation data indicates the peer supports NFC-DEP. |
| 3719 | ** activated: Activation data. |
| 3720 | ** |
| 3721 | ** Returns: True if the peer supports NFC-DEP. |
| 3722 | ** |
| 3723 | *******************************************************************************/ |
| 3724 | static bool isPeerToPeer (tNFA_ACTIVATED& activated) |
| 3725 | { |
| 3726 | return activated.activate_ntf.protocol == NFA_PROTOCOL_NFC_DEP; |
| 3727 | } |
| 3728 | |
| 3729 | /******************************************************************************* |
| 3730 | ** |
| 3731 | ** Function: isListenMode |
| 3732 | ** |
| 3733 | ** Description: Indicates whether the activation data indicates it is |
| 3734 | ** listen mode. |
| 3735 | ** |
| 3736 | ** Returns: True if this listen mode. |
| 3737 | ** |
| 3738 | *******************************************************************************/ |
| 3739 | static bool isListenMode(tNFA_ACTIVATED& activated) |
| 3740 | { |
| 3741 | return ((NFC_DISCOVERY_TYPE_LISTEN_A == activated.activate_ntf.rf_tech_param.mode) |
| 3742 | || (NFC_DISCOVERY_TYPE_LISTEN_B == activated.activate_ntf.rf_tech_param.mode) |
| 3743 | || (NFC_DISCOVERY_TYPE_LISTEN_F == activated.activate_ntf.rf_tech_param.mode) |
| 3744 | || (NFC_DISCOVERY_TYPE_LISTEN_A_ACTIVE == activated.activate_ntf.rf_tech_param.mode) |
| 3745 | || (NFC_DISCOVERY_TYPE_LISTEN_F_ACTIVE == activated.activate_ntf.rf_tech_param.mode) |
| 3746 | || (NFC_DISCOVERY_TYPE_LISTEN_ISO15693 == activated.activate_ntf.rf_tech_param.mode) |
| 3747 | || (NFC_DISCOVERY_TYPE_LISTEN_B_PRIME == activated.activate_ntf.rf_tech_param.mode) |
| 3748 | || (NFC_INTERFACE_EE_DIRECT_RF == activated.activate_ntf.intf_param.type)); |
| 3749 | } |
| 3750 | |
| 3751 | /******************************************************************************* |
| 3752 | ** |
| 3753 | ** Function: nfcManager_doCheckLlcp |
| 3754 | ** |
| 3755 | ** Description: Not used. |
| 3756 | ** |
| 3757 | ** Returns: True |
| 3758 | ** |
| 3759 | *******************************************************************************/ |
| 3760 | static jboolean nfcManager_doCheckLlcp(JNIEnv*, jobject) |
| 3761 | { |
| 3762 | ALOGD("%s", __FUNCTION__); |
| 3763 | return JNI_TRUE; |
| 3764 | } |
| 3765 | |
| 3766 | |
| 3767 | static jboolean nfcManager_doCheckJcopDlAtBoot(JNIEnv* e, jobject o) |
| 3768 | { |
| 3769 | unsigned int num = 0; |
| 3770 | ALOGD("%s", __FUNCTION__); |
| 3771 | if(GetNxpNumValue(NAME_NXP_JCOPDL_AT_BOOT_ENABLE,(void*)&num,sizeof(num))) { |
| 3772 | if(num == 0x01) { |
| 3773 | return JNI_TRUE; |
| 3774 | } |
| 3775 | else { |
| 3776 | return JNI_FALSE; |
| 3777 | } |
| 3778 | } |
| 3779 | else { |
| 3780 | return JNI_FALSE; |
| 3781 | } |
| 3782 | } |
| 3783 | |
| 3784 | |
| 3785 | /******************************************************************************* |
| 3786 | ** |
| 3787 | ** Function: nfcManager_doActivateLlcp |
| 3788 | ** |
| 3789 | ** Description: Not used. |
| 3790 | ** |
| 3791 | ** Returns: True |
| 3792 | ** |
| 3793 | *******************************************************************************/ |
| 3794 | static jboolean nfcManager_doActivateLlcp(JNIEnv*, jobject) |
| 3795 | { |
| 3796 | ALOGD("%s", __FUNCTION__); |
| 3797 | return JNI_TRUE; |
| 3798 | } |
| 3799 | |
| 3800 | |
| 3801 | /******************************************************************************* |
| 3802 | ** |
| 3803 | ** Function: nfcManager_doAbort |
| 3804 | ** |
| 3805 | ** Description: Not used. |
| 3806 | ** |
| 3807 | ** Returns: None |
| 3808 | ** |
| 3809 | *******************************************************************************/ |
| 3810 | static void nfcManager_doAbort(JNIEnv*, jobject) |
| 3811 | { |
| 3812 | ALOGE("%s: abort()", __FUNCTION__); |
| 3813 | abort(); |
| 3814 | } |
| 3815 | |
| 3816 | |
| 3817 | /******************************************************************************* |
| 3818 | ** |
| 3819 | ** Function: nfcManager_doDownload |
| 3820 | ** |
| 3821 | ** Description: Download firmware patch files. Do not turn on NFC. |
| 3822 | ** |
| 3823 | ** Returns: True if ok. |
| 3824 | ** |
| 3825 | *******************************************************************************/ |
| 3826 | static jboolean nfcManager_doDownload(JNIEnv*, jobject) |
| 3827 | { |
| 3828 | ALOGD ("%s: enter", __FUNCTION__); |
| 3829 | NfcAdaptation& theInstance = NfcAdaptation::GetInstance(); |
| 3830 | |
| 3831 | theInstance.Initialize(); //start GKI, NCI task, NFC task |
| 3832 | theInstance.DownloadFirmware (); |
| 3833 | theInstance.Finalize(); |
| 3834 | ALOGD ("%s: exit", __FUNCTION__); |
| 3835 | return JNI_TRUE; |
| 3836 | } |
| 3837 | |
| 3838 | |
| 3839 | /******************************************************************************* |
| 3840 | ** |
| 3841 | ** Function: nfcManager_doResetTimeouts |
| 3842 | ** |
| 3843 | ** Description: Not used. |
| 3844 | ** |
| 3845 | ** Returns: None |
| 3846 | ** |
| 3847 | *******************************************************************************/ |
| 3848 | static void nfcManager_doResetTimeouts(JNIEnv*, jobject) |
| 3849 | { |
| 3850 | ALOGD ("%s", __FUNCTION__); |
| 3851 | NfcTag::getInstance().resetAllTransceiveTimeouts (); |
| 3852 | } |
| 3853 | |
| 3854 | |
| 3855 | /******************************************************************************* |
| 3856 | ** |
| 3857 | ** Function: nfcManager_doSetTimeout |
| 3858 | ** |
| 3859 | ** Description: Set timeout value. |
| 3860 | ** e: JVM environment. |
| 3861 | ** o: Java object. |
| 3862 | ** tech: technology ID. |
| 3863 | ** timeout: Timeout value. |
| 3864 | ** |
| 3865 | ** Returns: True if ok. |
| 3866 | ** |
| 3867 | *******************************************************************************/ |
| 3868 | static bool nfcManager_doSetTimeout(JNIEnv*, jobject, jint tech, jint timeout) |
| 3869 | { |
| 3870 | if (timeout <= 0) |
| 3871 | { |
| 3872 | ALOGE("%s: Timeout must be positive.",__FUNCTION__); |
| 3873 | return false; |
| 3874 | } |
| 3875 | ALOGD ("%s: tech=%d, timeout=%d", __FUNCTION__, tech, timeout); |
| 3876 | gGeneralTransceiveTimeout = timeout; |
| 3877 | NfcTag::getInstance().setTransceiveTimeout (tech, timeout); |
| 3878 | return true; |
| 3879 | } |
| 3880 | |
| 3881 | |
| 3882 | /******************************************************************************* |
| 3883 | ** |
| 3884 | ** Function: nfcManager_doGetTimeout |
| 3885 | ** |
| 3886 | ** Description: Get timeout value. |
| 3887 | ** e: JVM environment. |
| 3888 | ** o: Java object. |
| 3889 | ** tech: technology ID. |
| 3890 | ** |
| 3891 | ** Returns: Timeout value. |
| 3892 | ** |
| 3893 | *******************************************************************************/ |
| 3894 | static jint nfcManager_doGetTimeout(JNIEnv*, jobject, jint tech) |
| 3895 | { |
| 3896 | int timeout = NfcTag::getInstance().getTransceiveTimeout (tech); |
| 3897 | ALOGD ("%s: tech=%d, timeout=%d", __FUNCTION__, tech, timeout); |
| 3898 | return timeout; |
| 3899 | } |
| 3900 | |
| 3901 | |
| 3902 | /******************************************************************************* |
| 3903 | ** |
| 3904 | ** Function: nfcManager_doDump |
| 3905 | ** |
| 3906 | ** Description: Not used. |
| 3907 | ** e: JVM environment. |
| 3908 | ** o: Java object. |
| 3909 | ** |
| 3910 | ** Returns: Text dump. |
| 3911 | ** |
| 3912 | *******************************************************************************/ |
| 3913 | static jstring nfcManager_doDump(JNIEnv* e, jobject) |
| 3914 | { |
| 3915 | char buffer[100]; |
| 3916 | snprintf(buffer, sizeof(buffer), "libnfc llc error_count=%u", /*libnfc_llc_error_count*/ 0); |
| 3917 | return e->NewStringUTF(buffer); |
| 3918 | } |
| 3919 | |
| 3920 | |
| 3921 | /******************************************************************************* |
| 3922 | ** |
| 3923 | ** Function: nfcManager_doSetP2pInitiatorModes |
| 3924 | ** |
| 3925 | ** Description: Set P2P initiator's activation modes. |
| 3926 | ** e: JVM environment. |
| 3927 | ** o: Java object. |
| 3928 | ** modes: Active and/or passive modes. The values are specified |
| 3929 | ** in external/libnfc-nxp/inc/phNfcTypes.h. See |
| 3930 | ** enum phNfc_eP2PMode_t. |
| 3931 | ** |
| 3932 | ** Returns: None. |
| 3933 | ** |
| 3934 | *******************************************************************************/ |
| 3935 | static void nfcManager_doSetP2pInitiatorModes (JNIEnv *e, jobject o, jint modes) |
| 3936 | { |
| 3937 | ALOGD ("%s: modes=0x%X", __FUNCTION__, modes); |
| 3938 | struct nfc_jni_native_data *nat = getNative(e, o); |
| 3939 | |
| 3940 | tNFA_TECHNOLOGY_MASK mask = 0; |
| 3941 | if (modes & 0x01) mask |= NFA_TECHNOLOGY_MASK_A; |
| 3942 | if (modes & 0x02) mask |= NFA_TECHNOLOGY_MASK_F; |
| 3943 | if (modes & 0x04) mask |= NFA_TECHNOLOGY_MASK_F; |
| 3944 | if (modes & 0x08) mask |= NFA_TECHNOLOGY_MASK_A_ACTIVE; |
| 3945 | if (modes & 0x10) mask |= NFA_TECHNOLOGY_MASK_F_ACTIVE; |
| 3946 | if (modes & 0x20) mask |= NFA_TECHNOLOGY_MASK_F_ACTIVE; |
| 3947 | nat->tech_mask = mask; |
| 3948 | } |
| 3949 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 3950 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 3951 | /******************************************************************************* |
| 3952 | ** |
| 3953 | ** Function: nfcManager_getRouting |
| 3954 | ** |
| 3955 | ** Description: Get Routing Table information. |
| 3956 | ** e: JVM environment. |
| 3957 | ** o: Java object. |
| 3958 | ** |
| 3959 | ** Returns: Current routing Settings. |
| 3960 | ** |
| 3961 | *******************************************************************************/ |
| 3962 | static jbyteArray nfcManager_getRouting (JNIEnv *e, jobject o) |
| 3963 | { |
| 3964 | ALOGD ("%s : Enter", __FUNCTION__); |
| 3965 | jbyteArray jbuff = NULL; |
| 3966 | if (sRfEnabled) { |
| 3967 | // Stop RF Discovery if we were polling |
| 3968 | startRfDiscovery (false); |
| 3969 | } |
| 3970 | SyncEventGuard guard (sNfaGetRoutingEvent); |
| 3971 | sRoutingBuffLen = 0; |
| 3972 | RoutingManager::getInstance().getRouting(); |
| 3973 | sNfaGetRoutingEvent.wait (); |
| 3974 | if(sRoutingBuffLen > 0) |
| 3975 | { |
| 3976 | jbuff = e->NewByteArray (sRoutingBuffLen); |
| 3977 | e->SetByteArrayRegion (jbuff, 0, sRoutingBuffLen, (jbyte*) sRoutingBuff); |
| 3978 | } |
| 3979 | |
| 3980 | startRfDiscovery(true); |
| 3981 | return jbuff; |
| 3982 | } |
| 3983 | |
| 3984 | /******************************************************************************* |
| 3985 | ** |
| 3986 | ** Function: nfcManager_getNfcInitTimeout |
| 3987 | ** |
| 3988 | ** Description: Gets the chip version. |
| 3989 | ** e: JVM environment. |
| 3990 | ** o: Java object. |
| 3991 | ** |
| 3992 | ** Returns: timeout in seconds |
| 3993 | ** |
| 3994 | *******************************************************************************/ |
| 3995 | static int nfcManager_getNfcInitTimeout(JNIEnv* e, jobject o) |
| 3996 | { |
| 3997 | (void)e; |
| 3998 | (void)o; |
| 3999 | ALOGD ("%s: enter", __FUNCTION__); |
| 4000 | unsigned long disc_timeout =0; |
| 4001 | unsigned long session_id_timeout =0; |
| 4002 | disc_timeout = 0; |
| 4003 | gNfcInitTimeout = 0; |
| 4004 | gdisc_timeout = 0; |
| 4005 | |
| 4006 | if(GetNxpNumValue(NAME_NXP_DEFAULT_NFCEE_DISC_TIMEOUT, (void *)&disc_timeout, sizeof(disc_timeout))==false) |
| 4007 | { |
| 4008 | ALOGD ("NAME_NXP_DEFAULT_NFCEE_DISC_TIMEOUT not found"); |
| 4009 | disc_timeout = 0; |
| 4010 | } |
| 4011 | if(GetNxpNumValue(NAME_NXP_DEFAULT_NFCEE_TIMEOUT, (void *)&session_id_timeout, |
| 4012 | sizeof(session_id_timeout))==false) |
| 4013 | { |
| 4014 | ALOGD ("NAME_NXP_DEFAULT_NFCEE_TIMEOUT not found"); |
| 4015 | session_id_timeout = 0; |
| 4016 | } |
| 4017 | |
| 4018 | gNfcInitTimeout = (disc_timeout + session_id_timeout) *1000; |
| 4019 | gdisc_timeout = disc_timeout *1000; |
| 4020 | |
| 4021 | ALOGD (" gNfcInitTimeout = %d: gdisc_timeout = %d nfcManager_getNfcInitTimeout", |
| 4022 | gNfcInitTimeout, gdisc_timeout); |
| 4023 | return gNfcInitTimeout; |
| 4024 | } |
| 4025 | |
| 4026 | #endif |
| 4027 | |
| 4028 | /******************************************************************************* |
| 4029 | ** |
| 4030 | ** Function: nfcManager_doSetP2pTargetModes |
| 4031 | ** |
| 4032 | ** Description: Set P2P target's activation modes. |
| 4033 | ** e: JVM environment. |
| 4034 | ** o: Java object. |
| 4035 | ** modes: Active and/or passive modes. |
| 4036 | ** |
| 4037 | ** Returns: None. |
| 4038 | ** |
| 4039 | *******************************************************************************/ |
| 4040 | static void nfcManager_doSetP2pTargetModes (JNIEnv*, jobject, jint modes) |
| 4041 | { |
| 4042 | ALOGD ("%s: modes=0x%X", __FUNCTION__, modes); |
| 4043 | // Map in the right modes |
| 4044 | tNFA_TECHNOLOGY_MASK mask = 0; |
| 4045 | if (modes & 0x01) mask |= NFA_TECHNOLOGY_MASK_A; |
| 4046 | if (modes & 0x02) mask |= NFA_TECHNOLOGY_MASK_F; |
| 4047 | if (modes & 0x04) mask |= NFA_TECHNOLOGY_MASK_F; |
| 4048 | if (modes & 0x08) mask |= NFA_TECHNOLOGY_MASK_A_ACTIVE | NFA_TECHNOLOGY_MASK_F_ACTIVE; |
| 4049 | |
| 4050 | PeerToPeer::getInstance().setP2pListenMask(mask); |
| 4051 | } |
| 4052 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 4053 | #if((NFC_NXP_ESE == TRUE) && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 4054 | /******************************************************************************* |
| 4055 | ** |
| 4056 | ** Function: nfcManager_dosetEtsiReaederState |
| 4057 | ** |
| 4058 | ** Description: Set ETSI reader state |
| 4059 | ** e: JVM environment. |
| 4060 | ** o: Java object. |
| 4061 | ** newState : new state to be set |
| 4062 | ** |
| 4063 | ** Returns: None. |
| 4064 | ** |
| 4065 | *******************************************************************************/ |
| 4066 | static void nfcManager_dosetEtsiReaederState (JNIEnv*, jobject, se_rd_req_state_t newState) |
| 4067 | { |
| 4068 | ALOGD ("%s: Enter ", __FUNCTION__); |
| 4069 | RoutingManager::getInstance().setEtsiReaederState(newState); |
| 4070 | } |
| 4071 | |
| 4072 | /******************************************************************************* |
| 4073 | ** |
| 4074 | ** Function: nfcManager_dogetEtsiReaederState |
| 4075 | ** |
| 4076 | ** Description: Get current ETSI reader state |
| 4077 | ** e: JVM environment. |
| 4078 | ** o: Java object. |
| 4079 | ** |
| 4080 | ** Returns: State. |
| 4081 | ** |
| 4082 | *******************************************************************************/ |
| 4083 | static int nfcManager_dogetEtsiReaederState (JNIEnv*, jobject) |
| 4084 | { |
| 4085 | ALOGD ("%s: Enter ", __FUNCTION__); |
| 4086 | return RoutingManager::getInstance().getEtsiReaederState(); |
| 4087 | } |
| 4088 | |
| 4089 | /******************************************************************************* |
| 4090 | ** |
| 4091 | ** Function: nfcManager_doEtsiReaderConfig |
| 4092 | ** |
| 4093 | ** Description: Configuring to Emvco profile |
| 4094 | ** e: JVM environment. |
| 4095 | ** o: Java object. |
| 4096 | ** |
| 4097 | ** Returns: None. |
| 4098 | ** |
| 4099 | *******************************************************************************/ |
| 4100 | static void nfcManager_doEtsiReaderConfig (JNIEnv*, jobject, int eeHandle) |
| 4101 | { |
| 4102 | tNFC_STATUS status; |
| 4103 | ALOGD ("%s: Enter ", __FUNCTION__); |
| 4104 | status = SecureElement::getInstance().etsiReaderConfig(eeHandle); |
| 4105 | if(status != NFA_STATUS_OK) |
| 4106 | { |
| 4107 | ALOGD ("%s: etsiReaderConfig Failed ", __FUNCTION__); |
| 4108 | } |
| 4109 | else |
| 4110 | { |
| 4111 | ALOGD ("%s: etsiReaderConfig Success ", __FUNCTION__); |
| 4112 | } |
| 4113 | } |
| 4114 | |
| 4115 | /******************************************************************************* |
| 4116 | ** |
| 4117 | ** Function: nfcManager_doEtsiResetReaderConfig |
| 4118 | ** |
| 4119 | ** Description: Configuring to Nfc forum profile |
| 4120 | ** e: JVM environment. |
| 4121 | ** o: Java object. |
| 4122 | ** |
| 4123 | ** Returns: None. |
| 4124 | ** |
| 4125 | *******************************************************************************/ |
| 4126 | static void nfcManager_doEtsiResetReaderConfig (JNIEnv*, jobject) |
| 4127 | { |
| 4128 | tNFC_STATUS status; |
| 4129 | ALOGD ("%s: Enter ", __FUNCTION__); |
| 4130 | status = SecureElement::getInstance().etsiResetReaderConfig(); |
| 4131 | if(status != NFA_STATUS_OK) |
| 4132 | { |
| 4133 | ALOGD ("%s: etsiReaderConfig Failed ", __FUNCTION__); |
| 4134 | } |
| 4135 | else |
| 4136 | { |
| 4137 | ALOGD ("%s: etsiReaderConfig Success ", __FUNCTION__); |
| 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | /******************************************************************************* |
| 4142 | ** |
| 4143 | ** Function: nfcManager_doNotifyEEReaderEvent |
| 4144 | ** |
| 4145 | ** Description: Notify with the Reader event |
| 4146 | ** e: JVM environment. |
| 4147 | ** o: Java object. |
| 4148 | ** |
| 4149 | ** Returns: None. |
| 4150 | ** |
| 4151 | *******************************************************************************/ |
| 4152 | static void nfcManager_doNotifyEEReaderEvent (JNIEnv*, jobject, int evt) |
| 4153 | { |
| 4154 | ALOGD ("%s: Enter ", __FUNCTION__); |
| 4155 | |
| 4156 | SecureElement::getInstance().notifyEEReaderEvent(evt,swp_rdr_req_ntf_info.swp_rd_req_info.tech_mask); |
| 4157 | |
| 4158 | } |
| 4159 | |
| 4160 | /******************************************************************************* |
| 4161 | ** |
| 4162 | ** Function: nfcManager_doEtsiInitConfig |
| 4163 | ** |
| 4164 | ** Description: Chnage the ETSI state before start configuration |
| 4165 | ** e: JVM environment. |
| 4166 | ** o: Java object. |
| 4167 | ** |
| 4168 | ** Returns: None. |
| 4169 | ** |
| 4170 | *******************************************************************************/ |
| 4171 | static void nfcManager_doEtsiInitConfig (JNIEnv*, jobject, int evt) |
| 4172 | { |
| 4173 | ALOGD ("%s: Enter ", __FUNCTION__); |
| 4174 | SecureElement::getInstance().etsiInitConfig(); |
| 4175 | } |
| 4176 | #endif |
| 4177 | |
| 4178 | static void nfcManager_doEnableScreenOffSuspend(JNIEnv* e, jobject o) |
| 4179 | { |
| 4180 | PowerSwitch::getInstance().setScreenOffPowerState(PowerSwitch::POWER_STATE_FULL); |
| 4181 | } |
| 4182 | |
| 4183 | static void nfcManager_doDisableScreenOffSuspend(JNIEnv* e, jobject o) |
| 4184 | { |
| 4185 | PowerSwitch::getInstance().setScreenOffPowerState(PowerSwitch::POWER_STATE_OFF); |
| 4186 | } |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 4187 | #if((NFC_NXP_ESE == TRUE) && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 4188 | /******************************************************************************* |
| 4189 | ** |
| 4190 | ** Function: nfcManager_doUpdateScreenState |
| 4191 | ** |
| 4192 | ** Description: Update If any Pending screen state is present |
| 4193 | ** e: JVM environment. |
| 4194 | ** o: Java object. |
| 4195 | ** |
| 4196 | ** Returns: None. |
| 4197 | ** |
| 4198 | *******************************************************************************/ |
| 4199 | static void nfcManager_doUpdateScreenState(JNIEnv* e, jobject o) |
| 4200 | { |
| 4201 | ALOGD ("%s: Enter ", __FUNCTION__); |
| 4202 | eScreenState_t last_screen_state_request; |
| 4203 | |
| 4204 | if(pendingScreenState == true) |
| 4205 | { |
| 4206 | ALOGD ("%s: pendingScreenState = TRUE ", __FUNCTION__); |
| 4207 | pendingScreenState = false; |
| 4208 | last_screen_state_request = get_lastScreenStateRequest(); |
| 4209 | nfcManager_doSetScreenState(NULL,NULL,last_screen_state_request); |
| 4210 | } |
| 4211 | else |
| 4212 | { |
| 4213 | ALOGD ("%s: pendingScreenState = FALSE ", __FUNCTION__); |
| 4214 | } |
| 4215 | } |
| 4216 | #endif |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 4217 | #if(NXP_EXTNS == TRUE) |
| 4218 | /******************************************************************************* |
| 4219 | ** |
| 4220 | ** Function: nfcManager_doSelectUicc() |
| 4221 | ** |
| 4222 | ** Description: Issue any single TLV set config command as per input |
| 4223 | ** register values and bit values |
| 4224 | ** |
| 4225 | ** Returns: success/failure |
| 4226 | ** |
| 4227 | *******************************************************************************/ |
| 4228 | static int nfcManager_doSelectUicc(JNIEnv* e, jobject o, jint uiccSlot) |
| 4229 | { |
| 4230 | (void)e; |
| 4231 | (void)o; |
| 4232 | uint8_t retStat = STATUS_UNKNOWN_ERROR; |
| 4233 | #if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE) |
| 4234 | tNFA_STATUS status = NFC_STATUS_FAILED; |
| 4235 | ALOGD("%s: enter", __FUNCTION__); |
| 4236 | ALOGD("%s: sUicc1CntxLen : 0x%02x sUicc2CntxLen : 0x%02x", __FUNCTION__,dualUiccInfo.sUicc1CntxLen,dualUiccInfo.sUicc2CntxLen); |
| 4237 | tNFA_STATUS stat = NFA_STATUS_FAILED; |
| 4238 | BOOLEAN result =FALSE; |
| 4239 | UINT16 RegAddr = 0xA0EC; |
| 4240 | uint8_t bitVal; |
| 4241 | eScreenState_t last_screen_state_request; |
| 4242 | dualUiccInfo.uiccConfigStat = UICC_NOT_CONFIGURED; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 4243 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 4244 | RoutingManager& routingManager = RoutingManager::getInstance(); |
| 4245 | SecureElement &se = SecureElement::getInstance(); |
| 4246 | |
| 4247 | retStat = nfcManager_staticDualUicc_Precondition(uiccSlot); |
| 4248 | |
| 4249 | if(retStat != UICC_NOT_CONFIGURED) |
| 4250 | { |
| 4251 | goto endSwitch; |
| 4252 | } |
| 4253 | |
| 4254 | if(sRfEnabled) |
| 4255 | { |
| 4256 | startRfDiscovery(false); |
| 4257 | } |
| 4258 | |
| 4259 | bitVal = ((0x10) | uiccSlot); |
| 4260 | |
| 4261 | if((dualUiccInfo.sUicc1CntxLen !=0)||(dualUiccInfo.sUicc2CntxLen !=0)) |
| 4262 | { |
| 4263 | if((bitVal == 0x11)&&(dualUiccInfo.sUicc1CntxLen !=0)) |
| 4264 | { |
| 4265 | ALOGD ("%s : update uicc1 context information ", __FUNCTION__); |
| 4266 | UINT8 cfg[256] = {0x20,0x02}; |
| 4267 | |
| 4268 | memcpy(cfg+3, dualUiccInfo.sUicc1Cntx, dualUiccInfo.sUicc1CntxLen); |
| 4269 | cfg[2] = dualUiccInfo.sUicc1CntxLen-1; |
| 4270 | status = NxpNfc_Write_Cmd_Common(dualUiccInfo.sUicc1CntxLen+2, cfg); |
| 4271 | |
| 4272 | memcpy(cfg+3, dualUiccInfo.sUicc1TechCapblty, 10); |
| 4273 | cfg[2] = 9; |
| 4274 | status = NxpNfc_Write_Cmd_Common(12, cfg); |
| 4275 | |
| 4276 | } |
| 4277 | else if((bitVal == 0x12)&&(dualUiccInfo.sUicc2CntxLen !=0)) |
| 4278 | { |
| 4279 | ALOGD ("%s : update uicc2 context information", __FUNCTION__); |
| 4280 | UINT8 cfg[256] = {0x20,0x02}; |
| 4281 | memcpy(cfg+3, dualUiccInfo.sUicc2Cntx, dualUiccInfo.sUicc2CntxLen); |
| 4282 | cfg[2] = dualUiccInfo.sUicc2CntxLen-1; |
| 4283 | status = NxpNfc_Write_Cmd_Common(dualUiccInfo.sUicc2CntxLen+2, cfg); |
| 4284 | |
| 4285 | memcpy(cfg+3, dualUiccInfo.sUicc2TechCapblty, 10); |
| 4286 | cfg[2] = 9; |
| 4287 | status = NxpNfc_Write_Cmd_Common(12, cfg); |
| 4288 | } |
| 4289 | } |
| 4290 | |
| 4291 | /*Update NFCC SWIO line accordingly*/ |
| 4292 | if((Set_EERegisterValue(RegAddr, bitVal) != NFCSTATUS_OK)) |
| 4293 | { |
| 4294 | retStat = DUAL_UICC_ERROR_SELECT_FAILED; |
| 4295 | ALOGE ("%s : Set_EERegisterValue Failed", __FUNCTION__); |
| 4296 | goto endSwitch; |
| 4297 | } |
| 4298 | |
| 4299 | /*Mode Set Off for UICC*/ |
| 4300 | { |
| 4301 | SyncEventGuard guard (routingManager.mEeSetModeEvent); |
| 4302 | if ((NFA_EeModeSet (0x02, NFA_EE_MD_DEACTIVATE)) == NFA_STATUS_OK) |
| 4303 | { |
| 4304 | routingManager.mEeSetModeEvent.wait (); //wait for NFA_EE_MODE_SET_EVT |
| 4305 | } |
| 4306 | else |
| 4307 | { |
| 4308 | ALOGE ("%s : Failed to set EE inactive", __FUNCTION__); |
| 4309 | goto endSwitch; |
| 4310 | } |
| 4311 | } |
| 4312 | gSeDiscoverycount = 0; |
| 4313 | /*Perform HAL re-initialisation |
| 4314 | * NFA EE and HCI Subsystem de-init*/ |
| 4315 | { |
| 4316 | SyncEventGuard guard (sNfceeHciCbDisableEvent); |
| 4317 | NFA_EE_HCI_Control(false); |
| 4318 | sNfceeHciCbDisableEvent.wait(); |
| 4319 | } |
| 4320 | |
| 4321 | /*Reset Nfcc*/ |
| 4322 | status = NFA_ResetNfcc(); |
| 4323 | /*Perform NFA EE and HCI Subsystem initialisation*/ |
| 4324 | { |
| 4325 | SyncEventGuard guard (sNfceeHciCbEnableEvent); |
| 4326 | NFA_EE_HCI_Control(true); |
| 4327 | sNfceeHciCbEnableEvent.wait (); |
| 4328 | } |
| 4329 | |
| 4330 | { |
| 4331 | se.updateEEStatus(); |
| 4332 | //setListenMode(); |
| 4333 | routingManager.initialize(getNative(e, o)); |
| 4334 | HciRFParams::getInstance().initialize (); |
| 4335 | sIsSecElemSelected = (se.getActualNumEe() - 1 ); |
| 4336 | sIsSecElemDetected = sIsSecElemSelected; |
| 4337 | } |
| 4338 | |
| 4339 | ALOGD("%s : gSeDiscoverycount = %d", __FUNCTION__ , gSeDiscoverycount); |
| 4340 | /*Get the SWP1 and SWP2 lines status*/ |
| 4341 | if (NFA_STATUS_OK == GetSwpStausValue()) |
| 4342 | { |
| 4343 | /*The SWP lines enabled and SE's discovered*/ |
| 4344 | if (gSeDiscoverycount < gActualSeCount) |
| 4345 | { |
| 4346 | ALOGD("%s : Wait for ESE to discover, gdisc_timeout = %d", __FUNCTION__, gdisc_timeout); |
| 4347 | SyncEventGuard g(gNfceeDiscCbEvent); |
| 4348 | if(gNfceeDiscCbEvent.wait(gdisc_timeout) == false) |
| 4349 | { |
| 4350 | ALOGE ("%s: timeout waiting for nfcee dis event", __FUNCTION__); |
| 4351 | } |
| 4352 | } |
| 4353 | else |
| 4354 | { |
| 4355 | ALOGD("%s : All ESE are discovered ", __FUNCTION__); |
| 4356 | } |
| 4357 | } |
| 4358 | /*Get the eSE and UICC parameters for RF*/ |
| 4359 | checkforNfceeConfig(); |
| 4360 | |
| 4361 | if(se.getEeStatus(UICC_HANDLE) == NFC_NFCEE_STATUS_REMOVED) |
| 4362 | { |
| 4363 | ALOGD("%s : UICC 0x%02x status : NFC_NFCEE_STATUS_REMOVED. Clearing buffer", __FUNCTION__,sSelectedUicc); |
| 4364 | if((sSelectedUicc == 0x01)&&(dualUiccInfo.sUicc1CntxLen != 0x00)) |
| 4365 | { |
| 4366 | memset(dualUiccInfo.sUicc1Cntx,0x00,sizeof(dualUiccInfo.sUicc1Cntx)); |
| 4367 | dualUiccInfo.sUicc1CntxLen = 0x00; |
| 4368 | } |
| 4369 | else if((sSelectedUicc == 0x02)&&(dualUiccInfo.sUicc2CntxLen != 0x00)) |
| 4370 | { |
| 4371 | memset(dualUiccInfo.sUicc2Cntx,0x00,sizeof(dualUiccInfo.sUicc2Cntx)); |
| 4372 | dualUiccInfo.sUicc2CntxLen = 0x00; |
| 4373 | } |
| 4374 | } |
| 4375 | |
| 4376 | retStat = dualUiccInfo.uiccConfigStat; |
| 4377 | |
| 4378 | endSwitch: |
| 4379 | if((retStat == UICC_CONFIGURED) || (retStat == UICC_NOT_CONFIGURED)) |
| 4380 | { |
| 4381 | if(get_transcation_stat() == true) |
| 4382 | { |
| 4383 | /*Apply screen state if pending*/ |
| 4384 | set_transcation_stat(false); |
| 4385 | if(pendingScreenState == true) |
| 4386 | { |
| 4387 | pendingScreenState = false; |
| 4388 | last_screen_state_request = get_lastScreenStateRequest(); |
| 4389 | nfcManager_doSetScreenState(NULL,NULL,last_screen_state_request); |
| 4390 | } |
| 4391 | } |
| 4392 | } |
| 4393 | |
| 4394 | /*If retStat is success then routing table will be reconfigured from NfcService |
| 4395 | * As a part of commitRouting startRfDiscovery will be called. |
| 4396 | * If retStat is failed then NfcService will not reconfigured routing table |
| 4397 | * So do startRfDiscovery here*/ |
| 4398 | if((retStat != UICC_CONFIGURED) && (retStat != UICC_NOT_CONFIGURED) && (!sRfEnabled)) |
| 4399 | { |
| 4400 | startRfDiscovery(true); |
| 4401 | } |
| 4402 | |
| 4403 | ALOGD("%s: exit retStat = %d", __FUNCTION__, retStat); |
| 4404 | #else |
| 4405 | retStat = DUAL_UICC_FEATURE_NOT_AVAILABLE; |
| 4406 | ALOGD("%s: Dual uicc not supported retStat = %d", __FUNCTION__, retStat); |
| 4407 | #endif |
| 4408 | return retStat; |
| 4409 | } |
| 4410 | |
| 4411 | /******************************************************************************* |
| 4412 | ** |
| 4413 | ** Function: nfcManager_doGetSelectedUicc() |
| 4414 | ** |
| 4415 | ** Description: get the current selected active UICC |
| 4416 | ** |
| 4417 | ** Returns: UICC id |
| 4418 | ** |
| 4419 | *******************************************************************************/ |
| 4420 | static int nfcManager_doGetSelectedUicc(JNIEnv* e, jobject o) |
| 4421 | { |
| 4422 | uint8_t uicc_stat = STATUS_UNKNOWN_ERROR; |
| 4423 | #if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE) |
| 4424 | ALOGD ("%s: enter ",__FUNCTION__); |
| 4425 | uicc_stat = SecureElement::getInstance().getUiccStatus(sSelectedUicc); |
| 4426 | #else |
| 4427 | ALOGD ("%s: dual uicc not supported ",__FUNCTION__); |
| 4428 | uicc_stat = DUAL_UICC_FEATURE_NOT_AVAILABLE; |
| 4429 | #endif |
| 4430 | return uicc_stat; |
| 4431 | } |
| 4432 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 4433 | /***************************************************************************** |
| 4434 | ** |
| 4435 | ** JNI functions for android-4.0.1_r1 |
| 4436 | ** |
| 4437 | *****************************************************************************/ |
| 4438 | static JNINativeMethod gMethods[] = |
| 4439 | { |
| 4440 | {"doDownload", "()Z", |
| 4441 | (void *)nfcManager_doDownload}, |
| 4442 | |
| 4443 | {"initializeNativeStructure", "()Z", |
| 4444 | (void*) nfcManager_initNativeStruc}, |
| 4445 | |
| 4446 | {"doInitialize", "()Z", |
| 4447 | (void*) nfcManager_doInitialize}, |
| 4448 | |
| 4449 | {"doDeinitialize", "()Z", |
| 4450 | (void*) nfcManager_doDeinitialize}, |
| 4451 | |
| 4452 | {"sendRawFrame", "([B)Z", |
| 4453 | (void*) nfcManager_sendRawFrame}, |
| 4454 | |
| 4455 | {"doRouteAid", "([BIIZ)Z", |
| 4456 | (void*) nfcManager_routeAid}, |
| 4457 | |
| 4458 | {"doRouteNfcid2", "([B[B[B)I", |
| 4459 | (void*) nfcManager_routeNfcid2}, |
| 4460 | |
| 4461 | {"doUnRouteNfcid2", "([B)Z", |
| 4462 | (void*) nfcManager_unrouteNfcid2}, |
| 4463 | |
| 4464 | |
| 4465 | {"doUnrouteAid", "([B)Z", |
| 4466 | (void*) nfcManager_unrouteAid}, |
| 4467 | |
| 4468 | {"doSetRoutingEntry", "(IIII)Z", |
| 4469 | (void*)nfcManager_setRoutingEntry}, |
| 4470 | |
| 4471 | {"doClearRoutingEntry", "(I)Z", |
| 4472 | (void*)nfcManager_clearRoutingEntry}, |
| 4473 | |
| 4474 | {"clearAidTable", "()Z", |
| 4475 | (void*) nfcManager_clearAidTable}, |
| 4476 | |
| 4477 | {"setDefaultRoute", "(III)Z", |
| 4478 | (void*) nfcManager_setDefaultRoute}, |
| 4479 | |
| 4480 | {"getAidTableSize", "()I", |
| 4481 | (void*) nfcManager_getAidTableSize}, |
| 4482 | |
| 4483 | {"getRemainingAidTableSize", "()I", |
| 4484 | (void*) nfcManager_getRemainingAidTableSize}, |
| 4485 | |
| 4486 | {"getDefaultAidRoute", "()I", |
| 4487 | (void*) nfcManager_getDefaultAidRoute}, |
| 4488 | |
| 4489 | {"getDefaultDesfireRoute", "()I", |
| 4490 | (void*) nfcManager_getDefaultDesfireRoute}, |
| 4491 | |
| 4492 | {"getDefaultMifareCLTRoute", "()I", |
| 4493 | (void*) nfcManager_getDefaultMifareCLTRoute}, |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 4494 | #if(NXP_EXTNS == TRUE) |
| 4495 | {"getDefaultAidPowerState", "()I", |
| 4496 | (void*) nfcManager_getDefaultAidPowerState}, |
| 4497 | |
| 4498 | {"getDefaultDesfirePowerState", "()I", |
| 4499 | (void*) nfcManager_getDefaultDesfirePowerState}, |
| 4500 | |
| 4501 | {"getDefaultMifareCLTPowerState", "()I", |
| 4502 | (void*) nfcManager_getDefaultMifareCLTPowerState}, |
| 4503 | #endif |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 4504 | {"doRegisterT3tIdentifier", "([B)I", |
| 4505 | (void*) nfcManager_doRegisterT3tIdentifier}, |
| 4506 | |
| 4507 | {"doDeregisterT3tIdentifier", "(I)V", |
| 4508 | (void*) nfcManager_doDeregisterT3tIdentifier}, |
| 4509 | |
| 4510 | {"getLfT3tMax", "()I", |
| 4511 | (void*) nfcManager_getLfT3tMax}, |
| 4512 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 4513 | {"doEnableDiscovery", "(IZZZZZ)V", |
| 4514 | (void*) nfcManager_enableDiscovery}, |
| 4515 | |
| 4516 | {"doGetSecureElementList", "()[I", |
| 4517 | (void *)nfcManager_doGetSecureElementList}, |
| 4518 | |
| 4519 | {"doSelectSecureElement", "(I)V", |
| 4520 | (void *)nfcManager_doSelectSecureElement}, |
| 4521 | |
| 4522 | {"doDeselectSecureElement", "(I)V", |
| 4523 | (void *)nfcManager_doDeselectSecureElement}, |
| 4524 | |
| 4525 | {"doSetSEPowerOffState", "(IZ)V", |
| 4526 | (void *)nfcManager_doSetSEPowerOffState}, |
| 4527 | {"setDefaultTechRoute", "(III)V", |
| 4528 | (void *)nfcManager_setDefaultTechRoute}, |
| 4529 | |
| 4530 | {"setDefaultProtoRoute", "(III)V", |
| 4531 | (void *)nfcManager_setDefaultProtoRoute}, |
| 4532 | |
| 4533 | {"GetDefaultSE", "()I", |
| 4534 | (void *)nfcManager_GetDefaultSE}, |
| 4535 | |
| 4536 | {"doCheckLlcp", "()Z", |
| 4537 | (void *)nfcManager_doCheckLlcp}, |
| 4538 | |
| 4539 | {"doActivateLlcp", "()Z", |
| 4540 | (void *)nfcManager_doActivateLlcp}, |
| 4541 | |
| 4542 | {"doCreateLlcpConnectionlessSocket", "(ILjava/lang/String;)Lcom/android/nfc/dhimpl/NativeLlcpConnectionlessSocket;", |
| 4543 | (void *)nfcManager_doCreateLlcpConnectionlessSocket}, |
| 4544 | |
| 4545 | {"doCreateLlcpServiceSocket", "(ILjava/lang/String;III)Lcom/android/nfc/dhimpl/NativeLlcpServiceSocket;", |
| 4546 | (void*) nfcManager_doCreateLlcpServiceSocket}, |
| 4547 | |
| 4548 | {"doCreateLlcpSocket", "(IIII)Lcom/android/nfc/dhimpl/NativeLlcpSocket;", |
| 4549 | (void*) nfcManager_doCreateLlcpSocket}, |
| 4550 | |
| 4551 | {"doGetLastError", "()I", |
| 4552 | (void*) nfcManager_doGetLastError}, |
| 4553 | |
| 4554 | {"disableDiscovery", "()V", |
| 4555 | (void*) nfcManager_disableDiscovery}, |
| 4556 | |
| 4557 | {"doSetTimeout", "(II)Z", |
| 4558 | (void *)nfcManager_doSetTimeout}, |
| 4559 | |
| 4560 | {"doGetTimeout", "(I)I", |
| 4561 | (void *)nfcManager_doGetTimeout}, |
| 4562 | |
| 4563 | {"doResetTimeouts", "()V", |
| 4564 | (void *)nfcManager_doResetTimeouts}, |
| 4565 | |
| 4566 | {"doAbort", "()V", |
| 4567 | (void *)nfcManager_doAbort}, |
| 4568 | |
| 4569 | {"doSetP2pInitiatorModes", "(I)V", |
| 4570 | (void *)nfcManager_doSetP2pInitiatorModes}, |
| 4571 | |
| 4572 | {"doSetP2pTargetModes", "(I)V", |
| 4573 | (void *)nfcManager_doSetP2pTargetModes}, |
| 4574 | |
| 4575 | {"doEnableScreenOffSuspend", "()V", |
| 4576 | (void *)nfcManager_doEnableScreenOffSuspend}, |
| 4577 | |
| 4578 | {"doDisableScreenOffSuspend", "()V", |
| 4579 | (void *)nfcManager_doDisableScreenOffSuspend}, |
| 4580 | |
| 4581 | {"doDump", "()Ljava/lang/String;", |
| 4582 | (void *)nfcManager_doDump}, |
| 4583 | |
| 4584 | {"getChipVer", "()I", |
| 4585 | (void *)nfcManager_getChipVer}, |
| 4586 | |
| 4587 | {"getFwFileName", "()[B", |
| 4588 | (void *)nfcManager_getFwFileName}, |
| 4589 | |
| 4590 | {"JCOSDownload", "()I", |
| 4591 | (void *)nfcManager_doJcosDownload}, |
| 4592 | {"doCommitRouting", "()V", |
| 4593 | (void *)nfcManager_doCommitRouting}, |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 4594 | #if(NXP_EXTNS == TRUE) |
| 4595 | {"doSetNfcMode", "(I)V", |
| 4596 | (void *)nfcManager_doSetNfcMode}, |
| 4597 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 4598 | {"doGetSecureElementTechList", "()I", |
| 4599 | (void *)nfcManager_getSecureElementTechList}, |
| 4600 | |
| 4601 | {"doGetActiveSecureElementList", "()[I", |
| 4602 | (void *)nfcManager_getActiveSecureElementList}, |
| 4603 | |
| 4604 | {"doGetSecureElementUid", "()[B", |
| 4605 | (void *)nfcManager_getSecureElementUid}, |
| 4606 | |
| 4607 | {"setEmvCoPollProfile", "(ZI)I", |
| 4608 | (void *)nfcManager_setEmvCoPollProfile}, |
| 4609 | |
| 4610 | {"doSetSecureElementListenTechMask", "(I)V", |
| 4611 | (void *)nfcManager_setSecureElementListenTechMask}, |
| 4612 | {"doSetScreenState", "(I)V", |
| 4613 | (void*)nfcManager_doSetScreenState}, |
| 4614 | {"doSetScreenOrPowerState", "(I)V", |
| 4615 | (void*)nfcManager_doSetScreenOrPowerState}, |
| 4616 | //Factory Test Code |
| 4617 | {"doPrbsOn", "(IIII)V", |
| 4618 | (void *)nfcManager_doPrbsOn}, |
| 4619 | {"doPrbsOff", "()V", |
| 4620 | (void *)nfcManager_doPrbsOff}, |
| 4621 | // SWP self test |
| 4622 | {"SWPSelfTest", "(I)I", |
| 4623 | (void *)nfcManager_SWPSelfTest}, |
| 4624 | // check firmware version |
| 4625 | {"getFWVersion", "()I", |
| 4626 | (void *)nfcManager_getFwVersion}, |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 4627 | #if((NFC_NXP_ESE == TRUE) && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 4628 | {"setEtsiReaederState", "(I)V", |
| 4629 | (void *)nfcManager_dosetEtsiReaederState}, |
| 4630 | |
| 4631 | {"getEtsiReaederState", "()I", |
| 4632 | (void *)nfcManager_dogetEtsiReaederState}, |
| 4633 | |
| 4634 | {"etsiReaderConfig", "(I)V", |
| 4635 | (void *)nfcManager_doEtsiReaderConfig}, |
| 4636 | |
| 4637 | {"etsiResetReaderConfig", "()V", |
| 4638 | (void *)nfcManager_doEtsiResetReaderConfig}, |
| 4639 | |
| 4640 | {"notifyEEReaderEvent", "(I)V", |
| 4641 | (void *)nfcManager_doNotifyEEReaderEvent}, |
| 4642 | |
| 4643 | {"etsiInitConfig", "()V", |
| 4644 | (void *)nfcManager_doEtsiInitConfig}, |
| 4645 | |
| 4646 | {"updateScreenState", "()V", |
| 4647 | (void *)nfcManager_doUpdateScreenState}, |
| 4648 | #endif |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 4649 | #if(NXP_EXTNS == TRUE) |
| 4650 | {"doEnablep2p", "(Z)V", |
| 4651 | (void*)nfcManager_Enablep2p}, |
| 4652 | {"doSetProvisionMode", "(Z)V", |
| 4653 | (void *)nfcManager_setProvisionMode}, |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 4654 | {"doGetRouting", "()[B", |
| 4655 | (void *)nfcManager_getRouting}, |
| 4656 | {"getNfcInitTimeout", "()I", |
| 4657 | (void *)nfcManager_getNfcInitTimeout}, |
| 4658 | {"isVzwFeatureEnabled", "()Z", |
| 4659 | (void *)nfcManager_isVzwFeatureEnabled}, |
| 4660 | #endif |
| 4661 | {"doSetEEPROM", "([B)V", |
| 4662 | (void*)nfcManager_doSetEEPROM}, |
| 4663 | {"doGetSeInterface","(I)I", |
| 4664 | (void*)nfcManager_doGetSeInterface}, |
| 4665 | //Factory Test Code |
| 4666 | {"doCheckJcopDlAtBoot", "()Z", |
| 4667 | (void *)nfcManager_doCheckJcopDlAtBoot}, |
| 4668 | {"doEnableDtaMode", "()V", |
| 4669 | (void*) nfcManager_doEnableDtaMode}, |
| 4670 | {"doDisableDtaMode", "()V", |
| 4671 | (void*) nfcManager_doDisableDtaMode} |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 4672 | #if(NXP_EXTNS == TRUE) |
| 4673 | ,{"doselectUicc", "(I)I", |
| 4674 | (void*) nfcManager_doSelectUicc}, |
| 4675 | {"doGetSelectedUicc", "()I", |
| 4676 | (void*) nfcManager_doGetSelectedUicc} |
| 4677 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 4678 | }; |
| 4679 | |
| 4680 | |
| 4681 | /******************************************************************************* |
| 4682 | ** |
| 4683 | ** Function: register_com_android_nfc_NativeNfcManager |
| 4684 | ** |
| 4685 | ** Description: Regisgter JNI functions with Java Virtual Machine. |
| 4686 | ** e: Environment of JVM. |
| 4687 | ** |
| 4688 | ** Returns: Status of registration. |
| 4689 | ** |
| 4690 | *******************************************************************************/ |
| 4691 | int register_com_android_nfc_NativeNfcManager (JNIEnv *e) |
| 4692 | { |
| 4693 | ALOGD ("%s: enter", __FUNCTION__); |
| 4694 | PowerSwitch::getInstance ().initialize (PowerSwitch::UNKNOWN_LEVEL); |
| 4695 | ALOGD ("%s: exit", __FUNCTION__); |
| 4696 | return jniRegisterNativeMethods (e, gNativeNfcManagerClassName, gMethods, NELEM (gMethods)); |
| 4697 | } |
| 4698 | |
| 4699 | |
| 4700 | /******************************************************************************* |
| 4701 | ** |
| 4702 | ** Function: startRfDiscovery |
| 4703 | ** |
| 4704 | ** Description: Ask stack to start polling and listening for devices. |
| 4705 | ** isStart: Whether to start. |
| 4706 | ** |
| 4707 | ** Returns: None |
| 4708 | ** |
| 4709 | *******************************************************************************/ |
| 4710 | void startRfDiscovery(bool isStart) |
| 4711 | { |
| 4712 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 4713 | |
| 4714 | ALOGD ("%s: is start=%d", __FUNCTION__, isStart); |
| 4715 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 4716 | status = isStart ? NFA_StartRfDiscovery () : NFA_StopRfDiscovery (); |
| 4717 | if (status == NFA_STATUS_OK) |
| 4718 | { |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 4719 | if(gGeneralPowershutDown == NFC_MODE_OFF) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 4720 | sDiscCmdwhleNfcOff = true; |
| 4721 | sNfaEnableDisablePollingEvent.wait (); //wait for NFA_RF_DISCOVERY_xxxx_EVT |
| 4722 | sRfEnabled = isStart; |
| 4723 | sDiscCmdwhleNfcOff = false; |
| 4724 | } |
| 4725 | else |
| 4726 | { |
| 4727 | ALOGE ("%s: Failed to start/stop RF discovery; error=0x%X", __FUNCTION__, status); |
| 4728 | } |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 4729 | ALOGD ("%s: is exit=%d", __FUNCTION__, isStart); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 4730 | } |
| 4731 | |
| 4732 | /******************************************************************************* |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 4733 | ** |
| 4734 | ** Function: isDiscoveryStarted |
| 4735 | ** |
| 4736 | ** Description: Indicates whether the discovery is started. |
| 4737 | ** |
| 4738 | ** Returns: True if discovery is started |
| 4739 | ** |
| 4740 | *******************************************************************************/ |
| 4741 | bool isDiscoveryStarted () |
| 4742 | { |
| 4743 | return sRfEnabled; |
| 4744 | } |
| 4745 | |
| 4746 | /******************************************************************************* |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 4747 | ** |
| 4748 | ** Function: notifyPollingEventwhileNfcOff |
| 4749 | ** |
| 4750 | ** Description: Notifies sNfaEnableDisablePollingEvent if tag operations |
| 4751 | ** is in progress at the time Nfc Off is in progress to avoid |
| 4752 | ** NFC off thread infinite block. |
| 4753 | ** |
| 4754 | ** Returns: None |
| 4755 | ** |
| 4756 | *******************************************************************************/ |
| 4757 | static void notifyPollingEventwhileNfcOff() |
| 4758 | { |
| 4759 | ALOGD ("%s: sDiscCmdwhleNfcOff=%x", __FUNCTION__, sDiscCmdwhleNfcOff); |
| 4760 | if(sDiscCmdwhleNfcOff == true) |
| 4761 | { |
| 4762 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 4763 | sNfaEnableDisablePollingEvent.notifyOne (); |
| 4764 | } |
| 4765 | } |
| 4766 | |
| 4767 | /******************************************************************************* |
| 4768 | ** |
| 4769 | ** Function: doStartupConfig |
| 4770 | ** |
| 4771 | ** Description: Configure the NFC controller. |
| 4772 | ** |
| 4773 | ** Returns: None |
| 4774 | ** |
| 4775 | *******************************************************************************/ |
| 4776 | void doStartupConfig() |
| 4777 | { |
| 4778 | struct nfc_jni_native_data *nat = getNative(0, 0); |
| 4779 | tNFA_STATUS stat = NFA_STATUS_FAILED; |
| 4780 | int actualLen = 0; |
| 4781 | |
| 4782 | // If polling for Active mode, set the ordering so that we choose Active over Passive mode first. |
| 4783 | if (nat && (nat->tech_mask & (NFA_TECHNOLOGY_MASK_A_ACTIVE | NFA_TECHNOLOGY_MASK_F_ACTIVE))) |
| 4784 | { |
| 4785 | UINT8 act_mode_order_param[] = { 0x01 }; |
| 4786 | SyncEventGuard guard (sNfaSetConfigEvent); |
| 4787 | stat = NFA_SetConfig(NCI_PARAM_ID_ACT_ORDER, sizeof(act_mode_order_param), &act_mode_order_param[0]); |
| 4788 | if (stat == NFA_STATUS_OK) |
| 4789 | sNfaSetConfigEvent.wait (); |
| 4790 | } |
| 4791 | |
| 4792 | //configure RF polling frequency for each technology |
| 4793 | static tNFA_DM_DISC_FREQ_CFG nfa_dm_disc_freq_cfg; |
| 4794 | //values in the polling_frequency[] map to members of nfa_dm_disc_freq_cfg |
| 4795 | UINT8 polling_frequency [8] = {1, 1, 1, 1, 1, 1, 1, 1}; |
| 4796 | actualLen = GetStrValue(NAME_POLL_FREQUENCY, (char*)polling_frequency, 8); |
| 4797 | if (actualLen == 8) |
| 4798 | { |
| 4799 | ALOGD ("%s: polling frequency", __FUNCTION__); |
| 4800 | memset (&nfa_dm_disc_freq_cfg, 0, sizeof(nfa_dm_disc_freq_cfg)); |
| 4801 | nfa_dm_disc_freq_cfg.pa = polling_frequency [0]; |
| 4802 | nfa_dm_disc_freq_cfg.pb = polling_frequency [1]; |
| 4803 | nfa_dm_disc_freq_cfg.pf = polling_frequency [2]; |
| 4804 | nfa_dm_disc_freq_cfg.pi93 = polling_frequency [3]; |
| 4805 | nfa_dm_disc_freq_cfg.pbp = polling_frequency [4]; |
| 4806 | nfa_dm_disc_freq_cfg.pk = polling_frequency [5]; |
| 4807 | nfa_dm_disc_freq_cfg.paa = polling_frequency [6]; |
| 4808 | nfa_dm_disc_freq_cfg.pfa = polling_frequency [7]; |
| 4809 | p_nfa_dm_rf_disc_freq_cfg = &nfa_dm_disc_freq_cfg; |
| 4810 | } |
| 4811 | } |
| 4812 | |
| 4813 | |
| 4814 | /******************************************************************************* |
| 4815 | ** |
| 4816 | ** Function: nfcManager_isNfcActive |
| 4817 | ** |
| 4818 | ** Description: Used externaly to determine if NFC is active or not. |
| 4819 | ** |
| 4820 | ** Returns: 'true' if the NFC stack is running, else 'false'. |
| 4821 | ** |
| 4822 | *******************************************************************************/ |
| 4823 | bool nfcManager_isNfcActive() |
| 4824 | { |
| 4825 | return sIsNfaEnabled; |
| 4826 | } |
| 4827 | |
| 4828 | /******************************************************************************* |
| 4829 | ** |
| 4830 | ** Function: startStopPolling |
| 4831 | ** |
| 4832 | ** Description: Start or stop polling. |
| 4833 | ** isStartPolling: true to start polling; false to stop polling. |
| 4834 | ** |
| 4835 | ** Returns: None. |
| 4836 | ** |
| 4837 | *******************************************************************************/ |
| 4838 | void startStopPolling (bool isStartPolling) |
| 4839 | { |
| 4840 | ALOGD ("%s: enter; isStart=%u", __FUNCTION__, isStartPolling); |
| 4841 | startRfDiscovery (false); |
| 4842 | |
| 4843 | if (isStartPolling) startPolling_rfDiscoveryDisabled(0); |
| 4844 | else stopPolling_rfDiscoveryDisabled(); |
| 4845 | |
| 4846 | startRfDiscovery (true); |
| 4847 | ALOGD ("%s: exit", __FUNCTION__); |
| 4848 | } |
| 4849 | |
| 4850 | static tNFA_STATUS startPolling_rfDiscoveryDisabled(tNFA_TECHNOLOGY_MASK tech_mask) { |
| 4851 | tNFA_STATUS stat = NFA_STATUS_FAILED; |
| 4852 | |
| 4853 | unsigned long num = 0; |
| 4854 | |
| 4855 | if (tech_mask == 0 && GetNumValue(NAME_POLLING_TECH_MASK, &num, sizeof(num))) |
| 4856 | tech_mask = num; |
| 4857 | else if (tech_mask == 0) tech_mask = DEFAULT_TECH_MASK; |
| 4858 | |
| 4859 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 4860 | ALOGD ("%s: enable polling", __FUNCTION__); |
| 4861 | stat = NFA_EnablePolling (tech_mask); |
| 4862 | if (stat == NFA_STATUS_OK) |
| 4863 | { |
| 4864 | ALOGD ("%s: wait for enable event", __FUNCTION__); |
| 4865 | sPollingEnabled = true; |
| 4866 | sNfaEnableDisablePollingEvent.wait (); //wait for NFA_POLL_ENABLED_EVT |
| 4867 | } |
| 4868 | else |
| 4869 | { |
| 4870 | ALOGE ("%s: fail enable polling; error=0x%X", __FUNCTION__, stat); |
| 4871 | } |
| 4872 | |
| 4873 | return stat; |
| 4874 | } |
| 4875 | |
| 4876 | static tNFA_STATUS stopPolling_rfDiscoveryDisabled() { |
| 4877 | tNFA_STATUS stat = NFA_STATUS_FAILED; |
| 4878 | |
| 4879 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 4880 | ALOGD ("%s: disable polling", __FUNCTION__); |
| 4881 | stat = NFA_DisablePolling (); |
| 4882 | if (stat == NFA_STATUS_OK) { |
| 4883 | sPollingEnabled = false; |
| 4884 | sNfaEnableDisablePollingEvent.wait (); //wait for NFA_POLL_DISABLED_EVT |
| 4885 | } else { |
| 4886 | ALOGE ("%s: fail disable polling; error=0x%X", __FUNCTION__, stat); |
| 4887 | } |
| 4888 | |
| 4889 | return stat; |
| 4890 | } |
| 4891 | |
| 4892 | |
| 4893 | /******************************************************************************* |
| 4894 | ** |
| 4895 | ** Function: nfcManager_getChipVer |
| 4896 | ** |
| 4897 | ** Description: Gets the chip version. |
| 4898 | ** e: JVM environment. |
| 4899 | ** o: Java object. |
| 4900 | ** |
| 4901 | ** Returns: None 0x00 |
| 4902 | ** PN547C2 0x01 |
| 4903 | ** PN65T 0x02 . |
| 4904 | ** |
| 4905 | *******************************************************************************/ |
| 4906 | static int nfcManager_getChipVer(JNIEnv* e, jobject o) |
| 4907 | { |
| 4908 | (void)e; |
| 4909 | (void)o; |
| 4910 | ALOGD ("%s: enter", __FUNCTION__); |
| 4911 | unsigned long num =0; |
| 4912 | |
| 4913 | GetNxpNumValue(NAME_NXP_NFC_CHIP, (void *)&num, sizeof(num)); |
| 4914 | ALOGD ("%d: nfcManager_getChipVer", num); |
| 4915 | return num; |
| 4916 | } |
| 4917 | |
| 4918 | /******************************************************************************* |
| 4919 | ** |
| 4920 | ** Function: nfcManager_getFwFileName |
| 4921 | ** |
| 4922 | ** Description: Read Fw file name from config file. |
| 4923 | ** e: JVM environment. |
| 4924 | ** o: Java object. |
| 4925 | ** |
| 4926 | ** Returns: jbyteArray: File name read from config file |
| 4927 | ** NULL in case file name not found |
| 4928 | ** |
| 4929 | *******************************************************************************/ |
| 4930 | static jbyteArray nfcManager_getFwFileName(JNIEnv* e, jobject o) |
| 4931 | { |
| 4932 | (void)o; |
| 4933 | ALOGD ("%s: enter", __FUNCTION__); |
| 4934 | char fwFileName[256]; |
| 4935 | int fileLen = 0; |
| 4936 | jbyteArray jbuff = NULL; |
| 4937 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 4938 | if(GetNxpStrValue(NAME_NXP_FW_NAME, (char*)fwFileName, sizeof(fwFileName)) == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 4939 | { |
| 4940 | ALOGD ("%s: FW_NAME read success = %s", __FUNCTION__, fwFileName); |
| 4941 | fileLen = strlen(fwFileName); |
| 4942 | jbuff = e->NewByteArray (fileLen); |
| 4943 | e->SetByteArrayRegion (jbuff, 0, fileLen, (jbyte*) fwFileName); |
| 4944 | } |
| 4945 | else |
| 4946 | { |
| 4947 | ALOGD ("%s: FW_NAME not found", __FUNCTION__); |
| 4948 | } |
| 4949 | |
| 4950 | return jbuff; |
| 4951 | } |
| 4952 | |
| 4953 | /******************************************************************************* |
| 4954 | ** |
| 4955 | ** Function: DWPChannel_init |
| 4956 | ** |
| 4957 | ** Description: Initializes the DWP channel functions. |
| 4958 | ** |
| 4959 | ** Returns: True if ok. |
| 4960 | ** |
| 4961 | *******************************************************************************/ |
| 4962 | #if (NFC_NXP_ESE == TRUE) |
| 4963 | void DWPChannel_init(IChannel_t *DWP) |
| 4964 | { |
| 4965 | ALOGD ("%s: enter", __FUNCTION__); |
| 4966 | DWP->open = open; |
| 4967 | DWP->close = close; |
| 4968 | DWP->transceive = transceive; |
| 4969 | DWP->doeSE_Reset = doeSE_Reset; |
| 4970 | } |
| 4971 | #endif |
| 4972 | /******************************************************************************* |
| 4973 | ** |
| 4974 | ** Function: nfcManager_doJcosDownload |
| 4975 | ** |
| 4976 | ** Description: start jcos download. |
| 4977 | ** e: JVM environment. |
| 4978 | ** o: Java object. |
| 4979 | ** |
| 4980 | ** Returns: True if ok. |
| 4981 | ** |
| 4982 | *******************************************************************************/ |
| 4983 | static int nfcManager_doJcosDownload(JNIEnv* e, jobject o) |
| 4984 | { |
| 4985 | (void)e; |
| 4986 | (void)o; |
| 4987 | #if (NFC_NXP_ESE == TRUE) |
| 4988 | ALOGD ("%s: enter", __FUNCTION__); |
| 4989 | tNFA_STATUS status, tStatus; |
| 4990 | bool stat = false; |
| 4991 | UINT8 param; |
| 4992 | status, tStatus= NFA_STATUS_FAILED; |
| 4993 | |
| 4994 | if (sRfEnabled) { |
| 4995 | // Stop RF Discovery if we were polling |
| 4996 | startRfDiscovery (false); |
| 4997 | } |
| 4998 | DWPChannel_init(&Dwp); |
| 4999 | status = JCDNLD_Init(&Dwp); |
| 5000 | if(status != NFA_STATUS_OK) |
| 5001 | { |
| 5002 | ALOGE("%s: JCDND initialization failed", __FUNCTION__); |
| 5003 | } |
| 5004 | else |
| 5005 | { |
| 5006 | #if 0 |
| 5007 | param = 0x00; //Disable standby |
| 5008 | SyncEventGuard guard (sNfaVSCResponseEvent); |
| 5009 | tStatus = NFA_SendVsCommand (0x00,sizeof(param),¶m,nfaVSCCallback); |
| 5010 | if(NFA_STATUS_OK == tStatus) |
| 5011 | { |
| 5012 | sNfaVSCResponseEvent.wait(); //wait for NFA VS command to finish |
| 5013 | ALOGE("%s: start JcopOs_Download", __FUNCTION__); |
| 5014 | status = JCDNLD_StartDownload(); |
| 5015 | } |
| 5016 | #endif |
| 5017 | ALOGE("%s: start JcopOs_Download", __FUNCTION__); |
| 5018 | status = JCDNLD_StartDownload(); |
| 5019 | } |
| 5020 | |
| 5021 | #if 0 |
| 5022 | param = 0x01; //Enable standby |
| 5023 | SyncEventGuard guard (sNfaVSCResponseEvent); |
| 5024 | tStatus = NFA_SendVsCommand (0x00,sizeof(param),¶m,nfaVSCCallback); |
| 5025 | if(NFA_STATUS_OK == tStatus) |
| 5026 | { |
| 5027 | sNfaVSCResponseEvent.wait(); //wait for NFA VS command to finish |
| 5028 | |
| 5029 | } |
| 5030 | #endif |
| 5031 | stat = JCDNLD_DeInit(); |
| 5032 | /*If Nfc OFF/deinitialization happening dont perform RF discovery*/ |
| 5033 | if(dwpChannelForceClose == false) |
| 5034 | startRfDiscovery (true); |
| 5035 | |
| 5036 | ALOGD ("%s: exit; status =0x%X", __FUNCTION__,status); |
| 5037 | #else |
| 5038 | tNFA_STATUS status = 0x0F; |
| 5039 | ALOGD ("%s: No p61", __FUNCTION__); |
| 5040 | #endif |
| 5041 | return status; |
| 5042 | } |
| 5043 | |
| 5044 | static void nfcManager_doCommitRouting(JNIEnv* e, jobject o) |
| 5045 | { |
| 5046 | (void)e; |
| 5047 | (void)o; |
| 5048 | ALOGD ("%s: enter", __FUNCTION__); |
| 5049 | PowerSwitch::getInstance ().setLevel (PowerSwitch::FULL_POWER); |
| 5050 | PowerSwitch::getInstance ().setModeOn (PowerSwitch::HOST_ROUTING); |
| 5051 | if (sRfEnabled) { |
| 5052 | // Stop RF discovery to reconfigure |
| 5053 | startRfDiscovery(false); |
| 5054 | } |
| 5055 | RoutingManager::getInstance().commitRouting(); |
| 5056 | startRfDiscovery(true); |
| 5057 | ALOGD ("%s: exit", __FUNCTION__); |
| 5058 | |
| 5059 | } |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 5060 | #if(NXP_EXTNS == TRUE) |
| 5061 | static void nfcManager_doSetNfcMode(JNIEnv *e, jobject o, jint nfcMode) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5062 | { |
| 5063 | /* Store the shutdown state */ |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 5064 | gGeneralPowershutDown = nfcMode; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5065 | } |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 5066 | #endif |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 5067 | |
| 5068 | bool isNfcInitializationDone() |
| 5069 | { |
| 5070 | return sIsNfaEnabled; |
| 5071 | } |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5072 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5073 | /******************************************************************************* |
| 5074 | ** |
| 5075 | ** Function: StoreScreenState |
| 5076 | ** |
| 5077 | ** Description: Sets screen state |
| 5078 | ** |
| 5079 | ** Returns: None |
| 5080 | ** |
| 5081 | *******************************************************************************/ |
| 5082 | static void StoreScreenState(int state) |
| 5083 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5084 | ALOGD ("%s: enter", __FUNCTION__); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5085 | screenstate = state; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5086 | nfc_ncif_storeScreenState(state); |
| 5087 | ALOGD ("%s: exit", __FUNCTION__); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5088 | } |
| 5089 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5090 | /******************************************************************************* |
| 5091 | ** |
| 5092 | ** Function: getScreenState |
| 5093 | ** |
| 5094 | ** Description: returns screen state |
| 5095 | ** |
| 5096 | ** Returns: int |
| 5097 | ** |
| 5098 | *******************************************************************************/ |
| 5099 | int getScreenState() |
| 5100 | { |
| 5101 | return screenstate; |
| 5102 | } |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 5103 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5104 | #if(NFC_NXP_ESE == TRUE && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 5105 | /******************************************************************************* |
| 5106 | ** |
| 5107 | ** Function: isp2pActivated |
| 5108 | ** |
| 5109 | ** Description: returns p2pActive state |
| 5110 | ** |
| 5111 | ** Returns: bool |
| 5112 | ** |
| 5113 | *******************************************************************************/ |
| 5114 | bool isp2pActivated() |
| 5115 | { |
| 5116 | return sP2pActive; |
| 5117 | } |
| 5118 | #endif |
| 5119 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5120 | /******************************************************************************* |
| 5121 | ** |
| 5122 | ** Function: nfcManager_doSetScreenState |
| 5123 | ** |
| 5124 | ** Description: Set screen state |
| 5125 | ** |
| 5126 | ** Returns: None |
| 5127 | ** |
| 5128 | *******************************************************************************/ |
| 5129 | static void nfcManager_doSetScreenState (JNIEnv* e, jobject o, jint state) |
| 5130 | { |
| 5131 | tNFA_STATUS status = NFA_STATUS_OK; |
| 5132 | unsigned long auto_num = 0; |
| 5133 | uint8_t standby_num = 0x00; |
| 5134 | uint8_t *buffer = NULL; |
| 5135 | long bufflen = 260; |
| 5136 | long retlen = 0; |
| 5137 | int isfound; |
| 5138 | |
| 5139 | ALOGD ("%s: state = %d", __FUNCTION__, state); |
| 5140 | if (sIsDisabling || !sIsNfaEnabled) |
| 5141 | return; |
| 5142 | if(get_transcation_stat() == true) |
| 5143 | { |
| 5144 | ALOGD("Payment is in progress stopping enable/disable discovery"); |
| 5145 | set_lastScreenStateRequest((eScreenState_t)state); |
| 5146 | pendingScreenState = true; |
| 5147 | return; |
| 5148 | } |
| 5149 | int old = getScreenState(); |
| 5150 | if(old == state) { |
| 5151 | ALOGD("Screen state is not changed."); |
| 5152 | return; |
| 5153 | } |
| 5154 | acquireRfInterfaceMutexLock(); |
| 5155 | if (state) { |
| 5156 | if (sRfEnabled) { |
| 5157 | // Stop RF discovery to reconfigure |
| 5158 | startRfDiscovery(false); |
| 5159 | } |
| 5160 | |
| 5161 | if(state == NFA_SCREEN_STATE_LOCKED || state == NFA_SCREEN_STATE_OFF) |
| 5162 | { |
| 5163 | SyncEventGuard guard (sNfaEnableDisablePollingEvent); |
| 5164 | status = NFA_DisablePolling (); |
| 5165 | if (status == NFA_STATUS_OK) |
| 5166 | { |
| 5167 | sNfaEnableDisablePollingEvent.wait (); //wait for NFA_POLL_DISABLED_EVT |
| 5168 | }else |
| 5169 | ALOGE ("%s: Failed to disable polling; error=0x%X", __FUNCTION__, status); |
| 5170 | } |
| 5171 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5172 | if(GetNxpNumValue(NAME_NXP_CORE_SCRN_OFF_AUTONOMOUS_ENABLE,&auto_num ,sizeof(auto_num))) |
| 5173 | { |
| 5174 | ALOGD ("%s: enter; NAME_NXP_CORE_SCRN_OFF_AUTONOMOUS_ENABLE = %02x", __FUNCTION__, auto_num); |
| 5175 | } |
| 5176 | if(auto_num == 0x01) |
| 5177 | { |
| 5178 | buffer = (uint8_t*) malloc(bufflen*sizeof(uint8_t)); |
| 5179 | if(buffer == NULL) |
| 5180 | { |
| 5181 | ALOGD ("%s: enter; NAME_NXP_CORE_STANDBY buffer is NULL", __FUNCTION__); |
| 5182 | } |
| 5183 | else |
| 5184 | { |
| 5185 | isfound = GetNxpByteArrayValue(NAME_NXP_CORE_STANDBY, (char *) buffer,bufflen, &retlen); |
| 5186 | if (retlen > 0) |
| 5187 | { |
| 5188 | standby_num = buffer[3]; |
| 5189 | ALOGD ("%s: enter; NAME_NXP_CORE_STANDBY = %02x", __FUNCTION__, standby_num); |
| 5190 | SendAutonomousMode(state,standby_num); |
| 5191 | } |
| 5192 | else |
| 5193 | { |
| 5194 | ALOGD ("%s: enter; NAME_NXP_CORE_STANDBY = %02x", __FUNCTION__, standby_num); |
| 5195 | SendAutonomousMode(state , standby_num); |
| 5196 | } |
| 5197 | } |
| 5198 | } |
| 5199 | else |
| 5200 | { |
| 5201 | ALOGD ("%s: enter; NAME_NXP_CORE_SCRN_OFF_AUTONOMOUS_ENABLE = %02x", __FUNCTION__, auto_num); |
| 5202 | } |
| 5203 | if(buffer) |
| 5204 | { |
| 5205 | free(buffer); |
| 5206 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5207 | |
| 5208 | status = SetScreenState(state); |
| 5209 | if (status != NFA_STATUS_OK) |
| 5210 | { |
| 5211 | ALOGE ("%s: fail enable SetScreenState; error=0x%X", __FUNCTION__, status); |
| 5212 | } |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5213 | else |
| 5214 | { |
| 5215 | if ((old == NFA_SCREEN_STATE_OFF && state == NFA_SCREEN_STATE_LOCKED)|| |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 5216 | #if(NXP_EXTNS == TRUE) |
| 5217 | (old == NFA_SCREEN_STATE_LOCKED && state == NFA_SCREEN_STATE_UNLOCKED && sProvisionMode)|| |
| 5218 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5219 | (old == NFA_SCREEN_STATE_LOCKED && state == NFA_SCREEN_STATE_OFF && sIsSecElemSelected)) |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5220 | { |
| 5221 | startRfDiscovery(true); |
| 5222 | } |
| 5223 | StoreScreenState(state); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5224 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5225 | } |
| 5226 | releaseRfInterfaceMutexLock(); |
| 5227 | } |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 5228 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5229 | /******************************************************************************* |
| 5230 | ** |
| 5231 | ** Function: nfcManager_doSetScreenOrPowerState |
| 5232 | ** This function combines both screen state and power state(ven power) values. |
| 5233 | ** |
| 5234 | ** Description: Set screen or power state |
| 5235 | ** e: JVM environment. |
| 5236 | ** o: Java object. |
| 5237 | ** state:represents power or screen state (0-3 screen state),6 (power on),7(power off) |
| 5238 | ** |
| 5239 | ** Returns: None |
| 5240 | ** |
| 5241 | *******************************************************************************/ |
| 5242 | static void nfcManager_doSetScreenOrPowerState (JNIEnv* e, jobject o, jint state) |
| 5243 | { |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 5244 | tNFA_STATUS stat = NFA_STATUS_OK; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5245 | ALOGE ("%s: Enter", __FUNCTION__); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5246 | if (state <= NFA_SCREEN_STATE_UNLOCKED ) // SCREEN_STATE |
| 5247 | nfcManager_doSetScreenState(e, o, state); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 5248 | else if (state == VEN_POWER_STATE_ON) // POWER_ON NFC_OFF |
| 5249 | { |
| 5250 | nfcManager_doSetNfcMode(e , o, NFC_MODE_OFF); |
| 5251 | } |
| 5252 | else if (state == VEN_POWER_STATE_OFF) // POWER_OFF |
| 5253 | { |
| 5254 | if(sIsNfaEnabled) |
| 5255 | { |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 5256 | nfcManager_doSetNfcMode(e , o, NFC_MODE_ON); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 5257 | } |
| 5258 | else |
| 5259 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5260 | nfcManager_doSetNfcMode(e , o, NFC_MODE_OFF); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 5261 | } |
| 5262 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5263 | else |
| 5264 | ALOGE ("%s: unknown screen or power state. state=%d", __FUNCTION__, state); |
| 5265 | } |
| 5266 | #endif |
| 5267 | /******************************************************************************* |
| 5268 | ** |
| 5269 | ** Function: get_last_request |
| 5270 | ** |
| 5271 | ** Description: returns the last enable/disable discovery event |
| 5272 | ** |
| 5273 | ** Returns: last request (char) . |
| 5274 | ** |
| 5275 | *******************************************************************************/ |
| 5276 | static char get_last_request() |
| 5277 | { |
| 5278 | return(transaction_data.last_request); |
| 5279 | } |
| 5280 | /******************************************************************************* |
| 5281 | ** |
| 5282 | ** Function: set_last_request |
| 5283 | ** |
| 5284 | ** Description: stores the last enable/disable discovery event |
| 5285 | ** |
| 5286 | ** Returns: None . |
| 5287 | ** |
| 5288 | *******************************************************************************/ |
| 5289 | static void set_last_request(char status, struct nfc_jni_native_data *nat) |
| 5290 | { |
| 5291 | transaction_data.last_request = status; |
| 5292 | if (nat != NULL) |
| 5293 | { |
| 5294 | transaction_data.transaction_nat = nat; |
| 5295 | } |
| 5296 | } |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 5297 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5298 | /******************************************************************************* |
| 5299 | ** |
| 5300 | ** Function: set_transcation_stat |
| 5301 | ** |
| 5302 | ** Description: updates the transaction status |
| 5303 | ** |
| 5304 | ** Returns: None . |
| 5305 | ** |
| 5306 | *******************************************************************************/ |
| 5307 | void set_transcation_stat(bool result) |
| 5308 | { |
| 5309 | ALOGD ("%s: %d", __FUNCTION__, result); |
| 5310 | transaction_data.trans_in_progress = result; |
| 5311 | } |
| 5312 | |
| 5313 | #endif |
| 5314 | /******************************************************************************* |
| 5315 | ** |
| 5316 | ** Function: get_lastScreenStateRequest |
| 5317 | ** |
| 5318 | ** Description: returns the last screen state request |
| 5319 | ** |
| 5320 | ** Returns: last screen state request event (eScreenState_t) . |
| 5321 | ** |
| 5322 | *******************************************************************************/ |
| 5323 | static eScreenState_t get_lastScreenStateRequest() |
| 5324 | { |
| 5325 | ALOGD ("%s: %d", __FUNCTION__, transaction_data.last_screen_state_request); |
| 5326 | return(transaction_data.last_screen_state_request); |
| 5327 | } |
| 5328 | |
| 5329 | /******************************************************************************* |
| 5330 | ** |
| 5331 | ** Function: set_lastScreenStateRequest |
| 5332 | ** |
| 5333 | ** Description: stores the last screen state request |
| 5334 | ** |
| 5335 | ** Returns: None . |
| 5336 | ** |
| 5337 | *******************************************************************************/ |
| 5338 | static void set_lastScreenStateRequest(eScreenState_t status) |
| 5339 | { |
| 5340 | ALOGD ("%s: current=%d, new=%d", __FUNCTION__, transaction_data.last_screen_state_request, status); |
| 5341 | transaction_data.last_screen_state_request = status; |
| 5342 | } |
| 5343 | |
| 5344 | |
| 5345 | /******************************************************************************* |
| 5346 | ** |
| 5347 | ** Function: switchBackTimerProc_transaction |
| 5348 | ** |
| 5349 | ** Description: Callback function for interval timer. |
| 5350 | ** |
| 5351 | ** Returns: None |
| 5352 | ** |
| 5353 | *******************************************************************************/ |
| 5354 | static void cleanupTimerProc_transaction(union sigval) |
| 5355 | { |
| 5356 | ALOGD("Inside cleanupTimerProc"); |
| 5357 | cleanup_timer(); |
| 5358 | } |
| 5359 | |
| 5360 | void cleanup_timer() |
| 5361 | { |
| 5362 | ALOGD("Inside cleanup"); |
| 5363 | //set_transcation_stat(false); |
| 5364 | pthread_t transaction_thread; |
| 5365 | int irret = -1; |
| 5366 | ALOGD ("%s", __FUNCTION__); |
| 5367 | |
| 5368 | /* Transcation is done process the last request*/ |
| 5369 | pthread_attr_t attr; |
| 5370 | pthread_attr_init(&attr); |
| 5371 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 5372 | irret = pthread_create(&transaction_thread, &attr, enableThread, NULL); |
| 5373 | if(irret != 0) |
| 5374 | { |
| 5375 | ALOGE("Unable to create the thread"); |
| 5376 | } |
| 5377 | pthread_attr_destroy(&attr); |
| 5378 | transaction_data.current_transcation_state = NFA_TRANS_DM_RF_TRANS_END; |
| 5379 | } |
| 5380 | |
| 5381 | /******************************************************************************* |
| 5382 | ** |
| 5383 | ** Function: get_transcation_stat |
| 5384 | ** |
| 5385 | ** Description: returns the transaction status whether it is in progress |
| 5386 | ** |
| 5387 | ** Returns: bool . |
| 5388 | ** |
| 5389 | *******************************************************************************/ |
| 5390 | static bool get_transcation_stat(void) |
| 5391 | { |
| 5392 | return( transaction_data.trans_in_progress); |
| 5393 | } |
| 5394 | |
| 5395 | /******************************************************************************* |
| 5396 | ** |
| 5397 | ** Function: config_swp_reader_mode |
| 5398 | ** |
| 5399 | ** Description: handles the screen state during swp reader mode |
| 5400 | ** |
| 5401 | ** Returns: None. |
| 5402 | ** |
| 5403 | *******************************************************************************/ |
| 5404 | void config_swp_reader_mode(bool mode) |
| 5405 | { |
| 5406 | eScreenState_t last_screen_state_request; |
| 5407 | if(mode == true) |
| 5408 | { |
| 5409 | set_transcation_stat(true); |
| 5410 | } |
| 5411 | else |
| 5412 | { |
| 5413 | set_transcation_stat(false); |
| 5414 | if(pendingScreenState == true) |
| 5415 | { |
| 5416 | pendingScreenState = false; |
| 5417 | last_screen_state_request = get_lastScreenStateRequest(); |
| 5418 | nfcManager_doSetScreenState(NULL,NULL,last_screen_state_request); |
| 5419 | } |
| 5420 | |
| 5421 | } |
| 5422 | } |
| 5423 | |
| 5424 | /******************************************************************************* |
| 5425 | ** |
| 5426 | ** Function: checkforTranscation |
| 5427 | ** |
| 5428 | ** Description: Receive connection-related events from stack. |
| 5429 | ** connEvent: Event code. |
| 5430 | ** eventData: Event data. |
| 5431 | ** |
| 5432 | ** Returns: None |
| 5433 | ** |
| 5434 | *******************************************************************************/ |
| 5435 | void checkforTranscation(UINT8 connEvent, void* eventData) |
| 5436 | { |
| 5437 | tNFA_CONN_EVT_DATA *eventAct_Data = (tNFA_CONN_EVT_DATA*) eventData; |
| 5438 | tNFA_DM_CBACK_DATA* eventDM_Conn_data = (tNFA_DM_CBACK_DATA *) eventData; |
| 5439 | tNFA_EE_CBACK_DATA* ee_action_data = (tNFA_EE_CBACK_DATA *) eventData; |
| 5440 | tNFA_EE_ACTION& action = ee_action_data->action; |
| 5441 | ALOGD ("%s: enter; event=0x%X transaction_data.current_transcation_state = 0x%x", __FUNCTION__, connEvent, |
| 5442 | transaction_data.current_transcation_state); |
| 5443 | switch(connEvent) |
| 5444 | { |
| 5445 | case NFA_ACTIVATED_EVT: |
| 5446 | if((eventAct_Data->activated.activate_ntf.protocol != NFA_PROTOCOL_NFC_DEP) && (isListenMode(eventAct_Data->activated))) |
| 5447 | { |
| 5448 | ALOGD("ACTIVATED_EVT setting flag"); |
| 5449 | transaction_data.current_transcation_state = NFA_TRANS_ACTIVATED_EVT; |
| 5450 | set_transcation_stat(true); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5451 | }else{ |
| 5452 | // ALOGD("other event clearing flag "); |
| 5453 | // memset(&transaction_data, 0x00, sizeof(Transcation_Check_t)); |
| 5454 | } |
| 5455 | break; |
| 5456 | case NFA_EE_ACTION_EVT: |
| 5457 | if (transaction_data.current_transcation_state == NFA_TRANS_DEFAULT |
| 5458 | || transaction_data.current_transcation_state == NFA_TRANS_ACTIVATED_EVT) |
| 5459 | { |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5460 | if(getScreenState() == NFA_SCREEN_STATE_OFF) |
| 5461 | { |
| 5462 | if (!sP2pActive && eventDM_Conn_data->rf_field.status == NFA_STATUS_OK) |
| 5463 | SecureElement::getInstance().notifyRfFieldEvent (true); |
| 5464 | } |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5465 | #if((NFC_NXP_CHIP_TYPE != PN548C2) && (NFC_NXP_CHIP_TYPE != PN551)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5466 | if((action.param.technology == NFC_RF_TECHNOLOGY_A)&&(( getScreenState () == NFA_SCREEN_STATE_OFF || getScreenState () == NFA_SCREEN_STATE_LOCKED))) |
| 5467 | { |
| 5468 | transaction_data.current_transcation_state = NFA_TRANS_MIFARE_ACT_EVT; |
| 5469 | set_transcation_stat(true); |
| 5470 | } |
| 5471 | else |
| 5472 | #endif |
| 5473 | { |
| 5474 | transaction_data.current_transcation_state = NFA_TRANS_EE_ACTION_EVT; |
| 5475 | set_transcation_stat(true); |
| 5476 | } |
| 5477 | } |
| 5478 | break; |
| 5479 | case NFA_TRANS_CE_ACTIVATED: |
| 5480 | if (transaction_data.current_transcation_state == NFA_TRANS_DEFAULT || transaction_data.current_transcation_state == NFA_TRANS_ACTIVATED_EVT) |
| 5481 | { |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5482 | if(getScreenState() == NFA_SCREEN_STATE_OFF) |
| 5483 | { |
| 5484 | if (!sP2pActive && eventDM_Conn_data->rf_field.status == NFA_STATUS_OK) |
| 5485 | SecureElement::getInstance().notifyRfFieldEvent (true); |
| 5486 | } |
| 5487 | transaction_data.current_transcation_state = NFA_TRANS_CE_ACTIVATED; |
| 5488 | set_transcation_stat(true); |
| 5489 | } |
| 5490 | break; |
| 5491 | case NFA_TRANS_CE_DEACTIVATED: |
| 5492 | if (transaction_data.current_transcation_state == NFA_TRANS_CE_ACTIVATED) |
| 5493 | { |
| 5494 | transaction_data.current_transcation_state = NFA_TRANS_CE_DEACTIVATED; |
| 5495 | } |
| 5496 | break; |
| 5497 | #if (NFC_NXP_CHIP_TYPE == PN547C2) |
| 5498 | case NFA_DEACTIVATED_EVT: |
| 5499 | if(transaction_data.current_transcation_state == NFA_TRANS_MIFARE_ACT_EVT) |
| 5500 | { |
| 5501 | cleanup_timer(); |
| 5502 | } |
| 5503 | break; |
| 5504 | #endif |
| 5505 | case NFA_TRANS_DM_RF_FIELD_EVT: |
| 5506 | if (eventDM_Conn_data->rf_field.status == NFA_STATUS_OK && |
| 5507 | (transaction_data.current_transcation_state == NFA_TRANS_EE_ACTION_EVT |
| 5508 | || transaction_data.current_transcation_state == NFA_TRANS_CE_DEACTIVATED) |
| 5509 | && eventDM_Conn_data->rf_field.rf_field_status == 0) |
| 5510 | { |
| 5511 | ALOGD("start_timer"); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5512 | #if((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5513 | set_AGC_process_state(false); |
| 5514 | #endif |
| 5515 | transaction_data.current_transcation_state = NFA_TRANS_DM_RF_FIELD_EVT_OFF; |
| 5516 | scleanupTimerProc_transaction.set (50, cleanupTimerProc_transaction); |
| 5517 | } |
| 5518 | else if (eventDM_Conn_data->rf_field.status == NFA_STATUS_OK && |
| 5519 | transaction_data.current_transcation_state == NFA_TRANS_DM_RF_FIELD_EVT_OFF && |
| 5520 | eventDM_Conn_data->rf_field.rf_field_status == 1) |
| 5521 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5522 | #if((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551)) |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 5523 | nfcManagerEnableAGCDebug(connEvent); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5524 | #endif |
| 5525 | transaction_data.current_transcation_state = NFA_TRANS_DM_RF_FIELD_EVT_ON; |
| 5526 | ALOGD("Payment is in progress hold the screen on/off request "); |
| 5527 | transaction_data.current_transcation_state = NFA_TRANS_DM_RF_TRANS_START; |
| 5528 | scleanupTimerProc_transaction.kill (); |
| 5529 | |
| 5530 | } |
| 5531 | else if (eventDM_Conn_data->rf_field.status == NFA_STATUS_OK && |
| 5532 | transaction_data.current_transcation_state == NFA_TRANS_DM_RF_TRANS_START && |
| 5533 | eventDM_Conn_data->rf_field.rf_field_status == 0) |
| 5534 | { |
| 5535 | ALOGD("Transcation is done"); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5536 | #if((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5537 | set_AGC_process_state(false); |
| 5538 | #endif |
| 5539 | transaction_data.current_transcation_state = NFA_TRANS_DM_RF_TRANS_PROGRESS; |
| 5540 | //set_transcation_stat(false); |
| 5541 | cleanup_timer(); |
| 5542 | }else if(eventDM_Conn_data->rf_field.status == NFA_STATUS_OK && |
| 5543 | transaction_data.current_transcation_state == NFA_TRANS_ACTIVATED_EVT && |
| 5544 | eventDM_Conn_data->rf_field.rf_field_status == 0) |
| 5545 | { |
| 5546 | |
| 5547 | ALOGD("No transaction done cleaning up the variables"); |
| 5548 | cleanup_timer(); |
| 5549 | } |
| 5550 | break; |
| 5551 | default: |
| 5552 | break; |
| 5553 | } |
| 5554 | |
| 5555 | ALOGD ("%s: exit; event=0x%X transaction_data.current_transcation_state = 0x%x", __FUNCTION__, connEvent, |
| 5556 | transaction_data.current_transcation_state); |
| 5557 | } |
| 5558 | |
| 5559 | /******************************************************************************* |
| 5560 | ** |
| 5561 | ** Function: enableThread |
| 5562 | ** |
| 5563 | ** Description: thread to trigger enable/disable discovery related events |
| 5564 | ** |
| 5565 | ** Returns: None . |
| 5566 | ** |
| 5567 | *******************************************************************************/ |
| 5568 | void *enableThread(void *arg) |
| 5569 | { |
| 5570 | (void)arg; |
| 5571 | ALOGD ("%s: enter", __FUNCTION__); |
| 5572 | char last_request = get_last_request(); |
| 5573 | eScreenState_t last_screen_state_request = get_lastScreenStateRequest(); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5574 | #if((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5575 | set_AGC_process_state(false); |
| 5576 | #endif |
| 5577 | set_transcation_stat(false); |
| 5578 | bool screen_lock_flag = false; |
| 5579 | bool disable_discovery = false; |
| 5580 | |
| 5581 | if(sIsNfaEnabled != true || sIsDisabling == true) |
| 5582 | goto TheEnd; |
| 5583 | |
| 5584 | if (last_screen_state_request != NFA_SCREEN_STATE_DEFAULT) |
| 5585 | { |
| 5586 | ALOGD("update last screen state request: %d", last_screen_state_request); |
| 5587 | nfcManager_doSetScreenState(NULL, NULL, last_screen_state_request); |
| 5588 | if( last_screen_state_request == NFA_SCREEN_STATE_LOCKED) |
| 5589 | screen_lock_flag = true; |
| 5590 | } |
| 5591 | else |
| 5592 | { |
| 5593 | ALOGD("No request pending"); |
| 5594 | } |
| 5595 | |
| 5596 | |
| 5597 | if (last_request == 1) |
| 5598 | { |
| 5599 | ALOGD("send the last request enable"); |
| 5600 | sDiscoveryEnabled = false; |
| 5601 | sPollingEnabled = false; |
| 5602 | |
| 5603 | nfcManager_enableDiscovery(NULL, NULL, transaction_data.discovery_params.technologies_mask, transaction_data.discovery_params.enable_lptd, |
| 5604 | transaction_data.discovery_params.reader_mode, transaction_data.discovery_params.enable_host_routing, |
| 5605 | transaction_data.discovery_params.enable_p2p,transaction_data.discovery_params.restart); |
| 5606 | } |
| 5607 | else if (last_request == 2) |
| 5608 | { |
| 5609 | ALOGD("send the last request disable"); |
| 5610 | nfcManager_disableDiscovery(NULL, NULL); |
| 5611 | disable_discovery = true; |
| 5612 | } |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 5613 | #if(NXP_EXTNS == TRUE) |
| 5614 | else if (last_request == 3) |
| 5615 | { |
| 5616 | ALOGD("send the last request to enable P2P "); |
| 5617 | nfcManager_Enablep2p(NULL, NULL, transaction_data.discovery_params.enable_p2p); |
| 5618 | } |
| 5619 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5620 | if(screen_lock_flag && disable_discovery) |
| 5621 | { |
| 5622 | |
| 5623 | startRfDiscovery(true); |
| 5624 | } |
| 5625 | screen_lock_flag = false; |
| 5626 | disable_discovery = false; |
| 5627 | memset(&transaction_data, 0x00, sizeof(Transcation_Check_t)); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5628 | #if((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5629 | memset(&menableAGC_debug_t, 0x00, sizeof(enableAGC_debug_t)); |
| 5630 | #endif |
| 5631 | TheEnd: |
| 5632 | ALOGD ("%s: exit", __FUNCTION__); |
| 5633 | pthread_exit(NULL); |
| 5634 | return NULL; |
| 5635 | } |
| 5636 | |
| 5637 | /******************************************************************************* |
| 5638 | ** |
| 5639 | ** Function sig_handler |
| 5640 | ** |
| 5641 | ** Description This function is used to handle the different types of |
| 5642 | ** signal events. |
| 5643 | ** |
| 5644 | ** Returns None |
| 5645 | ** |
| 5646 | *******************************************************************************/ |
| 5647 | void sig_handler(int signo) |
| 5648 | { |
| 5649 | switch (signo) |
| 5650 | { |
| 5651 | case SIGINT: |
| 5652 | ALOGE("received SIGINT\n"); |
| 5653 | break; |
| 5654 | case SIGABRT: |
| 5655 | ALOGE("received SIGABRT\n"); |
| 5656 | NFA_HciW4eSETransaction_Complete(Wait); |
| 5657 | break; |
| 5658 | case SIGSEGV: |
| 5659 | ALOGE("received SIGSEGV\n"); |
| 5660 | break; |
| 5661 | case SIGHUP: |
| 5662 | ALOGE("received SIGHUP\n"); |
| 5663 | break; |
| 5664 | } |
| 5665 | } |
| 5666 | |
| 5667 | /******************************************************************************* |
| 5668 | ** |
| 5669 | ** Function nfcManager_doGetSeInterface |
| 5670 | ** |
| 5671 | ** Description This function is used to get the eSE Client interfaces. |
| 5672 | ** |
| 5673 | ** Returns integer - Physical medium |
| 5674 | ** |
| 5675 | *******************************************************************************/ |
| 5676 | static int nfcManager_doGetSeInterface(JNIEnv* e, jobject o, jint type) |
| 5677 | { |
| 5678 | unsigned long num = 0; |
| 5679 | switch(type) |
| 5680 | { |
| 5681 | case LDR_SRVCE: |
| 5682 | if(GetNxpNumValue (NAME_NXP_P61_LS_DEFAULT_INTERFACE, (void*)&num, sizeof(num))==false) |
| 5683 | { |
| 5684 | ALOGD ("NAME_NXP_P61_LS_DEFAULT_INTERFACE not found"); |
| 5685 | num = 1; |
| 5686 | } |
| 5687 | break; |
| 5688 | case JCOP_SRVCE: |
| 5689 | if(GetNxpNumValue (NAME_NXP_P61_JCOP_DEFAULT_INTERFACE, (void*)&num, sizeof(num))==false) |
| 5690 | { |
| 5691 | ALOGD ("NAME_NXP_P61_JCOP_DEFAULT_INTERFACE not found"); |
| 5692 | num = 1; |
| 5693 | } |
| 5694 | break; |
| 5695 | case LTSM_SRVCE: |
| 5696 | if(GetNxpNumValue (NAME_NXP_P61_LTSM_DEFAULT_INTERFACE, (void*)&num, sizeof(num))==false) |
| 5697 | { |
| 5698 | ALOGD ("NAME_NXP_P61_LTSM_DEFAULT_INTERFACE not found"); |
| 5699 | num = 1; |
| 5700 | } |
| 5701 | break; |
| 5702 | default: |
| 5703 | break; |
| 5704 | } |
| 5705 | ALOGD ("%d: nfcManager_doGetSeInterface", num); |
| 5706 | return num; |
| 5707 | } |
| 5708 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 5709 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5710 | /********************************************************************************** |
| 5711 | ** |
| 5712 | ** Function: pollT3TThread |
| 5713 | ** |
| 5714 | ** Description: This thread sends commands to switch from P2P to T3T |
| 5715 | ** When ReaderMode is enabled, When P2P is detected,Switch to T3T |
| 5716 | ** with Frame RF interface and Poll for T3T |
| 5717 | ** |
| 5718 | ** Returns: None. |
| 5719 | ** |
| 5720 | **********************************************************************************/ |
| 5721 | static void* pollT3TThread(void *arg) |
| 5722 | { |
| 5723 | ALOGD ("%s: enter", __FUNCTION__); |
| 5724 | bool status=false; |
| 5725 | |
| 5726 | if (sReaderModeEnabled && (sTechMask == NFA_TECHNOLOGY_MASK_F)) |
| 5727 | { |
| 5728 | /*Deactivate RF to go to W4_HOST_SELECT state |
| 5729 | *Send Select Command to Switch to FrameRF interface from NFCDEP interface |
| 5730 | *After NFC-DEP activation with FrameRF Intf, invoke T3T Polling Cmd*/ |
| 5731 | { |
| 5732 | SyncEventGuard g (sRespCbEvent); |
| 5733 | if (NFA_STATUS_OK != (status = NFA_Deactivate (TRUE))) //deactivate to sleep state |
| 5734 | { |
| 5735 | ALOGE ("%s: deactivate failed, status = %d", __FUNCTION__, status); |
| 5736 | } |
| 5737 | if (sRespCbEvent.wait (2000) == false) //if timeout occurred |
| 5738 | { |
| 5739 | ALOGE ("%s: timeout waiting for deactivate", __FUNCTION__); |
| 5740 | } |
| 5741 | } |
| 5742 | { |
| 5743 | SyncEventGuard g2 (sRespCbEvent); |
| 5744 | ALOGD ("Switching RF Interface from NFC-DEP to FrameRF for T3T\n"); |
| 5745 | if (NFA_STATUS_OK != (status = NFA_Select (*((UINT8*)arg), NFA_PROTOCOL_T3T, NFA_INTERFACE_FRAME))) |
| 5746 | { |
| 5747 | ALOGE ("%s: NFA_Select failed, status = %d", __FUNCTION__, status); |
| 5748 | } |
| 5749 | if (sRespCbEvent.wait (2000) == false) //if timeout occured |
| 5750 | { |
| 5751 | ALOGE ("%s: timeout waiting for select", __FUNCTION__); |
| 5752 | } |
| 5753 | } |
| 5754 | } |
| 5755 | ALOGD ("%s: exit", __FUNCTION__); |
| 5756 | pthread_exit(NULL); |
| 5757 | return NULL; |
| 5758 | } |
| 5759 | |
| 5760 | /********************************************************************************** |
| 5761 | ** |
| 5762 | ** Function: switchP2PToT3TRead |
| 5763 | ** |
| 5764 | ** Description: Create a thread to change the RF interface by Deactivating to Sleep |
| 5765 | ** |
| 5766 | ** Returns: None. |
| 5767 | ** |
| 5768 | **********************************************************************************/ |
| 5769 | static bool switchP2PToT3TRead(UINT8 disc_id) |
| 5770 | { |
| 5771 | pthread_t pollT3TThreadId; |
| 5772 | int irret = -1; |
| 5773 | ALOGD ("%s:entry", __FUNCTION__); |
| 5774 | felicaReader_Disc_id = disc_id; |
| 5775 | |
| 5776 | /* Transcation is done process the last request*/ |
| 5777 | pthread_attr_t attr; |
| 5778 | pthread_attr_init(&attr); |
| 5779 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 5780 | irret = pthread_create(&pollT3TThreadId, &attr, pollT3TThread, (void*)&felicaReader_Disc_id); |
| 5781 | if(irret != 0) |
| 5782 | { |
| 5783 | ALOGE("Unable to create the thread"); |
| 5784 | } |
| 5785 | pthread_attr_destroy(&attr); |
| 5786 | ALOGD ("%s:exit", __FUNCTION__); |
| 5787 | return irret; |
| 5788 | } |
| 5789 | |
| 5790 | static void NxpResponsePropCmd_Cb(UINT8 event, UINT16 param_len, UINT8 *p_param) |
| 5791 | { |
| 5792 | ALOGD("NxpResponsePropCmd_Cb Received length data = 0x%x status = 0x%x", param_len, p_param[3]); |
| 5793 | SyncEventGuard guard (sNfaNxpNtfEvent); |
| 5794 | sNfaNxpNtfEvent.notifyOne (); |
| 5795 | } |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 5796 | |
| 5797 | /******************************************************************************* |
| 5798 | ** |
| 5799 | ** Function: nfcManager_setProvisionMode |
| 5800 | ** |
| 5801 | ** Description: set/reset provision mode |
| 5802 | ** e: JVM environment. |
| 5803 | ** o: Java object. |
| 5804 | ** |
| 5805 | ** Returns: None. |
| 5806 | ** |
| 5807 | *******************************************************************************/ |
| 5808 | static void nfcManager_setProvisionMode(JNIEnv* e, jobject o, jboolean provisionMode) |
| 5809 | { |
| 5810 | ALOGD ("Enter :%s provisionMode = %d", __FUNCTION__,provisionMode); |
| 5811 | sProvisionMode = provisionMode; |
| 5812 | NFA_setProvisionMode(provisionMode); |
| 5813 | // When disabling provisioning mode, make sure configuration of routing table is also updated |
| 5814 | // this is required to make sure p2p is blocked during locked screen |
| 5815 | if ( !provisionMode ) |
| 5816 | { |
| 5817 | RoutingManager::getInstance().commitRouting(); |
| 5818 | } |
| 5819 | } |
| 5820 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5821 | /********************************************************************************** |
| 5822 | ** |
| 5823 | ** Function: checkforNfceeBuffer |
| 5824 | ** |
| 5825 | ** Description: checking for the Nfcee Buffer (GetConfigs for SWP_INT_SESSION_ID (EA and EB)) |
| 5826 | ** |
| 5827 | ** Returns: None . |
| 5828 | ** |
| 5829 | **********************************************************************************/ |
| 5830 | void checkforNfceeBuffer() |
| 5831 | { |
| 5832 | int i, count = 0; |
| 5833 | |
| 5834 | for(i=4;i<12;i++) |
| 5835 | { |
| 5836 | if(sConfig[i] == 0xff) |
| 5837 | count++; |
| 5838 | } |
| 5839 | |
| 5840 | if(count >= 8) |
| 5841 | sNfceeConfigured = 1; |
| 5842 | else |
| 5843 | sNfceeConfigured = 0; |
| 5844 | |
| 5845 | memset (sConfig, 0, sizeof (sConfig)); |
| 5846 | |
| 5847 | } |
| 5848 | /********************************************************************************** |
| 5849 | ** |
| 5850 | ** Function: checkforNfceeConfig |
| 5851 | ** |
| 5852 | ** Description: checking for the Nfcee is configured or not (GetConfigs for SWP_INT_SESSION_ID (EA and EB)) |
| 5853 | ** |
| 5854 | ** Returns: None . |
| 5855 | ** |
| 5856 | **********************************************************************************/ |
| 5857 | void checkforNfceeConfig() |
| 5858 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5859 | UINT8 uicc_flag = 0,ese_flag = 0; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5860 | |
| 5861 | unsigned long timeout_buff_val=0,check_cnt=0,retry_cnt=0; |
| 5862 | |
| 5863 | tNFA_STATUS status; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5864 | tNFA_PMID param_ids_UICC[] = {0xA0, 0xEA}; |
| 5865 | tNFA_PMID param_ids_eSE[] = {0xA0, 0xEB}; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5866 | |
| 5867 | ALOGD ("%s: enter", __FUNCTION__); |
| 5868 | |
| 5869 | status = GetNxpNumValue(NAME_NXP_DEFAULT_NFCEE_TIMEOUT, (void*)&timeout_buff_val, sizeof(timeout_buff_val)); |
| 5870 | |
| 5871 | if(status == TRUE) |
| 5872 | { |
| 5873 | check_cnt = timeout_buff_val*RETRY_COUNT; |
| 5874 | } |
| 5875 | else |
| 5876 | { |
| 5877 | check_cnt = default_count*RETRY_COUNT; |
| 5878 | } |
| 5879 | |
| 5880 | ALOGD ("NAME_DEFAULT_NFCEE_TIMEOUT = %lu", check_cnt); |
| 5881 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5882 | if(SecureElement::getInstance().getEeStatus(ESE_HANDLE) == NFC_NFCEE_STATUS_ACTIVE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5883 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5884 | ese_flag = 0x01; |
| 5885 | ALOGD("eSE_flag SET"); |
| 5886 | } |
| 5887 | if(SecureElement::getInstance().getEeStatus(UICC_HANDLE) == NFC_NFCEE_STATUS_ACTIVE) |
| 5888 | { |
| 5889 | uicc_flag = 0x01; |
| 5890 | ALOGD("uicc_flag SET"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5891 | } |
| 5892 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5893 | if((ese_flag == 0x01)||(uicc_flag == 0x01)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5894 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5895 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5896 | |
| 5897 | if(uicc_flag) |
| 5898 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5899 | sCheckNfceeFlag = 1; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5900 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5901 | SyncEventGuard guard (android::sNfaGetConfigEvent); |
| 5902 | while(check_cnt > retry_cnt) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5903 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5904 | status = NFA_GetConfig(0x01,param_ids_UICC); |
| 5905 | if(status == NFA_STATUS_OK) |
| 5906 | { |
| 5907 | android::sNfaGetConfigEvent.wait(); |
| 5908 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5909 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5910 | if(sNfceeConfigured == 1) |
| 5911 | { |
| 5912 | ALOGD("UICC Not Configured"); |
| 5913 | } |
| 5914 | else |
| 5915 | { |
| 5916 | ALOGD("UICC Configured"); |
| 5917 | #if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE) |
| 5918 | dualUiccInfo.uiccConfigStat = UICC_CONFIGURED; |
| 5919 | #endif |
| 5920 | break; |
| 5921 | } |
| 5922 | usleep(100000); |
| 5923 | retry_cnt++; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5924 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5925 | } |
| 5926 | |
| 5927 | if(check_cnt <= retry_cnt) |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5928 | ALOGE("UICC Not Configured"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5929 | retry_cnt=0; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5930 | #if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE) |
| 5931 | sCheckNfceeFlag = 0; |
| 5932 | getUiccContext(); |
| 5933 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5934 | } |
| 5935 | |
| 5936 | if(ese_flag) |
| 5937 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5938 | sCheckNfceeFlag = 1; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5939 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5940 | SyncEventGuard guard (android::sNfaGetConfigEvent); |
| 5941 | while(check_cnt > retry_cnt) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5942 | { |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5943 | status = NFA_GetConfig(0x01,param_ids_eSE); |
| 5944 | if(status == NFA_STATUS_OK) |
| 5945 | { |
| 5946 | android::sNfaGetConfigEvent.wait(); |
| 5947 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5948 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5949 | if(sNfceeConfigured == 1) |
| 5950 | { |
| 5951 | ALOGD("eSE Not Configured"); |
| 5952 | } |
| 5953 | else |
| 5954 | { |
| 5955 | ALOGD("eSE Configured"); |
| 5956 | break; |
| 5957 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5958 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5959 | usleep(100000); |
| 5960 | retry_cnt++; |
| 5961 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5962 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5963 | if(check_cnt <= retry_cnt) |
| 5964 | ALOGD("eSE Not Configured"); |
| 5965 | retry_cnt=0; |
| 5966 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5967 | } |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 5968 | RoutingManager::getInstance().handleSERemovedNtf(); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5969 | sCheckNfceeFlag = 0; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5970 | } |
| 5971 | #endif |
| 5972 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 5973 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 5974 | static void nfaNxpSelfTestNtfTimerCb (union sigval) |
| 5975 | { |
| 5976 | ALOGD ("%s", __FUNCTION__); |
| 5977 | ALOGD("NXP SWP SelfTest : Can't get a notification about SWP Status!!"); |
| 5978 | SyncEventGuard guard (sNfaNxpNtfEvent); |
| 5979 | sNfaNxpNtfEvent.notifyOne (); |
| 5980 | SetCbStatus(NFA_STATUS_FAILED); |
| 5981 | } |
| 5982 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 5983 | #if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE) |
| 5984 | /********************************************************************************** |
| 5985 | ** |
| 5986 | ** Function: getUiccContext |
| 5987 | ** |
| 5988 | ** Description: Read and store UICC context values |
| 5989 | ** Respective context will be applied during next switching |
| 5990 | ** |
| 5991 | ** Returns: None |
| 5992 | ** |
| 5993 | **********************************************************************************/ |
| 5994 | static void getUiccContext() |
| 5995 | { |
| 5996 | UINT8 i; |
| 5997 | tNFA_STATUS status; |
| 5998 | tNFA_PMID param_ids_UICC_getContext[] = {0xA0, 0xF4}; |
| 5999 | tNFA_PMID param_ids_UICC_getOtherContext[] = {0xA0, 0xF5}; |
| 6000 | ALOGD ("%s: Enter", __FUNCTION__); |
| 6001 | |
| 6002 | SyncEventGuard guard (android::sNfaGetConfigEvent); |
| 6003 | status = NFA_GetConfig(0x01,param_ids_UICC_getContext); |
| 6004 | if(status == NFA_STATUS_OK) |
| 6005 | { |
| 6006 | android::sNfaGetConfigEvent.wait(); |
| 6007 | } |
| 6008 | |
| 6009 | ALOGD ("%s: save UICC context Info : Len = %d", __FUNCTION__,sCurrentConfigLen); |
| 6010 | /*If the session ID is changed or uicc changed*/ |
| 6011 | if((dualUiccInfo.sUicc1CntxLen != 0)&&(sSelectedUicc == 0x01)) |
| 6012 | { |
| 6013 | for(i= 5 ; i < 13; i++) |
| 6014 | { |
| 6015 | if(sConfig[i] != dualUiccInfo.sUicc1Cntx[1]) |
| 6016 | break; |
| 6017 | } |
| 6018 | if(i != 13) |
| 6019 | { |
| 6020 | memcpy(dualUiccInfo.sUicc1Cntx, sConfig, sCurrentConfigLen); |
| 6021 | } |
| 6022 | } |
| 6023 | /*If the session ID is changed or uicc changed*/ |
| 6024 | if((dualUiccInfo.sUicc2CntxLen != 0)&&(sSelectedUicc == 0x02)) |
| 6025 | { |
| 6026 | for(i= 5 ; i < 13; i++) |
| 6027 | { |
| 6028 | if(sConfig[i] != dualUiccInfo.sUicc2Cntx[1]) |
| 6029 | break; |
| 6030 | } |
| 6031 | if(i != 13) |
| 6032 | { |
| 6033 | memcpy(dualUiccInfo.sUicc2Cntx, sConfig, sCurrentConfigLen); |
| 6034 | } |
| 6035 | } |
| 6036 | |
| 6037 | /*For the first power cycle for uicc1*/ |
| 6038 | if((dualUiccInfo.sUicc1CntxLen == 0)&&(sSelectedUicc == 0x01)) |
| 6039 | { |
| 6040 | ALOGD ("%s: power cycle storing UICC1 info",__FUNCTION__); |
| 6041 | dualUiccInfo.sUicc1CntxLen = sCurrentConfigLen; |
| 6042 | for(i= 5 ; i < 13; i++) |
| 6043 | { |
| 6044 | if(sConfig[i] != (UINT8)0xFF) |
| 6045 | break; |
| 6046 | } |
| 6047 | if(i == 13) |
| 6048 | { |
| 6049 | dualUiccInfo.sUicc1CntxLen = 0; |
| 6050 | } |
| 6051 | else |
| 6052 | { |
| 6053 | memcpy(dualUiccInfo.sUicc1Cntx, sConfig, sCurrentConfigLen); |
| 6054 | status = NFA_GetConfig(0x01,param_ids_UICC_getOtherContext); |
| 6055 | if(status == NFA_STATUS_OK) |
| 6056 | { |
| 6057 | android::sNfaGetConfigEvent.wait(); |
| 6058 | } |
| 6059 | memcpy(dualUiccInfo.sUicc1TechCapblty, sConfig, sCurrentConfigLen); |
| 6060 | } |
| 6061 | } |
| 6062 | /*For the first power cycle for uicc2*/ |
| 6063 | else if((dualUiccInfo.sUicc2CntxLen == 0)&&(sSelectedUicc == 0x02)) |
| 6064 | { |
| 6065 | ALOGD ("%s: power cycle storing UICC2 info",__FUNCTION__); |
| 6066 | dualUiccInfo.sUicc2CntxLen = sCurrentConfigLen; |
| 6067 | for(i= 5 ; i < 13; i++) |
| 6068 | { |
| 6069 | if(sConfig[i] != (UINT8)0xFF) |
| 6070 | break; |
| 6071 | } |
| 6072 | if(i == 13) |
| 6073 | { |
| 6074 | dualUiccInfo.sUicc2CntxLen = 0; |
| 6075 | } |
| 6076 | else |
| 6077 | { |
| 6078 | memcpy(dualUiccInfo.sUicc2Cntx, sConfig, sCurrentConfigLen); |
| 6079 | status = NFA_GetConfig(0x01,param_ids_UICC_getOtherContext); |
| 6080 | if(status == NFA_STATUS_OK) |
| 6081 | { |
| 6082 | android::sNfaGetConfigEvent.wait(); |
| 6083 | } |
| 6084 | memcpy(dualUiccInfo.sUicc2TechCapblty, sConfig, sCurrentConfigLen); |
| 6085 | } |
| 6086 | } |
| 6087 | else |
| 6088 | { |
| 6089 | ALOGD ("%s: UICC info are already stored..",__FUNCTION__); |
| 6090 | } |
| 6091 | ALOGD ("%s: Exit", __FUNCTION__); |
| 6092 | } |
| 6093 | |
| 6094 | /********************************************************************************** |
| 6095 | ** |
| 6096 | ** Function: notifyUiccEvent |
| 6097 | ** |
| 6098 | ** Description: Notifies UICC event sto Service |
| 6099 | ** Possible values: |
| 6100 | ** UICC_CONNECTED_0 - 0 UICC connected |
| 6101 | ** UICC_CONNECTED_1 - 1 UICC connected |
| 6102 | ** UICC_CONNECTED_2 - 2 UICCs connected |
| 6103 | ** |
| 6104 | ** Returns: None |
| 6105 | ** |
| 6106 | **********************************************************************************/ |
| 6107 | static void notifyUiccEvent (union sigval) |
| 6108 | { |
| 6109 | ALOGD ("%s", __FUNCTION__); |
| 6110 | struct nfc_jni_native_data *nat = getNative(NULL, NULL); |
| 6111 | JNIEnv* e; |
| 6112 | ScopedAttach attach(nat->vm, &e); |
| 6113 | if (e == NULL) |
| 6114 | { |
| 6115 | ALOGE ("jni env is null"); |
| 6116 | return; |
| 6117 | } |
| 6118 | if(dualUiccInfo.uiccActivStat == 0x00) /*No UICC Detected*/ |
| 6119 | { |
| 6120 | e->CallVoidMethod (nat->manager, android::gCachedNfcManagerNotifyUiccStatusEvent, UICC_CONNECTED_0); |
| 6121 | } |
| 6122 | else if((dualUiccInfo.uiccActivStat == 0x01)||(dualUiccInfo.uiccActivStat == 0x02)) /*One UICC Detected*/ |
| 6123 | { |
| 6124 | e->CallVoidMethod (nat->manager, android::gCachedNfcManagerNotifyUiccStatusEvent, UICC_CONNECTED_1); |
| 6125 | } |
| 6126 | else if(dualUiccInfo.uiccActivStat == 0x03) /*Two UICC Detected*/ |
| 6127 | { |
| 6128 | e->CallVoidMethod (nat->manager, android::gCachedNfcManagerNotifyUiccStatusEvent, UICC_CONNECTED_2); |
| 6129 | } |
| 6130 | |
| 6131 | } |
| 6132 | |
| 6133 | static int nfcManager_staticDualUicc_Precondition(int uiccSlot) |
| 6134 | { |
| 6135 | unsigned long uicc_active_state = 0; |
| 6136 | uint8_t retStat = UICC_NOT_CONFIGURED; |
| 6137 | |
| 6138 | if(GetNxpNumValue (NAME_NXP_DUAL_UICC_ENABLE, (void*)&uicc_active_state, sizeof(uicc_active_state))) |
| 6139 | { |
| 6140 | ALOGD ("NXP_DUAL_UICC_ENABLE : 0x%02x",uicc_active_state); |
| 6141 | } |
| 6142 | else |
| 6143 | { |
| 6144 | ALOGE ("NXP_DUAL_UICC_ENABLE Not found taking default value 0x01"); |
| 6145 | uicc_active_state = 0x00; |
| 6146 | } |
| 6147 | |
| 6148 | if(uicc_active_state != 0x01) |
| 6149 | { |
| 6150 | ALOGE("%s:FAIL Dual UICC feature not available", __FUNCTION__); |
| 6151 | retStat = DUAL_UICC_FEATURE_NOT_AVAILABLE; |
| 6152 | } |
| 6153 | else if(sIsDisabling) |
| 6154 | { |
| 6155 | ALOGE("%s:FAIL Nfc is Disabling : Switch UICC not allowed", __FUNCTION__); |
| 6156 | retStat = DUAL_UICC_ERROR_NFC_TURNING_OFF; |
| 6157 | } |
| 6158 | else if(SecureElement::getInstance().isBusy()) |
| 6159 | { |
| 6160 | ALOGE("%s:FAIL SE wired-mode : busy", __FUNCTION__); |
| 6161 | retStat = DUAL_UICC_ERROR_NFCC_BUSY; |
| 6162 | } |
| 6163 | else if(rfActivation) |
| 6164 | { |
| 6165 | ALOGE("%s:FAIL RF session ongoing", __FUNCTION__); |
| 6166 | retStat = DUAL_UICC_ERROR_NFCC_BUSY; |
| 6167 | } |
| 6168 | else if((uiccSlot != 0x01) && (uiccSlot != 0x02)) |
| 6169 | { |
| 6170 | ALOGE("%s: Invalid slot id"); |
| 6171 | retStat = DUAL_UICC_ERROR_INVALID_SLOT; |
| 6172 | } |
| 6173 | else if(get_transcation_stat() == true) |
| 6174 | { |
| 6175 | ALOGE ("%s: FAIL Transaction in progress", __FUNCTION__); |
| 6176 | retStat = DUAL_UICC_ERROR_NFCC_BUSY; |
| 6177 | } |
| 6178 | else |
| 6179 | { |
| 6180 | set_transcation_stat(true); |
| 6181 | } |
| 6182 | return retStat; |
| 6183 | } |
| 6184 | |
| 6185 | #endif |
| 6186 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 6187 | static void nfaNxpSelfTestNtfCallback(UINT8 event, UINT16 param_len, UINT8 *p_param) |
| 6188 | { |
| 6189 | (void)event; |
| 6190 | ALOGD ("%s", __FUNCTION__); |
| 6191 | |
| 6192 | if(param_len == 0x05 && p_param[3] == 00) //p_param[4] 0x00:SWP Link OK 0x03:SWP link dead. |
| 6193 | { |
| 6194 | ALOGD("NXP SWP SelfTest : SWP Link OK "); |
| 6195 | SetCbStatus(NFA_STATUS_OK); |
| 6196 | } |
| 6197 | else |
| 6198 | { |
| 6199 | if(p_param[3] == 0x03) ALOGD("NXP SWP SelfTest : SWP Link dead "); |
| 6200 | SetCbStatus(NFA_STATUS_FAILED); |
| 6201 | } |
| 6202 | |
| 6203 | switch(p_param[4]){ //information of PMUVCC. |
| 6204 | case 0x00 : ALOGD("NXP SWP SelfTest : No PMUVCC ");break; |
| 6205 | case 0x01 : ALOGD("NXP SWP SelfTest : PMUVCC = 1.8V ");break; |
| 6206 | case 0x02 : ALOGD("NXP SWP SelfTest : PMUVCC = 3.3V ");break; |
| 6207 | case 0x03 : ALOGD("NXP SWP SelfTest : PMUVCC = undetermined ");break; |
| 6208 | default : ALOGD("NXP SWP SelfTest : unknown PMUVCC ");break; |
| 6209 | } |
| 6210 | |
| 6211 | SyncEventGuard guard (sNfaNxpNtfEvent); |
| 6212 | sNfaNxpNtfEvent.notifyOne (); |
| 6213 | } |
| 6214 | |
| 6215 | static void nfcManager_doPrbsOn(JNIEnv* e, jobject o, jint prbs, jint hw_prbs, jint tech, jint rate) |
| 6216 | { |
| 6217 | (void)e; |
| 6218 | (void)o; |
| 6219 | ALOGD ("%s: enter", __FUNCTION__); |
| 6220 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 6221 | // bool stat = false; /*commented to eliminate unused variable warning*/ |
| 6222 | |
| 6223 | if (!sIsNfaEnabled) { |
| 6224 | ALOGD("NFC does not enabled!!"); |
| 6225 | return; |
| 6226 | } |
| 6227 | |
| 6228 | if (sDiscoveryEnabled) { |
| 6229 | ALOGD("Discovery must not be enabled for SelfTest"); |
| 6230 | return ; |
| 6231 | } |
| 6232 | |
| 6233 | if(tech < 0 || tech > 2) |
| 6234 | { |
| 6235 | ALOGD("Invalid tech! please choose A or B or F"); |
| 6236 | return; |
| 6237 | } |
| 6238 | |
| 6239 | if(rate < 0 || rate > 3){ |
| 6240 | ALOGD("Invalid bitrate! please choose 106 or 212 or 424 or 848"); |
| 6241 | return; |
| 6242 | } |
| 6243 | |
| 6244 | //Technology to stream 0x00:TypeA 0x01:TypeB 0x02:TypeF |
| 6245 | //Bitrate 0x00:106kbps 0x01:212kbps 0x02:424kbps 0x03:848kbps |
| 6246 | //prbs and hw_prbs 0x00 or 0x01 two extra parameters included in case of pn548AD |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 6247 | #if((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 6248 | UINT8 param[4]; |
| 6249 | memset(param, 0x00, sizeof(param)); |
| 6250 | param[0] = prbs; |
| 6251 | param[1] = hw_prbs; |
| 6252 | param[2] = tech; //technology |
| 6253 | param[3] = rate; //bitrate |
| 6254 | ALOGD("phNxpNciHal_getPrbsCmd: PRBS = %d HW_PRBS = %d", prbs, hw_prbs); |
| 6255 | #else |
| 6256 | UINT8 param[2]; |
| 6257 | memset(param, 0x00, sizeof(param)); |
| 6258 | param[0] = tech; |
| 6259 | param[1] = rate; |
| 6260 | #endif |
| 6261 | switch (tech) |
| 6262 | { |
| 6263 | case 0x00: |
| 6264 | ALOGD("phNxpNciHal_getPrbsCmd - NFC_RF_TECHNOLOGY_A"); |
| 6265 | break; |
| 6266 | case 0x01: |
| 6267 | ALOGD("phNxpNciHal_getPrbsCmd - NFC_RF_TECHNOLOGY_B"); |
| 6268 | break; |
| 6269 | case 0x02: |
| 6270 | ALOGD("phNxpNciHal_getPrbsCmd - NFC_RF_TECHNOLOGY_F"); |
| 6271 | break; |
| 6272 | default: |
| 6273 | break; |
| 6274 | } |
| 6275 | switch (rate) |
| 6276 | { |
| 6277 | case 0x00: |
| 6278 | ALOGD("phNxpNciHal_getPrbsCmd - NFC_BIT_RATE_106"); |
| 6279 | break; |
| 6280 | case 0x01: |
| 6281 | ALOGD("phNxpNciHal_getPrbsCmd - NFC_BIT_RATE_212"); |
| 6282 | break; |
| 6283 | case 0x02: |
| 6284 | ALOGD("phNxpNciHal_getPrbsCmd - NFC_BIT_RATE_424"); |
| 6285 | break; |
| 6286 | case 0x03: |
| 6287 | ALOGD("phNxpNciHal_getPrbsCmd - NFC_BIT_RATE_848"); |
| 6288 | break; |
| 6289 | default: |
| 6290 | break; |
| 6291 | } |
| 6292 | //step2. PRBS Test stop : CORE RESET_CMD |
| 6293 | status = Nxp_SelfTest(3, param); //CORE_RESET_CMD |
| 6294 | if(NFA_STATUS_OK != status) |
| 6295 | { |
| 6296 | ALOGD("%s: CORE RESET_CMD Fail!", __FUNCTION__); |
| 6297 | status = NFA_STATUS_FAILED; |
| 6298 | goto TheEnd; |
| 6299 | } |
| 6300 | //step3. PRBS Test stop : CORE_INIT_CMD |
| 6301 | status = Nxp_SelfTest(4, param); //CORE_INIT_CMD |
| 6302 | if(NFA_STATUS_OK != status) |
| 6303 | { |
| 6304 | ALOGD("%s: CORE_INIT_CMD Fail!", __FUNCTION__); |
| 6305 | status = NFA_STATUS_FAILED; |
| 6306 | goto TheEnd; |
| 6307 | } |
| 6308 | //step4. : NXP_ACT_PROP_EXTN |
| 6309 | status = Nxp_SelfTest(5, param); //NXP_ACT_PROP_EXTN |
| 6310 | if(NFA_STATUS_OK != status) |
| 6311 | { |
| 6312 | ALOGD("%s: NXP_ACT_PROP_EXTN Fail!", __FUNCTION__); |
| 6313 | status = NFA_STATUS_FAILED; |
| 6314 | goto TheEnd; |
| 6315 | } |
| 6316 | |
| 6317 | status = Nxp_SelfTest(1, param); |
| 6318 | ALOGD ("%s: exit; status =0x%X", __FUNCTION__,status); |
| 6319 | |
| 6320 | TheEnd: |
| 6321 | //Factory Test Code |
| 6322 | ALOGD ("%s: exit; status =0x%X", __FUNCTION__,status); |
| 6323 | return; |
| 6324 | } |
| 6325 | |
| 6326 | static void nfcManager_doPrbsOff(JNIEnv* e, jobject o) |
| 6327 | { |
| 6328 | (void)e; |
| 6329 | (void)o; |
| 6330 | ALOGD ("%s: enter", __FUNCTION__); |
| 6331 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 6332 | // bool stat = false; /*commented to eliminate unused variable warning*/ |
| 6333 | UINT8 param; |
| 6334 | |
| 6335 | if (!sIsNfaEnabled) { |
| 6336 | ALOGD("NFC does not enabled!!"); |
| 6337 | return; |
| 6338 | } |
| 6339 | |
| 6340 | if (sDiscoveryEnabled) { |
| 6341 | ALOGD("Discovery must not be enabled for SelfTest"); |
| 6342 | return; |
| 6343 | } |
| 6344 | |
| 6345 | //Factory Test Code |
| 6346 | //step1. PRBS Test stop : VEN RESET |
| 6347 | status = Nxp_SelfTest(2, ¶m); //VEN RESET |
| 6348 | if(NFA_STATUS_OK != status) |
| 6349 | { |
| 6350 | ALOGD("step1. PRBS Test stop : VEN RESET Fail!"); |
| 6351 | status = NFA_STATUS_FAILED; |
| 6352 | goto TheEnd; |
| 6353 | } |
| 6354 | |
| 6355 | TheEnd: |
| 6356 | //Factory Test Code |
| 6357 | ALOGD ("%s: exit; status =0x%X", __FUNCTION__,status); |
| 6358 | |
| 6359 | return; |
| 6360 | } |
| 6361 | |
| 6362 | static jint nfcManager_SWPSelfTest(JNIEnv* e, jobject o, jint ch) |
| 6363 | { |
| 6364 | (void)e; |
| 6365 | (void)o; |
| 6366 | ALOGD ("%s: enter", __FUNCTION__); |
| 6367 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 6368 | tNFA_STATUS regcb_stat = NFA_STATUS_FAILED; |
| 6369 | UINT8 param[1]; |
| 6370 | |
| 6371 | if (!sIsNfaEnabled) { |
| 6372 | ALOGD("NFC does not enabled!!"); |
| 6373 | return status; |
| 6374 | } |
| 6375 | |
| 6376 | if (sDiscoveryEnabled) { |
| 6377 | ALOGD("Discovery must not be enabled for SelfTest"); |
| 6378 | return status; |
| 6379 | } |
| 6380 | |
| 6381 | if (ch < 0 || ch > 1){ |
| 6382 | ALOGD("Invalid channel!! please choose 0 or 1"); |
| 6383 | return status; |
| 6384 | } |
| 6385 | |
| 6386 | |
| 6387 | //step1. : CORE RESET_CMD |
| 6388 | status = Nxp_SelfTest(3, param); //CORE_RESET_CMD |
| 6389 | if(NFA_STATUS_OK != status) |
| 6390 | { |
| 6391 | ALOGD("step2. PRBS Test stop : CORE RESET_CMD Fail!"); |
| 6392 | status = NFA_STATUS_FAILED; |
| 6393 | goto TheEnd; |
| 6394 | } |
| 6395 | |
| 6396 | //step2. : CORE_INIT_CMD |
| 6397 | status = Nxp_SelfTest(4, param); //CORE_INIT_CMD |
| 6398 | if(NFA_STATUS_OK != status) |
| 6399 | { |
| 6400 | ALOGD("step3. PRBS Test stop : CORE_INIT_CMD Fail!"); |
| 6401 | status = NFA_STATUS_FAILED; |
| 6402 | goto TheEnd; |
| 6403 | } |
| 6404 | |
| 6405 | //step3. : NXP_ACT_PROP_EXTN |
| 6406 | status = Nxp_SelfTest(5, param); //NXP_ACT_PROP_EXTN |
| 6407 | if(NFA_STATUS_OK != status) |
| 6408 | { |
| 6409 | ALOGD("step: NXP_ACT_PROP_EXTN Fail!"); |
| 6410 | status = NFA_STATUS_FAILED; |
| 6411 | goto TheEnd; |
| 6412 | } |
| 6413 | |
| 6414 | regcb_stat = NFA_RegVSCback (true,nfaNxpSelfTestNtfCallback); //Register CallBack for NXP NTF |
| 6415 | if(NFA_STATUS_OK != regcb_stat) |
| 6416 | { |
| 6417 | ALOGD("To Regist Ntf Callback is Fail!"); |
| 6418 | goto TheEnd; |
| 6419 | } |
| 6420 | |
| 6421 | param[0] = ch; // SWP channel 0x00 : SWP1(UICC) 0x01:SWP2(eSE) |
| 6422 | status = Nxp_SelfTest(0, param); |
| 6423 | if(NFA_STATUS_OK != status) |
| 6424 | { |
| 6425 | status = NFA_STATUS_FAILED; |
| 6426 | goto TheEnd; |
| 6427 | } |
| 6428 | |
| 6429 | { |
| 6430 | ALOGD("NFC NXP SelfTest wait for Notificaiton"); |
| 6431 | nfaNxpSelfTestNtfTimer.set(1000, nfaNxpSelfTestNtfTimerCb); |
| 6432 | SyncEventGuard guard (sNfaNxpNtfEvent); |
| 6433 | sNfaNxpNtfEvent.wait(); //wait for NXP Self NTF to come |
| 6434 | } |
| 6435 | |
| 6436 | status = GetCbStatus(); |
| 6437 | if(NFA_STATUS_OK != status) |
| 6438 | { |
| 6439 | status = NFA_STATUS_FAILED; |
| 6440 | } |
| 6441 | |
| 6442 | TheEnd: |
| 6443 | if(NFA_STATUS_OK == regcb_stat) { |
| 6444 | regcb_stat = NFA_RegVSCback (false,nfaNxpSelfTestNtfCallback); //DeRegister CallBack for NXP NTF |
| 6445 | } |
| 6446 | nfaNxpSelfTestNtfTimer.kill(); |
| 6447 | ALOGD ("%s: exit; status =0x%X", __FUNCTION__,status); |
| 6448 | return status; |
| 6449 | } |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 6450 | |
| 6451 | |
| 6452 | /******************************************************************************* |
| 6453 | ** |
| 6454 | ** Function: nfcManager_doPartialInitialize |
| 6455 | ** |
| 6456 | ** Description: Initializes the NFC partially if it is not initialized. |
| 6457 | ** This will be required for transceive during NFC off. |
| 6458 | ** |
| 6459 | ** |
| 6460 | ** Returns: true/false . |
| 6461 | ** |
| 6462 | *******************************************************************************/ |
| 6463 | static bool nfcManager_doPartialInitialize () |
| 6464 | { |
| 6465 | |
| 6466 | ALOGD("%s enter", __FUNCTION__); |
| 6467 | tNFA_STATUS stat = NFA_STATUS_OK; |
| 6468 | if (sIsNfaEnabled || gsNfaPartialEnabled) |
| 6469 | { |
| 6470 | ALOGD ("%s: NFC already enabled", __FUNCTION__); |
| 6471 | return true; |
| 6472 | } |
| 6473 | NfcAdaptation& theInstance = NfcAdaptation::GetInstance(); |
| 6474 | theInstance.MinInitialize(); |
| 6475 | |
| 6476 | tHAL_NFC_ENTRY* halFuncEntries = theInstance.GetHalEntryFuncs (); |
| 6477 | ALOGD("%s: calling nfa init", __FUNCTION__); |
| 6478 | if(NULL == halFuncEntries) |
| 6479 | { |
| 6480 | theInstance.Finalize(); |
| 6481 | gsNfaPartialEnabled = false; |
| 6482 | return false; |
| 6483 | } |
| 6484 | |
| 6485 | NFA_SetBootMode(NFA_FAST_BOOT_MODE); |
| 6486 | NFA_Init (halFuncEntries); |
| 6487 | ALOGD("%s: calling enable", __FUNCTION__); |
| 6488 | stat = NFA_Enable (nfaDeviceManagementCallback, nfaConnectionCallback); |
| 6489 | if (stat == NFA_STATUS_OK) |
| 6490 | { |
| 6491 | SyncEventGuard guard (sNfaEnableEvent); |
| 6492 | sNfaEnableEvent.wait(); //wait for NFA command to finish |
| 6493 | } |
| 6494 | |
| 6495 | if (sIsNfaEnabled) |
| 6496 | { |
| 6497 | gsNfaPartialEnabled = true; |
| 6498 | sIsNfaEnabled = false; |
| 6499 | } |
| 6500 | else |
| 6501 | { |
| 6502 | NFA_Disable (FALSE /* ungraceful */); |
| 6503 | theInstance.Finalize(); |
| 6504 | gsNfaPartialEnabled = false; |
| 6505 | } |
| 6506 | |
| 6507 | ALOGD("%s exit status = 0x%x", __FUNCTION__ ,gsNfaPartialEnabled); |
| 6508 | return gsNfaPartialEnabled; |
| 6509 | } |
| 6510 | /******************************************************************************* |
| 6511 | ** |
| 6512 | ** Function: nfcManager_doPartialDeInitialize |
| 6513 | ** |
| 6514 | ** Description: DeInitializes the NFC partially if it is partially initialized. |
| 6515 | ** |
| 6516 | ** Returns: true/false . |
| 6517 | ** |
| 6518 | *******************************************************************************/ |
| 6519 | static bool nfcManager_doPartialDeInitialize() |
| 6520 | { |
| 6521 | tNFA_STATUS stat = NFA_STATUS_OK; |
| 6522 | if(!gsNfaPartialEnabled) |
| 6523 | { |
| 6524 | ALOGD ("%s: cannot deinitialize NFC , not partially initilaized", __FUNCTION__); |
| 6525 | return true; |
| 6526 | } |
| 6527 | ALOGD ("%s:enter", __FUNCTION__); |
| 6528 | stat = NFA_Disable (TRUE /* graceful */); |
| 6529 | if (stat == NFA_STATUS_OK) |
| 6530 | { |
| 6531 | ALOGD ("%s: wait for completion", __FUNCTION__); |
| 6532 | SyncEventGuard guard (sNfaDisableEvent); |
| 6533 | sNfaDisableEvent.wait (); //wait for NFA command to finish |
| 6534 | } |
| 6535 | else |
| 6536 | { |
| 6537 | ALOGE ("%s: fail disable; error=0x%X", __FUNCTION__, stat); |
| 6538 | } |
| 6539 | NfcAdaptation& theInstance = NfcAdaptation::GetInstance(); |
| 6540 | theInstance.Finalize(); |
| 6541 | NFA_SetBootMode(NFA_NORMAL_BOOT_MODE); |
| 6542 | gsNfaPartialEnabled = false; |
| 6543 | return true; |
| 6544 | } |
| 6545 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 6546 | /********************************************************************************** |
| 6547 | ** |
| 6548 | ** Function: nfcManager_getFwVersion |
| 6549 | ** |
| 6550 | ** Description: To get the FW Version |
| 6551 | ** |
| 6552 | ** Returns: int fw version as below four byte format |
| 6553 | ** [0x00 0xROM_CODE_V 0xFW_MAJOR_NO 0xFW_MINOR_NO] |
| 6554 | ** |
| 6555 | **********************************************************************************/ |
| 6556 | |
| 6557 | static jint nfcManager_getFwVersion(JNIEnv* e, jobject o) |
| 6558 | { |
| 6559 | (void)e; |
| 6560 | (void)o; |
| 6561 | ALOGD ("%s: enter", __FUNCTION__); |
| 6562 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 6563 | // bool stat = false; /*commented to eliminate unused variable warning*/ |
| 6564 | jint version = 0, temp = 0; |
| 6565 | tNFC_FW_VERSION nfc_native_fw_version; |
| 6566 | |
| 6567 | if (!sIsNfaEnabled) { |
| 6568 | ALOGD("NFC does not enabled!!"); |
| 6569 | return status; |
| 6570 | } |
| 6571 | memset(&nfc_native_fw_version, 0, sizeof(nfc_native_fw_version)); |
| 6572 | |
| 6573 | nfc_native_fw_version = nfc_ncif_getFWVersion(); |
| 6574 | ALOGD ("FW Version: %x.%x.%x", nfc_native_fw_version.rom_code_version, |
| 6575 | nfc_native_fw_version.major_version,nfc_native_fw_version.minor_version); |
| 6576 | |
| 6577 | temp = nfc_native_fw_version.rom_code_version; |
| 6578 | version = temp << 16; |
| 6579 | temp = nfc_native_fw_version.major_version; |
| 6580 | version |= temp << 8; |
| 6581 | version |= nfc_native_fw_version.minor_version; |
| 6582 | |
| 6583 | ALOGD ("%s: exit; version =0x%X", __FUNCTION__,version); |
| 6584 | return version; |
| 6585 | } |
| 6586 | |
| 6587 | static void nfcManager_doSetEEPROM(JNIEnv* e, jobject o, jbyteArray val) |
| 6588 | { |
| 6589 | (void)e; |
| 6590 | (void)o; |
| 6591 | (void)val; |
| 6592 | ALOGD ("%s: enter", __FUNCTION__); |
| 6593 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 6594 | // bool stat = false; /*commented to eliminate unused variable warning*/ |
| 6595 | // UINT8 param; /*commented to eliminate unused variable warning*/ |
| 6596 | |
| 6597 | if (!sIsNfaEnabled) { |
| 6598 | ALOGD("NFC does not enabled!!"); |
| 6599 | return; |
| 6600 | } |
| 6601 | |
| 6602 | ALOGD ("%s: exit; status =0x%X", __FUNCTION__,status); |
| 6603 | |
| 6604 | return; |
| 6605 | } |
| 6606 | |
| 6607 | /******************************************************************************* |
| 6608 | ** |
| 6609 | ** Function: getUICC_RF_Param_SetSWPBitRate() |
| 6610 | ** |
| 6611 | ** Description: Get All UICC Parameters and set SWP bit rate |
| 6612 | ** |
| 6613 | ** Returns: success/failure |
| 6614 | ** |
| 6615 | *******************************************************************************/ |
| 6616 | tNFA_STATUS getUICC_RF_Param_SetSWPBitRate() |
| 6617 | { |
| 6618 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 6619 | tNFA_PMID rf_params_NFCEE_UICC[] = {0xA0, 0xEF}; |
| 6620 | uint8_t sakValue = 0x00; |
| 6621 | bool isMifareSupported; |
| 6622 | |
| 6623 | ALOGD("%s: enter", __FUNCTION__); |
| 6624 | |
| 6625 | SyncEventGuard guard (android::sNfaGetConfigEvent); |
| 6626 | status = NFA_GetConfig(0x01, rf_params_NFCEE_UICC); |
| 6627 | if (status != NFA_STATUS_OK) |
| 6628 | { |
| 6629 | ALOGE("%s: NFA_GetConfig failed", __FUNCTION__); |
| 6630 | return status; |
| 6631 | } |
| 6632 | android::sNfaGetConfigEvent.wait(); |
| 6633 | sakValue = sConfig[SAK_VALUE_AT]; |
| 6634 | ALOGD ("SAK Value =0x%X",sakValue); |
| 6635 | if((sakValue & 0x08) == 0x00) |
| 6636 | { |
| 6637 | isMifareSupported = false; |
| 6638 | } |
| 6639 | else |
| 6640 | { |
| 6641 | isMifareSupported = true; |
| 6642 | } |
| 6643 | status = SetUICC_SWPBitRate(isMifareSupported); |
| 6644 | |
| 6645 | return status; |
| 6646 | } |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 6647 | #if((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 6648 | /******************************************************************************* |
| 6649 | ** |
| 6650 | ** Function: nfcManagerEnableAGCDebug |
| 6651 | ** |
| 6652 | ** Description: Enable/Disable Dynamic RSSI feature. |
| 6653 | ** |
| 6654 | ** Returns: None |
| 6655 | ** |
| 6656 | *******************************************************************************/ |
| 6657 | static void nfcManagerEnableAGCDebug(UINT8 connEvent) |
| 6658 | { |
| 6659 | unsigned long enableAGCDebug = 0; |
| 6660 | int retvalue = 0xFF; |
| 6661 | GetNxpNumValue (NAME_NXP_AGC_DEBUG_ENABLE, (void*)&enableAGCDebug, sizeof(enableAGCDebug)); |
| 6662 | menableAGC_debug_t.enableAGC = enableAGCDebug; |
| 6663 | ALOGD ("%s ,%lu:", __FUNCTION__, enableAGCDebug); |
| 6664 | if(sIsNfaEnabled != true || sIsDisabling == true) |
| 6665 | return; |
| 6666 | if(!menableAGC_debug_t.enableAGC) |
| 6667 | { |
| 6668 | ALOGD ("%s AGCDebug not enabled", __FUNCTION__); |
| 6669 | return; |
| 6670 | } |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 6671 | if(connEvent == NFA_TRANS_DM_RF_FIELD_EVT && |
| 6672 | menableAGC_debug_t.AGCdebugstarted == false) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 6673 | { |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 6674 | pthread_t agcThread; |
| 6675 | pthread_attr_t attr; |
| 6676 | pthread_attr_init(&attr); |
| 6677 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 6678 | retvalue = pthread_create(&agcThread, &attr, enableAGCThread, NULL); |
| 6679 | pthread_attr_destroy(&attr); |
| 6680 | if(retvalue == 0) |
| 6681 | { |
| 6682 | menableAGC_debug_t.AGCdebugstarted = true; |
| 6683 | set_AGC_process_state(true); |
| 6684 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 6685 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 6686 | } |
| 6687 | |
| 6688 | void *enableAGCThread(void *arg) |
| 6689 | { |
| 6690 | tNFA_STATUS status = NFA_STATUS_FAILED; |
| 6691 | while( menableAGC_debug_t.AGCdebugstarted == true ) |
| 6692 | { |
| 6693 | if(get_AGC_process_state() == false) |
| 6694 | { |
| 6695 | sleep(10000); |
| 6696 | continue; |
| 6697 | } |
| 6698 | status = SendAGCDebugCommand(); |
| 6699 | if(status == NFA_STATUS_OK) |
| 6700 | { |
| 6701 | ALOGD ("%s: enable success exit", __FUNCTION__); |
| 6702 | } |
| 6703 | usleep(500000); |
| 6704 | } |
| 6705 | ALOGD ("%s: exit", __FUNCTION__); |
| 6706 | pthread_exit(NULL); |
| 6707 | return NULL; |
| 6708 | } |
| 6709 | /******************************************************************************* |
| 6710 | ** |
| 6711 | ** Function: set_AGC_process_state |
| 6712 | ** |
| 6713 | ** Description: sets the AGC process to stop |
| 6714 | ** |
| 6715 | ** Returns: None . |
| 6716 | ** |
| 6717 | *******************************************************************************/ |
| 6718 | void set_AGC_process_state(bool state) |
| 6719 | { |
| 6720 | menableAGC_debug_t.AGCdebugrunning = state; |
| 6721 | } |
| 6722 | |
| 6723 | /******************************************************************************* |
| 6724 | ** |
| 6725 | ** Function: get_AGC_process_state |
| 6726 | ** |
| 6727 | ** Description: returns the AGC process state. |
| 6728 | ** |
| 6729 | ** Returns: true/false . |
| 6730 | ** |
| 6731 | *******************************************************************************/ |
| 6732 | bool get_AGC_process_state() |
| 6733 | { |
| 6734 | return menableAGC_debug_t.AGCdebugrunning; |
| 6735 | } |
| 6736 | #endif |
| 6737 | /******************************************************************************* |
| 6738 | ** |
| 6739 | ** Function: getrfDiscoveryDuration() |
| 6740 | ** |
| 6741 | ** Description: gets the current rf discovery duration. |
| 6742 | ** |
| 6743 | ** Returns: UINT16 |
| 6744 | ** |
| 6745 | *******************************************************************************/ |
| 6746 | UINT16 getrfDiscoveryDuration() |
| 6747 | { |
| 6748 | return discDuration; |
| 6749 | } |
| 6750 | #endif |
| 6751 | |
| 6752 | } |
| 6753 | /* namespace android */ |