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