No empty .Rs/.Re
[netbsd-mini2440.git] / sys / netiso / tp_param.h
blobcf4726377e661e0a6919c900801fdd6b22edfc55
1 /* $NetBSD: tp_param.h,v 1.19 2009/03/14 19:03:41 christos Exp $ */
3 /*-
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
31 * @(#)tp_param.h 8.1 (Berkeley) 6/10/93
34 /***********************************************************
35 Copyright IBM Corporation 1987
37 All Rights Reserved
39 Permission to use, copy, modify, and distribute this software and its
40 documentation for any purpose and without fee is hereby granted,
41 provided that the above copyright notice appear in all copies and that
42 both that copyright notice and this permission notice appear in
43 supporting documentation, and that the name of IBM not be
44 used in advertising or publicity pertaining to distribution of the
45 software without specific, written prior permission.
47 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
48 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
49 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
50 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
51 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
52 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
53 SOFTWARE.
55 ******************************************************************/
58 * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
61 #ifndef _NETISO_TP_PARAM_H_
62 #define _NETISO_TP_PARAM_H_
64 /******************************************************
65 * compile time parameters that can be changed
66 *****************************************************/
68 #define TP_CLASSES_IMPLEMENTED 0x11 /* zero and 4 */
70 #define TP_DECBIT_CLEAR_COUNT 3
72 /* #define N_TPREF 100 */
73 #ifdef _KERNEL
74 extern int N_TPREF;
75 #endif
77 #define TP_SOCKBUFSIZE ((u_long)4096)
78 #define TP0_SOCKBUFSIZE ((u_long)512)
79 #define MAX_TSAP_SEL_LEN 64
81 /* maximum tpdu size we'll accept: */
82 #define TP_TPDUSIZE 0xc /* 4096 octets for
83 * classes 1-4 */
84 #define TP0_TPDUSIZE 0xb /* 2048 octets for class 0 */
85 #define TP_DFL_TPDUSIZE 0x7 /* 128 octets default */
87 * NOTE: don't ever negotiate 8192 because could get wraparound in
88 * checksumming (No mtu is likely to be larger than 4K anyway...)
90 #define TP_NRETRANS 12 /* TCP_MAXRXTSHIFT + 1 */
91 #define TP_MAXRXTSHIFT 6 /* factor of 64 */
92 #define TP_MAXPORT 0xefff
95 * ALPHA: to be used in the context: gain= 1/(2**alpha), or put another way,
96 * gaintimes(x) (x)>>alpha (forgetting the case alpha==0)
98 #define TP_RTT_ALPHA 3
99 #define TP_RTV_ALPHA 2
100 #define TP_REXMTVAL(tpcb)\
101 (((tp_rttadd + (tpcb)->tp_rtt + ((tpcb)->tp_rtv)) << 2) / tp_rttdiv)
102 #define TP_RANGESET(tv, value, min, max) \
103 ((tv = value) > (max) ? (tv = max) : (tv < min ? tv = min : tv))
106 * not sure how to treat data on disconnect
108 #define T_CONN_DATA 0x1
109 #define T_DISCONNECT 0x2
110 #define T_DISC_DATA 0x4
111 #define T_XDATA 0x8
113 #define ISO_CLNS 0
114 #define IN_CLNS 1
115 #define ISO_CONS 2
116 #define ISO_COSNS 3
117 #define TP_MAX_NETSERVICES 3
119 /* Indices into tp stats ackreason[i] */
120 #define _ACK_DONT_ 0
121 #define _ACK_STRAT_EACH_ 0x1
122 #define _ACK_STRAT_FULLWIN_ 0x2
123 #define _ACK_DUP_ 0x3
124 #define _ACK_EOT_ 0x4
125 #define _ACK_REORDER_ 0x5
126 #define _ACK_USRRCV_ 0x6
127 #define _ACK_FCC_ 0x7
128 #define _ACK_NUM_REASONS_ 0x8
130 /* masks for use in tp_stash() */
131 #define ACK_DONT 0
132 #define ACK_STRAT_EACH (1<< _ACK_STRAT_EACH_)
133 #define ACK_STRAT_FULLWIN (1<< _ACK_STRAT_FULLWIN_)
134 #define ACK_DUP (1<< _ACK_DUP_)
135 #define ACK_EOT (1<< _ACK_EOT_)
136 #define ACK_REORDER (1<< _ACK_REORDER_)
138 /******************************************************
139 * constants used in the protocol
140 *****************************************************/
142 #define TP_VERSION 0x1
144 #define TP_MAX_HEADER_LEN 256
146 #define TP_MIN_TPDUSIZE 0x7 /* 128 octets */
147 #define TP_MAX_TPDUSIZE 0xd /* 8192 octets */
149 #define TP_MAX_XPD_DATA 0x10 /* 16 octets */
150 #define TP_MAX_CC_DATA 0x20 /* 32 octets */
151 #define TP_MAX_CR_DATA TP_MAX_CC_DATA
152 #define TP_MAX_DR_DATA 0x40 /* 64 octets */
154 #define TP_XTD_FMT_BIT 0x80000000
155 #define TP_XTD_FMT_MASK 0x7fffffff
156 #define TP_NML_FMT_BIT 0x80
157 #define TP_NML_FMT_MASK 0x7f
160 * values for the tpdu_type field, 2nd byte in a tpdu
163 #define TP_MIN_TPDUTYPE 0x1
165 #define XPD_TPDU_type 0x1
166 #define XAK_TPDU_type 0x2
167 #define GR_TPDU_type 0x3
168 #define AK_TPDU_type 0x6
169 #define ER_TPDU_type 0x7
170 #define DR_TPDU_type 0x8
171 #define DC_TPDU_type 0xc
172 #define CC_TPDU_type 0xd
173 #define CR_TPDU_type 0xe
174 #define DT_TPDU_type 0xf
176 #define TP_MAX_TPDUTYPE 0xf
179 * identifiers for the variable-length options in tpdus
182 #define TPP_acktime 0x85
183 #define TPP_residER 0x86
184 #define TPP_priority 0x87
185 #define TPP_transdelay 0x88
186 #define TPP_throughput 0x89
187 #define TPP_subseq 0x8a
188 #define TPP_flow_cntl_conf 0x8c /* not implemented */
189 #define TPP_addl_info 0xe0
190 #define TPP_tpdu_size 0xc0
191 #define TPP_calling_sufx 0xc1
192 #define TPP_invalid_tpdu 0xc1 /* the bozos used a value
193 * twice */
194 #define TPP_called_sufx 0xc2
195 #define TPP_checksum 0xc3
196 #define TPP_vers 0xc4
197 #define TPP_security 0xc5
198 #define TPP_addl_opt 0xc6
199 #define TPP_alt_class 0xc7
200 #define TPP_perf_meas 0xc8 /* local item : perf meas on,
201 * svp */
202 #define TPP_ptpdu_size 0xf0 /* preferred TPDU size */
203 #define TPP_inact_time 0xf2 /* inactivity time exchanged */
206 /******************************************************
207 * Some fundamental data types
208 *****************************************************/
209 #define TP_LOCAL 22
210 #define TP_FOREIGN 33
212 #ifndef EOK
213 #define EOK 0
214 #endif /* EOK */
216 #define TP_CLASS_0 (1<<0)
217 #define TP_CLASS_1 (1<<1)
218 #define TP_CLASS_2 (1<<2)
219 #define TP_CLASS_3 (1<<3)
220 #define TP_CLASS_4 (1<<4)
222 #define TP_FORCE 0x1
223 #define TP_STRICT 0x2
226 * if ../sys/mbuf.h gets MT_types up to 0x40, these will have to be changed:
228 #define MT_XPD 0x44
229 #define MT_EOT 0x40
231 #define TP_ENOREF 0x80000000
233 typedef unsigned int SeqNum;
234 typedef unsigned short RefNum;
236 /******************************************************
237 * Macro used all over, for driver
238 *****************************************************/
240 #define DoEvent(x) \
241 ((E.ev_number=(x)),(tp_driver(tpcb,&E)))
243 /******************************************************
244 * Some macros used all over, for timestamping
245 *****************************************************/
247 #define GET_CUR_TIME(tvalp) ((*tvalp) = time)
249 #define GET_TIME_SINCE(oldtvalp, diffp) {\
250 (diffp)->tv_sec = time.tv_sec - (oldtvalp)->tv_sec;\
251 (diffp)->tv_usec = time.tv_usec - (oldtvalp)->tv_usec;\
252 if( (diffp)->tv_usec <0 ) {\
253 (diffp)->tv_sec--;\
254 (diffp)->tv_usec = 1000000 - (diffp)->tv_usec;\
258 /******************************************************
259 * Macro used for changing types of mbufs
260 *****************************************************/
262 #define CHANGE_MTYPE(m, TYPE)\
263 if((m)->m_type != TYPE) { \
264 mbstat.m_mtypes[(m)->m_type]--; mbstat.m_mtypes[TYPE]++; \
265 (m)->m_type = TYPE; \
268 /******************************************************
269 * Macros used for adding options to a tpdu header and for
270 * parsing the headers.
271 * Options are variable-length and must be bcopy-d because on the
272 * RT your assignments must be N-word aligned for objects of length
273 * N. Such a drag.
274 *****************************************************/
276 struct tp_vbp {
277 u_char tpv_code;
278 u_char tpv_len;
279 char tpv_val;
281 #define vbptr(x) ((struct tp_vbp *)(x))
282 #define vbval(x,type) (*((type *)&(((struct tp_vbp *)(x))->tpv_val)))
283 #define vbcode(x) (vbptr(x)->tpv_code)
284 #define vblen(x) (vbptr(x)->tpv_len)
286 #define vb_putval(dst,type,src)\
287 memcpy((void *)&(((struct tp_vbp *)(dst))->tpv_val), (void *)&(src),\
288 sizeof(type))
290 #define vb_getval(src,type,dst)\
291 bcopy((void *)&(((struct tp_vbp *)(src))->tpv_val),(void *)&(dst),sizeof(type))
293 #define ADDOPTION(type, DU, len, src)\
294 { char *P;\
295 P = (char *)(DU) + (int)((DU)->tpdu_li);\
296 vbptr(P)->tpv_code = type;\
297 vbptr(P)->tpv_len = len;\
298 memcpy(&(vbptr(P)->tpv_val), &src, (unsigned)len);\
299 DU->tpdu_li += len+2;/* 1 for code, 1 for length */\
301 /******************************************************
302 * Macro for the local credit:
303 * uses max transmission unit for the ll
304 * (as modified by the max TPDU size negotiated)
305 *****************************************************/
307 #if defined(ARGO_DEBUG)&&!defined(LOCAL_CREDIT_EXPAND)
308 #define LOCAL_CREDIT(tpcb) tp_local_credit(tpcb)
309 #else
310 #define LOCAL_CREDIT(tpcb) { if (tpcb->tp_rsycnt == 0) {\
311 struct sockbuf *xxsb = &((tpcb)->tp_sock->so_rcv);\
312 int xxi = sbspace(xxsb);\
313 xxi = (xxi<0) ? 0 : ((xxi) / (tpcb)->tp_l_tpdusize);\
314 xxi = min(xxi, (tpcb)->tp_maxlcredit); \
315 if (!(tpcb->tp_cebit_off)) { \
316 (tpcb)->tp_lcredit = ROUND((tpcb)->tp_win_recv); \
317 if (xxi < (tpcb)->tp_lcredit) { \
318 (tpcb)->tp_lcredit = xxi; \
320 } else \
321 (tpcb)->tp_lcredit = xxi; \
323 #endif /* ARGO_DEBUG */
325 #ifdef _KERNEL
326 extern int tp_rttadd, tp_rttdiv;
327 #include <sys/syslog.h>
328 #define printf logpri(LOG_DEBUG),addlog
330 #ifndef tp_NSTATES
332 #include <netiso/tp_states.h>
333 #include <netiso/tp_events.h>
335 #ifndef __CONCAT3
336 # if __STDC__
337 # define __CONCAT3(a,b,c) a ## b ## c
338 # else
339 # define __CONCAT3(a,b,c) a/**/b/**/c
340 # endif /* __STDC__ */
341 #endif
343 #define TPDU_ATTR(X) __CONCAT3(ev_union.EV_,X,_TPDU)
345 #endif /* tp_NSTATES */
346 #endif /* _KERNEL */
348 #endif /* !_NETISO_TP_PARAM_H_ */