xref: /original-bsd/sys/netiso/tp_param.h (revision 3705696b)
1 /*-
2  * Copyright (c) 1991, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)tp_param.h	8.1 (Berkeley) 06/10/93
8  */
9 
10 /***********************************************************
11 		Copyright IBM Corporation 1987
12 
13                       All Rights Reserved
14 
15 Permission to use, copy, modify, and distribute this software and its
16 documentation for any purpose and without fee is hereby granted,
17 provided that the above copyright notice appear in all copies and that
18 both that copyright notice and this permission notice appear in
19 supporting documentation, and that the name of IBM not be
20 used in advertising or publicity pertaining to distribution of the
21 software without specific, written prior permission.
22 
23 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
24 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
25 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
26 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
27 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
28 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
29 SOFTWARE.
30 
31 ******************************************************************/
32 
33 /*
34  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
35  */
36 /*
37  * ARGO TP
38  *
39  * $Header: tp_param.h,v 5.3 88/11/18 17:28:18 nhall Exp $
40  * $Source: /usr/argo/sys/netiso/RCS/tp_param.h,v $
41  *
42  */
43 
44 #ifndef __TP_PARAM__
45 #define __TP_PARAM__
46 
47 
48 /******************************************************
49  * compile time parameters that can be changed
50  *****************************************************/
51 
52 #define 	TP_CLASSES_IMPLEMENTED 0x11 /* zero and 4 */
53 
54 #define		TP_DECBIT_CLEAR_COUNT	3
55 
56 /*#define 	N_TPREF				100 */
57 #ifdef KERNEL
58 extern int N_TPREF;
59 #endif
60 
61 #define 	TP_SOCKBUFSIZE		((u_long)4096)
62 #define 	TP0_SOCKBUFSIZE		((u_long)512)
63 #define		MAX_TSAP_SEL_LEN	64
64 
65 /* maximum tpdu size we'll accept: */
66 #define 	TP_TPDUSIZE			0xc		/* 4096 octets for classes 1-4*/
67 #define 	TP0_TPDUSIZE		0xb		/* 2048 octets for class 0 */
68 #define 	TP_DFL_TPDUSIZE		0x7		/* 128 octets default */
69 	/* NOTE: don't ever negotiate 8192 because could get
70 	 * wraparound in checksumming
71 	 * (No mtu is likely to be larger than 4K anyway...)
72 	 */
73 #define		TP_NRETRANS			12		/* TCP_MAXRXTSHIFT + 1 */
74 #define		TP_MAXRXTSHIFT		6		/* factor of 64 */
75 #define		TP_MAXPORT			0xefff
76 
77 /* ALPHA: to be used in the context: gain= 1/(2**alpha), or
78  * put another way, gaintimes(x) (x)>>alpha (forgetting the case alpha==0)
79  */
80 #define 	TP_RTT_ALPHA		3
81 #define 	TP_RTV_ALPHA		2
82 #define		TP_REXMTVAL(tpcb)\
83 	((tp_rttadd + (tpcb)->tp_rtt + ((tpcb)->tp_rtv) << 2) / tp_rttdiv)
84 #define		TP_RANGESET(tv, value, min, max) \
85 	((tv = value) > (max) ? (tv = max) : (tv < min ? tv = min : tv))
86 
87 /*
88  * not sure how to treat data on disconnect
89  */
90 #define 	T_CONN_DATA			0x1
91 #define 	T_DISCONNECT		0x2
92 #define 	T_DISC_DATA			0x4
93 #define 	T_XDATA				0x8
94 
95 #define ISO_CLNS	 0
96 #define IN_CLNS	 	 1
97 #define ISO_CONS	 2
98 #define ISO_COSNS	 3
99 #define TP_MAX_NETSERVICES 3
100 
101 /* Indices into tp stats ackreason[i] */
102 #define _ACK_DONT_ 0
103 #define _ACK_STRAT_EACH_ 0x1
104 #define _ACK_STRAT_FULLWIN_ 0x2
105 #define _ACK_DUP_ 0x3
106 #define _ACK_EOT_ 0x4
107 #define _ACK_REORDER_ 0x5
108 #define _ACK_USRRCV_ 0x6
109 #define _ACK_FCC_ 0x7
110 #define _ACK_NUM_REASONS_ 0x8
111 
112 /* masks for use in tp_stash() */
113 #define ACK_DONT 			0
114 #define ACK_STRAT_EACH		(1<< _ACK_STRAT_EACH_)
115 #define ACK_STRAT_FULLWIN	(1<< _ACK_STRAT_FULLWIN_)
116 #define ACK_DUP 			(1<< _ACK_DUP_)
117 #define ACK_EOT				(1<< _ACK_EOT_)
118 #define ACK_REORDER			(1<< _ACK_REORDER_)
119 
120 /******************************************************
121  * constants used in the protocol
122  *****************************************************/
123 
124 #define		TP_VERSION 			0x1
125 
126 #define 	TP_MAX_HEADER_LEN	256
127 
128 #define 	TP_MIN_TPDUSIZE		0x7		/* 128 octets */
129 #define 	TP_MAX_TPDUSIZE		0xd		/* 8192 octets */
130 
131 #define		TP_MAX_XPD_DATA		0x10	/* 16 octets */
132 #define		TP_MAX_CC_DATA		0x20	/* 32 octets */
133 #define		TP_MAX_CR_DATA		TP_MAX_CC_DATA
134 #define		TP_MAX_DR_DATA		0x40	/* 64 octets */
135 
136 #define		TP_XTD_FMT_BIT 	0x80000000
137 #define		TP_XTD_FMT_MASK	0x7fffffff
138 #define		TP_NML_FMT_BIT 	0x80
139 #define		TP_NML_FMT_MASK	0x7f
140 
141 /*
142  * values for the tpdu_type field, 2nd byte in a tpdu
143  */
144 
145 #define TP_MIN_TPDUTYPE 0x1
146 
147 #define XPD_TPDU_type	0x1
148 #define XAK_TPDU_type	0x2
149 #define GR_TPDU_type	0x3
150 #define AK_TPDU_type	0x6
151 #define ER_TPDU_type	0x7
152 #define DR_TPDU_type	0x8
153 #define DC_TPDU_type	0xc
154 #define CC_TPDU_type	0xd
155 #define CR_TPDU_type	0xe
156 #define DT_TPDU_type	0xf
157 
158 #define TP_MAX_TPDUTYPE 0xf
159 
160 /*
161  * identifiers for the variable-length options in tpdus
162  */
163 
164 #define		TPP_acktime			0x85
165 #define		TPP_residER			0x86
166 #define		TPP_priority		0x87
167 #define		TPP_transdelay		0x88
168 #define		TPP_throughput		0x89
169 #define		TPP_subseq			0x8a
170 #define		TPP_flow_cntl_conf	0x8c	/* not implemented */
171 #define		TPP_addl_info		0xe0
172 #define		TPP_tpdu_size		0xc0
173 #define		TPP_calling_sufx	0xc1
174 #define		TPP_invalid_tpdu	0xc1	/* the bozos used a value twice */
175 #define		TPP_called_sufx		0xc2
176 #define		TPP_checksum		0xc3
177 #define		TPP_vers			0xc4
178 #define		TPP_security		0xc5
179 #define		TPP_addl_opt		0xc6
180 #define		TPP_alt_class		0xc7
181 #define		TPP_perf_meas		0xc8	/* local item : perf meas on, svp */
182 #define		TPP_ptpdu_size		0xf0	/* preferred TPDU size */
183 #define		TPP_inact_time		0xf2	/* inactivity time exchanged */
184 
185 
186 /******************************************************
187  * Some fundamental data types
188  *****************************************************/
189 #ifndef		TRUE
190 #define		TRUE				1
191 #endif		/* TRUE */
192 
193 #ifndef		FALSE
194 #define		FALSE				0
195 #endif		/* FALSE */
196 
197 #define		TP_LOCAL				22
198 #define		TP_FOREIGN				33
199 
200 #ifndef 	EOK
201 #define 	EOK 	0
202 #endif  	/* EOK */
203 
204 #define 	TP_CLASS_0 	(1<<0)
205 #define 	TP_CLASS_1 	(1<<1)
206 #define 	TP_CLASS_2 	(1<<2)
207 #define 	TP_CLASS_3 	(1<<3)
208 #define 	TP_CLASS_4 	(1<<4)
209 
210 #define 	TP_FORCE 	0x1
211 #define 	TP_STRICT 	0x2
212 
213 #ifndef 	MNULL
214 #define 	MNULL				(struct mbuf *)0
215 #endif 	/* MNULL */
216 	/* if ../sys/mbuf.h gets MT_types up to 0x40, these will
217 	 * have to be changed:
218 	 */
219 #define 	MT_XPD 				0x44
220 #define 	MT_EOT 				0x40
221 
222 #define		TP_ENOREF			0x80000000
223 
224 typedef 	unsigned int	SeqNum;
225 typedef		unsigned short	RefNum;
226 typedef		int				ProtoHook;
227 
228 /******************************************************
229  * Macro used all over, for driver
230  *****************************************************/
231 
232 #define  DoEvent(x) \
233   ((E.ev_number=(x)),(tp_driver(tpcb,&E)))
234 
235 /******************************************************
236  * Some macros used all over, for timestamping
237  *****************************************************/
238 
239 #define GET_CUR_TIME(tvalp) ((*tvalp) = time)
240 
241 #define GET_TIME_SINCE(oldtvalp, diffp) {\
242 	(diffp)->tv_sec = time.tv_sec - (oldtvalp)->tv_sec;\
243 	(diffp)->tv_usec = time.tv_usec - (oldtvalp)->tv_usec;\
244 	if( (diffp)->tv_usec <0 ) {\
245 		(diffp)->tv_sec --;\
246 		(diffp)->tv_usec = 1000000 - (diffp)->tv_usec;\
247 	}\
248 }
249 
250 /******************************************************
251  * Some macros used for address families
252  *****************************************************/
253 
254 #define satosiso(ADDR) ((struct sockaddr_iso *)(ADDR))
255 #define satosin(ADDR) ((struct sockaddr_in *)(ADDR))
256 
257 /******************************************************
258  * Macro used for changing types of mbufs
259  *****************************************************/
260 
261 #define CHANGE_MTYPE(m, TYPE)\
262 	if((m)->m_type != TYPE) { \
263 		mbstat.m_mtypes[(m)->m_type]--; mbstat.m_mtypes[TYPE]++; \
264 		(m)->m_type = TYPE; \
265 	}
266 
267 /******************************************************
268  * Macros used for adding options to a tpdu header and for
269  * parsing the headers.
270  * Options are variable-length and must be bcopy-d because on the
271  * RT your assignments must be N-word aligned for objects of length
272  * N.  Such a drag.
273  *****************************************************/
274 
275 struct tp_vbp {
276 	u_char	tpv_code;
277 	char 	tpv_len;
278 	char	tpv_val;
279 };
280 #define vbptr(x) ((struct tp_vbp *)(x))
281 #define vbval(x,type) (*((type *)&(((struct tp_vbp *)(x))->tpv_val)))
282 #define vbcode(x) (vbptr(x)->tpv_code)
283 #define vblen(x) (vbptr(x)->tpv_len)
284 
285 #define vb_putval(dst,type,src)\
286 	bcopy((caddr_t)&(src),(caddr_t)&(((struct tp_vbp *)(dst))->tpv_val),\
287 	sizeof(type))
288 
289 #define vb_getval(src,type,dst)\
290 bcopy((caddr_t)&(((struct tp_vbp *)(src))->tpv_val),(caddr_t)&(dst),sizeof(type))
291 
292 #define ADDOPTION(type, DU, len, src)\
293 {	register caddr_t P;\
294 	P = (caddr_t)(DU) + (int)((DU)->tpdu_li);\
295 	vbptr(P)->tpv_code = type;\
296 	vbptr(P)->tpv_len = len;\
297 	bcopy((caddr_t)&src, (caddr_t)&(vbptr(P)->tpv_val), (unsigned)len);\
298 	DU->tpdu_li += len+2;/* 1 for code, 1 for length */\
299 }
300 /******************************************************
301  * Macro for the local credit:
302  * uses max transmission unit for the ll
303  * (as modified by the max TPDU size negotiated)
304  *****************************************************/
305 
306 #if defined(ARGO_DEBUG)&&!defined(LOCAL_CREDIT_EXPAND)
307 #define LOCAL_CREDIT(tpcb) tp_local_credit(tpcb)
308 #else
309 #define LOCAL_CREDIT(tpcb) { if (tpcb->tp_rsycnt == 0) {\
310     register struct sockbuf *xxsb = &((tpcb)->tp_sock->so_rcv);\
311     register int xxi = sbspace(xxsb);\
312     xxi = (xxi<0) ? 0 : ((xxi) / (tpcb)->tp_l_tpdusize);\
313     xxi = min(xxi, (tpcb)->tp_maxlcredit); \
314     if (!(tpcb->tp_cebit_off)) { \
315         (tpcb)->tp_lcredit = ROUND((tpcb)->tp_win_recv); \
316         if (xxi < (tpcb)->tp_lcredit) { \
317             (tpcb)->tp_lcredit = xxi; \
318         } \
319     } else \
320         (tpcb)->tp_lcredit = xxi; \
321 } }
322 #endif /* ARGO_DEBUG */
323 
324 #ifdef KERNEL
325 extern int tp_rttadd, tp_rttdiv;
326 #include <sys/syslog.h>
327 #define printf logpri(LOG_DEBUG),addlog
328 
329 #ifndef  tp_NSTATES
330 
331 #include <netiso/tp_states.h>
332 #include <netiso/tp_events.h>
333 #if defined(__STDC__) || defined(__cplusplus)
334 #undef ATTR
335 #define ATTR(X) ev_union.EV_ ## X
336 #endif /* defined(__STDC__) || defined(__cplusplus) */
337 
338 #endif  /* tp_NSTATES  */
339 #endif /* KERNEL */
340 
341 #endif /* __TP_PARAM__ */
342