1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - MB - include
3   File:     mb_gameinfo.h
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-11-27#$
14   $Rev: 9425 $
15   $Author: yosizaki $
16  *---------------------------------------------------------------------------*/
17 
18 /*
19  * This header file is used only by the internal implementation and child devices.
20  * This is not required to create a normal multiboot parent.
21  */
22 
23 
24 #ifndef MB_GAME_INFO_H_
25 #define MB_GAME_INFO_H_
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 
32 #include <nitro/types.h>
33 #include <nitro/wm.h>
34 #include <nitro/mb/mb_gameinfo.h>
35 
36 
37 //=============================================================================
38 //
39 // Data type definitions
40 //
41 //=============================================================================
42 
43 #define MB_GAMEINFO_PARENT_FLAG                     (0x0001)
44 #define MB_GAMEINFO_CHILD_FLAG( __child_aid__ )     ( 1 << ( __child_aid__ ) )
45 
46 //---------------------------------------------------------
47 // Game information distributed from a parent device to a child device by a beacon
48 //---------------------------------------------------------
49 
50 /*
51  * List structure for receiving a child device's game information
52  */
53 typedef struct MBGameInfoRecvList
54 {
55     MBGameInfo gameInfo;               // Parent game information
56     WMBssDesc bssDesc;                 // Information for a parent connection.
57     u32     getFlagmentFlag;           // Indicates in bits the fragmentary beacon that, at present, was received
58     u32     allFlagmentFlag;           // Value of flagmentMaxNum converted into bits
59     u16     getPlayerFlag;             // Indicates in bits the player flags that, at present, have already been received
60     s16     lifetimeCount;             // Lifetime counter for this information (if this parent's beacon is received, lifetime will be prolonged)
61     u16     linkLevel;                 /* Value (expressed in four stages) that indicates the beacon reception strength from the parent */
62     u8      beaconNo;                  // Number of the beacon that was last received
63     u8      sameBeaconRecvCount;       // The number of times the same beacon number was consecutively received
64 }
65 MBGameInfoRecvList, MbGameInfoRecvList;
66 
67 
68 /*
69  * Structure that shows the reception status of beacons on the child device
70  */
71 typedef struct MbBeaconRecvStatus
72 {
73     u16     usingGameInfoFlag;         // Shows in bits the gameInfo array elements being used to receive game information
74     u16     usefulGameInfoFlag;        // Receives all beacons at once and shows game information for which validGameInfoFlag is on
75     // (The validGameInfoFlag may temporarily go down when updating communication members and so on. For display and connection, use this flag to make a determination)
76     u16     validGameInfoFlag;         // Shows in bits the gameInfo array elements that have completely received game information
77     u16     nowScanTargetFlag;         // Shows in bits the current scan target
78     s16     nowLockTimeCount;          // Remaining lock time of the current Scan target
79     s16     notFoundLockTargetCount;   // Number of times the current ScanTarget was consecutively not found
80     u16     scanCountUnit;             // Value of the current scan time converted into a count number
81     u8      pad[2];
82     MBGameInfoRecvList list[MB_GAME_INFO_RECV_LIST_NUM];        // List for receiving game information
83 }
84 MbBeaconRecvStatus;
85 /*
86  * Note: The child device has finished getting parent information when getFlagmentFlag == allFlagmentFlag and getPlayerFlag == gameInfo.volat.nowPlayerFlag
87  *
88  *
89  *
90  */
91 
92 
93 /*
94  * The msg returned by the callback functions for MB_RecvGameInfoBeacon and MB_CountGameInfoLifetime
95  *
96  */
97 typedef enum MbBeaconMsg
98 {
99     MB_BC_MSG_GINFO_VALIDATED = 1,
100     MB_BC_MSG_GINFO_INVALIDATED,
101     MB_BC_MSG_GINFO_LOST,
102     MB_BC_MSG_GINFO_LIST_FULL,
103     MB_BC_MSG_GINFO_BEACON
104 }
105 MbBeaconMsg;
106 
107 typedef void (*MBBeaconMsgCallback) (MbBeaconMsg msg, MBGameInfoRecvList * gInfop, int index);
108 
109 typedef void (*MbScanLockFunc) (u8 *macAddress);
110 typedef void (*MbScanUnlockFunc) (void);
111 
112 /******************************************************************************/
113 /* The following are used internally */
114 
115 
116 //------------------
117 // Parent-side functions
118 //------------------
119 
120     // Initializes the send status
121 void    MB_InitSendGameInfoStatus(void);
122 
123     // Creates an MbGameInfo from the MbGameRegistry
124 void    MBi_MakeGameInfo(MBGameInfo *gameInfop,
125                          const MBGameRegistry *mbGameRegp, const MBUserInfo *parent);
126 
127     // Updates MBGameInfo's child device member information
128 void    MB_UpdateGameInfoMember(MBGameInfo *gameInfop,
129                                 const MBUserInfo *member, u16 nowPlayerFlag, u16 changePlayerFlag);
130 
131     // Adds a created MBGameInfo to the send list so that it will be transmitted by a beacon
132 void    MB_AddGameInfo(MBGameInfo *newGameInfop);
133 
134     // Deletes the MBGameInfo that has been added to the send list
135 BOOL    MB_DeleteGameInfo(MBGameInfo *gameInfop);
136 
137     // Puts the MBGameInfo that is registered with the send list on a beacon and transmits it
138 void    MB_SendGameInfoBeacon(u32 ggid, u16 tgid, u8 attribute);
139 
140 
141 //------------------
142 // Child-side functions
143 //------------------
144     // Statically allocates the beacon receive status buffer
145 void    MBi_SetBeaconRecvStatusBufferDefault(void);
146     // Sets the beacon receive status buffer
147 void    MBi_SetBeaconRecvStatusBuffer(MbBeaconRecvStatus * buf);
148 
149     // Determines whether the obtained beacon represents a multiboot parent device
150 BOOL    MBi_CheckMBParent(WMBssDesc *bssDescp);
151 
152     // Initializes the receive status
153 void    MB_InitRecvGameInfoStatus(void);
154 
155     // Extracts MBGameInfo from a received beacon
156 BOOL    MB_RecvGameInfoBeacon(MBBeaconMsgCallback Callbackp, u16 linkLevel, WMBssDesc *bssDescp);
157 
158     // Lifetime count for the parent information list
159 void    MB_CountGameInfoLifetime(MBBeaconMsgCallback Callbackp, BOOL found_parent);
160 
161     // Sets the scan lock function
162 void    MBi_SetScanLockFunc(MbScanLockFunc lockFunc, MbScanUnlockFunc unlockFunc);
163 
164     // Gets a pointer to a received parent information structure
165 MBGameInfoRecvList *MB_GetGameInfoRecvList(int index);
166 
167 /* Gets the beacon reception status */
168 const MbBeaconRecvStatus *MB_GetBeaconRecvStatus(void);
169 
170 /* Deletes the specified game information */
171 void    MB_DeleteRecvGameInfo(int index);
172 void    MB_DeleteRecvGameInfoWithoutBssdesc(int index);
173 
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 #endif // MB_GAME_INFO_H_
180