code:
/*-
 * Copyright (c) 1984, 1985, 1986, 1987, 1993
 *	The Regents of the University of California.
 * Copyright (c) 2004-2006 Robert N. M. Watson
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Copyright (c) 1995, Mike Mitchell
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)ipx_pcb.h
 *
 * $FreeBSD: release/9.0.0/sys/netipx/ipx_pcb.h 169463 2007-05-11 10:38:34Z rwatson $
 */

#ifndef _NETIPX_IPX_PCB_H_
#define	_NETIPX_IPX_PCB_H_

/*
 * IPX protocol interface control block.
 */
struct ipxpcb {
	LIST_ENTRY(ipxpcb) ipxp_list;
	struct	socket *ipxp_socket;	/* back pointer to socket */
	struct	ipx_addr ipxp_faddr;	/* destination address */
	struct	ipx_addr ipxp_laddr;	/* socket's address */
	caddr_t	ipxp_pcb;		/* protocol specific stuff */
	struct	route ipxp_route;	/* routing information */
	struct	ipx_addr ipxp_lastdst;	/* validate cached route for dg socks*/
	short	ipxp_flags;
	u_char	ipxp_dpt;		/* default packet type for ipx_output */
	u_char	ipxp_rpt;		/* last received packet type by ipx_input() */
	struct	mtx ipxp_mtx;
};

/*
 * Additional IPX pcb-related types and variables.
 */
LIST_HEAD(ipxpcbhead, ipxpcb);
extern struct ipxpcbhead ipxpcb_list;
extern struct ipxpcbhead ipxrawpcb_list;

#ifdef _KERNEL
extern struct mtx	ipxpcb_list_mtx;
#endif

/*
 * IPX/SPX PCB flags.
 */
#define IPXP_IN_ABORT		0x1	/* Calling abort through socket. */
#define IPXP_RAWIN		0x2	/* Show headers on input. */
#define IPXP_RAWOUT		0x4	/* Show header on output. */
#define IPXP_ALL_PACKETS	0x8	/* Turn off higher proto processing. */
#define	IPXP_CHECKSUM		0x10	/* Use checksum on this socket. */
#define	IPXP_DROPPED		0x20	/* Connection dropped. */
#define	IPXP_SPX		0x40	/* SPX PCB. */

#define	IPX_WILDCARD		1

#define ipxp_lport ipxp_laddr.x_port
#define ipxp_fport ipxp_faddr.x_port

#define	sotoipxpcb(so)		((struct ipxpcb *)((so)->so_pcb))

/*
 * Nominal space allocated to an IPX socket.
 */
#define	IPXSNDQ		16384
#define	IPXRCVQ		40960

#ifdef _KERNEL
int	ipx_pcballoc(struct socket *so, struct ipxpcbhead *head,
	    struct thread *p);
int	ipx_pcbbind(struct ipxpcb *ipxp, struct sockaddr *nam,
	    struct thread *p);
int	ipx_pcbconnect(struct ipxpcb *ipxp, struct sockaddr *nam,
	    struct thread *p);
void	ipx_pcbdetach(struct ipxpcb *ipxp);
void	ipx_pcbdisconnect(struct ipxpcb *ipxp);
void	ipx_pcbfree(struct ipxpcb *ipxp);
struct ipxpcb *ipx_pcblookup(struct ipx_addr *faddr, u_short lport, int wildp);
void	ipx_getpeeraddr(struct ipxpcb *ipxp, struct sockaddr **nam);
void	ipx_getsockaddr(struct ipxpcb *ipxp, struct sockaddr **nam);

#define	IPX_LIST_LOCK_INIT()	mtx_init(&ipxpcb_list_mtx, "ipx_list_mtx", \
				    NULL, MTX_DEF | MTX_RECURSE)
#define	IPX_LIST_LOCK()		mtx_lock(&ipxpcb_list_mtx)
#define	IPX_LIST_UNLOCK()	mtx_unlock(&ipxpcb_list_mtx)
#define	IPX_LIST_LOCK_ASSERT()	mtx_assert(&ipxpcb_list_mtx, MA_OWNED)

#define	IPX_LOCK_INIT(ipx)	mtx_init(&(ipx)->ipxp_mtx, "ipx_mtx", NULL, \
				    MTX_DEF)
#define	IPX_LOCK_DESTROY(ipx)	mtx_destroy(&(ipx)->ipxp_mtx)
#define	IPX_LOCK(ipx)		mtx_lock(&(ipx)->ipxp_mtx)
#define	IPX_UNLOCK(ipx)		mtx_unlock(&(ipx)->ipxp_mtx)
#define	IPX_LOCK_ASSERT(ipx)	mtx_assert(&(ipx)->ipxp_mtx, MA_OWNED)
#endif /* _KERNEL */

#endif /* !_NETIPX_IPX_PCB_H_ */


code:
/*-
 * Copyright (c) 1984, 1985, 1986, 1987, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Copyright (c) 1995, Mike Mitchell
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)ipx_var.h
 *
 * $FreeBSD: release/9.0.0/sys/netipx/ipx_var.h 194591 2009-06-21 16:11:40Z rwatson $
 */

#ifndef _NETIPX_IPX_VAR_H_
#define _NETIPX_IPX_VAR_H_

/*
 * IPX Kernel Structures and Variables
 */
struct	ipxstat {
	u_long	ipxs_total;		/* total packets received */
	u_long	ipxs_badsum;		/* checksum bad */
	u_long	ipxs_tooshort;		/* packet too short */
	u_long	ipxs_toosmall;		/* not enough data */
	u_long	ipxs_forward;		/* packets forwarded */
	u_long	ipxs_cantforward;	/* packets rcvd for unreachable dest */
	u_long	ipxs_delivered;		/* datagrams delivered to upper level*/
	u_long	ipxs_localout;		/* total ipx packets generated here */
	u_long	ipxs_odropped;		/* lost packets due to nobufs, etc. */
	u_long	ipxs_noroute;		/* packets discarded due to no route */
	u_long	ipxs_mtutoosmall;	/* the interface mtu is too small */
};

#ifdef _KERNEL

#ifdef SYSCTL_DECL
SYSCTL_DECL(_net_ipx);
SYSCTL_DECL(_net_ipx_ipx);
#endif

extern int ipxcksum;
extern long ipx_pexseq;
extern struct ipxstat ipxstat;
extern struct pr_usrreqs ipx_usrreqs;
extern struct pr_usrreqs ripx_usrreqs;
extern struct sockaddr_ipx ipx_netmask;
extern struct sockaddr_ipx ipx_hostmask;

extern const union ipx_net ipx_zeronet;
extern const union ipx_net ipx_broadnet;
extern const union ipx_host ipx_broadhost;

struct ifnet;
struct ipx_addr;
struct ipxpcb;
struct mbuf;
struct thread;
struct route;
struct sockaddr;
struct socket;
struct sockopt;

u_short	ipx_cksum(struct mbuf *m, int len);
int	ipx_control(struct socket *so, u_long cmd, caddr_t data,
	    struct ifnet *ifp, struct thread *td);
void	ipx_ctlinput(int cmd, struct sockaddr *arg_as_sa, void *dummy);
int	ipx_ctloutput(struct socket *so, struct sockopt *sopt);
void	ipx_drop(struct ipxpcb *ipxp, int errno);
void	ipx_init(void);
void	ipx_input(struct mbuf *m, struct ipxpcb *ipxp);
int	ipx_outputfl(struct mbuf *m0, struct route *ro, int flags);
int	ipx_output_type20(struct mbuf *);
int	ipx_peeraddr(struct socket *so, struct sockaddr **nam);
void	ipx_printhost(struct ipx_addr *addr);
int	ipx_sockaddr(struct socket *so, struct sockaddr **nam);

#endif /* _KERNEL */

#endif /* !_NETIPX_IPX_VAR_H_ */

repo_name: veiledmerc/mira

license: mit


code:
/*-
 * Copyright (c) 1984, 1985, 1986, 1987, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Copyright (c) 1995, Mike Mitchell
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)spx.h
 *
 * $FreeBSD: release/9.0.0/sys/netipx/spx.h 194547 2009-06-20 18:24:25Z rwatson $
 */

#ifndef _NETIPX_SPX_H_
#define	_NETIPX_SPX_H_

/*
 * Definitions for IPX style Sequenced Packet Protocol
 */

struct spxhdr {
	u_char	spx_cc;		/* connection control */
	u_char	spx_dt;		/* datastream type */
#define	SPX_SP	0x80		/* system packet */
#define	SPX_SA	0x40		/* send acknowledgement */
#define	SPX_OB	0x20		/* attention (out of band data) */
#define	SPX_EM	0x10		/* end of message */
	u_short	spx_sid;	/* source connection identifier */
	u_short	spx_did;	/* destination connection identifier */
	u_short	spx_seq;	/* sequence number */
	u_short	spx_ack;	/* acknowledge number */
	u_short	spx_alo;	/* allocation number */
} __packed;

/*
 * Definitions for NS(tm) Internet Datagram Protocol
 * containing a Sequenced Packet Protocol packet.
 */
struct spx {
	struct ipx	si_i;
	struct spxhdr 	si_s;
} __packed;
struct spx_q {
	struct mbuf		*sq_msi;
	struct spx		*sq_si;
	LIST_ENTRY(spx_q)	 sq_entry;
};
#define SI(x)	((struct spx *)x)
#define si_sum	si_i.ipx_sum
#define si_len	si_i.ipx_len
#define si_tc	si_i.ipx_tc
#define si_pt	si_i.ipx_pt
#define si_dna	si_i.ipx_dna
#define si_sna	si_i.ipx_sna
#define si_sport	si_i.ipx_sna.x_port
#define si_cc	si_s.spx_cc
#define si_dt	si_s.spx_dt
#define si_sid	si_s.spx_sid
#define si_did	si_s.spx_did
#define si_seq	si_s.spx_seq
#define si_ack	si_s.spx_ack
#define si_alo	si_s.spx_alo

