• 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 enableRoutingToHost();
37   void disableRoutingToHost();
38   bool addAidRouting(const uint8_t* aid, uint8_t aidLen, int route,
39                      int aidInfo);
40   bool removeAidRouting(const uint8_t* aid, uint8_t aidLen);
41   bool commitRouting();
42   int registerT3tIdentifier(uint8_t* t3tId, uint8_t t3tIdLen);
43   void deregisterT3tIdentifier(int handle);
44   void onNfccShutdown();
45   int registerJniFunctions(JNIEnv* e);
46 
47  private:
48   RoutingManager();
49   ~RoutingManager();
50   RoutingManager(const RoutingManager&);
51   RoutingManager& operator=(const RoutingManager&);
52 
53   void handleData(uint8_t technology, const uint8_t* data, uint32_t dataLen,
54                   tNFA_STATUS status);
55   void notifyActivated(uint8_t technology);
56   void notifyDeactivated(uint8_t technology);
57 
58   // See AidRoutingManager.java for corresponding
59   // AID_MATCHING_ constants
60 
61   // Every routing table entry is matched exact (BCM20793)
62   static const int AID_MATCHING_EXACT_ONLY = 0x00;
63   // Every routing table entry can be matched either exact or prefix
64   static const int AID_MATCHING_EXACT_OR_PREFIX = 0x01;
65   // Every routing table entry is matched as a prefix
66   static const int AID_MATCHING_PREFIX_ONLY = 0x02;
67 
68   static void nfaEeCallback(tNFA_EE_EVT event, tNFA_EE_CBACK_DATA* eventData);
69   static void stackCallback(uint8_t event, tNFA_CONN_EVT_DATA* eventData);
70   static void nfcFCeCallback(uint8_t event, tNFA_CONN_EVT_DATA* eventData);
71 
72   static int com_android_nfc_cardemulation_doGetDefaultRouteDestination(
73       JNIEnv* e);
74   static int com_android_nfc_cardemulation_doGetDefaultOffHostRouteDestination(
75       JNIEnv* e);
76   static int com_android_nfc_cardemulation_doGetAidMatchingMode(JNIEnv* e);
77 
78   std::vector<uint8_t> mRxDataBuffer;
79   map<int, uint16_t> mMapScbrHandle;
80 
81   // Fields below are final after initialize()
82   nfc_jni_native_data* mNativeData;
83   int mDefaultOffHostRoute;
84   int mDefaultFelicaRoute;
85   int mDefaultEe;
86   int mAidMatchingMode;
87   int mNfcFOnDhHandle;
88   bool mIsScbrSupported;
89   uint16_t mDefaultSysCode;
90   uint16_t mDefaultSysCodeRoute;
91   uint8_t mDefaultSysCodePowerstate;
92   uint8_t mOffHostAidRoutingPowerState;
93   bool mReceivedEeInfo;
94   tNFA_EE_CBACK_DATA mCbEventData;
95   tNFA_EE_DISCOVER_REQ mEeInfo;
96   tNFA_TECHNOLOGY_MASK mSeTechMask;
97   static const JNINativeMethod sMethods[];
98   SyncEvent mEeRegisterEvent;
99   SyncEvent mRoutingEvent;
100   SyncEvent mEeUpdateEvent;
101   SyncEvent mEeInfoEvent;
102   SyncEvent mEeSetModeEvent;
103 };
104