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

📄 m2pa_sdt.c

📁 No7信令,我需要交换类似的代码, 请店长审核,谢谢了,急着交换,谢谢
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** @(#) m2pa_sdt.c,v 0.7.8.1 2001/12/11 13:15:14 brian Exp ----------------------------------------------------------------------------- Copyright (C) 2001  OpenSS7 Corporation <http://www.openss7.com> 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; either version 2 of the License, or (at your option) any later version. 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. ----------------------------------------------------------------------------- Last Modified 2001/12/11 13:15:14 by brian *****************************************************************************/#ident "@(#) m2pa_sdt.c,v 0.7.8.1 2001/12/11 13:15:14 brian Exp"static char const ident[] = "SS7AlphaRelease(0.7.8.1) 2001/12/11 13:15:14";#define M2PA_DESCRIP	"M2PA/SCTP SIGNALLING DATA TERMINAL (SDT) STREAMS MODULE"#define M2PA_COPYRIGHT	"Copyright (c) 2001 OpenSS7 Corp.  All Rights Reserved."#define M2PA_DEVICE	"Part of the OpenSS7 Stack for LiS STREAMS."#define M2PA_CONTACT	"Brian Bidulock <bidulock@openss7.org>"#define M2PA_BANNER	M2PA_DESCRIP	"\n" \			M2PA_COPYRIGHT	"\n" \			M2PA_DEVICE	"\n" \			M2PA_CONTACT	"\n"MODULE_AUTHOR(M2PA_CONTACT);MODULE_DESCRIPTION(M2PA_DESCRIP);MODULE_SUPPORTED_DEVICE(M2PA_DEVICE);#ifndef INT#define INT void#endiftypedef void (*bufcall_fnc_t)(long);/* *  ========================================================================= * *  STREAMS Definitions * *  ========================================================================= */static struct module_info m2pa_info ={	0,		/* Module ID number		*/	"m2pa-sdt",	/* Module name			*/	0,		/* Min packet size accepted	*/  /* FIXME */	INFPSZ,		/* Max packet size accepted	*/  /* FIXME */	1<<15,		/* Hi water mark		*/  /* FIXME */	1<<10		/* Lo water mark		*/  /* FIXME */};static int m2pa_open (queue_t *, dev_t *, int, int, cred_t *);static int m2pa_close(queue_t *, int, cred_t *);static INT m2pa_rput (queue_t *, mblk_t *);static INT m2pa_rsrv (queue_t *);static struct qinit m2pa_rinit ={	m2pa_rput,	/* Read put (msg from below)	*/	m2pa_rsrv,	/* Read queue service		*/	m2pa_open,	/* Each open			*/	m2pa_close,	/* Last close			*/	NULL,		/* Admin (not used)		*/	&m2pa_info,	/* Information			*/	NULL		/* Statistics			*/};static INT m2pa_wput (queue_t *, mblk_t *);static INT m2pa_wsrv (queue_t *);static struct qinit m2pa_winit ={	m2pa_wput,	/* Write put (msg from above)	*/	m2pa_wsrv,	/* Write queue service		*/	NULL,		/* Each open			*/	NULL,		/* Last close			*/	NULL,		/* Admin (not used)		*/	&m2pa_info,	/* Information			*/	NULL		/* Statistics			*/};static INT t_rput (queue_t *, mblk_t *);static INT t_rsrv (queue_t *);static struct streamtab m2pa_info ={	&m2pa_rinit,	/* Upper read  queue		*/	&m2pa_winit,	/* Upper write queue		*/	&t_rinit,	/* Lower read  queue		*/	&t_winit	/* Lower write queue		*/};/* *  ========================================================================= * *  M2PA Private Structure * *  ========================================================================= */typedef struct m2pa {	struct m2pa	*next;	queue_t		*rq;	queue_t		*wq;	uint		state;		/* SDT interface state		*/	uint		version;	/* version execting		*/	uint		flags;		/* interface flags		*/	ulong		token;		/* my bind token		*/	lmi_option_t	options;	/* protocol and variant options	*/	sdt_config_t	sdt_conf;	/* SDT configuration options	*/	sdl_config_t	sdl_conf;	/* SDL configuration options	*/	dev_config_t	dev_conf;	/* DEV configuration options	*/} m2pa_t;#define M2PA_VERSION_DRAFT3	3#define M2PA_VERSION_DRAFT4	4#define M2PA_VERSION_DEFAULT	M2PA_VERSION_DRAFT4/* *  ========================================================================= * *  SDT Provider (M2PA) -> DTL User Primitives * *  ========================================================================= *//* *  LMI_INFO_ACK *  --------------------------------------------- */static intlmi_info_ack(m2pa_t *m2){	mblk_t *mp;	lmi_info_ack_t *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) {		mp->b_datap->db_type = M_PCPROTO;		p = ((lmi_info_ack_t *)mp->b_wptr)++;		p->lmi_primitive	= LMI_INFO_ACK;		p->lmi_version		= 1;		p->lmi_state		= m2->state;		p->lmi_max_sdu		= -1;		p->lmi_min_sdu		= 0;		p->lmi_header_len	= 0;		p->lmi_ppa_style	= LMI_STYLE1;		putnext(m2->rq, mp);		return(0);	} rare();   return(-ENOBUFS);}/* *  LMI_OK_ACK *  --------------------------------------------- */static intlmi_ok_ack(m2pa_t *m2, long prim){	mblk_t *mp;	lmi_ok_ack_t *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) {		mp->b_datap->db_type = M_PCPROTO;		p = ((lmi_ok_ack_t *)mp->b_wptr)++;		p->lmi_primitive	= LMI_OK_ACK;		p->lmi_correct_primitive= prim;		switch ( m2->state )		{			case LMI_ATTACH_PENDING: m2->state = LMI_DISABLED;  break;			case LMI_DETACH_PENDING: m2->state = LMI_UNATTACHED; break;			/* default is don't change state */		}		p->lmi_state		= m2->state;		putnext(m2->rq, mp);		return(0);	} rare();   return(-ENOBUFS);}/* *  LMI_ERROR_ACK *  --------------------------------------------- */static intlmi_error_ack(m2pa_t *m2, long prim, long err){	mblk_t *mp;	lmi_error_ack_t *p;	switch ( err )	{		case -EBUSY:		case -EAGAIN:		case -ENOMEM:		case -ENOBUFS:			seldom(); return(err);	}	if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) {		mp->b_datap->db_type = M_PCPROTO;		p = ((lmi_error_ack_t *)mp->b_wptr)++;		p->lmi_primitive	= LMI_ERROR_ACK;		p->lmi_errno		= err<0 ? -err       : 0;		p->lmi_reason		= err<0 ? LMI_SYSERR : err;		p->lmi_error_primitive	= prim;		switch ( m2->state )		{			case LMI_ATTACH_PENDING:    m2->state = LMI_UNATTACHED;   break;			case LMI_DETACH_PENDING:    m2->state = LMI_DISABLED;	    break;			case LMI_ENABLE_PENDING:    m2->state = LMI_DISABLED;	    break;			case LMI_DISABLE_PENDING:   m2->state = LMI_ENABLED;	    break;			/*			 *  Default is not to change state.			 */		}		p->lmi_state		= m2->state;		putnext(m2->rq, mp);		return(0);	} rare();   return(-ENOBUFS);}/* *  LMI_ENABLE_CON *  --------------------------------------------- */static intlmi_enable_con(m2pa_t *m2){	mblk_t *mp;	lmi_enable_con_t *p;	ensure( m2->state == LMI_ENABLE_PENDING, return(-EFAULT) );	if ( canputnext(m2->rq) ) {	if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) {		mp->b_datap->db_type = M_PROTO;		p = ((lmi_enable_con_t *)mp->b_wptr)++;		p->lmi_primitive	= LMI_ENABLE_CON;		p->lmi_state		= m2->state = LMI_ENABLED;		putnext(m2->rq, mp);		return(0);	} rare();   return(-ENOBUFS);	} rare();   return(-EBUSY);}/* *  LMI_DISABLE_CON *  --------------------------------------------- */static intlmi_disable_con(m2pa_t *m2){	mblk_t *mp;	lmi_disable_con_t *p;	ensure( m2->state == LMI_DISABLE_PENDING, return(-EFAULT) );	if ( canputnext(m2->rq) ) {	if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) {		mp->b_datap->db_type = M_PROTO;		p = ((lmi_disable_con_t *)mp->b_wptr)++;		p->lmi_primitive	= LMI_DISABLE_CON;		p->lmi_state		= m2->state = LMI_DISABLED;		putnext(m2->rq, mp);		return(0);	} rare();   return(-ENOBUFS);	} rare();   return(-EBUSY);}#if 0/* *  LMI_OPTMGMT_ACK *  --------------------------------------------- */static intlmi_optmgmt_ack(m2pa_t *m2, ulong flags, void *opt_ptr, size_t opt_len){	mblk_t *mp;	lmi_optmgmt_ack_t *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) {		mp->b_datap->db_type = M_PCPROTO;		p = ((lmi_optmgmt_ack_t *)mp->b_wptr)++;		p->lmi_primitive	= LMI_OPTMGMT_ACK;		p->lmi_opt_length	= opt_len;		p->lmi_opt_offset	= opt_len?sizeof(*p):0;		p->lmi_mgmt_flags	= flags;		bcopy(opt_ptr, mp->b_wptr, opt_len);		mp->b_wptr += opt_len;		putnext(m2->rq, mp);		return(0);	} rare();   return(-ENOBUFS);}#endif/* *  LMI_ERROR_IND *  --------------------------------------------- */static intlmi_error_ind(m2pa_t *m2, long err){	mblk_t *mp;	lmi_error_ind_t *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) {		mp->b_datap->db_type = M_PCPROTO;		p = ((lmi_error_ind_t *)mp->b_wptr)++;		p->lmi_primitive	= LMI_ERROR_IND;		p->lmi_errno		= err<0 ? -err       : 0;		p->lmi_reason		= err<0 ? LMI_SYSERR : err;		p->lmi_state		= m2->state;		putnext(m2->rq, mp);		return(0);	} rare();   return(-ENOBUFS);}/* *  LMI_STATS_IND *  --------------------------------------------- */static intlmi_stats_ind(m2pa_t *m2, ulong interval, ulong timestamp){	mblk_t *mp;	lmi_stats_ind_t *p;	if ( bcanputnext(m2->rq, mp->b_band) ) {	if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) {		mp->b_datap->db_type = M_PROTO;		p = ((lmi_stats_ind_t *)mp->b_wptr)++;		p->lmi_primitive	= LMI_STATS_IND;		p->lmi_interval		= interval;		p->lmi_timestamp	= timestamp;		putnext(m2->rq, mp);		return(0);	} rare();   return(-ENOBUFS);	} seldom(); return(-EBUSY);}/* *  LMI_EVENT_IND *  --------------------------------------------- */static intlmi_event_ind(m2pa_t *m2, ulong oid, ulong severity, ulong timestamp){	mblk_t *mp;	lmi_event_ind_t *p;	if ( bcanputnext(m2->rq, mp->b_band) ) {	if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) {		mp->b_datap->db_type = M_PROTO;		p = ((lmi_event_ind_t *)mp->b_wptr)++;		p->lmi_primitive	= LMI_EVENT_IND;		p->lmi_objectid		= oid;		p->lmi_timestamp	= timestamp;		p->lmi_severity		= severity;		putnext(m2->rq, mp);		return(0);	} rare();   return(-ENOBUFS);	} seldom(); return(-EBUSY);}/* *  SDT_RC_SIGNAL_UNIT_IND *  ------------------------------------------------------------------------- */static inline mblk_t *sdt_rc_signal_unit_ind(void){	mblk_t *mp;	sdt_rc_signal_unit_ind_t *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) )	{		mp->b_datap->db_type = M_PROTO;		p = (sdt_rc_signal_unit_ind_t *)mp->b_wptr;		p->sdt_primitive    = SDT_RC_SIGNAL_UNIT_IND;		mp->b_wptr += sizeof(*p);	}	return(mp);}/* *  SDT_RC_CONGESTION_ACCEPT_IND *  ------------------------------------------------------------------------- */static inline mblk_t *sdt_rc_congestion_accept_ind(void){	mblk_t *mp;	sdt_rc_congestion_accept_ind_t *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) )	{		mp->b_datap->db_type = M_PROTO;		p = (sdt_rc_congestion_accept_ind_t *)mp->b_wptr;		p->sdt_primitive    = SDT_RC_CONGESTION_ACCEPT_IND;		mp->b_wptr += sizeof(*p);	}	return(mp);}/* *  SDT_RC_CONGESTION_DISCARD_IND *  ------------------------------------------------------------------------- */static inline mblk_t *sdt_rc_congestion_discard_ind(void){	mblk_t *mp;	sdt_rc_congestion_discard_ind_t *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) )	{		mp->b_datap->db_type = M_PROTO;		p = (sdt_rc_congestion_discard_ind_t *)mp->b_wptr;		p->sdt_primitive    = SDT_RC_CONGESTION_DISCARD_IND;		mp->b_wptr += sizeof(*p);	}	return(mp);}/* *  SDT_RC_NO_CONGESTION_IND *  ------------------------------------------------------------------------- */static inline mblk_t *sdt_rc_no_congestion_ind(void){	mblk_t *mp;	sdt_rc_no_congestion_ind_t *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) )	{		mp->b_datap->db_type = M_PROTO;		p = (sdt_rc_no_congestion_ind_t *)mp->b_wptr;		p->sdt_primitive    = SDT_RC_CONGESTION_IND;		mp->b_wptr += sizeof(*p);	}	return(mp);}/* *  SDT_IAC_CORRECT_SU_IND *  ------------------------------------------------------------------------- */static inline mblk_t *sdt_iac_correct_su_ind(void){	mblk_t *mp;	sdt_iac_correct_su_ind_t *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) )	{		mp->b_datap->db_type = M_PROTO;		p = (sdt_iac_correct_su_ind_t *)mp->b_wptr;		p->sdt_primitive    = SDT_IAC_CORRECT_SU_IND;		mp->b_wptr += sizeof(*p);	}	return(mp);}/* *  SDT_IAC_ABORT_PROVING_IND *  ------------------------------------------------------------------------- */static inline mblk_t *sdt_iac_abort_proving_ind(void){	mblk_t *mp;	sdt_iac_abort_proving_ind_t *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) )	{		mp->b_datap->db_type = M_PROTO;		p = (sdt_iac_abort_proving_ind_t *)mp->b_wptr;		p->sdt_primitive    = SDT_IAC_ABORT_PROVING_IND;		mp->b_wptr += sizeof(*p);	}	return(mp);}/* *  SDT_LSC_LINK_FAILURE_IND *  ------------------------------------------------------------------------- */static inline mblk_t *sdt_lsc_link_failure_ind(void){	mblk_t *mp;	sdt_lsc_link_failure_ind_t *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) )	{		mp->b_datap->db_type = M_PROTO;		p = (sdt_lsc_link_failure_ind_t *)mp->b_wptr;		p->sdt_primitive    = SDT_LSC_LINK_FAILURE_IND;		mp->b_wptr += sizeof(*p);	}	return(mp);}/* *  SDT_TXC_TRANSMISSION_REQUEST_IND *  ------------------------------------------------------------------------- */static inline mblk_t *sdt_txc_transmission_request_ind(void){	mblk_t *mp;	sdt_txc_transmission_request_ind_t *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) )	{		mp->b_datap->db_type = M_PROTO;		p = (sdt_txc_transmission_request_ind_t *)mp->b_wptr;		p->sdt_primitive    = SDT_TXC_TRANSMISSION_REQUEST_IND;		mp->b_wptr += sizeof(*p);	}	return(mp);}/* *  ========================================================================= * *  M2PA SL-Provider --> T-Provider (SCTP) Primitives (M_CTL, M_PROTO, M_PCPROTO) * *  ========================================================================= *//* *  T_INFO_REQ *  ------------------------------------------------------------------------- */static inline mblk_t *t_info_req(void){	mblk_t *mp;	struct T_info_req *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) )	{		mp->b_datap->db_type = M_PCPROTO;		p = (struct T_info_req *)mp->b_wptr;		p->PRIM_type	= T_INFO_REQ;		mp->b_wptr += sizeof(*p);	}	return(mp);}/* *  T_ADDR_REQ *  ------------------------------------------------------------------------- */static inline mblk_t *t_addr_req(void){	mblk_t *mp;	struct T_addr_req *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) )	{		mp->b_datap->db_type = M_PCPROTO;		p = (struct T_addr_req *)mp->b_wptr;		p->PRIM_type	= T_ADDR_REQ;		p->b_wptr += sizeof(*p);	}	return(mp);}/* *  T_BIND_REQ *  ------------------------------------------------------------------------- */static inline mblk_t *t_bind_req(add_ptr, add_len, cons)	const caddr_t add_ptr;	const size_t add_len;	const uint cons;{	mblk_t *mp;	struct T_bind_req *p;	if ( (mp = allocb(sizeof(*p)+add_len, BPRI_MED)) )	{		mp->b_datap->db_type = M_PCPROTO;		p = (struct T_bind_req *)mp->b_wptr;		p->PRIM_type	    = T_BIND_REQ;		p->ADDR_length	    = add_len;		p->ADDR_offset	    = add_len ? sizeof(*p) : 0;		p->CONIND_number    = cons;		mp->b_wptr += sizeof(*p);		bcopy(add_ptr, mp->b_wptr, add_len);		mp->b_wptr += add_len;	}	return(mp);}/* *  T_UNBIND_REQ *  ------------------------------------------------------------------------- */static inline mblk_t *t_unbind_req(void){	mblk_t *mp;	struct T_unbind_req *p;	if ( (mp = allocb(sizeof(*p), BPRI_MED)) )	{		mp->b_datap->db_type = M_PCPROTO;		p = (struct T_unbind_req *)mp->b_wptr;		p->PRIM_type	= T_UNBIND_REQ;		mp->b_wptr += sizeof(*p);	}	return(mp);}/* *  T_OPTMGMT_REQ *  ------------------------------------------------------------------------- */static inline mblk_t *t_optmgmt_req(opt_ptr, opt_len, flags)	const caddr_t opt_ptr;	const size_t opt_len;	const uint flags;{	mblk_t *mp;	struct T_optmgnt_req *p;	if ( (mp = allocb(sizeof(*p)+opt_len, BPRI_MED)) )	{		mp->b_datap->db_type = M_PCPROTO;		p = (struct T_optmgmt_req *)mp->b_wptr;		p->PRIM_type	= T_OPMGMT_REQ;		p->OPT_length	= opt_len;		p->OPT_offset	= sizeof(*p);		p->MGMT_flags	= flags;		mp->b_wptr += sizeof(*p);		bcopy(opt_ptr, mp->b_wptr, opt_len);		mp->b_wptr += opt_len;	}	return(mp);}/* *  T_CONN_REQ *  ------------------------------------------------------------------------- */static inline mblk_t *t_conn_req(dst_ptr, dst_len, opt_ptr, opt_len)	const caddr_t dst_ptr;	const size_t dst_len;

⌨️ 快捷键说明

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