/*
 * SPX control block, one per connection
 */
struct spxpcb {
	LIST_HEAD(, spx_q)	s_q;	/* queue for out-of-order receipt */
	struct	ipxpcb	*s_ipxpcb;	/* backpointer to internet pcb */
	u_char	s_state;
	u_char	s_flags;
#define	SF_ACKNOW	0x01		/* Ack peer immediately */
#define	SF_DELACK	0x02		/* Ack, but try to delay it */
#define	SF_HI	0x04			/* Show headers on input */
#define	SF_HO	0x08			/* Show headers on output */
#define	SF_PI	0x10			/* Packet (datagram) interface */
#define SF_WIN	0x20			/* Window info changed */
#define SF_RXT	0x40			/* Rxt info changed */
#define SF_RVD	0x80			/* Calling from read usrreq routine */
	u_short s_mtu;			/* Max packet size for this stream */
/* use sequence fields in headers to store sequence numbers for this
   connection */
	struct	ipx	s_ipx;
	struct	spxhdr	s_shdr;		/* prototype header to transmit */
#define s_cc s_shdr.spx_cc		/* connection control (for EM bit) */
#define s_dt s_shdr.spx_dt		/* datastream type */
#define s_sid s_shdr.spx_sid		/* source connection identifier */
#define s_did s_shdr.spx_did		/* destination connection identifier */
#define s_seq s_shdr.spx_seq		/* sequence number */
#define s_ack s_shdr.spx_ack		/* acknowledge number */
#define s_alo s_shdr.spx_alo		/* allocation number */
#define s_dport s_ipx.ipx_dna.x_port	/* where we are sending */
	struct spxhdr s_rhdr;		/* last received header (in effect!)*/
	u_short s_rack;			/* their acknowledge number */
	u_short s_ralo;			/* their allocation number */
	u_short s_smax;			/* highest packet # we have sent */
	u_short	s_snxt;			/* which packet to send next */

/* congestion control */
#define	CUNIT	1024			/* scaling for ... */
	int	s_cwnd;			/* Congestion-controlled window */
					/* in packets * CUNIT */
	short	s_swnd;			/* == tcp snd_wnd, in packets */
	short	s_smxw;			/* == tcp max_sndwnd */
					/* difference of two spx_seq's can be
					   no bigger than a short */
	u_short	s_swl1;			/* == tcp snd_wl1 */
	u_short	s_swl2;			/* == tcp snd_wl2 */
	int	s_cwmx;			/* max allowable cwnd */
	int	s_ssthresh;		/* s_cwnd size threshold for
					 * slow start exponential-to-
					 * linear switch */
/* transmit timing stuff
 * srtt and rttvar are stored as fixed point, for convenience in smoothing.
 * srtt has 3 bits to the right of the binary point, rttvar has 2.
 */
	short	s_idle;			/* time idle */
#define	SPXT_NTIMERS	4
	short	s_timer[SPXT_NTIMERS];	/* timers */
	short	s_rxtshift;		/* log(2) of rexmt exp. backoff */
	short	s_rxtcur;		/* current retransmit value */
	u_short	s_rtseq;		/* packet being timed */
	short	s_rtt;			/* timer for round trips */
	short	s_srtt;			/* averaged timer */
	short	s_rttvar;		/* variance in round trip time */
	char	s_force;		/* which timer expired */
	char	s_dupacks;		/* counter to intuit xmt loss */

/* out of band data */
	char	s_oobflags;
#define SF_SOOB	0x08			/* sending out of band data */
#define SF_IOOB 0x10			/* receiving out of band data */
	char	s_iobc;			/* input characters */
/* debug stuff */
	u_short	s_want;			/* Last candidate for sending */
	char	s_outx;			/* exit taken from spx_output */
	char	s_inx;			/* exit taken from spx_input */
	u_short	s_flags2;		/* more flags for testing */
#define SF_NEWCALL	0x100		/* for new_recvmsg */
#define SO_NEWCALL	10		/* for new_recvmsg */
};

#define	ipxtospxpcb(np)	((struct spxpcb *)(np)->ipxp_pcb)
#define	sotospxpcb(so)	(ipxtospxpcb(sotoipxpcb(so)))

#ifdef _KERNEL

extern struct pr_usrreqs spx_usrreqs;
extern struct pr_usrreqs spx_usrreq_sps;

void	spx_ctlinput(int cmd, struct sockaddr *arg_as_sa, void *dummy);
int	spx_ctloutput(struct socket *so, struct sockopt *sopt);
void	spx_fasttimo(void);
void	spx_init(void);
void	spx_input(struct mbuf *m, struct ipxpcb *ipxp);
void	spx_slowtimo(void);

#endif /* _KERNEL */

#endif /* !_NETIPX_SPX_H_ */


code:
/*-
 * Copyright (c) 1984, 1985, 1986, 1987, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Copyright (c) 1995, Mike Mitchell
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)spx_debug.h
 *
 * $FreeBSD: release/9.0.0/sys/netipx/spx_debug.h 171656 2007-07-30 11:06:42Z des $
 */

#ifndef _NETIPX_SPX_DEBUG_H_
#define	_NETIPX_SPX_DEBUG_H_

struct	spx_debug {
	u_long	sd_time;
	short	sd_act;
	short	sd_ostate;
	caddr_t	sd_cb;
	short	sd_req;
	struct	spx sd_si;
	struct	spxpcb sd_sp;
};

#define	SA_INPUT 	0
#define	SA_OUTPUT	1
#define	SA_USER		2
#define	SA_RESPOND	3
#define	SA_DROP		4

#ifdef SANAMES
const char *spxnames[] =
    { "input", "output", "user", "respond", "drop" };
#endif

#define	SPX_NDEBUG 100
#ifndef _KERNEL
/* XXX common variables for broken applications. */
struct	spx_debug spx_debug[SPX_NDEBUG];
int	spx_debx;
#endif

#ifdef _KERNEL
extern char *prurequests[];
extern char *sanames[];

void	spx_trace(short act, u_char ostate, struct spxpcb *sp, struct spx *si,
	    int req);
#endif

#endif /* !_NETIPX_SPX_DEBUG_H_ */


code:
/*-
 * Copyright (c) 1982, 1986, 1988, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Copyright (c) 1995, Mike Mitchell
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)spx_timer.h
 *
 * $FreeBSD: release/9.0.0/sys/netipx/spx_timer.h 165899 2007-01-08 22:14:00Z rwatson $
 */

#ifndef _NETIPX_SPX_TIMER_H_
#define _NETIPX_SPX_TIMER_H_

/*
 * Definitions of the SPX timers.  These timers are counted
 * down PR_SLOWHZ times a second.
 */
#define	SPXT_REXMT	0		/* retransmit */
#define	SPXT_PERSIST	1		/* retransmit persistence */
#define	SPXT_KEEP	2		/* keep alive */
#define	SPXT_2MSL	3		/* 2*msl quiet time timer */

/*
 * The SPXT_REXMT timer is used to force retransmissions.
 * The SPX has the SPXT_REXMT timer set whenever segments
 * have been sent for which ACKs are expected but not yet
 * received.  If an ACK is received which advances tp->snd_una,
 * then the retransmit timer is cleared (if there are no more
 * outstanding segments) or reset to the base value (if there
 * are more ACKs expected).  Whenever the retransmit timer goes off,
 * we retransmit one unacknowledged segment, and do a backoff
 * on the retransmit timer.
 *
 * The SPXT_PERSIST timer is used to keep window size information
 * flowing even if the window goes shut.  If all previous transmissions
 * have been acknowledged (so that there are no retransmissions in progress),
 * and the window is too small to bother sending anything, then we start
 * the SPXT_PERSIST timer.  When it expires, if the window is nonzero,
 * we go to transmit state.  Otherwise, at intervals send a single byte
 * into the peer's window to force him to update our window information.
 * We do this at most as often as SPXT_PERSMIN time intervals,
 * but no more frequently than the current estimate of round-trip
 * packet time.  The SPXT_PERSIST timer is cleared whenever we receive
 * a window update from the peer.
 *
 * The SPXT_KEEP timer is used to keep connections alive.  If an
 * connection is idle (no segments received) for SPXTV_KEEP amount of time,
 * but not yet established, then we drop the connection.  If the connection
 * is established, then we force the peer to send us a segment by sending:
 *	<SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK>
 * This segment is (deliberately) outside the window, and should elicit
 * an ack segment in response from the peer.  If, despite the SPXT_KEEP
 * initiated segments we cannot elicit a response from a peer in SPXT_MAXIDLE
 * amount of time, then we drop the connection.
 */

#define	SPX_TTL		30		/* default time to live for SPX segs */
/*
 * Time constants.
 */
#define	SPXTV_MSL	( 15*PR_SLOWHZ)		/* max seg lifetime */
#define	SPXTV_SRTTBASE	0			/* base roundtrip time;
						   if 0, no idea yet */
#define	SPXTV_SRTTDFLT	(  3*PR_SLOWHZ)		/* assumed RTT if no info */

#define	SPXTV_PERSMIN	(  5*PR_SLOWHZ)		/* retransmit persistence */
#define	SPXTV_PERSMAX	( 60*PR_SLOWHZ)		/* maximum persist interval */

#define	SPXTV_KEEP	( 75*PR_SLOWHZ)		/* keep alive - 75 secs */
#define	SPXTV_MAXIDLE	(  8*SPXTV_KEEP)	/* maximum allowable idle
						   time before drop conn */

#define	SPXTV_MIN	(  1*PR_SLOWHZ)		/* minimum allowable value */
#define	SPXTV_REXMTMAX	( 64*PR_SLOWHZ)		/* max allowable REXMT value */

#define	SPX_LINGERTIME	120			/* linger at most 2 minutes */

#define	SPX_MAXRXTSHIFT	12			/* maximum retransmits */

