xref: /titanic_51/usr/src/head/xti.h (revision bbaa8b60dd95d714741fc474adad3cf710ef4efd)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1996 Sun Microsystems, Inc.	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #ifndef _XTI_H
27 #define	_XTI_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 
33 /*
34  * The following include file has declarations needed by both the kernel
35  * level transport providers and the user level library. This file includes
36  * it to expose its namespaces to XTI user level interface.
37  */
38 #include <sys/tpicommon.h>
39 
40 /*
41  * Include XTI interface level options management declarations
42  */
43 #include <sys/xti_xtiopt.h>
44 
45 #if !defined(_XPG5)
46 
47 /*
48  * Include declarations related to OSI transport and management data
49  * structures, and the Internet Protocol Suite.
50  * Note: The older Unix95/XNS4 XTI spec required these to be
51  * exposed through the generic interface header.
52  */
53 #include <sys/xti_osi.h>
54 #include <sys/xti_inet.h>
55 
56 #endif /* !defined(_XPG5) */
57 
58 #ifdef	__cplusplus
59 extern "C" {
60 #endif
61 
62 /*
63  * The following t_errno error codes are included in the namespace by
64  * inclusion of <sys/tpicommon.h> above. The english language error strings
65  * associated with the error values are reproduced here for easy reference.
66  *
67  * Error		Value	Error message string
68  * ----			-----	--------------------
69  * TBADADDR		1	Incorrect address format
70  * TBADOPT		2	Incorrect options format
71  * TACCES		3	Illegal permissions
72  * TBADF		4	Illegal file descriptor
73  * TNOADDR		5	Couldn't allocate address
74  * TOUTSTATE		6	Routine will place interface out of state
75  * TBADSEQ		7	Illegal called/calling sequence number
76  * TSYSERR		8	System error
77  * TLOOK		9	An event requires attention
78  * TBADDATA		10	Illegal amount of data
79  * TBUFOVFLW		11	Buffer not large enough
80  * TFLOW		12	Can't send message - (blocked)
81  * TNODATA		13	No message currently available
82  * TNODIS		14	Disconnect message not found
83  * TNOUDERR		15	Unitdata error message not found
84  * TBADFLAG		16	Incorrect flags specified
85  * TNOREL		17	Orderly release message not found
86  * TNOTSUPPORT		18	Primitive not supported by provider
87  * TSTATECHNG		19	State is in process of changing
88  * TNOSTRUCTYPE		20	Unsupported structure type requested
89  * TBADNAME		21	Invalid transport provider name
90  * TBADQLEN		22	Listener queue length limit is zero
91  * TADDRBUSY		23	Transport address is in use
92  * TINDOUT		24	Outstanding connection indications
93  * TPROVMISMATCH	25	Listener-acceptor transport provider mismatch
94  * TRESQLEN		26	Connection acceptor has listen queue length
95  *				limit greater than zero
96  * TRESADDR		27	Connection acceptor-listener addresses not
97  *				same but required by transport
98  * TQFULL		28	Incoming connection queue is full
99  * TPROTO		29	Protocol error on transport primitive
100  *
101  */
102 
103 /*
104  * The following are the events returned by t_look
105  */
106 #define	T_LISTEN	0x0001	/* connection indication received	*/
107 #define	T_CONNECT	0x0002	/* connect confirmation received	*/
108 #define	T_DATA		0x0004	/* normal data received			*/
109 #define	T_EXDATA	0x0008	/* expedited data received		*/
110 #define	T_DISCONNECT	0x0010	/* disconnect received			*/
111 #define	T_UDERR		0x0040	/* data gram error indication		*/
112 #define	T_ORDREL	0x0080	/* orderly release indication		*/
113 #define	T_GODATA	0x0100	/* sending normal data is again possible */
114 #define	T_GOEXDATA	0x0200	/* sending expedited data is again possible */
115 
116 /*
117  * Flags for data primitives
118  */
119 #define	T_MORE		0x001	/* more data		*/
120 #define	T_EXPEDITED	0x002	/* expedited data	*/
121 #define	T_PUSH		0x004	/* send data immediately */
122 
123 /*
124  * XTI error return
125  */
126 #if defined(_REENTRANT) || defined(_TS_ERRNO)
127 extern int	*__t_errno();
128 #define	t_errno (*(__t_errno()))
129 #else
130 extern int t_errno;
131 #endif	/* defined(_REENTRANT) || defined(_TS_ERRNO) */
132 
133 
134 /*
135  * The following are for t_sysconf()
136  */
137 #ifndef T_IOV_MAX
138 #define	T_IOV_MAX	16	/* Maximum number of scatter/gather buffers */
139 #endif				/* Should be <= IOV_MAX */
140 
141 #ifndef _SC_T_IOV_MAX
142 #define	_SC_T_IOV_MAX 	79	/* Should be same in <unistd.h> for use by */
143 #endif				/* sysconf() */
144 
145 struct t_iovec {
146 	void	*iov_base;
147 	size_t	iov_len;
148 };
149 
150 /*
151  * Translate source level interface to binary entry point names.
152  *
153  * Note: This is done to maintain co-existence of TLI and XTI
154  * interfaces which have identical names for most functions but
155  * different semantics. The XTI names are moved to the different
156  * prefix space in the ABI. The #ifdef is required to make use of
157  * of the compiler feature to allow redefinition of external names
158  * where available. Otherwise a simple #define is used when this
159  * header is used with other compilers.
160  * The use of #define also has the effect of renaming all names (not
161  * just function names) to the new name. The TLI function names
162  * (e.g. t_bind) can have identical names for structure names
163  * (e.g struct t_bind). Therefore, this redefinition of names needs
164  * to be before all structure and function name declarations in the header.
165  */
166 
167 #ifdef __PRAGMA_REDEFINE_EXTNAME
168 
169 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
170 #pragma redefine_extname t_accept	_xti_accept
171 #else
172 #pragma redefine_extname t_accept	_xti_xns5_accept
173 #endif
174 #pragma redefine_extname t_alloc	_xti_alloc
175 #pragma redefine_extname t_bind		_xti_bind
176 #pragma redefine_extname t_close	_xti_close
177 #pragma redefine_extname t_connect	_xti_connect
178 #pragma redefine_extname t_error	_xti_error
179 #pragma redefine_extname t_free		_xti_free
180 #pragma redefine_extname t_getinfo	_xti_getinfo
181 #pragma redefine_extname t_getstate	_xti_getstate
182 #pragma redefine_extname t_getprotaddr	_xti_getprotaddr
183 #pragma redefine_extname t_listen	_xti_listen
184 #pragma redefine_extname t_look		_xti_look
185 #pragma redefine_extname t_open		_xti_open
186 #pragma redefine_extname t_optmgmt	_xti_optmgmt
187 #pragma redefine_extname t_rcv		_xti_rcv
188 #pragma redefine_extname t_rcvconnect	_xti_rcvconnect
189 #pragma redefine_extname t_rcvdis	_xti_rcvdis
190 #pragma redefine_extname t_rcvrel	_xti_rcvrel
191 #pragma redefine_extname t_rcvreldata	_xti_rcvreldata
192 #pragma redefine_extname t_rcvudata	_xti_rcvudata
193 #pragma redefine_extname t_rcvuderr	_xti_rcvuderr
194 #pragma redefine_extname t_rcvv		_xti_rcvv
195 #pragma redefine_extname t_rcvvudata	_xti_rcvvudata
196 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
197 #pragma redefine_extname t_snd		_xti_snd
198 #else
199 #pragma redefine_extname t_snd		_xti_xns5_snd
200 #endif
201 #pragma redefine_extname t_snddis	_xti_snddis
202 #pragma redefine_extname t_sndrel	_xti_sndrel
203 #pragma redefine_extname t_sndreldata	_xti_sndreldata
204 #pragma redefine_extname t_sndudata	_xti_sndudata
205 #pragma redefine_extname t_sndv		_xti_sndv
206 #pragma redefine_extname t_sndvudata	_xti_sndvudata
207 #pragma redefine_extname t_strerror	_xti_strerror
208 #pragma redefine_extname t_sync		_xti_sync
209 #pragma redefine_extname t_sysconf	_xti_sysconf
210 #pragma redefine_extname t_unbind	_xti_unbind
211 
212 #else /* __PRAGMA_REDEFINE_EXTNAME */
213 
214 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
215 #define	t_accept	_xti_accept
216 #else
217 #define	t_accept	_xti_xns5_accept
218 #endif
219 #define	t_alloc		_xti_alloc
220 #define	t_bind		_xti_bind
221 #define	t_close		_xti_close
222 #define	t_connect	_xti_connect
223 #define	t_error		_xti_error
224 #define	t_free		_xti_free
225 #define	t_getinfo	_xti_getinfo
226 #define	t_getstate	_xti_getstate
227 #define	t_getprotaddr	_xti_getprotaddr
228 #define	t_listen	_xti_listen
229 #define	t_look		_xti_look
230 #define	t_open		_xti_open
231 #define	t_optmgmt	_xti_optmgmt
232 #define	t_rcv		_xti_rcv
233 #define	t_rcvconnect	_xti_rcvconnect
234 #define	t_rcvdis	_xti_rcvdis
235 #define	t_rcvrel	_xti_rcvrel
236 #define	t_rcvreldata	_xti_rcvreldata
237 #define	t_rcvudata	_xti_rcvudata
238 #define	t_rcvuderr	_xti_rcvuderr
239 #define	t_rcvv		_xti_rcvv
240 #define	t_rcvvudata	_xti_rcvvudata
241 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
242 #define	t_snd		_xti_snd
243 #else
244 #define	t_snd		_xti_xns5_snd
245 #endif
246 #define	t_snddis	_xti_snddis
247 #define	t_sndrel	_xti_sndrel
248 #define	t_sndreldata	_xti_sndreldata
249 #define	t_sndudata	_xti_sndudata
250 #define	t_sndv		_xti_sndv
251 #define	t_sndvudata	_xti_sndvudata
252 #define	t_strerror	_xti_strerror
253 #define	t_sync		_xti_sync
254 #define	t_sysconf	_xti_sysconf
255 #define	t_unbind	_xti_unbind
256 
257 #endif /* __PRAGMA_REDEFINE_EXTNAME */
258 
259 /*
260  * protocol specific service limits
261  */
262 struct t_info {
263 	t_scalar_t addr;	/* max size of protocol address		*/
264 	t_scalar_t options;	/* max size of protocol options		*/
265 	t_scalar_t tsdu;	/* max size of max transport service	*/
266 				/* data unit	*/
267 	t_scalar_t etsdu;	/* max size of max expedited tsdu	*/
268 	t_scalar_t connect;	/* max data for connection primitives	*/
269 	t_scalar_t discon;	/* max data for disconnect primitives	*/
270 	t_scalar_t servtype;	/* provider service type		*/
271 	t_scalar_t flags;	/* other info about transport providers	*/
272 };
273 
274 /*
275  * Flags definitions for the t_info structure
276  */
277 #define	T_SENDZERO	0x001	/* supports 0-length TSDUs */
278 #define	T_ORDRELDATA	0x002	/* supports orderly release data */
279 
280 /*
281  * netbuf structure
282  */
283 struct netbuf {
284 	unsigned int maxlen;
285 	unsigned int len;
286 #if defined(_XPG5)
287 	void *buf;
288 #else
289 	char *buf;
290 #endif
291 };
292 
293 /*
294  * t_opthdr structure
295  */
296 struct t_opthdr {
297 	t_uscalar_t	len;	/* total length of option */
298 	t_uscalar_t	level;	/* protocol level */
299 	t_uscalar_t	name;	/* option name */
300 	t_uscalar_t	status;	/* status value */
301 	/* followed by option value */
302 };
303 
304 /*
305  * t_bind - format of the addres and options arguments of bind
306  */
307 
308 struct t_bind {
309 	struct netbuf	addr;
310 	unsigned int	qlen;
311 };
312 
313 /*
314  * options management
315  */
316 struct t_optmgmt {
317 	struct netbuf	opt;
318 	t_scalar_t	flags;
319 };
320 
321 /*
322  * disconnect structure
323  */
324 struct t_discon {
325 	struct netbuf	udata;		/* user data		*/
326 	int		reason;		/* reason code		*/
327 	int		sequence;	/* sequence number	*/
328 };
329 
330 /*
331  * call structure
332  */
333 struct t_call {
334 	struct netbuf	addr;		/*  address		*/
335 	struct netbuf	opt;		/* options		*/
336 	struct netbuf	udata;		/* user data		*/
337 	int		sequence;	/* sequence number	*/
338 };
339 
340 /*
341  * data gram structure
342  */
343 struct t_unitdata {
344 	struct netbuf	addr;		/*  address		*/
345 	struct netbuf	opt;		/* options		*/
346 	struct netbuf	udata;		/* user data		*/
347 };
348 
349 /*
350  * unitdata error
351  */
352 struct t_uderr {
353 	struct netbuf	addr;		/* address		*/
354 	struct netbuf	opt;		/* options 		*/
355 	t_scalar_t	error;		/* error code		*/
356 };
357 
358 /*
359  * The following are structure types used when dynamically
360  * allocating the above structures via t_structalloc().
361  */
362 #define	T_BIND		1		/* struct t_bind	*/
363 #define	T_OPTMGMT	2		/* struct t_optmgmt	*/
364 #define	T_CALL		3		/* struct t_call	*/
365 #define	T_DIS		4		/* struct t_discon	*/
366 #define	T_UNITDATA	5		/* struct t_unitdata	*/
367 #define	T_UDERROR	6		/* struct t_uderr	*/
368 #define	T_INFO		7		/* struct t_info	*/
369 
370 /*
371  * The following bits specify which fields of the above
372  * structures should be allocated by t_alloc().
373  */
374 #define	T_ADDR	0x01			/* address		*/
375 #define	T_OPT	0x02			/* options		*/
376 #define	T_UDATA	0x04			/* user data		*/
377 #define	T_ALL	0xffff			/* all the above fields */
378 
379 
380 /*
381  * the following are the states for the user
382  */
383 
384 #define	T_UNINIT	0		/* uninitialized		*/
385 #define	T_UNBND		1		/* unbound			*/
386 #define	T_IDLE		2		/* idle				*/
387 #define	T_OUTCON	3		/* outgoing connection pending 	*/
388 #define	T_INCON		4		/* incoming connection pending	*/
389 #define	T_DATAXFER	5		/* data transfer		*/
390 #define	T_OUTREL	6		/* outgoing release pending	*/
391 #define	T_INREL		7		/* incoming release pending	*/
392 
393 
394 #define	T_UNUSED		-1
395 #define	T_NULL			0
396 
397 
398 /*
399  * Allegedly general purpose constant. Used with (and needs to be bitwise
400  * distinct from) T_NOPROTECT, T_PASSIVEPROTECT and T_ACTIVEPROTECT
401  * which are OSI specific constants but part of this header (defined
402  * in <xti_osi.h> which is included in this header for historical
403  * XTI specification reasons)
404  */
405 #define	T_ABSREQ		0x8000
406 
407 /*
408  * General definitions for option management
409  *
410  * Multiple variable length options may be packed into a single option buffer.
411  * Each option consists of a fixed length header followed by variable length
412  * data. The header and data will have to be aligned at appropriate
413  * boundaries. The following macros are used to manipulate the options.
414  *
415  * Helper Macros: Macros beginning with a "_T" prefix are helper macros.
416  *		  They are private, not meant for public use and may
417  *		  change without notice. Users  should use the standard
418  *		  XTI macros beginning with "T_" prefix
419  */
420 
421 #define	_T_OPT_HALIGN_SZ	(sizeof (t_scalar_t)) /* Hdr Alignment size  */
422 #define	_T_OPT_DALIGN_SZ	(sizeof (int32_t))    /* Data Alignment size */
423 #define	_T_OPTHDR_SZ	(sizeof (struct t_opthdr))
424 
425 /* Align 'x' to the next 'asize' alignment  boundary */
426 #define	_T_OPT_ALIGN(x, asize) \
427 	(((uintptr_t)(x) + ((asize) - 1L)) & ~((asize) - 1L))
428 
429 /* Align 'x' to the next header alignment  boundary */
430 #define	_T_OPTHDR_ALIGN(x) \
431 	(_T_OPT_ALIGN((x), _T_OPT_HALIGN_SZ))
432 
433 /* Align 'x' to the next data alignment  boundary */
434 #define	_T_OPTDATA_ALIGN(x) \
435 	(_T_OPT_ALIGN((x), _T_OPT_DALIGN_SZ))
436 
437 /*
438  * struct t_opthdr *T_OPT_FIRSTHDR(struct netbuf *nbp):
439  *     Get aligned start of first option header
440  *
441  * unsigned char *T_OPT_DATA(struct t_opthdr *tohp):
442  *     Get aligned start of data part after option header
443  *
444  * struct t_opthdr *T_OPT_NEXTHDR(struct netbuf *nbp, struct t_opthdr *tohp):
445  * 	Skip to next option header
446  */
447 
448 #define	T_OPT_FIRSTHDR(nbp)    \
449 	((nbp)->len >= _T_OPTHDR_SZ ? (struct t_opthdr *)(nbp)->buf : \
450 	    (struct t_opthdr *)0)
451 
452 #define	T_OPT_DATA(tohp)	\
453 	((unsigned char *)_T_OPTDATA_ALIGN((char *)(tohp) + _T_OPTHDR_SZ))
454 
455 #define	_T_NEXTHDR(pbuf, buflen, popt) \
456 	(((char *)_T_OPTHDR_ALIGN((char *)(popt) + (popt)->len) + \
457 	    _T_OPTHDR_SZ <= ((char *)(pbuf) + (buflen))) ? \
458 	(struct t_opthdr *)((char *)_T_OPTHDR_ALIGN((char *)(popt) + \
459 	    (popt)->len)) : (struct t_opthdr *)0)
460 
461 #define	T_OPT_NEXTHDR(nbp, tohp)   (_T_NEXTHDR((nbp)->buf, (nbp)->len, (tohp)))
462 
463 #if !defined(_XPG5)
464 /*
465  * The macros below are meant for older applications for compatibility.
466  * New applications should use the T_OPT_* macros, obviating the need
467  * to explicitly use the T_ALIGN macro
468  *
469  * struct t_opthdr *OPT_NEXTHDR(char *pbuf, unsigned int buflen,
470  *                               struct t_opthdr *popt):
471  *         Skip to next option header
472  */
473 #define	T_ALIGN(p)	(((uintptr_t)(p) + (sizeof (t_scalar_t) - 1))\
474 					& ~(sizeof (t_scalar_t) - 1))
475 #define	OPT_NEXTHDR(pbuf, buflen, popt)	(_T_NEXTHDR((pbuf), (buflen), (popt)))
476 #endif
477 
478 /*
479  * XTI LIBRARY FUNCTIONS
480  */
481 
482 #if defined(__STDC__)
483 
484 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
485 extern int t_accept(int, int, struct t_call *);
486 extern char *t_alloc(int, int, int);
487 extern int t_bind(int, struct t_bind *, struct t_bind *);
488 extern int t_connect(int, struct t_call *, struct t_call *);
489 extern int t_error(char *);
490 extern int t_free(char *, int);
491 extern int t_open(char *, int, struct t_info *);
492 extern int t_optmgmt(int, struct t_optmgmt *, struct t_optmgmt *);
493 extern int t_rcv(int, char *, unsigned int, int *);
494 extern int t_snd(int, char *, unsigned int, int);
495 extern int t_snddis(int, struct t_call *);
496 extern int t_sndudata(int, struct t_unitdata *);
497 extern char *t_strerror(int);
498 #else
499 extern int t_accept(int, int, const struct t_call *);
500 extern void *t_alloc(int, int, int);
501 extern int t_bind(int, const struct t_bind *, struct t_bind *);
502 extern int t_connect(int, const struct t_call *, struct t_call *);
503 extern int t_error(const char *);
504 extern int t_free(void *, int);
505 extern int t_open(const char *, int, struct t_info *);
506 extern int t_optmgmt(int, const struct t_optmgmt *, struct t_optmgmt *);
507 extern int t_rcv(int, void *, unsigned int, int *);
508 extern int t_snd(int, void *, unsigned int, int);
509 extern int t_snddis(int, const struct t_call *);
510 extern int t_sndudata(int, const struct t_unitdata *);
511 extern const char *t_strerror(int);
512 #endif
513 extern int t_close(int);
514 extern int t_getinfo(int, struct t_info *);
515 extern int t_getstate(int);
516 extern int t_getprotaddr(int, struct t_bind *, struct t_bind *);
517 extern int t_listen(int, struct t_call *);
518 extern int t_look(int);
519 extern int t_rcvconnect(int, struct t_call *);
520 extern int t_rcvdis(int, struct t_discon *);
521 extern int t_rcvrel(int);
522 extern int t_rcvreldata(int, struct t_discon *);
523 extern int t_rcvudata(int, struct t_unitdata *, int *);
524 extern int t_rcvuderr(int, struct t_uderr *);
525 extern int t_rcvv(int, struct t_iovec *, unsigned int, int *);
526 extern int t_rcvvudata(int, struct t_unitdata *, struct t_iovec *,
527 	unsigned int, int *);
528 extern int t_sndrel(int);
529 extern int t_sndreldata(int, struct t_discon *);
530 extern int t_sndv(int, const struct t_iovec *,  unsigned int, int);
531 extern int t_sndvudata(int, struct t_unitdata *, struct t_iovec *,
532 	unsigned int);
533 extern int t_sync(int);
534 extern int t_sysconf(int);
535 extern int t_unbind(int);
536 
537 #endif /* __STDC__ */
538 
539 #ifdef	__cplusplus
540 }
541 #endif
542 
543 #endif	/* _XTI_H */
544