📄 sdl_sctp.c
字号:
/***************************************************************************** @(#) sdl_sctp.c,v SS7AlphaRelease(0.7.8.1) 2001/12/11 13:15:49 ----------------------------------------------------------------------------- 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:49 by brian *****************************************************************************/#ident "@(#) sdl_sctp.c,v SS7AlphaRelease(0.7.8.1) 2001/12/11 13:15:49"static char const ident[] = "sdl_sctp.c,v SS7AlphaRelease(0.7.8.1) 2001/12/11 13:15:49";#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 "../debug.h"#include "../bufq.h"#define SDL_DESCRIP "SS7/SCTP SIGNALLING DATA LINK (SDL) STREAMS MODULE."#define SDL_COPYRIGHT "Copyright (c) 2001 OpenSS7 Corp. All Rights Reserved."#define SDL_DEVICE "Part of the OpenSS7 Stack for LiS STREAMS."#define SDL_CONTACT "Brian Bidulock <bidulock@openss7.org>"#define SDL_BANNER SDL_DESCRIP "\n" \ SDL_COPYRIGHT "\n" \ SDL_DEVICE "\n" \ SDL_CONTACT "\n"MODULE_AUTHOR(SDL_CONTACT);MODULE_DESCRIPTION(SDL_DESCRIP);MODULE_SUPPORTED_DEVICE(SDL_DEVICE);#ifndef INT#define INT void#endif//#define SDL_RX_COMPRESSION//#define SDL_TX_COMPRESSIONtypedef void (*bufcall_fnc_t)(long);/* * ========================================================================= * * STREAMS Definitions * * ========================================================================= */static struct module_info sdl_minfo ={ 0, /* Module ID number */ "sdl-sctp", /* 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 sdl_open (queue_t *, dev_t *, int, int, cred_t *);static int sdl_close(queue_t *, int, cred_t *);static INT sdl_rput (queue_t *, mblk_t *);static INT sdl_rsrv (queue_t *);static struct qinit sdl_rinit ={ sdl_rput, /* Read put (msg from below) */ sdl_rsrv, /* Read queue service */ sdl_open, /* Each open */ sdl_close, /* Last close */ NULL, /* Admin (not used) */ &sdl_minfo, /* Information */ NULL /* Statistics */};static INT sdl_wput (queue_t *, mblk_t *);static INT sdl_wsrv (queue_t *);static struct qinit sdl_winit ={ sdl_wput, /* Write put (msg from above) */ sdl_wsrv, /* Write queue service */ NULL, /* Each open */ NULL, /* Last close */ NULL, /* Admin (not used) */ &sdl_minfo, /* Information */ NULL /* Statistics */};static struct streamtab sdl_info ={ &sdl_rinit, /* Upper read queue */ &sdl_winit, /* Upper write queue */ NULL, /* Lower read queue */ NULL /* Lower write queue */};/* * ========================================================================= * * SDL Private Structure * * ========================================================================= */typedef struct sdl { struct sdl *next; queue_t *rq; queue_t *wq; uint state; /* SDL interface state */ uint version; /* version executing */ uint flags; /* interface flags */ ulong token; /* my bind token */ mblk_t *rx_buf; /* RX compression buffer */ size_t rx_count; /* RX compression count */ mblk_t *tx_buf; /* TX compression buffer */ size_t tx_count; /* TX compression count */ uint timer_tick; /* tick timer */ lmi_option_t lmi_conf; /* protocol and variant options */ sdl_config_t sdl_conf; /* SDL configuration options */ dev_device_t dev_conf; /* DEV configuration options */} sdl_t;#define SDL_LSSU_SIO 0#define SDL_LSSU_SIN 1#define SDL_LSSU_SIE 2#define SDL_LSSU_SIOS 3#define SDL_LSSU_SIPO 4#define SDL_LSSU_SIB 5#define SDL_LSS2_SIO 0 + 8#define SDL_LSS2_SIN 1 + 8#define SDL_LSS2_SIE 2 + 8#define SDL_LSS2_SIOS 3 + 8#define SDL_LSS2_SIPO 4 + 8#define SDL_LSS2_SIB 5 + 8#define SDL_FISU 16#define SDL_MSU 17#define SDL_FLAG_RX_ENABLED 0x01#define SDL_FLAG_TX_ENABLED 0x02#define SDL_EVENT_TX_WAKEUP 1/* * ========================================================================= * * SDL Provider (SDL) -> SDL User Primitives * * ========================================================================= *//* * LMI_INFO_ACK * --------------------------------------------- */static intlmi_info_ack(sdl_t *sp){ mblk_t *mp; lmi_info_ack_t *p; ensure( sp , return(-EFAULT) ); 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 = sp->state; p->lmi_max_sdu = -1; p->lmi_min_sdu = 0; p->lmi_header_len = 0; p->lmi_ppa_style = LMI_STYLE1; putnext(sp->rq, mp); return(0); } rare(); return(-ENOBUFS);}/* * LMI_OK_ACK * --------------------------------------------- */static intlmi_ok_ack(sdl_t *sp, long prim){ mblk_t *mp; lmi_ok_ack_t *p; ensure( sp , return(-EFAULT) ); 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 ( sp->state ) { case LMI_ATTACH_PENDING: sp->state = LMI_DISABLED; break; case LMI_DETACH_PENDING: sp->state = LMI_UNATTACHED; break; /* default is don't change state */ } p->lmi_state = sp->state; putnext(sp->rq, mp); return(0); } rare(); return(-ENOBUFS);}/* * LMI_ERROR_ACK * --------------------------------------------- */static intlmi_error_ack(sdl_t *sp, 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); } ensure( sp , return(-EFAULT) ); 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 ( sp->state ) { case LMI_ATTACH_PENDING: sp->state = LMI_UNATTACHED; break; case LMI_DETACH_PENDING: sp->state = LMI_DISABLED; break; case LMI_ENABLE_PENDING: sp->state = LMI_DISABLED; break; case LMI_DISABLE_PENDING: sp->state = LMI_ENABLED; break; /* * Default is not to change state. */ } p->lmi_state = sp->state; putnext(sp->rq, mp); return(0); } rare(); return(-ENOBUFS);}/* * LMI_ENABLE_CON * --------------------------------------------- */static intlmi_enable_con(sdl_t *sp){ mblk_t *mp; lmi_enable_con_t *p; ensure( sp , return(-EFAULT) ); ensure( sp->state == LMI_ENABLE_PENDING, return(-EFAULT) ); if ( canputnext(sp->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 = sp->state = LMI_ENABLED; putnext(sp->rq, mp); return(0); } rare(); return(-ENOBUFS); } rare(); return(-EBUSY);}/* * LMI_DISABLE_CON * --------------------------------------------- */static intlmi_disable_con(sdl_t *sp){ mblk_t *mp; lmi_disable_con_t *p; ensure( sp , return(-EFAULT) ); ensure( sp->state == LMI_DISABLE_PENDING, return(-EFAULT) ); if ( canputnext(sp->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 = sp->state = LMI_DISABLED; putnext(sp->rq, mp); return(0); } rare(); return(-ENOBUFS); } rare(); return(-EBUSY);}#if 0/* * LMI_OPTMGMT_ACK * --------------------------------------------- */static intlmi_optmgmt_ack(sdl_t *sp, ulong flags, void *opt_ptr, size_t opt_len){ mblk_t *mp; lmi_optmgmt_ack_t *p; ensure( sp , return(-EFAULT) ); 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(sp->rq, mp); return(0); } rare(); return(-ENOBUFS);}#endif/* * LMI_ERROR_IND * --------------------------------------------- */static intlmi_error_ind(sdl_t *sp, long err){ mblk_t *mp; lmi_error_ind_t *p; ensure( sp , return(-EFAULT) ); 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 = sp->state; putnext(sp->rq, mp); return(0); } rare(); return(-ENOBUFS);}/* * LMI_STATS_IND * --------------------------------------------- */static intlmi_stats_ind(sdl_t *sp, ulong interval, ulong timestamp){ mblk_t *mp; lmi_stats_ind_t *p; ensure( sp , return(-EFAULT) ); if ( bcanputnext(sp->rq, mp->b_band) ) { 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(sp->rq, mp); return(0); } rare(); return(-ENOBUFS); } seldom(); return(-EBUSY);}/* * LMI_EVENT_IND * --------------------------------------------- */static intlmi_event_ind(sdl_t *sp, ulong oid, ulong severity, ulong timestamp){ mblk_t *mp; lmi_event_ind_t *p; ensure( sp , return(-EFAULT) ); if ( bcanputnext(sp->rq, mp->b_band) ) { if ( (mp = allocb(sizeof(*p), 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 = timestamp; p->lmi_severity = severity; putnext(sp->rq, mp); return(0); } rare(); return(-ENOBUFS); } seldom(); return(-EBUSY);}/* * SDL_DAEDR_RECEIVED_BITS_IND * --------------------------------------------- */static intsdl_read(sdl_t *sp, mblk_t *dp){ ensure( sp , return(-EFAULT) ); if ( canputnext(sp->rq) ) { putnext(sp->rq, dp); return(0); } seldom(); return(-EBUSY);}#if 0static intsdl_daedr_received_bits_ind(sdl_t *sp, ulong count, mblk_t *dp){ mblk_t *mp; sdl_daedr_received_bits_ind_t *p; ensure( sp , return(-EFAULT) ); if ( canputnext(sp->rq) ) { if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) { mp->b_datap->db_type = M_PROTO; p = ((sdl_daedr_received_bits_ind_t *)mp->b_wptr)++; p->sdl_primitive = SDL_DAEDR_RECEIVED_BITS_IND; p->sdl_count = count; putnext(sp->rq, mp); return(0); } rare(); return(-ENOBUFS); } seldom(); return(-EBUSY);}#endif/* * SDL_DAEDR_CORRECT_SU_IND * --------------------------------------------- */static intsdl_daedr_correct_su_ind(sdl_t *sp, ulong count){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -