?? mtp3app.c
字號:
/*
* Test app to send and receive MTP3 packets and generate other MTP3 API calls.
* Always displays any MTP packets (or other events) received. User hits <CR>
* and can get a prompt to enter MTP3 primitive command.
*
* To run:
*
* mtp3app -o <opc> [-s <sio>] [-b <board>] [-n <nsap> ] -?
*
* <opc> originating point code to use for outgoing packets: required
*
* <sio> Service Information Octet value; default: 0x85 (ISUP)
*
* <board> Board number to use (defaults to 1)
*
* <nsap> MTP network SAP number to bind to
*
* User Commands:
*
* SEND <dpc> # prompts for data to send
* FLOW [OFF | ON]
* STA [OFF | ON] # Turn on/off extended status indications
*/
#ifdef UNIX
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stream.h>
#include <ctype.h>
#endif /* UNIX */
#ifdef __OS2__
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#endif /* __OS2__ */
#ifdef WIN32
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#endif /* WIN32 */
#include "ss7type.h"
#include "mtp3api.h"
#include "tx_core.h"
#define DFLT_ENT 0x20 /* Default application entity ID */
#define DFLT_INST 0 /* PC is always board zero */
#define DFLT_SAP 0 /* defaults to first SAP in MTP configuration file */
/* globals (with defaults) for parameter values */
U32 Dpc = 0; /* dest point code - no default */
U32 Opc = 0L; /* my point code, no default */
U8 Sio = 0x85; /* SIO value to send (default national ISUP) */
U8 MyEnt = DFLT_ENT; /* application entity ID, can be overridden to allow
* multiple copies to run simultaneously */
S16 MySap = 0; /* MTP3 NSAP to bind to (default 0) */
int Board = 1; /* MTP3's Board Number */
/* other globals */
#define MAX_PACKET 272
U8 Buf[MAX_PACKET]; /* packet buffer */
unsigned long PktXmitCnt = 0; /* packet xmit count */
unsigned long ByteXmitCnt = 0; /* byte xmit count */
#define MAX_PARMS 10
extern CPI_WAIT_TYPE stdInput;
/*
func to dump data in hex+ascii format
IN: Buf data to show
ByteCnt #Bytes in Buf
OUT: <file> gets multiple lines
*/
void showHex(unsigned char *Buf, unsigned short ByteCnt)
{
unsigned short Li;
unsigned short LMax;
unsigned short ToDo;
unsigned short Bi;
unsigned short Ai;
char Ascii[80];
unsigned char B;
/* Dump to std out in hex followed by ascii */
for (ToDo = ByteCnt, Bi = 0; ToDo > 0; ToDo -= LMax)
{
LMax = (ToDo > 16) ? 16 : ToDo; /* max bytes this line */
printf("%04X| ", Bi);
Ai = 0;
for (Li = 0; Li < LMax; Li++) /* each byte this line */
{
B = *Buf++; /* next byte to show */
printf("%02X ", B); /* as hex */
if (!isprint(B)) /* printable ascii? */
B = '.'; /* no, use this */
Ascii[Ai++] = B; /* into ascii portiob */
} /* for Li */
for (Li = LMax; Li < 16; Li++) /* pad short ln if necessary */
{
printf(" "); /* so asci lines up */
}
Ascii[Ai] = 0; /* terminate the ascii */
printf(" ");
printf("%s\n", Ascii); /* show the ascii */
Bi += LMax;
} /* for ToDo */
} /* ShowHex */
/* tokenize
*
* Takes input line and creates an array of pointers to individual
* tokens in the input line. First separator after each token in
* input line is replaced with a null so that each token becomes
* a null terminated string.
*/
short tokenize( char *buf, char *tokens[] )
{
char *p = buf;
char *endp;
short cnt;
/* initialize token pointers to all null */
for(cnt = 0; cnt <= MAX_PARMS; cnt++ )
{
tokens[cnt] = 0;
}
/* begin scanning for tokens */
cnt = 0;
while( *p != 0 && cnt <= MAX_PARMS )
{
/* skip leading space or tabs */
while( *p == ' ' || *p == '\t' )
{
p++;
}
/* beginning of token (or end of line) */
if( *p != 0 )
{
/* scan for end of token, converting to upper case as we go */
endp = p;
while( *endp != ' ' && *endp != '\t' && *endp != 0 )
{
if( islower( *endp ) )
{
*endp = 'A' + (*endp - 'a'); /* convert to upper */
}
endp++;
}
/* now have a begin & end of token */
tokens[cnt++] = p;
if( *endp == 0 )
{
p = endp; /* end of input - terminate scan */
}
else
{
*endp = 0; /* null terminate token */
p = &endp[1]; /* start next scan at after null */
}
} /* end if *p != 0 */
} /* end while *p != 0 .... */
return( cnt );
}
/* cmdPrompt
*
* Prompts user to enter command, collects parameters, and issues appropriate
* MTP3 API command
*/
void cmdPrompt( void )
{
char buffer[256];
char *tokens[MAX_PARMS +1];
short len;
short cnt;
short status;
short action;
long a1, a2, a3; /* individual point code components */
/* prompt for a command */
printf( "Command?>" );
tx_core_gets(buffer, 255);
printf( "\n" );
cnt = tokenize( buffer, tokens );
if( cnt == 0 )
return;
if( (strcmp( tokens[0], "SEND" ) == 0) || (strcmp( tokens[0], "S" ) == 0) )
{
if( cnt < 2 )
{
printf( "Point code expected\n" );
return;
}
/* scan next token for valid DPC */
if( (sscanf( tokens[1], "%lu.%lu.%lu", &a1, &a2, &a3 )) == 3 )
{
Dpc = ((a1 & 0xFF) << 16) + ((a2 & 0xFF) << 8) + (a3 & 0xFF);
}
else if( (sscanf( tokens[1], "%iu", &Dpc )) != 1 )
{
printf( "Parameter error [%s] - point code expected\n", tokens[1]);
return;
}
/* prompt for message data */
printf( "Message Data?>" );
tx_core_gets(buffer, 255);
printf( "\n" );
if ((len = strlen( buffer )) > 0)
{
/* send the data, including terminating null */
status = MTP3SendData((U8) Board,
MySap,
Opc,
Dpc,
(U8) 0,
(U8) 1,
(U8 *) buffer,
(short) len,
Sio );
if( status != 0 )
{
printf( "Mtp3SendData failed, status = %d\n", status);
}
}
}
else if( (strcmp( tokens[0], "FLOW" ) == 0) || (strcmp( tokens[0], "F" ) == 0) )
{
/* scan next token for valid DPC */
if( cnt < 2 )
{
printf( "FLOW OFF or ON expected\n" );
return;
}
if( strncmp( tokens[1], "ON", 2 ) == 0 )
action = 1;
else if( strncmp( tokens[1], "OFF", 3 ) == 0 )
action = 0;
else
{
printf( "FLOW OFF or ON expected\n" );
return;
}
status = MTP3Flow( (U8) Board, MySap, action );
if( status != 0 )
{
printf( "Mtp3Flow failed, status = %d\n", status );
}
}
else if( (strcmp( tokens[0], "XSTA" ) == 0) || (strcmp( tokens[0], "X" ) == 0) )
{
/* scan for ON or OFF */
if( cnt < 2 )
{
printf( "XSTA OFF or ON expected\n" );
return;
}
if( strncmp( tokens[1], "ON", 2 ) == 0 )
{
status = MTP3RegXStaReq( (U8) Board, MySap);
if( status != 0 )
{
printf( "MTP3RegXStatReq failed, status = %d\n", status );
}
}
else if( strncmp( tokens[1], "OFF", 3 ) == 0 )
{
status = MTP3DeregXStaReq( (U8) Board, MySap);
if( status != 0 )
{
printf( "MTP3DeregXStaReq failed, status = %d\n", status );
}
}
else
{
printf( "XSTA OFF or ON expected\n" );
return;
}
}
else
{
printf( "SEND, FLOW or XSTA command expected\n" );
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -