1 /*---------------------------------------------------------------------------* 2 Project: TwlSDK - WM - demos - wmDEMOlib 3 File: wm_lib.h 4 5 Copyright 2006-2008 Nintendo. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Date:: 2008-09-18#$ 14 $Rev: 8573 $ 15 $Author: okubata_ryoma $ 16 *---------------------------------------------------------------------------*/ 17 18 #ifndef WMDEMOLIB_WM_LIB_H_ 19 #define WMDEMOLIB_WM_LIB_H_ 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 /*===========================================================================*/ 26 27 /* wm_lib.h */ 28 #ifdef SDK_TWL 29 #include <twl.h> 30 #else 31 #include <nitro.h> 32 #endif 33 34 #include <nitro/wm/common/wm.h> 35 36 #define WM_MODE_MP_PARENT 1 37 #define WM_MODE_MP_CHILD 2 38 #define WM_MODE_INFRASTRUCTURE 3 39 40 #define WM_DMA_NO 2 41 42 #define WM_PORT_KEYSHARING 15 43 44 #define WM_TYPE_CHILD_CONNECTED 0 45 #define WM_TYPE_CHILD_DISCONNECTED 1 46 #define WM_TYPE_MP_PARENT_SENT 2 47 #define WM_TYPE_MP_PARENT_RECV 3 48 #define WM_TYPE_PARENT_FOUND 4 49 #define WM_TYPE_PARENT_NOT_FOUND 5 50 #define WM_TYPE_CONNECTED_TO_PARENT 6 51 #define WM_TYPE_DISCONNECTED 7 52 #define WM_TYPE_MP_CHILD_SENT 8 53 #define WM_TYPE_MP_CHILD_RECV 9 54 #define WM_TYPE_DISCONNECTED_FROM_PARENT 10 55 #define WM_TYPE_CONNECT_FAILED 11 56 #define WM_TYPE_DCF_CHILD_SENT 12 57 #define WM_TYPE_DCF_CHILD_SENT_ERR 13 58 #define WM_TYPE_DCF_CHILD_RECV 14 59 #define WM_TYPE_DISCONNECT_COMPLETE 15 60 #define WM_TYPE_DISCONNECT_FAILED 16 61 #define WM_TYPE_END_COMPLETE 17 62 #define WM_TYPE_MP_CHILD_SENT_ERR 18 63 #define WM_TYPE_MP_PARENT_SENT_ERR 19 64 #define WM_TYPE_MP_STARTED 20 65 #define WM_TYPE_INIT_COMPLETE 21 66 #define WM_TYPE_END_MP_COMPLETE 22 67 #define WM_TYPE_SET_GAMEINFO_COMPLETE 23 68 #define WM_TYPE_SET_GAMEINFO_FAILED 24 69 #define WM_TYPE_MP_SEND_ENABLE 25 70 #define WM_TYPE_PARENT_STARTED 26 71 #define WM_TYPE_BEACON_LOST 27 72 #define WM_TYPE_BEACON_SENT 28 73 #define WM_TYPE_BEACON_RECV 29 74 #define WM_TYPE_MP_SEND_DISABLE 30 75 #define WM_TYPE_DISASSOCIATE 31 76 #define WM_TYPE_REASSOCIATE 32 77 #define WM_TYPE_AUTHENTICATE 33 78 #define WM_TYPE_SET_LIFETIME 34 79 #define WM_TYPE_DCF_STARTED 35 80 #define WM_TYPE_DCF_SENT 36 81 #define WM_TYPE_DCF_SENT_ERR 37 82 #define WM_TYPE_DCF_RECV 38 83 #define WM_TYPE_DCF_END 39 84 #define WM_TYPE_MPACK_IND 40 85 #define WM_TYPE_MP_CHILD_SENT_TIMEOUT 41 86 #define WM_TYPE_SEND_QUEUE_FULL_ERR 42 87 88 #define WM_TYPE_API_ERROR 255 // Error on the value returned from an API call 89 #define WM_TYPE_ERROR 256 // Error on callback 90 91 92 #define WL_HEADER_LENGTH_P 48 // WL header length when the parent receives 93 #define WM_HEADER_LENGTH (2+4) // WM Header length 94 #define WL_HEADER_LENGTH_T 8 // Total WL header length 95 #define WL_HEADER_LENGTH_C 8 // WL header length of each child's data 96 97 // Macro; computes the size of the child receive buffer 98 #define WM_CalcChildSendBufSize(_pInfo_) (u16)(WM_SIZE_MP_CHILD_SEND_BUFFER(((WMgameInfo *)(&(((WMbssDesc*)(_pInfo_))->gameInfo)))->childMaxSize, TRUE)) 99 #define WM_CalcChildRecvBufSize(_pInfo_) (u16)(WM_SIZE_MP_CHILD_RECEIVE_BUFFER(((WMgameInfo *)(&(((WMbssDesc*)(_pInfo_))->gameInfo)))->parentMaxSize, TRUE)) 100 101 // Macro; computes the size of the parent send and receive buffers 102 #define WM_CalcParentSendBufSize(_libParam_) (u16)(WM_SIZE_MP_PARENT_SEND_BUFFER(((WM_lib_param*)(&(_libParam_)))->parentParam->parentMaxSize, TRUE)) 103 #define WM_CalcParentRecvBufSize(_libParam_) (u16)(WM_SIZE_MP_PARENT_RECEIVE_BUFFER(((WM_lib_param*)(&(_libParam_)))->parentParam->childMaxSize, WM_NUM_MAX_CHILD, TRUE)) 104 105 106 typedef void (*WMcallbackFunc2) (u16 type, void *arg); // WM callback type (Part 2) 107 108 // wm_lib parameter structure 109 typedef struct 110 { 111 void *wmBuf; // WM system buffer 112 WMpparam *parentParam; // Parent information settings (used by the parent) 113 WMbssDesc *parentInfoBuf; // Buffer for getting parent information (used by the child) 114 u16 *sendBuf; // Send buffer 115 u16 *recvBuf; // MP receive buffer 116 WMdcfRecvBuf *dcfBuf; // DCF receive buffer 117 WMstatus *statusBuf; // Buffer for getting status (this should be deleted, if possible) 118 WMcallbackFunc2 callback; // Callback for WM_lib 119 WMbssDesc *pInfo; // Pointer to information for the connected parent (used by the child) 120 u16 sendBufSize; // Size of send buffer 121 u16 recvBufSize; // Size of MP Receive buffer 122 u16 dcfBufSize; // DCF receive buffer size 123 u16 mode; // WM_MODE_*** 124 u16 endReq; 125 u16 mpStarted; // Flag indicating that MP has started 126 u16 mpBusy; // MP transmit request flag 127 u16 child_bitmap; // Child connection state 128 u16 parentInfoBufSize; // Size of the buffer that gets the parent information (used by StartScanEx) 129 130 // KeySharing function 131 u16 keySharing; // KeySharing execution flag (1: Run KS, 0: Do not run KS) 132 WMkeySetBuf *ksBuf; // KeySharing buffer 133 134 // Related to continuous sends 135 u16 contSend; // Flag indicating execution of continuous transmission (1: Continuous transmission, 0: Per-frame communication) 136 137 // wep related 138 u16 wepMode; // WEPmode used for connection 139 u16 wepKeyId; // ID of WEPKey used for connection 140 u8 wepKey[80]; // WEPkey used for connection 141 142 // Connection authentication related 143 u16 authMode; // WM_AUTHMODE_OPEN_SYSTEM or WM_AUTHMODE_SHARED_KEY 144 145 // Related to gameinfo 146 u8 *uname; // UserName 147 u8 *gname; // GameName 148 u16 currentTgid; // TGID of the connected parent (checked with BeaconRecv.Ind) 149 150 // user gameinfo related 151 u16 userGameInfoLength; // Length of user area 152 u16 *userGameInfo; // Pointer to user area buffer 153 154 // MP resend related 155 BOOL no_retry; // Resend processing execution flag (FALSE: Resend, TRUE: No resend) 156 157 // Related to ScanEx 158 BOOL scanExFlag; // Set to TRUE when using ScanEx 159 160 u32 ggidFilter; // GGID filtering (everything passes through when 0xffffffff) 161 162 // u16 rsv1; // for 4byte padding 163 } 164 WM_lib_param; 165 166 //----------------------------------- 167 // WM_lib_Init() 168 int WM_lib_Init(WM_lib_param * para); // WM_lib initialization 169 170 //----------------------------------- 171 // WM_lib_SetMPData() 172 int WM_lib_SetMPData(u16 *data, u16 size); // MP data transmission 173 174 //----------------------------------- 175 // WM_lib_SetMPDataEX() 176 int WM_lib_SetMPDataEX(u16 *data, u16 size, u16 pollbitmap); 177 // Send MP data (support for pollbitmap) 178 179 //----------------------------------- 180 // WM_lib_End() 181 int WM_lib_End(void); // Request termination of parent mode 182 183 //----------------------------------- 184 // WM_lib_ConnectToParent() 185 int WM_lib_ConnectToParent(WMbssDesc *pInfo); // Request connection to parent 186 187 //----------------------------------- 188 // WM_lib_SetDCFData() 189 int WM_lib_SetDCFData(const u8 *destAdr, u16 *data, u16 size); // DCF data transmission 190 191 //----------------------------------- 192 // WM_lib_SetGameInfo() 193 int WM_lib_SetGameInfo(u16 *userGameInfo, u16 size, u32 ggid, u16 tgid); 194 195 //----------------------------------- 196 // WM_lib_Disconnect() 197 int WM_lib_Disconnect(u16 aid); // Disconnect child (aid) from parent 198 199 200 //----------------------------------- 201 // WM_lib_CheckMPSend() 202 BOOL WM_lib_CheckMPSend(void); // Check MP transmit permission 203 204 205 //----------------------------------- 206 // WM_lib_GetKeySet() 207 int WM_lib_GetKeySet(WMkeySet *keySet); 208 209 //----------------------------------- 210 // WM_lib_set_auto() 211 void WM_lib_set_auto(BOOL flag); // Automatically register both parent and child 212 213 //----------------------------------- 214 // WM_lib_set_bssid() 215 void WM_lib_set_bssid(u16 bssid0, u16 bssid1, u16 bssid2); // BssId setting 216 217 //----------------------------------- 218 // WM_lib_CurrentScanChannel() 219 220 void WM_lib_set_mp_dcf_parallel(BOOL flag); 221 void WM_lib_set_no_retry_flag(BOOL flag); 222 223 //----------------------------------- 224 // Functions for setting and getting parameters for Scan 225 void WM_lib_set_max_scan_time(u16 time); // Set continuous Scan time 226 u16 WM_lib_get_max_scan_time(void); // Get continuous Scan time 227 void WM_lib_set_scan_channel_seek(BOOL flag); // Channel seek configuration 228 void WM_lib_set_channel(u16 channel); // Channel configuration 229 u16 WM_lib_CurrentScanChannel(void); // Return channel currently being scanning 230 void WM_lib_set_scanBssid(u8 *bssid); // BSSID filtering 231 232 //----------------------------------- 233 // Functions for setting and getting parameters for ScanEx 234 void WM_lib_set_scanEx_maxChannelTime(u16 time); // Configure maxChannelTime 235 u16 WM_lib_get_scanEx_maxChannelTime(void); // Get maxChannelTime 236 void WM_lib_set_scanEx_channelList(u16 channel); // Configure channelList(bitmap) 237 u16 WM_lib_get_scanEx_channelList(void); // Get channelList(bitmap) 238 void WM_lib_set_scanEx_scanType(u16 scanType); // ScanType configuration WM_SCANTYPE_ACTIVE(0), WM_SCANTYPE_PASSIVE(1) 239 u16 WM_lib_get_scanEx_scanType(void); // Get ScanType WM_SCANTYPE_ACTIVE(0), WM_SCANTYPE_PASSIVE(1) 240 void WM_lib_set_scanEx_ssidLength(u16 ssidLength); // Configure SSID length for SSID filtering 241 void WM_lib_set_scanEx_ssid(u8 *ssid); // SSID configuration for SSID filtering 242 void WM_lib_set_scanEx_bssid(u8 *bssid); // BSSID configuration for BSSID filtering 243 244 //----------------------------------- 245 // WM_lib_CalcRSSI() 246 u16 WM_lib_CalcRSSI(u16 rate_rssi, u16 aid); // Convert rate_rssi to RSSI value 247 248 249 /************ Start where wm_tool.h was **********************/ 250 251 252 #define WM_NUM_PARENT_INFORMATIONS 16 253 #define WM_NUM_CHILD_INFORMATIONS 15 254 255 256 typedef struct 257 { 258 u16 found_parent_count; // Number of parents found 259 u16 my_aid; // AID assigned to self 260 WMmpRecvBuf *recvBuf; // MP buffer passed with WM_StartMP() 261 u16 *sendBuf; // MP send data buffer passed with WM_SetMPData() 262 u8 MacAdrList[WM_NUM_PARENT_INFORMATIONS][6]; // For saving Parent MacAddresses (for 4 machines) 263 WMbssDesc *parentInfo[WM_NUM_PARENT_INFORMATIONS]; // BssDesc for storing Parent information (for 4 machines) and used during connection 264 u16 channelList[WM_NUM_PARENT_INFORMATIONS]; // For saving Parent channels (for 4 machines) 265 u16 ssidLength[WM_NUM_PARENT_INFORMATIONS]; // Parent SSID lengths 266 u8 ssidList[WM_NUM_PARENT_INFORMATIONS][32]; // For saving Parent SSIDs (for 4 machines) 267 u16 gameInfoLength[WM_NUM_PARENT_INFORMATIONS]; // Length of parent GameInfo 268 269 u16 find_counter[WM_NUM_PARENT_INFORMATIONS]; // Number of times a parent was found 270 271 u16 rsv[10]; 272 WMgameInfo gameInfoList[WM_NUM_PARENT_INFORMATIONS] ATTRIBUTE_ALIGN(32); // For saving parent GameInfo (for 4 machines) 273 } 274 childInfo; 275 276 277 typedef struct 278 { 279 u8 addr[6]; 280 u8 reserved[2]; // For 4 byte padding 281 } 282 MACADDRESS; 283 284 typedef struct 285 { 286 int valid; 287 MACADDRESS macaddr; 288 } 289 CHILD_INFO; 290 291 typedef void (*WM_LIB_CALLBACK) (u16 type, void *arg); 292 293 294 int wm_lib_get_last_found_parent_no(void); 295 void save_parentInfo(WMstartScanCallback *buf, WM_lib_param * param, childInfo * info); 296 void save_parentInfoEx(WMstartScanExCallback *buf, WM_lib_param * param, childInfo * info); 297 298 299 BOOL wm_lib_get_own_macaddress(MACADDRESS * ma); 300 301 302 303 304 305 /* Initialization functions */ 306 307 308 309 /* Functions planned to be deleted */ 310 void wm_lib_add_child_list(WMstartParentCallback *arg); 311 void wm_lib_delete_child_list(WMstartParentCallback *arg); 312 void wm_lib_add_parent_list(WMstartScanCallback *arg); 313 void wm_lib_add_parent_listEx(WMStartScanExCallback *arg); 314 void wm_lib_delete_parent_list(WMstartScanCallback *arg); 315 void wm_lib_parent_found_count_reset(void); 316 void wm_lib_set_my_aid(int aid); 317 318 /* Functions for both the parent and child devices */ 319 void wm_lib_comm_init(void); 320 int wm_lib_start(void); 321 const char *wm_lib_get_wlib_version(void); 322 void wm_lib_set_mode(u16 mode); 323 void wm_lib_set_recvbuffer(u8 *buf); 324 void wm_lib_set_sendbuffer(u8 *buf); 325 void wm_lib_set_callback(WM_LIB_CALLBACK callback); 326 int wm_lib_get_recvbuffer_size(void); 327 int wm_lib_get_sendbuffer_size(void); 328 void wm_lib_set_keySharing_mode(int flag); 329 void wm_lib_set_contSend_mode(int flag); 330 void wm_lib_set_multiboot_mode(int flag); 331 void wm_lib_set_ggid(u32 ggid); 332 u32 wm_lib_get_ggid(void); 333 void wm_lib_set_tgid(u16 tgid); 334 u16 wm_lib_get_tgid(void); 335 void wm_lib_set_scan_bssid(u16 bssid0, u16 bssid1, u16 bssid2); 336 337 338 /* Parent Functions */ 339 void wm_lib_set_gameinfo_gamename(char *str); 340 void wm_lib_set_gameinfo_username(char *user_name); 341 u32 wm_lib_get_parent_gameinfo_ggid(int id); 342 u16 wm_lib_get_parent_gameinfo_tgid(int id); 343 u16 *wm_lib_get_parent_gameinfo_usergameinfo(int id); 344 u16 wm_lib_get_parent_gameinfo_usergameinfosize(int id); 345 346 void wm_lib_set_parent_send_size(u16 size); 347 void wm_lib_set_parent_channel(u16 ch); 348 void wm_lib_set_beacon_period(u16 period_ms); 349 350 351 void wm_lib_set_parent_recv_size_per_child(u16 size); 352 BOOL wm_lib_get_child_macaddress(int aid, MACADDRESS * ma); 353 BOOL wm_lib_is_child_valid(int aid); 354 int wm_lib_set_gameinfo(void); 355 356 /* Child Functions */ 357 358 BOOL wm_lib_is_parent_gameinfo_valid(int id); 359 int wm_lib_get_parent_gameinfo_channel(int id); 360 int wm_lib_get_parent_gameinfo_parent_sendmaxsize(int id); 361 int wm_lib_get_parent_gameinfo_child_sendbufsize(int id); 362 int wm_lib_get_parent_gameinfo_child_recvbufsize(int id); 363 const char *wm_lib_get_parent_gameinfo_username(int id); 364 const char *wm_lib_get_parent_gameinfo_gamename(int id); 365 366 367 void *WM_lib_get_mp_parent_callback_ptr(void); 368 void *WM_lib_get_mp_child_callback_ptr(void); 369 370 371 int wm_lib_get_parent_found_count(void); 372 int wm_lib_connect_parent(int parent_no); 373 BOOL wm_lib_get_parent_macaddress(int id, MACADDRESS * ma); 374 int wm_lib_get_my_aid(void); 375 376 /* Get Keysharing Keyset */ 377 int wm_lib_get_keyset(WMkeySet *keyset); 378 int wm_lib_connect_parent_via_bssdesc(WMbssDesc *bssDesc); 379 380 void wm_lib_set_ggidFilter(u32 ggidFilter); 381 382 /* 383 Get pointer to WMbssDesc structure 384 */ 385 WMbssDesc *wm_get_parent_bssdesc(int id, WMbssDesc *bssDescp); 386 387 int wm_lib_connect_parent_via_bssdesc(WMbssDesc *bssDescp); 388 389 /************ End where wm_tool.h was **********************/ 390 391 /****************************************************/ 392 393 394 /*===========================================================================*/ 395 396 #ifdef __cplusplus 397 } /* extern "C" */ 398 #endif 399 400 #endif /* WMDEMOLIB_WM_LIB_H_ */ 401 402 /*---------------------------------------------------------------------------* 403 End of file 404 *---------------------------------------------------------------------------*/ 405