18c2ecf20Sopenharmony_ci#ifndef _SLHC_H
28c2ecf20Sopenharmony_ci#define _SLHC_H
38c2ecf20Sopenharmony_ci/*
48c2ecf20Sopenharmony_ci * Definitions for tcp compression routines.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * $Header: slcompress.h,v 1.10 89/12/31 08:53:02 van Exp $
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Copyright (c) 1989 Regents of the University of California.
98c2ecf20Sopenharmony_ci * All rights reserved.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms are permitted
128c2ecf20Sopenharmony_ci * provided that the above copyright notice and this paragraph are
138c2ecf20Sopenharmony_ci * duplicated in all such forms and that any documentation,
148c2ecf20Sopenharmony_ci * advertising materials, and other materials related to such
158c2ecf20Sopenharmony_ci * distribution and use acknowledge that the software was developed
168c2ecf20Sopenharmony_ci * by the University of California, Berkeley.  The name of the
178c2ecf20Sopenharmony_ci * University may not be used to endorse or promote products derived
188c2ecf20Sopenharmony_ci * from this software without specific prior written permission.
198c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
208c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
218c2ecf20Sopenharmony_ci * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci *	Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
248c2ecf20Sopenharmony_ci *	- Initial distribution.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * modified for KA9Q Internet Software Package by
288c2ecf20Sopenharmony_ci * Katie Stevens (dkstevens@ucdavis.edu)
298c2ecf20Sopenharmony_ci * University of California, Davis
308c2ecf20Sopenharmony_ci * Computing Services
318c2ecf20Sopenharmony_ci *	- 01-31-90	initial adaptation
328c2ecf20Sopenharmony_ci *
338c2ecf20Sopenharmony_ci *	- Feb 1991	Bill_Simpson@um.cc.umich.edu
348c2ecf20Sopenharmony_ci *			variable number of conversation slots
358c2ecf20Sopenharmony_ci *			allow zero or one slots
368c2ecf20Sopenharmony_ci *			separate routines
378c2ecf20Sopenharmony_ci *			status display
388c2ecf20Sopenharmony_ci */
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/*
418c2ecf20Sopenharmony_ci * Compressed packet format:
428c2ecf20Sopenharmony_ci *
438c2ecf20Sopenharmony_ci * The first octet contains the packet type (top 3 bits), TCP
448c2ecf20Sopenharmony_ci * 'push' bit, and flags that indicate which of the 4 TCP sequence
458c2ecf20Sopenharmony_ci * numbers have changed (bottom 5 bits).  The next octet is a
468c2ecf20Sopenharmony_ci * conversation number that associates a saved IP/TCP header with
478c2ecf20Sopenharmony_ci * the compressed packet.  The next two octets are the TCP checksum
488c2ecf20Sopenharmony_ci * from the original datagram.  The next 0 to 15 octets are
498c2ecf20Sopenharmony_ci * sequence number changes, one change per bit set in the header
508c2ecf20Sopenharmony_ci * (there may be no changes and there are two special cases where
518c2ecf20Sopenharmony_ci * the receiver implicitly knows what changed -- see below).
528c2ecf20Sopenharmony_ci *
538c2ecf20Sopenharmony_ci * There are 5 numbers which can change (they are always inserted
548c2ecf20Sopenharmony_ci * in the following order): TCP urgent pointer, window,
558c2ecf20Sopenharmony_ci * acknowledgment, sequence number and IP ID.  (The urgent pointer
568c2ecf20Sopenharmony_ci * is different from the others in that its value is sent, not the
578c2ecf20Sopenharmony_ci * change in value.)  Since typical use of SLIP links is biased
588c2ecf20Sopenharmony_ci * toward small packets (see comments on MTU/MSS below), changes
598c2ecf20Sopenharmony_ci * use a variable length coding with one octet for numbers in the
608c2ecf20Sopenharmony_ci * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
618c2ecf20Sopenharmony_ci * range 256 - 65535 or 0.  (If the change in sequence number or
628c2ecf20Sopenharmony_ci * ack is more than 65535, an uncompressed packet is sent.)
638c2ecf20Sopenharmony_ci */
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/*
668c2ecf20Sopenharmony_ci * Packet types (must not conflict with IP protocol version)
678c2ecf20Sopenharmony_ci *
688c2ecf20Sopenharmony_ci * The top nibble of the first octet is the packet type.  There are
698c2ecf20Sopenharmony_ci * three possible types: IP (not proto TCP or tcp with one of the
708c2ecf20Sopenharmony_ci * control flags set); uncompressed TCP (a normal IP/TCP packet but
718c2ecf20Sopenharmony_ci * with the 8-bit protocol field replaced by an 8-bit connection id --
728c2ecf20Sopenharmony_ci * this type of packet syncs the sender & receiver); and compressed
738c2ecf20Sopenharmony_ci * TCP (described above).
748c2ecf20Sopenharmony_ci *
758c2ecf20Sopenharmony_ci * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
768c2ecf20Sopenharmony_ci * is logically part of the 4-bit "changes" field that follows.  Top
778c2ecf20Sopenharmony_ci * three bits are actual packet type.  For backward compatibility
788c2ecf20Sopenharmony_ci * and in the interest of conserving bits, numbers are chosen so the
798c2ecf20Sopenharmony_ci * IP protocol version number (4) which normally appears in this nibble
808c2ecf20Sopenharmony_ci * means "IP packet".
818c2ecf20Sopenharmony_ci */
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#include <linux/ip.h>
858c2ecf20Sopenharmony_ci#include <linux/tcp.h>
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/* SLIP compression masks for len/vers byte */
888c2ecf20Sopenharmony_ci#define SL_TYPE_IP 0x40
898c2ecf20Sopenharmony_ci#define SL_TYPE_UNCOMPRESSED_TCP 0x70
908c2ecf20Sopenharmony_ci#define SL_TYPE_COMPRESSED_TCP 0x80
918c2ecf20Sopenharmony_ci#define SL_TYPE_ERROR 0x00
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/* Bits in first octet of compressed packet */
948c2ecf20Sopenharmony_ci#define NEW_C	0x40	/* flag bits for what changed in a packet */
958c2ecf20Sopenharmony_ci#define NEW_I	0x20
968c2ecf20Sopenharmony_ci#define NEW_S	0x08
978c2ecf20Sopenharmony_ci#define NEW_A	0x04
988c2ecf20Sopenharmony_ci#define NEW_W	0x02
998c2ecf20Sopenharmony_ci#define NEW_U	0x01
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci/* reserved, special-case values of above */
1028c2ecf20Sopenharmony_ci#define SPECIAL_I (NEW_S|NEW_W|NEW_U)		/* echoed interactive traffic */
1038c2ecf20Sopenharmony_ci#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)	/* unidirectional data */
1048c2ecf20Sopenharmony_ci#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#define TCP_PUSH_BIT 0x10
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/*
1098c2ecf20Sopenharmony_ci * data type and sizes conversion assumptions:
1108c2ecf20Sopenharmony_ci *
1118c2ecf20Sopenharmony_ci *	VJ code		KA9Q style	generic
1128c2ecf20Sopenharmony_ci *	u_char		byte_t		unsigned char	 8 bits
1138c2ecf20Sopenharmony_ci *	u_short		int16		unsigned short	16 bits
1148c2ecf20Sopenharmony_ci *	u_int		int16		unsigned short	16 bits
1158c2ecf20Sopenharmony_ci *	u_long		unsigned long	unsigned long	32 bits
1168c2ecf20Sopenharmony_ci *	int		int32		long		32 bits
1178c2ecf20Sopenharmony_ci */
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_citypedef __u8 byte_t;
1208c2ecf20Sopenharmony_citypedef __u32 int32;
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci/*
1238c2ecf20Sopenharmony_ci * "state" data for each active tcp conversation on the wire.  This is
1248c2ecf20Sopenharmony_ci * basically a copy of the entire IP/TCP header from the last packet
1258c2ecf20Sopenharmony_ci * we saw from the conversation together with a small identifier
1268c2ecf20Sopenharmony_ci * the transmit & receive ends of the line use to locate saved header.
1278c2ecf20Sopenharmony_ci */
1288c2ecf20Sopenharmony_cistruct cstate {
1298c2ecf20Sopenharmony_ci	byte_t	cs_this;	/* connection id number (xmit) */
1308c2ecf20Sopenharmony_ci	bool	initialized;	/* true if initialized */
1318c2ecf20Sopenharmony_ci	struct cstate *next;	/* next in ring (xmit) */
1328c2ecf20Sopenharmony_ci	struct iphdr cs_ip;	/* ip/tcp hdr from most recent packet */
1338c2ecf20Sopenharmony_ci	struct tcphdr cs_tcp;
1348c2ecf20Sopenharmony_ci	unsigned char cs_ipopt[64];
1358c2ecf20Sopenharmony_ci	unsigned char cs_tcpopt[64];
1368c2ecf20Sopenharmony_ci	int cs_hsize;
1378c2ecf20Sopenharmony_ci};
1388c2ecf20Sopenharmony_ci#define NULLSLSTATE	(struct cstate *)0
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci/*
1418c2ecf20Sopenharmony_ci * all the state data for one serial line (we need one of these per line).
1428c2ecf20Sopenharmony_ci */
1438c2ecf20Sopenharmony_cistruct slcompress {
1448c2ecf20Sopenharmony_ci	struct cstate *tstate;	/* transmit connection states (array)*/
1458c2ecf20Sopenharmony_ci	struct cstate *rstate;	/* receive connection states (array)*/
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	byte_t tslot_limit;	/* highest transmit slot id (0-l)*/
1488c2ecf20Sopenharmony_ci	byte_t rslot_limit;	/* highest receive slot id (0-l)*/
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	byte_t xmit_oldest;	/* oldest xmit in ring */
1518c2ecf20Sopenharmony_ci	byte_t xmit_current;	/* most recent xmit id */
1528c2ecf20Sopenharmony_ci	byte_t recv_current;	/* most recent rcvd id */
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	byte_t flags;
1558c2ecf20Sopenharmony_ci#define SLF_TOSS	0x01	/* tossing rcvd frames until id received */
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	int32 sls_o_nontcp;	/* outbound non-TCP packets */
1588c2ecf20Sopenharmony_ci	int32 sls_o_tcp;	/* outbound TCP packets */
1598c2ecf20Sopenharmony_ci	int32 sls_o_uncompressed;	/* outbound uncompressed packets */
1608c2ecf20Sopenharmony_ci	int32 sls_o_compressed;	/* outbound compressed packets */
1618c2ecf20Sopenharmony_ci	int32 sls_o_searches;	/* searches for connection state */
1628c2ecf20Sopenharmony_ci	int32 sls_o_misses;	/* times couldn't find conn. state */
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	int32 sls_i_uncompressed;	/* inbound uncompressed packets */
1658c2ecf20Sopenharmony_ci	int32 sls_i_compressed;	/* inbound compressed packets */
1668c2ecf20Sopenharmony_ci	int32 sls_i_error;	/* inbound error packets */
1678c2ecf20Sopenharmony_ci	int32 sls_i_tossed;	/* inbound packets tossed because of error */
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	int32 sls_i_runt;
1708c2ecf20Sopenharmony_ci	int32 sls_i_badcheck;
1718c2ecf20Sopenharmony_ci};
1728c2ecf20Sopenharmony_ci#define NULLSLCOMPR	(struct slcompress *)0
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci/* In slhc.c: */
1758c2ecf20Sopenharmony_cistruct slcompress *slhc_init(int rslots, int tslots);
1768c2ecf20Sopenharmony_civoid slhc_free(struct slcompress *comp);
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ciint slhc_compress(struct slcompress *comp, unsigned char *icp, int isize,
1798c2ecf20Sopenharmony_ci		  unsigned char *ocp, unsigned char **cpp, int compress_cid);
1808c2ecf20Sopenharmony_ciint slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize);
1818c2ecf20Sopenharmony_ciint slhc_remember(struct slcompress *comp, unsigned char *icp, int isize);
1828c2ecf20Sopenharmony_ciint slhc_toss(struct slcompress *comp);
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci#endif	/* _SLHC_H */
185