📄 test-q781.c
字号:
/***************************************************************************** @(#) test-q781.c,v SS7AlphaRelease(0.7.8.2) 2001/12/11 15:28:45 ----------------------------------------------------------------------------- Copyright (c) 2001 OpenSS7 Corporation <http://www.openss7.com/> Copyright (c) 1997-2000 Brian F. G. Bidulock <bidulock@dallas.net> All Rights Reserved. Unauthorized distribution or duplication is prohibited. This software and related documentation is protected by copyright and distributed under licenses restricting its use, copying, distribution and decompilation. No part of this software or related documentation may be reproduced in any form by any means without the prior written authorization of the copyright holder, and licensors, if any. The recipient of this document, by its retention and use, warrants that the recipient will protect this information and keep it confidential, and will not disclose the information contained in this document without the written permission of its owner. The author reserves the right to revise this software and documentation for any reason, including but not limited to, conformity with standards promulgated by various agencies, utilization of advances in the state of the technical arts, or the reflection of changes in the design of any techniques, or procedures embodied, described, or referred to herein. The author is under no obligation to provide any feature listed herein. ----------------------------------------------------------------------------- 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 15:28:45 by <bidulock@openss7.org> *****************************************************************************/#ident "@(#) test-q781.c,v SS7AlphaRelease(0.7.8.2) 2001/12/11 15:28:45"static char const ident[] = "test-q781.c,v SS7AlphaRelease(0.7.8.2) 2001/12/11 15:28:45";#include <stropts.h>#include <stdlib.h>#include <unistd.h>#include <sys/ioctl.h>#include <sys/time.h>#include <sys/poll.h>#include <linux/poll.h>#include <stdio.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#include <string.h>#include <ss7/lmi.h>#include <ss7/lmi_ioctl.h>#include <ss7/sdli.h>#include <ss7/sdli_ioctl.h>#include <ss7/devi.h>#include <ss7/devi_ioctl.h>#include <ss7/sdti.h>#include <ss7/sdti_ioctl.h>#include <ss7/sli.h>#include <ss7/sli_ioctl.h>#include <signal.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#define SUCCESS 0#define FAILURE 1#define INCONCLUSIVE -1#define SCRIPTERROR -2#define FFLUSH(stream)/* * ------------------------------------------------------------------------- * * Configuration * * ------------------------------------------------------------------------- */static struct { dev_ulong ifclock; lmi_option_t opt; sdl_config_t sdl;} ptconf;static struct { dev_ulong ifclock; lmi_option_t opt; sdl_config_t sdl; sdt_config_t sdt; sl_config_t sl;} iutconf;/* * ------------------------------------------------------------------------- * * Timer Functions * * ------------------------------------------------------------------------- *//* * Timer values for tests: each timer has a low range (minus error margin) * and a high range (plus error margin). */typedef struct timer_range { long lo; long hi;} timer_range_t;enum { t1 = 0, t2, t3, t4n, t4e, t5, t6, t7, tmax };static timer_range_t timer[tmax] = { { 40000, 50000 }, /* Timer T1 30000 */ { 5000, 150000 }, /* Timer T2 5000 */ { 1000, 1500 }, /* Timer T3 100 */ { 7500, 9500 }, /* Timer T4n 3000 */ { 400, 600 }, /* Timer T4e 50 */ { 125, 125 }, /* Timer T5 10 */ { 3000, 6000 }, /* Timer T6 300 */ { 500, 2000 } /* Timer T7 50 */};long test_start = 0;/* * Return the current time in milliseconds. */static long milliseconds(char *t) { long ret; struct timeval now; printf(" |\n"); printf(" | %s\n",t); printf(" |\n"); FFLUSH(stdout); gettimeofday(&now, NULL); if ( !test_start ) /* avoid blowing over precision */ test_start = now.tv_sec; ret = (now.tv_sec - test_start) * 1000; ret += (now.tv_usec + 500L) / 1000; return ret;}/* * Check the current time against the beginning time provided as an argnument * and see if the time inverval falls between the low and high values for the * timer as specified by arguments. Return SUCCESS if the interval is within * the allowable range and FAILURE otherwise. */static int check_time(const char* t, long beg, long lo, long hi) { long i; struct timeval now; if ( gettimeofday(&now, NULL) ) { printf(" ****ERROR: couldn't get time!\n"); printf(" %s: %s\n",__FUNCTION__,strerror(errno)); FFLUSH(stdout); return FAILURE; } i = (now.tv_sec - test_start) * 1000; i += (now.tv_usec + 500L)/1000; i -= beg; printf(" check time: %4s (%ld <= %ld <= %ld)\n", t, lo-100, i, hi+100); FFLUSH(stdout); if ( lo - 100 <= i && i <= hi + 100 ) return SUCCESS; else return FAILURE;}static int timer_timeout = 0;static void timer_handler(int signum) { if ( signum == SIGALRM ) timer_timeout = 1; return;}static int timer_sethandler(void) { sigset_t mask; struct sigaction act; act.sa_handler = timer_handler; act.sa_flags = SA_RESTART|SA_ONESHOT; act.sa_restorer = NULL; sigemptyset(&act.sa_mask); if ( sigaction(SIGALRM, &act, NULL) ) return FAILURE; sigemptyset(&mask); sigaddset(&mask,SIGALRM); sigprocmask(SIG_UNBLOCK,&mask,NULL); return SUCCESS;}/* * Start an interval timer as the overall test timer. */static int start_tt(long duration) { struct itimerval setting = { { 0, 0 }, { duration/1000, (duration%1000)*1000 } }; if ( timer_sethandler() ) return FAILURE; if ( setitimer(ITIMER_REAL, &setting, NULL) ) return FAILURE; timer_timeout = 0; return SUCCESS;}static int stop_tt(void) { sigset_t mask; struct sigaction act; act.sa_handler = SIG_DFL; act.sa_flags = 0; act.sa_restorer = NULL; sigemptyset(&act.sa_mask); if ( sigaction(SIGALRM, &act, NULL) ) return FAILURE; timer_timeout = 0; sigemptyset(&mask); sigaddset(&mask,SIGALRM); sigprocmask(SIG_BLOCK,&mask,NULL); return SUCCESS;}#define SIO LSSU_SIO /* PT events and signals */#define SIN LSSU_SIN#define SIE LSSU_SIE#define SIOS LSSU_SIOS#define SIPO LSSU_SIPO#define SIB LSSU_SIB#define SIX 6#define SIO2 100 + LSSU_SIO /* PT events and signals */#define SIN2 100 + LSSU_SIN#define SIE2 100 + LSSU_SIE#define SIOS2 100 + LSSU_SIOS#define SIPO2 100 + LSSU_SIPO#define SIB2 100 + LSSU_SIB#define SIX2 100 + 6#define FISU 20 /* PT signals and events */#define FISU_S 21#define FISU_BAD_FIB 22#define FISU_CORRUPT 23#define FISU_CORRUPT_S 24#define LSSU_CORRUPT 25#define LSSU_CORRUPT_S 32#define MSU 26#define MSU_SEVEN_ONES 27#define MSU_TOO_LONG 28#define MSU_TOO_SHORT 29#define TX_BREAK 30#define TX_MAKE 31#define FISU_FISU_1FLAG 60#define FISU_FISU_2FLAG 61#define MSU_MSU_1FLAG 62#define MSU_MSU_2FLAG 63#define TIMEOUT 40 /* TIMER events */#define COUNT 41#define TRIES 39#define ETC 49#define SIB_S 42#define IN_SERVICE 43 /* IUT events */#define OUT_OF_SERVICE 44#define RPO 45#define RPR 46#define IUT_MSU 47#define POWER_ON 200 /* IUT signals */#define START 201#define STOP 202#define LPO 203#define LPR 204#define EMERG 205#define CEASE 206#define SEND_MSU 207#define SEND_MSU_S 208#define CONG_A 209#define CONG_D 210#define NO_CONG 211#define CLEARB 212#define UNKNOWN 48#define NO_MSG -1#define BUFSIZE 300static int state = 0;static int count = 0;static int tries = 0;static int expand = 0;static long beg_time = 0;static unsigned long iut_options = 0;int pt_fd = 0;unsigned char pt_buf[BUFSIZE];unsigned char pt_fib = 0x80;unsigned char pt_fsn = 0x7f;unsigned char pt_bib = 0x80;unsigned char pt_bsn = 0x7f;unsigned char pt_li = 0;unsigned char pt_sio = 0;int iut_fd = 0;unsigned char iut_buf[BUFSIZE];unsigned char iut_fib = 0x80;unsigned char iut_fsn = 0x7f;unsigned char iut_bib = 0x80;unsigned char iut_bsn = 0x7f;unsigned char iut_li = 0;unsigned char iut_sio = 0;unsigned char iut_len = 0;#define MSU_LEN 35int msu_len = MSU_LEN;static int oldpsb = 0;static int oldmsg = 0;static int cntmsg = 0;static int oldact = 0;static int cntact = 0;static int oldisb = 0;static int oldret = 0;static int cntret = 0;static int oldprm = 0;static int cntprm = 0;#define send pt_sendstatic int send(int msg) { int ret = SUCCESS; int len; char *label = NULL; char cbuf[BUFSIZE]; struct strbuf ctrl = { sizeof(* cbuf), 0, cbuf }; struct strbuf data = { sizeof(*pt_buf), 0, pt_buf }; struct strioctl ioc; union SDL_primitives *p = (union SDL_primitives *)cbuf; if ( msg != oldmsg || oldpsb != (((pt_bib|pt_bsn)<<8)|(pt_fib|pt_fsn)) ) { oldmsg = msg; oldpsb = ((pt_bib|pt_bsn)<<8)|(pt_fib|pt_fsn);// if ( cntmsg ) {// printf(" Ct=%d\n", cntmsg+1);// FFLUSH(stdout);// } cntmsg = 0; } else if ( !expand ) cntmsg++; switch ( msg ) { case SIO: case SIN: case SIE: case SIOS: case SIPO: case SIB: case SIX: pt_buf[0] = pt_bib|pt_bsn; pt_buf[1] = pt_fib|pt_fsn; pt_buf[2] = 1; pt_buf[3] = msg; len = 4; switch ( msg ) { case SIO: if ( !cntmsg ) printf(" SIO (%02x/%02x) ---------------->\n", pt_bib|pt_bsn, pt_fib|pt_fsn); break; case SIN: if ( !cntmsg ) printf(" SIN (%02x/%02x) ---------------->\n", pt_bib|pt_bsn, pt_fib|pt_fsn); break; case SIE: if ( !cntmsg ) printf(" SIE (%02x/%02x) ---------------->\n", pt_bib|pt_bsn, pt_fib|pt_fsn); break; case SIOS: if ( !cntmsg ) printf(" SIOS (%02x/%02x) ---------------->\n", pt_bib|pt_bsn, pt_fib|pt_fsn); break; case SIPO: if ( !cntmsg ) printf(" SIPO (%02x/%02x) ---------------->\n", pt_bib|pt_bsn, pt_fib|pt_fsn); break; case SIB: if ( !cntmsg ) printf(" SIB (%02x/%02x) ---------------->\n", pt_bib|pt_bsn, pt_fib|pt_fsn); break; case SIX: if ( !cntmsg ) printf(" LSSU (%02x/%02x) (corrupt)------->\n", pt_bib|pt_bsn, pt_fib|pt_fsn); break; } FFLUSH(stdout); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -