MKWii Network Protocol/STATUS

From Custom Mario Kart
Jump to: navigation, search

This pages is related to MKWii Network Protocol and describes the record type STATUS.

The status packages are from one client to another in 3 different ways:

  • Direct client to client communication
  • Client to Server MS to Server MASTER to client communication. Server MASTER itself prefixes the message by a master message of type 06.
  • Client to Server GPCM to client communication using a GPCM90vMAT message. The message header is omitted. This is used for known friends.

The used data structure is identical for all 3 communication ways, only the header is different. The members itself are mainly stored as little endian data.



Basic Message Header

All status records start with a 20 bytes long message header:

The total record length is the length of the header plus extent (20+ELEN). For GPCM90vMAT messages this header is omitted.

Naming

knocker
A player who wants to enter a room.
(room) player
A player of a room.
host
The host of a room. Exact one room player is host, all others are guests.
guest
All room players except the host.

Protocol

New Player enters room

If a knocker will enter a room, the following handshaking (only status packages reflected) is done with each room player that is already in the room:

  1. Status 01 is send by room player.
  2. Status 04 is send by knocker.
  3. Status 05 is send by room player.
  4. Some seconds of silence.
  5. Either it starts again with step 1, or it continues
  6. Status 01 is send by knocker.
  7. Status 02 is send by room player.

Traceable public IP

The value "traceable public IP" means the last reachable host on the route to the client. Do a traceroute on publicip and put the farthest reachable host here. This is the behaviour of the official server, but probably it'd be enough to simply put the public IP here.

Message Types

Type 01: Ask for entrance

This status packet is send from a knocker to each room player, when the knocker will enter the room or group. There are 2 ways to transmit the message:


Status Type 01
Offset Size Endian Description
0x00 4 little Unknown, 0 (80%) or 3 (20%)
0x04 4 4 bytes Traceable public IPv4 of the sender, byte by byte (similar to big endian).
0x08 4 little Public port of the sender. Always the same value as the public port of the header.
0x0c 4 4 bytes Local IPv4 of the sender, byte by byte (similar to big endian).
0x10 4 little Local port of the sender.
0x14 4 little Unknown, always 1
0x18 4 little Unknown, 1 or 0
0x1c 4 little Number of players at the knocker's console (1 or 2)
0x20 4 little An unique identfication number of this status packet. The reply of the player (status type 0x02) use the same ID.
0x24 End of the packet, 36 bytes total.

Type 02: Allow entrance

This status packet is send from the room player to the knocker as reply of a type 0x01 message to confirm the entrance of the guest. There are 2 ways to transmit the message:


Status Type 02
Offset Size Endian Description
0x00 4 little Parameter »maxplayers« (not 100% sure) = Number of possible guests. Always 11.
0x04 4 little Most likely the client slot index of the sender (zero based, not player count).
0x08 4 little Parameter »dwc_pid«. It is the same as the profile id of the header.
0x0c 4 4 bytes Traceable public IPv4 of the sender, byte by byte (similar to big endian).
0x10 4 little Public port of the sender. Always the same value as the public port of the header.
0x14 4 4 bytes Local IPv4 of the sender, byte by byte (similar to big endian).
0x18 4 little Local port of the sender.
0x1c 4 little Unknown, always 1
0x20 4 little Number of players at the room player's console.
0x24 4 little Parameter »dwc_groupid« (not 100% sure).
0x28 4 little Most likely the client slot index of the receiver (zero based, not player count).
0x2c 4 little Most likely the client/console count already in the room.
0x30 4 little The identfication number send by the guest (status type 0x01).
0x34 End of the packet, 52 bytes total.

Type 03: Room full

This status packet is sent from the room player to the knocker when access is denied because the room is full. Packet contains information about the player count (mostly 12, may be 11 when joining with a 2nd player on the same console).

Status Type 03
Offset Size Endian Description
0x00 4 little BCD-value with current player count (0x11 for 11 players and 0x12 for 12 players).
0x04 End of the packet, 4 bytes total.

Type 04: Ping

Status packet without additional data. Probably just a "ping" packet.

Type 05: Pong

Status packet without additional data. Probably the answer to a "ping" packet.

Type 06: Local IP

This packet contains the local IP of the player.

