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