18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/* packet.h: Rx packet layout and definitions
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
58c2ecf20Sopenharmony_ci * Written by David Howells (dhowells@redhat.com)
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _LINUX_RXRPC_PACKET_H
98c2ecf20Sopenharmony_ci#define _LINUX_RXRPC_PACKET_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_citypedef u32	rxrpc_seq_t;	/* Rx message sequence number */
128c2ecf20Sopenharmony_citypedef u32	rxrpc_serial_t;	/* Rx message serial number */
138c2ecf20Sopenharmony_citypedef __be32	rxrpc_seq_net_t; /* on-the-wire Rx message sequence number */
148c2ecf20Sopenharmony_citypedef __be32	rxrpc_serial_net_t; /* on-the-wire Rx message serial number */
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/*****************************************************************************/
178c2ecf20Sopenharmony_ci/*
188c2ecf20Sopenharmony_ci * on-the-wire Rx packet header
198c2ecf20Sopenharmony_ci * - all multibyte fields should be in network byte order
208c2ecf20Sopenharmony_ci */
218c2ecf20Sopenharmony_cistruct rxrpc_wire_header {
228c2ecf20Sopenharmony_ci	__be32		epoch;		/* client boot timestamp */
238c2ecf20Sopenharmony_ci#define RXRPC_RANDOM_EPOCH	0x80000000	/* Random if set, date-based if not */
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	__be32		cid;		/* connection and channel ID */
268c2ecf20Sopenharmony_ci#define RXRPC_MAXCALLS		4			/* max active calls per conn */
278c2ecf20Sopenharmony_ci#define RXRPC_CHANNELMASK	(RXRPC_MAXCALLS-1)	/* mask for channel ID */
288c2ecf20Sopenharmony_ci#define RXRPC_CIDMASK		(~RXRPC_CHANNELMASK)	/* mask for connection ID */
298c2ecf20Sopenharmony_ci#define RXRPC_CIDSHIFT		ilog2(RXRPC_MAXCALLS)	/* shift for connection ID */
308c2ecf20Sopenharmony_ci#define RXRPC_CID_INC		(1 << RXRPC_CIDSHIFT)	/* connection ID increment */
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	__be32		callNumber;	/* call ID (0 for connection-level packets) */
338c2ecf20Sopenharmony_ci	__be32		seq;		/* sequence number of pkt in call stream */
348c2ecf20Sopenharmony_ci	__be32		serial;		/* serial number of pkt sent to network */
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	uint8_t		type;		/* packet type */
378c2ecf20Sopenharmony_ci#define RXRPC_PACKET_TYPE_DATA		1	/* data */
388c2ecf20Sopenharmony_ci#define RXRPC_PACKET_TYPE_ACK		2	/* ACK */
398c2ecf20Sopenharmony_ci#define RXRPC_PACKET_TYPE_BUSY		3	/* call reject */
408c2ecf20Sopenharmony_ci#define RXRPC_PACKET_TYPE_ABORT		4	/* call/connection abort */
418c2ecf20Sopenharmony_ci#define RXRPC_PACKET_TYPE_ACKALL	5	/* ACK all outstanding packets on call */
428c2ecf20Sopenharmony_ci#define RXRPC_PACKET_TYPE_CHALLENGE	6	/* connection security challenge (SRVR->CLNT) */
438c2ecf20Sopenharmony_ci#define RXRPC_PACKET_TYPE_RESPONSE	7	/* connection secutity response (CLNT->SRVR) */
448c2ecf20Sopenharmony_ci#define RXRPC_PACKET_TYPE_DEBUG		8	/* debug info request */
458c2ecf20Sopenharmony_ci#define RXRPC_PACKET_TYPE_PARAMS	9	/* Parameter negotiation (unspec'd, ignore) */
468c2ecf20Sopenharmony_ci#define RXRPC_PACKET_TYPE_10		10	/* Ignored */
478c2ecf20Sopenharmony_ci#define RXRPC_PACKET_TYPE_11		11	/* Ignored */
488c2ecf20Sopenharmony_ci#define RXRPC_PACKET_TYPE_VERSION	13	/* version string request */
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	uint8_t		flags;		/* packet flags */
518c2ecf20Sopenharmony_ci#define RXRPC_CLIENT_INITIATED	0x01		/* signifies a packet generated by a client */
528c2ecf20Sopenharmony_ci#define RXRPC_REQUEST_ACK	0x02		/* request an unconditional ACK of this packet */
538c2ecf20Sopenharmony_ci#define RXRPC_LAST_PACKET	0x04		/* the last packet from this side for this call */
548c2ecf20Sopenharmony_ci#define RXRPC_MORE_PACKETS	0x08		/* more packets to come */
558c2ecf20Sopenharmony_ci#define RXRPC_JUMBO_PACKET	0x20		/* [DATA] this is a jumbo packet */
568c2ecf20Sopenharmony_ci#define RXRPC_SLOW_START_OK	0x20		/* [ACK] slow start supported */
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci	uint8_t		userStatus;	/* app-layer defined status */
598c2ecf20Sopenharmony_ci#define RXRPC_USERSTATUS_SERVICE_UPGRADE 0x01	/* AuriStor service upgrade request */
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	uint8_t		securityIndex;	/* security protocol ID */
628c2ecf20Sopenharmony_ci	union {
638c2ecf20Sopenharmony_ci		__be16	_rsvd;		/* reserved */
648c2ecf20Sopenharmony_ci		__be16	cksum;		/* kerberos security checksum */
658c2ecf20Sopenharmony_ci	};
668c2ecf20Sopenharmony_ci	__be16		serviceId;	/* service ID */
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci} __packed;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/*****************************************************************************/
718c2ecf20Sopenharmony_ci/*
728c2ecf20Sopenharmony_ci * jumbo packet secondary header
738c2ecf20Sopenharmony_ci * - can be mapped to read header by:
748c2ecf20Sopenharmony_ci *   - new_serial = serial + 1
758c2ecf20Sopenharmony_ci *   - new_seq = seq + 1
768c2ecf20Sopenharmony_ci *   - new_flags = j_flags
778c2ecf20Sopenharmony_ci *   - new__rsvd = j__rsvd
788c2ecf20Sopenharmony_ci *   - duplicating all other fields
798c2ecf20Sopenharmony_ci */
808c2ecf20Sopenharmony_cistruct rxrpc_jumbo_header {
818c2ecf20Sopenharmony_ci	uint8_t		flags;		/* packet flags (as per rxrpc_header) */
828c2ecf20Sopenharmony_ci	uint8_t		pad;
838c2ecf20Sopenharmony_ci	union {
848c2ecf20Sopenharmony_ci		__be16	_rsvd;		/* reserved */
858c2ecf20Sopenharmony_ci		__be16	cksum;		/* kerberos security checksum */
868c2ecf20Sopenharmony_ci	};
878c2ecf20Sopenharmony_ci};
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define RXRPC_JUMBO_DATALEN	1412	/* non-terminal jumbo packet data length */
908c2ecf20Sopenharmony_ci#define RXRPC_JUMBO_SUBPKTLEN	(RXRPC_JUMBO_DATALEN + sizeof(struct rxrpc_jumbo_header))
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/*
938c2ecf20Sopenharmony_ci * The maximum number of subpackets that can possibly fit in a UDP packet is:
948c2ecf20Sopenharmony_ci *
958c2ecf20Sopenharmony_ci *	((max_IP - IP_hdr - UDP_hdr) / RXRPC_JUMBO_SUBPKTLEN) + 1
968c2ecf20Sopenharmony_ci *	= ((65535 - 28 - 28) / 1416) + 1
978c2ecf20Sopenharmony_ci *	= 46 non-terminal packets and 1 terminal packet.
988c2ecf20Sopenharmony_ci */
998c2ecf20Sopenharmony_ci#define RXRPC_MAX_NR_JUMBO	47
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci/*****************************************************************************/
1028c2ecf20Sopenharmony_ci/*
1038c2ecf20Sopenharmony_ci * on-the-wire Rx ACK packet data payload
1048c2ecf20Sopenharmony_ci * - all multibyte fields should be in network byte order
1058c2ecf20Sopenharmony_ci */
1068c2ecf20Sopenharmony_cistruct rxrpc_ackpacket {
1078c2ecf20Sopenharmony_ci	__be16		bufferSpace;	/* number of packet buffers available */
1088c2ecf20Sopenharmony_ci	__be16		maxSkew;	/* diff between serno being ACK'd and highest serial no
1098c2ecf20Sopenharmony_ci					 * received */
1108c2ecf20Sopenharmony_ci	__be32		firstPacket;	/* sequence no of first ACK'd packet in attached list */
1118c2ecf20Sopenharmony_ci	__be32		previousPacket;	/* sequence no of previous packet received */
1128c2ecf20Sopenharmony_ci	__be32		serial;		/* serial no of packet that prompted this ACK */
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	uint8_t		reason;		/* reason for ACK */
1158c2ecf20Sopenharmony_ci#define RXRPC_ACK_REQUESTED		1	/* ACK was requested on packet */
1168c2ecf20Sopenharmony_ci#define RXRPC_ACK_DUPLICATE		2	/* duplicate packet received */
1178c2ecf20Sopenharmony_ci#define RXRPC_ACK_OUT_OF_SEQUENCE	3	/* out of sequence packet received */
1188c2ecf20Sopenharmony_ci#define RXRPC_ACK_EXCEEDS_WINDOW	4	/* packet received beyond end of ACK window */
1198c2ecf20Sopenharmony_ci#define RXRPC_ACK_NOSPACE		5	/* packet discarded due to lack of buffer space */
1208c2ecf20Sopenharmony_ci#define RXRPC_ACK_PING			6	/* keep alive ACK */
1218c2ecf20Sopenharmony_ci#define RXRPC_ACK_PING_RESPONSE		7	/* response to RXRPC_ACK_PING */
1228c2ecf20Sopenharmony_ci#define RXRPC_ACK_DELAY			8	/* nothing happened since received packet */
1238c2ecf20Sopenharmony_ci#define RXRPC_ACK_IDLE			9	/* ACK due to fully received ACK window */
1248c2ecf20Sopenharmony_ci#define RXRPC_ACK__INVALID		10	/* Representation of invalid ACK reason */
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	uint8_t		nAcks;		/* number of ACKs */
1278c2ecf20Sopenharmony_ci#define RXRPC_MAXACKS	255
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	uint8_t		acks[0];	/* list of ACK/NAKs */
1308c2ecf20Sopenharmony_ci#define RXRPC_ACK_TYPE_NACK		0
1318c2ecf20Sopenharmony_ci#define RXRPC_ACK_TYPE_ACK		1
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci} __packed;
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci/* Some ACKs refer to specific packets and some are general and can be updated. */
1368c2ecf20Sopenharmony_ci#define RXRPC_ACK_UPDATEABLE ((1 << RXRPC_ACK_REQUESTED)	|	\
1378c2ecf20Sopenharmony_ci			      (1 << RXRPC_ACK_PING_RESPONSE)	|	\
1388c2ecf20Sopenharmony_ci			      (1 << RXRPC_ACK_DELAY)		|	\
1398c2ecf20Sopenharmony_ci			      (1 << RXRPC_ACK_IDLE))
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci/*
1438c2ecf20Sopenharmony_ci * ACK packets can have a further piece of information tagged on the end
1448c2ecf20Sopenharmony_ci */
1458c2ecf20Sopenharmony_cistruct rxrpc_ackinfo {
1468c2ecf20Sopenharmony_ci	__be32		rxMTU;		/* maximum Rx MTU size (bytes) [AFS 3.3] */
1478c2ecf20Sopenharmony_ci	__be32		maxMTU;		/* maximum interface MTU size (bytes) [AFS 3.3] */
1488c2ecf20Sopenharmony_ci	__be32		rwind;		/* Rx window size (packets) [AFS 3.4] */
1498c2ecf20Sopenharmony_ci	__be32		jumbo_max;	/* max packets to stick into a jumbo packet [AFS 3.5] */
1508c2ecf20Sopenharmony_ci};
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/*****************************************************************************/
1538c2ecf20Sopenharmony_ci/*
1548c2ecf20Sopenharmony_ci * Kerberos security type-2 challenge packet
1558c2ecf20Sopenharmony_ci */
1568c2ecf20Sopenharmony_cistruct rxkad_challenge {
1578c2ecf20Sopenharmony_ci	__be32		version;	/* version of this challenge type */
1588c2ecf20Sopenharmony_ci	__be32		nonce;		/* encrypted random number */
1598c2ecf20Sopenharmony_ci	__be32		min_level;	/* minimum security level */
1608c2ecf20Sopenharmony_ci	__be32		__padding;	/* padding to 8-byte boundary */
1618c2ecf20Sopenharmony_ci} __packed;
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci/*****************************************************************************/
1648c2ecf20Sopenharmony_ci/*
1658c2ecf20Sopenharmony_ci * Kerberos security type-2 response packet
1668c2ecf20Sopenharmony_ci */
1678c2ecf20Sopenharmony_cistruct rxkad_response {
1688c2ecf20Sopenharmony_ci	__be32		version;	/* version of this response type */
1698c2ecf20Sopenharmony_ci	__be32		__pad;
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	/* encrypted bit of the response */
1728c2ecf20Sopenharmony_ci	struct {
1738c2ecf20Sopenharmony_ci		__be32		epoch;		/* current epoch */
1748c2ecf20Sopenharmony_ci		__be32		cid;		/* parent connection ID */
1758c2ecf20Sopenharmony_ci		__be32		checksum;	/* checksum */
1768c2ecf20Sopenharmony_ci		__be32		securityIndex;	/* security type */
1778c2ecf20Sopenharmony_ci		__be32		call_id[4];	/* encrypted call IDs */
1788c2ecf20Sopenharmony_ci		__be32		inc_nonce;	/* challenge nonce + 1 */
1798c2ecf20Sopenharmony_ci		__be32		level;		/* desired level */
1808c2ecf20Sopenharmony_ci	} encrypted;
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	__be32		kvno;		/* Kerberos key version number */
1838c2ecf20Sopenharmony_ci	__be32		ticket_len;	/* Kerberos ticket length  */
1848c2ecf20Sopenharmony_ci} __packed;
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci#endif /* _LINUX_RXRPC_PACKET_H */
187