#ifdef	SPXTIMERS
char *spxtimers[] =
    { "REXMT", "PERSIST", "KEEP", "2MSL" };
#endif

/*
 * Force a time value to be in a certain range.
 */
#define	SPXT_RANGESET(tv, value, tvmin, tvmax) { \
	(tv) = (value); \
	if ((tv) < (tvmin)) \
		(tv) = (tvmin); \
	else if ((tv) > (tvmax)) \
		(tv) = (tvmax); \
}

#endif /* !_NETIPX_SPX_TIMER_H_ */


code:
/*-
 * Copyright (c) 1984, 1985, 1986, 1987, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Copyright (c) 1995, Mike Mitchell
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)spx_var.h
 *
 * $FreeBSD: release/9.0.0/sys/netipx/spx_var.h 194547 2009-06-20 18:24:25Z rwatson $
 */

#ifndef _NETIPX_SPX_VAR_H_
#define _NETIPX_SPX_VAR_H_

struct	spxstat {
	long	spxs_connattempt;	/* connections initiated */
	long	spxs_accepts;		/* connections accepted */
	long	spxs_connects;		/* connections established */
	long	spxs_drops;		/* connections dropped */
	long	spxs_conndrops;		/* embryonic connections dropped */
	long	spxs_closed;		/* conn. closed (includes drops) */
	long	spxs_segstimed;		/* segs where we tried to get rtt */
	long	spxs_rttupdated;	/* times we succeeded */
	long	spxs_delack;		/* delayed acks sent */
	long	spxs_timeoutdrop;	/* conn. dropped in rxmt timeout */
	long	spxs_rexmttimeo;	/* retransmit timeouts */
	long	spxs_persisttimeo;	/* persist timeouts */
	long	spxs_keeptimeo;		/* keepalive timeouts */
	long	spxs_keepprobe;		/* keepalive probes sent */
	long	spxs_keepdrops;		/* connections dropped in keepalive */

	long	spxs_sndtotal;		/* total packets sent */
	long	spxs_sndpack;		/* data packets sent */
	long	spxs_sndbyte;		/* data bytes sent */
	long	spxs_sndrexmitpack;	/* data packets retransmitted */
	long	spxs_sndrexmitbyte;	/* data bytes retransmitted */
	long	spxs_sndacks;		/* ack-only packets sent */
	long	spxs_sndprobe;		/* window probes sent */
	long	spxs_sndurg;		/* packets sent with URG only */
	long	spxs_sndwinup;		/* window update-only packets sent */
	long	spxs_sndctrl;		/* control (SYN|FIN|RST) packets sent */
	long	spxs_sndvoid;		/* couldn't find requested packet*/

	long	spxs_rcvtotal;		/* total packets received */
	long	spxs_rcvpack;		/* packets received in sequence */
	long	spxs_rcvbyte;		/* bytes received in sequence */
	long	spxs_rcvbadsum;		/* packets received with ccksum errs */
	long	spxs_rcvbadoff;		/* packets received with bad offset */
	long	spxs_rcvshort;		/* packets received too short */
	long	spxs_rcvduppack;	/* duplicate-only packets received */
	long	spxs_rcvdupbyte;	/* duplicate-only bytes received */
	long	spxs_rcvpartduppack;	/* packets with some duplicate data */
	long	spxs_rcvpartdupbyte;	/* dup. bytes in part-dup. packets */
	long	spxs_rcvoopack;		/* out-of-order packets received */
	long	spxs_rcvoobyte;		/* out-of-order bytes received */
	long	spxs_rcvpackafterwin;	/* packets with data after window */
	long	spxs_rcvbyteafterwin;	/* bytes rcvd after window */
	long	spxs_rcvafterclose;	/* packets rcvd after "close" */
	long	spxs_rcvwinprobe;	/* rcvd window probe packets */
	long	spxs_rcvdupack;		/* rcvd duplicate acks */
	long	spxs_rcvacktoomuch;	/* rcvd acks for unsent data */
	long	spxs_rcvackpack;	/* rcvd ack packets */
	long	spxs_rcvackbyte;	/* bytes acked by rcvd acks */
	long	spxs_rcvwinupd;		/* rcvd window update packets */
};
struct	spx_istat {
	short	hdrops;
	short	badsum;
	short	badlen;
	short	slotim;
	short	fastim;
	short	nonucn;
	short	noconn;
	short	notme;
	short	wrncon;
	short	bdreas;
	short	gonawy;
	short	notyet;
	short	lstdup;
	struct spxstat newstats;
};

#define	SPX_ISSINCR	128
/*
 * spx sequence numbers are 16 bit integers operated
 * on with modular arithmetic.  These macros can be
 * used to compare such integers.
 */
#define	SSEQ_LT(a,b)	(((short)((a)-(b))) < 0)
#define	SSEQ_LEQ(a,b)	(((short)((a)-(b))) <= 0)
#define	SSEQ_GT(a,b)	(((short)((a)-(b))) > 0)
#define	SSEQ_GEQ(a,b)	(((short)((a)-(b))) >= 0)

#ifdef _KERNEL
/* Following was struct spxstat spxstat; */
#ifndef spxstat
#define	spxstat	spx_istat.newstats
#endif
extern struct spx_istat	spx_istat;
extern u_short	spx_newchecks[50];

int	spx_output(struct spxpcb *cb, struct mbuf *m0);
int	spx_reass(struct spxpcb *cb, struct mbuf *msi, struct spx *si);
void	spx_reass_flush(struct spxpcb *cb);
void	spx_reass_init(struct spxpcb *cb);
#endif

#endif /* !_NETIPX_SPX_VAR_H_ */


code:
/*
 * Copyright (c) 1996-2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 * 	All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Author: Hartmut Brandt <harti@freebsd.org>
 *
 * $Begemot: libunimsg/netnatm/addr.h,v 1.3 2004/07/08 08:21:45 brandt Exp $
 */
#ifndef _NETNATM_ADDR_H_
#define _NETNATM_ADDR_H_

int uni_str2nsap(u_char *, const char *);
void uni_nsap2str(char *, const u_char *, int);

void uni_prefix2str(char *, const u_char *, u_int, int);

int uni_e1642nsap(u_char *, const char *);
int uni_nsap2e164(char *, const u_char *, int);

#endif


code:
/*
 * Copyright (c) 2003-2004
 *	Hartmut Brandt
 *	All rights reserved.
 *
 * Copyright (c) 2001-2002
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 *	All rights reserved.
 *
 * Author: Harti Brandt <harti@freebsd.org>
 *
 * Redistribution of this software and documentation and use in source and
 * binary forms, with or without modification, are permitted provided that
 * the following conditions are met:
 *
 * 1. Redistributions of source code or documentation must retain the above
 *    copyright notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE AUTHORS
 * AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * THE AUTHORS OR ITS CONTRIBUTORS  BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $Begemot: libunimsg/netnatm/api/atmapi.h,v 1.1 2004/07/08 08:21:48 brandt Exp $
 *
 * ATM API as defined per af-saa-0108
 */
#ifndef _NETNATM_API_ATMAPI_H_
#define _NETNATM_API_ATMAPI_H_

#include <sys/types.h>

/* size of an endpointlen including trailing \0 */
#define	ATM_EPNAMSIZ	65

enum atmstate {
	ATM_A0,		/* non existent */
	ATM_A1,		/* initial */
	ATM_A2,		/* outgoing call preparation */
	ATM_A3,		/* outgoing call requested */
	ATM_A4,		/* incoming call preparation */
	ATM_A5,		/* wait incoming call */
	ATM_A6,		/* incoming call present */
	ATM_A7,		/* incoming call requested */
	ATM_A8,		/* p2p data transfer */
	ATM_A9,		/* p2mp root data transfer */
	ATM_A10,	/* p2mp leaf data transfer */
	ATM_A11,	/* terminated */
};

enum atmop {
	ATMOP_RESP,				/* 0 */
	ATMOP_ABORT_CONNECTION,
	ATMOP_ACCEPT_INCOMING_CALL,
	ATMOP_ADD_PARTY,
	ATMOP_ADD_PARTY_REJECT,
	ATMOP_ADD_PARTY_SUCCESS,		/* 5 */
	ATMOP_ARRIVAL_OF_INCOMING_CALL,
	ATMOP_CALL_RELEASE,
	ATMOP_CONNECT_OUTGOING_CALL,
	ATMOP_DROP_PARTY,
	ATMOP_GET_LOCAL_PORT_INFO,		/* 10 */
	ATMOP_P2MP_CALL_ACTIVE,
	ATMOP_P2P_CALL_ACTIVE,
	ATMOP_PREPARE_INCOMING_CALL,
	ATMOP_PREPARE_OUTGOING_CALL,
	ATMOP_QUERY_CONNECTION_ATTRIBUTES,	/* 15 */
	ATMOP_REJECT_INCOMING_CALL,
	ATMOP_SET_CONNECTION_ATTRIBUTES,
	ATMOP_WAIT_ON_INCOMING_CALL,
	ATMOP_SET_CONNECTION_ATTRIBUTES_X,
	ATMOP_QUERY_CONNECTION_ATTRIBUTES_X,	/* 20 */
	ATMOP_QUERY_STATE,
};

#define ATM_DEFINE_ERRORS						\
   DEF(ATMERR_OK,		 0, "OK")				\
   DEF(ATMERR_SYS,		-1, "syscall error")			\
   DEF(ATMERR_BAD_OP,		-2, "bad operation")			\
   DEF(ATMERR_BAD_ARGS,		-3, "bad arguments for operation")	\
   DEF(ATMERR_BAD_STATE,	-4, "operation in bad state")		\
   DEF(ATMERR_BAD_ATTR,		-5, "unknown attribute")		\
   DEF(ATMERR_BAD_VALUE,	-6, "bad attribute value")		\
   DEF(ATMERR_BUSY,		-7, "busy")				\
   DEF(ATMERR_RDONLY,		-8, "read-only attribute")		\
   DEF(ATMERR_BAD_SAP,		-9, "bad SAP")				\
   DEF(ATMERR_OVERLAP,		-10,"overlaping SAP")			\
   DEF(ATMERR_BAD_ENDPOINT,	-11,"bad ATM endpoint")			\
   DEF(ATMERR_PREVIOUSLY_ABORTED,-12,"previously aborted")		\
   DEF(ATMERR_NO_CALL,		-13,"no incoming call")			\
   DEF(ATMERR_BAD_LEAF_IDENT,	-14,"bad leaf identifier")		\
   DEF(ATMERR_BAD_PORT,		-15,"unknown port")			\
   DEF(ATMERR_BAD_SIGNAL,	-29-UNIAPI_ERROR_BAD_SIGNAL, "bad signal")\
   DEF(ATMERR_BADCU,		-29-UNIAPI_ERROR_BADCU, "bad coordinator state")\
   DEF(ATMERR_BAD_CALLSTATE,	-29-UNIAPI_ERROR_BAD_CALLSTATE, "bad call state")\
   DEF(ATMERR_BAD_EPSTATE,	-29-UNIAPI_ERROR_BAD_EPSTATE, "bad party state")\
   DEF(ATMERR_BAD_UNIARG,	-29-UNIAPI_ERROR_BAD_ARG, "bad uni argument")\
   DEF(ATMERR_BAD_CALL,		-29-UNIAPI_ERROR_BAD_CALL, "unknown call")\
   DEF(ATMERR_BAD_PARTY,	-29-UNIAPI_ERROR_BAD_PARTY, "unknown party")\
   DEF(ATMERR_BAD_CTYPE,	-29-UNIAPI_ERROR_BAD_CTYPE, "wrong call type")\
   DEF(ATMERR_BAD_IE,		-29-UNIAPI_ERROR_BAD_IE, "bad information element")\
   DEF(ATMERR_EPREF_INUSE,	-29-UNIAPI_ERROR_EPREF_INUSE, "endpoint reference in use")\
   DEF(ATMERR_MISSING_IE,	-29-UNIAPI_ERROR_MISSING_IE, "missing information element")\
   DEF(ATMERR_ENCODING,		-29-UNIAPI_ERROR_ENCODING, "encoding error")\
   DEF(ATMERR_NOMEM,		-29-UNIAPI_ERROR_NOMEM, "no memory")\
   DEF(ATMERR_UNIBUSY,		-29-UNIAPI_ERROR_BUSY, "uni process busy")

#define ATM_MKUNIERR(E)	(-29 - (E))

enum atm_error {
#define DEF(NAME,VAL,STR)	NAME = (VAL),
ATM_DEFINE_ERRORS
#undef DEF
};

enum atm_attribute {
	ATM_ATTR_NONE = 0,
	ATM_ATTR_BLLI_SELECTOR,
	ATM_ATTR_BLLI,
	ATM_ATTR_BEARER,
	ATM_ATTR_TRAFFIC,
	ATM_ATTR_QOS,
	ATM_ATTR_EXQOS,
	ATM_ATTR_CALLED,
	ATM_ATTR_CALLEDSUB,
	ATM_ATTR_CALLING,
	ATM_ATTR_CALLINGSUB,
	ATM_ATTR_AAL,
	ATM_ATTR_EPREF,
	ATM_ATTR_CONNED,
	ATM_ATTR_CONNEDSUB,
	ATM_ATTR_EETD,
	ATM_ATTR_ABRSETUP,
	ATM_ATTR_ABRADD,
	ATM_ATTR_CONNID,
	ATM_ATTR_MDCR,
};

struct atm_resp {
	int32_t		resp;
	uint32_t	data;		/* type of attached data */
};
enum {
	ATMRESP_NONE,			/* no data */
	ATMRESP_ATTRS,			/* attribute(s) */
	ATMRESP_PORTS,			/* port info */
	ATMRESP_STATE,			/* endpoint state */
	ATMRESP_EXSTAT,			/* extended status */
};

struct atm_abort_connection {
	struct uni_ie_cause cause;
};

struct atm_query_connection_attributes {
	uint32_t	attr;
};
struct atm_set_connection_attributes {
	uint32_t	attr;
};
struct atm_query_connection_attributes_x {
	uint32_t	count;
#if defined(__GNUC__) && __GNUC__ < 3
	uint32_t	attr[0];
#else
	uint32_t	attr[];
#endif
};
struct atm_set_connection_attributes_x {
	uint32_t	count;
#if defined(__GNUC__) && __GNUC__ < 3
	uint32_t	attr[0];
#else
	uint32_t	attr[];
#endif
};
struct atm_prepare_incoming_call {
	struct uni_sap	sap;
	uint32_t	queue_size;
};
struct atm_connect_outgoing_call {
	struct uni_ie_called	called;
};
struct atm_call_release {
	struct uni_ie_cause	cause[2];
};
struct atm_p2p_call_active {
	struct uni_ie_connid	connid;
};
struct atm_p2mp_call_active {
	struct uni_ie_connid	connid;
};
struct atm_accept_incoming_call {
	char	newep[ATM_EPNAMSIZ];
};
struct atm_reject_incoming_call {
	struct uni_ie_cause	cause;
};
struct atm_add_party {
	uint16_t		leaf_ident;
	struct uni_ie_called	called;
};
struct atm_add_party_success {
	uint16_t		leaf_ident;
};
struct atm_add_party_reject {
	uint16_t		leaf_ident;
	struct uni_ie_cause	cause;
};
struct atm_drop_party {
	uint16_t		leaf_ident;
	struct uni_ie_cause	cause;
};

/*
 * Get local port info. If port is 0, information on all ports is returned,
 * otherwise only on the named port.
 * The response consists of a header with two counters, a list of ports
 * (struct atm_port_info) and a list of addresses (struct uni_addr).
 * The port to which an address belongs is implicit in the num_addrs field
 * of the port.
 */
struct atm_get_local_port_info {
	uint32_t	port;
};

struct atm_port_list {
	uint32_t	num_ports;	/* number of ports */
	uint32_t	num_addrs;	/* total number of addresses */
};

struct atm_port_info {
	uint32_t	port;
	uint32_t	pcr;
	uint32_t	max_vpi_bits;
	uint32_t	max_vci_bits;
	uint32_t	max_svpc_vpi;
	uint32_t	max_svcc_vpi;
	uint32_t	min_svcc_vci;
	u_char		esi[6];
	uint32_t	num_addrs;	/* number of addresses on this port */
};

/*
 * Endpoint state info
 */
struct atm_epstate {
	char	name[ATM_EPNAMSIZ];
	uint8_t	state;
};

/*
 * Extended status information.
 */
struct atm_exstatus {
	uint32_t	neps;		/* endpoints */
	uint32_t	nports;		/* ports */
	uint32_t	nconns;		/* connections */
	uint32_t	nparties;	/* number of parties */
};
struct atm_exstatus_ep {
	char		name[ATM_EPNAMSIZ];
	uint8_t		state;		/* Ux */
};
struct atm_exstatus_port {
	uint32_t	portno;
	uint8_t		state;
};
struct atm_exstatus_conn {
	uint32_t	id;
	uint32_t	cref;		/* (flag << 23) | cref */
	uint32_t	port;
	char		ep[ATM_EPNAMSIZ];	/* \0 - none */
	uint8_t		state;		/* Cx */
};
struct atm_exstatus_party {
	uint32_t	connid;
	uint16_t	epref;
	uint8_t		state;		/* Px */
};
#endif


code:
/*
 * Copyright (c) 2003-2004
 *	Hartmut Brandt
 *	All rights reserved.
 *
 * Author: Harti Brandt <harti@freebsd.org>
 *
 * Redistribution of this software and documentation and use in source and
 * binary forms, with or without modification, are permitted provided that
 * the following conditions are met:
 *
 * 1. Redistributions of source code or documentation must retain the above
 *    copyright notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE AUTHOR
 * AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * THE AUTHOR OR ITS CONTRIBUTORS  BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $Begemot: libunimsg/netnatm/api/ccatm.h,v 1.1 2004/07/08 08:21:58 brandt Exp $
 *
 * ATM API as defined per af-saa-0108
 *
 * Interface to the supporting code.
 */

#ifndef _API_CCATM_H_
#define _API_CCATM_H_

struct ccuser;
struct ccconn;
struct ccport;
struct ccdata;

struct cc_funcs {
	/* send signal to API user */
	void	(*send_user)(struct ccuser *, void *, u_int, void *, size_t);

	/* respond API user */
	void	(*respond_user)(struct ccuser *, void *, int, u_int,
		    void *, size_t);

	/* send signal to uni for connection */
	void	(*send_uni)(struct ccconn *, void *, u_int, u_int,
		    struct uni_msg *);

	/* send global signal to uni */
	void	(*send_uni_glob)(struct ccport *, void *, u_int, u_int,
		    struct uni_msg *);

	/* log a message */
	void	(*log)(const char *, ...);
};

enum {
	CCLOG_USER_STATE	= 0x00000001,
	CCLOG_USER_INST		= 0x00000002,
	CCLOG_USER_SIG		= 0x00000004,
	CCLOG_CONN_STATE	= 0x00000010,
	CCLOG_CONN_INST		= 0x00000020,
	CCLOG_CONN_SIG		= 0x00000040,
	CCLOG_PARTY_STATE	= 0x00000100,
	CCLOG_PARTY_INST	= 0x00000200,
	CCLOG_PARTY_SIG		= 0x00000400,
	CCLOG_SIGS		= 0x00001000,
};

/* instance handling */
struct ccdata *cc_create(const struct cc_funcs *);
void cc_destroy(struct ccdata *);
void cc_reset(struct ccdata *);

/* input a response from the UNI layer to CC */
int cc_uni_response(struct ccport *, u_int cookie, u_int reason, u_int state);

/* Signal from UNI on this port */
int cc_uni_signal(struct ccport *, u_int cookie, u_int sig, struct uni_msg *);

/* retrieve addresses */
int cc_get_addrs(struct ccdata *, u_int, struct uni_addr **, u_int **, u_int *);

/* dump state */
typedef int (*cc_dump_f)(struct ccdata *, void *, const char *);
int cc_dump(struct ccdata *, size_t, cc_dump_f, void *);

/* start/stop port */
int cc_port_stop(struct ccdata *, u_int);
int cc_port_start(struct ccdata *, u_int);

/* is port running? */
int cc_port_isrunning(struct ccdata *, u_int, int *);

/* return port number */
u_int cc_port_no(struct ccport *);

/* Clear address and prefix information from the named port. */
int cc_port_clear(struct ccdata *, u_int);

/* Address registered.  */
int cc_addr_register(struct ccdata *, u_int, const struct uni_addr *);

/* Address unregistered. */
int cc_addr_unregister(struct ccdata *, u_int, const struct uni_addr *);

/* get port info */
int cc_port_get_param(struct ccdata *, u_int, struct atm_port_info *);

/* set port info */
int cc_port_set_param(struct ccdata *, const struct atm_port_info *);

/* get port list */
int cc_port_getlist(struct ccdata *, u_int *, u_int **);

/* create a port */
struct ccport *cc_port_create(struct ccdata *, void *, u_int);

/* destroy a port */
void cc_port_destroy(struct ccport *, int);

/* New endpoint created */
struct ccuser *cc_user_create(struct ccdata *, void *, const char *);

/* destroy user endpoint */
void cc_user_destroy(struct ccuser *);

/* signal from user */
int cc_user_signal(struct ccuser *, u_int, struct uni_msg *);

/* Management is given up on this node. */
void cc_unmanage(struct ccdata *);

/* handle all queued signals */
void cc_work(struct ccdata *);

/* set/get logging flags */
void cc_set_log(struct ccdata *, u_int);
u_int cc_get_log(const struct ccdata *);

/* get extended status */
int cc_get_extended_status(const struct ccdata *, struct atm_exstatus *,
    struct atm_exstatus_ep **, struct atm_exstatus_port **,
    struct atm_exstatus_conn **, struct atm_exstatus_party **);

#endif


code:
/*
 * Copyright (c) 2001-2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 * 	All rights reserved.
 *
 * Author: Hartmut Brandt <harti@freebsd.org>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Begemot: libunimsg/netnatm/api/unisap.h,v 1.6 2005/05/23 11:49:17 brandt_h Exp $
 */
#ifndef _NETNATM_API_UNISAP_H_
#define _NETNATM_API_UNISAP_H_

#include <netnatm/msg/uni_config.h>

enum unisve_tag {
	UNISVE_ABSENT,		/* Element is absent */
	UNISVE_PRESENT,		/* Element is present with specific value */
	UNISVE_ANY		/* Any values is acceptable */
};

struct unisve_addr {
	enum unisve_tag		tag;
	enum uni_addr_type	type;	/* type of address */
	enum uni_addr_plan	plan;	/* addressing plan */
	uint32_t		len;	/* length of address */
	u_char			addr[UNI_ADDR_MAXLEN];
};

struct unisve_selector {
	enum unisve_tag	tag;
	uint8_t		selector;
};

struct unisve_blli_id2 {
	enum unisve_tag	tag;
	u_int		proto:5;	/* the protocol */
	u_int		user:7;		/* user specific protocol */
};

struct unisve_blli_id3 {
	enum unisve_tag	tag;
	u_int		proto:5;	/* L3 protocol */
	u_int		user:7;		/* user specific protocol */
	u_int		ipi:8;		/* ISO/IEC TR 9557 IPI */
	u_int		oui:24;		/* IEEE 802.1 OUI */
	u_int		pid:16;		/* IEEE 802.1 PID */
	uint32_t	noipi;		/* ISO/IEC TR 9557 per frame */
};

struct unisve_bhli {
	enum unisve_tag	tag;
	enum uni_bhli	type;		/* type of info */
	uint32_t	len;		/* length of info */
	uint8_t		info[8];	/* info itself */
};

struct uni_sap {
	struct unisve_addr	addr;
	struct unisve_selector	selector;
	struct unisve_blli_id2	blli_id2;
	struct unisve_blli_id3	blli_id3;
	struct unisve_bhli	bhli;
};

int unisve_check_addr(const struct unisve_addr *);
int unisve_check_selector(const struct unisve_selector *);
int unisve_check_blli_id2(const struct unisve_blli_id2 *);
int unisve_check_blli_id3(const struct unisve_blli_id3 *);
int unisve_check_bhli(const struct unisve_bhli *);

int unisve_check_sap(const struct uni_sap *);

int unisve_overlap_addr(const struct unisve_addr *, const struct unisve_addr *);
int unisve_overlap_selector(const struct unisve_selector *,
    const struct unisve_selector *);
int unisve_overlap_blli_id2(const struct unisve_blli_id2 *,
    const struct unisve_blli_id2 *);
int unisve_overlap_blli_id3(const struct unisve_blli_id3 *,
    const struct unisve_blli_id3 *);
int unisve_overlap_bhli(const struct unisve_bhli *,
    const struct unisve_bhli *);
int unisve_overlap_sap(const struct uni_sap *, const struct uni_sap *);

int unisve_is_catchall(const struct uni_sap *);
int unisve_match(const struct uni_sap *, const struct uni_ie_called *,
	const struct uni_ie_blli *, const struct uni_ie_bhli *);

enum {
	UNISVE_OK = 0,
	UNISVE_ERROR_BAD_TAG,
	UNISVE_ERROR_TYPE_PLAN_CONFLICT,
	UNISVE_ERROR_ADDR_SEL_CONFLICT,
	UNISVE_ERROR_ADDR_LEN,
	UNISVE_ERROR_BAD_ADDR_TYPE,
	UNISVE_ERROR_BAD_BHLI_TYPE,
	UNISVE_ERROR_BAD_BHLI_LEN,
};

#define UNISVE_ERRSTR					\
	"no error",					\
	"bad SVE tag",					\
	"bad address type/plan combination",		\
	"bad address plan/selector tag combination",	\
	"bad address length in SVE",			\
	"unknown address type in SVE",			\
	"bad BHLI type in SVE",				\
	"BHLI info too long in SVE",

#endif


code:
/*
 * Copyright (c) 1996-2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 * 	All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Author: Hartmut Brandt <harti@freebsd.org>
 *
 * $Begemot: libunimsg/netnatm/msg/uni_config.h,v 1.3 2003/09/19 11:58:15 hbb Exp $
 */
#ifndef _uni_uni_config_h_
#define _uni_uni_config_h_

enum {
	/* maximum number of reported error IEs */
	UNI_MAX_ERRIE	= 50,

	/* maximum number of Generic Identifier Transport IE's per message */
	UNI_NUM_IE_GIT	= 3,

	/* maximum number of BLLI's in SETUP */
	UNI_NUM_IE_BLLI	= 3,

	/* maximum number of CALLEDSUB's */
	UNI_NUM_IE_CALLEDSUB = 2,

	/* maximum number of CALLINGSUB's */
	UNI_NUM_IE_CALLINGSUB = 2,

	/* maximum number of TNS's */
	UNI_NUM_IE_TNS = 4,

	/* maximum length of TNS name */
	UNI_TNS_MAXLEN = 4,

	/* maximum info size in user-to-user signalling IE */
	UNI_UU_MAXLEN	= 128,

	/* maximum length of address */
	UNI_ADDR_MAXLEN	= 20,

	/* maximum length of subaddress */
	UNI_SUBADDR_MAXLEN = 20,

	/* maximum number of DTLs */
	UNI_NUM_IE_DTL = 10,
	/* maximum number of identifiers in DTL */
	UNI_DTL_MAXNUM = 20,
};
#endif


code:
/*
 * Copyright (c) 1996-2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 * 	All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Author: Hartmut Brandt <harti@freebsd.org>
 *
 * $Begemot: libunimsg/netnatm/msg/uni_hdr.h,v 1.6 2004/07/08 08:22:05 brandt Exp $
 */
#ifndef _NETNATM_MSG_UNI_HDR_H_
#define _NETNATM_MSG_UNI_HDR_H_

#include <sys/types.h>
#ifdef _KERNEL
#include <sys/stdint.h>
#else
#include <stdint.h>
#endif

#include <netnatm/msg/uni_config.h>

enum {
	UNI_PROTO	= 0x09,		/* protocol discriminator */
	PNNI_PROTO	= 0xf0,		/* PNNI protocol discriminator */
};

/*
 * Message types
 */
enum uni_msgtype {
	UNI_UNKNOWN		= 0x100,/* unknown message */

	UNI_ALERTING		= 0x01,	/* alerting */
	UNI_CALL_PROC		= 0x02, /* call proceeding */
	UNI_SETUP		= 0x05,	/* setup */
	UNI_CONNECT		= 0x07,	/* connect */
	UNI_CONNECT_ACK		= 0x0f,	/* connect ack */

	UNI_RESTART		= 0x46,	/* restart */
	UNI_RELEASE		= 0x4d,	/* release */
	UNI_RESTART_ACK		= 0x4e,	/* restart acknowledgement */
	UNI_RELEASE_COMPL	= 0x5a,	/* release complete */

	UNI_NOTIFY		= 0x6e,	/* notify user */
	UNI_STATUS_ENQ		= 0x75,	/* status enquiry */
	UNI_STATUS		= 0x7d,	/* status */

	UNI_ADD_PARTY		= 0x80,	/* add party */
	UNI_ADD_PARTY_ACK	= 0x81,	/* add party acknowledgement */
	UNI_ADD_PARTY_REJ	= 0x82,	/* add party reject */
	UNI_DROP_PARTY		= 0x83,	/* drop party */
	UNI_DROP_PARTY_ACK	= 0x84,	/* drop party acknowledgement */
	UNI_PARTY_ALERTING	= 0x85,	/* party alerting */

