⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtp_npi.c

📁 OpenSS7 This the fourth public release of the OpenSS7 Master Package. See README in the release for
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** @(#) mtp_npi.c,v openss7-0_9_2_E(0.9.2.19) 2007/02/26 07:25:40 ----------------------------------------------------------------------------- Copyright (c) 2001-2006  OpenSS7 Corporation <http://www.openss7.com/> Copyright (c) 1997-2000  Brian F. G. Bidulock <bidulock@openss7.org> All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ----------------------------------------------------------------------------- U.S. GOVERNMENT RESTRICTED RIGHTS.  If you are licensing this Software on behalf of the U.S. Government ("Government"), the following provisions apply to you.  If the Software is supplied by the Department of Defense ("DoD"), it is classified as "Commercial Computer Software" under paragraph 252.227-7014 of the DoD Supplement to the Federal Acquisition Regulations ("DFARS") (or any successor regulations) and the Government is acquiring only the license rights granted herein (the license rights customarily provided to non-Government users).  If the Software is supplied to any unit or agency of the Government other than DoD, it is classified as "Restricted Computer Software" and the Government's rights in the Software are defined in paragraph 52.227-19 of the Federal Acquisition Regulations ("FAR") (or any successor regulations) or, in the cases of NASA, in paragraph 18.52.227-86 of the NASA Supplement to the FAR (or any successor regulations). ----------------------------------------------------------------------------- Commercial licensing and support of this software is available from OpenSS7 Corporation at a fee.  See http://www.openss7.com/ ----------------------------------------------------------------------------- Last Modified 2007/02/26 07:25:40 by brian ----------------------------------------------------------------------------- mtp_npi.c,v Revision 0.9.2.19  2007/02/26 07:25:40  brian - synchronizing changes Revision 0.9.2.18  2007/02/17 02:49:17  brian - first clean recompile of MTP modules on LFS Revision 0.9.2.17  2007/02/14 14:09:11  brian - broad changes updating support for SS7 MTP and M3UA Revision 0.9.2.16  2007/02/13 07:55:43  brian - working up MTP and UAs Revision 0.9.2.15  2006/05/08 11:01:00  brian - new compilers mishandle postincrement of cast pointers Revision 0.9.2.14  2006/03/07 01:10:46  brian - binary compatible callouts Revision 0.9.2.13  2006/03/04 13:00:15  brian - FC4 x86_64 gcc 4.0.4 2.6.15 changes *****************************************************************************/#ident "@(#) mtp_npi.c,v openss7-0_9_2_E(0.9.2.19) 2007/02/26 07:25:40"static char const ident[] =    "mtp_npi.c,v openss7-0_9_2_E(0.9.2.19) 2007/02/26 07:25:40";/* *  This is a MTP NPI module which can be pushed over an MTPI (Message Transfer Part Interface) *  stream to effect an NPI interface to the MTP.  This module is intended to be used by application *  programs or by upper modules that expect an NPI connectionless service provider. */#define _LFS_SOURCE	1#define _SVR4_SOURCE	1#define _MPS_SOURCE	1#define _SUN_SOURCE	1#include <sys/os7/compat.h>#include <sys/strsun.h>#undef DB_TYPE#define DB_TYPE(mp) mp->b_datap->db_type#include <linux/socket.h>#include <ss7/lmi.h>#include <ss7/lmi_ioctl.h>#include <ss7/mtpi.h>#include <ss7/mtpi_ioctl.h>#include <sys/npi.h>#include <sys/npi_ss7.h>#include <sys/npi_mtp.h>#include <sys/xti.h>#include <sys/xti_ss7.h>#include <sys/xti_mtp.h>#define MTP_NPI_DESCRIP		"SS7 Message Transfer Part (MTP) NPI STREAMS MODULE."#define MTP_NPI_REVISION	"LfS mtp_npi.c,v openss7-0_9_2_E(0.9.2.19) 2007/02/26 07:25:40"#define MTP_NPI_COPYRIGHT	"Copyright (c) 1997-2007 OpenSS7 Corporation.  All Rights Reserved."#define MTP_NPI_DEVICE		"Part of the OpenSS7 Stack for Linux Fast-STREAMS."#define MTP_NPI_CONTACT		"Brian Bidulock <bidulock@openss7.org>"#define MTP_NPI_LICENSE		"GPL"#define MTP_NPI_BANNER		MTP_NPI_DESCRIP		"\n" \				MTP_NPI_REVISION	"\n" \				MTP_NPI_COPYRIGHT	"\n" \				MTP_NPI_DEVICE		"\n" \				MTP_NPI_CONTACT		"\n"#define MTP_NPI_SPLASH		MTP_NPI_DESCRIP		"\n" \				MTP_NPI_REVISION	"\n"#ifdef LINUXMODULE_AUTHOR(MTP_NPI_CONTACT);MODULE_DESCRIPTION(MTP_NPI_DESCRIP);MODULE_SUPPORTED_DEVICE(MTP_NPI_DEVICE);#ifdef MODULE_LICENSEMODULE_LICENSE(MTP_NPI_LICENSE);#endif				/* MODULE_LICENSE */#if defined MODULE_ALIASMODULE_ALIAS("streams-mtp_npi");#endif#endif				/* LINUX */#ifdef LFS#define MTP_NPI_MOD_ID		CONFIG_STREAMS_MTP_NPI_MODID#define MTP_NPI_MOD_NAME	CONFIG_STREAMS_MTP_NPI_NAME#endif#define MOD_ID		MTP_NPI_MOD_ID#define MOD_NAME	MTP_NPI_MOD_NAME#ifdef MODULE#define MOD_BANNER	MTP_NPI_BANNER#else				/* MODULE */#define MOD_BANNER	MTP_NPI_SPLASH#endif				/* MODULE *//* *  ========================================================================= * *  MTP-NPI Private Structure * *  ========================================================================= */typedef struct mtp {	queue_t *rq;			/* RD queue */	queue_t *wq;			/* WR queue */	cred_t cred;	struct mtp_addr src;		/* srce address */	struct mtp_addr dst;		/* dest address */	size_t src_len;	size_t dst_len;	uint coninds;	struct {		mtp_ulong pvar;		mtp_ulong popt;		mtp_ulong sls;		/* default options */		mtp_ulong mp;		/* default options */		mtp_ulong debug;	/* default options */		mtp_ulong sls_mask;	} options;	N_info_ack_t prot;} mtp_t;#define MTP_PRIV(__q) ((struct mtp *)(__q)->q_ptr)static caddr_t mtp_opens = NULL;#define STRLOGST	1	/* log Stream state transitions */#define STRLOGTO	2	/* log Stream timeouts */#define STRLOGRX	3	/* log Stream primitives received */#define STRLOGTX	4	/* log Stream primitives issued */#define STRLOGTE	5	/* log Stream timer events */#define STRLOGDA	6	/* log Stream data *//* *  ========================================================================= * *  ADDRESS Handling * *  ========================================================================= */static inline fastcall size_tn_addr_size(struct mtp_addr *add){	if (add)		return sizeof(*add);	return (0);}static inline fastcall voidn_build_addr(struct mtp_addr *add, unsigned char *p){	if (add)		bcopy(add, p, sizeof(*add));}/* *  ========================================================================= * *  QOS Parameters * *  ========================================================================= */typedef struct mtp_opts {	uint flags;			/* success flags */	mtp_ulong *sls;	mtp_ulong *mp;	mtp_ulong *debug;} mtp_opts_t;struct {	mtp_ulong sls;	mtp_ulong mp;	mtp_ulong debug;} opt_defaults = {0, 0, 0};static intn_parse_opts(struct mtp *mtp, struct mtp_opts *ops, unsigned char *op, size_t len){	fixme(("Write this function\n"));	return (-EFAULT);}static inline fastcall size_tn_opts_size(union N_qos_mtp *qos){	if (qos) {		switch(qos->n_qos_type) {		case N_QOS_SEL_DATA_MTP:			return (sizeof(qos->n_qos_data));		case N_QOS_SEL_CONN_MTP:			return (sizeof(qos->n_qos_conn));		case N_QOS_SEL_INFO_MTP:			return (sizeof(qos->n_qos_info));		case N_QOS_RANGE_INFO_MTP:			return (sizeof(qos->n_qos_range));		default:			return (0);		}	}	return (0);}static inline fastcall voidn_build_opts(union N_qos_mtp *qos, unsigned char *p){	if (qos) {		switch (qos->n_qos_type) {		case N_QOS_SEL_DATA_MTP:			return bcopy(qos, p, sizeof(qos->n_qos_data));		case N_QOS_SEL_CONN_MTP:			return bcopy(qos, p, sizeof(qos->n_qos_conn));		case N_QOS_SEL_INFO_MTP:			return bcopy(qos, p, sizeof(qos->n_qos_info));		case N_QOS_RANGE_INFO_MTP:			return bcopy(qos, p, sizeof(qos->n_qos_range));		default:			return;		}	}}/* *  ========================================================================= * *  STATE Functions * *  ========================================================================= */static const char *mtp_state(mtp_ulong state){	switch (state) {	case NS_UNBND:		return ("NS_UNBND");	case NS_WACK_BREQ:		return ("NS_WACK_BREQ");	case NS_WACK_UREQ:		return ("NS_WACK_UREQ");	case NS_IDLE:		return ("NS_IDLE");	case NS_WACK_OPTREQ:		return ("NS_WACK_OPTREQ");	case NS_WACK_RRES:		return ("NS_WACK_RRES");	case NS_WCON_CREQ:		return ("NS_WCON_CREQ");	case NS_WRES_CIND:		return ("NS_WRES_CIND");	case NS_WACK_CRES:		return ("NS_WACK_CRES");	case NS_DATA_XFER:		return ("NS_DATA_XFER");	case NS_WCON_RREQ:		return ("NS_WCON_RREQ");	case NS_WRES_RIND:		return ("NS_WRES_RIND");	case NS_WACK_DREQ6:		return ("NS_WACK_DREQ6");	case NS_WACK_DREQ7:		return ("NS_WACK_DREQ7");	case NS_WACK_DREQ9:		return ("NS_WACK_DREQ9");	case NS_WACK_DREQ10:		return ("NS_WACK_DREQ10");	case NS_WACK_DREQ11:		return ("NS_WACK_DREQ11");	case NS_NOSTATES:		return ("NS_NOSTATES");	default:		return ("????");	}}static mtp_ulongmtp_set_state(struct mtp *mtp, mtp_ulong newstate){	mtp_ulong oldstate = mtp->prot.CURRENT_state;	if (newstate != oldstate) {		mi_strlog(mtp->rq, STRLOGST, SL_TRACE, "%s <- %s", mtp_state(newstate),			  mtp_state(oldstate));		mtp->prot.CURRENT_state = newstate;	}	return (oldstate);}static mtp_ulongmtp_get_state(struct mtp *mtp){	return mtp->prot.CURRENT_state;}static mtp_ulongmtp_get_statef(struct mtp *mtp){	return (1 << mtp_get_state(mtp));}static mtp_ulongmtp_chk_state(struct mtp *mtp, mtp_ulong mask){	return (mtp_get_statef(mtp) & mask);}static mtp_ulongmtp_not_state(struct mtp *mtp, mtp_ulong mask){	return (mtp_chk_state(mtp, ~mask));}#ifndef NS_NOSTATES#define NS_NOSTATES (NS_WACK_DREQ11 + 1)#endif/* *  TLI interface state flags */#if 0#define NSF_UNBND	( 1 << NS_UNBND		)#define NSF_WACK_BREQ	( 1 << NS_WACK_BREQ	)#define NSF_WACK_UREQ	( 1 << NS_WACK_UREQ	)#define NSF_IDLE	( 1 << NS_IDLE		)#define NSF_WACK_OPTREQ	( 1 << NS_WACK_OPTREQ	)#define NSF_WACK_RRES	( 1 << NS_WACK_RRES	)#define NSF_WCON_CREQ	( 1 << NS_WCON_CREQ	)#define NSF_WRES_CIND	( 1 << NS_WRES_CIND	)#define NSF_WACK_CRES	( 1 << NS_WACK_CRES	)#define NSF_DATA_XFER	( 1 << NS_DATA_XFER	)#define NSF_WCON_RREQ	( 1 << NS_WCON_RREQ	)#define NSF_WRES_RIND	( 1 << NS_WRES_RIND	)#define NSF_WACK_DREQ6	( 1 << NS_WACK_DREQ6	)#define NSF_WACK_DREQ7	( 1 << NS_WACK_DREQ7	)#define NSF_WACK_DREQ9	( 1 << NS_WACK_DREQ9	)#define NSF_WACK_DREQ10	( 1 << NS_WACK_DREQ10	)#define NSF_WACK_DREQ11	( 1 << NS_WACK_DREQ11	)#endif#define NSF_NOSTATES	( 1 << NS_NOSTATES	)#define NSF_WACK_DREQ	(NSF_WACK_DREQ6 \			|NSF_WACK_DREQ7 \			|NSF_WACK_DREQ9 \			|NSF_WACK_DREQ10 \			|NSF_WACK_DREQ11)#define NSF_WACK	(NSF_WACK_BREQ \			|NSF_WACK_UREQ \			|NSF_WACK_OPTREQ \			|NSF_WACK_RRES \			|NSF_WACK_CRES \			|NSF_WACK_DREQ6 \			|NSF_WACK_DREQ7 \			|NSF_WACK_DREQ9 \			|NSF_WACK_DREQ10 \			|NSF_WACK_DREQ11)static voidmtp_bind(struct mtp *mtp, struct mtp_addr *src){	if (src) {		mtp->src = *src;		mtp->src_len = sizeof(*src);	}	return;}static inline voidmtp_connect(struct mtp *mtp, struct mtp_addr *dst){	if (dst) {		mtp->dst = *dst;		mtp->dst_len = sizeof(*dst);	}	return;}static voidmtp_unbind(struct mtp *mtp){	mtp->src_len = 0;	return;}static voidmtp_disconnect(struct mtp *mtp){	mtp->dst_len = 0;	return;}/* *  ========================================================================= * *  PRIMITIVES * *  ========================================================================= *//* *  Primitives sent upstream *  ------------------------------------------------------------------------- *//** * m_error: - issue an M_ERROR message upstream * @mtp: private structure * @q: active queue * @msg: message to free upon success * @err: error value */static intm_error(struct mtp *mtp, queue_t *q, mblk_t *msg, int err){	mblk_t *mp;	if ((mp = mi_allocb(q, 2, BPRI_MED))) {		DB_TYPE(mp) = M_ERROR;		*mp->b_wptr++ = err < 0 ? -err : err;		*mp->b_wptr++ = err < 0 ? -err : err;		mtp_set_state(mtp, NS_NOSTATES);		freemsg(msg);		mi_strlog(q, STRLOGRX, SL_TRACE, "<- M_ERROR");		putnext(mtp->rq, mp);		return (0);	}	return (-ENOBUFS);}/** * t_conn_ind: - issue a T_CONN_IND primitive upstream * @mtp: private structure * @q: active queue * @bp: message block to free upon success * @src: souce address * @opt: options * @dp: user data */static inline fastcall __unlikely intn_conn_ind(struct mtp *mtp, queue_t *q, mblk_t *bp,	   np_ulong seq, np_ulong flags, struct mtp_addr *src, struct mtp_addr *dst,	   union N_qos_mtp *qos, mblk_t *dp){	N_conn_ind_t *p;	mblk_t *mp;	const size_t src_len = n_addr_size(src);	const size_t dst_len = n_addr_size(dst);	const size_t qos_len = n_opts_size(qos);	const size_t msg_len = sizeof(*p) + src_len + dst_len + qos_len;	if (likely((mp = mi_allocb(q, msg_len, BPRI_MED)) != NULL)) {		if (likely(canputnext(mtp->rq))) {			DB_TYPE(mp) = M_PROTO;			p = (typeof(p)) mp->b_wptr;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -