• 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   void enableRoutingToHost();
38   void disableRoutingToHost();
39   bool addAidRouting(const uint8_t* aid, uint8_t aidLen, int route, int aidInfo,
40                      int power);
41   bool removeAidRouting(const uint8_t* aid, uint8_t aidLen);
42   bool commitRouting();
43   int registerT3tIdentifier(uint8_t* t3tId, uint8_t t3tIdLen);
44   void deregisterT3tIdentifier(int handle);
45   void onNfccShutdown();
46   int registerJniFunctions(JNIEnv* e);
47   bool setNfcSecure(bool enable);
48   void updateRoutingTable();
49   void eeSetPwrAndLinkCtrl(uint8_t config);
50 
51  private:
52   RoutingManager();
53   ~RoutingManager();
54   RoutingManager(const RoutingManager&);
55   RoutingManager& operator=(const RoutingManager&);
56 
57   void handleData(uint8_t technology, const uint8_t* data, uint32_t dataLen,
58                   tNFA_STATUS status);
59   void notifyActivated(uint8_t technology);
60   void notifyDeactivated(uint8_t technology);
61   void notifyEeUpdated();
62   tNFA_TECHNOLOGY_MASK updateEeTechRouteSetting();
63   void updateDefaultProtocolRoute();
64   void updateDefaultRoute();
65   bool isTypeATypeBTechSupportedInEe(tNFA_HANDLE eeHandle);
66 
67   // See AidRoutingManager.java for corresponding
68   // AID_MATCHING_ constants
69 
70   // Every routing table entry is matched exact (BCM20793)
71   static const int AID_MATCHING_EXACT_ONLY = 0x00;
72   // Every routing table entry can be matched either exact or prefix
73   static const int AID_MATCHING_EXACT_OR_PREFIX = 0x01;
74   // Every routing table entry is matched as a prefix
75   static const int AID_MATCHING_PREFIX_ONLY = 0x02;
76 
77   static void nfaEeCallback(tNFA_EE_EVT event, tNFA_EE_CBACK_DATA* eventData);
78   static void stackCallback(uint8_t event, tNFA_CONN_EVT_DATA* eventData);
79   static void nfcFCeCallback(uint8_t event, tNFA_CONN_EVT_DATA* eventData);
80 
81   static int com_android_nfc_cardemulation_doGetDefaultRouteDestination(
82       JNIEnv* e);
83   static int com_android_nfc_cardemulation_doGetDefaultOffHostRouteDestination(
84       JNIEnv* e);
85   static jbyteArray com_android_nfc_cardemulation_doGetOffHostUiccDestination(
86       JNIEnv* e);
87   static jbyteArray com_android_nfc_cardemulation_doGetOffHostEseDestination(
88       JNIEnv* e);
89   static int com_android_nfc_cardemulation_doGetAidMatchingMode(JNIEnv* e);
90   static int com_android_nfc_cardemulation_doGetDefaultIsoDepRouteDestination(
91       JNIEnv* e);
92 
93   std::vector<uint8_t> mRxDataBuffer;
94   map<int, uint16_t> mMapScbrHandle;
95   bool mSecureNfcEnabled;
96 
97   // Fields below are final after initialize()
98   nfc_jni_native_data* mNativeData;
99   int mDefaultOffHostRoute;
100   vector<uint8_t> mOffHostRouteUicc;
101   vector<uint8_t> mOffHostRouteEse;
102   int mDefaultFelicaRoute;
103   int mDefaultEe;
104   int mDefaultIsoDepRoute;
105   int mAidMatchingMode;
106   int mNfcFOnDhHandle;
107   bool mIsScbrSupported;
108   uint16_t mDefaultSysCode;
109   uint16_t mDefaultSysCodeRoute;
110   uint8_t mDefaultSysCodePowerstate;
111   uint8_t mOffHostAidRoutingPowerState;
112   uint8_t mHostListenTechMask;
113   uint8_t mOffHostListenTechMask;
114   bool mDeinitializing;
115   bool mEeInfoChanged;
116   bool mReceivedEeInfo;
117   bool mAidRoutingConfigured;
118   tNFA_EE_CBACK_DATA mCbEventData;
119   tNFA_EE_DISCOVER_REQ mEeInfo;
120   tNFA_TECHNOLOGY_MASK mSeTechMask;
121   static const JNINativeMethod sMethods[];
122   SyncEvent mEeRegisterEvent;
123   SyncEvent mRoutingEvent;
124   SyncEvent mEeUpdateEvent;
125   SyncEvent mEeInfoEvent;
126   SyncEvent mEeSetModeEvent;
127   SyncEvent mEePwrAndLinkCtrlEvent;
128 };
129