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