📄 m2pa_sl.c
字号:
/***************************************************************************** @(#) m2pa_sl.c,v 0.7.8.1 2001/12/11 13:15:14 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:14 by brian *****************************************************************************/#ident "SS7AlphaRelease(0.7.8.1) Copyright (C) 2001/12/11 13:15:14 OpenSS7 Corporation"static char const ident[] = "SS7AlphaRelease(0.7.8.1) 2001/12/11 13:15:14";#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 <sys/dki.h>#include <sys/npi.h>#include <sys/npi_sctp.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 "../debug.h"#include "../bufq.h"#define M2PA_DESCRIP "M2PA/SCTP SIGNALLING LINK (SL) STREAMS MODULE."#define M2PA_COPYRIGHT "Copyright (c) 2001 OpenSS7 Corp. All Rights Reserved."#define M2PA_DEVICE "Part of the OpenSS7 Stack for LiS STREAMS."#define M2PA_CONTACT "Brian Bidulock <bidulock@openss7.org>"#define M2PA_BANNER M2PA_DESCRIP "\n" \ M2PA_COPYRIGHT "\n" \ M2PA_DEVICE "\n" \ M2PA_CONTACT "\n"MODULE_AUTHOR(M2PA_CONTACT);MODULE_DESCRIPTION(M2PA_DESCRIP);MODULE_SUPPORTED_DEVICE(M2PA_DEVICE);#ifndef INT#define INT void#endiftypedef void (*bufcall_fnc_t)(long);/* * ========================================================================= * * STREAMS Definitions * * ========================================================================= */static struct module_info sl_minfo ={ 0, /* Module ID number */ "m2pa-sl", /* Module name */ 0, /* Min packet size accepted */ /* FIXME */ INFPSZ, /* Max packet size accepted */ /* FIXME */ 1<<15, /* Hi water mark */ /* FIXME */ 1<<10 /* Lo water mark */ /* FIXME */};static int sl_open (queue_t *, dev_t *, int, int, cred_t *);static int sl_close(queue_t *, int, cred_t *);static INT sl_rput (queue_t *, mblk_t *);static INT 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 INT sl_wput (queue_t *, mblk_t *);static INT 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 */};static struct streamtab sl_info ={ &sl_rinit, /* Upper read queue */ &sl_winit, /* Upper write queue */ NULL, /* Lower read queue */ NULL /* Lower write queue */};/* * ========================================================================= * * M2PA-SL Private Structure * * ========================================================================= */typedef struct sl { struct sl *next; queue_t *rq; queue_t *wq; uint i_state; /* SL interface state */ uint version; /* version executing */ uint flags; /* interface flags */ ulong token; /* my bind token */ bufq_t rb; /* receive buffer */ bufq_t tb; /* transmission buffer */ bufq_t rtb; /* retransmission buffer */ uint state; /* link state */ uint timer_t1; /* t1 timer */ uint timer_t2; /* t2 timer */ uint timer_t3; /* t3 timer */ uint timer_t4; /* t4 timer */#if 0 uint timer_t5; /* t5 timer */#endif uint timer_t6; /* t6 timer */ uint timer_t7; /* t7 timer */#if 0 uint timer_t8; /* t8 timer */ uint timer_t9; /* t9 timer */#endif uint rmsu; /* received unacked msus */ uint tmsu; /* transmitted unacked msus */ uint rack; /* received acked msus */ uint tack; /* transmitted acked msus */ uint fsnr; /* received msu seq number */ uint fsnt; /* transmitted msu seq number */ uint back; /* bad acks */ sl_statem_t statem; /* state machine variables */ lmi_option_t option; /* protocol and variant options */ sl_config_t config; /* SL configuration options */ sl_notify_t notify; /* SL notification options */ sl_stats_t stats; /* SL statistics */ sl_stats_t stamp; /* SL statistics timestamps */ sdt_config_t sdt_conf; /* SDT configuration options */ sdl_config_t sdl_conf; /* SDL configuration options */ dev_device_t dev_conf; /* DEV configuration options */} sl_t;#define M2PA_VERSION_DRAFT3 3#define M2PA_VERSION_DRAFT4 4#define M2PA_VERSION_DEFAULT M2PA_VERSION_DRAFT4/* * ========================================================================= * * M2PA PDU Message Definitions * * ========================================================================= */#define M2PA_PPI 5#define M2PA_MESSAGE_CLASS 11#define M2PA_VERSION 1#define M2PA_MTYPE_DATA 1#define M2PA_MTYPE_STATUS 2#define M2PA_MTYPE_PROVING 3#define M2PA_MTYPE_ACK 4#define M2PA_DATA_MESSAGE \ __constant_htonl((M2PA_VERSION<<24)|(M2PA_MESSAGE_CLASS<<8)|M2PA_MTYPE_DATA)#define M2PA_STATUS_MESSAGE \ __constant_htonl((M2PA_VERSION<<24)|(M2PA_MESSAGE_CLASS<<8)|M2PA_MTYPE_STATUS)#define M2PA_PROVING_MESSAGE \ __constant_htonl((M2PA_VERSION<<24)|(M2PA_MESSAGE_CLASS<<8)|M2PA_MTYPE_PROVING)#define M2PA_ACK_MESSAGE \ __constant_htonl((M2PA_VERSION<<24)|(M2PA_MESSAGE_CLASS<<8)|M2PA_MTYPE_ACK)#define M2PA_STATUS_STREAM 0#define M2PA_DATA_STREAM 1#define M2PA_STATUS_OUT_OF_SERVICE (__constant_htonl(0)) /* XXX */#define M2PA_STATUS_ALIGNMENT (__constant_htonl(1))#define M2PA_STATUS_PROVING_NORMAL (__constant_htonl(2))#define M2PA_STATUS_PROVING_EMERGENCY (__constant_htonl(3))#define M2PA_STATUS_IN_SERVICE (__constant_htonl(4))#define M2PA_STATUS_PROCESSOR_OUTAGE (__constant_htonl(5))#define M2PA_STATUS_PROCESSOR_OUTAGE_ENDED (__constant_htonl(6))#define M2PA_STATUS_BUSY (__constant_htonl(7))#define M2PA_STATUS_BUSY_ENDED (__constant_htonl(8))/* * ========================================================================= * * OUTPUT Events * * ========================================================================= * ------------------------------------------------------------------------- * * SL Provider (M2PA) -> SL User Primitives * * ------------------------------------------------------------------------- * * LMI_INFO_ACK * --------------------------------------------- */static intlmi_info_ack(sl_t *sl){ mblk_t *mp; lmi_info_ack_t *p; if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) { mp->b_datap->db_type = M_PCPROTO; p = ((lmi_info_ack_t *)mp->b_wptr)++; p->lmi_primitive = LMI_INFO_ACK; p->lmi_version = 1; p->lmi_state = sl->i_state; p->lmi_max_sdu = -1; p->lmi_min_sdu = 0; p->lmi_header_len = 0; p->lmi_ppa_style = LMI_STYLE1; putnext(sl->rq, mp); return(0); } rare(); return(-ENOBUFS);}#if 0/* * LMI_OK_ACK * --------------------------------------------- */static intlmi_ok_ack(sl_t *sl, long prim){ mblk_t *mp; lmi_ok_ack_t *p; if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) { mp->b_datap->db_type = M_PCPROTO; p = ((lmi_ok_ack_t *)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 is don't change state */ } p->lmi_state = sl->i_state; putnext(sl->rq, mp); return(0); } rare(); return(-ENOBUFS);}#endif/* * LMI_ERROR_ACK * --------------------------------------------- */static intlmi_error_ack(sl_t *sl, long prim, long err){ mblk_t *mp; lmi_error_ack_t *p; switch ( err ) { case -EBUSY: case -EAGAIN: case -ENOMEM: case -ENOBUFS: seldom(); return(err); } if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) { mp->b_datap->db_type = M_PCPROTO; p = ((lmi_error_ack_t *)mp->b_wptr)++; p->lmi_primitive = LMI_ERROR_ACK; p->lmi_errno = err<0 ? -err : 0; p->lmi_reason = err<0 ? LMI_SYSERR : err; 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 is not to change state. */ } p->lmi_state = sl->i_state; putnext(sl->rq, mp); return(0); } rare(); return(-ENOBUFS);}/* * LMI_ENABLE_CON * --------------------------------------------- */static intlmi_enable_con(sl_t *sl){ mblk_t *mp; lmi_enable_con_t *p; ensure( sl->i_state == LMI_ENABLE_PENDING, return(-EFAULT) ); if ( canputnext(sl->rq) ) { if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) { mp->b_datap->db_type = M_PROTO; p = ((lmi_enable_con_t *)mp->b_wptr)++; p->lmi_primitive = LMI_ENABLE_CON; p->lmi_state = sl->i_state = LMI_ENABLED; putnext(sl->rq, mp); return(0); } rare(); return(-ENOBUFS); } rare(); return(-EBUSY);}/* * LMI_DISABLE_CON * --------------------------------------------- */static intlmi_disable_con(sl_t *sl){ mblk_t *mp; lmi_disable_con_t *p; ensure( sl->i_state == LMI_DISABLE_PENDING, return(-EFAULT) ); if ( canputnext(sl->rq) ) { if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) { mp->b_datap->db_type = M_PROTO; p = ((lmi_disable_con_t *)mp->b_wptr)++; p->lmi_primitive = LMI_DISABLE_CON; p->lmi_state = sl->i_state = LMI_DISABLED; putnext(sl->rq, mp); return(0); } rare(); return(-ENOBUFS); } rare(); return(-EBUSY);}/* * LMI_OPTMGMT_ACK * --------------------------------------------- */#if 0static intlmi_optmgmt_ack(sl_t *sl, ulong flags, void *opt_ptr, size_t opt_len){ mblk_t *mp; lmi_optmgmt_ack_t *p; if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) { mp->b_datap->db_type = M_PCPROTO; p = ((lmi_optmgmt_ack_t *)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; bcopy(opt_ptr, mp->b_wptr, opt_len); mp->b_wptr += opt_len; putnext(sl->rq, mp); return(0); } rare(); return(-ENOBUFS);}#endif/* * LMI_ERROR_IND * --------------------------------------------- */#if 0static intlmi_error_ind(sl_t *sl, long err){ mblk_t *mp; lmi_error_ind_t *p; if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) { mp->b_datap->db_type = M_PCPROTO; p = ((lmi_error_ind_t *)mp->b_wptr)++; p->lmi_primitive = LMI_ERROR_IND; p->lmi_errno = err<0 ? -err : 0; p->lmi_reason = err<0 ? LMI_SYSERR : err; p->lmi_state = sl->i_state; putnext(sl->rq, mp); return(0); } rare(); return(-ENOBUFS);}#endif/* * LMI_STATS_IND * --------------------------------------------- */#if 0static intlmi_stats_ind(sl_t *sl, ulong interval, ulong timestamp){ mblk_t *mp; lmi_stats_ind_t *p; if ( canputnext(sl->rq) ) { if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) { mp->b_datap->db_type = M_PROTO; p = ((lmi_stats_ind_t *)mp->b_wptr)++; p->lmi_primitive = LMI_STATS_IND; p->lmi_interval = interval; p->lmi_timestamp = timestamp; putnext(sl->rq, mp); return(0); } rare(); return(-ENOBUFS); } seldom(); return(-EBUSY);}#endif/* * LMI_EVENT_IND * --------------------------------------------- */static intlmi_event_ind(sl_t *sl, ulong oid, ulong severity, void *inf_ptr, size_t inf_len){ mblk_t *mp; lmi_event_ind_t *p; if ( canputnext(sl->rq) ) { if ( (mp = allocb(sizeof(*p)+inf_len, BPRI_MED)) ) { mp->b_datap->db_type = M_PROTO; p = ((lmi_event_ind_t *)mp->b_wptr)++; p->lmi_primitive = LMI_EVENT_IND; p->lmi_objectid = oid; p->lmi_timestamp = jiffies; p->lmi_severity = severity; bcopy(mp->b_wptr, inf_ptr, inf_len); mp->b_wptr += inf_len; putnext(sl->rq, mp); return(0); } rare(); return(-ENOBUFS); } seldom(); return(-EBUSY);}/* * SL_PDU_IND * --------------------------------------------- */static intsl_pdu_ind(sl_t *sl, mblk_t *dp){ mblk_t *mp; sl_pdu_ind_t *p; if ( canputnext(sl->rq) ) { if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) { mp->b_datap->db_type = M_PROTO; p = ((sl_pdu_ind_t *)mp->b_wptr)++; p->sl_primitive = SL_PDU_IND; mp->b_cont = dp; ptrace(("Delivering mp = %u\n",(uint)mp));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -