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

📄 sdt.c

📁 No7信令,我需要交换类似的代码, 请店长审核,谢谢了,急着交换,谢谢
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** @(#) sdt.c,v SS7AlphaRelease(0.7.8.1) 2001/12/11 13:15:38 ----------------------------------------------------------------------------- Copyright (c) 2001  OpenSS7 Corporation <http://www.openss7.com> Copyright (c) 1997-2000  Brian F. G. Bidulock <bidulock@dallas.net> 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 success regulations) or, in the cases of NASA, in paragraph 18.52.227-86 of the NASA Supplement to the FAR (or any successor regulations). ----------------------------------------------------------------------------- Last Modified 2001/12/11 13:15:38 by brian *****************************************************************************/#ident "@(#) sdt.c,v SS7AlphaRelease(0.7.8.1) 2001/12/11 13:15:38"static char const ident[] = "sdt.c,v SS7AlphaRelease(0.7.8.1) 2001/12/11 13:15:38";/* *  This is an SDT (Signalling Data Terminal) kernel module which provides all *  of the capabilities of the SDTI.  It can be used by drivers in two *  fashions: * *  1)  Drivers can provide a set of missing functions by registering with the *      module using sdt_register_driver.  This relieves much of the STREAMS *      burden from the driver implementation and permits the driver to be *      more portable across the Linux, STREAMS, and BSD implementation of the *      OpenSS7 stack. * *  2)  Drivers which implement the OpenSS7 SDLI can push this module to form *      an SDTI driver implementation. * *  Both fashions permit SS7 Level 2 compliant state machines to be tested *  once, but used by many drivers. */#include <linux/config.h>#include <linux/version.h>#include <linux/modversions.h>#include <linux/module.h>#include <sys/stream.h>#include <sys/stropts.h>#include <sys/cmn_err.h>#include "../debug.h"#include "../bufq.h"#include <ss7/lmi.h>#include <ss7/lmi_ioctl.h>#include <ss7/devi.h>#include <ss7/devi_ioctl.h>#include <ss7/sdli.h>#include <ss7/sdli_ioctl.h>#include <ss7/sdti.h>#include <ss7/sdti_ioctl.h>#include "../lmi/lm.h"#include "../devi/dev.h"#include "../sdli/sdl.h"#include "../sdti/sdt.h"#define SDT_DESCRIP	"SS7/SDT: (Signalling Data Terminal) STREAMS DRIVER."#define SDT_COPYRIGHT	"Copyright (c) 1997-2001 OpenSS7 Corporation.  All Rights Reserved."#define SDT_DEVICES	"Supports OpenSS7 SDT drivers."#define SDT_CONTACT	"Brian Bidulock <bidulock@openss7.org>"#define SDT_BANNER	SDT_DESCRIP   "\n" \			SDT_COPYRIGHT "\n" \			SDT_DEVICES   "\n" \			SDT_CONTACT   "\n"#ifdef MODULEMODULE_AUTHOR(SDT_CONTACT);MODULE_DESCRIPTION(SDT_DESCRIP);MODULE_SUPPORTED_DEVICE(SDT_DEVICES);#define MODULE_STATIC static#else#define MOD_INC_USE_COUNT#define MOD_DEC_USE_COUNT#define MODULE_STATIC#endif#ifdef SDT_DEBUGstatic int sdt_debug = SDT_DEBUG;#elsestatic int sdt_debug = 2;#endif#define DEBUG_LEVEL sdt_debug#define SDT_CMAJOR 0#define SDT_NMINOR 255/* *  ======================================================================= * *  STREAMS Definitions * *  ======================================================================= */static struct module_info sdt_minfo ={	0,		/* Module ID number			*/	"sdt",		/* Module name				*/	1,		/* Min packet size accepted		*/	512,		/* Max packet size accepted		*/	8*272,		/* Hi water mark			*/	1*272		/* Lo water mark			*/};static void sdt_rput (queue_t *, mblk_t *);static void sdt_rsrv (queue_t *);static int  sdt_open (queue_t *, dev_t *, int, int, cred_t *);static int  sdt_close(queue_t *, int, cred_t *);static struct qinit sdt_rinit ={	sdt_rput,	/* Read put (message from below)	*/	sdt_rsrv,	/* Read queue service			*/	sdt_open,	/* Each open				*/	sdt_close,	/* Last close				*/	NULL,		/* Admin (not used)			*/	&sdt_minfo,	/* Information				*/	NULL		/* Statistics				*/};static void sdt_wput (queue_t *, mblk_t *);static void sdt_wsrv (queue_t *);static struct qinit sdt_winit ={	sdt_wput,	/* Write put (message from above)	*/	sdt_wsrv,	/* Write queue service			*/	NULL,		/* Each open				*/	NULL,		/* Last close				*/	NULL,		/* Admin (not used)			*/	&sdt_minfo,	/* Information				*/	NULL		/* Statistics				*/};#ifndef LIS_REGISTEREDstatic#endifstruct streamtab sdt_info ={	&sdt_rinit,	/* Upper read  queue			*/	&sdt_winit,	/* Upper write queue			*/	NULL,		/* Lower read  queue			*/	NULL		/* Lower write queue			*/};/* *  ======================================================================= * *  LMI PROTOCOL CONFIGURATION IOCTLs * *  ======================================================================= */static int sdt_iocgoptions(sdt_t *sdt, int cmd, void *arg){	bcopy(&sdt->option, arg, _IOC_SIZE(cmd));	return(0);}static int sdt_iocsoptions(sdt_t *sdt, int cmd, void *arg){	bcopy(arg, &sdt->option, _IOC_SIZE(cmd));	return(0);}static int sdt_iocgconfig(sdt_t *sdt, int cmd, void *arg){	bcopy(&sdt->config, arg, _IOC_SIZE(cmd));	return(0);}static int sdt_iocsconfig(sdt_t *sdt, int cmd, void *arg){	signed long int *src, *dst, *end;	dst = (signed long int *)&sdt->config;	end = (signed long int *)((&sdt->config)+1);	src = arg;	while ( dst < end )	{		if ( *src != -1 )			*dst = *src;		dst++; src++;	}	return(0);}static int sdt_iocgstatem(sdt_t *sdt, int cmd, void *arg){	bcopy(&sdt->statem, arg, _IOC_SIZE(cmd));	return(0);}static int sdt_iocsstatsp(sdt_t *sdt, int cmd, void *arg){	(void)arg;	rare(); return EOPNOTSUPP;}static int sdt_iocgstatsp(sdt_t *sdt, int cmd, void *arg){	(void)arg;	rare(); return EOPNOTSUPP;}static int sdt_ioccstats(sdt_t *sdt, int cmd, void *arg){	(void)arg;	bzero(&sdt->stats, _IOC_SIZE(cmd));	return(0);}static int sdt_iocgstats(sdt_t *sdt, int cmd, void *arg){	bcopy(&sdt->stats, arg, _IOC_SIZE(cmd));	return(0);}static int sdt_iocsnotify(sdt_t *sdt, int cmd, void *arg){	caddr_t dst, src, end;	src = arg;	dst = (caddr_t)&sdt->notify;	end = (caddr_t)((&sdt->notify)+1);	while ( dst < end ) *dst++ |= *src++;	return(0);}static int sdt_ioccnotify(sdt_t *sdt, int cmd, void *arg){	caddr_t dst, src, end;	src = arg;	dst = (caddr_t)&sdt->notify;	end = (caddr_t)((&sdt->notify)+1);	while ( dst < end ) *dst++ &= ~*src++;	return(0);}static int sdt_iocgnotify(sdt_t *sdt, int cmd, void *arg){	bcopy(&sdt->notify, arg, _IOC_SIZE(cmd));	return(0);}static int (*sdt_ioc_lmiops [])(sdt_t *, int, void *) ={	sdt_iocgoptions,	/* SDT_IOCGOPTIONS	*/	sdt_iocsoptions,	/* SDT_IOCSOPTIONS	*/	sdt_iocgconfig,		/* SDT_IOCGCONFIG	*/	sdt_iocsconfig,		/* SDT_IOCSCONFIG	*/	NULL,			/* SDT_IOCTCONFIG	*/	NULL,			/* SDT_IOCCCONFIG	*/	sdt_iocgstatem,		/* SDT_IOCGSTATEM	*/	NULL,			/* SDT_IOCCMRESET	*/	sdt_iocgstatsp,		/* SDT_IOCGSTATSP	*/	sdt_iocsstatsp,		/* SDT_IOCSSTATSP	*/	sdt_iocgstats,		/* SDT_IOCGSTATS	*/	sdt_ioccstats,		/* SDT_IOCCSTATS	*/	sdt_iocgnotify,		/* SDT_IOCGNOTIFY	*/	sdt_iocsnotify,		/* SDT_IOCSNOTIFY	*/	sdt_ioccnotify		/* SDT_IOCCNOTIFY	*/};/* *  ============================================================== * *  SDT->SL Service Primitives (M_CTL, M_PROTO, M_PCPROTO) * *  ============================================================== */static inline void sdt_uprim(sdt_t *sdt, int type, int prim){	mblk_t *mp;	if ( (mp = allocb(sizeof(sdt_long), BPRI_HI)) )	{		mp->b_datap->db_type = type;		*((sdt_long *)mp->b_wptr)++ = prim;		putnext(sdt->rq, mp);	}}static inline void sdt_rc_signal_unit(sdt_t *sdt, mblk_t *mp){	if ( mp->b_datap->db_type != M_DATA )		*((int *)mp->b_rptr) = SDT_RC_SIGNAL_UNIT_IND;	putnext(sdt->rq, mp);}static inline void sdt_rc_congestion_accept(sdt_t *sdt){	sdt_uprim(sdt, M_PCPROTO, SDT_RC_CONGESTION_ACCEPT_IND);}static inline void sdt_rc_congestion_discard(sdt_t *sdt){	sdt_uprim(sdt, M_PCPROTO, SDT_RC_CONGESTION_DISCARD_IND);}static inline void sdt_rc_no_congestion(sdt_t *sdt){	sdt_uprim(sdt, M_PCPROTO, SDT_RC_NO_CONGESTION_IND);}static inline void sdt_iac_correct_su(sdt_t *sdt){	sdt_uprim(sdt, M_PROTO, SDT_IAC_CORRECT_SU_IND);}static inline void sdt_iac_abort_proving(sdt_t *sdt){	sdt_uprim(sdt, M_PCPROTO, SDT_IAC_ABORT_PROVING_IND);}static inline void sdt_lsc_link_failure(sdt_t *sdt){	sdt_uprim(sdt, M_PCPROTO, SDT_LSC_LINK_FAILURE_IND);}static inline void sdt_txc_transmission_request(sdt_t *sdt){	sdt_uprim(sdt, M_PCPROTO, SDT_TXC_TRANSMISSION_REQUEST_IND);}static sdt_ucalls_t sdt_mod_ucalls ={	sdt_rc_signal_unit,		/* rc_signal_unit		*/	sdt_rc_congestion_accept,	/* rc_congestion_accept		*/	sdt_rc_congestion_discard,	/* rc_congestion_discard	*/	sdt_rc_no_congestion,		/* rc_no_congestion		*/	sdt_iac_correct_su,		/* iac_correct_su		*/	sdt_iac_abort_proving,		/* iac_abort_proving		*/	sdt_lsc_link_failure,		/* lsc_link_failure		*/	sdt_txc_transmission_request	/* txc_transmission_request	*/};/* *  ============================================================== * *  SDT->SDL Service Primitives (M_CTL, M_PROTO, M_PCPROTO) * *  ============================================================== */static inline voidsdt_dprim(sdt_t *sdt, int type, int prim){	mblk_t *mp;	if ( (mp = allocb(sizeof(sdt_long), BPRI_HI)) )	{		mp->b_datap->db_type = type;		*((sdt_long *)mp->b_wptr)++ = prim;		putnext(sdt->wq, mp);	}}static void sdl_daedt_xmit_req(sdt_t *sdt, mblk_t *mp){	if ( mp->b_datap->db_type != M_DATA )	{		*((int *)mp->b_rptr) = SDL_DAEDT_TRANSMISSION_REQ;		mp->b_datap->db_type = M_PROTO;	}	putnext(sdt->wq, mp);}static void sdl_daedt_start_req(sdt_t *sdt){	sdt_dprim(sdt, M_PCPROTO, SDL_DAEDT_START_REQ);}static void sdl_daedr_start_req(sdt_t *sdt){	sdt_dprim(sdt, M_PCPROTO, SDL_DAEDR_START_REQ);}static struct sdt_mcalls sdt_mod_dcalls ={	sdl_daedt_xmit_req,	/* daedt_xmit	*/	sdl_daedt_start_req,	/* daedt_start	*/	sdl_daedr_start_req	/* daedr_start	*/};/* *  ============================================================== * *  SDT->SDL Service Calls (Driver) * *  ============================================================== */static void sdl_daedt_xmit(sdt_t *sdt, mblk_t *mp){	sdt->driver->dcalls->daedt_xmit(sdt->device, mp);}static void sdl_daedt_start(sdt_t *sdt){	sdt->driver->dcalls->daedt_start(sdt->device);}static void sdl_daedr_start(sdt_t *sdt){	sdt->driver->dcalls->daedr_start(sdt->device);}static struct sdt_mcalls sdt_drv_dcalls ={	sdl_daedt_xmit,		/* daedt_xmit	*/	sdl_daedt_start,	/* daedt_start	*/	sdl_daedr_start		/* daedr_start	*/};/* *  ========================================================================= * *  PROTOCOL STATE MACHINE FUNCTIONS * *  ========================================================================= */static inline voidsdt_aerm_su_in_error(sdt_t *sdt){	if ( sdt->statem.aerm_state == SDT_STATE_MONITORING )	{		sdt->statem.Ca++;		if ( sdt->statem.Ca == sdt->statem.Ti )		{			sdt->statem.aborted_proving = 1;			sdt->ucalls->iac_abort_proving(sdt); /*-upstream-*/			sdt->statem.aerm_state = SDT_STATE_IDLE;		}	}}static inline voidsdt_aerm_correct_su(sdt_t *sdt) /* RxISR */{	if ( sdt->statem.aerm_state == SDT_STATE_IDLE )	{		if ( sdt->statem.aborted_proving )		{			sdt->ucalls->iac_correct_su(sdt);			sdt->statem.aborted_proving = 0;		}	}}static inline voidsdt_suerm_start(sdt_t *sdt){	sdt->statem.Cs = 0;	sdt->statem.Ns = 0;	sdt->statem.suerm_state = SDT_STATE_IN_SERVICE;}static inline voidsdt_suerm_stop(sdt_t *sdt){	sdt->statem.suerm_state = SDT_STATE_IDLE;}

⌨️ 快捷键说明

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