	UNI_LEAF_SETUP_FAIL	= 0x90,	/* leaf setup failed */
	UNI_LEAF_SETUP_REQ	= 0x91,	/* leaf setup request */

	UNI_COBISETUP		= 0x15,	/* Q.2932 COBI-setup */
	UNI_FACILITY		= 0x62,	/* Q.2932 facility */

	UNI_MODIFY_REQ		= 0x88,	/* Q.2963 Modify request */
	UNI_MODIFY_ACK		= 0x89,	/* Q.2963 Modify acknowledgement */
	UNI_MODIFY_REJ		= 0x8a,	/* Q.2963 Modify reject */
	UNI_CONN_AVAIL		= 0x8b,	/* Q.2963 Connection available */
};

/*
 * Information element types
 */
enum uni_ietype {
	UNI_IE_CAUSE		= 0x08,	/* cause */
	UNI_IE_CALLSTATE	= 0x14,	/* call state */
	UNI_IE_FACILITY		= 0x1C,	/* Q.2932 facility IE */
	UNI_IE_NOTIFY		= 0x27,	/* UNI4.0 notify */
	UNI_IE_EETD		= 0x42,	/* UNI4.0 end-to-end transit delay */
	UNI_IE_CONNED		= 0x4c,	/* UNI4.0/Q.2951 connected address */
	UNI_IE_CONNEDSUB	= 0x4d,	/* UNI4.0/Q.2951 connected subaddress */
	UNI_IE_EPREF		= 0x54,	/* endpoint reference */
	UNI_IE_EPSTATE		= 0x55,	/* enpoint state */
	UNI_IE_AAL		= 0x58,	/* ATM adaptation layer parameters */
	UNI_IE_TRAFFIC		= 0x59,	/* ATM traffic descriptor */
	UNI_IE_CONNID		= 0x5a,	/* connection identifier */
	UNI_IE_QOS		= 0x5c,	/* quality of service parameter */
	UNI_IE_BHLI		= 0x5d,	/* broadband higher layer information */
	UNI_IE_BEARER		= 0x5e,	/* broadband bearer capability */
	UNI_IE_BLLI		= 0x5f,	/* broadband lower layer information */
	UNI_IE_LSHIFT		= 0x60,	/* broadband locking shift */
	UNI_IE_NLSHIFT		= 0x61,	/* broadband non-locking shift */
	UNI_IE_SCOMPL		= 0x62,	/* broadband sending complete */
	UNI_IE_REPEAT		= 0x63,	/* broadband repeat indicator */
	UNI_IE_CALLING		= 0x6c,	/* calling party number */
	UNI_IE_CALLINGSUB	= 0x6d,	/* calling party subaddress */
	UNI_IE_CALLED		= 0x70,	/* called party number */
	UNI_IE_CALLEDSUB	= 0x71,	/* called party subaddress */
	UNI_IE_TNS		= 0x78,	/* transit network selection */
	UNI_IE_RESTART		= 0x79,	/* restart indicator */
	UNI_IE_UU		= 0x7e,	/* UNI4.0/Q.2957 user-to-user info */
	UNI_IE_GIT		= 0x7f,	/* UNI4.0 generic identifier transport*/
	UNI_IE_MINTRAFFIC	= 0x81,	/* Q.2962 minimum traffic desc */
	UNI_IE_ATRAFFIC		= 0x82,	/* Q.2962 alternate traffic desc */
	UNI_IE_ABRSETUP		= 0x84,	/* UNI4.0 ABR setup parameters */
	UNI_IE_REPORT		= 0x89,	/* Q.2963 broadband report type */
	UNI_IE_CALLED_SOFT	= 0xe0,	/* PNNI Calling party soft PVPC */
	UNI_IE_CRANKBACK	= 0xe1,	/* PNNI Crankback */
	UNI_IE_DTL		= 0xe2,	/* PNNI designated transit list */
	UNI_IE_CALLING_SOFT	= 0xe3,	/* PNNI Called party soft PVPC */
	UNI_IE_ABRADD		= 0xe4,	/* UNI4.0 ABR additional parameters */
	UNI_IE_LIJ_CALLID	= 0xe8,	/* UNI4.0 LIF call identifier */
	UNI_IE_LIJ_PARAM	= 0xe9,	/* UNI4.0 LIF parameters */
	UNI_IE_LIJ_SEQNO	= 0xea,	/* UNI4.0 LIF sequence number */
	UNI_IE_CSCOPE		= 0xeb,	/* UNI4.0 connection scope selection */
	UNI_IE_EXQOS		= 0xec,	/* UNI4.0 extended QoS parameters */
	UNI_IE_MDCR		= 0xf0,	/* UNI4.0+ Minimum desired call rate */
	UNI_IE_UNREC		= 0xfe,
};

enum uni_coding {
	UNI_CODING_ITU = 0x0,
	UNI_CODING_NET = 0x3,
};

enum uni_msgact {
	UNI_MSGACT_CLEAR	= 0x0,
	UNI_MSGACT_IGNORE	= 0x1,
	UNI_MSGACT_REPORT	= 0x2,

	UNI_MSGACT_DEFAULT	= 0x4
};

enum uni_ieact {
	UNI_IEACT_CLEAR		= 0x00,	/* clear call */
	UNI_IEACT_IGNORE	= 0x01,	/* ignore IE and proceed */
	UNI_IEACT_REPORT	= 0x02,	/* ignore IE, report and proceed */
	UNI_IEACT_MSG_IGNORE	= 0x05,	/* ignore message */
	UNI_IEACT_MSG_REPORT	= 0x06,	/* ignore message and report */

	UNI_IEACT_DEFAULT	= 0x08
};

struct uni_cref {
	u_int	flag;
	u_int	cref;
};

/*
 * Message header.
 */
struct uni_msghdr {
	struct uni_cref	cref;
	enum uni_msgact	act;		/* action indicator */
	u_int		pass:1;		/* PNNI pass along request */
};

enum {
	CREF_GLOBAL	= 0,
	CREF_DUMMY	= 0x7fffff,
};

/*
 * General information element header.
 */
struct uni_iehdr {
	enum uni_coding	coding;		/* coding standard */
	enum uni_ieact	act;		/* action indicator */
	u_int		pass : 1;	/* PNNI pass along request */
	u_int		present;	/* which optional elements are present */
#define UNI_IE_EMPTY	0x80000000
#define UNI_IE_PRESENT	0x40000000
#define UNI_IE_ERROR	0x20000000
#define UNI_IE_XXX	0x10000000
#define UNI_IE_MASK	0xf0000000
};

#define IE_ISPRESENT(IE) \
	(((IE).h.present & (UNI_IE_PRESENT|UNI_IE_EMPTY)) == UNI_IE_PRESENT)
#define IE_SETPRESENT(IE) \
	((IE).h.present = ((IE).h.present & ~UNI_IE_MASK) | \
		UNI_IE_PRESENT)

#define IE_ADDPRESENT(IE) \
	((IE).h.present = ((IE).h.present & ~UNI_IE_EMPTY) | \
		UNI_IE_PRESENT)

#define IE_ISEMPTY(IE) \
	(((IE).h.present & UNI_IE_MASK) == (UNI_IE_PRESENT | UNI_IE_EMPTY))
#define IE_SETEMPTY(IE) \
	((IE).h.present = ((IE).h.present & ~UNI_IE_MASK) | \
		UNI_IE_EMPTY | UNI_IE_PRESENT)

#define IE_ISERROR(IE) \
	(((IE).h.present & UNI_IE_MASK) == (UNI_IE_PRESENT | UNI_IE_ERROR))
#define IE_SETERROR(IE) \
	((IE).h.present = ((IE).h.present & ~UNI_IE_MASK) | \
		UNI_IE_ERROR | UNI_IE_PRESENT)

#define IE_ISGOOD(IE) \
	(((IE).h.present & UNI_IE_MASK) == (UNI_IE_PRESENT))

#endif


code:
/* This file was created automatically
 * Source file: $Begemot: libunimsg/atm/msg/ie.def,v 1.3 2003/09/19 11:58:15 hbb Exp $
 * $FreeBSD: release/9.0.0/sys/contrib/ngatm/netnatm/msg/uni_ie.h 121936 2003-11-03 09:11:53Z harti $
 */

#ifndef _NETNATM_MSG_UNI_IE_H_
#define _NETNATM_MSG_UNI_IE_H_

union uni_ieall {
	struct uni_iehdr h;
	struct uni_ie_cause cause;
	struct uni_ie_callstate callstate;
	struct uni_ie_facility facility;
	struct uni_ie_notify notify;
	struct uni_ie_eetd eetd;
	struct uni_ie_conned conned;
	struct uni_ie_connedsub connedsub;
	struct uni_ie_epref epref;
	struct uni_ie_epstate epstate;
	struct uni_ie_aal aal;
	struct uni_ie_traffic traffic;
	struct uni_ie_connid connid;
	struct uni_ie_qos qos;
	struct uni_ie_bhli bhli;
	struct uni_ie_bearer bearer;
	struct uni_ie_blli blli;
	struct uni_ie_lshift lshift;
	struct uni_ie_nlshift nlshift;
	struct uni_ie_scompl scompl;
	struct uni_ie_repeat repeat;
	struct uni_ie_calling calling;
	struct uni_ie_callingsub callingsub;
	struct uni_ie_called called;
	struct uni_ie_calledsub calledsub;
	struct uni_ie_tns tns;
	struct uni_ie_restart restart;
	struct uni_ie_uu uu;
	struct uni_ie_git git;
	struct uni_ie_mintraffic mintraffic;
	struct uni_ie_atraffic atraffic;
	struct uni_ie_abrsetup abrsetup;
	struct uni_ie_report report;
	struct uni_ie_called_soft called_soft;
	struct uni_ie_crankback crankback;
	struct uni_ie_dtl dtl;
	struct uni_ie_calling_soft calling_soft;
	struct uni_ie_abradd abradd;
	struct uni_ie_lij_callid lij_callid;
	struct uni_ie_lij_param lij_param;
	struct uni_ie_lij_seqno lij_seqno;
	struct uni_ie_cscope cscope;
	struct uni_ie_exqos exqos;
	struct uni_ie_mdcr mdcr;
	struct uni_ie_unrec unrec;
};

