summaryrefslogtreecommitdiff
path: root/package/ead/src/ead.h
blob: 3bd64f9d57f90228ad609b7aa233b8b937e77c4c (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
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
/*
 * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#ifndef __EAD_H
#define __EAD_H

#define EAD_DEBUGLEVEL	1

#include <stdint.h>
#include <stddef.h>

#ifndef MAXSALTLEN
#define MAXSALTLEN 32
#endif

#define EAD_PORT	56026UL
#define EAD_MAGIC	3671771902UL
#define EAD_CMD_TIMEOUT	10

#define EAD_MAX_IV_INCR	128

/* request/response types */
/* response id == request id + 1 */
enum ead_type {
	EAD_TYPE_PING,
	EAD_TYPE_PONG,

	EAD_TYPE_SET_USERNAME,
	EAD_TYPE_ACK_USERNAME,

	EAD_TYPE_GET_PRIME,
	EAD_TYPE_PRIME,

	EAD_TYPE_SEND_A,
	EAD_TYPE_SEND_B,

	EAD_TYPE_SEND_AUTH,
	EAD_TYPE_DONE_AUTH,

	EAD_TYPE_SEND_CMD,
	EAD_TYPE_RESULT_CMD,

	EAD_TYPE_LAST
};

enum ead_auth_type {
	EAD_AUTH_DEFAULT,
	EAD_AUTH_MD5
};

enum ead_cmd_type {
	EAD_CMD_NORMAL,
	EAD_CMD_BACKGROUND,
	EAD_CMD_LAST
};

struct ead_msg_pong {
	uint16_t auth_type;
	char name[];
} __attribute__((packed));

struct ead_msg_number {
	uint8_t id;
	unsigned char data[];
} __attribute__((packed));

struct ead_msg_salt {
	uint8_t prime;
	uint8_t len;
	unsigned char salt[MAXSALTLEN];
	unsigned char ext_salt[MAXSALTLEN];
} __attribute__((packed));

struct ead_msg_user {
	char username[32];
} __attribute__((packed));

struct ead_msg_auth {
	unsigned char data[20];
} __attribute__((packed));

struct ead_msg_cmd {
	uint8_t type;
	uint16_t timeout;
	unsigned char data[];
} __attribute__((packed));

struct ead_msg_cmd_data {
	uint8_t done;
	unsigned char data[];
} __attribute__((packed));

struct ead_msg_encrypted {
	uint32_t hash[5];
	uint32_t iv;
	uint8_t pad;
	union {
		struct ead_msg_cmd cmd;
		struct ead_msg_cmd_data cmd_data;
	} data[];
} __attribute__((packed));


#define EAD_DATA(_msg, _type) (&((_msg)->data[0]._type))
#define EAD_ENC_DATA(_msg, _type) (&((_msg)->data[0].enc.data[0]._type))

struct ead_msg {
	uint32_t magic;
	uint32_t len;
	uint32_t type;
	uint16_t nid; /* node id */
	uint16_t tid; /* transaction id */
	union {
		struct ead_msg_pong pong;
		struct ead_msg_user user;
		struct ead_msg_number number;
		struct ead_msg_auth auth;
		struct ead_msg_salt salt;
		struct ead_msg_encrypted enc;
	} data[];
} __attribute__((packed));


#endif