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#include "sys.h"
23
25#define MW_MSG_MAX_BUFLEN 512
26#define MW_MS_TO_FRAMES(ms) (((ms)*60/500 + 1)/2)
27
28#define MW_BUFLEN 1500
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
63// Reserved
72// Reserved
75// Reserved (for setting socket options)
104// Reserved
115 MW_CMD_ERROR = 255
116};
117
133
138 MW_PHY_11BGN = 7
139};
140
142union ip_addr {
143 uint32_t addr;
144 uint8_t byte[4];
145};
146
149 char dst_port[6];
150 char src_port[6];
151 uint8_t channel;
153 char dst_addr[];
154};
155
157struct mw_ip_cfg {
158 union ip_addr addr;
159 union ip_addr mask;
161 union ip_addr dns1;
162 union ip_addr dns2;
163};
164
168// string will not be NULL terminated.
175
178 uint8_t cfg_slot;
179 uint8_t reserved[3];
180 struct mw_ip_cfg ip;
181};
182
185 uint16_t up_delay;
186 int8_t tz;
187 uint8_t dst;
191};
192
195 uint32_t dt_bin[2];
197 char dt_str[MW_CMD_MAX_BUFLEN - 2 * sizeof(uint32_t)];
198};
199
202 uint32_t addr;
204 uint8_t data[MW_CMD_MAX_BUFLEN - sizeof(uint32_t)];
205};
206
209 uint32_t addr;
210 uint16_t len;
211};
212
215 uint32_t reserved;
216 uint16_t port;
217 uint8_t channel;
218};
219
236
254
257 uint8_t slot;
258 uint8_t reserved[3];
260};
261
272
280
283 uint32_t st_flags;
284 struct {
285#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
287 uint8_t online:1;
288 uint8_t cfg_ok:1;
289 uint8_t dt_ok:1;
290 uint8_t cfg:2;
291 uint16_t reserved:3;
292 uint16_t ch_ev:16;
293#else
294 uint16_t ch_ev:16;
295 uint16_t reserved:3;
296 uint8_t cfg:2;
297 uint8_t dt_ok:1;
298 uint8_t cfg_ok:1;
299 uint8_t online:1;
300 enum mw_state sys_stat:8;
301#endif
302 };
303};
304
307 uint16_t device;
308 uint8_t manufacturer;
309};
310
313 uint8_t method;
314 uint8_t num_paths;
315 uint8_t num_kv_pairs;
316 char req[];
317};
318
320 uint8_t retries;
321 char domain[64];
322};
323
325 uint32_t transmitted;
326 uint32_t received;
327 uint32_t total_time_ms;
328};
329
331 uint16_t total;
332 uint16_t len;
333 char *payload;
334};
335
337typedef union mw_cmd {
338 char packet[MW_CMD_MAX_BUFLEN + 2 * sizeof(uint16_t)];
339 struct {
340 uint16_t cmd;
341 uint16_t data_len;
342 // If datalen is nonzero, additional command data goes here until
343 // filling datalen bytes.
344 union {
345 uint8_t ch;
349 uint16_t w_data[MW_CMD_MAX_BUFLEN / sizeof(uint16_t)];
351 uint32_t dw_data[MW_CMD_MAX_BUFLEN / sizeof(uint32_t)];
369 uint16_t fl_sect;
370 uint32_t fl_id;
371 uint16_t rnd_len;
372 };
373 };
375
383 uint32_t remote_ip;
384 uint16_t remote_port;
387};
388
389#endif //_MW_MSG_H_
390
392
mw_sock_stat
Socket status.
Definition mw-msg.h:274
#define MW_CMD_MAX_BUFLEN
Maximum data length contained inside command buffer.
Definition mw-msg.h:34
enum PACKED mw_command
Supported commands.
Definition mw-msg.h:55
#define MW_GT_AVATAR_HEIGHT
Gamertag avatar graphick height in pixels.
Definition mw-msg.h:50
#define MW_PASS_MAXLEN
Maximum password length (including '\0').
Definition mw-msg.h:39
#define MW_GT_TAGLINE_MAX
Gamertag tagline maximum length.
Definition mw-msg.h:46
#define MW_GT_SECURITY_MAX
Gamertag security maximum length.
Definition mw-msg.h:44
#define MW_GT_AVATAR_WIDTH
Gamertag avatar graphick width in pixels.
Definition mw-msg.h:48
#define MW_SSID_MAXLEN
Maximum SSID length (including '\0').
Definition mw-msg.h:37
#define MW_GT_NICKNAME_MAX
Gamertag nickname maximum length.
Definition mw-msg.h:42
#define MW_GT_TG_TOKEN_MAX
Telegram token maximum length.
Definition mw-msg.h:52
enum PACKED mw_phy_type
WiFi PHY configuration for the connection to the AP.
Definition mw-msg.h:135
mw_state
MwState Possible states of the system state machine.
Definition mw-msg.h:263
enum PACKED mw_security
Supported security protocols.
Definition mw-msg.h:119
@ MW_SOCK_NONE
Unused socket.
Definition mw-msg.h:275
@ MW_SOCK_TCP_EST
TCP socket, connection established.
Definition mw-msg.h:277
@ MW_SOCK_UDP_READY
UDP socket ready for sending/receiving.
Definition mw-msg.h:278
@ MW_SOCK_TCP_LISTEN
Socket bound and listening.
Definition mw-msg.h:276
@ MW_ST_INIT
Initialization state.
Definition mw-msg.h:264
@ MW_ST_AP_JOIN
Trying to join an access point.
Definition mw-msg.h:266
@ MW_ST_IDLE
Idle state, until connected to an AP.
Definition mw-msg.h:265
@ MW_ST_MAX
Limit number for state machine.
Definition mw-msg.h:270
@ MW_ST_READY
Connected to The Internet.
Definition mw-msg.h:268
@ MW_ST_SCAN
Scanning access points.
Definition mw-msg.h:267
@ MW_ST_TRANSPARENT
Transparent communication state.
Definition mw-msg.h:269
MW_CMD_GAME_ENDPOINT_SET
Set game API endpoint.
Definition mw-msg.h:112
MW_CMD_WIFI_ADV_SET
Set advanced WiFi parameters.
Definition mw-msg.h:108
MW_CMD_GAMERTAG_SET
Configures a gamertag.
Definition mw-msg.h:90
MW_SEC_OPEN
Open WiFi network.
Definition mw-msg.h:120
MW_CMD_HTTP_CLEANUP
Clean request data.
Definition mw-msg.h:103
MW_CMD_ECHO
Echo data.
Definition mw-msg.h:58
MW_CMD_SERVER_URL_SET
Set the main server URL.
Definition mw-msg.h:106
MW_SEC_WEP
WEP security.
Definition mw-msg.h:121
MW_CMD_IP_CFG
Configure IPv4.
Definition mw-msg.h:64
MW_CMD_HTTP_METHOD_SET
Set HTTP request method.
Definition mw-msg.h:96
MW_CMD_UPGRADE_LIST
Get firmware upgrade versions.
Definition mw-msg.h:110
MW_SEC_WPA2_WPA3_PSK
WPA2 or WPA3 security.
Definition mw-msg.h:127
MW_CMD_DEF_AP_CFG
Set default AP configuration.
Definition mw-msg.h:66
MW_SEC_OWE
OWE security.
Definition mw-msg.h:129
MW_CMD_GAME_REQUEST
Perform a game API request.
Definition mw-msg.h:114
MW_SEC_WPA3_PSK
WPA3 PSK security.
Definition mw-msg.h:126
MW_CMD_HTTP_OPEN
Open HTTP request.
Definition mw-msg.h:101
MW_CMD_SLEEP
Set the module to sleep mode.
Definition mw-msg.h:94
MW_CMD_OK
OK command reply.
Definition mw-msg.h:56
MW_CMD_UPGRADE_PERFORM
Start firmware upgrade.
Definition mw-msg.h:111
MW_CMD_GAMERTAG_GET
Gets a stored gamertag.
Definition mw-msg.h:91
MW_CMD_LOG
Write a message to log trace.
Definition mw-msg.h:92
MW_CMD_SNTP_CFG
Configure SNTP service.
Definition mw-msg.h:78
MW_CMD_BSSID_GET
Gets the WiFi BSSID.
Definition mw-msg.h:89
MW_CMD_NV_CFG_SAVE
Save non-volatile config.
Definition mw-msg.h:109
MW_SEC_WPA2_ENTERPRISE
WPA2 Enterprise security.
Definition mw-msg.h:125
MW_SEC_WPA2_PSK
WPA2 PSK security.
Definition mw-msg.h:123
MW_CMD_PING
Ping host.
Definition mw-msg.h:77
MW_CMD_HTTP_CERT_QUERY
Query the X.509 hash of cert.
Definition mw-msg.h:97
MW_CMD_UDP_SET
Configure UDP socket.
Definition mw-msg.h:74
MW_PHY_11B
Legacy, do not use unless necessary.
Definition mw-msg.h:136
MW_CMD_SERVER_URL_GET
Get the main server URL.
Definition mw-msg.h:105
MW_CMD_HTTP_URL_SET
Set HTTP URL for request.
Definition mw-msg.h:95
MW_SEC_WPA_PSK
WPA PSK security.
Definition mw-msg.h:122
MW_CMD_AP_CFG
Configure access point.
Definition mw-msg.h:60
MW_CMD_TCP_BIND
Bind TCP socket to port.
Definition mw-msg.h:71
MW_CMD_WIFI_ADV_GET
Get advanced WiFi parameters.
Definition mw-msg.h:107
MW_CMD_HTTP_HDR_ADD
Add HTTP request header.
Definition mw-msg.h:99
MW_CMD_TCP_CON
Connect TCP socket.
Definition mw-msg.h:70
MW_CMD_SNTP_CFG_GET
Get SNTP configuration.
Definition mw-msg.h:79
MW_CMD_GAME_KEYVAL_ADD
Add key/value appended to requests.
Definition mw-msg.h:113
MW_CMD_FLASH_ID
Get WiFi flash chip identifiers.
Definition mw-msg.h:85
MW_CMD_DT_SET
Set date and time.
Definition mw-msg.h:81
MW_CMD_DEF_CFG_SET
Set default configuration.
Definition mw-msg.h:87
MW_CMD_AP_LEAVE
Leave previously joined AP.
Definition mw-msg.h:69
MW_CMD_SOCK_STAT
Get socket status.
Definition mw-msg.h:76
MW_CMD_FLASH_READ
Read from WiFi module flash.
Definition mw-msg.h:83
MW_CMD_HTTP_CERT_SET
Set HTTPS certificate.
Definition mw-msg.h:98
MW_SEC_WPA_WPA2_PSK
WPA or WPA2 security.
Definition mw-msg.h:124
MW_CMD_CLOSE
Disconnect and free TCP/UDP socket.
Definition mw-msg.h:73
MW_CMD_FLASH_WRITE
Write to WiFi module flash.
Definition mw-msg.h:82
MW_PHY_11BG
No 802.11n compatibility.
Definition mw-msg.h:137
MW_CMD_HTTP_FINISH
Finish HTTP request.
Definition mw-msg.h:102
MW_CMD_AP_SCAN
Scan for access points.
Definition mw-msg.h:59
MW_CMD_SYS_STAT
Get system status.
Definition mw-msg.h:86
MW_CMD_IP_CFG_GET
Get IPv4 configuration.
Definition mw-msg.h:65
MW_CMD_FLASH_ERASE
Erase sector from WiFi flash.
Definition mw-msg.h:84
MW_CMD_VERSION
Get firmware version.
Definition mw-msg.h:57
MW_SEC_WAPI_PSK
WAPI PSK security.
Definition mw-msg.h:128
MW_CMD_FACTORY_RESET
Set default configuratioSet default configuration.
Definition mw-msg.h:93
MW_CMD_DEF_AP_CFG_GET
Get default AP configuration.
Definition mw-msg.h:67
MW_CMD_DATETIME
Get date and time.
Definition mw-msg.h:80
MW_CMD_AP_JOIN
Join access point.
Definition mw-msg.h:68
MW_SEC_UNKNOWN
Unknown security.
Definition mw-msg.h:130
MW_CMD_IP_CURRENT
Get current IPv4 configuration.
Definition mw-msg.h:62
MW_CMD_HTTP_HDR_DEL
Delete HTTP request header.
Definition mw-msg.h:100
MW_CMD_HRNG_GET
Gets random numbers.
Definition mw-msg.h:88
MW_CMD_AP_CFG_GET
Get access point configuration.
Definition mw-msg.h:61
Flash chip identifiers.
Definition mw-msg.h:306
uint8_t manufacturer
Manufacturer ID.
Definition mw-msg.h:308
uint16_t device
Device ID.
Definition mw-msg.h:307
Game API request.
Definition mw-msg.h:312
uint8_t num_paths
Number of paths.
Definition mw-msg.h:314
char req[]
Request data.
Definition mw-msg.h:316
uint8_t num_kv_pairs
Number of key/value pairs.
Definition mw-msg.h:315
uint8_t method
Request method.
Definition mw-msg.h:313
Gamertag set message data.
Definition mw-msg.h:256
uint8_t reserved[3]
Reserved, set to 0.
Definition mw-msg.h:258
uint8_t slot
Slot to store gamertag (0 to 2).
Definition mw-msg.h:257
struct mw_gamertag gamertag
Gamertag to set.
Definition mw-msg.h:259
Gamertag data.
Definition mw-msg.h:238
uint8_t avatar_pal[32]
Avatar image palette.
Definition mw-msg.h:252
int id
Unique gamertag id.
Definition mw-msg.h:240
char tg_token[MW_GT_TG_TOKEN_MAX]
Telegram token.
Definition mw-msg.h:248
char security[MW_GT_SECURITY_MAX]
User security string.
Definition mw-msg.h:244
char nickname[MW_GT_NICKNAME_MAX]
User nickname.
Definition mw-msg.h:242
char tagline[MW_GT_TAGLINE_MAX]
User defined text tag.
Definition mw-msg.h:246
uint8_t avatar_tiles[MW_GT_AVATAR_WIDTH *MW_GT_AVATAR_HEIGHT/2]
Avatar image tiles.
Definition mw-msg.h:250
IP configuration parameters.
Definition mw-msg.h:157
union ip_addr gateway
Gateway IP address in binary format.
Definition mw-msg.h:160
union ip_addr dns2
DNS server 2 IP address in binary format.
Definition mw-msg.h:162
union ip_addr mask
Subnet mask in binary IP format.
Definition mw-msg.h:159
union ip_addr addr
Host IP address in binary format.
Definition mw-msg.h:158
union ip_addr dns1
DNS server 1 IP address in binary format.
Definition mw-msg.h:161
AP configuration message.
Definition mw-msg.h:169
enum mw_phy_type phy_type
PHY type bitmask.
Definition mw-msg.h:171
uint8_t cfg_num
Configuration number.
Definition mw-msg.h:170
char ssid[MW_SSID_MAXLEN]
SSID string.
Definition mw-msg.h:172
char pass[MW_PASS_MAXLEN]
Password string.
Definition mw-msg.h:173
Bind message data.
Definition mw-msg.h:214
uint32_t reserved
Reserved, set to 0.
Definition mw-msg.h:215
uint16_t port
Port to bind to.
Definition mw-msg.h:216
uint8_t channel
Channel used for the socket bound to port.
Definition mw-msg.h:217
Date and time message.
Definition mw-msg.h:194
char dt_str[MW_CMD_MAX_BUFLEN - 2 *sizeof(uint32_t)]
Date and time in textual format.
Definition mw-msg.h:197
uint32_t dt_bin[2]
Definition mw-msg.h:195
Flash memory address and data.
Definition mw-msg.h:201
uint8_t data[MW_CMD_MAX_BUFLEN - sizeof(uint32_t)]
Data associated to the address.
Definition mw-msg.h:204
uint32_t addr
Definition mw-msg.h:202
Flash memory block.
Definition mw-msg.h:208
uint16_t len
Length of the block.
Definition mw-msg.h:210
uint32_t addr
Start address.
Definition mw-msg.h:209
TCP/UDP address message.
Definition mw-msg.h:148
uint8_t channel
Definition mw-msg.h:151
char dst_port[6]
TCP destination port string.
Definition mw-msg.h:149
char src_port[6]
TCP source port string.
Definition mw-msg.h:150
char dst_addr[]
Data payload.
Definition mw-msg.h:153
IP configuration message.
Definition mw-msg.h:177
uint8_t cfg_slot
Configuration slot.
Definition mw-msg.h:178
uint8_t reserved[3]
Reserved (set to 0).
Definition mw-msg.h:179
struct mw_ip_cfg ip
IPv4 configuration data.
Definition mw-msg.h:180
SNTP and timezone configuration.
Definition mw-msg.h:184
uint16_t up_delay
Update delay in seconds (min: 15).
Definition mw-msg.h:185
int8_t tz
Timezone (from -11 to 13).
Definition mw-msg.h:186
char servers[MW_CMD_MAX_BUFLEN - 4]
Definition mw-msg.h:190
uint8_t dst
Definition mw-msg.h:187
Definition mw-msg.h:319
Definition mw-msg.h:324
Payload with remote IP and port.
Definition mw-msg.h:382
uint32_t remote_ip
IP of the remote end.
Definition mw-msg.h:383
uint16_t remote_port
Definition mw-msg.h:384
char payload[MW_CMD_MAX_BUFLEN - 4 - 2]
Data payload.
Definition mw-msg.h:386
Definition mw-msg.h:330
Advanced WiFi configuration.
Definition mw-msg.h:221
uint32_t rx_max_single_pkt_len
WiFi RX max single packet size.
Definition mw-msg.h:227
uint8_t reserved[3]
Unused, set to 0.
Definition mw-msg.h:234
uint8_t ampdu_rx_enable
WiFi AMPDU RX feature enable flag.
Definition mw-msg.h:223
uint8_t rx_buf_num
WiFi RX buffer number.
Definition mw-msg.h:230
uint32_t rx_buf_len
WiFi RX buffer size.
Definition mw-msg.h:228
uint8_t left_continuous_rx_buf_num
WiFi Rx left continuous rx buffer number.
Definition mw-msg.h:232
uint32_t rx_ampdu_buf_len
WiFi AMPDU RX buffer length.
Definition mw-msg.h:226
uint8_t amsdu_rx_enable
WiFi AMSDU RX feature enable flag.
Definition mw-msg.h:229
uint8_t qos_enable
WiFi QOS feature enable flag.
Definition mw-msg.h:222
uint8_t rx_pkt_num
WiFi RX packet number.
Definition mw-msg.h:231
uint8_t rx_ba_win
WiFi Block Ack RX window size.
Definition mw-msg.h:224
uint8_t rx_ampdu_buf_num
WiFi AMPDU RX buffer number.
Definition mw-msg.h:225
uint8_t tx_buf_num
WiFi TX buffer number.
Definition mw-msg.h:233
Entry point unit / Interrupt callback / System.
#define PACKED
Macro for packing structures and enumerates.
Definition sys.h:56
Types definition.
IPv4 address.
Definition mw-msg.h:142
uint32_t addr
IP address in 32 bit form.
Definition mw-msg.h:143
Command sent to system FSM.
Definition mw-msg.h:337
struct mw_msg_flash_range fl_range
Flash memory range.
Definition mw-msg.h:358
struct mw_gamertag_set_msg gamertag_set
Gamertag set.
Definition mw-msg.h:364
struct mw_msg_date_time date_time
Date and time message.
Definition mw-msg.h:356
struct mw_msg_sntp_cfg sntp_cfg
SNTP client configuration.
Definition mw-msg.h:355
struct mw_ping_request ping
Ping message.
Definition mw-msg.h:360
uint16_t rnd_len
Length of the random buffer to fill.
Definition mw-msg.h:371
uint16_t fl_sect
Flash sector.
Definition mw-msg.h:369
struct mw_msg_in_addr in_addr
Internet address.
Definition mw-msg.h:352
uint32_t fl_id
Flash IDs.
Definition mw-msg.h:370
uint16_t w_data[MW_CMD_MAX_BUFLEN/sizeof(uint16_t)]
RAW data in uint16_t format.
Definition mw-msg.h:349
struct mw_wifi_adv_cfg wifi_adv_cfg
Advanced WiFi configuration.
Definition mw-msg.h:366
struct mw_gamertag gamertag_get
Gamertag get.
Definition mw-msg.h:365
struct mw_flash_id flash_id
Flash chip identifiers.
Definition mw-msg.h:367
uint8_t ch
Definition mw-msg.h:345
struct mw_msg_flash_data fl_data
Flash memory data.
Definition mw-msg.h:357
struct mw_msg_bind bind
Bind message.
Definition mw-msg.h:359
uint16_t data_len
Data length.
Definition mw-msg.h:341
uint16_t cmd
Command code.
Definition mw-msg.h:340
char packet[MW_CMD_MAX_BUFLEN+2 *sizeof(uint16_t)]
Packet raw data.
Definition mw-msg.h:338
struct mw_msg_ip_cfg ip_cfg
IP configuration.
Definition mw-msg.h:354
uint32_t dw_data[MW_CMD_MAX_BUFLEN/sizeof(uint32_t)]
RAW data in uint32_t format.
Definition mw-msg.h:351
struct mw_ping_response ping_response
Ping message.
Definition mw-msg.h:361
struct mw_ga_request ga_request
Game API request.
Definition mw-msg.h:368
union mw_msg_sys_stat sys_stat
System status.
Definition mw-msg.h:363
uint8_t data[MW_CMD_MAX_BUFLEN]
RAW data in uint8_t format.
Definition mw-msg.h:347
struct mw_upgrade_list_response ug_list_response
Ping message.
Definition mw-msg.h:362
struct mw_msg_ap_cfg ap_cfg
Access Point configuration.
Definition mw-msg.h:353
System status.
Definition mw-msg.h:282
enum mw_state sys_stat
System status.
Definition mw-msg.h:286
uint16_t reserved
Reserved flags.
Definition mw-msg.h:291
uint8_t dt_ok
Date and time synchronized at least once.
Definition mw-msg.h:289
uint8_t online
Module is connected to the Internet.
Definition mw-msg.h:287
uint16_t ch_ev
Channel flags with the pending event.
Definition mw-msg.h:292
uint8_t cfg
Default network configuration.
Definition mw-msg.h:290
uint32_t st_flags
Accesses all the flags at once.
Definition mw-msg.h:283
uint8_t cfg_ok
Configuration OK.
Definition mw-msg.h:288