#endif


code:
/* This file was created automatically
 * Source file: $Begemot: libunimsg/atm/msg/msg.def,v 1.3 2003/09/19 11:58:15 hbb Exp $
 * $FreeBSD: release/9.0.0/sys/contrib/ngatm/netnatm/msg/uni_msg.h 121936 2003-11-03 09:11:53Z harti $
 */

#ifndef _NETNATM_MSG_UNI_MSG_H_
#define _NETNATM_MSG_UNI_MSG_H_

struct uni_alerting {
	struct uni_msghdr	hdr;
	struct uni_ie_connid	connid;
	struct uni_ie_epref	epref;
	struct uni_ie_notify	notify;
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_uu	uu;
	struct uni_ie_report	report;
	struct uni_ie_unrec	unrec;
};

struct uni_call_proc {
	struct uni_msghdr	hdr;
	struct uni_ie_connid	connid;
	struct uni_ie_epref	epref;
	struct uni_ie_notify	notify;
	struct uni_ie_unrec	unrec;
};

struct uni_connect {
	struct uni_msghdr	hdr;
	struct uni_ie_aal	aal;
	struct uni_ie_blli	blli;
	struct uni_ie_connid	connid;
	struct uni_ie_epref	epref;
	struct uni_ie_notify	notify;
	struct uni_ie_conned	conned;
	struct uni_ie_connedsub	connedsub;
	struct uni_ie_eetd	eetd;
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_uu	uu;
	struct uni_ie_traffic	traffic;
	struct uni_ie_exqos	exqos;
	struct uni_ie_facility	facility;
	struct uni_ie_abrsetup	abrsetup;
	struct uni_ie_abradd	abradd;
	struct uni_ie_called_soft	called_soft;
	struct uni_ie_report	report;
	struct uni_ie_unrec	unrec;
};

struct uni_connect_ack {
	struct uni_msghdr	hdr;
	struct uni_ie_notify	notify;
	struct uni_ie_unrec	unrec;
};

struct uni_release {
	struct uni_msghdr	hdr;
	struct uni_ie_cause	cause[2];
	struct uni_ie_notify	notify;
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_uu	uu;
	struct uni_ie_facility	facility;
	struct uni_ie_crankback	crankback;
	struct uni_ie_unrec	unrec;
};

struct uni_release_compl {
	struct uni_msghdr	hdr;
	struct uni_ie_cause	cause[2];
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_uu	uu;
	struct uni_ie_crankback	crankback;
	struct uni_ie_unrec	unrec;
};

struct uni_setup {
	struct uni_msghdr	hdr;
	struct uni_ie_aal	aal;
	struct uni_ie_traffic	traffic;
	struct uni_ie_bearer	bearer;
	struct uni_ie_bhli	bhli;
	struct uni_ie_repeat	blli_repeat;
	struct uni_ie_blli	blli[UNI_NUM_IE_BLLI];
	struct uni_ie_called	called;
	struct uni_ie_calledsub	calledsub[UNI_NUM_IE_CALLEDSUB];
	struct uni_ie_calling	calling;
	struct uni_ie_callingsub	callingsub[UNI_NUM_IE_CALLINGSUB];
	struct uni_ie_connid	connid;
	struct uni_ie_qos	qos;
	struct uni_ie_eetd	eetd;
	struct uni_ie_notify	notify;
	struct uni_ie_scompl	scompl;
	struct uni_ie_tns	tns[UNI_NUM_IE_TNS];
	struct uni_ie_epref	epref;
	struct uni_ie_atraffic	atraffic;
	struct uni_ie_mintraffic	mintraffic;
	struct uni_ie_uu	uu;
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_lij_callid	lij_callid;
	struct uni_ie_lij_param	lij_param;
	struct uni_ie_lij_seqno	lij_seqno;
	struct uni_ie_exqos	exqos;
	struct uni_ie_abrsetup	abrsetup;
	struct uni_ie_abradd	abradd;
	struct uni_ie_cscope	cscope;
	struct uni_ie_calling_soft	calling_soft;
	struct uni_ie_called_soft	called_soft;
	struct uni_ie_repeat	dtl_repeat;
	struct uni_ie_dtl	dtl[UNI_NUM_IE_DTL];
	struct uni_ie_report	report;
	struct uni_ie_mdcr	mdcr;
	struct uni_ie_unrec	unrec;
};

struct uni_status {
	struct uni_msghdr	hdr;
	struct uni_ie_callstate	callstate;
	struct uni_ie_cause	cause;
	struct uni_ie_epref	epref;
	struct uni_ie_epstate	epstate;
	struct uni_ie_unrec	unrec;
};

struct uni_status_enq {
	struct uni_msghdr	hdr;
	struct uni_ie_epref	epref;
	struct uni_ie_unrec	unrec;
};

struct uni_notify {
	struct uni_msghdr	hdr;
	struct uni_ie_notify	notify;
	struct uni_ie_epref	epref;
	struct uni_ie_unrec	unrec;
};

struct uni_restart {
	struct uni_msghdr	hdr;
	struct uni_ie_connid	connid;
	struct uni_ie_restart	restart;
	struct uni_ie_unrec	unrec;
};

struct uni_restart_ack {
	struct uni_msghdr	hdr;
	struct uni_ie_connid	connid;
	struct uni_ie_restart	restart;
	struct uni_ie_unrec	unrec;
};

struct uni_add_party {
	struct uni_msghdr	hdr;
	struct uni_ie_aal	aal;
	struct uni_ie_bhli	bhli;
	struct uni_ie_blli	blli;
	struct uni_ie_called	called;
	struct uni_ie_calledsub	calledsub[UNI_NUM_IE_CALLEDSUB];
	struct uni_ie_calling	calling;
	struct uni_ie_callingsub	callingsub[UNI_NUM_IE_CALLINGSUB];
	struct uni_ie_scompl	scompl;
	struct uni_ie_tns	tns[UNI_NUM_IE_TNS];
	struct uni_ie_epref	epref;
	struct uni_ie_notify	notify;
	struct uni_ie_eetd	eetd;
	struct uni_ie_uu	uu;
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_lij_seqno	lij_seqno;
	struct uni_ie_calling_soft	calling_soft;
	struct uni_ie_called_soft	called_soft;
	struct uni_ie_repeat	dtl_repeat;
	struct uni_ie_dtl	dtl[UNI_NUM_IE_DTL];
	struct uni_ie_unrec	unrec;
};

struct uni_add_party_ack {
	struct uni_msghdr	hdr;
	struct uni_ie_epref	epref;
	struct uni_ie_aal	aal;
	struct uni_ie_blli	blli;
	struct uni_ie_notify	notify;
	struct uni_ie_eetd	eetd;
	struct uni_ie_conned	conned;
	struct uni_ie_connedsub	connedsub;
	struct uni_ie_uu	uu;
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_called_soft	called_soft;
	struct uni_ie_unrec	unrec;
};

struct uni_party_alerting {
	struct uni_msghdr	hdr;
	struct uni_ie_epref	epref;
	struct uni_ie_notify	notify;
	struct uni_ie_uu	uu;
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_unrec	unrec;
};

struct uni_add_party_rej {
	struct uni_msghdr	hdr;
	struct uni_ie_cause	cause;
	struct uni_ie_epref	epref;
	struct uni_ie_uu	uu;
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_crankback	crankback;
	struct uni_ie_unrec	unrec;
};

struct uni_drop_party {
	struct uni_msghdr	hdr;
	struct uni_ie_cause	cause;
	struct uni_ie_epref	epref;
	struct uni_ie_notify	notify;
	struct uni_ie_uu	uu;
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_unrec	unrec;
};

struct uni_drop_party_ack {
	struct uni_msghdr	hdr;
	struct uni_ie_epref	epref;
	struct uni_ie_cause	cause;
	struct uni_ie_uu	uu;
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_unrec	unrec;
};

struct uni_leaf_setup_req {
	struct uni_msghdr	hdr;
	struct uni_ie_tns	tns[UNI_NUM_IE_TNS];
	struct uni_ie_calling	calling;
	struct uni_ie_callingsub	callingsub[UNI_NUM_IE_CALLINGSUB];
	struct uni_ie_called	called;
	struct uni_ie_calledsub	calledsub[UNI_NUM_IE_CALLEDSUB];
	struct uni_ie_lij_callid	lij_callid;
	struct uni_ie_lij_seqno	lij_seqno;
	struct uni_ie_unrec	unrec;
};

struct uni_leaf_setup_fail {
	struct uni_msghdr	hdr;
	struct uni_ie_cause	cause;
	struct uni_ie_called	called;
	struct uni_ie_calledsub	calledsub;
	struct uni_ie_lij_seqno	lij_seqno;
	struct uni_ie_tns	tns[UNI_NUM_IE_TNS];
	struct uni_ie_unrec	unrec;
};

struct uni_cobisetup {
	struct uni_msghdr	hdr;
	struct uni_ie_facility	facility;
	struct uni_ie_called	called;
	struct uni_ie_calledsub	calledsub;
	struct uni_ie_calling	calling;
	struct uni_ie_notify	notify;
	struct uni_ie_unrec	unrec;
};

struct uni_facility {
	struct uni_msghdr	hdr;
	struct uni_ie_facility	facility;
	struct uni_ie_called	called;
	struct uni_ie_calledsub	calledsub;
	struct uni_ie_calling	calling;
	struct uni_ie_notify	notify;
	struct uni_ie_unrec	unrec;
};

