?? sdl.c
字號:
/***************************************************************************** @(#) sdl.c,v openss7-0_9_2_E(0.9.2.14) 2006/04/24 05:01:01 ----------------------------------------------------------------------------- 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/04/24 05:01:01 by brian *****************************************************************************/#ident "@(#) sdl.c,v openss7-0_9_2_E(0.9.2.14) 2006/04/24 05:01:01"static char const ident[] = "sdl.c,v openss7-0_9_2_E(0.9.2.14) 2006/04/24 05:01:01";/* * This is an SDL (Signalling Data Link) kernel module which provides the * capabilities of the SDL to any pipe. Its principal purpose is testing. */#include <sys/os7/compat.h>#include <ss7/lmi.h>#include <ss7/lmi_ioctl.h>#include <ss7/sdli.h>#include <ss7/sdli_ioctl.h>#define SDL_DESCRIP "SS7/SDL: (Signalling Data Link) STREAMS MODULE."#define SDL_REVISION "OpenSS7 sdl.c,v openss7-0_9_2_E(0.9.2.14) 2006/04/24 05:01:01"#define SDL_COPYRIGHT "Copyright (c) 1997-2002 OpenSS7 Corporation. All Rights Reserved."#define SDL_DEVICE "Supports STREAMS pipes."#define SDL_CONTACT "Brian Bidulock <bidulock@openss7.org>"#define SDL_LICENSE "GPL"#define SDL_BANNER SDL_DESCRIP "\n" \ SDL_REVISION "\n" \ SDL_COPYRIGHT "\n" \ SDL_DEVICE "\n" \ SDL_CONTACT "\n"#define SDL_SPLASH SDL_DEVICE " - " \ SDL_REVISION "\n"#ifdef LINUXMODULE_AUTHOR(SDL_CONTACT);MODULE_DESCRIPTION(SDL_DESCRIP);MODULE_SUPPORTED_DEVICE(SDL_DEVICE);#ifdef MODULE_LICENSEMODULE_LICENSE(SDL_LICENSE);#endif /* MODULE_LICENSE */#if defined MODULE_ALIASMODULE_ALIAS("streams-sdl");#endif#endif /* LINUX */#ifdef LFS#define SDL_MOD_ID CONFIG_STREAMS_SDL_MODID#define SDL_MOD_NAME CONFIG_STREAMS_SDL_NAME#endif/* * ======================================================================= * * STREAMS Definitions * * ======================================================================= */#define MOD_ID SDL_MOD_ID#define MOD_NAME SDL_MOD_NAME#ifdef MODULE#define MOD_BANNER SDL_BANNER#else /* MODULE */#define MOD_BANNER SDL_SPLASH#endif /* MODULE */STATIC struct module_info sdl_rinfo = { .mi_idnum = MOD_ID, /* Module ID number */ .mi_idname = MOD_NAME, /* Module name */ .mi_minpsz = 1, /* Min packet size accepted */ .mi_maxpsz = 128, /* Max packet size accepted */ .mi_hiwat = 1, /* Hi water mark */ .mi_lowat = 0, /* Lo water mark */};STATIC struct module_info sdl_winfo = { .mi_idnum = MOD_ID, /* Module ID number */ .mi_idname = MOD_NAME, /* Module name */ .mi_minpsz = 1, /* Min packet size accepted */ .mi_maxpsz = 280, /* Max packet size accepted */ .mi_hiwat = 1, /* Hi water mark */ .mi_lowat = 0 /* Lo water mark */};STATIC streamscall int sdl_open(queue_t *, dev_t *, int, int, cred_t *);STATIC streamscall int sdl_close(queue_t *, int, cred_t *);STATIC struct qinit sdl_rinit = { .qi_putp = ss7_oput, /* Read put (message from below) */ .qi_qopen = sdl_open, /* Each open */ .qi_qclose = sdl_close, /* Last close */ .qi_minfo = &sdl_rinfo, /* Information */};STATIC struct qinit sdl_winit = { .qi_putp = ss7_iput, /* Write put (message from above) */ .qi_minfo = &sdl_winfo, /* Information */};STATIC struct streamtab sdlinfo = { .st_rdinit = &sdl_rinit, /* Upper read queue */ .st_wrinit = &sdl_winit, /* Upper write queue */};/* * ======================================================================== * * Private structure * * ======================================================================== */typedef struct sdl { STR_DECLARATION (struct sdl); /* stream declaration */ unsigned long timestamp; /* next tick timestamp */ unsigned long bytecount; /* bytes send within tick */ unsigned long tickbytes; /* bytes per tick */ lmi_option_t option; /* LMI protocol and variant options */ sdl_timers_t timers; /* SDL protocol timers */ 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 */ lmi_sta_t statsp; /* SDL statistics periods */} sdl_t;#define SDL_PRIV(__q) ((struct sdl *)(__q)->q_ptr)struct sdl *sdl_opens = NULL;STATIC struct sdl *sdl_alloc_priv(queue_t *, struct sdl **, dev_t *, cred_t *);STATIC struct sdl *sdl_get(struct sdl *);STATIC void sdl_put(struct sdl *);STATIC void sdl_free_priv(queue_t *);struct lmi_option lmi_default = { pvar:SS7_PVAR_ITUT_96, popt:0,};struct sdl_config sdl_default = { ifflags:0, iftype:SDL_TYPE_NONE, ifrate:64000, ifgtype:SDL_GTYPE_NONE, ifgrate:0, ifmode:SDL_MODE_PEER, ifgmode:SDL_MODE_NONE, ifgcrc:SDL_GCRC_NONE, ifclock:SDL_CLOCK_SHAPER, ifcoding:SDL_CODING_NONE, ifframing:SDL_FRAMING_NONE, ifleads:0, ifalarms:0, ifrxlevel:0, iftxlevel:0, ifsync:0, ifsyncsrc:{0, 0, 0, 0},};/* * ======================================================================== * * PRIMITIVES * * ======================================================================== *//* * ------------------------------------------------------------------------ * * Primitives sent upstream * * ------------------------------------------------------------------------ *//* * M_ERROR * ----------------------------------- */STATIC INLINE intm_error(queue_t *q, struct sdl *s, 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; s->i_state = LMI_UNUSABLE; printd(("%s: %p: <- M_ERROR\n", MOD_NAME, s)); putnext(s->oq, mp); return (QR_DONE); } rare(); return (-ENOBUFS);}#if 0/* * M_HANGUP * ----------------------------------- */STATIC INLINE intm_hangup(queue_t *q, struct sdl *s, int err){ mblk_t *mp; if ((mp = ss7_allocb(q, 2, BPRI_MED))) { mp->b_datap->db_type = M_HANGUP; *(mp->b_wptr)++ = err < 0 ? -err : err; *(mp->b_wptr)++ = err < 0 ? -err : err; s->i_state = LMI_UNUSABLE; printd(("%s: %p: <- M_HANGUP\n", MOD_NAME, s)); putnext(s->oq, mp); return (QR_DONE); } rare(); return (-ENOBUFS);}#endif/* * LMI_INFO_ACK * ----------------------------------- */STATIC INLINE intlmi_info_ack(queue_t *q, struct sdl *s){ mblk_t *mp; lmi_info_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_INFO_ACK; p->lmi_version = 1; p->lmi_state = s->i_state; p->lmi_max_sdu = 64; p->lmi_min_sdu = 8; p->lmi_header_len = 0; p->lmi_ppa_style = LMI_STYLE1; /* only STYLE1 for modules */ printd(("%s: %p: <- LMI_INFO_ACK\n", MOD_NAME, s)); putnext(s->oq, mp); return (QR_DONE); } rare(); return (-ENOBUFS);}/* * LMI_OK_ACK * ----------------------------------- */STATIC INLINE intlmi_ok_ack(queue_t *q, struct sdl *s, 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; switch (s->i_state) { case LMI_ATTACH_PENDING: s->i_state = LMI_DISABLED; break; case LMI_DETACH_PENDING: s->i_state = LMI_UNATTACHED; break; } p->lmi_state = s->i_state; printd(("%s: %p: <- LMI_OK_ACK\n", MOD_NAME, s)); putnext(s->oq, mp); return (QR_DONE); } rare(); return (-ENOBUFS);}/* * LMI_ERROR_ACK * ----------------------------------- */STATIC INLINE intlmi_error_ack(queue_t *q, struct sdl *s, long prim, ulong reason, ulong errno){ 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 = errno; p->lmi_reason = reason; p->lmi_error_primitive = prim; switch (s->i_state) { case LMI_ATTACH_PENDING: s->i_state = LMI_UNATTACHED; break; case LMI_DETACH_PENDING: s->i_state = LMI_DISABLED; break; case LMI_ENABLE_PENDING: s->i_state = LMI_DISABLED; break; case LMI_DISABLE_PENDING: s->i_state = LMI_ENABLED; break; default: break; } p->lmi_state = s->i_state; printd(("%s: %p: <- LMI_ERROR_ACK\n", MOD_NAME, s)); putnext(s->oq, mp); return (QR_DONE); } rare(); return (-ENOBUFS);}/* * LMI_ENABLE_CON * ----------------------------------- */STATIC INLINE intlmi_enable_con(queue_t *q, struct sdl *s){ 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; switch (s->i_state) { case LMI_ENABLE_PENDING: s->i_state = LMI_ENABLED; s->timestamp = jiffies; s->bytecount = 0; break; default: swerr(); break; } p->lmi_state = s->i_state; printd(("%s: %p: <- LMI_ENABLE_CON\n", MOD_NAME, s)); putnext(s->oq, mp); return (QR_DONE); } rare(); return (-ENOBUFS);}/* * LMI_DISABLE_CON * ----------------------------------- */STATIC INLINE intlmi_disable_con(queue_t *q, struct sdl *s){ mblk_t *mp; lmi_disable_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_DISABLE_CON; switch (s->i_state) { case LMI_DISABLE_PENDING: s->i_state = LMI_DISABLED; break; default: swerr(); break; } p->lmi_state = s->i_state; printd(("%s: %p: <- LMI_DISABLE_CON\n", MOD_NAME, s)); putnext(s->oq, mp); return (QR_DONE); } rare(); return (-ENOBUFS);}#if 0/* * LMI_OPTMGMT_ACK * ----------------------------------- */STATIC INLINE intlmi_optmgmt_ack(queue_t *q, struct sdl *s, ulong flags, caddr_t opt_ptr, size_t opt_len){ mblk_t *mp; lmi_optmgmt_ack_t *p; if ((mp = ss7_allocb(q, sizeof(*p) + opt_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_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; printd(("%s: %p: <- LMI_OPTMGMT_ACK\n", MOD_NAME, s)); putnext(s->oq, mp); return (QR_DONE); } rare(); return (-ENOBUFS);}/* * LMI_ERROR_IND * ----------------------------------- */STATIC INLINE intlmi_error_ind(queue_t *q, struct sdl *s, long error, long reason){ mblk_t *mp; lmi_error_ind_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_IND; p->lmi_errno = error; p->lmi_reason = reason; p->lmi_state = s->i_state; printd(("%s: %p: <- LMI_ERROR_IND\n", MOD_NAME, s)); putnext(s->oq, mp); return (QR_DONE); } rare(); return (-ENOBUFS);}/* * LMI_STATS_IND * ----------------------------------- */STATIC INLINE intlmi_stats_ind(queue_t *q, struct sdl *s){ mblk_t *mp; lmi_stats_ind_t *p; if ((mp = ss7_allocb(q, sizeof(*p), BPRI_MED))) { mp->b_datap->db_type = M_PROTO; p = (typeof(p)) mp->b_wptr; mp->b_wptr += sizeof(*p); p->lmi_primitive = LMI_STATS_IND; p->lmi_interval = 0; p->lmi_timestamp = jiffies; printd(("%s: %p: <- LMI_STATS_IND\n", MOD_NAME, s)); putnext(s->oq, mp); return (QR_DONE); } rare(); return (-ENOBUFS);}/* * LMI_EVENT_IND * ----------------------------------- */STATIC INLINE intlmi_event_ind(queue_t *q, struct sdl *s, ulong oid, ulong level, caddr_t inf_ptr, size_t inf_len){ mblk_t *mp; lmi_event_ind_t *p; if ((mp = ss7_allocb(q, sizeof(*p) + inf_len, BPRI_MED))) { mp->b_datap->db_type = M_PROTO; p = (typeof(p)) mp->b_wptr; mp->b_wptr += sizeof(*p); p->lmi_primitive = LMI_EVENT_IND; p->lmi_objectid = oid; p->lmi_timestamp = jiffies; p->lmi_severity = level; bcopy(inf_ptr, mp->b_wptr, inf_len); mp->b_wptr += inf_len; printd(("%s: %p: <- LMI_EVENT_IND\n", MOD_NAME, s)); putnext(s->oq, mp); return (QR_DONE); } rare(); return (-ENOBUFS);}/* * SDL_RECEIVED_BITS_IND * ----------------------------------- */STATIC INLINE intsdl_received_bits_ind(queue_t *q, struct sdl *s, mblk_t *dp){ mblk_t *mp; sdl_received_bits_ind_t *p; if ((mp = ss7_allocb(q, sizeof(*p), BPRI_MED))) { mp->b_datap->db_type = M_PROTO; p = (typeof(p)) mp->b_wptr; mp->b_wptr += sizeof(*p); p->sdl_primitive = SDL_RECEIVED_BITS_IND; mp->b_cont = dp; putnext(s->oq, mp); return (QR_ABSORBED); } rare(); return (-ENOBUFS);}/* * SDL_DISCONNECT_IND * ----------------------------------- */STATIC INLINE intsdl_disconnect_ind(queue_t *q, struct sdl *s){ mblk_t *mp; sdl_disconnect_ind_t *p; if ((mp = ss7_allocb(q, sizeof(*p), BPRI_MED))) { mp->b_datap->db_type = M_PCPROTO; p = (typeof(p)) mp->b_wptr;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -