sgdk
Loading...
Searching...
No Matches
mw-msg.h
Go to the documentation of this file.
1/************************************************************************/
17#ifndef _MW_MSG_H_
18#define _MW_MSG_H_
19
20#include "types.h"
21
22#if (MODULE_MEGAWIFI != 0)
23
25#define PACKED __attribute__((__packed__))
26
28#define MW_MSG_MAX_BUFLEN 512
29
31#define MW_CMD_HEADLEN (2 * sizeof(uint16_t))
32
34#define MW_CMD_MAX_BUFLEN (MW_MSG_MAX_BUFLEN - MW_CMD_HEADLEN)
35
37#define MW_SSID_MAXLEN 32
39#define MW_PASS_MAXLEN 64
40
42#define MW_GT_NICKNAME_MAX 32
44#define MW_GT_SECURITY_MAX 32
46#define MW_GT_TAGLINE_MAX 32
48#define MW_GT_AVATAR_WIDTH 32
50#define MW_GT_AVATAR_HEIGHT 48
52#define MW_GT_TG_TOKEN_MAX 64
53
55enum PACKED mw_command {
56 MW_CMD_OK = 0,
57 MW_CMD_VERSION = 1,
58 MW_CMD_ECHO = 2,
59 MW_CMD_AP_SCAN = 3,
60 MW_CMD_AP_CFG = 4,
61 MW_CMD_AP_CFG_GET = 5,
62 MW_CMD_IP_CURRENT = 6,
63// Reserved
64 MW_CMD_IP_CFG = 8,
65 MW_CMD_IP_CFG_GET = 9,
66 MW_CMD_DEF_AP_CFG = 10,
67 MW_CMD_DEF_AP_CFG_GET = 11,
68 MW_CMD_AP_JOIN = 12,
69 MW_CMD_AP_LEAVE = 13,
70 MW_CMD_TCP_CON = 14,
71 MW_CMD_TCP_BIND = 15,
72// Reserved
73 MW_CMD_CLOSE = 17,
74 MW_CMD_UDP_SET = 18,
75// Reserved (for setting socket options)
76 MW_CMD_SOCK_STAT = 20,
77 MW_CMD_PING = 21,
78 MW_CMD_SNTP_CFG = 22,
79 MW_CMD_SNTP_CFG_GET = 23,
80 MW_CMD_DATETIME = 24,
81 MW_CMD_DT_SET = 25,
82 MW_CMD_FLASH_WRITE = 26,
83 MW_CMD_FLASH_READ = 27,
84 MW_CMD_FLASH_ERASE = 28,
85 MW_CMD_FLASH_ID = 29,
86 MW_CMD_SYS_STAT = 30,
87 MW_CMD_DEF_CFG_SET = 31,
88 MW_CMD_HRNG_GET = 32,
89 MW_CMD_BSSID_GET = 33,
90 MW_CMD_GAMERTAG_SET = 34,
91 MW_CMD_GAMERTAG_GET = 35,
92 MW_CMD_LOG = 36,
93 MW_CMD_FACTORY_RESET = 37,
94 MW_CMD_SLEEP = 38,
95 MW_CMD_HTTP_URL_SET = 39,
96 MW_CMD_HTTP_METHOD_SET = 40,
97 MW_CMD_HTTP_CERT_QUERY = 41,
98 MW_CMD_HTTP_CERT_SET = 42,
99 MW_CMD_HTTP_HDR_ADD = 43,
100 MW_CMD_HTTP_HDR_DEL = 44,
101 MW_CMD_HTTP_OPEN = 45,
102 MW_CMD_HTTP_FINISH = 46,
103 MW_CMD_HTTP_CLEANUP = 47,
104// Reserved
105 MW_CMD_SERVER_URL_GET = 49,
106 MW_CMD_SERVER_URL_SET = 50,
107 MW_CMD_WIFI_ADV_GET = 51,
108 MW_CMD_WIFI_ADV_SET = 52,
109 MW_CMD_NV_CFG_SAVE = 53,
110 MW_CMD_UPGRADE_LIST = 54,
111 MW_CMD_UPGRADE_PERFORM = 55,
112 MW_CMD_GAME_ENDPOINT_SET = 56,
113 MW_CMD_GAME_KEYVAL_ADD = 57,
114 MW_CMD_GAME_REQUEST = 58,
115 MW_CMD_ERROR = 255
116};
117
119enum PACKED mw_security {
120 MW_SEC_OPEN = 0,
121 MW_SEC_WEP,
122 MW_SEC_WPA_PSK,
123 MW_SEC_WPA2_PSK,
124 MW_SEC_WPA_WPA2_PSK,
125 MW_SEC_UNKNOWN
126};
127
129enum PACKED mw_phy_type {
130 MW_PHY_11B = 1,
131 MW_PHY_11BG = 3,
132 MW_PHY_11BGN = 7
133};
134
136union ip_addr {
137 uint32_t addr;
138 uint8_t byte[4];
139};
140
142struct mw_msg_in_addr {
143 char dst_port[6];
144 char src_port[6];
145 uint8_t channel;
147 char dst_addr[];
148};
149
151struct mw_ip_cfg {
152 union ip_addr addr;
153 union ip_addr mask;
154 union ip_addr gateway;
155 union ip_addr dns1;
156 union ip_addr dns2;
157};
158
162// string will not be NULL terminated.
163struct mw_msg_ap_cfg {
164 uint8_t cfg_num;
165 enum mw_phy_type phy_type;
166 char ssid[MW_SSID_MAXLEN];
167 char pass[MW_PASS_MAXLEN];
168};
169
171struct mw_msg_ip_cfg {
172 uint8_t cfg_slot;
173 uint8_t reserved[3];
174 struct mw_ip_cfg ip;
175};
176
178struct mw_msg_sntp_cfg {
179 uint16_t up_delay;
180 int8_t tz;
181 uint8_t dst;
184 char servers[MW_CMD_MAX_BUFLEN - 4];
185};
186
188struct mw_msg_date_time {
189 uint32_t dt_bin[2];
191 char dt_str[MW_CMD_MAX_BUFLEN - 2 * sizeof(uint32_t)];
192};
193
195struct mw_msg_flash_data {
196 uint32_t addr;
198 uint8_t data[MW_CMD_MAX_BUFLEN - sizeof(uint32_t)];
199};
200
202struct mw_msg_flash_range {
203 uint32_t addr;
204 uint16_t len;
205};
206
208struct mw_msg_bind {
209 uint32_t reserved;
210 uint16_t port;
211 uint8_t channel;
212};
213
215struct mw_wifi_adv_cfg {
216 uint8_t qos_enable;
217 uint8_t ampdu_rx_enable;
218 uint8_t rx_ba_win;
219 uint8_t rx_ampdu_buf_num;
220 uint32_t rx_ampdu_buf_len;
221 uint32_t rx_max_single_pkt_len;
222 uint32_t rx_buf_len;
223 uint8_t amsdu_rx_enable;
224 uint8_t rx_buf_num;
225 uint8_t rx_pkt_num;
226 uint8_t left_continuous_rx_buf_num;
227 uint8_t tx_buf_num;
228 uint8_t reserved[3];
229};
230
232struct mw_gamertag {
234 int id;
236 char nickname[MW_GT_NICKNAME_MAX];
238 char security[MW_GT_SECURITY_MAX];
240 char tagline[MW_GT_TAGLINE_MAX];
242 char tg_token[MW_GT_TG_TOKEN_MAX];
244 uint8_t avatar_tiles[MW_GT_AVATAR_WIDTH * MW_GT_AVATAR_HEIGHT / 2];
246 uint8_t avatar_pal[32];
247};
248
250struct mw_gamertag_set_msg {
251 uint8_t slot;
252 uint8_t reserved[3];
253 struct mw_gamertag gamertag;
254};
255
257enum mw_state {
258 MW_ST_INIT = 0,
259 MW_ST_IDLE,
260 MW_ST_AP_JOIN,
261 MW_ST_SCAN,
262 MW_ST_READY,
263 MW_ST_TRANSPARENT,
264 MW_ST_MAX
265};
266
268enum mw_sock_stat {
269 MW_SOCK_NONE = 0,
270 MW_SOCK_TCP_LISTEN,
271 MW_SOCK_TCP_EST,
272 MW_SOCK_UDP_READY
273};
274
276union mw_msg_sys_stat {
277 uint32_t st_flags;
278 struct {
279#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
280 enum mw_state sys_stat:8;
281 uint8_t online:1;
282 uint8_t cfg_ok:1;
283 uint8_t dt_ok:1;
284 uint8_t cfg:2;
285 uint16_t reserved:3;
286 uint16_t ch_ev:16;
287#else
288 uint16_t ch_ev:16;
289 uint16_t reserved:3;
290 uint8_t cfg:2;
291 uint8_t dt_ok:1;
292 uint8_t cfg_ok:1;
293 uint8_t online:1;
294 enum mw_state sys_stat:8;
295#endif
296 };
297};
298
300struct mw_flash_id {
301 uint16_t device;
302 uint8_t manufacturer;
303};
304
306struct mw_ga_request {
307 uint8_t method;
308 uint8_t num_paths;
309 uint8_t num_kv_pairs;
310 char req[];
311};
312
314typedef union mw_cmd {
315 char packet[MW_CMD_MAX_BUFLEN + 2 * sizeof(uint16_t)];
316 struct {
317 uint16_t cmd;
318 uint16_t data_len;
319 // If datalen is nonzero, additional command data goes here until
320 // filling datalen bytes.
321 union {
322 uint8_t ch;
324 uint8_t data[MW_CMD_MAX_BUFLEN];
326 uint16_t w_data[MW_CMD_MAX_BUFLEN / sizeof(uint16_t)];
328 uint32_t dw_data[MW_CMD_MAX_BUFLEN / sizeof(uint32_t)];
329 struct mw_msg_in_addr in_addr;
330 struct mw_msg_ap_cfg ap_cfg;
331 struct mw_msg_ip_cfg ip_cfg;
332 struct mw_msg_sntp_cfg sntp_cfg;
333 struct mw_msg_date_time date_time;
334 struct mw_msg_flash_data fl_data;
335 struct mw_msg_flash_range fl_range;
336 struct mw_msg_bind bind;
337 union mw_msg_sys_stat sys_stat;
338 struct mw_gamertag_set_msg gamertag_set;
339 struct mw_gamertag gamertag_get;
340 struct mw_wifi_adv_cfg wifi_adv_cfg;
341 struct mw_flash_id flash_id;
342 struct mw_ga_request ga_request;
343 uint16_t fl_sect;
344 uint32_t fl_id;
345 uint16_t rnd_len;
346 };
347 };
348} mw_cmd;
349
356struct mw_reuse_payload {
357 uint32_t remote_ip;
358 uint16_t remote_port;
360 char payload[MW_CMD_MAX_BUFLEN - 4 - 2];
361};
362
363#endif // MODULE_MEGAWIFI
364
365#endif //_MW_MSG_H_
366
Types definition.