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

📄 sl.c

📁 OpenSS7 This the fourth public release of the OpenSS7 Master Package. See README in the release for
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** @(#) sl.c,v openss7-0_9_2_E(0.9.2.17) 2006/12/27 16:35:55 ----------------------------------------------------------------------------- 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 2006/12/27 16:35:55 by brian ----------------------------------------------------------------------------- sl.c,v Revision 0.9.2.17  2006/12/27 16:35:55  brian - added slpmod module and fixups for make check target Revision 0.9.2.16  2006/05/08 11:01:10  brian - new compilers mishandle postincrement of cast pointers Revision 0.9.2.15  2006/04/24 05:01:02  brian - call interface corrections Revision 0.9.2.14  2006/03/07 01:11:46  brian - updated headers *****************************************************************************/#ident "@(#) sl.c,v openss7-0_9_2_E(0.9.2.17) 2006/12/27 16:35:55"static char const ident[] =    "sl.c,v openss7-0_9_2_E(0.9.2.17) 2006/12/27 16:35:55";/* *  This is an SL (Signalling Link) module which can be pushed over an SDT *  (Signalling Data Terminal) module to effect an OpenSS7 Signalling Link. *  Having the SL state machines separate permits live upgrade and allows this *  state machine to be rigorously conformance tested only once. */#include <sys/os7/compat.h>#include <ss7/lmi.h>#include <ss7/lmi_ioctl.h>#include <ss7/sdti.h>#include <ss7/sdti_ioctl.h>#include <ss7/sli.h>#include <ss7/sli_ioctl.h>#define SL_DESCRIP	"SS7/IP SIGNALLING LINK (SL) STREAMS MODULE."#define SL_REVISION	"OpenSS7 sl.c,v openss7-0_9_2_E(0.9.2.17) 2006/12/27 16:35:55"#define SL_COPYRIGHT	"Copyright (c) 1997-2006 OpenSS7 Corporation.  All Rights Reserved."#define SL_DEVICE	"Part of the OpenSS7 Stack for Linux Fast-STREAMS."#define SL_CONTACT	"Brian Bidulock <bidulock@openss7.org>"#define SL_LICENSE	"GPL"#define SL_BANNER	SL_DESCRIP	"\n" \			SL_REVISION	"\n" \			SL_COPYRIGHT	"\n" \			SL_DEVICE	"\n" \			SL_CONTACT	"\n"#define SL_SPLASH	SL_DESCRIP	"\n" \			SL_REVISION	"\n"#ifdef LINUXMODULE_AUTHOR(SL_CONTACT);MODULE_DESCRIPTION(SL_DESCRIP);MODULE_SUPPORTED_DEVICE(SL_DEVICE);#ifdef MODULE_LICENSEMODULE_LICENSE(SL_LICENSE);#endif				/* MODULE_LICENSE */#if defined MODULE_ALIASMODULE_ALIAS("streams-sl");#endif#endif				/* LINUX */#ifdef LFS#define SL_MOD_ID	CONFIG_STREAMS_SL_MODID#define SL_MOD_NAME	CONFIG_STREAMS_SL_NAME#endif/* *  ========================================================================= * *  STREAMS Definitions * *  ========================================================================= */#define MOD_ID		SL_MOD_ID#define MOD_NAME	SL_MOD_NAME#ifdef MODULE#define MOD_BANNER	SL_BANNER#else				/* MODULE */#define MOD_BANNER	SL_SPLASH#endif				/* MODULE */STATIC struct module_info sl_minfo = {	.mi_idnum = MOD_ID,		/* Module ID number */	.mi_idname = MOD_NAME,		/* Module name */	.mi_minpsz = 1,			/* Min packet size accepted */	.mi_maxpsz = INFPSZ,		/* Max packet size accepted */	.mi_hiwat = 1 << 15,		/* Hi water mark */	.mi_lowat = 1 << 10,		/* Lo water mark */};STATIC int streamscall sl_open(queue_t *, dev_t *, int, int, cred_t *);STATIC int streamscall sl_close(queue_t *, int, cred_t *);STATIC struct qinit sl_rinit = {	.qi_putp = ss7_oput,		/* Read put (msg from below) */	.qi_qopen = sl_open,		/* Each open */	.qi_qclose = sl_close,		/* Last close */	.qi_minfo = &sl_minfo,		/* Information */};STATIC struct qinit sl_winit = {	.qi_putp = ss7_iput,		/* Write put (msg from above) */	.qi_minfo = &sl_minfo,		/* Information */};STATIC struct streamtab slinfo = {	.st_rdinit = &sl_rinit,		/* Upper read queue */	.st_wrinit = &sl_winit,		/* Upper write queue */};/* *  ========================================================================= * *  SL Private Structure * *  ========================================================================= */typedef struct sl {	STR_DECLARATION (struct sl);	/* stream declaration */	bufq_t rb;			/* receive buffer */	bufq_t tb;			/* transmission buffer */	bufq_t rtb;			/* retransmission buffer */	lmi_option_t option;		/* LMI options */	sl_timers_t timers;		/* SL timers */	sl_config_t config;		/* SL configuration */	sl_statem_t statem;		/* SL state machine */	sl_notify_t notify;		/* SL notification options */	sl_stats_t stats;		/* SL statistics */	sl_stats_t stamp;		/* SL statistics timestamps */	lmi_sta_t statsp;		/* SL statistics periods */} sl_t;#define SL_PRIV(__q) ((struct sl *)(__q)->q_ptr)struct sl *sl_opens = NULL;STATIC struct sl *sl_alloc_priv(queue_t *, struct sl **, dev_t *, cred_t *);STATIC struct sl *sl_get(struct sl *);STATIC void sl_put(struct sl *);STATIC void sl_free_priv(queue_t *);struct lmi_option lmi_default = {	pvar:SS7_PVAR_ITUT_96,	popt:0,};struct sl_config sl_default = {	t1:45 * HZ,	t2:5 * HZ,	t2l:20 * HZ,	t2h:100 * HZ,	t3:1 * HZ,	t4n:8 * HZ,	t4e:500 * HZ / 1000,	t5:100 * HZ / 1000,	t6:4 * HZ,	t7:1 * HZ,	rb_abate:3,	rb_accept:6,	rb_discard:9,	tb_abate_1:128 * 272,	tb_onset_1:256 * 272,	tb_discd_1:384 * 272,	tb_abate_2:512 * 272,	tb_onset_2:640 * 272,	tb_discd_2:768 * 272,	tb_abate_3:896 * 272,	tb_onset_3:1024 * 272,	tb_discd_3:1152 * 272,	N1:127,	N2:8192,	M:5,};/* *  ======================================================================== * *  PRIMITIVES * *  ======================================================================== *//* *  ------------------------------------------------------------------------ * *  Primitive sent upstream * *  ------------------------------------------------------------------------ *//* *  M_ERROR *  ----------------------------------- */STATIC INLINE intm_error(queue_t *q, struct sl *sl, int err){	mblk_t *mp;	if ((mp = ss7_allocb(q, 2, BPRI_MED))) {		mp->b_datap->db_type = M_ERROR;		*(mp->b_wptr)++ = err < 0 ? -err : err;		*(mp->b_wptr)++ = err < 0 ? -err : err;		sl->i_state = LMI_UNUSABLE;		printd(("%s: %p: <- M_ERROR\n", MOD_NAME, sl));		putnext(sl->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}#if 0/* *  M_HANGUP *  ----------------------------------- *  This primitive is not generated, but is merely passed from below. */STATIC INLINE intm_hangup(queue_t *q, struct sl *sl, int err){	mblk_t *mp;	if ((mp = ss7_allocb(q, 2, BPRI_MED))) {		mp->b_datap->db_type = M_HANGUP;		*(mp->b_wptr)++ = err < 0 ? -err : err;		*(mp->b_wptr)++ = err < 0 ? -err : err;		sl->i_state = LMI_UNUSABLE;		printd(("%s: %p: <- M_HANGUP\n", MOD_NAME, sl));		putnext(sl->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_INFO_ACK *  ----------------------------------- *  This primitive is not generated, but is merely passed from below. */STATIC INLINE intlmi_info_ack(queue_t *q, struct sl *sl, caddr_t ppa_ptr, size_t ppa_len){	mblk_t *mp;	lmi_info_ack_t *p;	if ((mp = ss7_allocb(q, sizeof(*p) + ppa_len, BPRI_MED))) {		mp->b_datap->db_type = M_PCPROTO;		p = ((typeof(p)) mp->b_wptr)++;		p->lmi_primitive = LMI_INFO_ACK;		p->lmi_version = 1;		p->lmi_state = sl->i_state;		p->lmi_max_sdu = 272 + 1 + ((sl->option.popt & SS7_POPT_XSN) ? 6 : 3);		p->lmi_min_sdu = ((sl->option.popt & SS7_POPT_XSN) ? 6 : 3);		p->lmi_header_len = 0;		p->lmi_ppa_style = LMI_STYLE2;		bcopy(ppa_ptr, mp->b_wptr, ppa_len);		mp->b_wptr += ppa_len;		printd(("%s: %p: <- LMI_INFO_ACK\n", MOD_NAME, sl));		putnext(sl->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_OK_ACK *  ----------------------------------- *  This primitive is not generated, but is merely passed from below. */STATIC INLINE intlmi_ok_ack(queue_t *q, struct sl *sl, long prim){	mblk_t *mp;	lmi_ok_ack_t *p;	if ((mp = ss7_allocb(q, sizeof(*p), BPRI_MED))) {		mp->b_datap->db_type = M_PCPROTO;		p = ((typeof(p)) mp->b_wptr)++;		p->lmi_primitive = LMI_OK_ACK;		p->lmi_correct_primitive = prim;		switch (sl->i_state) {		case LMI_ATTACH_PENDING:			sl->i_state = LMI_DISABLED;			break;		case LMI_DETACH_PENDING:			sl->i_state = LMI_UNATTACHED;			break;		default:			break;		}		p->lmi_state = sl->i_state;		printd(("%s: %p: <- LMI_OK_ACK\n", MOD_NAME, sl));		putnext(sl->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}#endif/* *  LMI_ERROR_ACK *  ----------------------------------- */STATIC INLINE intlmi_error_ack(queue_t *q, struct sl *sl, long prim, ulong reason, ulong errno){	mblk_t *mp;	lmi_error_ack_t *p;	if ((mp = ss7_allocb(q, sizeof(*p), BPRI_MED))) {		mp->b_datap->db_type = M_PCPROTO;		p = (typeof(p)) mp->b_wptr;		mp->b_wptr += sizeof(*p);		p->lmi_primitive = LMI_ERROR_ACK;		p->lmi_errno = errno;		p->lmi_reason = reason;		p->lmi_error_primitive = prim;		switch (sl->i_state) {		case LMI_ATTACH_PENDING:			sl->i_state = LMI_UNATTACHED;			break;		case LMI_DETACH_PENDING:			sl->i_state = LMI_DISABLED;			break;		case LMI_ENABLE_PENDING:			sl->i_state = LMI_DISABLED;			break;		case LMI_DISABLE_PENDING:			sl->i_state = LMI_ENABLED;			break;		default:			break;		}		p->lmi_state = sl->i_state;		printd(("%s: %p: <- LMI_ERROR_ACK\n", MOD_NAME, sl));		putnext(sl->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}#if 0/* *  LMI_ENABLE_CON *  ----------------------------------- *  This primitive is not generated, but is merely passed from below. */STATIC INLINE intlmi_enable_con(queue_t *q, struct sl *sl){	mblk_t *mp;	lmi_enable_con_t *p;	if ((mp = ss7_allocb(q, sizeof(*p), BPRI_MED))) {		mp->b_datap->db_type = M_PCPROTO;		p = ((typeof(p)) mp->b_wptr)++;		p->lmi_primitive = LMI_ENABLE_CON;		assure(sl->i_state == LMI_ENABLE_PENDING);		sl->i_state = LMI_ENABLED;		p->lmi_state = sl->i_state;		printd(("%s: %p: <- LMI_ENABLE_CON\n", MOD_NAME, sl));		putnext(sl->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_DISABLE_CON *  ----------------------------------- *  This primitive is not generated, but is merely passed from below. */STATIC INLINE intlmi_disable_con(queue_t *q, struct sl *sl){	mblk_t *mp;	lmi_disable_con_t *p;	if ((mp = ss7_allocb(q, sizeof(*p), BPRI_MED))) {		mp->b_datap->db_type = M_PCPROTO;		p = ((typeof(p)) mp->b_wptr)++;		p->lmi_primitive = LMI_DISABLE_CON;		assure(sl->i_state == LMI_DISABLE_PENDING);		sl->i_state = LMI_DISABLED;		p->lmi_state = sl->i_state;		printd(("%s: %p: <- LMI_DISABLE_CON\n", MOD_NAME, sl));		putnext(sl->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_OPTMGMT_ACK *  ----------------------------------- *  This primitive is not generated, but is merely passed from below. */STATIC INLINE intlmi_optmgmt_ack(queue_t *q, struct sl *sl, ulong flags, caddr_t opt_ptr, size_t opt_len){	mblk_t *mp;	lmi_optmgmt_ack_t *p;	if ((mp = ss7_allocb(q, sizeof(*p) + opt_len, BPRI_MED))) {		mp->b_datap->db_type = M_PCPROTO;		p = ((typeof(p)) 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;		printd(("%s: %p: <- LMI_OPTMGMT_ACK\n", MOD_NAME, sl));		putnext(sl->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_ERROR_IND *  ----------------------------------- *  This primitive is not generated, but is merely passed from below. */STATIC INLINE intlmi_error_ind(queue_t *q, struct sl *sl, ulong errno, ulong reason){	mblk_t *mp;	lmi_error_ind_t *p;	if ((mp = ss7_allocb(q, sizeof(*p), BPRI_MED))) {		mp->b_datap->db_type = M_PCPROTO;		p = ((typeof(p)) mp->b_wptr)++;		p->lmi_primitive = LMI_ERROR_IND;		p->lmi_errno = errno;		p->lmi_reason = reason;		p->lmi_state = sl->i_state;		printd(("%s: %p: <- LMI_ERROR_IND\n", MOD_NAME, sl));		putnext(sl->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}#endif#if 0

⌨️ 快捷键说明

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