?? mtp_tpi.c
字號:
/***************************************************************************** @(#) mtp_tpi.c,v openss7-0_9_2_E(0.9.2.22) 2007/02/26 07:25:40 ----------------------------------------------------------------------------- Copyright (c) 2001-2007 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; version 2 of the License. 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 2007/02/26 07:25:40 by brian ----------------------------------------------------------------------------- mtp_tpi.c,v Revision 0.9.2.22 2007/02/26 07:25:40 brian - synchronizing changes Revision 0.9.2.21 2007/02/17 02:49:17 brian - first clean recompile of MTP modules on LFS Revision 0.9.2.20 2007/02/14 14:09:12 brian - broad changes updating support for SS7 MTP and M3UA Revision 0.9.2.19 2007/02/13 07:55:43 brian - working up MTP and UAs Revision 0.9.2.18 2006/05/08 11:01:01 brian - new compilers mishandle postincrement of cast pointers Revision 0.9.2.17 2006/03/07 01:10:50 brian - binary compatible callouts Revision 0.9.2.16 2006/03/04 13:00:16 brian - FC4 x86_64 gcc 4.0.4 2.6.15 changes *****************************************************************************/#ident "@(#) mtp_tpi.c,v openss7-0_9_2_E(0.9.2.22) 2007/02/26 07:25:40"static char const ident[] = "mtp_tpi.c,v openss7-0_9_2_E(0.9.2.22) 2007/02/26 07:25:40";/* * This is a MTP TPI module which can be pushed over an MTPI (Message Transfer Part Interface) * stream to effect a TPI interface to the MTP. This module is intended to be used by application * programs or by upper modules that expect a TPI connectionless service provider. */#define _LFS_SOURCE 1#define _SVR4_SOURCE 1#define _MPS_SOURCE 1#define _SUN_SOURCE 1#include <sys/os7/compat.h>#include <sys/strsun.h>#undef DB_TYPE#define DB_TYPE(mp) ((mp)->b_datap->db_type)#include <linux/socket.h>#include <ss7/lmi.h>#include <ss7/lmi_ioctl.h>#include <ss7/mtpi.h>#include <ss7/mtpi_ioctl.h>#include <sys/tihdr.h>#include <sys/xti.h>#include <sys/xti_mtp.h>#define MTP_TPI_DESCRIP "SS7 Message Transfer Part (MTP) TPI STREAMS MODULE."#define MTP_TPI_REVISION "LfS mtp_tpi.c,v openss7-0_9_2_E(0.9.2.22) 2007/02/26 07:25:40"#define MTP_TPI_COPYRIGHT "Copyright (c) 1997-2007 OpenSS7 Corporation. All Rights Reserved."#define MTP_TPI_DEVICE "Part of the OpenSS7 Stack for Linux Fast-STREAMS."#define MTP_TPI_CONTACT "Brian Bidulock <bidulock@openss7.org>"#define MTP_TPI_LICENSE "GPL"#define MTP_TPI_BANNER MTP_TPI_DESCRIP "\n" \ MTP_TPI_REVISION "\n" \ MTP_TPI_COPYRIGHT "\n" \ MTP_TPI_DEVICE "\n" \ MTP_TPI_CONTACT "\n"#define MTP_TPI_SPLASH MTP_TPI_DESCRIP "\n" \ MTP_TPI_REVISION "\n"#ifdef LINUXMODULE_AUTHOR(MTP_TPI_CONTACT);MODULE_DESCRIPTION(MTP_TPI_DESCRIP);MODULE_SUPPORTED_DEVICE(MTP_TPI_DEVICE);#ifdef MODULE_LICENSEMODULE_LICENSE(MTP_TPI_LICENSE);#endif /* MODULE_LICENSE */#if defined MODULE_ALIASMODULE_ALIAS("streams-mtp_tpi");#endif#endif /* LINUX */#ifdef LFS#define MTP_TPI_MOD_ID CONFIG_STREAMS_MTP_TPI_MODID#define MTP_TPI_MOD_NAME CONFIG_STREAMS_MTP_TPI_NAME#endif#define MOD_ID MTP_TPI_MOD_ID#define MOD_NAME MTP_TPI_MOD_NAME#ifdef MODULE#define MOD_BANNER MTP_TPI_BANNER#else /* MODULE */#define MOD_BANNER MTP_TPI_SPLASH#endif /* MODULE *//* * ========================================================================= * * MTP-TPI Private Structure * * ========================================================================= */typedef struct mtp { queue_t *rq; /* RD queue */ queue_t *wq; /* WR queue */ cred_t cred; struct mtp_addr src; /* srce address */ struct mtp_addr dst; /* dest address */ size_t src_len; size_t dst_len; uint coninds; struct { mtp_ulong pvar; mtp_ulong popt; mtp_ulong sls; /* default options */ mtp_ulong mp; /* default options */ mtp_ulong debug; /* default options */ mtp_ulong sls_mask; } options; struct T_info_ack prot;} mtp_t;#define MTP_PRIV(__q) ((struct mtp *)(__q)->q_ptr)static caddr_t mtp_opens = NULL;#define STRLOGST 1 /* log Stream state transitions */#define STRLOGTO 2 /* log Stream timeouts */#define STRLOGRX 3 /* log Stream primitives received */#define STRLOGTX 4 /* log Stream primitives issued */#define STRLOGTE 5 /* log Stream timer events */#define STRLOGDA 6 /* log Stream data *//* * ========================================================================= * * ADDRESS Handling * * ========================================================================= */static inline fastcall size_tt_addr_size(struct mtp_addr *add){ size_t len = 0; if (add) { len = sizeof(struct sockaddr_mtp); } return (len);}static inline fastcall voidt_build_addr(struct mtp_addr *add, unsigned char *p){ if (add) { struct sockaddr_mtp *sa = (typeof(sa)) p; sa->mtp_family = 0; sa->mtp_ni = add->ni; sa->mtp_si = add->si; sa->mtp_pc = add->pc; }}/* * ========================================================================= * * OPTION Handling * * ========================================================================= */typedef struct mtp_opts { uint flags; /* success flags */ mtp_ulong *sls; mtp_ulong *mp; mtp_ulong *debug;} mtp_opts_t;struct { mtp_ulong sls; mtp_ulong mp; mtp_ulong debug;} opt_defaults = {0, 0, 0};#define _T_ALIGN_SIZEOF(s) \ ((sizeof((s)) + _T_ALIGN_SIZE - 1) & ~(_T_ALIGN_SIZE - 1))static inline fastcall size_tt_opts_size(struct mtp_opts *ops){ size_t len = 0; if (ops) { const size_t hlen = sizeof(struct t_opthdr); /* 32 bytes */ if (ops->sls) len += hlen + _T_ALIGN_SIZEOF(*(ops->sls)); if (ops->mp) len += hlen + _T_ALIGN_SIZEOF(*(ops->mp)); if (ops->debug) len += hlen + _T_ALIGN_SIZEOF(*(ops->debug)); } return (len);}static inline fastcall voidt_build_opts(struct mtp_opts *ops, unsigned char *p){ if (ops) { struct t_opthdr *oh; const size_t hlen = sizeof(struct t_opthdr); if (ops->sls) { oh = (typeof(oh)) p++; oh->len = hlen + sizeof(*(ops->sls)); oh->level = T_SS7_MTP; oh->name = T_MTP_SLS; oh->status = (ops->flags & (1 << T_MTP_SLS)) ? T_SUCCESS : T_FAILURE; *((typeof(ops->sls)) p) = *(ops->sls); p += _T_ALIGN_SIZEOF(*ops->sls); } if (ops->mp) { oh = (typeof(oh)) p++; oh->len = hlen + sizeof(*(ops->mp)); oh->level = T_SS7_MTP; oh->name = T_MTP_MP; oh->status = (ops->flags & (1 << T_MTP_MP)) ? T_SUCCESS : T_FAILURE; *((typeof(ops->mp)) p) = *(ops->mp); p += _T_ALIGN_SIZEOF(*ops->mp); } if (ops->debug) { oh = (typeof(oh)) p++; oh->len = hlen + sizeof(*(ops->debug)); oh->level = T_SS7_MTP; oh->name = T_MTP_DEBUG; oh->status = (ops->flags & (1 << T_MTP_DEBUG)) ? T_SUCCESS : T_FAILURE; *((typeof(ops->debug)) p) = *(ops->debug); p += _T_ALIGN_SIZEOF(*ops->debug); } }}static intt_parse_opts(struct mtp_opts *ops, unsigned char *op, size_t len){ struct t_opthdr *oh; for (oh = _T_OPT_FIRSTHDR_OFS(op, len, 0); oh; oh = _T_OPT_NEXTHDR_OFS(op, len, oh, 0)) { switch (oh->level) { case T_SS7_MTP: switch (oh->name) { case T_MTP_SLS: ops->sls = (void *) _T_OPT_DATA_OFS(oh, 0); ops->flags |= (1 << T_MTP_SLS); continue; case T_MTP_MP: ops->mp = (void *) _T_OPT_DATA_OFS(oh, 0); ops->flags |= (1 << T_MTP_MP); continue; case T_MTP_DEBUG: ops->debug = (void *) _T_OPT_DATA_OFS(oh, 0); ops->flags |= (1 << T_MTP_DEBUG); continue; } } } if (oh) return (TBADOPT); return (0);}#if 0static intt_parse_qos(struct mtp_opts *ops, unsigned char *op, size_t len){ fixme(("Write this function\n")); return (-EFAULT);}#endif/* * ========================================================================= * * OPTIONS handling * * ========================================================================= */static intmtp_opt_check(struct mtp *mtp, struct mtp_opts *ops){ if (ops->flags) { ops->flags = 0; if (ops->sls) ops->flags |= (1 << T_MTP_SLS); if (ops->mp) ops->flags |= (1 << T_MTP_MP); if (ops->debug) ops->flags |= (1 << T_MTP_DEBUG); } return (0);}static intmtp_opt_default(struct mtp *mtp, struct mtp_opts *ops){ if (ops) { int flags = ops->flags; ops->flags = 0; if (!flags || ops->sls) { ops->sls = &opt_defaults.sls; ops->flags |= (1 << T_MTP_SLS); } if (!flags || ops->mp) { ops->mp = &opt_defaults.mp; ops->flags |= (1 << T_MTP_MP); } if (!flags || ops->debug) { ops->debug = &opt_defaults.debug; ops->flags |= (1 << T_MTP_DEBUG); } return (0); } swerr(); return (-EFAULT);}static intmtp_opt_current(struct mtp *mtp, struct mtp_opts *ops){ int flags = ops->flags; ops->flags = 0; if (!flags || ops->sls) { ops->sls = &mtp->options.sls; ops->flags |= (1 << T_MTP_SLS); } if (!flags || ops->mp) { ops->mp = &mtp->options.mp; ops->flags |= (1 << T_MTP_MP); } if (!flags || ops->debug) { ops->debug = &mtp->options.debug; ops->flags |= (1 << T_MTP_DEBUG); } return (0);}static intmtp_opt_negotiate(struct mtp *mtp, struct mtp_opts *ops){ if (ops->flags) { ops->flags = 0; if (ops->sls) { mtp->options.sls = *ops->sls; ops->sls = &mtp->options.sls; ops->flags |= (1 << T_MTP_SLS); } if (ops->mp) { mtp->options.mp = *ops->mp; ops->mp = &mtp->options.mp; ops->flags |= (1 << T_MTP_MP); } if (ops->debug) { mtp->options.debug = *ops->debug; ops->debug = &mtp->options.debug; ops->flags |= (1 << T_MTP_DEBUG); } } return (0);}/* * ========================================================================= * * STATE Changes * * ========================================================================= */static const char *mtp_state(mtp_ulong state){ switch (state) { case TS_UNBND: return ("TS_UNBND"); case TS_WACK_BREQ: return ("TS_WACK_BREQ"); case TS_WACK_UREQ: return ("TS_WACK_UREQ"); case TS_IDLE: return ("TS_IDLE"); case TS_WACK_OPTREQ: return ("TS_WACK_OPTREQ"); case TS_WACK_CREQ: return ("TS_WACK_CREQ"); case TS_WCON_CREQ: return ("TS_WCON_CREQ"); case TS_WRES_CIND: return ("TS_WRES_CIND"); case TS_WACK_CRES: return ("TS_WACK_CRES"); case TS_DATA_XFER: return ("TS_DATA_XFER"); case TS_WIND_ORDREL: return ("TS_WIND_ORDREL"); case TS_WREQ_ORDREL: return ("TS_WREQ_ORDREL"); case TS_WACK_DREQ6: return ("TS_WACK_DREQ6"); case TS_WACK_DREQ7: return ("TS_WACK_DREQ7"); case TS_WACK_DREQ9: return ("TS_WACK_DREQ9"); case TS_WACK_DREQ10: return ("TS_WACK_DREQ10"); case TS_WACK_DREQ11: return ("TS_WACK_DREQ11"); case TS_NOSTATES: return ("TS_UNINIT"); default: return ("????"); }}static mtp_ulongmtp_set_state(struct mtp *mtp, mtp_ulong newstate){ mtp_ulong oldstate = mtp->prot.CURRENT_state; if (newstate != oldstate) { mi_strlog(mtp->rq, STRLOGST, SL_TRACE, "%s <- %s", mtp_state(newstate), mtp_state(oldstate)); mtp->prot.CURRENT_state = newstate; } return (oldstate);}static mtp_ulongmtp_get_state(struct mtp *mtp){ return mtp->prot.CURRENT_state;}static mtp_ulongmtp_get_statef(struct mtp *mtp){ return (1 << mtp_get_state(mtp));}static mtp_ulongmtp_chk_state(struct mtp *mtp, mtp_ulong mask){ return (mtp_get_statef(mtp) & mask);}static mtp_ulongmtp_not_state(struct mtp *mtp, mtp_ulong mask)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -