forked from prashantsathe/secure_element
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransport.h
More file actions
74 lines (67 loc) · 1.88 KB
/
Transport.h
File metadata and controls
74 lines (67 loc) · 1.88 KB
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
66
67
68
69
70
71
72
73
74
#ifndef __SE_TRANSPORT__
#define __SE_TRANSPORT__
namespace android {
namespace hardware {
namespace secure_element {
namespace V1_2 {
namespace implementation {
/**
* ITransport is an abstract interface with a set of virtual methods that allow communication
* between the JCserver and the secure element HAL.
*/
class ITransport {
public:
virtual ~ITransport(){}
/**
* Opens connection.
*/
virtual bool openConnection() = 0;
/**
* Send data over communication channel and receives data back from the remote end.
*/
virtual bool sendData(const uint8_t* inData, const size_t inLen, std::vector<uint8_t>& output) = 0;
/**
* Closes the connection.
*/
virtual bool closeConnection() = 0;
/**
* Returns the state of the connection status. Returns true if the connection is active, false if connection is
* broken.
*/
virtual bool isConnected() = 0;
};
class SocketTransport : public ITransport {
public:
SocketTransport() : mSocket(-1), socketStatus(false) {
}
/**
* Creates a socket instance and connects to the provided server IP and port.
*/
bool openConnection() override;
/**
* Sends data over socket and receives data back.
*/
bool sendData(const uint8_t* inData, const size_t inLen, std::vector<uint8_t>& output) override;
/**
* Closes the connection.
*/
bool 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:
/**
* Socket instance.
*/
int mSocket;
bool socketStatus;
bool readData(std::vector<uint8_t>& output);
};
} // namespace implementation
} // namespace V1_2
} // namespace secure_element
} // namespace hardware
} // namespace android
#endif /* __SE_TRANSPORT__ */