struct uni_modify_req {
	struct uni_msghdr	hdr;
	struct uni_ie_traffic	traffic;
	struct uni_ie_atraffic	atraffic;
	struct uni_ie_mintraffic	mintraffic;
	struct uni_ie_notify	notify;
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_unrec	unrec;
};

struct uni_modify_ack {
	struct uni_msghdr	hdr;
	struct uni_ie_report	report;
	struct uni_ie_traffic	traffic;
	struct uni_ie_notify	notify;
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_unrec	unrec;
};

struct uni_modify_rej {
	struct uni_msghdr	hdr;
	struct uni_ie_cause	cause;
	struct uni_ie_notify	notify;
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_unrec	unrec;
};

struct uni_conn_avail {
	struct uni_msghdr	hdr;
	struct uni_ie_notify	notify;
	struct uni_ie_git	git[UNI_NUM_IE_GIT];
	struct uni_ie_report	report;
	struct uni_ie_unrec	unrec;
};

struct uni_unknown {
	struct uni_msghdr	hdr;
	struct uni_ie_epref	epref;
	struct uni_ie_unrec	unrec;
};

union uni_msgall {
	struct uni_msghdr	hdr;
	struct uni_alerting	alerting;
	struct uni_call_proc	call_proc;
	struct uni_connect	connect;
	struct uni_connect_ack	connect_ack;	/* !pnni */
	struct uni_release	release;
	struct uni_release_compl	release_compl;
	struct uni_setup	setup;
	struct uni_status	status;
	struct uni_status_enq	status_enq;
	struct uni_notify	notify;
	struct uni_restart	restart;
	struct uni_restart_ack	restart_ack;
	struct uni_add_party	add_party;
	struct uni_add_party_ack	add_party_ack;
	struct uni_party_alerting	party_alerting;
	struct uni_add_party_rej	add_party_rej;
	struct uni_drop_party	drop_party;
	struct uni_drop_party_ack	drop_party_ack;
	struct uni_leaf_setup_req	leaf_setup_req;	/* !pnni */
	struct uni_leaf_setup_fail	leaf_setup_fail;	/* !pnni */
	struct uni_cobisetup	cobisetup;	/* !pnni&&q2932 */
	struct uni_facility	facility;	/* !pnni&&q2932 */
	struct uni_modify_req	modify_req;	/* !pnni */
	struct uni_modify_ack	modify_ack;	/* !pnni */
	struct uni_modify_rej	modify_rej;	/* !pnni */
	struct uni_conn_avail	conn_avail;	/* !pnni */
	struct uni_unknown	unknown;
};

#endif


code:
/*
 * Copyright (c) 1996-2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 * 	All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Author: Hartmut Brandt <harti@freebsd.org>
 *
 * $Begemot: libunimsg/netnatm/msg/unimsglib.h,v 1.6 2004/07/08 08:22:07 brandt Exp $
 */
#ifndef _NETNATM_MSG_UNIMSGLIB_H_
#define _NETNATM_MSG_UNIMSGLIB_H_

#include <netnatm/msg/uni_config.h>

struct uni_msg;

enum uni_ierr_type {
	UNI_IERR_UNK,	/* unknown IE */
	UNI_IERR_LEN,	/* length error */
	UNI_IERR_BAD,	/* content error */
	UNI_IERR_ACC,	/* access element content error */
	UNI_IERR_MIS,	/* mandatory IE missing (not used here) */
};

struct uni_ierr {
	enum uni_ierr_type	err;	/* what error */
	enum uni_ieact		act;	/* the action indicator */
	u_int			ie:8;	/* the ie type */
	u_int			man:1;	/* mandatory flag */
	u_int			epref:1;/* Q.2971 9.5.3.2.1 low-pri epref */
};

/*
 * Context buffer. Needed to reduce number of arguments to routines.
 */
struct unicx {
	/*
	 * globals for error handling
	 */
	u_int		errcnt;		/* number of bad IEs */
	struct uni_ierr	err[UNI_MAX_ERRIE]; /* the errors */

	int		q2932;		/* Enable GFP */
	int		pnni;		/* Enable PNNI */

	int		git_hard;	/* do hard check on GIT IE */
	int		bearer_hard;	/* do hard check on BEARER IE */
	int		cause_hard;	/* do hard check on cause */

	int		multiline;	/* printing mode */
	u_int		tabsiz;		/* tabulation size */

	/*
	 * Internal context of library -- don't touch
	 */
	struct uni_ie_repeat	repeat;	/* repeat IE during decoding */
	enum uni_ietype		ielast;	/* last IE seen for repeat handling */

	const char 		*prefix[20];
	u_int			nprefix;
	int			doindent;
	char			*buf;
	size_t			bufsiz;
	u_int			indent;		/* indentation */
	int			dont_init;
};

/*
 * Functions for all messages
 */
void uni_print_cref(char *, size_t, const struct uni_cref *, struct unicx *);
void uni_print_msghdr(char *, size_t, const struct uni_msghdr *, struct unicx *);
void uni_print(char *, size_t, const struct uni_all *, struct unicx *);
void uni_print_msg(char *, size_t, u_int _mtype, const union uni_msgall *,
    struct unicx *);
int uni_encode(struct uni_msg *, struct uni_all *, struct unicx *);
int uni_decode(struct uni_msg *, struct uni_all *, struct unicx *);

int uni_decode_head(struct uni_msg *, struct uni_all *, struct unicx *);
int uni_decode_body(struct uni_msg *, struct uni_all *, struct unicx *);

int uni_encode_msg_hdr(struct uni_msg *, struct uni_msghdr *, enum uni_msgtype,
    struct unicx *, int *);

/*
 * Functions for all information elements
 */
void uni_print_ie(char *, size_t, enum uni_ietype, const union uni_ieall *,
    struct unicx *);
int uni_check_ie(enum uni_ietype, union uni_ieall *, struct unicx *);
int uni_encode_ie(enum uni_ietype, struct uni_msg *, union uni_ieall *,
    struct unicx *);
int uni_decode_ie_hdr(enum uni_ietype *, struct uni_iehdr *, struct uni_msg *,
    struct unicx *, u_int *);
int uni_encode_ie_hdr(struct uni_msg *, enum uni_ietype, struct uni_iehdr *,
    u_int, struct unicx *);
int uni_decode_ie_body(enum uni_ietype, union uni_ieall *, struct uni_msg *,
    u_int, struct unicx *);

/*
 * Context handling
 */
void uni_initcx(struct unicx *);
void uni_print_cx(char *, size_t, struct unicx *);

#define	UNI_SAVE_IERR(CX, IETYPE, ACT, ERRCODE)				\
	(((CX)->errcnt < UNI_MAX_ERRIE) ?				\
	 ((CX)->err[(CX)->errcnt].ie = (IETYPE),			\
	  (CX)->err[(CX)->errcnt].act = (ACT),				\
	  (CX)->err[(CX)->errcnt].err = (ERRCODE),			\
	  (CX)->err[(CX)->errcnt].man = 0,				\
	  (CX)->errcnt++,						\
	  1) : 0)

/*
 * Traffic classification
 */
enum uni_traffic_class {
	UNI_TRAFFIC_CBR1,
	UNI_TRAFFIC_CBR2,
	UNI_TRAFFIC_CBR3,
	UNI_TRAFFIC_rtVBR1,
	UNI_TRAFFIC_rtVBR2,
	UNI_TRAFFIC_rtVBR3,
	UNI_TRAFFIC_rtVBR4,
	UNI_TRAFFIC_rtVBR5,
	UNI_TRAFFIC_rtVBR6,
	UNI_TRAFFIC_nrtVBR1,
	UNI_TRAFFIC_nrtVBR2,
	UNI_TRAFFIC_nrtVBR3,
	UNI_TRAFFIC_nrtVBR4,
	UNI_TRAFFIC_nrtVBR5,
	UNI_TRAFFIC_nrtVBR6,
	UNI_TRAFFIC_ABR,
	UNI_TRAFFIC_UBR1,
	UNI_TRAFFIC_UBR2,
};

/* classify traffic */
int uni_classify_traffic(const struct uni_ie_bearer *,
    const struct uni_ie_traffic *,
    enum uni_traffic_class *, enum uni_traffic_class *,
    char *, size_t);

#endif


code:
/*
 * Copyright (c) 2001-2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 * 	All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Author: Hartmut Brandt <harti@freebsd.org>
 *
 * $Begemot: libunimsg/netnatm/msg/uniprint.h,v 1.4 2004/07/08 08:22:08 brandt Exp $
 *
 * Print utility functions. These are only needed if you want to hook to
 * the format of the uni printing routines.
 */
#ifndef _NETNATM_MSG_UNIPRINT_H_
#define _NETNATM_MSG_UNIPRINT_H_

#include <netnatm/msg/uni_config.h>

/*
 * This structure is used to define value->string mappings.
 * It must be terminated by a { NULL, 0 } entry.
 */
struct uni_print_tbl {
	const char *name;
	u_int val;
};
void uni_print_tbl(const char *_entry, u_int _val,
    const struct uni_print_tbl *_tbl, struct unicx *_cx);

/* initialize printing. This must be called at the start from each external
 * callable printing function. */
void uni_print_init(char *_buf, size_t _bufsiz, struct unicx *_cx);

/* End the current (semantical) line. This takes care of indendation and
 * actually print the newline in the appropriate modes. */
void uni_print_eol(struct unicx *_cx);

/* Push or pop a prefix. This takes care of indendation. */
void uni_print_push_prefix(const char *_prefix, struct unicx *_cx);
void uni_print_pop_prefix(struct unicx *_cx);

/* Print a flag taking care of the right prefixing */
void uni_print_flag(const char *_flag, struct unicx *_cx);

/* Print an entry taking care of the right prefixing */
void uni_print_entry(struct unicx *_cx, const char *_entry,
    const char *_fmt, ...) __printflike(3, 4);

/* Generic printf */
void uni_printf(struct unicx *_cx, const char *_fmt, ...) __printflike(2, 3);

#endif