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

📄 spm.c

📁 OpenSS7 This the fourth public release of the OpenSS7 Master Package. See README in the release for
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** @(#) spm.c,v openss7-0_9_2_E(0.9.2.19) 2006/12/06 11:45:18 ----------------------------------------------------------------------------- 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/12/06 11:45:18 by brian *****************************************************************************/#ident "@(#) spm.c,v openss7-0_9_2_E(0.9.2.19) 2006/12/06 11:45:18"static char const ident[] =    "spm.c,v openss7-0_9_2_E(0.9.2.19) 2006/12/06 11:45:18";/* *  This is an SDL pipemod driver for testing and use with pipes.  This module *  is pushed on one side of the pipe (after pipemod) to make a pipe appear as *  a directly connected pair of SDL drivers. */#define _DEBUG 1#include <sys/os7/compat.h>#include <ss7/lmi.h>#include <ss7/lmi_ioctl.h>#include <ss7/sdli.h>#include <ss7/sdli_ioctl.h>#define SPM_DESCRIP	"SS7/SDL: (Signalling Data Terminal) STREAMS PIPE MODULE."#define SPM_REVISION	"OpenSS7 spm.c,v openss7-0_9_2_E(0.9.2.19) 2006/12/06 11:45:18"#define SPM_COPYRIGHT	"Copyright (c) 1997-2002 OpenSS7 Corporation.  All Rights Reserved."#define SPM_DEVICE	"Provides OpenSS7 SDL pipe driver."#define SPM_CONTACT	"Brian Bidulock <bidulock@openss7.org>"#define SPM_LICENSE	"GPL"#define SPM_BANNER	SPM_DESCRIP	"\n" \			SPM_REVISION	"\n" \			SPM_COPYRIGHT	"\n" \			SPM_DEVICE	"\n" \			SPM_CONTACT	"\n"#define SPM_SPLASH	SPM_DEVICE	" - " \			SPM_REVISION#ifdef LINUXMODULE_AUTHOR(SPM_CONTACT);MODULE_DESCRIPTION(SPM_DESCRIP);MODULE_SUPPORTED_DEVICE(SPM_DEVICE);#ifdef MODULE_LICENSEMODULE_LICENSE(SPM_LICENSE);#endif				/* MODULE_LICENSE */#if defined MODULE_ALIASMODULE_ALIAS("streams-spm");#endif#endif				/* LINUX */#ifdef LFS#define SPM_MOD_ID	CONFIG_STREAMS_SPM_MODID#define SPM_MOD_NAME	CONFIG_STREAMS_SPM_NAME#endif				/* LFS */#ifndef SPM_MOD_NAME#define SPM_MOD_NAME	"spm"#endif#ifndef SPM_MOD_ID#define SPM_MOD_ID	0#endif/* *  ======================================================================= * *  STREAMS Definitions * *  ======================================================================= */#define MOD_ID		SPM_MOD_ID#define MOD_NAME	SPM_MOD_NAME#ifdef MODULE#define MOD_BANNER	SPM_BANNER#else				/* MODULE */#define MOD_BANNER	SPM_SPLASH#endif				/* MODULE */STATIC struct module_info spm_winfo = {	MOD_ID,				/* Module ID number */	MOD_NAME "-wr",			/* Module name */	1,				/* Min packet size accepted */	280,				/* Max packet size accepted */	1,				/* Hi water mark */	0				/* Lo water mark */};STATIC struct module_info spm_rinfo = {	MOD_ID,				/* Module ID number */	MOD_NAME "-rd",			/* Module name */	1,				/* Min packet size accepted */	128,				/* Max packet size accepted */	1,				/* Hi water mark */	0				/* Lo water mark */};STATIC int streamscall spm_open(queue_t *, dev_t *, int, int, cred_t *);STATIC int streamscall spm_close(queue_t *, int, cred_t *);STATIC int streamscall spm_wput(queue_t *, mblk_t *);STATIC int streamscall spm_wsrv(queue_t *);STATIC struct qinit spm_winit = {	spm_wput,			/* Write put (message from above) */	spm_wsrv,			/* Write queue service */	NULL,				/* Each open */	NULL,				/* Last close */	NULL,				/* Admin (not used) */	&spm_winfo,			/* Information */	NULL				/* Statistics */};STATIC int streamscall spm_rput(queue_t *, mblk_t *);STATIC int streamscall spm_rsrv(queue_t *);STATIC struct qinit spm_rinit = {	spm_rput,			/* Read put (message from below) */	spm_rsrv,			/* Read queue service */	spm_open,			/* Each open */	spm_close,			/* Last close */	NULL,				/* Admin (not used) */	&spm_rinfo,			/* Information */	NULL				/* Statistics */};STATIC struct streamtab spminfo = {	&spm_rinit,			/* Upper read queue */	&spm_winit,			/* Upper write queue */	NULL,				/* Lower read queue */	NULL				/* Lower write queue */};/* *  ======================================================================== * *  Private structure * *  ======================================================================== */typedef struct spm {	struct spm *next;		/* list linkage */	struct spm **prev;		/* list linkage */	major_t cmajor;			/* major device number */	minor_t cminor;			/* minor device number */	queue_t *rq;			/* rd queue */	queue_t *wq;			/* wr queue */	uint rbid;			/* rd bufcall id */	uint wbid;			/* wr bufcall id */	spinlock_t lock;		/* queue lock */	uint nest;			/* nest of this queue lock */	void *user;			/* user of this queue lock */	uint state;			/* interface state */	uint version;			/* interface version */	uint flags;			/* interface flags */	size_t refcnt;			/* reference count */	lmi_option_t option;		/* LMI protocol and variant options */	sdl_statem_t statem;		/* SDL state machine variables */	sdl_config_t config;		/* SDL configuration options */	sdl_notify_t notify;		/* SDL notification options */	sdl_stats_t stats;		/* SDL statistics */	sdl_stats_t stamp;		/* SDL statistics timestamps */	sdl_stats_t statsp;		/* SDL statistics periods */	unsigned long wts;		/* WR throttle timestamp */	uint wno;			/* WR throttle count */	uint wtim;			/* WR throttle timer */	unsigned long rts;		/* RD throttle timestamp */	uint rno;			/* RD throttle count */	uint rtim;			/* WR throttle timer */} spm_t;#define PRIV(__q) ((spm_t *)(__q)->q_ptr)/* *  ======================================================================== * *  PRIVATE struct allocation and deallocation * *  ======================================================================== */STATIC kmem_cache_t *spm_priv_cachep = NULL;/* *  Cache allocation *  ------------------------------------------------------------------------ */STATIC intspm_init_caches(void){	if (!spm_priv_cachep &&	    !(spm_priv_cachep = kmem_cache_create	      ("spm_priv_cachep", sizeof(spm_t), 0, SLAB_HWCACHE_ALIGN, NULL, NULL))) {		cmn_err(CE_PANIC, "%s: did not allocate spm_priv_cachep", MOD_NAME);		return (-ENOMEM);	} else		printd(("%s: Allocated/selected private structure cache\n", MOD_NAME));	return (0);}STATIC intspm_term_caches(void){	if (spm_priv_cachep) {		if (kmem_cache_destroy(spm_priv_cachep)) {			cmn_err(CE_WARN, "%s: did not destroy spm_priv_cachep.", __FUNCTION__);			return (-EBUSY);		} else			printd(("spm: destroyed spm_priv_cachep\n"));	}	return (0);}/* *  Private structure allocation *  ------------------------------------------------------------------------ */STATIC spm_t *spm_alloc_priv(queue_t *q, spm_t ** sp, major_t cmajor, minor_t cminor){	spm_t *s;	if ((s = kmem_cache_alloc(spm_priv_cachep, SLAB_ATOMIC))) {		printd(("spm: allocated module private structure\n"));		bzero(s, sizeof(*s));		if ((s->next = *sp))			s->next->prev = &s->next;		s->prev = sp;		*sp = s;		printd(("spm: linked module private structure\n"));		s->rq = RD(q);		s->wq = WR(q);		s->rq->q_ptr = s->wq->q_ptr = s;		s->cmajor = cmajor;		s->cminor = cminor;		spin_lock_init(&s->lock);	/* "spm-queue-lock" */		s->state = LMI_DISABLED;	/* Style 1 */		s->version = 1;		s->wts = jiffies;		s->wno = 0;		s->rts = jiffies;		s->rno = 0;		/* 		 *  Set some defaults:		 */		printd(("spm: setting module defaults\n"));		/* 		   LMI configuration defaults */		s->option.pvar = SS7_PVAR_ITUT_88;		s->option.popt = 0;#if 0		/* 		   SDT configuration defaults */		s->config.Tin = 4;	/* AERM normal proving threshold */		s->config.Tie = 1;	/* AERM emergency proving threshold */		s->config.T = 64;	/* SUERM error threshold */		s->config.D = 256;	/* SUERM error rate parameter */		s->config.t8 = 100 * HZ / 1000;	/* T8 timeout */		s->config.Te = 577169;	/* EIM error threshold */		s->config.De = 9308000;	/* EIM correct decrement */		s->config.Ue = 144292000;	/* EIM error increment */#endif	}	return (s);}STATIC voidspm_free_priv(queue_t *q){	uint t;	spm_t *s = PRIV(q);	ensure(s, return);	if (s->rbid)		unbufcall(xchg(&s->rbid, 0));	if (s->wbid)		unbufcall(xchg(&s->wbid, 0));	if ((*(s->prev) = s->next))		s->next->prev = s->prev;	s->next = NULL;	s->prev = NULL;	if ((t = xchg(&s->wtim, 0)))		untimeout(t);	if ((t = xchg(&s->rtim, 0)))		untimeout(t);	noenable(s->wq);	noenable(s->rq);	assure(s->refcnt == 0);	printd(("spm: unlinked module private structure\n"));	kmem_cache_free(spm_priv_cachep, s);	printd(("spm: freed module private structure\n"));	return;}/* *  ======================================================================== * *  PRIMITIVES sent upstream or downstream * *  ======================================================================== *//* *  M_ERROR *  ----------------------------------- */#if 0STATIC intm_error(queue_t *q, 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;		qreply(q, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  SDL_RECEIVED_BITS_IND *  ----------------------------------- */STATIC INLINE intsdl_received_bits_ind(queue_t *q, mblk_t *mp){	union SDL_primitives *p = (union SDL_primitives *) mp->b_rptr;	p->sdl_primitive = SDL_RECEIVED_BITS_IND;	putnext(q, mp);	return (QR_ABSORBED);}#endif/* *  SDL_DISCONNECT_IND *  ----------------------------------- */STATIC INLINE intsdl_disconnect_ind(queue_t *q, mblk_t *mp){	union SDL_primitives *p = (union SDL_primitives *) mp->b_rptr;	p->sdl_primitive = SDL_DISCONNECT_IND;	putnext(q, mp);	return (QR_ABSORBED);}/* *  LMI_INFO_ACK *  ----------------------------------- */STATIC INLINE intlmi_info_ack(queue_t *q, long state, 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;		mp->b_wptr += sizeof(*p);		p->lmi_primitive = LMI_INFO_ACK;		p->lmi_version = 1;		p->lmi_state = state;		p->lmi_max_sdu = 8;		p->lmi_min_sdu = 8;		p->lmi_header_len = 0;		p->lmi_ppa_style = LMI_STYLE1;		bcopy(ppa_ptr, mp->b_wptr, ppa_len);		mp->b_wptr += ppa_len;		qreply(q, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_OK_ACK *  ----------------------------------- */STATIC INLINE intlmi_ok_ack(queue_t *q, long state, 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;		p->lmi_state = state;		qreply(q, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_ERROR_ACK *  ----------------------------------- */STATIC INLINE intlmi_error_ack(queue_t *q, long state, long prim, long err, long reason){	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 = err;		p->lmi_reason = reason;		p->lmi_state = state;		qreply(q, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_ENABLE_CON *  ----------------------------------- */STATIC INLINE intlmi_enable_con(queue_t *q, long state){	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 = state;		qreply(q, mp);		return (QR_DONE);	}	rare();	return (-ENOBUFS);}/* *  LMI_DISABLE_CON *  ----------------------------------- */STATIC INLINE intlmi_disable_con(queue_t *q, long state)

⌨️ 快捷键说明

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