Home docs pia LAN Protocol
Post

LAN Protocol

This page describes the protocol that’s used to find nearby consoles in LAN mode. In this mode, UDP broadcast packets are used to discover other consoles. LAN mode is not the default mode for local multiplayer and not all games support it. It can usually be enabled by pressing L + R + Left Stick in one of the menus.

Every packet starts with a single byte that indicates its type.

Packet types

(0) Browse Request

Up to 5.44:

This packet is sent through UDP broadcast port 30000. It is sent in plain text, and is not encapsulated in a Pia packet.

6.16 - 6.30:

This packet is sent through port 35000 instead.

Up to 5.6:

OffsetSizeDescription
0x01Packet type (0)
0x14Size of search criteria (0x23A)
0x50x23ALanSessionSearchCriteria

5.7 - 5.44:

OffsetSizeDescription
0x01Packet type (0)
0x14Size of search criteria (0x23A)
0x50x23ALanSessionSearchCriteria
0x23F0x12ACrypto challenge

6.16 - 6.30:

OffsetSizeDescription
0x01Packet type (0)
0x14Size of search network setting (0x16)
0x2 LanSearchNetworkSetting
 0x12ACrypto challenge

LanSessionSearchCriteria

Up to 5.44:

OffsetSizeDescription
0x04Minimum number of participants (range)
0x44Maximum number of participants (range)
0x81Opened only
0x91Vacant only
0xA4Result range offset
0xE4Result range size
0x124Game mode
0x164Session type
0x1A0x50 * 6Attribute lists
0x1FA1 * 6Number of attributes
0x2004 * 6Attribute range min
0x2184 * 6Attribute range max
0x2301 * 6Is attribute range used
0x2364Search flags

Search flags

These flags indicate which fields are compared against the active session to determine if there is a match.

MaskDescription
0x1Minimum number of participants
0x2Maximum number of participants
0x4Opened only
0x8Vacant only
0x10Game mode
0x20Session type
0x40First attribute list
0x800Last attribute list

Range

OffsetSizeDescription
0x02Maximum
0x22Minimum

Attribute list

Each attribute list may contain up to 20 attributes. Every attribute is stored as a 4-byte integer.

LanSearchNetworkSetting

6.16 - 6.20:

OffsetSizeDescription
0x08Matchmake key
0x82Maximum number of stations (upper bound)
0xA2Maximum number of stations (lower bound)
0xC2Search flags

6.23 - 6.30:

OffsetSizeDescription
0x08Matchmake key
0x82Maximum number of stations (upper bound)
0xA2Maximum number of stations (lower bound)
0xC2Search flags
0xE8Title id

Search Flags

These flags indicate which fields are compared against the active session to determine if there is a match.

6.16 - 6.26:

MaskDescription
0x1Matchmake key
0x2Maximum number of stations
0x4Opened only
0x8Vacant only

6.29 - 6.30:

MaskDescription
0x1Ignored
0x2Matchmake key
0x4Maximum number of stations
0x8Opened only
0x10Vacant only

(1) Browse reply

This packet is sent to the source of the browse request in plain text, and is not encapsulated in a Pia packet.

Up to 5.6:

TypeDescription
Uint8Packet type (1)
Uint32Size of session info
LanSessionInfoSession info

5.7 - 5.44:

TypeDescription
Uint8Packet type (1)
Uint32Size of session info
LanSessionInfoSession info
BytesCrypto challenge reply

6.29 - 6.30:

TypeDescription
Uint8Packet type (1)
Uint32Size of network property
LanNetworkPropertyNetwork property
BytesCrypto challenge reply

LanSessionInfo

Up to 5.2:

TypeDescription
Uint32Game mode
Uint32Session id
Uint32 (x6)Attributes
Uint16Current number of participants
Uint16Minimum number of participants
Uint16Maximum number of participants
Uint32Session type
Bytes (0x180)Application data
Uint32Application data size
BoolIs opened
StationLocationHost address
LanStationInfo (x16)Station info of every player in the room

5.3 - 5.6:

TypeDescription
Uint32Game mode
Uint32Session id
Uint32 (x6)Attributes
Uint16Current number of participants
Uint16Minimum number of participants
Uint16Maximum number of participants
Uint8System communication version
Uint8Application communication version
Uint16Session type
Bytes (0x180)Application data
Uint32Application data size
BoolIs opened
StationLocationHost address
LanStationInfo (x16)Station info of every player in the room

5.7 - 5.9:

TypeDescription
Uint32Game mode
Uint32Session id
Uint32 (x6)Attributes
Uint16Current number of participants
Uint16Minimum number of participants
Uint16Maximum number of participants
Uint8System communication version
Uint8Application communication version
Uint16Session type
Bytes (0x180)Application data
Uint32Application data size
BoolIs opened
StationLocationHost address
LanStationInfo (x16)Station info of every player in the room
Bytes (0x20)Session key param

5.10 - 5.44:

TypeDescription
Uint32Game mode
Uint32Session id
Uint32 (x6)Attributes
Uint16Current number of participants
Uint16Minimum number of participants
Uint16Maximum number of participants
Uint8System communication version
Uint8Application communication version
Uint16Session type
Bytes (0x180)Application data
Uint32Application data size
BoolIs opened
StationAddressHost address
Uint64Host constant id
Uint32Host variable id
Uint32Host service variable id
LanStationInfo (x16)Station info of every player in the room
Bytes (0x20)Session key param

