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

📄 sl.c

📁 No7信令,我需要交换类似的代码, 请店长审核,谢谢了,急着交换,谢谢
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** @(#) sl.c,v 0.7.8.1 2001/12/11 13:15:40 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. ----------------------------------------------------------------------------- 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:40 by brian *****************************************************************************/#ident "@(#) sl.c,v 0.7.8.1 2001/12/11 13:15:40 brian Exp"static char const ident[] = "SS7AlphaRelease(0.7.8.1) 2001/12/11 13:15:40";/* *  This is an SL (Signalling Link) kernel module which provides all of the *  capabilities of the SLI.  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 SDTI can push this module to form *	an SLI 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 <ss7/sli.h>#include <ss7/sli_ioctl.h>#include "../lmi/lm.h"#include "../devi/dev.h"#include "../sdli/sdl.h"#include "../sdti/sdt.h"#include "../sli/sl.h"#define SL_DESCRIP	"SS7/SLI: (Signalling Link Interface) STREAMS DRIVER."#define SL_COPYRIGHT	"Copyright (c) 1997-2001 Brian Bidulock.  All Rights Reserved."#define SL_DEVICES	"Supports OpenSS7 SL drivers."#define SL_CONTACT	"Brian Bidulock <bidulock@openss7.org>"#define SL_BANNER	SL_DESCRIP	"\n" \			SL_COPYRIGHT	"\n" \			SL_DEVICES	"\n" \			SL_CONTACT	"\n"#ifdef MODULEMODULE_AUTHOR(SL_CONTACT);MODULE_DESCRIPTION(SL_DESCRIP);MODULE_SUPPORTED_DEVICE(SL_DEVICES);#define MODULE_STATIC static#else#define MOD_INC_USE_COUNT#define MOD_DEC_USE_COUNT#define MODULE_STATIC#endif#ifdef SL_DEBUGstatic int sl_debug = SL_DEBUG;#elsestatic int sl_debug = 2;#endif#define DEBUG_LEVEL sl_debug#define SL_CMAJOR 0#define SL_NMINOR 255/* *  ======================================================================= * *  STREAMS Definitions * *  ======================================================================= */static struct module_info sl_minfo ={	0,		/* Module ID number		*/	"sl",		/* Module name			*/	1,		/* Min packet size accepted	*/	512,		/* Max packet size accepted	*/	8*272,		/* Hi water mark		*/	1*272		/* Lo water mark		*/};static int  sl_open (queue_t *, dev_t *, int, int, cred_t *);static int  sl_close(queue_t *, int, cred_t *);static void sl_rput (queue_t *, mblk_t *);static void sl_rsrv (queue_t *);static struct qinit sl_rinit ={	sl_rput,	/* Read put (msg from below)	*/	sl_rsrv,	/* Read queue service		*/	sl_open,	/* Each open			*/	sl_close,	/* Last close			*/	NULL,		/* Admin (not used)		*/	&sl_minfo,	/* Information			*/	NULL		/* Statistics			*/};static void sl_wput (queue_t *, mblk_t *);static void sl_wsrv (queue_t *);static struct qinit sl_winit ={	sl_wput,	/* Write put (msg from above)	*/	sl_wsrv,	/* Write queue service		*/	NULL,		/* Each open			*/	NULL,		/* Last close			*/	NULL,		/* Admin (not used)		*/	&sl_minfo,	/* Information			*/	NULL		/* Statistics			*/};#ifndef LIS_REGISTEREDstatic#endifstruct streamtab sl_info ={	&sl_rinit,	/* Upper read  queue		*/	&sl_winit,	/* Upper write queue		*/	NULL,		/* Lower read  queue		*/	NULL		/* Lower write queue		*/};/* *  ======================================================================= * *  LMI PROTOCOL CONFIGURATION IOCTLs * *  ======================================================================= */static intsl_iocgoptions(sl_t *sl, int cmd, void *arg){	bcopy(&sl->option, arg, _IOC_SIZE(cmd));	return(0);}static intsl_iocsoptions(sl_t *sl, int cmd, void *arg){	bcopy(arg, &sl->option, _IOC_SIZE(cmd));	if ( sl->option.popt & SS7_POPT_XSN )	{		sl->statem.sn_mask = 0x7fff;		sl->statem.ib_mask = 0x8000;	}	else	{		sl->statem.sn_mask = 0x7f;		sl->statem.ib_mask = 0x80;	}	return(0);}static intsl_iocgconfig(sl_t *sl, int cmd, void *arg){	bcopy(&sl->config, arg, _IOC_SIZE(cmd));	return(0);}static intsl_iocsconfig(sl_t *sl, int cmd, void *arg){	signed long int *src, *dst, *end;	dst = (signed long int *)&sl->config;	end = (signed long int *)((&sl->config)+1);	src = arg;	while ( dst < end )	{		if ( *src != -1 )			*dst = *src;		dst++; src++;	}	return(0);}static intsl_iocgstatem(sl_t *sl, int cmd, void *arg){	bcopy(&sl->statem, arg, _IOC_SIZE(cmd));	return(0);}static intsl_iocsstatsp(sl_t *sl, int cmd, void *arg){	(void)arg;	return EOPNOTSUPP;}static intsl_iocgstatsp(sl_t *sl, int cmd, void *arg){	(void)arg;	return EOPNOTSUPP;}static intsl_ioccstats(sl_t *sl, int cmd, void *arg){	(void)arg;	bzero(&sl->stats, _IOC_SIZE(cmd));	return(0);}static intsl_iocgstats(sl_t *sl, int cmd, void *arg){	bcopy(&sl->stats, arg, _IOC_SIZE(cmd));	return(0);}static intsl_iocsnotify(sl_t *sl, int cmd, void *arg){	caddr_t dst, src, end;	src = arg;	dst = (caddr_t)&sl->notify;	end = (caddr_t)((&sl->notify)+1);	while ( dst < end )		*dst++ |= *src++;	return(0);}static intsl_ioccnotify(sl_t *sl, int cmd, void *arg){	caddr_t dst, src, end;	src = arg;	dst = (caddr_t)&sl->notify;	end = (caddr_t)((&sl->notify)+1);	while ( dst < end )		*dst++ &= ~*src++;	return(0);}static intsl_iocgnotify(sl_t *sl, int cmd, void *arg){	bcopy(&sl->notify, arg, _IOC_SIZE(cmd));	return(0);}static int (*sl_ioc_lmiops [])(sl_t *, int, void *) ={	sl_iocgoptions,	/* SL_IOCGOPTIONS	*/	sl_iocsoptions,	/* SL_IOCSOPTIONS	*/	sl_iocgconfig,	/* SL_IOCGCONFIG	*/	sl_iocsconfig,	/* SL_IOCSCONFIG	*/	NULL,		/* SL_IOCTCONFIG	*/	NULL,		/* SL_IOCCCONFIG	*/	sl_iocgstatem,	/* SL_IOCGSTATEM	*/	NULL,		/* SL_IOCCMRESET	*/	sl_iocgstatsp,	/* SL_IOCGSTATSP	*/	sl_iocsstatsp,	/* SL_IOCSSTATSP	*/	sl_iocgstats,	/* SL_IOCGSTATS		*/	sl_ioccstats,	/* SL_IOCCSTATS		*/	sl_iocgnotify,	/* SL_IOCGNOTIFY	*/	sl_iocsnotify,	/* SL_IOCSNOTIFY	*/	sl_ioccnotify	/* SL_IOCCNOTIFY	*/};/* *  ======================================================================= * *  SL->LK Serivce Primitives (M_CTL, M_PROTO, M_PCPROTO) * *  ======================================================================= */static inline void sl_uprim_link(sl_t *sl, int type, int prim, mblk_t *mp){	mblk_t *md = mp;	if ( mp->b_datap->db_type != M_DATA )	{		mp->b_wptr = mp->b_rptr;		*((sl_long *)mp->b_rptr)++ = prim;		md = mp->b_cont;	}	adjmsg(md, (sl->option.popt&SS7_POPT_XSN)?6:3); /* trim L2 header */	putnext(sl->rq, mp);}static inline void sl_uprim(sl_t *sl, int type, int prim){	mblk_t *mp;	if ( (mp = allocb(sizeof(sl_long), BPRI_HI)) )	{		mp->b_datap->db_type = type;		*((sl_long *)mp->b_wptr)++ = prim;		putnext(sl->rq, mp);	}}static inline void sl_uprim_arg(sl_t *sl, int type, int prim, int arg){	mblk_t *mp;	if ( (mp = allocb(2*sizeof(sl_long), BPRI_HI)) )	{		mp->b_datap->db_type = type;		*((sl_long *)mp->b_wptr)++ = prim;		*((sl_long *)mp->b_wptr)++ = arg;		putnext(sl->rq, mp);	}}static inline void sl_uprim_2arg(sl_t *sl, int type, int prim, int arg, int arg2){	mblk_t *mp;	if ( (mp = allocb(3*sizeof(sl_long), BPRI_HI)) )	{		mp->b_datap->db_type = type;		*((sl_long *)mp->b_wptr)++ = prim;		*((sl_long *)mp->b_wptr)++ = arg;		*((sl_long *)mp->b_wptr)++ = arg2;		putnext(sl->rq, mp);	}}static inline void sl_uprim_3arg(sl_t *sl, int type, int prim, int arg, int arg2, int arg3){	mblk_t *mp;	if ( (mp = allocb(4*sizeof(sl_long), BPRI_HI)) )	{		mp->b_datap->db_type = type;		*((sl_long *)mp->b_wptr)++ = prim;		*((sl_long *)mp->b_wptr)++ = arg;		*((sl_long *)mp->b_wptr)++ = arg2;		*((sl_long *)mp->b_wptr)++ = arg3;		putnext(sl->rq, mp);	}}static inline void sl_l3_pdu(sl_t *sl, mblk_t *mp){	sl_uprim_link(sl, M_PCPROTO, SL_PDU_IND, mp);}static inline void sl_l3_link_congested(sl_t *sl, int cong, int disc){	sl_uprim_3arg(sl, M_PCPROTO, SL_LINK_CONGESTED_IND,			jiffies, cong, disc);}static inline void sl_l3_link_congestion_ceased(sl_t *sl, int cong, int disc){	sl_uprim_3arg(sl, M_PCPROTO, SL_LINK_CONGESTION_CEASED_IND,			jiffies, cong, disc);}static inline void sl_l3_retrieved_message(sl_t *sl, mblk_t *mp){	sl_uprim_link(sl, M_PROTO, SL_RETRIEVED_MESSAGE_IND, mp);}static inline void sl_l3_retrieval_complete(sl_t *sl){	sl_uprim(sl, M_PCPROTO, SL_RETRIEVAL_COMPLETE_IND);}static inline void sl_l3_rb_cleared(sl_t *sl){	sl_uprim(sl, M_PCPROTO, SL_RB_CLEARED_IND);}static inline void sl_l3_bsnt(sl_t *sl, int bsnt){	sl_uprim_arg(sl, M_PCPROTO, SL_BSNT_IND, bsnt);}static inline void sl_l3_in_service(sl_t *sl){	sl_uprim(sl, M_PCPROTO, SL_IN_SERVICE_IND);}static inline void sl_l3_out_of_service(sl_t *sl, int reason){	sl_uprim_2arg(sl, M_PCPROTO, SL_OUT_OF_SERVICE_IND,			jiffies, reason);}static inline void sl_l3_remote_processor_outage(sl_t *sl){	sl_uprim_arg(sl, M_PCPROTO, SL_REMOTE_PROCESSOR_OUTAGE_IND,			jiffies);}static inline void sl_l3_remote_processor_recovered(sl_t *sl){	sl_uprim_arg(sl, M_PCPROTO, SL_REMOTE_PROCESSOR_RECOVERED_IND,			jiffies);}static inline void sl_l3_rtb_cleared(sl_t *sl){	sl_uprim(sl, M_PCPROTO, SL_RTB_CLEARED_IND);}static sl_ucalls_t sl_mod_ucalls ={	sl_l3_pdu,				/* sl_pdu		*/	sl_l3_link_congested,			/* sl_congested		*/	sl_l3_link_congestion_ceased,		/* sl_no_cong		*/	sl_l3_retrieved_message,		/* sl_rtrv_msg		*/	sl_l3_retrieval_complete,		/* sl_rtrv_comp		*/	sl_l3_rb_cleared,			/* sl_rb_cleared	*/	sl_l3_bsnt,				/* sl_bsnt		*/

⌨️ 快捷键说明

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