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 "SyncEvent.h" 22 #include "NfcJniUtil.h" 23 #include "RouteDataSet.h" 24 #include <vector> 25 extern "C" 26 { 27 #include "nfa_api.h" 28 #include "nfa_ee_api.h" 29 } 30 31 class RoutingManager 32 { 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* aid, UINT8 aidLen, int route); 39 bool removeAidRouting(const UINT8* aid, UINT8 aidLen); 40 bool commitRouting(); 41 int registerT3tIdentifier(UINT8* t3tId, UINT8 t3tIdLen); 42 void deregisterT3tIdentifier(int handle); 43 void onNfccShutdown(); 44 int registerJniFunctions (JNIEnv* e); 45 private: 46 RoutingManager(); 47 ~RoutingManager(); 48 RoutingManager(const RoutingManager&); 49 RoutingManager& operator=(const RoutingManager&); 50 51 void handleData (UINT8 technology, const UINT8* data, UINT32 dataLen, tNFA_STATUS status); 52 void notifyActivated (UINT8 technology); 53 void notifyDeactivated (UINT8 technology); 54 55 // See AidRoutingManager.java for corresponding 56 // AID_MATCHING_ constants 57 58 // Every routing table entry is matched exact (BCM20793) 59 static const int AID_MATCHING_EXACT_ONLY = 0x00; 60 // Every routing table entry can be matched either exact or prefix 61 static const int AID_MATCHING_EXACT_OR_PREFIX = 0x01; 62 // Every routing table entry is matched as a prefix 63 static const int AID_MATCHING_PREFIX_ONLY = 0x02; 64 65 static void nfaEeCallback (tNFA_EE_EVT event, tNFA_EE_CBACK_DATA* eventData); 66 static void stackCallback (UINT8 event, tNFA_CONN_EVT_DATA* eventData); 67 static void nfcFCeCallback (UINT8 event, tNFA_CONN_EVT_DATA* eventData); 68 69 static int com_android_nfc_cardemulation_doGetDefaultRouteDestination (JNIEnv* e); 70 static int com_android_nfc_cardemulation_doGetDefaultOffHostRouteDestination (JNIEnv* e); 71 static int com_android_nfc_cardemulation_doGetAidMatchingMode (JNIEnv* e); 72 73 std::vector<UINT8> mRxDataBuffer; 74 75 // Fields below are final after initialize() 76 nfc_jni_native_data* mNativeData; 77 int mDefaultEe; 78 int mDefaultEeNfcF; 79 int mOffHostEe; 80 int mActiveSe; 81 int mActiveSeNfcF; 82 int mAidMatchingMode; 83 int mNfcFOnDhHandle; 84 bool mReceivedEeInfo; 85 tNFA_EE_DISCOVER_REQ mEeInfo; 86 tNFA_TECHNOLOGY_MASK mSeTechMask; 87 static const JNINativeMethod sMethods []; 88 SyncEvent mEeRegisterEvent; 89 SyncEvent mRoutingEvent; 90 SyncEvent mEeUpdateEvent; 91 SyncEvent mEeInfoEvent; 92 SyncEvent mEeSetModeEvent; 93 }; 94 95