1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - WM - demos - wmDEMOlib
3   File:     wm_tool.c
4 
5   Copyright 2007-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 #ifdef SDK_TWL
19 #include <twl.h>
20 #else
21 #include <nitro.h>
22 #endif
23 
24 #include <nitro/wm.h>
25 #include "wm_lib.h"
26 
27 #define WM_BEACON_PERIOD_DEFAULT    (200)       // Default value for the Beacon interval (ms)
28 
29 
30 static WM_lib_param libParam ATTRIBUTE_ALIGN(32);       // WM_lib parameter structure
31 
32 static u8 libParam_wmbuf[WM_SYSTEM_BUF_SIZE] ATTRIBUTE_ALIGN(32);
33 static u8 libParam_statusBuf[WM_STATUS_BUF_SIZE] ATTRIBUTE_ALIGN(32);
34 static u8 libParam_parentParam[WM_PARENT_PARAM_SIZE] ATTRIBUTE_ALIGN(32);
35 
36 static u8 libParam_dcfBuf[WM_DCF_MAX_SIZE * 2] ATTRIBUTE_ALIGN(32);
37 
38 static u8 libParam_parentInfoBuf[WM_BSS_DESC_SIZE] ATTRIBUTE_ALIGN(32);
39 static u8 my_parentInfo[WM_NUM_PARENT_INFORMATIONS][WM_BSS_DESC_SIZE] ATTRIBUTE_ALIGN(32);
40 
41 static CHILD_INFO child_info[WM_NUM_CHILD_INFORMATIONS] ATTRIBUTE_ALIGN(32);
42 static childInfo ACinfo;               // Variable structure used with child mode
43 
44 static WMkeySetBuf libParam_ksbuf ATTRIBUTE_ALIGN(32);  // Keysharing buffer
45 
46 // For storing parent info (for 4 machines) used during connection
47 static u16 userGameInfoBuf[32] ATTRIBUTE_ALIGN(32);
48 
49 static u8 user_name[WM_SIZE_USERNAME] ATTRIBUTE_ALIGN(4);
50 static u8 game_name[WM_SIZE_GAMENAME] ATTRIBUTE_ALIGN(4);
51 
52 static int last_found_parent_no = -1;
53 
wm_lib_get_last_found_parent_no(void)54 int wm_lib_get_last_found_parent_no(void)
55 {
56     return last_found_parent_no;
57 }
58 
59 //--------------------------------------------------------------
60 // Store the parent information obtained with scan
save_parentInfo(WMstartScanCallback * buf,WM_lib_param * param,childInfo * info)61 void save_parentInfo(WMstartScanCallback *buf, WM_lib_param * param, childInfo * info)
62 {
63     int     i = 0;
64 
65     // WM_lib_set_scan_channel_seek(FALSE);
66     // wm_lib_set_scan_bssid(buf->macAddress[0],buf->macAddress[1], buf->macAddress[2]);
67 
68     while (i < info->found_parent_count)
69     {
70         if (buf->macAddress[0] == info->MacAdrList[i][0] &&
71             buf->macAddress[1] == info->MacAdrList[i][1] &&
72             buf->macAddress[2] == info->MacAdrList[i][2] &&
73             buf->macAddress[3] == info->MacAdrList[i][3] &&
74             buf->macAddress[4] == info->MacAdrList[i][4] &&
75             buf->macAddress[5] == info->MacAdrList[i][5])
76         {
77 
78             ++info->find_counter[i];   // Increment the number of times found
79 
80             info->channelList[i] = buf->channel;        // Update channel information
81             info->gameInfoLength[i] = buf->gameInfoLength;
82             info->gameInfoList[i] = buf->gameInfo;
83             DC_InvalidateRange(info->parentInfo[i], WM_BSS_DESC_SIZE);  // Invalidate cache
84             MI_DmaCopy16(WM_DMA_NO,    // DMA number
85                          param->parentInfoBuf,  // src
86                          info->parentInfo[i],   // dest
87                          WM_BSS_DESC_SIZE       // Size of the transmission
88                 );
89             last_found_parent_no = i;
90             return;
91         }
92         i++;
93     }
94 
95     if (i >= WM_NUM_PARENT_INFORMATIONS)
96     {
97         return;                        /* When the registration limitations have been exceeded */
98     }
99 
100     // Check to see if it is the designated GGID
101     if (param->ggidFilter != 0xffffffff)
102     {
103         if (buf->gameInfoLength == 0 || buf->gameInfo.ggid != param->ggidFilter)
104             return;
105     }
106 
107     info->found_parent_count = (u16)(i + 1);
108 
109 
110     // Newly discovered parent, so store data
111     info->MacAdrList[i][0] = buf->macAddress[0];
112     info->MacAdrList[i][1] = buf->macAddress[1];
113     info->MacAdrList[i][2] = buf->macAddress[2];
114     info->MacAdrList[i][3] = buf->macAddress[3];
115     info->MacAdrList[i][4] = buf->macAddress[4];
116     info->MacAdrList[i][5] = buf->macAddress[5];
117     info->channelList[i] = buf->channel;
118     info->ssidLength[i] = buf->ssidLength;
119 
120     MI_CpuCopy8(buf->ssid, info->ssidList[i], 32);
121     //    for(j = 0; j < 16; j++ )
122     //        info->ssidList[i][j]       = buf->ssid[j];
123     info->gameInfoLength[i] = buf->gameInfoLength;
124     info->gameInfoList[i] = buf->gameInfo;
125 
126     DC_InvalidateRange(info->parentInfo[i], WM_BSS_DESC_SIZE);  // Invalidate cache
127 
128     MI_DmaCopy16(WM_DMA_NO,            // DMA number
129                  param->parentInfoBuf, // src
130                  info->parentInfo[i],  // dest
131                  WM_BSS_DESC_SIZE      // Size of the transmission
132         );
133     last_found_parent_no = i;
134 }
135 
136 //--------------------------------------------------------------
137 // Store the parent information obtained with scan
save_parentInfoEx(WMstartScanExCallback * buf,WM_lib_param * param,childInfo * info)138 void save_parentInfoEx(WMstartScanExCallback *buf, WM_lib_param * param, childInfo * info)
139 {
140     int     i, j, k;
141 
142     WMBssDesc *bssDesc;
143     u16     bssDescLength;
144     // WMOtherElements elems;   // To test the acquisition of otherElement
145 
146     // Invalidate cache for parent information storage buffer
147     DC_InvalidateRange(param->parentInfoBuf, WM_SIZE_SCAN_EX_BUF);
148 
149     // Loop as many times as the number of parents that were found this time
150     for (k = 0; k < buf->bssDescCount; ++k)
151     {
152         // Get parent information start address from callback
153         bssDesc = buf->bssDesc[k];
154 
155         // Test the getting of otherElement
156         //elems = WM_GetOtherElements( bssDesc );
157 
158         i = 0;
159         while (1)
160         {
161             // bssDesc length is in 16-bit units. Convert to byte lengths.
162             bssDescLength = (u16)(bssDesc->length * 2);
163 
164             // Check whether this is a parent that has already been found
165             if (i < info->found_parent_count)
166             {
167                 if (bssDesc->bssid[0] == info->MacAdrList[i][0] &&
168                     bssDesc->bssid[1] == info->MacAdrList[i][1] &&
169                     bssDesc->bssid[2] == info->MacAdrList[i][2] &&
170                     bssDesc->bssid[3] == info->MacAdrList[i][3] &&
171                     bssDesc->bssid[4] == info->MacAdrList[i][4] &&
172                     bssDesc->bssid[5] == info->MacAdrList[i][5])
173                 {
174                     ++info->find_counter[i];    // Increment the number of times found
175 
176                     info->channelList[i] = bssDesc->channel;    // Update channel information
177                     info->gameInfoLength[i] = bssDesc->gameInfoLength;
178 
179                     if (info->gameInfoLength[i] != 0)
180                     {
181                         MI_CpuCopy16((u16 *)&(bssDesc->gameInfo),
182                                      (u16 *)&(info->gameInfoList[i]), info->gameInfoLength[i]);
183                     }
184                     MI_DmaCopy16(WM_DMA_NO,     // DMA number
185                                  bssDesc,       // src
186                                  info->parentInfo[i],   // dest
187                                  bssDescLength  // Size of the transmission
188                         );
189 
190                     break;             // Move to next parent information check
191                 }
192             }
193             else
194             {
195                 // Do nothing and exit if the parent information list is entirely full
196                 if (i == WM_NUM_PARENT_INFORMATIONS - 1)
197                     break;
198 
199                 // Check to see if it is the designated GGID
200                 if (param->ggidFilter != 0xffffffff)
201                 {
202                     if (bssDesc->gameInfoLength == 0 || bssDesc->gameInfo.ggid != param->ggidFilter)
203                         break;
204                 }
205 
206                 if (i == info->found_parent_count)
207                 {
208                     // This is a newly found parent. Therefore add to parent information list.
209                     info->found_parent_count = (u16)(i + 1);
210 
211                     info->MacAdrList[i][0] = bssDesc->bssid[0];
212                     info->MacAdrList[i][1] = bssDesc->bssid[1];
213                     info->MacAdrList[i][2] = bssDesc->bssid[2];
214                     info->MacAdrList[i][3] = bssDesc->bssid[3];
215                     info->MacAdrList[i][4] = bssDesc->bssid[4];
216                     info->MacAdrList[i][5] = bssDesc->bssid[5];
217 
218                     info->channelList[i] = bssDesc->channel;
219                     info->ssidLength[i] = bssDesc->ssidLength;
220                     for (j = 0; j < 16; j++)
221                         info->ssidList[i][j] = bssDesc->ssid[j];
222                     info->gameInfoLength[i] = bssDesc->gameInfoLength;
223 
224                     if (info->gameInfoLength[i] != 0)
225                     {
226                         MI_CpuCopy16((u16 *)&(bssDesc->gameInfo),
227                                      (u16 *)&(info->gameInfoList[i]), info->gameInfoLength[i]);
228                     }
229 
230                     MI_DmaCopy16(WM_DMA_NO,     // DMA number
231                                  bssDesc,       // src
232                                  info->parentInfo[i],   // dest
233                                  bssDescLength  // Size of the transmission
234                         );
235 
236                     break;             // Move to next parent information check
237                 }
238             }
239             ++i;
240         }
241     }
242 }
243 
wm_lib_comm_init(void)244 void wm_lib_comm_init(void)
245 {
246     int     i;
247 
248     WM_lib_set_auto(TRUE);
249 
250     MI_DmaClear32(WM_DMA_NO, &libParam, sizeof(libParam));
251     MI_DmaClear32(WM_DMA_NO, libParam_statusBuf, WM_STATUS_BUF_SIZE);
252     MI_DmaClear32(WM_DMA_NO, libParam_wmbuf, WM_SYSTEM_BUF_SIZE);
253     MI_DmaClear32(WM_DMA_NO, libParam_parentParam, WM_PARENT_PARAM_SIZE);
254     MI_DmaClear32(WM_DMA_NO, libParam_parentInfoBuf, WM_BSS_DESC_SIZE);
255     MI_DmaClear32(WM_DMA_NO, my_parentInfo, sizeof(my_parentInfo));
256     MI_DmaClear32(WM_DMA_NO, child_info, sizeof(child_info));
257     MI_DmaClear32(WM_DMA_NO, &ACinfo, sizeof(ACinfo));
258     MI_DmaClear32(WM_DMA_NO, &libParam_ksbuf, sizeof(libParam_ksbuf));
259 
260     libParam.statusBuf = (WMstatus *)&libParam_statusBuf;
261     libParam.wmBuf = (void *)&libParam_wmbuf;
262     libParam.parentParam = (WMpparam *)&libParam_parentParam;
263     libParam.parentInfoBuf = (WMbssDesc *)&libParam_parentInfoBuf;
264 
265     libParam.dcfBufSize = WM_DCF_MAX_SIZE;
266     libParam.dcfBuf = (WMdcfRecvBuf *)libParam_dcfBuf;
267 
268     libParam.wepMode = WM_WEPMODE_NO;  /* WM_WEPMODE_40 */
269 
270     libParam.keySharing = 0;
271     libParam.contSend = 0;             // 1 -> continuous send
272 
273     libParam.parentParam->KS_Flag = libParam.keySharing;
274     libParam.parentParam->CS_Flag = libParam.contSend;
275 
276 
277     /*
278        OS_Printf("parentParam = %d %d\n",sizeof(WMpparam), WM_PARENT_PARAM_SIZE);
279        OS_Printf("parentInfoBuf = %d %d\n",sizeof(WMbssDesc), WM_BSS_DESC_SIZE);
280        OS_Printf("wmstatus = %d %d\n",sizeof(WMstatus), WM_STATUS_BUF_SIZE);
281      */
282 
283     // Set the parent information (information obtained by a child when scanning)
284     libParam.parentParam->ggid = 0x003fff12;
285     libParam.parentParam->tgid = 123;  // Plan to use a random value
286     libParam.parentParam->entryFlag = 1;        // Allow child entry
287     libParam.parentParam->multiBootFlag = 0;    // Do not allow multiboot
288 
289     libParam.parentParam->beaconPeriod = WM_GetDispersionBeaconPeriod();        // Default value for the Beacon interval (ms)
290     libParam.parentParam->maxEntry = 15;
291 
292 
293 //  userGameInfoBuf[0] = 0x1111;        // Test
294 //  userGameInfoBuf[1] = 0x2222;
295 //  userGameInfoBuf[2] = 0x3333;
296 //  userGameInfoBuf[3] = 0x4444;
297 
298     libParam.parentParam->userGameInfo = userGameInfoBuf;
299     libParam.parentParam->userGameInfoLength = 32;
300 
301     libParam.sendBufSize = 0;
302     libParam.recvBufSize = 0;
303 
304     for (i = 0; i < WM_NUM_CHILD_INFORMATIONS; i++)
305     {
306         child_info[i].valid = 0;
307     }
308 
309     wm_lib_parent_found_count_reset();
310     for (i = 0; i < WM_NUM_PARENT_INFORMATIONS; i++)
311     {
312         ACinfo.parentInfo[i] = (WMbssDesc *)&(my_parentInfo[i][0]);
313         ACinfo.MacAdrList[i][0] = 0;
314         ACinfo.MacAdrList[i][1] = 0;
315         ACinfo.MacAdrList[i][2] = 0;
316         ACinfo.MacAdrList[i][3] = 0;
317         ACinfo.MacAdrList[i][4] = 0;
318         ACinfo.MacAdrList[i][5] = 0;
319     }
320     ACinfo.my_aid = (u16)0;
321 
322 }
323 
wm_lib_set_callback(WMcallbackFunc2 callback)324 void wm_lib_set_callback(WMcallbackFunc2 callback)
325 {
326     libParam.callback = callback;
327 }
328 
329 
wm_lib_set_parent_send_size(u16 size)330 void wm_lib_set_parent_send_size(u16 size)
331 {
332     libParam.parentParam->parentMaxSize = size; // Parent maximum transmission size (in bytes)
333     //  libParam.sendBufSize =  size;                //  Buffer length
334     libParam.sendBufSize = WM_CalcParentSendBufSize(libParam);
335 
336 }
337 
wm_lib_set_parent_recv_size_per_child(u16 size)338 void wm_lib_set_parent_recv_size_per_child(u16 size)
339 {
340     libParam.parentParam->childMaxSize = size;  // Child maximum transmission size (in bytes)
341     libParam.recvBufSize = WM_CalcParentRecvBufSize(libParam);
342 }
343 
344 
wm_lib_set_keySharing_mode(int flag)345 void wm_lib_set_keySharing_mode(int flag)
346 {
347     libParam.keySharing = (u16)flag;   // Will be deleted
348     libParam.parentParam->KS_Flag = (u16)flag;
349     libParam.ksBuf = &libParam_ksbuf;
350 }
351 
352 
wm_lib_set_contSend_mode(int flag)353 void wm_lib_set_contSend_mode(int flag)
354 {
355     libParam.contSend = (u16)flag;     // Will be deleted
356     libParam.parentParam->CS_Flag = (u16)flag;
357 }
358 
359 
wm_lib_set_multiboot_mode(int flag)360 void wm_lib_set_multiboot_mode(int flag)
361 {
362     libParam.parentParam->multiBootFlag = (u16)flag;
363 }
364 
wm_lib_set_parent_channel(u16 ch)365 void wm_lib_set_parent_channel(u16 ch)
366 {
367     libParam.parentParam->channel = ch;
368 }
369 
wm_lib_set_beacon_period(u16 period_ms)370 void wm_lib_set_beacon_period(u16 period_ms)
371 {
372     libParam.parentParam->beaconPeriod = period_ms;
373 }
374 
375 #define WM_LIB_GGID_LO_MASK     (0x0000ffff)
376 #define WM_LIB_GGID_HI_MASK     (0xffff0000)
377 #define WM_LIB_GGID_HI_SHIFT    (16)
378 
wm_lib_set_ggid(u32 ggid)379 void wm_lib_set_ggid(u32 ggid)
380 {
381     libParam.parentParam->ggid = ggid;
382 }
383 
wm_lib_get_ggid(void)384 u32 wm_lib_get_ggid(void)
385 {
386     return libParam.parentParam->ggid;
387 }
388 
wm_lib_set_tgid(u16 tgid)389 void wm_lib_set_tgid(u16 tgid)
390 {
391     libParam.parentParam->tgid = tgid;
392 }
393 
wm_lib_get_tgid(void)394 u16 wm_lib_get_tgid(void)
395 {
396     return libParam.parentParam->tgid;
397 }
398 
wm_lib_set_scan_bssid(u16 bssid0,u16 bssid1,u16 bssid2)399 void wm_lib_set_scan_bssid(u16 bssid0, u16 bssid1, u16 bssid2)
400 {
401     WM_lib_set_bssid(bssid2, bssid1, bssid0);
402 }
403 
wm_lib_set_gameinfo_username(char * name)404 void wm_lib_set_gameinfo_username(char *name)
405 {
406     int     i;
407     char   *c = (char *)user_name;
408     for (i = 0; i < WM_SIZE_USERNAME; i++)
409     {
410         if (*name == 0)
411         {
412             break;
413         }
414         *c++ = *name++;
415     }
416     libParam.uname = user_name;
417 }
418 
wm_lib_set_gameinfo_gamename(char * game)419 void wm_lib_set_gameinfo_gamename(char *game)
420 {
421     int     i;
422     char   *c = (char *)game_name;
423     for (i = 0; i < WM_SIZE_GAMENAME; i++)
424     {
425         if (*game == 0)
426         {
427             break;
428         }
429         *c++ = *game++;
430     }
431     libParam.gname = game_name;
432 }
433 
434 
wm_lib_set_mode(u16 mode)435 void wm_lib_set_mode(u16 mode)
436 {
437     libParam.mode = mode;
438 }
439 
wm_lib_set_sendbuffer(u8 * buf)440 void wm_lib_set_sendbuffer(u8 *buf)
441 {
442     libParam.sendBuf = (u16 *)buf;
443 }
444 
wm_lib_set_recvbuffer(u8 * buf)445 void wm_lib_set_recvbuffer(u8 *buf)
446 {
447     libParam.recvBuf = (u16 *)buf;
448 }
449 
wm_lib_get_recvbuffer_size(void)450 int wm_lib_get_recvbuffer_size(void)
451 {
452     return (int)libParam.recvBufSize;
453 }
454 
wm_lib_get_sendbuffer_size(void)455 int wm_lib_get_sendbuffer_size(void)
456 {
457     return (int)libParam.sendBufSize;
458 }
459 
wm_lib_get_wlib_version(void)460 const char *wm_lib_get_wlib_version(void)
461 {
462     return (const char *)(libParam.statusBuf->wlVersion);
463 }
464 
wm_lib_set_ggidFilter(u32 ggidFilter)465 void wm_lib_set_ggidFilter(u32 ggidFilter)
466 {
467     libParam.ggidFilter = ggidFilter;
468 }
469 
470 
wm_lib_start(void)471 int wm_lib_start(void)
472 {
473     int     errcode;
474 
475     errcode = WM_lib_Init(&libParam);  // WM_lib initialization
476 
477     return errcode;
478 }
479 
480 
wm_lib_get_own_macaddress(MACADDRESS * ma)481 BOOL wm_lib_get_own_macaddress(MACADDRESS * ma)
482 {
483     int     i;
484     (void)WM_ReadStatus(libParam.statusBuf);
485     for (i = 0; i < 6; i++)
486     {
487         ma->addr[i] = libParam.statusBuf->MacAddress[i];
488     }
489     return TRUE;
490 }
491 
492 
493 /* Parent Functions */
wm_lib_is_child_valid(int aid)494 BOOL wm_lib_is_child_valid(int aid)
495 {
496     if (child_info[aid].valid)
497         return TRUE;
498     else
499         return FALSE;
500 }
501 
502 
wm_lib_add_child_list(WMstartParentCallback * arg)503 void wm_lib_add_child_list(WMstartParentCallback *arg)
504 {
505     int     i;
506     child_info[arg->aid].valid = 1;
507     for (i = 0; i < 6; i++)
508     {
509         child_info[arg->aid].macaddr.addr[i] = arg->macAddress[i];
510     }
511 }
512 
wm_lib_delete_child_list(WMstartParentCallback * arg)513 void wm_lib_delete_child_list(WMstartParentCallback *arg)
514 {
515     child_info[arg->aid].valid = 0;
516 }
517 
wm_lib_get_child_macaddress(int aid,MACADDRESS * ma)518 BOOL wm_lib_get_child_macaddress(int aid, MACADDRESS * ma)
519 {
520     int     i;
521     for (i = 0; i < 6; i++)
522     {
523         ma->addr[i] = child_info[aid].macaddr.addr[i];
524     }
525     return TRUE;
526 }
527 
wm_lib_set_gameinfo(void)528 int wm_lib_set_gameinfo(void)
529 {
530     // Set user name and game name
531     MI_DmaCopy16(WM_DMA_NO, libParam.uname,
532                  &libParam.parentParam->userGameInfo[0], WM_SIZE_USERNAME);
533     MI_DmaCopy16(WM_DMA_NO, libParam.gname,
534                  &libParam.parentParam->userGameInfo[WM_SIZE_USERNAME / sizeof(u16)],
535                  WM_SIZE_GAMENAME);
536     return WM_lib_SetGameInfo(libParam.parentParam->userGameInfo,
537                               libParam.parentParam->userGameInfoLength,
538                               libParam.parentParam->ggid, libParam.parentParam->tgid);
539 }
540 
541 /******************************/
542 /* Child Functions */
543 
wm_lib_get_my_aid(void)544 int wm_lib_get_my_aid(void)
545 {
546     return ACinfo.my_aid;
547 }
548 
wm_lib_set_my_aid(int aid)549 void wm_lib_set_my_aid(int aid)
550 {
551     ACinfo.my_aid = (u16)aid;
552 }
553 
wm_lib_add_parent_list(WMstartScanCallback * arg)554 void wm_lib_add_parent_list(WMstartScanCallback *arg)
555 {
556     save_parentInfo(arg, &libParam, &ACinfo);
557 }
558 
wm_lib_add_parent_listEx(WMStartScanExCallback * arg)559 void wm_lib_add_parent_listEx(WMStartScanExCallback *arg)
560 {
561     save_parentInfoEx(arg, &libParam, &ACinfo);
562 }
563 
wm_lib_delete_parent_list(WMstartScanCallback * arg)564 void wm_lib_delete_parent_list(WMstartScanCallback *arg)
565 {
566 #pragma unused(arg)
567     /* Called with WM_STATECODE_PARENT_NOT_FOUND */
568     //wm_lib_set_scan_bssid(arg->macAddress[0],buf->macAddress[1], buf->macAddress[2]);
569     // WM_lib_set_scan_channel_seek(TRUE);
570     // wm_lib_set_scan_bssid(0xffff,0xffff,0xffff);
571 }
572 
wm_lib_get_parent_gameinfo_channel(int id)573 int wm_lib_get_parent_gameinfo_channel(int id)
574 {
575     return (int)(ACinfo.channelList[id]);
576 }
577 
wm_lib_is_parent_gameinfo_valid(int id)578 BOOL wm_lib_is_parent_gameinfo_valid(int id)
579 {
580     if (ACinfo.gameInfoLength[id] != 0)
581         return TRUE;
582     else
583         return FALSE;
584 }
585 
wm_lib_get_parent_gameinfo_parent_sendmaxsize(int id)586 int wm_lib_get_parent_gameinfo_parent_sendmaxsize(int id)
587 {
588     return ACinfo.gameInfoList[id].parentMaxSize;
589 }
590 
wm_lib_get_parent_gameinfo_child_sendbufsize(int id)591 int wm_lib_get_parent_gameinfo_child_sendbufsize(int id)
592 {
593     // return ACinfo.gameInfoList[id].childMaxSize;
594     return WM_CalcChildSendBufSize((ACinfo.parentInfo[id]));
595 }
596 
wm_lib_get_parent_gameinfo_child_recvbufsize(int id)597 int wm_lib_get_parent_gameinfo_child_recvbufsize(int id)
598 {
599     return WM_CalcChildRecvBufSize((ACinfo.parentInfo[id]));
600 }
601 
602 
wm_lib_get_parent_gameinfo_username(int id)603 const char *wm_lib_get_parent_gameinfo_username(int id)
604 {
605     return (const char *)(ACinfo.gameInfoList[id].old_type.userName);
606 }
607 
wm_lib_get_parent_gameinfo_gamename(int id)608 const char *wm_lib_get_parent_gameinfo_gamename(int id)
609 {
610     return (const char *)(ACinfo.gameInfoList[id].old_type.gameName);
611 }
612 
613 
wm_lib_get_parent_gameinfo_ggid(int id)614 u32 wm_lib_get_parent_gameinfo_ggid(int id)
615 {
616     return (ACinfo.gameInfoList[id].ggid);
617 }
618 
wm_lib_get_parent_gameinfo_tgid(int id)619 u16 wm_lib_get_parent_gameinfo_tgid(int id)
620 {
621     return (ACinfo.gameInfoList[id].tgid);
622 }
623 
wm_lib_get_parent_gameinfo_usergameinfo(int id)624 u16    *wm_lib_get_parent_gameinfo_usergameinfo(int id)
625 {
626     return (ACinfo.gameInfoList[id].userGameInfo);
627 }
628 
wm_lib_get_parent_gameinfo_usergameinfosize(int id)629 u16 wm_lib_get_parent_gameinfo_usergameinfosize(int id)
630 {
631     return (ACinfo.gameInfoList[id].userGameInfoLength);
632 }
633 
634 
wm_lib_get_parent_macaddress(int id,MACADDRESS * ma)635 BOOL wm_lib_get_parent_macaddress(int id, MACADDRESS * ma)
636 {
637     int     i;
638     for (i = 0; i < 6; i++)
639     {
640         ma->addr[i] = ACinfo.MacAdrList[id][i];
641     }
642     return TRUE;
643 }
644 
wm_lib_parent_found_count_reset(void)645 void wm_lib_parent_found_count_reset(void)
646 {
647     ACinfo.found_parent_count = 0;
648 }
649 
wm_lib_get_parent_found_count(void)650 int wm_lib_get_parent_found_count(void)
651 {
652     return ACinfo.found_parent_count;
653 }
654 
wm_lib_get_keyset(WMkeySet * keyset)655 int wm_lib_get_keyset(WMkeySet *keyset)
656 {
657     return WM_GetKeySet(libParam.ksBuf, keyset);
658 }
659 
wm_lib_connect_parent(int parent_no)660 int wm_lib_connect_parent(int parent_no)
661 {
662     WMbssDesc *pInfo = (ACinfo.parentInfo[parent_no]);
663     libParam.recvBufSize = (u16)wm_lib_get_parent_gameinfo_child_recvbufsize(parent_no);
664     libParam.sendBufSize = (u16)wm_lib_get_parent_gameinfo_child_sendbufsize(parent_no);
665     return WM_lib_ConnectToParent(pInfo);
666 }
667 
668 
669 //  Get pointer to WMbssDesc structure
wm_get_parent_bssdesc(int id,WMbssDesc * bssDescp)670 WMbssDesc *wm_get_parent_bssdesc(int id, WMbssDesc *bssDescp)
671 {
672 
673     if (bssDescp != NULL)
674     {
675         MI_CpuCopy16(ACinfo.parentInfo[id], bssDescp, sizeof(WMbssDesc));
676     }
677     return ACinfo.parentInfo[id];
678 
679 }
680 
wm_lib_connect_parent_via_bssdesc(WMbssDesc * bssDescp)681 int wm_lib_connect_parent_via_bssdesc(WMbssDesc *bssDescp)
682 {
683     if (bssDescp == NULL)
684         return WM_ERRCODE_FAILED;
685 
686     libParam.recvBufSize = (u16)WM_CalcChildRecvBufSize(bssDescp);
687     libParam.sendBufSize = (u16)WM_CalcChildSendBufSize(bssDescp);
688     return WM_lib_ConnectToParent(bssDescp);
689 }
690 
691 /*---------------------------------------------------------------------------*
692   End of file
693  *---------------------------------------------------------------------------*/
694