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

📄 sdt.c

📁 OpenSS7 This the fourth public release of the OpenSS7 Master Package. See README in the release for
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** @(#) sdt.c,v openss7-0_9_2_E(0.9.2.13) 2006/04/24 05:01:02 ----------------------------------------------------------------------------- Copyright (c) 2001-2004  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; 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. ----------------------------------------------------------------------------- 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/04/24 05:01:02 by brian *****************************************************************************/#ident "@(#) sdt.c,v openss7-0_9_2_E(0.9.2.13) 2006/04/24 05:01:02"static char const ident[] =    "sdt.c,v openss7-0_9_2_E(0.9.2.13) 2006/04/24 05:01:02";/* *  This is a SDT (Signalling Data Terminal) kernel module.  It provides the *  SDT interface on the top of the module and can be pushed on top of a *  stream providing the SDL (Signalling Data Link) interface.  This module *  contains the DAEDR, DAEDT, SUERM, AERM and EIM functions to be tested once *  and used by many drivers.  The SDL stream upon which this module is pushed *  provides and accepts a blocked bit-stream as input and output.  Conversion *  between the packet interface of the SDT and the bit-stream interface of *  the SDL is performed using soft-HDLC. */#include <sys/os7/compat.h>#include <ss7/lmi.h>#include <ss7/lmi_ioctl.h>#include <ss7/sdli.h>#include <ss7/sdli_ioctl.h>#include <ss7/sdti.h>#include <ss7/sdti_ioctl.h>#define SDT_DESCRIP	"SS7/SDT: (Signalling Data Terminal) STREAMS MODULE."#define SDT_REVISION	"OpenSS7 sdt.c,v openss7-0_9_2_E (0.9.2.13) 2006/04/24 05:01:02"#define SDT_COPYRIGHT	"Copyright (c) 1997-2002 OpenSS7 Corporation.  All Rights Reserved."#define SDT_DEVICE	"Supports OpenSS7 SDL drivers."#define SDT_CONTACT	"Brian Bidulock <bidulock@openss7.org>"#define SDT_LICENSE	"GPL"#define SDT_BANNER	SDT_DESCRIP	"\n" \			SDT_REVISION	"\n" \			SDT_COPYRIGHT	"\n" \			SDT_DEVICE	"\n" \			SDT_CONTACT	"\n"#define SDT_SPLASH	SDT_DEVICE	" - " \			SDT_REVISION	"\n"#ifdef LINUXMODULE_AUTHOR(SDT_CONTACT);MODULE_DESCRIPTION(SDT_DESCRIP);MODULE_SUPPORTED_DEVICE(SDT_DEVICE);#ifdef MODULE_LICENSEMODULE_LICENSE(SDT_LICENSE);#endif				/* MODULE_LICENSE */#if defined MODULE_ALIASMODULE_ALIAS("streams-sdt");#endif#endif				/* LINUX */#ifndef SDT_MOD_NAME#define SDT_MOD_NAME	"sdt"#endif#ifndef SDT_MOD_ID#define SDT_MOD_ID	0#endif/* *  ======================================================================= * *  STREAMS Definitions * *  ======================================================================= */#define MOD_ID		SDT_MOD_ID#define MOD_NAME	SDT_MOD_NAME#ifdef MODULE#define MOD_BANNER	SDT_BANNER#else				/* MODULE */#define MOD_BANNER	SDT_SPLASH#endif				/* MODULE */STATIC struct module_info sdt_rinfo = {	.mi_idnum = MOD_ID,		/* Module ID number */	.mi_idname = MOD_NAME,		/* Module name */	.mi_minpsz = 1,			/* Min packet size accepted */	.mi_maxpsz = 128,		/* Max packet size accepted */	.mi_hiwat = 1,			/* Hi water mark */	.mi_lowat = 0,			/* Lo water mark */};STATIC struct module_info sdt_winfo = {	.mi_idnum = MOD_ID,		/* Module ID number */	.mi_idname = MOD_NAME,		/* Module name */	.mi_minpsz = 1,			/* Min packet size accepted */	.mi_maxpsz = 280,		/* Max packet size accepted */	.mi_hiwat = 1,			/* Hi water mark */	.mi_lowat = 0,			/* Lo water mark */};STATIC int streamscall sdt_open(queue_t *, dev_t *, int, int, cred_t *);STATIC int streamscall sdt_close(queue_t *, int, cred_t *);STATIC struct qinit sdt_rinit = {	.qi_putp = ss7_oput,		/* Read put (message from below) */	.qi_qopen = sdt_open,		/* Each open */	.qi_qclose = sdt_close,		/* Last close */	.qi_minfo = &sdt_rinfo,		/* Information */};STATIC struct qinit sdt_winit = {	.qi_putp = ss7_iput,		/* Write put (message from above) */	.qi_minfo = &sdt_winfo,		/* Information */};STATIC struct streamtab sdtinfo = {	.st_rdinit = &sdt_rinit,	/* Upper read queue */	.st_wrinit = &sdt_winit,	/* Upper write queue */};/* *  ======================================================================== * *  Private structure * *  ======================================================================== */typedef struct sdt_path {	uint residue;			/* residue bits */	uint rbits;			/* number of residue bits */	ushort bcc;			/* crc for message */	uint state;			/* state */	uint mode;			/* path mode */	uint type;			/* path frame type */	uint bytes;			/* number of whole bytes */	mblk_t *msg;			/* message */	mblk_t *nxt;			/* message chain block */	mblk_t *cmp;			/* repeat/compress buffer */	uint repeat;			/* repeat/compress count */} sdt_path_t;typedef struct sdt {	STR_DECLARATION (struct sdt);	/* streamd declaration */	sdt_path_t tx;			/* transmit path variables */	sdt_path_t rx;			/* receive path variables */	uint rx_octets;			/* no received octets */	sdt_timers_t timers;		/* SDT protocol timers */	lmi_option_t option;		/* LMI protocol and variant options */	sdt_statem_t statem;		/* SDT state machine variables */	sdt_config_t config;		/* SDT configuration options */	sdt_notify_t notify;		/* SDT notification options */	sdt_stats_t stats;		/* SDT statistics */	sdt_stats_t stamp;		/* SDT statistics timestamps */	lmi_sta_t statsp;		/* SDT statistics periods */} sdt_t;#define SDT_PRIV(__q) ((struct sdt *)(__q)->q_ptr)struct sdt *sdt_opens = NULL;STATIC struct sdt *sdt_alloc_priv(queue_t *, struct sdt **, dev_t *, cred_t *);STATIC struct sdt *sdt_get(struct sdt *);STATIC void sdt_put(struct sdt *);STATIC void sdt_free_priv(queue_t *);struct lmi_option lmi_default = {	pvar:SS7_PVAR_ITUT_96,	popt:0,};struct sdt_config sdt_default = {	Tin:4,				/* AERM normal proving threshold */	Tie:1,				/* AERM emergency proving threshold */	T:64,				/* SUERM error threshold */	D:256,				/* SUERM error rate parameter */	t8:100 * HZ / 1000,		/* T8 timeout */	Te:577169,			/* EIM error threshold */	De:9308,			/* EIM correct decrement */	Ue:144292,			/* EIM error increment */	N:16,				/* octets per su in OCM */	m:272,				/* maximum SIF size */	b:8,				/* transmit block size */	f:SDT_FLAGS_ONE,		/* one flag between frames */};/* *  ======================================================================== * *  PRIMITIVES * *  ======================================================================== *//* *  ------------------------------------------------------------------------ * *  Primitives sent upstream * *  ------------------------------------------------------------------------ *//* *  M_ERROR *  ----------------------------------- */STATIC intm_error(queue_t *q, struct sdt *s, 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;		s->i_state = LMI_UNUSABLE;		printd(("%s: %p: <- M_ERROR\n", MOD_NAME, s));		putnext(s->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}#if 0/* *  M_HANGUP *  ----------------------------------- */STATIC intm_hangup(queue_t *q, struct sdt *s, 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;		s->i_state = LMI_UNUSABLE;		printd(("%s: %p: <- M_HANGUP\n", MOD_NAME, s));		putnext(s->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_INFO_ACK *  ----------------------------------- *  NOTE: before pushing SDT as a module, a STYLE2 SDL driver should have *  already been attached so that the SDT module can run as a STYLE1 module. */STATIC INLINE intlmi_info_ack(queue_t *q, struct sdt *s){	mblk_t *mp;	lmi_info_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_INFO_ACK;		p->lmi_version = 1;		p->lmi_state = s->i_state;		p->lmi_max_sdu = s->config.m + 1 + ((s->option.popt & SS7_POPT_XSN) ? 6 : 3);		p->lmi_min_sdu = ((s->option.popt & SS7_POPT_XSN) ? 6 : 3);		p->lmi_header_len = 0;		p->lmi_ppa_style = LMI_STYLE1;	/* only STYLE1 for modules */		printd(("%s: %p: <- LMI_INFO_ACK\n", MOD_NAME, s));		putnext(s->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_OK_ACK *  ----------------------------------- */STATIC INLINE intlmi_ok_ack(queue_t *q, struct sdt *s, 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;		mp->b_wptr += sizeof(*p);		p->lmi_primitive = LMI_OK_ACK;		p->lmi_correct_primitive = prim;		switch (s->i_state) {		case LMI_ATTACH_PENDING:			s->i_state = LMI_DISABLED;			break;		case LMI_DETACH_PENDING:			s->i_state = LMI_UNATTACHED;			break;		}		p->lmi_state = s->i_state;		printd(("%s: %p: <- LMI_OK_ACK\n", MOD_NAME, s));		putnext(s->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}#endif/* *  LMI_ERROR_ACK *  ----------------------------------- */STATIC INLINE intlmi_error_ack(queue_t *q, struct sdt *s, 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 (s->i_state) {		case LMI_ATTACH_PENDING:			s->i_state = LMI_UNATTACHED;			break;		case LMI_DETACH_PENDING:			s->i_state = LMI_DISABLED;			break;		case LMI_ENABLE_PENDING:			s->i_state = LMI_DISABLED;			break;		case LMI_DISABLE_PENDING:			s->i_state = LMI_ENABLED;			break;		default:			break;		}		p->lmi_state = s->i_state;		printd(("%s: %p: <- LMI_ERROR_ACK\n", MOD_NAME, s));		putnext(s->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}#if 0/* *  LMI_ENABLE_CON *  ----------------------------------- */STATIC INLINE intlmi_enable_con(queue_t *q, struct sdt *s){	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;		mp->b_wptr += sizeof(*p);		p->lmi_primitive = LMI_ENABLE_CON;		p->lmi_state = s->i_state;		printd(("%s: %p: <- LMI_ENABLE_CON\n", MOD_NAME, s));		putnext(s->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_DISABLE_CON *  ----------------------------------- */STATIC INLINE intlmi_disable_con(queue_t *q, struct sdt *s){	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;		mp->b_wptr += sizeof(*p);		p->lmi_primitive = LMI_DISABLE_CON;		p->lmi_state = s->i_state;		printd(("%s: %p: <- LMI_DISABLE_CON\n", MOD_NAME, s));		putnext(s->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_OPTMGMT_ACK *  ----------------------------------- */STATIC INLINE intlmi_optmgmt_ack(queue_t *q, struct sdt *s, 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;		mp->b_wptr += sizeof(*p);		p->lmi_primitive = LMI_OPTMGMT_ACK;		p->lmi_opt_length = opt_len;		p->lmi_opt_offset = opt_len ? sizeof(*p) : 0;		p->lmi_flags = flags;		bcopy(opt_ptr, mp->b_wptr, opt_len);		mp->b_wptr += opt_len;		printd(("%s: %p: <- LMI_OPTMGMT_ACK\n", MOD_NAME, s));		putnext(s->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_ERROR_IND *  ----------------------------------- */STATIC INLINE intlmi_error_ind(queue_t *q, struct sdt *s, long error, long 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;		mp->b_wptr += sizeof(*p);		p->lmi_primitive = LMI_ERROR_IND;		p->lmi_errno = error;		p->lmi_reason = reason;		p->lmi_state = s->i_state;		printd(("%s: %p: <- LMI_ERROR_IND\n", MOD_NAME, s));		putnext(s->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_STATS_IND *  ----------------------------------- */STATIC INLINE intlmi_stats_ind(queue_t *q, struct sdt *s){	mblk_t *mp;	lmi_stats_ind_t *p;	if ((mp = ss7_allocb(q, sizeof(*p), BPRI_MED))) {		mp->b_datap->db_type = M_PROTO;		p = (typeof(p)) mp->b_wptr;		mp->b_wptr += sizeof(*p);		p->lmi_primitive = LMI_STATS_IND;		p->lmi_interval = 0;		p->lmi_timestamp = jiffies;		printd(("%s: %p: <- LMI_STATS_IND\n", MOD_NAME, s));		putnext(s->oq, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/*

⌨️ 快捷键说明

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