1 #pragma once 2 3 #include <map> 4 #include <memory> 5 #include <vector> 6 7 #include <aidl/android/se/omapi/BnSecureElementListener.h> 8 #include <aidl/android/se/omapi/ISecureElementChannel.h> 9 #include <aidl/android/se/omapi/ISecureElementListener.h> 10 #include <aidl/android/se/omapi/ISecureElementReader.h> 11 #include <aidl/android/se/omapi/ISecureElementService.h> 12 #include <aidl/android/se/omapi/ISecureElementSession.h> 13 14 #include <android/binder_manager.h> 15 16 #include "ITransport.h" 17 18 namespace keymint::javacard { 19 using std::vector; 20 21 /** 22 * OmapiTransport is derived from ITransport. This class gets the OMAPI service binder instance and 23 * uses IPC to communicate with OMAPI service. OMAPI inturn communicates with hardware via 24 * ISecureElement. 25 */ 26 class OmapiTransport : public ITransport { 27 28 public: OmapiTransport()29 OmapiTransport() 30 : omapiSeService(nullptr), eSEReader(nullptr), session(nullptr), channel(nullptr), 31 mVSReaders({}) {} 32 /** 33 * Gets the binder instance of ISEService, gets te reader corresponding to secure element, 34 * establishes a session and opens a basic channel. 35 */ 36 keymaster_error_t openConnection() override; 37 /** 38 * Transmists the data over the opened basic channel and receives the data back. 39 */ 40 keymaster_error_t sendData(const vector<uint8_t>& inData, vector<uint8_t>& output) override; 41 42 /** 43 * Closes the connection. 44 */ 45 keymaster_error_t closeConnection() override; 46 /** 47 * Returns the state of the connection status. Returns true if the connection is active, false 48 * if connection is broken. 49 */ 50 bool isConnected() override; 51 52 private: 53 std::shared_ptr<aidl::android::se::omapi::ISecureElementService> omapiSeService; 54 std::shared_ptr<aidl::android::se::omapi::ISecureElementReader> eSEReader; 55 std::shared_ptr<aidl::android::se::omapi::ISecureElementSession> session; 56 std::shared_ptr<aidl::android::se::omapi::ISecureElementChannel> channel; 57 std::map<std::string, std::shared_ptr<aidl::android::se::omapi::ISecureElementReader>> 58 mVSReaders; 59 keymaster_error_t initialize(); 60 bool 61 internalTransmitApdu(std::shared_ptr<aidl::android::se::omapi::ISecureElementReader> reader, 62 std::vector<uint8_t> apdu, std::vector<uint8_t>& transmitResponse); 63 }; 64 65 } // namespace keymint::javacard 66