| /* |
| * Copyright (C) 2013 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| /* |
| * Manage the listen-mode routing table. |
| */ |
| /****************************************************************************** |
| * |
| * The original Work has been changed by NXP. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| * |
| * Copyright 2018 NXP |
| * |
| ******************************************************************************/ |
| #pragma once |
| #include <vector> |
| #include "NfcJniUtil.h" |
| #include "RouteDataSet.h" |
| #include "SyncEvent.h" |
| |
| #include "nfa_api.h" |
| #include "nfa_ee_api.h" |
| #if(NXP_EXTNS == TRUE) |
| #include "SecureElement.h" |
| #define AVAILABLE_PROTO_ENTRIES() 0x05 |
| #endif |
| typedef struct |
| { |
| uint8_t protocol; |
| uint16_t routeLoc; |
| uint8_t power; |
| uint8_t enable; |
| } protoEntry_t; |
| |
| typedef struct |
| { |
| uint8_t technology; |
| uint16_t routeLoc; |
| uint8_t power; |
| uint8_t enable; |
| } techEntry_t; |
| |
| typedef struct |
| { |
| uint16_t nfceeID;//ID for the route location |
| tNFA_TECHNOLOGY_MASK tech_switch_on; /* default routing - technologies switch_on */ |
| tNFA_TECHNOLOGY_MASK tech_switch_off; /* default routing - technologies switch_off */ |
| tNFA_TECHNOLOGY_MASK tech_battery_off; /* default routing - technologies battery_off*/ |
| tNFA_TECHNOLOGY_MASK tech_screen_lock; /* default routing - technologies screen_lock*/ |
| tNFA_TECHNOLOGY_MASK tech_screen_off; /* default routing - technologies screen_off*/ |
| tNFA_TECHNOLOGY_MASK tech_screen_off_lock; /* default routing - technologies screen_off_lock*/ |
| tNFA_PROTOCOL_MASK proto_switch_on; /* default routing - protocols switch_on */ |
| tNFA_PROTOCOL_MASK proto_switch_off; /* default routing - protocols switch_off */ |
| tNFA_PROTOCOL_MASK proto_battery_off; /* default routing - protocols battery_off */ |
| tNFA_PROTOCOL_MASK proto_screen_lock; /* default routing - protocols screen_lock */ |
| tNFA_PROTOCOL_MASK proto_screen_off; /* default routing - protocols screen_off */ |
| tNFA_PROTOCOL_MASK proto_screen_off_lock; /* default routing - protocols screen_off_lock */ |
| |
| } LmrtEntry_t; |
| class RoutingManager { |
| public: |
| static RoutingManager& getInstance(); |
| bool initialize(nfc_jni_native_data* native); |
| void enableRoutingToHost(); |
| void disableRoutingToHost(); |
| #if(NXP_EXTNS != TRUE) |
| bool addAidRouting(const uint8_t* aid, uint8_t aidLen, int route, |
| int aidInfo); |
| #endif |
| bool removeAidRouting(const uint8_t* aid, uint8_t aidLen); |
| bool commitRouting(); |
| int registerT3tIdentifier(uint8_t* t3tId, uint8_t t3tIdLen); |
| void deregisterT3tIdentifier(int handle); |
| void onNfccShutdown(); |
| int registerJniFunctions(JNIEnv* e); |
| #if(NXP_EXTNS == TRUE) |
| void extractRouteLocationAndPowerStates(const int defaultRoute, const int protoRoute, const int techRoute); |
| uint16_t getUiccRouteLocId(const int route); |
| void initialiseTableEntries(void); |
| void compileProtoEntries(void); |
| void compileTechEntries(void); |
| void consolidateProtoEntries(void); |
| void consolidateTechEntries(void); |
| void setProtoRouting(void); |
| void setEmptyAidEntry(void); |
| void setTechRouting(void); |
| void processTechEntriesForFwdfunctionality(void); |
| void configureOffHostNfceeTechMask(void); |
| void checkProtoSeID(void); |
| void dumpTables(int); |
| bool setDefaultRoute(const int defaultRoute, const int protoRoute, const int techRoute); |
| uint32_t getUicc2selected(); |
| bool addAidRouting(const uint8_t* aid, uint8_t aidLen, int route, |
| int aidInfo, int power); |
| uint8_t sCurrentSelectedUICCSlot; |
| SyncEvent mAidAddRemoveEvent; |
| #endif |
| private: |
| RoutingManager(); |
| ~RoutingManager(); |
| RoutingManager(const RoutingManager&); |
| RoutingManager& operator=(const RoutingManager&); |
| |
| void handleData(uint8_t technology, const uint8_t* data, uint32_t dataLen, |
| tNFA_STATUS status); |
| void notifyActivated(uint8_t technology); |
| void notifyDeactivated(uint8_t technology); |
| |
| // See AidRoutingManager.java for corresponding |
| // AID_MATCHING_ constants |
| |
| // Every routing table entry is matched exact (BCM20793) |
| static const int AID_MATCHING_EXACT_ONLY = 0x00; |
| // Every routing table entry can be matched either exact or prefix |
| static const int AID_MATCHING_EXACT_OR_PREFIX = 0x01; |
| // Every routing table entry is matched as a prefix |
| static const int AID_MATCHING_PREFIX_ONLY = 0x02; |
| |
| static void nfaEeCallback(tNFA_EE_EVT event, tNFA_EE_CBACK_DATA* eventData); |
| static void stackCallback(uint8_t event, tNFA_CONN_EVT_DATA* eventData); |
| static void nfcFCeCallback(uint8_t event, tNFA_CONN_EVT_DATA* eventData); |
| |
| static int com_android_nfc_cardemulation_doGetDefaultRouteDestination( |
| JNIEnv* e); |
| static int com_android_nfc_cardemulation_doGetDefaultOffHostRouteDestination( |
| JNIEnv* e); |
| static int com_android_nfc_cardemulation_doGetAidMatchingMode(JNIEnv* e); |
| |
| std::vector<uint8_t> mRxDataBuffer; |
| |
| // Fields below are final after initialize() |
| nfc_jni_native_data* mNativeData; |
| int mDefaultEe; |
| int mDefaultEeNfcF; |
| int mOffHostEe; |
| int mActiveSe; |
| int mActiveSeNfcF; |
| int mAidMatchingMode; |
| int mNfcFOnDhHandle; |
| bool mReceivedEeInfo; |
| tNFA_EE_DISCOVER_REQ mEeInfo; |
| tNFA_TECHNOLOGY_MASK mSeTechMask; |
| static const JNINativeMethod sMethods[]; |
| SyncEvent mEeRegisterEvent; |
| SyncEvent mRoutingEvent; |
| SyncEvent mEeUpdateEvent; |
| SyncEvent mEeInfoEvent; |
| SyncEvent mEeSetModeEvent; |
| #if(NXP_EXTNS == TRUE) |
| //Currently 4 protocols supported namely T3T, ISO-DEP, ISO-7816, NFC-DEP(taken care internally by the libnfc stack) |
| static const int MAX_PROTO_ENTRIES = 0x03; |
| static const int PROTO_T3T_IDX = 0x00; |
| static const int PROTO_ISODEP_IDX = 0x01; |
| static const int PROTO_ISO7816_IDX = 0x02; |
| //Currently 3 Technologies supported namely A,B,F |
| static const int MAX_TECH_ENTRIES = 0x03; |
| static const int TECH_A_IDX = 0x00; |
| static const int TECH_B_IDX = 0x01; |
| static const int TECH_F_IDX = 0x02; |
| //Fixed number of Lmrt entries |
| static const int MAX_ROUTE_LOC_ENTRIES = 0x04; |
| //Fixed route location Lmrt index |
| static const int ROUTE_LOC_HOST_ID_IDX = 0x00; |
| static const int ROUTE_LOC_ESE_ID_IDX = 0x01; |
| static const int ROUTE_LOC_UICC1_ID_IDX = 0x02; |
| static const int ROUTE_LOC_UICC2_ID_IDX = 0x03; |
| //Fixed route location Lmrt entries |
| static const int ROUTE_LOC_HOST_ID = 0x400; |
| //FIX THIS:static const int ROUTE_LOC_ESE_ID = SecureElement::EE_HANDLE_0xF3; |
| static const int ROUTE_LOC_ESE_ID = 0x4C0; |
| static const int ROUTE_LOC_UICC1_ID = 0x402; |
| static const int ROUTE_LOC_UICC1_ID_NCI2_0 = 0x480; |
| //FIX THIS:static const int ROUTE_LOC_UICC2_ID = SecureElement::EE_HANDLE_0xF8; |
| //FIX THIS:static const int ROUTE_LOC_UICC3_ID = SecureElement::EE_HANDLE_0xF9; |
| static const int ROUTE_LOC_UICC2_ID = 0x481; |
| static const int ROUTE_LOC_UICC3_ID = 0x482; |
| // Fixed power states masks |
| static const int PWR_SWTCH_ON_SCRN_UNLCK_MASK = 0x01; |
| static const int PWR_SWTCH_OFF_MASK = 0x02; |
| static const int PWR_BATT_OFF_MASK = 0x04; |
| static const int PWR_SWTCH_ON_SCRN_LOCK_MASK = 0x08; |
| static const int PWR_SWTCH_ON_SCRN_OFF_MASK = 0x10; |
| static const int PWR_SWTCH_ON_SCRN_OFF_LOCK_MASK = 0x20; |
| static const int POWER_STATE_MASK = 0xFF; |
| static const int HOST_SCREEN_STATE_MASK = 0x09; |
| int mHostListnTechMask; |
| int mUiccListnTechMask; |
| int mFwdFuntnEnable; |
| uint32_t mDefaultIso7816SeID; |
| uint32_t mDefaultIso7816Powerstate; |
| uint32_t mDefaultIsoDepSeID; |
| uint32_t mDefaultIsoDepPowerstate; |
| uint32_t mDefaultT3TSeID; |
| uint32_t mDefaultT3TPowerstate; |
| uint32_t mDefaultTechType; |
| uint32_t mDefaultTechASeID; |
| uint32_t mDefaultTechAPowerstate; |
| uint32_t mDefaultTechBSeID; |
| uint32_t mDefaultTechBPowerstate; |
| uint32_t mDefaultTechFSeID; |
| uint32_t mDefaultTechFPowerstate; |
| protoEntry_t mProtoTableEntries[MAX_PROTO_ENTRIES]; |
| techEntry_t mTechTableEntries[MAX_TECH_ENTRIES]; |
| LmrtEntry_t mLmrtEntries[MAX_ROUTE_LOC_ENTRIES]; |
| uint32_t mCeRouteStrictDisable; |
| uint32_t mTechSupportedByEse; |
| uint32_t mTechSupportedByUicc1; |
| uint32_t mTechSupportedByUicc2; |
| #endif |
| }; |