1 /* 2 ** 3 ** Copyright 2020, The Android Open Source Project 4 ** 5 ** Licensed under the Apache License, Version 2.0 (the "License"); 6 ** you may not use this file except in compliance with the License. 7 ** You may obtain a copy of the License at 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 */ 17 /****************************************************************************** 18 ** 19 ** The original Work has been changed by NXP. 20 ** 21 ** Licensed under the Apache License, Version 2.0 (the "License"); 22 ** you may not use this file except in compliance with the License. 23 ** You may obtain a copy of the License at 24 ** 25 ** http://www.apache.org/licenses/LICENSE-2.0 26 ** 27 ** Unless required by applicable law or agreed to in writing, software 28 ** distributed under the License is distributed on an "AS IS" BASIS, 29 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 30 ** See the License for the specific language governing permissions and 31 ** limitations under the License. 32 ** 33 ** Copyright 2020-2021 NXP 34 ** 35 *********************************************************************************/ 36 #pragma once 37 #include "ITransport.h" 38 #include <AppletConnection.h> 39 #include <IntervalTimer.h> 40 #include <memory> 41 #include <vector> 42 43 namespace keymint::javacard { 44 using std::shared_ptr; 45 using std::vector; 46 /** 47 * HalToHalTransport is derived from ITransport. This class gets the OMAPI service binder instance and uses IPC to 48 * communicate with OMAPI service. OMAPI inturn communicates with hardware via ISecureElement. 49 */ 50 class HalToHalTransport : public ITransport { 51 52 public: HalToHalTransport(const std::vector<uint8_t> & mAppletAID)53 HalToHalTransport(const std::vector<uint8_t>& mAppletAID) 54 : ITransport(mAppletAID), 55 mAppletConnection(mAppletAID) {} 56 57 /** 58 * Gets the binder instance of ISEService, gets the reader corresponding to secure element, establishes a session 59 * and opens a basic channel. 60 */ 61 bool openConnection() override; 62 /** 63 * Transmists the data over the opened basic channel and receives the data back. 64 */ 65 bool sendData(const vector<uint8_t>& inData, vector<uint8_t>& output) override; 66 /** 67 * Closes the connection. 68 */ 69 bool closeConnection() override; 70 /** 71 * Returns the state of the connection status. Returns true if the connection is active, false if connection is 72 * broken. 73 */ 74 bool isConnected() override; 75 private: 76 AppletConnection mAppletConnection; 77 IntervalTimer mTimer; 78 79 }; 80 } // namespace keymint::javacard