-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdmap-connection.h
126 lines (94 loc) · 2.41 KB
/
dmap-connection.h
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef __DMAP_CONNECTION_H__
#define __DMAP_CONNECTION_H__
#include "dmap-const.h"
#include <linux/mutex.h>
#define DMAP_PACKET_MAGIC 0xCBEECBEE
#define DMAP_PACKET_BODY_SIZE 65520
#define DMAP_PACKET_HELLO 1
#define DMAP_PACKET_PING 2
#define DMAP_PACKET_BYE 3
#define DMAP_PACKET_SET_KEY 4
#define DMAP_PACKET_GET_KEY 5
#define DMAP_PACKET_DEL_KEY 6
#define DMAP_PACKET_UPD_KEY 7
#define DMAP_PACKET_CMPXCHG_KEY 8
struct dmap_packet_header {
__le32 magic;
__le32 type;
__le32 len;
__le32 result;
};
struct dmap_packet {
struct dmap_packet_header header;
unsigned char body[DMAP_PACKET_BODY_SIZE];
};
struct dmap_req_set_key {
unsigned char key[DMAP_KEY_SIZE];
unsigned char value[DMAP_VALUE_SIZE];
};
struct dmap_resp_set_key {
__le64 padding;
};
struct dmap_req_get_key {
unsigned char key[DMAP_KEY_SIZE];
};
struct dmap_resp_get_key {
unsigned char value[DMAP_VALUE_SIZE];
};
struct dmap_req_del_key {
unsigned char key[DMAP_KEY_SIZE];
};
struct dmap_resp_del_key {
__le64 padding;
};
struct dmap_req_upd_key {
unsigned char key[DMAP_KEY_SIZE];
unsigned char value[DMAP_VALUE_SIZE];
};
struct dmap_resp_upd_key {
__le64 padding;
};
struct dmap_req_cmpxchg_key {
unsigned char key[DMAP_KEY_SIZE];
unsigned char exchange[DMAP_VALUE_SIZE];
unsigned char comparand[DMAP_VALUE_SIZE];
};
struct dmap_resp_cmpxchg_key {
unsigned char value[DMAP_VALUE_SIZE];
};
struct dmap_req_hello {
struct dmap_address source;
};
struct dmap_resp_hello {
struct dmap_address addr;
};
struct dmap_req_ping {
struct dmap_address source;
};
struct dmap_resp_ping {
__le64 padding;
};
struct dmap_req_bye {
struct dmap_address source;
};
struct dmap_resp_bye {
__le64 padding;
};
struct dmap_connection {
struct mutex mutex;
struct socket *sock;
char host[DMAP_HOST_SIZE];
int port;
};
int dmap_con_init(struct dmap_connection *con);
void dmap_con_deinit(struct dmap_connection *con);
int dmap_con_connect(struct dmap_connection *con, char *host, u16 port);
int dmap_con_set_socket(struct dmap_connection *con, struct socket *sock);
int dmap_con_close(struct dmap_connection *con);
int dmap_con_send(struct dmap_connection *con, u32 type, u32 len,
u32 result, struct dmap_packet *packet);
int dmap_con_recv(struct dmap_connection *con, struct dmap_packet *packet,
u32 *type, u32 *len, u32 *result);
int dmap_con_recv_check(struct dmap_connection *con, struct dmap_packet *packet,
u32 type, u32 len);
#endif