1 /*---------------------------------------------------------------------------*
2 Project: MP library
3 File: mp.h
4
5 Copyright 2006 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 $Log: mp.h,v $
14 Revision 1.39 2008/06/05 09:51:23 seiki_masashi
15 Added the MPWaitPseudoVBlank function.
16
17 Revision 1.38 2008/06/03 03:25:37 seiki_masashi
18 Fixed a bug that prevented 'indication' notifications from being sent normally.
19 Added the pseudo V-Blank notification.
20
21 Revision 1.37 2007/10/24 13:46:26 seiki_masashi
22 Changed the method of passing ssid information when a child device connection is made.
23
24 Revision 1.36 2007/10/24 01:54:51 seiki_masashi
25 Added the MP_SIZE_SSID constant.
26
27 Revision 1.35 2007/10/23 13:01:47 seiki_masashi
28 Added the MPCountPopulation function.
29
30 Revision 1.34 2007/10/22 09:42:22 seiki_masashi
31 Added constants for the MPDS library.
32
33 Revision 1.33 2007/10/10 08:36:37 seiki_masashi
34 Added the MPSetPortConfigEx function.
35
36 Revision 1.32 2007/10/04 09:38:48 seiki_masashi
37 Support for MP_BEACON_PERIOD_AUTO.
38
39 Revision 1.31 2007/10/03 05:04:24 seiki_masashi
40 Changed asynchronous function arguments to directly take void* userData.
41
42 Revision 1.30 2007/09/25 14:26:04 seiki_masashi
43 Added MP_FATAL_ERROR_INTERNAL_ERROR.
44
45 Revision 1.29 2007/08/24 04:43:01 seiki_masashi
46 Added threads for each callback type.
47 Removed MPCommandBlock.
48
49 Revision 1.28 2007/01/16 08:46:47 seiki_masashi
50 Corrected processing of restBits.
51
52 Revision 1.27 2007/01/16 07:03:12 seiki_masashi
53 Corrected processing of restBits.
54
55 Revision 1.26 2007/01/15 10:25:08 seiki_masashi
56 Implemented sequential communications.
57
58 Revision 1.25 2006/11/24 07:37:41 seiki_masashi
59 Made changes to add padding to MPConfig so that the size will be a multiple of 32 bytes.
60
61 Revision 1.24 2006/11/13 09:37:13 seiki_masashi
62 Added MPSwitchBufferAddrCheck function.
63
64 Revision 1.23 2006/09/26 12:11:07 seiki_masashi
65 Changed code to use semaphores during requests.
66
67 Revision 1.22 2006/09/15 12:59:43 seiki_masashi
68 Small fix
69
70 Revision 1.21 2006/09/07 13:59:42 seiki_masashi
71 Changed debug output.
72 Changed result codes.
73
74 Revision 1.20 2006/09/02 12:33:55 seiki_masashi
75 Added the MPDisconnectAll function
76
77 Revision 1.19 2006/08/28 12:34:39 seiki_masashi
78 Changed the SwapBytes function to a function in the NET library.
79
80 Revision 1.18 2006/08/14 14:37:53 yasu
81 Support for PADDING warnings.
82
83 Revision 1.17 2006/08/03 09:12:13 seiki_masashi
84 typedef added to enum
85
86 Revision 1.16 2006/07/04 00:22:52 seiki_masashi
87 Added the const modifier to the const pointer.
88
89 Revision 1.15 2006/07/03 13:35:27 seiki_masashi
90 Added Life Time.
91
92 Revision 1.14 2006/07/03 09:28:44 seiki_masashi
93 Cleaned up error codes.
94
95 Revision 1.13 2006/07/03 08:37:04 seiki_masashi
96 Changed specifications of MPGetLinkLevel.
97
98 Revision 1.12 2006/07/03 00:20:23 seiki_masashi
99 Changed specifications so that automatic channel selection of MP_CHANNEL_AUTO is left up to WD.
100
101 Revision 1.11 2006/07/02 13:03:19 seiki_masashi
102 Added link level calculation.
103
104 Revision 1.10 2006/07/02 11:51:28 seiki_masashi
105 Added MP_CHANNEL_AUTO.
106 Changed MP_DISCONNECT_REASON_*.
107
108 Revision 1.9 2006/06/29 05:41:43 adachi_hiroaki
109 Added MPDisconnect.
110
111 Revision 1.8 2006/06/28 12:48:56 seiki_masashi
112 Small fix
113
114 Revision 1.7 2006/06/26 13:08:32 seiki_masashi
115 Small fix
116
117 Revision 1.6 2006/06/23 04:57:01 seiki_masashi
118 Changed specifications so that FatalError notifications are made to the indicationCallbackFunction.
119
120 Revision 1.5 2006/06/23 04:40:05 seiki_masashi
121 Changed so that priority can be set.
122
123 Revision 1.4 2006/06/23 02:27:36 seiki_masashi
124 Deleted prio from the arguments of the MPSend function.
125
126 Revision 1.3 2006/06/22 00:49:02 seiki_masashi
127 Revised code related to sends.
128
129 Revision 1.2 2006/06/21 02:58:30 seiki_masashi
130 Various revisions
131
132 Revision 1.1 2006/06/16 13:03:02 seiki_masashi
133 Initial commit
134
135 $NoKeywords: $
136 *---------------------------------------------------------------------------*/
137
138 #ifndef REVOLUTION_MP_H__
139 #define REVOLUTION_MP_H__
140
141 #include <revolution/types.h>
142 #include <revolution/net.h>
143
144 #ifdef __cplusplus
145 extern "C" {
146 #endif
147 /*===========================================================================*/
148
149 #define MP_RAW_IF 1 // enable raw MP send/receive functions for testing
150 #define MP_USE_SEMAPHORE_FOR_REQUEST
151
152 /*===========================================================================*/
153
154 // The range of MPResult is 0 and the negative numbers.
155 #define MP_RESULT_MP_ERROR_FLAG 0xffffff00
156 #define MP_RESULT_WD_ERROR_FLAG 0x80008000
157 typedef enum
158 {
159 MP_RESULT_OK = 0,
160 MP_RESULT_CLOSED = ( MP_RESULT_MP_ERROR_FLAG | 0x00 ), // -256
161 MP_RESULT_ILLEGAL_PARAMETER = ( MP_RESULT_MP_ERROR_FLAG | 0x01 ), // -255
162 MP_RESULT_ALREADY_IN_USE = ( MP_RESULT_MP_ERROR_FLAG | 0x06 ), // -250
163 MP_RESULT_NOT_ENOUGH_MEMORY = ( MP_RESULT_MP_ERROR_FLAG | 0x10 ), // -240
164 MP_RESULT_NOT_ENOUGH_RESOURCE = ( MP_RESULT_MP_ERROR_FLAG | 0x11 ), // -239
165 MP_RESULT_NOT_ALLOWED = ( MP_RESULT_MP_ERROR_FLAG | 0x12 ), // -238
166 MP_RESULT_BUSY = ( MP_RESULT_MP_ERROR_FLAG | 0x13 ), // -237
167 MP_RESULT_ILLEGAL_STATE = ( MP_RESULT_MP_ERROR_FLAG | 0x14 ), // -236
168 MP_RESULT_TIMEOUT = ( MP_RESULT_MP_ERROR_FLAG | 0x15 ), // -235
169 MP_RESULT_NO_DATA = ( MP_RESULT_MP_ERROR_FLAG | 0x16 ), // -234
170 MP_RESULT_FAILURE = ( MP_RESULT_MP_ERROR_FLAG | 0x17 ), // -233
171 MP_RESULT_FATAL_ERROR = ( MP_RESULT_MP_ERROR_FLAG | 0xff ), // -1
172 MP_RESULT_WD_CLOSED = ( MP_RESULT_WD_ERROR_FLAG | 0x00 ),
173 MP_RESULT_WD_ILLEGAL_PARAMETER = ( MP_RESULT_WD_ERROR_FLAG | 0x01 ),
174 MP_RESULT_WD_UNAVAILABLE_COMMAND = ( MP_RESULT_WD_ERROR_FLAG | 0x02 ),
175 MP_RESULT_WL_FAILURE = ( MP_RESULT_WD_ERROR_FLAG | 0x03 ),
176 MP_RESULT_WD_INSUFFICIENT_BUFFER = ( MP_RESULT_WD_ERROR_FLAG | 0x04 ),
177 MP_RESULT_WD_FAIL_IOBUF = ( MP_RESULT_WD_ERROR_FLAG | 0x05 ),
178 MP_RESULT_WD_ALREADY_IN_USE = ( MP_RESULT_WD_ERROR_FLAG | 0x06 )
179 } MPResult;
180
181 typedef enum
182 {
183 MP_FATAL_ERROR_NONE = 0,
184 MP_FATAL_ERROR_NOT_ENOUGH_MEMORY = 1,
185 MP_FATAL_ERROR_INTERNAL_ERROR = 2,
186 MP_FATAL_ERROR_UNKNOWN = 0xff
187 } MPFatalError;
188
189 #define MP_CHILD_MAX 15
190 #define MP_CHILD_BITS_MASK 0x0000fffe
191 #define MP_AID_MAX (MP_CHILD_MAX+1)
192 #define MP_AID_BITS_MASK 0x0000ffff
193 #define MP_PORT_MAX 16
194 #define MP_PORT_BROADCAST 0xffffffff
195 #define MP_RAW_PORT_MAX 8
196 #define MP_SEQ_PORT_MAX 8
197 #define MP_DATA_MAX 512
198
199 #define MP_LINKLEVEL_MAX 4
200
201 #define MP_CHANNEL_AUTO 0
202 #define MP_LIFETIME_DEFAULT 4000
203 #define MP_TGID_AUTO 0xffffffff
204 #define MP_BEACON_PERIOD_AUTO 0
205
206 #define MP_SIZE_MACADDRESS 6
207 #define MP_SIZE_SSID 32
208 #define MP_SIZE_SSID_INTERNAL 8
209 #define MP_SIZE_SSID_USER_DATA 24
210 #define MP_GAMEINFO_USER_SIZE_MAX 112
211
212 #define MP_GAMEINFO_MAGIC_NUMBER 0x0001
213 #define MP_GAMEINFO_VERSION_NUMBER 1
214 #define MP_GAMEINFO_PLATFORM_ID_NITRO 0
215 #define MP_GAMEINFO_PLATFORM_ID_REVOLUTION 8
216
217 #define MP_ATTR_ENTRY_SHIFT 0
218 #define MP_ATTR_MB_SHIFT 1
219 #define MP_ATTR_FLAG_ENTRY (1 << MP_ATTR_ENTRY_SHIFT)
220 #define MP_ATTR_FLAG_MB (1 << MP_ATTR_MB_SHIFT)
221
222 typedef enum
223 {
224 MP_MODE_NONE = 0x00,
225 MP_MODE_PARENT = 0x01, // MP parent device mode
226
227 MP_MODE_ENABLE_PSEUDO_VBLANK_INDICATION = 0x10000
228 } MPMode;
229
230 #define MP_PRIORITY_LEVEL 4 // 4 priority levels
231 typedef enum MPPriorityLevel
232 {
233 MP_PRIORITY_URGENT = 0,
234 MP_PRIORITY_HIGH,
235 MP_PRIORITY_NORMAL,
236 MP_PRIORITY_LOW
237 } MPPriorityLevel;
238
239 // MPCallbackType is a non-zero, positive number. This separates it from the range of MPResult.
240 #define MP_CB_GROUP_MASK 0xffff0000
241 #define MP_CB_GROUP_PORT 0x00000000
242 #define MP_CB_GROUP_ASYNC 0x00010000
243 #define MP_CB_GROUP_INDICATION 0x00020000
244 #define MP_CB_GROUP_MPDS 0x00030000
245 typedef enum
246 {
247 MP_PORT_CB_TYPE_NONE = (MP_CB_GROUP_PORT | 0x00), // unused
248 MP_PORT_CB_TYPE_STARTUP = (MP_CB_GROUP_PORT | 0x01),
249 MP_PORT_CB_TYPE_CLEANUP = (MP_CB_GROUP_PORT | 0x02),
250 MP_PORT_CB_TYPE_DATA_RECEIVED = (MP_CB_GROUP_PORT | 0x03),
251 MP_PORT_CB_TYPE_CONNECTED = (MP_CB_GROUP_PORT | 0x04),
252 MP_PORT_CB_TYPE_DISCONNECTED = (MP_CB_GROUP_PORT | 0x05),
253 MP_ASYNC_CB_TYPE_DATA_SENT = (MP_CB_GROUP_ASYNC | 0x01),
254 MP_ASYNC_CB_TYPE_BEACON_SENT = (MP_CB_GROUP_ASYNC | 0x02),
255 MP_INDICATION_CB_TYPE_PSEUDO_VBLANK = (MP_CB_GROUP_INDICATION | 0x01),
256 MP_INDICATION_CB_TYPE_FATAL_ERROR = (MP_CB_GROUP_INDICATION | 0xff01),
257 MPDS_PORT_CB_TYPE_DATASET_RECEIVED = (MP_CB_GROUP_MPDS | 0x01)
258 } MPCallbackType;
259 #define MPPortCallbackType MPCallbackType // for backward compatibility
260 #define MP_INDICATION_TYPE_FATAL_ERROR MP_INDICATION_CB_TYPE_FATAL_ERROR // for backward compatibility
261
262 #define MP_REQUEST_TYPE_BLOCKING OS_MESSAGE_BLOCK
263 #define MP_REQUEST_TYPE_NONBLOCKING OS_MESSAGE_NOBLOCK
264
265 // reason code for disconnect
266 typedef enum
267 {
268 // reason value for disconnect due to external cause.
269 MP_DISCONNECT_REASON_RESERVED = 0, // reserved
270 MP_DISCONNECT_REASON_UNSPECIFIED = 1, // error that cannot be specifically identified
271 MP_DISCONNECT_REASON_PREV_AUTH_INVALID = 2, // The immediately previous authentication is no longer valid.
272 MP_DISCONNECT_REASON_DEAUTH_LEAVING = 3, // Deauthenticated because unit has left the BSS.
273 MP_DISCONNECT_REASON_INACTIVE = 4, // Released connection due to inactivity.
274 MP_DISCONNECT_REASON_UNABLE_HANDLE = 5, // Released connection due to lack of sufficient resources for AP.
275 MP_DISCONNECT_REASON_RX_CLASS2_FROM_NONAUTH_STA = 6, // A Class2 frame was received from an unauthenticated STA.
276 MP_DISCONNECT_REASON_RX_CLASS3_FROM_NONASSOC_STA = 7, // A Class3 frame was received from an unconnected STA.
277 MP_DISCONNECT_REASON_DISASSOC_LEAVING = 8, // Released association because unit has left the BSS.
278 MP_DISCONNECT_REASON_ASSOC_STA_NOTAUTHED = 9, // An STA which has requested connection has not yet undergone authentication.
279 // reason values specific to local communications of the Wii-DS
280 MP_DISCONNECT_REASON_NO_ENTRY = 19, // Current entry not received for parent.
281 // reason value related to auto disconnect from inside the library
282 MP_DISCONNECT_REASON_MP_LIFETIME = 0x8001, // MP communication lifetime has run out.
283 MP_DISCONNECT_REASON_UPDATE = 0xc001, // Corresponding child has been re-registered under a different AID.
284 MP_DISCONNECT_REASON_DEPRIVED_AID = 0xc002, // Another party in the communication has been registered with the same AID number.
285
286 // reason values for active disconnection by the library
287 MP_DISCONNECT_REASON_RESET = 0xf001, // disconnected as a result of reset
288 MP_DISCONNECT_REASON_ACTIVE = 0xf002 // disconnected self using disconnect function
289 } MPDisconnectReason;
290 #define MP_IS_DISCONNECTED_FROM_MYSELF(reason) (((reason)&0xf000) == 0xf000)
291
292 #define MP_DEBUG_LEVEL_ERROR (1U << 0)
293 #define MP_DEBUG_LEVEL_WARNING (1U << 1)
294 #define MP_DEBUG_LEVEL_REPORT (1U << 2)
295 #define MP_DEBUG_LEVEL_TRACE (1U << 8)
296 #define MP_DEBUG_LEVEL_DEFAULT (MP_DEBUG_LEVEL_ERROR|MP_DEBUG_LEVEL_WARNING|MP_DEBUG_LEVEL_REPORT)
297
298 #define MP_DEBUG_LEVEL_DETAIL (1U << 16)
299 #define MP_DEBUG_LEVEL_DETAIL_SEND (1U << 17)
300 #define MP_DEBUG_LEVEL_DETAIL_RECV (1U << 18)
301 #define MP_DEBUG_LEVEL_DETAIL_MPSEQ (1U << 19)
302 #define MP_DEBUG_LEVEL_DETAIL_PACKET (1U << 20)
303 #define MP_DEBUG_LEVEL_DETAIL_TSF (1U << 21)
304 #define MP_DEBUG_LEVEL_DETAIL_TMPTT (1U << 22)
305 #define MP_DEBUG_LEVEL_DETAIL_VBLANK (1U << 23)
306 #define MP_DEBUG_LEVEL_DETAIL_REQUEST (1U << 24)
307 #define MP_DEBUG_LEVEL_DETAIL_IPC (1U << 25)
308 #define MP_DEBUG_LEVEL_DETAIL_CALLBACK (1U << 26)
309
310
311 //////////////////////////////////////////////////////////////////////////////
312
313 #if defined(REVO_IOP_ENDIAN_LITTLE)
314 #define MPMPToH8(data) (data)
315 #define MPMPToH16(data) (data)
316 #define MPMPToH32(data) (data)
317 #define MPHToMP8(data) (data)
318 #define MPHToMP16(data) (data)
319 #define MPHToMP32(data) (data)
320 #endif
321
322 #if defined(REVO_IOP_ENDIAN_BIG) || defined(GEKKO)
323 #define MPMPToH8(data) (u8)(data)
324 #define MPMPToH16(data) NETSwapBytes16(data)
325 #define MPMPToH32(data) NETSwapBytes32(data)
326 #define MPHToMP8(data) (u8)(data)
327 #define MPHToMP16(data) NETSwapBytes16(data)
328 #define MPHToMP32(data) NETSwapBytes32(data)
329 #endif
330
331 //////////////////////////////////////////////////////////////////////////////
332
333 #define MP_MACADDRESS_PRINT_FORMAT "%02X:%02X:%02X:%02X:%02X:%02X"
334 #define MP_MACADDRESS_PRINT_LIST( mac ) \
335 (mac)[0], (mac)[1], (mac)[2], (mac)[3], (mac)[4], (mac)[5]
336
337
338 //////////////////////////////////////////////////////////////////////////////
339
340 typedef struct MPPortCallbackInfo_Startup
341 {
342 u32 padding;
343 } MPPortCallbackInfo_Startup;
344
345 typedef struct MPPortCallbackInfo_Cleanup
346 {
347 u32 padding;
348 } MPPortCallbackInfo_Cleanup;
349
350 typedef struct MPPortCallbackInfo_DataReceived
351 {
352 u32 fromAid;
353
354 void* data;
355 u32 length;
356 u32 seqNo;
357 } MPPortCallbackInfo_DataReceived;
358
359
360 typedef struct MPPortCallbackInfo_Connected
361 {
362 u32 fromAid;
363
364 u32 ssidUserDataLength;
365
366 u8 macAddress[MP_SIZE_MACADDRESS];
367
368 u8 padding[2];
369
370 union {
371 struct {
372 u8 _ssidInternal[MP_SIZE_SSID_INTERNAL];
373 u8 ssidUserData[MP_SIZE_SSID_USER_DATA];
374 };
375 u8 _ssid[MP_SIZE_SSID];
376 };
377
378 u32 _ssidLength;
379 } MPPortCallbackInfo_Connected;
380
381 typedef struct MPPortCallbackInfo_Disconnected
382 {
383 u32 fromAid;
384
385 u32 reason;
386 u8 macAddress[6];
387
388 u8 padding[2];
389 } MPPortCallbackInfo_Disconnected;
390
391 typedef struct MPAsyncCallbackInfo_DataSent
392 {
393 u32 aidBits;
394
395 void* data;
396 u32 length;
397
398 u32 restBits;
399
400 u32 seqNo;
401 } MPAsyncCallbackInfo_DataSent;
402
403 typedef struct MPAsyncCallbackInfo_BeaconSent
404 {
405 u8 padding[4];
406 } MPAsyncCallbackInfo_BeaconSent;
407
408 typedef struct MPCallbackInfoHeader
409 {
410 s32 type;
411 s32 result;
412 u32 padding;
413 void *userData;
414 } MPCallbackInfoHeader;
415
416 typedef struct MPIndicationInfo
417 {
418 union {
419 MPCallbackInfoHeader header;
420 // same as MPCallbackInfoHeader
421 struct {
422 s32 type;
423 s32 result;
424 s32 value;
425 u32 padding;
426 };
427 };
428
429 } MPIndicationInfo;
430
431 typedef struct MPCallbackInfo
432 {
433 union {
434 MPCallbackInfoHeader header;
435 // same as MPCallbackInfoHeader
436 struct {
437 s32 type;
438 s32 result;
439 u32 port;
440 void *userData;
441 };
442 };
443
444 union {
445 MPPortCallbackInfo_Startup startup;
446 MPPortCallbackInfo_Cleanup cleanup;
447 MPPortCallbackInfo_DataReceived dataReceived;
448 MPPortCallbackInfo_Connected connected;
449 MPPortCallbackInfo_Disconnected disconnected;
450 MPAsyncCallbackInfo_DataSent dataSent;
451 MPAsyncCallbackInfo_BeaconSent beaconSent;
452
453 u8 raw_binary[80];
454 };
455 } MPCallbackInfo;
456 #define MPCommandBlock MPCallbackInfo // for backward compatibility
457 #define MPPortCallbackInfo MPCallbackInfo // for backward compatibility
458
459 typedef struct MPChildInfo
460 {
461 u32 aid;
462 u8 macAddress[6];
463
464 u8 padding[2];
465 } MPChildInfo;
466
467 typedef void (*MPCallback)( s32 result, MPCallbackInfo *info );
468 typedef void (*MPIndicationCallback)( s32 type, MPIndicationInfo *info );
469 typedef void (*MPPortCallback)( s32 type, MPPortCallbackInfo *info );
470
471 typedef struct MPPortConfig
472 {
473 MPPortCallback callbackFunction; // receive callback for port
474 u32 priority; // send priority for port
475 void* userData; // User data passed to the port receive callback.
476 u8 padding[4];
477 } MPPortConfig;
478
479 typedef struct MPConfig
480 {
481
482 void* (*alloc)(u32 size);
483 void (*free) (void* ptr);
484
485 OSPriority threadPriority; // thread priority for MP task
486
487 u32 mode; // MPMode
488
489 u32 ggid;
490 u32 tgid; // 16-bit ID that must be created each time a parent is started
491 // appropriate value is automatically assigned using MP_TGID_AUTO
492 u32 channel; // channel to be used
493 // appropriate channel is automatically selected using MP_CHANNEL_AUTO
494
495 s32 lifeTime; // Time limit used to disconnect if state of non-communication continues. Specified in units of milliseconds.
496 // The lifetime feature is disabled if 0 is specified.
497 // Under normal conditions, specify MP_LIFETIME_DEFAULT (4000).
498
499 // for parent mode
500 u32 beaconPeriod; // Beacon interval (ms)
501 // Under normal conditions, specify MP_BEACONPERIOD_AUTO.
502 u32 maxNodes; // number of child devices that can connect
503 u32 parentMaxSize; // maximum parent send size
504 u32 childMaxSize; // maximum child send size
505 s32 entryFlag; // 1: Connect possible, 0: Connect not possible
506 s32 multiBootFlag; // must be set to 0 for normal parents
507
508 s32 frequency; // MP communication frequency (0 is used to indicate continuous communication)
509
510 u32 userGameInfoLength; // Length of the user area inside GameInfo
511 u8 userGameInfo[ MP_GAMEINFO_USER_SIZE_MAX ]; // Data in the user area inside GameInfo
512
513 // Callback
514 MPIndicationCallback indicationCallbackFunction; // callback for notifying indication
515
516 // portConfig
517 MPPortConfig portConfig[MP_PORT_MAX]; // receive callback for port
518
519 u8 padding[12];
520
521 } MPConfig;
522
523
524 // Same as WDGameInfo
525 typedef struct MPGameInfo
526 {
527 u16 magicNumber;
528 u8 ver; // == 1
529 u8 platform;
530 u32 ggid;
531 u16 tgid;
532 u8 userGameInfoLength; /* byte length of the user area */
533 u8 attribute;
534 u16 parentMaxSize;
535 u16 childMaxSize;
536 u8 userGameInfo[ MP_GAMEINFO_USER_SIZE_MAX ];
537
538 } __attribute__((packed)) MPGameInfo;
539
540
541 //////////////////////////////////////////////////////////////////////////////
542
543 /*---------------------------------------------------------------------------*
544 Name : MPStartup
545 Description : Initializes and starts the MP communication.
546 Arguments : config - MP communication settings
547 Returns : s32 - Returns the result of the processing. Returns a negative value if processing failed.
548 *---------------------------------------------------------------------------*/
549 s32 MPStartup( const MPConfig* config );
550
551 /*---------------------------------------------------------------------------*
552 Name : MPCleanup
553 Description : Ends the MP communication.
554 Arguments : None.
555 Returns : s32 - Returns the result of the processing. Returns a negative value if processing failed.
556 *---------------------------------------------------------------------------*/
557 s32 MPCleanup( void );
558
559 /*---------------------------------------------------------------------------*
560 Name : MPSend
561 Description : Sends data.
562 Arguments : data - Pointer to the data to be sent
563 length - Length of data to be sent
564 aidBits - AID list of send destinations
565 port - Port number to which data is to be sent
566 restBits - Required resend list of AIDs
567 Returns : s32 - Returns the result of the processing. Returns a negative value if processing failed.
568 *---------------------------------------------------------------------------*/
569 s32 MPSend( const void* data, u32 length, u32 aidBits, u32 port, u32* restBits );
570
571 /*---------------------------------------------------------------------------*
572 Name : MPSendAsync
573 Description : Sends data.
574 Arguments : data - Pointer to the data to be sent
575 length - Length of data to be sent
576 aidBits - AID list of send destinations
577 port - Port number to which data is to be sent
578 restBits - Required resend list of AIDs
579 cb - The callback function invoked when an asynchronous function completes.
580 userData - Application-dependent pointer value to pass to the callback function.
581 Returns : s32 - Returns the result of the processing. Returns a negative value if processing failed.
582 *---------------------------------------------------------------------------*/
583 s32 MPSendAsync( const void* data, u32 length, u32 aidBits, u32 port,
584 u32* restBits, MPCallback cb, void* userData );
585
586 /*---------------------------------------------------------------------------*
587 Name : MPUpdateBeacon
588 Description : Current settings are accessed and GameInfo is updated and sent.
589 Arguments : None.
590 Returns : s32 - Returns the result of the processing. Returns a negative value if processing failed.
591 *---------------------------------------------------------------------------*/
592 s32 MPUpdateBeacon( void );
593
594 /*---------------------------------------------------------------------------*
595 Name : MPUpdateBeaconAsync
596 Description : Current settings are accessed and GameInfo is updated and sent.
597 Arguments : cb - The callback function invoked when an asynchronous function completes.
598 userData - Application-dependent pointer value to pass to the callback function.
599 Returns : s32 - Returns the result of the processing. Returns a negative value if processing failed.
600 *---------------------------------------------------------------------------*/
601 s32 MPUpdateBeaconAsync( MPCallback cb, void* userData );
602
603 /*---------------------------------------------------------------------------*
604 Name : MPSetUserGameInfo
605 Description : Sets UserGameInfo information.
606 To apply the values set using this function to the send beacon, you must call the MPUpdateBeacon function.
607
608 Arguments : userGameInfo - UserGameInfo information applied to the beacon.
609 size - Size of userGameInfo (<= MP_GAMEINFO_USER_SIZE_MAX)
610 Returns : s32 - Returns the result of the processing. Returns a negative value if processing failed.
611 *---------------------------------------------------------------------------*/
612 s32 MPSetUserGameInfo( const void* userGameInfo, u32 size );
613
614 /*---------------------------------------------------------------------------*
615 Name : MPSetEntryFlag
616 Description : Changes connection permission settings.
617 To apply the values set using this function to the send beacon, you must call the MPUpdateBeacon function.
618
619 Arguments : entryFlag - TRUE if child connections are allowed.
620 Returns : s32 - Returns the result of the processing. Returns a negative value if processing failed.
621 *---------------------------------------------------------------------------*/
622 s32 MPSetEntryFlag( BOOL entryFlag );
623
624 s32 MPiSetMultiBootFlag( BOOL multiBootFlag );
625
626 /*---------------------------------------------------------------------------*
627 Name : MPGetFatalError
628 Description : Returns the type value of the last Fatal Error.
629 Arguments : None.
630 Returns : The type value of the last Fatal Error
631 *---------------------------------------------------------------------------*/
632 s32 MPGetFatalError( void );
633
634 /*---------------------------------------------------------------------------*
635 Name : MPSwitchBufferAddrCheck
636 Description : Toggles the operation mode: one mode checks whether the buffer used by the MP library exists in MEM2, and the other mode performs no check.
637
638 Arguments : enabled - Specifies the operation mode for the check.
639 TRUE: Check. FALSE : Don't check.
640 Returns : BOOL - Returns the operation mode from before the switch.
641 *---------------------------------------------------------------------------*/
642 BOOL MPSwitchBufferAddrCheck( BOOL enabled );
643
644 /*---------------------------------------------------------------------------*
645 Name : MPDisconnect
646 Description : Disconnects the other party in communication.
647 Arguments : aid - AID of the communication target to be disconnected.
648 Returns : s32 - Returns the result of the processing. Returns a negative value if processing failed.
649 *---------------------------------------------------------------------------*/
650 s32 MPDisconnect( u32 aid );
651
652 /*---------------------------------------------------------------------------*
653 Name : MPDisconnectAll
654 Description : Disconnects all communicating parties currently connected.
655 Arguments : None.
656 Returns : s32 - Returns the result of the processing. Returns a negative value if processing failed.
657 *---------------------------------------------------------------------------*/
658 s32 MPDisconnectAll( void );
659
660 /*---------------------------------------------------------------------------*
661 Name : MPGetLinkLevel
662 Description : Gets the receiving signal strength.
663 Arguments : None.
664 Returns : s32 - Returns a signal strength value from 0 to 3. Returns a negative value if processing failed.
665 *---------------------------------------------------------------------------*/
666 s32 MPGetLinkLevel( void );
667
668 /*---------------------------------------------------------------------------*
669 Name : MPGetConnectedAIDs
670 Description : Gets the list of currently connected AIDs.
671 Arguments : None.
672 Returns : u32 value representing set bits corresponding to currently connected AIDs.
673 *---------------------------------------------------------------------------*/
674 u32 MPGetConnectedAIDs( void );
675
676 /*---------------------------------------------------------------------------*
677 Name : MPIsConnected
678 Description : Determines whether a given AID is currently connected.
679 Arguments : aid - AID to be detected.
680 Returns : TRUE if the AID is connected.
681 *---------------------------------------------------------------------------*/
682 BOOL MPIsConnected( u32 aid );
683
684 /*---------------------------------------------------------------------------*
685 Name: MPCountPopulation
686 Description: Determines the number of '1' bits in a binary 32-bit expression.
687 Arguments: x
688 Returns: The number of '1' bits in the binary expression
689 *---------------------------------------------------------------------------*/
690 u8 MPCountPopulation(u32 x);
691
692 /*---------------------------------------------------------------------------*
693 Name : MPWaitPseudoVBlank
694 Description : Wait for a pseudo V-Blank.
695 Arguments : None.
696 Returns : TRUE if had been waiting for a pseudo V-Blank, FALSE if MP is not in operation.
697
698 *---------------------------------------------------------------------------*/
699 BOOL MPWaitPseudoVBlank( void );
700
701 #ifndef NDEBUG
702 /*---------------------------------------------------------------------------*
703 Name : MPSetDebugLevel
704 Description : Change the level of debug output.
705 Arguments : level - Debug output type bit to be output
706 Returns : None.
707 *---------------------------------------------------------------------------*/
708 void MPSetDebugLevel( u32 level );
709 #else
710 #define MPSetDebugLevel( level ) ( (void)0 )
711 #endif
712
713
714 //////////////////////////////////////////////////////////////////////////////
715
716 /*---------------------------------------------------------------------------*
717 Name : MPSetIndicationConfig
718 Description : Sets the callback for the notifying indication to MPConfig.
719 This must be set before calling the MPStartup function.
720 Arguments : config - MP communication settings
721 callback - Callback for indication notification.
722 Returns : None.
723 *---------------------------------------------------------------------------*/
MPSetIndicationConfig(MPConfig * config,MPIndicationCallback callback)724 static inline void MPSetIndicationConfig( MPConfig* config, MPIndicationCallback callback )
725 {
726 config->indicationCallbackFunction = callback;
727 }
728
729 /*---------------------------------------------------------------------------*
730 Name : MPSetPortConfig
731 Description : Performs the port settings in MPConfig.
732 This must be set before calling the MPStartup function.
733 Arguments : config - MP communication settings
734 port - Port number for which the callback is being set.
735 callback - Receive callback for port
736 priority - Send priority of the port.
737 Returns : None.
738 *---------------------------------------------------------------------------*/
MPSetPortConfig(MPConfig * config,u32 port,MPPortCallback callback,u32 priority)739 static inline void MPSetPortConfig( MPConfig* config, u32 port, MPPortCallback callback, u32 priority )
740 {
741 config->portConfig[port].callbackFunction = callback;
742 config->portConfig[port].priority = priority;
743 config->portConfig[port].userData = NULL;
744 }
745
746 /*---------------------------------------------------------------------------*
747 Name : MPSetPortConfigEx
748 Description : Performs the port settings in MPConfig.
749 This must be set before calling the MPStartup function.
750 Arguments : config - MP communication settings
751 port - Port number for which the callback is being set.
752 priority - Send priority of the port.
753 callback - Receive callback for port
754 userData - User data to pass to the port receive callback.
755 Returns : None.
756 *---------------------------------------------------------------------------*/
MPSetPortConfigEx(MPConfig * config,u32 port,MPPortCallback callback,u32 priority,void * userData)757 static inline void MPSetPortConfigEx( MPConfig* config, u32 port, MPPortCallback callback, u32 priority, void* userData )
758 {
759 config->portConfig[port].callbackFunction = callback;
760 config->portConfig[port].priority = priority;
761 config->portConfig[port].userData = userData;
762 }
763
764 /*---------------------------------------------------------------------------*
765 Name : MPGetCallbackGroup
766 Description : Gets the group from the value of the callback type.
767 Arguments : type - callback type
768 Returns : The group to which that callback type belongs.
769 *---------------------------------------------------------------------------*/
MPGetCallbackGroup(s32 type)770 static inline s32 MPGetCallbackGroup( s32 type )
771 {
772 return (s32)(type & MP_CB_GROUP_MASK);
773 }
774
775
776
777
778 #ifdef MP_RAW_IF
779
780 #define MP_NtoHs MPMPToH16
781 #define MP_NtoHl MPMPToH32
782 #define MP_HtoNs MPHToMP16
783 #define MP_HtoNl MPHToMP32
784
785 typedef s32 MPError;
786
787 MPError MPiRawSendDataToPort(const u16* sendData, u16 sendDataSize, u16 destBitmap, u16 port);
788 MPError MPiRawReceiveData(u16* recvBuf, u16 recvBufSize);
789
790 #define MP_SendDataToPort MPiRawSendDataToPort
791 #define MP_ReceiveData MPiRawReceiveData
792
793 #ifdef REVO_IOP_RELEASE
794
795 # define MP_Panic( ... ) UTL_Terminate()
796 # define MP_Warning( ... ) ( (void)0 )
797
798 #else
799
800 # define MP_Panic( ... ) UTLi_Panic( "MP", __FILE__, __LINE__, __VA_ARGS__ )
801 # define MP_Warning( ... ) UTLi_Warning( "MP", __FILE__, __LINE__, __VA_ARGS__ )
802
803 #endif
804
805 #endif
806
807 /*===========================================================================*/
808 #ifdef __cplusplus
809 }
810 #endif
811 #endif /* REVOLUTION_MP_H__ */
812
813 /*---------------------------------------------------------------------------*
814 End of file
815 *---------------------------------------------------------------------------*/
816