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