-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathprotocolTypes.h
More file actions
executable file
·347 lines (297 loc) · 7.71 KB
/
Copy pathprotocolTypes.h
File metadata and controls
executable file
·347 lines (297 loc) · 7.71 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/*
* protocolTypes.h
*
* Created on: May 10, 2021
* Author: rony
*/
#ifndef PROTOCOLTYPES_H_
#define PROTOCOLTYPES_H_
#define VERSION_MAJOR 1
#define VERSION_MINOR 4
#define VERSION_REVISION 0
#define VERSION_STRING "1.4.0"
#define RELEASE_TYPE 'U'
#define MAIN_LISTEN_PORTNUMBER 30302
#define BROADCAST_PORTNUMBER 30301
#define COMMAND_SEND_FILE 0x00000000
#define COMMAND_RUN 0x00000001
#define COMMAND_CLOSE 0x00000002
#define COMMAND_MKDIR 0x00000003
#define COMMAND_DIR 0x00000004
#define COMMAND_GET_FILE 0x00000005
#define MAGIC_TOKEN 0xAABBCCDD
#define MAX_MESSAGE_LENGTH 0x8800
#define FILE_CHUNK_SIZE 0x8000
#define MAX_FILEPATH_LENGTH 256
typedef enum
{
//New Connection Signalling
PMT_NEW_CLIENT_PORT = 0x00000001,
PMT_VERSION = 0x00000002,
PMT_GET_VERSION = 0x00000003,
PMT_SHUTDOWN_SERVER = 0x00000004,
PMT_ACK = 0x00000005,
PMT_CANCEL_OPERATION = 0x00000006,
PMT_FAILED = 0x00000007,
PMT_CLOSING = 0x00000008,
//File operations
PMT_START_OF_SEND_FILE = 0x00000010,
PMT_FILE_CHUNK = 0x00000011,
PMT_CLOSE = 0x00000012,
PMT_MKDIR = 0x00000013,
PMT_GET_DIR_LIST = 0x00000014,
PMT_DIR_LIST = 0x00000015,
PMT_GET_FILE = 0x00000016,
PMT_PUT_FILE = 0x00000017,
PMT_DELETE_PATH = 0x00000018,
PMT_GET_VOLUMES = 0x00000019,
PMT_VOLUME_LIST = 0x0000001A,
PMT_RENAME_FILE = 0x0000001B,
PMT_FILE_CHUNK_CONF = 0x0000001C,
PMT_FILE_PUT_CONF = 0x0000001D,
PMT_PATH_DELETED = 0x0000001E,
//Device Discovery
PMT_DEVICE_DISCOVERY = 0x00000020,
PMT_DEVICE_ANNOUNCE = 0x00000021,
PMT_PING = 0x00000022,
PMT_PONG = 0x00000023,
//remote commands
PMT_RUN = 0x00000021,
PMT_REBOOT = 0x00000022,
//Remote shell
PMT_SHELL_EXEC = 0x00000030, // Client→Server: execute a command
PMT_SHELL_OUTPUT = 0x00000031, // Server→Client: stdout/stderr chunk
PMT_SHELL_DONE = 0x00000032, // Server→Client: command finished + exit code
PMT_SHELL_COMPLETE_REQ = 0x00000033, // Client→Server: tab-completion request
PMT_SHELL_COMPLETE_RSP = 0x00000034, // Server→Client: completion candidates
PMT_INVALID = 0x00000035
} ProtocolMessageType_t;
typedef struct
{
unsigned int token; //This token must be present at the begining of every message
unsigned int type; //The ProtocolMessageType_t
unsigned int length; //The length of this message including the payload
} ProtocolMessage_t;
typedef enum
{
AT_NOK = 0,
AT_OK = 1,
AT_DEST_EXISTS_AS_FILE = 2,
AT_DEST_EXISTS_AS_DIR = 3,
AT_UNKNOWN = 255
} AckTypes_t;
typedef struct
{
ProtocolMessage_t header;
char response; //User defined by 0 reject and !0 is accepted generally speaking
char padding[ 3 ];
} ProtocolMessage_Ack_t;
//This is a signal from the server informing the client to reconnect on a new port
typedef struct
{
ProtocolMessage_t header;
unsigned short port; //The new port for this client.
} ProtocolMessageNewClientPort_t;
typedef struct
{
ProtocolMessage_t header;
char message[128];
} ProtocolMessageDisconnect_t;
typedef enum
{
DET_ROOT = 0x00000001,
DET_USERDIR = 0x00000002,
DET_SOFTLINK= 0x00000003,
DET_LINKDIR = 0x00000004,
DET_FILE = 0xFFFFFFFD,
DET_LINKFILE= 0xFFFFFFFC,
DET_PIPEFILE= 0xFFFFFFFB
} DirEntType_t;
typedef struct
{
unsigned int entrySize; //The size of this entry
unsigned int type; //See DirEntType_t
unsigned int size; //File size in bytes
//unsigned int filenameLength; //The length of the filename
char filename[1]; //The filename as a null terminated c-string
} ProtocolMessage_DirEntry_t;
typedef struct
{
ProtocolMessage_t header;
unsigned int entryCount;
ProtocolMessage_DirEntry_t entries[1];
} ProtocolMessageDirectoryList_t;
typedef struct
{
ProtocolMessage_t header;
unsigned int length;
char path[1];
} ProtocolMessageGetDirectoryList_t;
typedef struct
{
ProtocolMessage_t header;
char reason[ 128 ];
} ProtocolMessage_QuitServer_t;
typedef struct
{
ProtocolMessage_t header;
unsigned char major;
unsigned char minor;
unsigned char rev;
char releaseType; //R = Released version, U = Unreleased
} ProtocolMessage_Version_t;
typedef struct
{
ProtocolMessage_t header;
char filePath[1];
} ProtocolMessage_FilePull_t;
typedef struct
{
ProtocolMessage_t header;
char filePath[1];
} ProtocolMessage_FilePut_t;
typedef struct
{
ProtocolMessage_t header;
unsigned int fileSize;
unsigned int numberOfFileChunks;
char filePath[1];
} ProtocolMessage_StartOfFileSend_t;
typedef struct
{
ProtocolMessage_t header;
unsigned int chunkNumber;
unsigned int bytesContained;
char chunk[ FILE_CHUNK_SIZE ];
} ProtocolMessage_FileChunk_t;
typedef struct
{
ProtocolMessage_t header;
unsigned int chunkNumber;
} ProtocolMessage_FileChunkConfirm_t;
typedef struct
{
ProtocolMessage_t header;
unsigned int chunkCount;
unsigned int filesize;
unsigned int checksum;
} ProtocolMessage_FilePutConfirm_t;
typedef struct
{
ProtocolMessage_t header;
char filePath[1];
} ProtocolMessage_MakeDir_t;
typedef struct
{
ProtocolMessage_t header;
unsigned int entryType;
char filePath[1];
} ProtocolMessage_DeletePath_t;
typedef enum
{
DFR_NONE = 0x00,
DFR_FILE_IN_USE = 0x01,
DFR_PATH_NOT_FOUND = 0x02,
DFR_OPERATION_ALREADY_UNDERWAY = 0x03,
DFR_INVALID_PATH = 0x04,
DFR_UNKNOWN = 0x05
} DeleteFailureReason;
typedef struct
{
ProtocolMessage_t header;
char deleteSucceeded; //0 = no. 1 = yes
char deleteCompleted; //0 = no. 1 = yes. Only used for recursive deletion
DeleteFailureReason failureReason;
char padding;
char filePath[1];
} ProtocolMessage_PathDeleted_t;
typedef struct
{
ProtocolMessage_t header;
unsigned short oldNameSize;
unsigned short newNameSize;
char filePaths[1]; //The old name shall be encoded first, then a NULL, then the new name and finally a NULL;
} ProtocolMessage_RenamePath_t;
typedef struct
{
ProtocolMessage_t header;
} ProtocolMessage_GetVolumeList_t;
typedef struct
{
unsigned int entrySize;
unsigned int diskType;
unsigned int id_NumSoftErrors;
unsigned int id_UnitNumber;
unsigned int id_DiskState;
unsigned int id_NumBlocks;
unsigned int id_NumBlocksUsed;
unsigned int id_BytesPerBlock;
unsigned int id_DiskType;
unsigned int id_InUse;
char name[1];
} VolumeEntry_t;
typedef struct
{
ProtocolMessage_t header;
unsigned int volumeCount;
VolumeEntry_t volumes[ 1 ];
} ProtocolMessage_VolumeList_t;
typedef struct
{
ProtocolMessage_t header;
char command[1];
} ProtocolMessage_Run_t;
typedef struct
{
ProtocolMessage_t header;
} ProtocolMessage_DeviceDiscovery_t;
typedef struct
{
ProtocolMessage_t header;
char name[32];
char osName[32];
char osVersion[32];
char hardware[32];
} ProtocolMessage_DeviceAnnouncement_t;
typedef struct
{
ProtocolMessage_t header;
} ProtocolMessage_Reboot_t;
typedef struct
{
ProtocolMessage_t header;
} ProtocolMessage_CancelOperation_t;
typedef struct
{
ProtocolMessage_t header;
char message[1];
} ProtocolMessage_Failed_t;
typedef struct
{
ProtocolMessage_t header;
char command[1];
} ProtocolMessage_ShellExec_t;
typedef struct
{
ProtocolMessage_t header;
char partial[512]; // partial path token to complete
} ProtocolMessage_ShellCompleteReq_t;
typedef struct
{
ProtocolMessage_t header;
unsigned int entryCount;
char entries[1]; // entryCount null-terminated strings packed together
} ProtocolMessage_ShellCompleteRsp_t;
typedef struct
{
ProtocolMessage_t header;
unsigned int bytesContained;
char output[FILE_CHUNK_SIZE];
} ProtocolMessage_ShellOutput_t;
typedef struct
{
ProtocolMessage_t header;
int returnCode;
char currentDir[256]; // current directory after command (null-terminated)
} ProtocolMessage_ShellDone_t;
#endif /* PROTOCOLTYPES_H_ */