⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test-q781.c

📁 OpenSS7 This the fourth public release of the OpenSS7 Master Package. See README in the release for
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** @(#) test-q781.c,v openss7-0_9_2_E(0.9.2.8) 2006/12/06 11:45:31 ----------------------------------------------------------------------------- Copyright (c) 2001-2005  OpenSS7 Corporation <http://www.openss7.com/> Copyright (c) 1997-2000  Brian F. G. Bidulock <bidulock@openss7.org> 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. ----------------------------------------------------------------------------- As an exception to the above, this software may be distributed under the GNU General Public License (GPL) Version 2 or later, so long as the software is distributed with, and only used for the testing of, OpenSS7 modules, drivers, and libraries. ----------------------------------------------------------------------------- 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/12/06 11:45:31 by brian ----------------------------------------------------------------------------- test-q781.c,v Revision 0.9.2.8  2006/12/06 11:45:31  brian - updated X400P driver and test suites Revision 0.9.2.7  2006/10/31 21:04:48  brian - changes for 32-bit compatibility and remove HZ dependency Revision 0.9.2.6  2006/10/27 22:56:37  brian - changes for 32-bit compatibility Revision 0.9.2.5  2005/06/22 07:58:44  brian - unsigned/signed pointer corrections for gcc4 on FC4 Revision 0.9.2.4  2005/05/14 08:31:35  brian - copyright header correction *****************************************************************************/#ident "@(#) test-q781.c,v openss7-0_9_2_E(0.9.2.8) 2006/12/06 11:45:31"static char const ident[] = "test-q781.c,v openss7-0_9_2_E(0.9.2.8) 2006/12/06 11:45:31";#include <stropts.h>#include <stdlib.h>#include <unistd.h>#include <sys/ioctl.h>#include <sys/time.h>#include <sys/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>#ifdef _GNU_SOURCE#include <getopt.h>#endif#define SUCCESS       0#define FAILURE       1#define INCONCLUSIVE -1#define SCRIPTERROR  -2#define FFLUSH(stream)/*  *  ------------------------------------------------------------------------- * *  Configuration * *  ------------------------------------------------------------------------- */static struct {	lmi_option_t opt;	sdt_config_t sdt;	sdl_config_t sdl;} ptconf;static struct {	lmi_option_t opt;	sl_config_t sl;	sdt_config_t sdt;	sdl_config_t sdl;} iutconf;/*  *  ------------------------------------------------------------------------- * *  Timer Functions * *  ------------------------------------------------------------------------- *//*  *  Timer values for tests: each timer has a low range (minus error margin) *  and a high range (plus error margin). */#define TEST_TIMEOUT 5000typedef struct timer_range {	long lo;	long hi;} timer_range_t;enum { t1 = 0, t2, t3, t4n, t4e, t5, t6, t7, tmax };#if 0static 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 */};#endiflong test_start = 0;#if 0/*  *  Return the current time in milliseconds. */static longmilliseconds(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 intcheck_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;}#endifstatic int timer_timeout = 0;static voidtimer_handler(int signum){	if (signum == SIGALRM)		timer_timeout = 1;	return;}static inttimer_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 intstart_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 intstop_tt(void){	struct itimerval setting = { {0, 0}, {0, 0} };	sigset_t mask;	struct sigaction act;	if (setitimer(ITIMER_REAL, &setting, NULL))		return FAILURE;	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          -1static const char *event_string(int e){	switch (e) {	case SIO:		return ("SIO");	case SIN:		return ("SIN");	case SIE:		return ("SIE");	case SIOS:		return ("SIOS");	case SIPO:		return ("SIPO");	case SIB:		return ("SIB");	case SIX:		return ("SIX");	case SIO2:		return ("SIO2");	case SIN2:		return ("SIN2");	case SIE2:		return ("SIE2");	case SIOS2:		return ("SIOS2");	case SIPO2:		return ("SIPO2");	case SIB2:		return ("SIB2");	case SIX2:		return ("SIX2");	case FISU:		return ("FISU");	case FISU_S:		return ("FISU_S");	case FISU_BAD_FIB:		return ("FISU_BAD_FIB");	case FISU_CORRUPT:		return ("FISU_CORRUPT");	case FISU_CORRUPT_S:		return ("FISU_CORRUPT_S");	case LSSU_CORRUPT:		return ("LSSU_CORRUPT");	case LSSU_CORRUPT_S:		return ("LSSU_CORRUPT_S");	case MSU:		return ("MSU");	case MSU_SEVEN_ONES:		return ("MSU_SEVEN_ONES");	case MSU_TOO_LONG:		return ("MSU_TOO_LONG");	case MSU_TOO_SHORT:		return ("MSU_TOO_SHORT");	case TX_BREAK:		return ("TX_BREAK");	case TX_MAKE:		return ("TX_MAKE");	case FISU_FISU_1FLAG:		return ("FISU_FISU_1FLAG");	case FISU_FISU_2FLAG:		return ("FISU_FISU_2FLAG");	case MSU_MSU_1FLAG:		return ("MSU_MSU_1FLAG");	case MSU_MSU_2FLAG:		return ("MSU_MSU_2FLAG");	case TIMEOUT:		return ("TIMEOUT");	case COUNT:		return ("COUNT");	case TRIES:		return ("TRIES");	case ETC:		return ("ETC");	case SIB_S:		return ("SIB_S");	case IN_SERVICE:		return ("IN_SERVICE");	case OUT_OF_SERVICE:		return ("OUT_OF_SERVICE");	case RPO:		return ("RPO");	case RPR:		return ("RPR");	case IUT_MSU:		return ("IUT_MSU");	case POWER_ON:		return ("POWER_ON");	case START:		return ("START");	case STOP:		return ("STOP");	case LPO:		return ("LPO");	case LPR:		return ("LPR");	case EMERG:		return ("EMERG");	case CEASE:		return ("CEASE");	case SEND_MSU:		return ("SEND_MSU");	case SEND_MSU_S:		return ("SEND_MSU_S");	case CONG_A:		return ("CONG_A");	case CONG_D:		return ("CONG_D");	case NO_CONG:		return ("NO_CONG");	case CLEARB:		return ("CLEARB");	case UNKNOWN:		return ("UNKNOWN");	case NO_MSG:		return ("NO_MSG");	default:		return ("??????");	}}#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;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;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;static int verbose = 0;#define send pt_sendstatic intsend(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 SDT_primitives *p = (union SDT_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 || verbose)				printf("    SIO  (%02x/%02x) ---------------->\n", pt_bib | pt_bsn,				       pt_fib | pt_fsn);			break;		case SIN:			if (!cntmsg || verbose)				printf("    SIN  (%02x/%02x) ---------------->\n", pt_bib | pt_bsn,				       pt_fib | pt_fsn);			break;		case SIE:			if (!cntmsg || verbose)				printf("    SIE  (%02x/%02x) ---------------->\n", pt_bib | pt_bsn,				       pt_fib | pt_fsn);			break;		case SIOS:			if (!cntmsg || verbose)				printf("    SIOS (%02x/%02x) ---------------->\n", pt_bib | pt_bsn,				       pt_fib | pt_fsn);			break;		case SIPO:			if (!cntmsg || verbose)				printf("    SIPO (%02x/%02x) ---------------->\n", pt_bib | pt_bsn,				       pt_fib | pt_fsn);			break;		case SIB:			if (!cntmsg || verbose)				printf("    SIB  (%02x/%02x) ---------------->\n", pt_bib | pt_bsn,				       pt_fib | pt_fsn);			break;		case SIX:			if (!cntmsg || verbose)				printf("    LSSU (%02x/%02x) (corrupt)------->\n", pt_bib | pt_bsn,				       pt_fib | pt_fsn);			break;		}		FFLUSH(stdout);		break;	case SIO2:	case SIN2:	case SIE2:	case SIOS2:	case SIPO2:	case SIB2:	case SIX2:		pt_buf[0] = pt_bib | pt_bsn;		pt_buf[1] = pt_fib | pt_fsn;		pt_buf[2] = 2;		pt_buf[3] = 0;		pt_buf[4] = msg - 100;		len = 5;		switch (msg) {		case SIO2:			if (!cntmsg || verbose)				printf("    SIO  (%02x/%02x)[2]-------------->\n", pt_bib | pt_bsn,				       pt_fib | pt_fsn);			break;		case SIN2:			if (!cntmsg || verbose)				printf("    SIN  (%02x/%02x)[2]-------------->\n", pt_bib | pt_bsn,				       pt_fib | pt_fsn);			break;		case SIE2:			if (!cntmsg || verbose)				printf("    SIE  (%02x/%02x)[2]-------------->\n", pt_bib | pt_bsn,				       pt_fib | pt_fsn);			break;		case SIOS2:			if (!cntmsg || verbose)				printf("    SIOS (%02x/%02x)[2]-------------->\n", pt_bib | pt_bsn,				       pt_fib | pt_fsn);			break;		case SIPO2:			if (!cntmsg || verbose)				printf("    SIPO (%02x/%02x)[2]-------------->\n", pt_bib | pt_bsn,				       pt_fib | pt_fsn);			break;		case SIB2:			if (!cntmsg || verbose)				printf("    SIB  (%02x/%02x)[2]-------------->\n", pt_bib | pt_bsn,				       pt_fib | pt_fsn);			break;		case SIX2:			if (!cntmsg || verbose)				printf("    LSSU (%02x/%02x)[2](corrupt)----->\n", pt_bib | pt_bsn,				       pt_fib | pt_fsn);			break;		}		FFLUSH(stdout);		break;	case SIB_S:		pt_buf[0] = pt_bib | pt_bsn;		pt_buf[1] = pt_fib | pt_fsn;		pt_buf[2] = 1;		pt_buf[3] = SIB;		len = 4;		break;	case COUNT:		printf("    Ct=%d\n", count);		FFLUSH(stdout);		return SUCCESS;	case TRIES:		printf("    %d iterations\n", tries);		FFLUSH(stdout);		return SUCCESS;	case ETC:		printf("      .\n");		printf("      .\n");		printf("      .\n");		FFLUSH(stdout);		return SUCCESS;	case FISU:		if (!cntmsg || verbose) {			printf("    FISU (%02x/%02x) ---------------->\n", pt_bib | pt_bsn,			       pt_fib | pt_fsn);			FFLUSH(stdout);		}	case FISU_S:		pt_buf[0] = pt_bib | pt_bsn;		pt_buf[1] = pt_fib | pt_fsn;		pt_buf[2] = 0;		len = 3;		break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -