sgdk
mw-msg.h
Go to the documentation of this file.
00001 /************************************************************************/
00017 #ifndef _MW_MSG_H_
00018 #define _MW_MSG_H_
00019 
00020 #include "types.h"
00021 
00022 #if (MODULE_MEGAWIFI != 0)
00023 
00025 #define PACKED          __attribute__((__packed__))
00026 
00028 #define MW_MSG_MAX_BUFLEN       512
00029 
00031 #define MW_CMD_HEADLEN          (2 * sizeof(uint16_t))
00032 
00034 #define MW_CMD_MAX_BUFLEN       (MW_MSG_MAX_BUFLEN - MW_CMD_HEADLEN)
00035 
00037 #define MW_SSID_MAXLEN          32
00038 
00039 #define MW_PASS_MAXLEN          64
00040 
00042 #define MW_GT_NICKNAME_MAX              32
00043 
00044 #define MW_GT_SECURITY_MAX              32
00045 
00046 #define MW_GT_TAGLINE_MAX               32
00047 
00048 #define MW_GT_AVATAR_WIDTH              32
00049 
00050 #define MW_GT_AVATAR_HEIGHT             48
00051 
00052 #define MW_GT_TG_TOKEN_MAX              64
00053 
00055 enum PACKED mw_command {
00056         MW_CMD_OK                =   0, 
00057         MW_CMD_VERSION           =   1, 
00058         MW_CMD_ECHO              =   2, 
00059         MW_CMD_AP_SCAN           =   3, 
00060         MW_CMD_AP_CFG            =   4, 
00061         MW_CMD_AP_CFG_GET        =   5, 
00062         MW_CMD_IP_CURRENT        =   6, 
00063 // Reserved
00064         MW_CMD_IP_CFG            =   8, 
00065         MW_CMD_IP_CFG_GET        =   9, 
00066         MW_CMD_DEF_AP_CFG        =  10, 
00067         MW_CMD_DEF_AP_CFG_GET    =  11, 
00068         MW_CMD_AP_JOIN           =  12, 
00069         MW_CMD_AP_LEAVE          =  13, 
00070         MW_CMD_TCP_CON           =  14, 
00071         MW_CMD_TCP_BIND          =  15, 
00072 // Reserved
00073         MW_CMD_CLOSE             =  17, 
00074         MW_CMD_UDP_SET           =  18, 
00075 // Reserved (for setting socket  options)
00076         MW_CMD_SOCK_STAT         =  20, 
00077         MW_CMD_PING              =  21, 
00078         MW_CMD_SNTP_CFG          =  22, 
00079         MW_CMD_SNTP_CFG_GET      =  23,  
00080         MW_CMD_DATETIME          =  24, 
00081         MW_CMD_DT_SET            =  25, 
00082         MW_CMD_FLASH_WRITE       =  26, 
00083         MW_CMD_FLASH_READ        =  27, 
00084         MW_CMD_FLASH_ERASE       =  28, 
00085         MW_CMD_FLASH_ID          =  29, 
00086         MW_CMD_SYS_STAT          =  30, 
00087         MW_CMD_DEF_CFG_SET       =  31, 
00088         MW_CMD_HRNG_GET          =  32, 
00089         MW_CMD_BSSID_GET         =  33, 
00090         MW_CMD_GAMERTAG_SET      =  34, 
00091         MW_CMD_GAMERTAG_GET      =  35, 
00092         MW_CMD_LOG               =  36, 
00093         MW_CMD_FACTORY_RESET     =  37, 
00094         MW_CMD_SLEEP             =  38, 
00095         MW_CMD_HTTP_URL_SET      =  39, 
00096         MW_CMD_HTTP_METHOD_SET   =  40, 
00097         MW_CMD_HTTP_CERT_QUERY   =  41, 
00098         MW_CMD_HTTP_CERT_SET     =  42, 
00099         MW_CMD_HTTP_HDR_ADD      =  43, 
00100         MW_CMD_HTTP_HDR_DEL      =  44, 
00101         MW_CMD_HTTP_OPEN         =  45, 
00102         MW_CMD_HTTP_FINISH       =  46, 
00103         MW_CMD_HTTP_CLEANUP      =  47, 
00104 // Reserved
00105         MW_CMD_SERVER_URL_GET    =  49, 
00106         MW_CMD_SERVER_URL_SET    =  50, 
00107         MW_CMD_WIFI_ADV_GET      =  51, 
00108         MW_CMD_WIFI_ADV_SET      =  52, 
00109         MW_CMD_NV_CFG_SAVE       =  53, 
00110         MW_CMD_UPGRADE_LIST      =  54, 
00111         MW_CMD_UPGRADE_PERFORM   =  55, 
00112         MW_CMD_GAME_ENDPOINT_SET =  56, 
00113         MW_CMD_GAME_KEYVAL_ADD   =  57, 
00114         MW_CMD_GAME_REQUEST      =  58, 
00115         MW_CMD_ERROR             = 255  
00116 };
00117 
00119 enum PACKED mw_security {
00120         MW_SEC_OPEN = 0,        
00121         MW_SEC_WEP,             
00122         MW_SEC_WPA_PSK,         
00123         MW_SEC_WPA2_PSK,        
00124         MW_SEC_WPA_WPA2_PSK,    
00125         MW_SEC_UNKNOWN          
00126 };
00127 
00129 enum PACKED mw_phy_type {
00130         MW_PHY_11B = 1,         
00131         MW_PHY_11BG = 3,        
00132         MW_PHY_11BGN = 7        
00133 };
00134 
00136 union ip_addr {
00137         uint32_t addr;          
00138         uint8_t byte[4];        
00139 };
00140 
00142 struct mw_msg_in_addr {
00143         char dst_port[6];       
00144         char src_port[6];       
00145         uint8_t channel;        
00146 
00147         char dst_addr[];
00148 };
00149 
00151 struct mw_ip_cfg {
00152         union ip_addr addr;     
00153         union ip_addr mask;     
00154         union ip_addr gateway;  
00155         union ip_addr dns1;     
00156         union ip_addr dns2;     
00157 };
00158 
00162 //           string will not be NULL terminated.
00163 struct mw_msg_ap_cfg {
00164         uint8_t cfg_num;                
00165         enum mw_phy_type phy_type;      
00166         char ssid[MW_SSID_MAXLEN];      
00167         char pass[MW_PASS_MAXLEN];      
00168 };
00169 
00171 struct mw_msg_ip_cfg {
00172         uint8_t cfg_slot;       
00173         uint8_t reserved[3];    
00174         struct mw_ip_cfg ip;    
00175 };
00176 
00178 struct mw_msg_sntp_cfg {
00179         uint16_t up_delay;      
00180         int8_t tz;              
00181         uint8_t dst;            
00182 
00183 
00184         char servers[MW_CMD_MAX_BUFLEN - 4];
00185 };
00186 
00188 struct mw_msg_date_time {
00189         uint32_t dt_bin[2];     
00190 
00191         char dt_str[MW_CMD_MAX_BUFLEN - 2 * sizeof(uint32_t)];
00192 };
00193 
00195 struct mw_msg_flash_data {
00196         uint32_t addr;          
00197 
00198         uint8_t data[MW_CMD_MAX_BUFLEN - sizeof(uint32_t)];
00199 };
00200 
00202 struct mw_msg_flash_range {
00203         uint32_t addr;          
00204         uint16_t len;           
00205 };
00206 
00208 struct mw_msg_bind {
00209         uint32_t reserved;      
00210         uint16_t port;          
00211         uint8_t  channel;       
00212 };
00213 
00215 struct mw_wifi_adv_cfg {
00216         uint8_t qos_enable;                     
00217         uint8_t ampdu_rx_enable;                
00218         uint8_t rx_ba_win;                      
00219         uint8_t rx_ampdu_buf_num;               
00220         uint32_t rx_ampdu_buf_len;              
00221         uint32_t rx_max_single_pkt_len;         
00222         uint32_t rx_buf_len;                    
00223         uint8_t amsdu_rx_enable;                
00224         uint8_t rx_buf_num;                     
00225         uint8_t rx_pkt_num;                     
00226         uint8_t left_continuous_rx_buf_num;     
00227         uint8_t tx_buf_num;                     
00228         uint8_t reserved[3];                    
00229 };
00230 
00232 struct mw_gamertag {
00234         int id;
00236         char nickname[MW_GT_NICKNAME_MAX];
00238         char security[MW_GT_SECURITY_MAX];
00240         char tagline[MW_GT_TAGLINE_MAX];
00242         char tg_token[MW_GT_TG_TOKEN_MAX];
00244         uint8_t avatar_tiles[MW_GT_AVATAR_WIDTH * MW_GT_AVATAR_HEIGHT / 2];
00246         uint8_t avatar_pal[32];
00247 };
00248 
00250 struct mw_gamertag_set_msg {
00251         uint8_t slot;                   
00252         uint8_t reserved[3];            
00253         struct mw_gamertag gamertag;    
00254 };
00255 
00257 enum mw_state {
00258         MW_ST_INIT = 0,         
00259         MW_ST_IDLE,             
00260         MW_ST_AP_JOIN,          
00261         MW_ST_SCAN,             
00262         MW_ST_READY,            
00263         MW_ST_TRANSPARENT,      
00264         MW_ST_MAX               
00265 };
00266 
00268 enum mw_sock_stat {
00269         MW_SOCK_NONE = 0,       
00270         MW_SOCK_TCP_LISTEN,     
00271         MW_SOCK_TCP_EST,        
00272         MW_SOCK_UDP_READY       
00273 };
00274 
00276 union mw_msg_sys_stat {
00277         uint32_t st_flags;              
00278         struct {
00279 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
00280                 enum mw_state sys_stat:8;       
00281                 uint8_t online:1;       
00282                 uint8_t cfg_ok:1;       
00283                 uint8_t dt_ok:1;        
00284                 uint8_t cfg:2;          
00285                 uint16_t reserved:3;    
00286                 uint16_t ch_ev:16;      
00287 #else
00288                 uint16_t ch_ev:16;      
00289                 uint16_t reserved:3;    
00290                 uint8_t cfg:2;          
00291                 uint8_t dt_ok:1;        
00292                 uint8_t cfg_ok:1;       
00293                 uint8_t online:1;       
00294                 enum mw_state sys_stat:8;       
00295 #endif
00296         };
00297 };
00298 
00300 struct mw_flash_id {
00301         uint16_t device;        
00302         uint8_t manufacturer;   
00303 };
00304 
00306 struct mw_ga_request {
00307         uint8_t method;         
00308         uint8_t num_paths;      
00309         uint8_t num_kv_pairs;   
00310         char req[];             
00311 };
00312 
00314 typedef union mw_cmd {
00315         char packet[MW_CMD_MAX_BUFLEN + 2 * sizeof(uint16_t)];  
00316         struct {
00317                 uint16_t cmd;                   
00318                 uint16_t data_len;              
00319                 // If datalen is nonzero, additional command data goes here until
00320                 // filling datalen bytes.
00321                 union {
00322                         uint8_t ch;             
00323 
00324                         uint8_t data[MW_CMD_MAX_BUFLEN];
00326                         uint16_t w_data[MW_CMD_MAX_BUFLEN / sizeof(uint16_t)];
00328                         uint32_t dw_data[MW_CMD_MAX_BUFLEN / sizeof(uint32_t)];
00329                         struct mw_msg_in_addr in_addr;          
00330                         struct mw_msg_ap_cfg ap_cfg;            
00331                         struct mw_msg_ip_cfg ip_cfg;            
00332                         struct mw_msg_sntp_cfg sntp_cfg;        
00333                         struct mw_msg_date_time date_time;      
00334                         struct mw_msg_flash_data fl_data;       
00335                         struct mw_msg_flash_range fl_range;     
00336                         struct mw_msg_bind bind;                
00337                         union mw_msg_sys_stat sys_stat;         
00338                         struct mw_gamertag_set_msg gamertag_set;
00339                         struct mw_gamertag gamertag_get;        
00340                         struct mw_wifi_adv_cfg wifi_adv_cfg;    
00341                         struct mw_flash_id flash_id;            
00342                         struct mw_ga_request ga_request;        
00343                         uint16_t fl_sect;       
00344                         uint32_t fl_id;         
00345                         uint16_t rnd_len;       
00346                 };
00347         };
00348 } mw_cmd;
00349 
00356 struct mw_reuse_payload {
00357         uint32_t remote_ip;     
00358         uint16_t remote_port;   
00359 
00360         char payload[MW_CMD_MAX_BUFLEN - 4 - 2];
00361 };
00362 
00363 #endif // MODULE_MEGAWIFI
00364 
00365 #endif //_MW_MSG_H_
00366 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines