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 2021-2024 NXP
34 **
35 *********************************************************************************/
36 #pragma once
37 #include <memory>
38 #include <vector>
39 
40 namespace keymint::javacard {
41 using std::shared_ptr;
42 using std::vector;
43 
44 /**
45  * ITransport is an interface with a set of virtual methods that allow communication between the
46  * HAL and the applet on the secure element.
47  */
48 class ITransport {
49   public:
~ITransport()50     virtual ~ITransport() {}
51 
ITransport(const std::vector<uint8_t> & mAppletAID)52     explicit ITransport(__attribute__((unused))
53                         const std::vector<uint8_t> &mAppletAID){};
54 
55 #ifdef NXP_EXTNS
56     /**
57      * Sets Applet AID.
58      */
setAppletAid(const vector<uint8_t> & aid)59     virtual bool setAppletAid(const vector<uint8_t> &aid) {
60       (void)aid;
61       return false;
62     }
63 
64     /**
65      * Sets state(start/finish) of crypto operation.
66      * This is required for channel session timeout mgmt.
67      */
setCryptoOperationState(uint8_t state)68     virtual void setCryptoOperationState(uint8_t state) { (void)state; };
69 #endif
70     /**
71      * Opens connection.
72      */
73     virtual bool openConnection() = 0;
74     /**
75      * Send data over communication channel and receives data back from the remote end.
76      */
77     virtual bool sendData(const vector<uint8_t>& inData, vector<uint8_t>& output) = 0;
78     /**
79      * Closes the connection.
80      */
81     virtual bool closeConnection() = 0;
82     /**
83      * Returns the state of the connection status. Returns true if the connection is active, false
84      * if connection is broken.
85      */
86     virtual bool isConnected() = 0;
87 };
88 }  // namespace keymint::javacard
89