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