LanStationInfo

OffsetSizeDescription
0x01Role (1=host, 2=player)
0x11Username encoding type (1=utf8, 2=utf16)
0x240Username
0x2A8Station id

LanNetworkProperty

6.29 - 6.30:

OffsetSizeDescription
0x08Network id
0x80x200Property data and padding
0x2084Property data size
0x20C8Matchmake key
0x2142Current number of stations
0x2162Maximum number of stations
0x2181Is opened
0x2191Has player number limit
0x21A1Current number of players
0x21B0x12Host address (StationAddress)

Property Data

If the application data consumes less than 0x184 bytes, this is reflected in the property data size field in the LanNetworkProperty structure.

OffsetSizeDescription
0x00x7CSystem property data
0x7CUp to 0x184Application data

System Property Data

OffsetSizeDescription
0x02System property data size (0x7C)
0x21System communication version
0x32Application communication version
0x516User password
0x151Has player number limit
0x161Current number of players
0x174Host player name size
0x1B1Host player name encoding (1=utf8, 2=utf16)
0x1C64Host player name and padding
0x5C32Session key param

System Communication Version

VersionPia Version
05.3
25.6
35.7
45.8
55.9
65.10
75.11 - 5.18
85.19 - 5.44
106.16 - 6.30

(3) Host Request

This packet is sent through UDP broadcast ports 49152 - 49155 and is encapsulated in a Pia message. The message payload contains the following data and is encrypted with the session key:

Up to 5.44:

OffsetSizeDescription
0x01Message type (3)
0x111Padding (always 0)
0xC4Session id

(4) Host Message

This message is encapsulated in a Pia message and is encrypted with the session key.

Up to 5.9:

OffsetSizeDescription
0x01Message type (4)
0x111Padding (always 0)
0xC4Session id
0x10 StationConnectionInfo for host

5.10 - 5.44:

OffsetSizeDescription
0x01Message type (4)
0x111Padding (always 0)
0xC4Session id
0x10 StationLocation for host

(5) Session Request

This packet is sent through UDP broadcast ports 49152 - 49155 and is encapsulated in a Pia message. The message payload contains the following data and is encrypted with the session key:

Up to 5.44:

OffsetSizeDescription
0x01Message type (5)
0x111Padding (always 0)
0xC4Session id

(6) Session Message

This message is encapsulated in a Pia message and is encrypted with the session key. The goal of this message is to transmit a LanSessionInfo structure. Depending on the size of the LanSessionInfo, this message may be split into multiple fragments. Each fragment contains up to 800 bytes of data.

Whenever the session is updated, a session message is sent through UDP broadcast port 49152 - 49155. A session message is also sent to a specific station when the station requests an update with a session request.

Up to 5.44:

OffsetSizeDescription
0x01Message type (6)
0x111Padding (always 0)
0xC4This is a random value that must be the same in all fragments that belong to the same session message. This is used to distinguish different session replies.
0x102Session message id. This is an incrementing number that should be the same in all fragments that belong to the same session message.
0x121Fragment index
0x131Number of fragments
0x144Fragment size
0x18 Fragment data

(7) Keep Alive Message

This packet is sent through UDP broadcast port 49152 and is encapsulated in a Pia message. This message is sent once every two seconds, even if the console is not participating in a session. If the console is participating in a session, the message payload is encrypted with the session key. Otherwise, the payload is not encrypted. The message payload contains the following data:

Up to 5.44:

OffsetSizeDescription
0x01Message type (7)
0x111Padding (always 0)

Crypto Challenge

In Pia version 5.7 and later, the browse request contains a cryptographic challenge that must be correctly answered in the browse reply. Both the challenge and the response have the following format:

OffsetSizeDescription
0x01Version
0x11Crypto enabled (0 or 1)
0x28Incrementing counter used for nonce
0xA16Challenge key (random bytes)
0x1A16Authentication tag for AES-GCM
0x2A256 or 16Challenge or response, encrypted with AES-GCM

The content of the challenge/response when crypto is enabled is described below. If crypto is disabled the authentication tag and challenge/response data are filled with random bytes.

The nonce for the AES-GCM algorithm is generated as follows:

OffsetSizeDescription
0x04Broadcast address (local_address | ~subnet_mask)
0x48Nonce counter

Version

The crypto challenge is the same in all versions.

VersionPia version
15.7 - 5.10
25.11 - 5.44
36.16 - 6.30

Challenge

The challenge consists of 256 random bytes. The key for encrypting the challenge is generated by AES-encrypting the challenge key with a game-specific key.

Response

The response contains the first 16 bytes of the HMAC-SHA256 of the decrypted challenge with a game-specific key. The key for encrypting the response is the first 16 bytes of the HMAC-SHA256 of the session key param with the game-specific key:

Session Key Param

The session key param are used to derive the challenge response key.

OffsetSizeDescription
0x016Challenge key in browse response
0x1016Challenge key received in browse request

When the host receives a valid browse request for the first time, it saves the session key param in the LanSessionInfo or LanNetworkProperty structure. This is used to derive the session key.

Contents