?? timod.c
字號:
/***************************************************************************** @(#) timod.c,v LiS-2_16_18-8(1.1.1.2.4.2) 2004/01/29 14:11:44 ----------------------------------------------------------------------------- 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 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). ----------------------------------------------------------------------------- Commercial licensing and support of this software is available from OpenSS7 Corporation at a fee. See http://www.openss7.com/ ----------------------------------------------------------------------------- Last Modified 2004/01/29 14:11:44 by brian *****************************************************************************/#ident "@(#) timod.c,v LiS-2_16_18-8(1.1.1.2.4.2) 2004/01/29 14:11:44"static char const ident[] = "timod.c,v LiS-2_16_18-8(1.1.1.2.4.2) 2004/01/29 14:11:44";/* * This is TIMOD an XTI library interface module for TPI Version 2 transport * service providers supporting the T_ADDR_REQ primitive. * * This module is suitable for supporting both Ole Husgaard's XTI library as * (that does not use T_GETPROTADDR) or the more complete OpenSS7 libxnet XTI * library that comes with the Linux Fast-STREAMS release. The libxnet * library has superior syncrhonization across a fork() and provides a * conforming t_sync() library call. */#if defined(_LIS_SOURCE) && !defined(MODULE)# error ****# error **** timod can only compile as a module under LiS.# error **** This is normally because LiS has been grossly misconfigured.# error **** Report bugs to <bugs@openss7.org>.# error ****#endif#include <linux/config.h>#include <linux/version.h>#ifdef CONFIG_MODVERSIONS#include <linux/modversions.h>#endif#include <linux/module.h>#include <linux/init.h>#include <sys/stream.h>#include <sys/stropts.h>#include <sys/cmn_err.h>/* These are for TPI definitions */#include <sys/tihdr.h>#include <sys/timod.h>#define TIMOD_DESCRIP "UNIX SYSTEM V RELEASE 4.2 FAST STREAMS FOR LINUX"#define TIMOD_COPYRIGHT "Copyright (c) 1997-2004 OpenSS7 Corporation. All Rights Reserved."#define TIMOD_REVISION "LfS timod.c,v LiS-2_16_18-8(1.1.1.2.4.2) 2004/01/29 14:11:44"#define TIMOD_DEVICE "SVR 4.2 STREAMS XTI Library Module for TLI Devices (TIMOD)"#define TIMOD_CONTACT "Brian Bidulock <bidulock@openss7.org>"#define TIMOD_LICENSE "GPL"#define TIMOD_BANNER TIMOD_DESCRIP "\n" \ TIMOD_COPYRIGHT "\n" \ TIMOD_REVISION "\n" \ TIMOD_DEVICE "\n" \ TIMOD_CONTACT "\n"#define TIMOD_SPLASH TIMOD_DEVICE " - " \ TIMOD_REVISION "\n"MODULE_AUTHOR(TIMOD_CONTACT);MODULE_DESCRIPTION(TIMOD_DESCRIP);MODULE_SUPPORTED_DEVICE(TIMOD_DEVICE);MODULE_LICENSE(TIMOD_LICENSE);#ifndef TIMOD_MOD_NAME# ifdef CONFIG_STREAMS_TIMOD_NAME# define TIMOD_MOD_NAME CONFIG_STREAMS_TIMOD_NAME# else# define TIMOD_MOD_NAME "timod"# endif#endif#ifndef TIMOD_MOD_ID# ifdef CONFIG_STREAMS_TIMOD_MODID# define TIMOD_MOD_ID CONFIG_STREAMS_TIMOD_MODID# else# define TIMOD_MOD_ID 0# endif#endifstatic modID_t modid = TIMOD_MOD_ID;MODULE_PARM(modid, "b");MODULE_PARM_DESC(modid, "Module ID for TIMOD.");static struct module_info timod_minfo = { mi_idnum:TIMOD_MOD_ID, /* Module ID number */ mi_idname:TIMOD_MOD_NAME, /* Module name */ mi_minpsz:0, /* Min packet size accepted */ mi_maxpsz:INFPSZ, /* Max packet size accepted */ mi_hiwat:1, /* Hi water mark */ mi_lowat:0, /* Lo water mark */};static int timod_open(queue_t *, dev_t *, int, int, cred_t *);static int timod_close(queue_t *, int, cred_t *);static int timod_rput(queue_t *, mblk_t *);static int timod_wput(queue_t *, mblk_t *);static struct qinit timod_rinit = { qi_putp:timod_rput, /* Read put (message from below) */ qi_qopen:timod_open, /* Each open */ qi_qclose:timod_close, /* Last close */ qi_minfo:&timod_minfo, /* Information */};static struct qinit timod_winit = { qi_putp:timod_wput, /* Write put (message from above) */ qi_minfo:&timod_minfo, /* Information */};static struct streamtab timod_info = { st_rdinit:&timod_rinit, /* Upper read queue */ st_wrinit:&timod_winit, /* Upper write queue */};/* * ------------------------------------------------------------------------- * * Private Datastructure ctors and dtors * * ------------------------------------------------------------------------- */struct timod { queue_t *rq; /* module read queue */ queue_t *wq; /* module write queue */ queue_t *hq; /* stream head read queue */ ulong state; /* module state */ ulong oldstate; /* module state */ ulong flags; /* module flags */ mblk_t *iocblk; /* ioctl being processed */ ulong qlen; /* bind ack queue length */ ulong cons; /* outstanding connection indications */};static kmem_cache_t *timod_priv_cachep = NULL;static inttimod_init_caches(void){ if (!timod_priv_cachep && !(timod_priv_cachep = kmem_cache_create(TIMOD_MOD_NAME, sizeof(struct timod), 0, SLAB_HWCACHE_ALIGN, NULL, NULL))) { cmn_err(CE_WARN, "%s: %s: Cannot allocate timod_priv_cachep", TIMOD_MOD_NAME, __FUNCTION__); return (-ENOMEM); } return (0);}static voidtimod_term_caches(void){ if (timod_priv_cachep) { if (kmem_cache_destroy(timod_priv_cachep)) cmn_err(CE_WARN, "%s: %s: did not destroy timod_priv_cachep", TIMOD_MOD_NAME, __FUNCTION__); } return;}static struct timod *timod_alloc_priv(queue_t *q){ struct timod *priv; if ((priv = kmem_cache_alloc(timod_priv_cachep, SLAB_ATOMIC))) { bzero(priv, sizeof(*priv)); priv->rq = q; priv->wq = WR(q); priv->hq = q->q_next; priv->state = TS_UNBND; /* assume we are in the correct initial state */ priv->oldstate = -1UL; priv->flags = 0; priv->qlen = 0; priv->cons = 0; /* we are a module with no service routine so our hiwat, lowat shouldn't matter; however, our minpsz, maxpsz do because we are the first queue under the stream head. We do not want to alter the characteristics of the transport packet sizes so we copy them here. This will allow the stream head to exhibit the same behaviour as before we were pushed. */ priv->wq->q_minpsz = priv->wq->q_next->q_minpsz; priv->wq->q_maxpsz = priv->wq->q_next->q_maxpsz; q->q_ptr = WR(q)->q_ptr = priv; } return (priv);}static voidtimod_free_priv(queue_t *q){ struct timod *priv; if ((priv = (typeof(priv)) q->q_ptr)) { q->q_ptr = WR(q)->q_ptr = NULL; priv->rq = NULL; priv->wq = NULL; priv->hq = NULL; priv->state = -1UL; priv->oldstate = -1UL; priv->flags = 0; priv->qlen = 0; priv->cons = 0; if (priv->iocblk) freemsg(xchg(&priv->iocblk, NULL)); kmem_cache_free(timod_priv_cachep, priv); } return;}static intsplit_buffer(mblk_t *mp, int offset){ unsigned char *ptr = mp->b_rptr + offset; if (ptr > mp->b_wptr) return (-EINVAL); if (ptr < mp->b_wptr) { mblk_t *dp; if ((dp = copyb(mp))) { dp->b_datap->db_type = M_DATA; dp->b_rptr += offset; mp->b_datap->db_type = M_PROTO; mp->b_wptr = ptr; linkb(mp, dp); return (0); } return (-ENOSR); } mp->b_datap->db_type = M_PROTO; return (0);}/* * ------------------------------------------------------------------------- * * PUT routine * * ------------------------------------------------------------------------- */static inttimod_rput(queue_t *q, mblk_t *mp){ struct timod *priv = q->q_ptr;#if defined _LIS_SOURCE if (q->q_next == NULL || OTHER(q)->q_next == NULL) { cmn_err(CE_WARN, "%s: %s: LiS pipe bug: called with NULL q->q_next pointer", TIMOD_MOD_NAME, __FUNCTION__); freemsg(mp); return (0); }#endif /* defined _LIS_SOURCE */ switch (mp->b_datap->db_type) { union T_primitives *p; struct iocblk *ioc; mblk_t *dp; case M_PCPROTO: case M_PROTO: p = (typeof(p)) mp->b_rptr; if (!(dp = xchg(&priv->iocblk, NULL))) goto pass_along; /* we are expecting a response, but only intercept the expected response, pass along others */ ioc = (typeof(ioc)) dp->b_rptr; switch (p->type) { case T_OK_ACK: switch (ioc->ioc_cmd) { case O_TI_UNBIND: case TI_UNBIND: priv->state = TS_UNBND; priv->qlen = 0; goto ack_it;#ifdef TI_ACCEPT case TI_ACCEPT:#endif case TI_SETMYNAME: switch (priv->state) { case TS_WACK_CRES: /* but could be TS_DATA_XFER for same stream connect */ priv->state = (priv->cons && --priv->cons > 0) ? TS_WRES_CIND : TS_IDLE; break; case TS_WACK_DREQ7: priv->state = (priv->cons && --priv->cons > 0) ? TS_WRES_CIND : TS_IDLE; break; } goto ack_it;#ifdef TI_CONNECT case TI_CONNECT:#endif case TI_SETPEERNAME: switch (priv->state) { case TS_WACK_CREQ: priv->state = TS_WCON_CREQ; break; case TS_WACK_DREQ6: case TS_WACK_DREQ9: case TS_WACK_DREQ10: case TS_WACK_DREQ11: priv->state = TS_IDLE; break; } priv->state = TS_WCON_CREQ; goto ack_it;#ifdef TI_DISCONNECT case TI_DISCONNECT: priv->state = TS_IDLE; goto ack_it;#endif } break; case T_INFO_ACK: switch (ioc->ioc_cmd) { case O_TI_GETINFO: case TI_GETINFO: priv->state = priv->oldstate; goto ack_it; } break; case T_BIND_ACK: switch (ioc->ioc_cmd) { case O_TI_BIND: case TI_BIND: priv->state = TS_IDLE; priv->qlen = p->bind_ack.CONIND_number; goto ack_it; } break; case T_OPTMGMT_ACK: switch (ioc->ioc_cmd) { case O_TI_OPTMGMT: case TI_OPTMGMT: priv->state = priv->oldstate; goto ack_it; } break; case T_ADDR_ACK: switch (ioc->ioc_cmd) {#ifdef TI_GETPROTADDR case TI_GETPROTADDR:#endif case TI_GETADDRS: case TI_GETMYNAME: case TI_GETPEERNAME: priv->state = priv->oldstate; goto ack_it; } break;#ifdef T_CAPABILITY_ACK case T_CAPABILITY_ACK: switch (ioc->ioc_cmd) { case TI_CAPABILITY: priv->state = priv->oldstate; goto ack_it; } break;#endif case T_ERROR_ACK: priv->state = priv->oldstate; dp->b_datap->db_type = M_IOCACK; linkb(dp, mp); ioc->ioc_count = mp->b_wptr - mp->b_rptr; ioc->ioc_error = 0; ioc->ioc_rval = (p->error_ack.UNIX_error << 8) | p->error_ack.TLI_error; if (ioc->ioc_rval == 0 || ioc->ioc_rval == TSYSERR) ioc->ioc_rval = (EINVAL << 8) | TSYSERR; putnext(q, dp); return (0); ack_it: dp->b_datap->db_type = M_IOCACK; linkb(dp, mp); ioc->ioc_count = mp->b_wptr - mp->b_rptr; ioc->ioc_error = 0; ioc->ioc_rval = 0; putnext(q, dp); return (0); } /* not expecting anything, but do state tracking */ pass_along: switch (p->type) { case T_CONN_IND: priv->oldstate = priv->state; priv->cons++; priv->state = TS_WRES_CIND; break; case T_CONN_CON: priv->oldstate = priv->state; priv->state = TS_DATA_XFER; break; case T_DISCON_IND: priv->oldstate = priv->state; if (priv->cons && --priv->cons) { priv->state = TS_WRES_CIND; break; } priv->state = TS_IDLE; break; case T_DATA_IND: priv->oldstate = priv->state; priv->state = TS_DATA_XFER; break; case T_EXDATA_IND: priv->oldstate = priv->state; priv->state = TS_DATA_XFER; break; case T_INFO_ACK: priv->state = priv->oldstate; break; case T_BIND_ACK: priv->oldstate = priv->state; priv->qlen = p->bind_ack.CONIND_number; priv->state = TS_IDLE; break; case T_ERROR_ACK: priv->state = priv->oldstate; break; case T_OK_ACK: switch ((priv->oldstate = priv->state)) { case TS_WACK_UREQ: priv->state = TS_UNBND; break; case TS_WACK_CREQ: priv->state = TS_WCON_CREQ; break; case TS_WACK_CRES: /* FIXME: depends */ priv->state = TS_DATA_XFER; break; case TS_WACK_DREQ6: case TS_WACK_DREQ9: case TS_WACK_DREQ10: case TS_WACK_DREQ11: priv->state = TS_IDLE; break; case TS_WACK_DREQ7: if (priv->cons && --priv->cons) { priv->state = TS_WRES_CIND; break; } priv->state = TS_IDLE; break; } break; case T_UNITDATA_IND: priv->oldstate = priv->state; priv->state = TS_IDLE; break; case T_UDERROR_IND: priv->oldstate = priv->state; priv->state = TS_IDLE; break; case T_OPTMGMT_ACK: priv->state = priv->oldstate; break; case T_ORDREL_IND: switch ((priv->oldstate = priv->state)) { case TS_DATA_XFER: priv->state = TS_WIND_ORDREL; break; case TS_WIND_ORDREL: priv->state = TS_IDLE; break; } break; case T_ADDR_ACK: priv->state = priv->oldstate; break;#ifdef T_CAPABILITY_ACK case T_CAPABILITY_ACK: priv->state = priv->oldstate; break;#endif } break; case M_ERROR: case M_HANGUP: priv->oldstate = -1UL; priv->state = -1UL; break; } putnext(q, mp); return (0);}static inttimod_wput(queue_t *q, mblk_t *mp){ struct timod *priv = q->q_ptr;#if defined _LIS_SOURCE if (q->q_next == NULL || OTHER(q)->q_next == NULL) { cmn_err(CE_WARN, "%s: %s: LiS pipe bug: called with NULL q->q_next pointer", TIMOD_MOD_NAME, __FUNCTION__); freemsg(mp); return (0); }#endif /* defined _LIS_SOURCE */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -