• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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  *  Manage the listen-mode routing table.
19  */
20 #pragma once
21 #include <vector>
22 #include "NfcJniUtil.h"
23 #include "RouteDataSet.h"
24 #include "SyncEvent.h"
25 
26 #include <map>
27 #include "nfa_api.h"
28 #include "nfa_ee_api.h"
29 
30 using namespace std;
31 
32 class RoutingManager {
33  public:
34   static RoutingManager& getInstance();
35   bool initialize(nfc_jni_native_data* native);
36   void deinitialize();
37   bool addAidRouting(const uint8_t* aid, uint8_t aidLen, int route, int aidInfo,
38                      int power);
39   bool removeAidRouting(const uint8_t* aid, uint8_t aidLen);
40   tNFA_STATUS commitRouting();
41   int registerT3tIdentifier(uint8_t* t3tId, uint8_t t3tIdLen);
42   void deregisterT3tIdentifier(int handle);
43   void onNfccShutdown();
44   int registerJniFunctions(JNIEnv* e);
45   bool setNfcSecure(bool enable);
46   void updateRoutingTable();
47   void eeSetPwrAndLinkCtrl(uint8_t config);
48   void updateIsoDepProtocolRoute(int route);
49   tNFA_TECHNOLOGY_MASK updateTechnologyABFRoute(int route, int felicaRoute);
50   void updateSystemCodeRoute(int route);
51   void clearRoutingEntry(int clearFlags);
52   void setEeTechRouteUpdateRequired();
53   void notifyEeAidSelected(tNFC_AID& aid, tNFA_HANDLE ee_handle);
54   void notifyEeProtocolSelected(uint8_t protocol, tNFA_HANDLE ee_handle);
55   void notifyEeTechSelected(uint8_t tech, tNFA_HANDLE ee_handle);
56   bool getNameOfEe(tNFA_HANDLE ee_handle, std::string& eeName);
57   void setEeInfoChangedFlag();
58 
59   static const int CLEAR_AID_ENTRIES = 0x01;
60   static const int CLEAR_PROTOCOL_ENTRIES = 0x02;
61   static const int CLEAR_TECHNOLOGY_ENTRIES = 0x04;
62   static const int CLEAR_SC_ENTRIES = 0x08;
63   SyncEvent mEeUpdateEvent;
64 
65  private:
66   RoutingManager();
67   ~RoutingManager();
68   RoutingManager(const RoutingManager&);
69   RoutingManager& operator=(const RoutingManager&);
70 
71   void handleData(uint8_t technology, const uint8_t* data, uint32_t dataLen,
72                   tNFA_STATUS status);
73   void notifyActivated(uint8_t technology);
74   void notifyDeactivated(uint8_t technology);
75   void notifyEeUpdated();
76   tNFA_TECHNOLOGY_MASK updateEeTechRouteSetting();
77   void updateDefaultProtocolRoute();
78   void updateDefaultRoute();
79   bool isTypeATypeBTechSupportedInEe(tNFA_HANDLE eeHandle);
80 
81   // See AidRoutingManager.java for corresponding
82   // AID_MATCHING_ constants
83 
84   // Every routing table entry is matched exact (BCM20793)
85   static const int AID_MATCHING_EXACT_ONLY = 0x00;
86   // Every routing table entry can be matched either exact or prefix
87   static const int AID_MATCHING_EXACT_OR_PREFIX = 0x01;
88   // Every routing table entry is matched as a prefix
89   static const int AID_MATCHING_PREFIX_ONLY = 0x02;
90 
91   static void nfaEeCallback(tNFA_EE_EVT event, tNFA_EE_CBACK_DATA* eventData);
92   static void stackCallback(uint8_t event, tNFA_CONN_EVT_DATA* eventData);
93   static void nfcFCeCallback(uint8_t event, tNFA_CONN_EVT_DATA* eventData);
94 
95   static int com_android_nfc_cardemulation_doGetDefaultRouteDestination(
96       JNIEnv* e);
97   static int com_android_nfc_cardemulation_doGetDefaultOffHostRouteDestination(
98       JNIEnv* e);
99   static int com_android_nfc_cardemulation_doGetDefaultFelicaRouteDestination(
100       JNIEnv* e);
101   static int com_android_nfc_cardemulation_doGetDefaultScRouteDestination(
102       JNIEnv* e);
103   static jbyteArray com_android_nfc_cardemulation_doGetOffHostUiccDestination(
104       JNIEnv* e);
105   static jbyteArray com_android_nfc_cardemulation_doGetOffHostEseDestination(
106       JNIEnv* e);
107   static int com_android_nfc_cardemulation_doGetAidMatchingMode(JNIEnv* e);
108   static int com_android_nfc_cardemulation_doGetDefaultIsoDepRouteDestination(
109       JNIEnv* e);
110   static int com_android_nfc_cardemulation_doGetEuiccMepMode(JNIEnv* e);
111 
112   std::vector<uint8_t> mRxDataBuffer;
113   map<int, uint16_t> mMapScbrHandle;
114   bool mSecureNfcEnabled;
115 
116   // Fields below are final after initialize()
117   nfc_jni_native_data* mNativeData;
118   int mDefaultOffHostRoute;
119   vector<uint8_t> mOffHostRouteUicc;
120   vector<uint8_t> mOffHostRouteEse;
121   int mDefaultFelicaRoute;
122   int mDefaultEe;
123   int mDefaultIsoDepRoute;
124   int mAidMatchingMode;
125   int mNfcFOnDhHandle;
126   int mEuiccMepMode;
127   bool mIsScbrSupported;
128   uint16_t mDefaultSysCode;
129   uint16_t mDefaultSysCodeRoute;
130   uint8_t mDefaultSysCodePowerstate;
131   uint8_t mOffHostAidRoutingPowerState;
132   uint8_t mHostListenTechMask;
133   uint8_t mOffHostListenTechMask;
134   bool mDefaultAidRouteAdded;
135   bool mDeinitializing;
136   bool mEeInfoChanged;
137   bool mReceivedEeInfo;
138   bool mAidRoutingConfigured;
139   bool mIsRFDiscoveryOptimized;
140   tNFA_EE_CBACK_DATA mCbEventData;
141   tNFA_EE_DISCOVER_REQ mEeInfo;
142   tNFA_TECHNOLOGY_MASK mSeTechMask;
143   static const JNINativeMethod sMethods[];
144   SyncEvent mEeRegisterEvent;
145   SyncEvent mRoutingEvent;
146   SyncEvent mEeInfoEvent;
147   SyncEvent mEeSetModeEvent;
148   SyncEvent mEePwrAndLinkCtrlEvent;
149   SyncEvent mAidAddRemoveEvent;
150 };
151