Status Type 06
Offset Size Endian Description
0x00 4 4-byte Local IP.
0x04 4 little Local port.
0x08 End of the packet, 8 bytes total.

Type 07: New client

Send by host when there joins a new player.

Status Type 07
Offset Size Endian Description
0x00 4 little PID of new guest
0x04 4 little slot ID of new guest
0x08 End of the packet, 8 bytes total.

Type 0D: Joining failed

This contains a little-endian PID and is sent by the host when a player tried to join, only connected partially, and then disconnected again. He hasn't done a full Natneg, so he can't send a disconnect himself, so the host sends a ST0D packet.

Type 0E: ?

Type 0F: Host

Type 0F is sent by the host (after a ST0D, possibly also at other occurrences) and just contains the PID of the host (the sender).

Type 10: Host disconnect?

Status Type 10
Offset Size Endian Description
0x00 4 little some PID; optional
0x04 4 little? some PID; optional
0x00,0x04,0x08 End of the packet, 0 or 4 or 8 bytes total.

Seems to be sent by the host when he disconected joining player(s) because the room doesn't go on suspend.

Type 52: New host request

This packet is sent by a player when the current host disconnects. The wii which has been in the room for the longest (Dolphin may cause problems and room splits due to its wrong time ...) sends a ST52 record to every other Wii, with the only parameter being the time (minutes? seconds? races?) how long it has already been in the race.

Type 53: New host request reply: Maybe

When a Wii sends a ST52 request, the other Wiis may respond with ST53 or ST54. Responding with ST53 means "I don't know if you should be the host", and then they receive another ST53 as acknowledgement.

The new host then replys with ST55 to tell the Wii that he is now the new host.

Type 54: New host request reply: Yes

When a Wii sends a ST52 request, the other Wiis may respond with ST53 or ST54. Responding with ST54 means "Yes, you are now the new host, I don't know any better candidate".

The new host then replys with another ST52 just to acknowledge, which is again acknowledged with a ST53.

Type 55: I am the new host

ST55 is sent by the new host to every Wii which answered the host request with ST53.

Type 82: SUSPEND flag control

This status types are being used by the players to control and coordinate the SUSPEND status of the current room. The guests tell the host the status they want the room to be in, and the host tells the guests what status he is going to set the room to.

Guest requests SUSPEND = 1

This is sent by every guest when he wants to enable SUSPEND

Status Type 82 - request SUSPEND = 1 (16 bytes)
Offset Size Endian Description
0x00 4 little PID of host.
0x04 4 little host flag. 0 for this record type, since this is sent by guests.
0x08 4 little 1, the wanted suspend value
0x0c 4 little Slot of guest
0x10 End of the packet, 16 bytes total.

Host sets SUSPEND = 1

The host has received requests from every client to enable suspend, confirms SUSPEND has been enabled.

Status Type 82 - set SUSPEND = 1 (16 bytes)
Offset Size Endian Description
0x00 4 little PID of host.
0x04 4 little Host flag, 1 as this is sent by the host
0x08 4 little 1, to indicate the wanted SUSPEND value
0x0c 4 little slot usage mask. bit 1 for used slot, bit 0 for empty slot
0x10 End of the packet, 16 bytes total.

Guests request SUSPEND = 0

Guest is ready to disable SUSPEND.

Status Type 82 - request SUSPEND = 0 (16 bytes)
Offset Size Endian Description
0x00 4 little PID of host.
0x04 4 little Host flag - 0, because it's sent by guests
0x08 4 little 0 to indicate the guest wants to turn off SUSPEND
0x0c 4 little Client slot
0x10 End of the packet, 16 bytes total.

Host sets SUSPEND = 0

This is sent by the host to indicate he is turning off suspend.

Status Type 82 - set SUSPEND = 0 (16 bytes)
Offset Size Endian Description
0x00 4 little PID of host.
0x04 4 little Host value, always 1
0x08 4 little 0, the new suspend value
0x0c 4 little slot usage mask. bit 1 for used slot, bit 0 for empty slot
0x10 End of the packet, 16 bytes total.

Client acknowledge

This is just an acknowledge to a client's request, sent by the host.

Status Type 82 - Client acknowledge (8 bytes)
Offset Size Endian Description
0x00 4 little PID of host.
0x04 4 little host flag, so, 1.
0x08 End of the packet, 8 bytes total.


