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 void onNfccShutdown(); 42 int registerJniFunctions (JNIEnv* e); 43 private: 44 RoutingManager(); 45 ~RoutingManager(); 46 RoutingManager(const RoutingManager&); 47 RoutingManager& operator=(const RoutingManager&); 48 49 void handleData (const UINT8* data, UINT32 dataLen, tNFA_STATUS status); 50 void notifyActivated (); 51 void notifyDeactivated (); 52 53 // See AidRoutingManager.java for corresponding 54 // AID_MATCHING_ constants 55 56 // Every routing table entry is matched exact (BCM20793) 57 static const int AID_MATCHING_EXACT_ONLY = 0x00; 58 // Every routing table entry can be matched either exact or prefix 59 static const int AID_MATCHING_EXACT_OR_PREFIX = 0x01; 60 // Every routing table entry is matched as a prefix 61 static const int AID_MATCHING_PREFIX_ONLY = 0x02; 62 63 static void nfaEeCallback (tNFA_EE_EVT event, tNFA_EE_CBACK_DATA* eventData); 64 static void stackCallback (UINT8 event, tNFA_CONN_EVT_DATA* eventData); 65 static int com_android_nfc_cardemulation_doGetDefaultRouteDestination (JNIEnv* e); 66 static int com_android_nfc_cardemulation_doGetDefaultOffHostRouteDestination (JNIEnv* e); 67 static int com_android_nfc_cardemulation_doGetAidMatchingMode (JNIEnv* e); 68 69 std::vector<UINT8> mRxDataBuffer; 70 71 // Fields below are final after initialize() 72 nfc_jni_native_data* mNativeData; 73 int mDefaultEe; 74 int mOffHostEe; 75 int mActiveSe; 76 int mAidMatchingMode; 77 bool mReceivedEeInfo; 78 tNFA_EE_DISCOVER_REQ mEeInfo; 79 tNFA_TECHNOLOGY_MASK mSeTechMask; 80 static const JNINativeMethod sMethods []; 81 SyncEvent mEeRegisterEvent; 82 SyncEvent mRoutingEvent; 83 SyncEvent mEeUpdateEvent; 84 SyncEvent mEeInfoEvent; 85 SyncEvent mEeSetModeEvent; 86 }; 87 88