Type 83: Current players

This packet is sent by the host to every other player every 15 seconds. It contains a list of used slots.

Status Type 83
Offset Size Endian Description
0x00 4 little PID of player.
0x04 4 little Slot usage mask (12 bit data, 20 bit padding)
0x08 4  ? unknown ID, changes when new client joins
0x0c End of the packet, 12 bytes total.

Statistics

This is a summary of all status packages of 286 dumps (mostly private room versus races).

----------------------------------
        msg   status
  count type type+size
----------------------------------
   9126 GPCM90 01 24 by-server
    704 STATUS 01 24 by-server

   3669 GPCM90 02 34 by-server
    327 STATUS 02 34 by-server

    195 GPCM90 03 04 by-server
     41 STATUS 03 04 by-server

   4887 GPCM90 04 00 by-server
    376 STATUS 04 00 by-server

   3203 GPCM90 05 00 by-server
    503 STATUS 05 00 by-server

      4 GPCM90 06 08 by-server

   7105 STATUS 07 08 peer-to-peer

   1151 STATUS 0d 04 peer-to-peer

   1191 STATUS 0e 00 peer-to-peer

   1169 STATUS 0f 00 peer-to-peer

      3 GPCM90 10 00 by-server
     13 STATUS 10 00 peer-to-peer
      7 GPCM90 10 04 by-server
     22 STATUS 10 04 peer-to-peer
      1 GPCM90 10 08 by-server
      3 STATUS 10 08 peer-to-peer

    262 STATUS 52 04 peer-to-peer

    436 STATUS 53 00 peer-to-peer

     31 STATUS 54 00 peer-to-peer

     23 STATUS 55 04 peer-to-peer

     13 STATUS 82 08 by-server
  19987 STATUS 82 08 peer-to-peer
     20 STATUS 82 10 by-server
  29343 STATUS 82 10 peer-to-peer

    237 STATUS 83 0c by-server
 320349 STATUS 83 0c peer-to-peer

Old data structures

This is the old data structure in GNU C notation used by mkw-ana from the beginning. It is deprecated and will be removed later.

typedef struct udp_status_t
{
  /*00*/    u32		record_id;	// always 0xbb49cc4d (be)
  /*04*/    u32		unknown_04;	// always 0x5a000000 (be)
  /*08*/    u8		subtype_id;     // indicating the record sub type
  /*09*/    u8		ext_len;	// length of record extension
					//   total_record_len := '0x14 + ext_len'
  /*0a*/    u16		user_id[3];	// unique user id for this session ?
  /*10*/    u32		cid;		// client id:
					//   last 4 bytes of FC in reverse order
  /*14*/

    union
    {
	struct	// send by host, any anouncement?
	{
  /*14*/    u32		obj_cid;	// client id of object
  /*18*/
	} s04;

	struct	// assign slot
		// => exception 'x x 7100 0514' found in 2013-01-24-ct-24h
	{
  /*14*/    u32		obj_cid;	// client id of object
  /*18*/    u8		slot;		// assign slot to 'obj_cid'
  /*19*/    u8		padding_19[3];	// always 0
  /*1c*/
	} s08;

	struct	// send by host, client mask
	{
  /*14*/    u32		copy_of_cid;	// copy of 'cid' above
  /*18*/    u16		slot_mask;	// slot usage mask in little endian
					//   each 1-bit represents one active client
  /*1a*/    u16		unknown_1a;	// always 0
  /*1e*/    u32		unknown_1c;	// any checksum or random token?
  /*20*/
	} s0c;

	struct	// to host, verify assigned slot?
	{
  /*14*/    u32		obj_cid;	// copy of 'cid' above
  /*18*/    u16		unknown_18;	// always 0x0000|0x0100 (be)
  /*1a*/    u16		unknown_1a;	// always 0
  /*1c*/    u16		unknown_1c;	// always 0x0000|0x0100 (be)
  /*1e*/    u16		unknown_1e;	// always 0
  /*20*/    u8		slot;		// assigned slot of 'obj_cid'
					//   or 0x1f or 0xff
  /*21*/    u8		padding_21[3];	// always 0
  /*22*/
	} s10;
    };
}
__attribute__ ((packed)) udp_status_t;