📄 test-x400p-sdl.c
字号:
/***************************************************************************** @(#) test-x400p-sdl.c,v openss7-0_9_2_E(0.9.2.5) 2006/03/07 01:18:01 ----------------------------------------------------------------------------- Copyright (c) 2001-2006 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, 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/03/07 01:18:01 by brian ----------------------------------------------------------------------------- test-x400p-sdl.c,v Revision 0.9.2.5 2006/03/07 01:18:01 brian - 64bit issues Revision 0.9.2.4 2005/05/14 08:31:39 brian - copyright header correction *****************************************************************************/#ident "@(#) test-x400p-sdl.c,v openss7-0_9_2_E(0.9.2.5) 2006/03/07 01:18:01"static char const ident[] = "test-x400p-sdl.c,v openss7-0_9_2_E(0.9.2.5) 2006/03/07 01:18:01";#include <stropts.h>#include <stdlib.h>#include <unistd.h>#include <sys/ioctl.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 <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <time.h>#ifdef _GNU_SOURCE#include <getopt.h>#endif#define BUFSIZE 280int verbose = 1;const char *lmi_strreason(unsigned int reason){ const char *r; switch (reason) { default: case LMI_UNSPEC: r = "Unknown or unspecified"; break; case LMI_BADADDRESS: r = "Address was invalid"; break; case LMI_BADADDRTYPE: r = "Invalid address type"; break; case LMI_BADDIAL: r = "(not used)"; break; case LMI_BADDIALTYPE: r = "(not used)"; break; case LMI_BADDISPOSAL: r = "Invalid disposal parameter"; break; case LMI_BADFRAME: r = "Defective SDU received"; break; case LMI_BADPPA: r = "Invalid PPA identifier"; break; case LMI_BADPRIM: r = "Unregognized primitive"; break; case LMI_DISC: r = "Disconnected"; break; case LMI_EVENT: r = "Protocol-specific event ocurred"; break; case LMI_FATALERR: r = "Device has become unusable"; break; case LMI_INITFAILED: r = "Link initialization failed"; break; case LMI_NOTSUPP: r = "Primitive not supported by this device"; break; case LMI_OUTSTATE: r = "Primitive was issued from invalid state"; break; case LMI_PROTOSHORT: r = "M_PROTO block too short"; break; case LMI_SYSERR: r = "UNIX system error"; break; case LMI_WRITEFAIL: r = "Unitdata request failed"; break; case LMI_CRCERR: r = "CRC or FCS error"; break; case LMI_DLE_EOT: r = "DLE EOT detected"; break; case LMI_FORMAT: r = "Format error detected"; break; case LMI_HDLC_ABORT: r = "Aborted frame detected"; break; case LMI_OVERRUN: r = "Input overrun"; break; case LMI_TOOSHORT: r = "Frame too short"; break; case LMI_INCOMPLETE: r = "Partial frame received"; break; case LMI_BUSY: r = "Telephone was busy"; break; case LMI_NOANSWER: r = "Connection went unanswered"; break; case LMI_CALLREJECT: r = "Connection rejected"; break; case LMI_HDLC_IDLE: r = "HDLC line went idle"; break; case LMI_HDLC_NOTIDLE: r = "HDLC link no longer idle"; break; case LMI_QUIESCENT: r = "Line being reassigned"; break; case LMI_RESUMED: r = "Line has been reassigned"; break; case LMI_DSRTIMEOUT: r = "Did not see DSR in time"; break; case LMI_LAN_COLLISIONS: r = "LAN excessive collisions"; break; case LMI_LAN_REFUSED: r = "LAN message refused"; break; case LMI_LAN_NOSTATION: r = "LAN no such station"; break; case LMI_LOSTCTS: r = "Lost Clear to Send signal"; break; case LMI_DEVERR: r = "Start of device-specific error codes"; break; } return r;}voiddo_lmi_get_msg(int fd){ int ret, flags = 0; struct strbuf ctrl; struct strbuf data; char cbuf[BUFSIZE]; char dbuf[BUFSIZE]; union LMI_primitives *p = (union LMI_primitives *) cbuf; ctrl.maxlen = BUFSIZE; ctrl.len = 0; ctrl.buf = cbuf; data.maxlen = BUFSIZE; data.len = 0; data.buf = dbuf; do_get_again: printf("\nAttempting getmsg\n"); if ((ret = getmsg(fd, &ctrl, &data, &flags)) < 0) { printf("error = %d\n", errno); perror("test"); return; } else printf("Getmsg succeeded!\n"); if (ret == 0) { if (ctrl.len > 0) { switch ((long) p->lmi_primitive) { case LMI_INFO_ACK: { int ppalen = ctrl.len - sizeof(p->info_ack); printf("LMI_INFO_ACK:\n"); printf("Version = 0x%08lx\n", p->info_ack.lmi_version); printf("State = %lu\n", p->info_ack.lmi_state); printf("Max sdu = %lu\n", p->info_ack.lmi_max_sdu); printf("Min sdu = %lu\n", p->info_ack.lmi_min_sdu); printf("Header len = %lu\n", p->info_ack.lmi_header_len); printf("PPA style = %lu\n", p->info_ack.lmi_ppa_style); printf("PPA length = %d\n", ppalen); return; } case LMI_OK_ACK: printf("LMI_OK_ACK:\n"); printf("Correct primitive = %ld\n", p->ok_ack.lmi_correct_primitive); printf("State = %ld\n", p->ok_ack.lmi_state); return; case LMI_ERROR_ACK: printf("LMI_ERROR_ACK:\n"); printf("Error number = %lu\n", p->error_ack.lmi_errno); printf("Error string = %s\n", strerror(p->error_ack.lmi_errno)); printf("Reason number = %lu\n", p->error_ack.lmi_reason); printf("Reason string = %s\n", lmi_strreason(p->error_ack.lmi_reason)); printf("Error primitive = %lu\n", p->error_ack.lmi_error_primitive); printf("State = %lu\n", p->error_ack.lmi_state); return; case LMI_ERROR_IND: printf("LMI_ERROR_IND:\n"); printf("Error number = %lu\n", p->error_ind.lmi_errno); printf("Error string = %s\n", strerror(p->error_ind.lmi_errno)); printf("Reason number = %lu\n", p->error_ind.lmi_reason); printf("Reason string = %s\n", lmi_strreason(p->error_ind.lmi_reason)); printf("State = %lu\n", p->error_ind.lmi_state); goto do_get_again; case LMI_ENABLE_CON: printf("LMI_ENABLE_CON:\n"); printf("State = %lu\n", p->enable_con.lmi_state); return; case LMI_DISABLE_CON: printf("LMI_DISABLE_CON:\n"); printf("State = %lu\n", p->disable_con.lmi_state); return; case LMI_STATS_IND: printf("LMI_STATS_IND:\n"); return; case LMI_EVENT_IND: printf("LMI_EVENT_IND:\n"); return; case SDL_BITS_FOR_TRANSMISSION_REQ: printf("SDL_BITS_FOR_TRANSMISSION_REQ:\n"); return; case SDL_CONNECT_REQ: printf("SDL_CONNECT_REQ:\n"); return; case SDL_DISCONNECT_REQ: printf("SDL_DISCONNECT_REQ:\n"); return; case SDL_RECEIVED_BITS_IND: printf("SDL_RECEIVED_BITS_IND:\n"); return; case SDL_DISCONNECT_IND: printf("SDL_DISCONNECT_IND:\n"); return; default: printf("Unrecognized response primitive %ld!\n", (long) p->lmi_primitive); goto do_get_again; } } }}voidinfo_req(int fd){ int ret; struct strbuf ctrl; char cbuf[BUFSIZE]; union LMI_primitives *p = (union LMI_primitives *) cbuf; ctrl.maxlen = BUFSIZE; ctrl.len = sizeof(p->info_req); ctrl.buf = cbuf; p->lmi_primitive = LMI_INFO_REQ; printf("\nAttempting info request\n"); if ((ret = putmsg(fd, &ctrl, NULL, RS_HIPRI)) < 0) { printf("error = %d\n", errno); perror("test"); exit(2); } else printf("Putmsg succeeded!\n"); do_lmi_get_msg(fd);}voidattach_req(int fd, uint16_t ppa){ int ret; struct strbuf ctrl; char cbuf[BUFSIZE]; union LMI_primitives *p = (union LMI_primitives *) cbuf; ctrl.maxlen = BUFSIZE; ctrl.len = sizeof(p->attach_req) + sizeof(ppa); ctrl.buf = cbuf; p->attach_req.lmi_primitive = LMI_ATTACH_REQ; bcopy(&ppa, p->attach_req.lmi_ppa, sizeof(ppa)); printf("\nAttempting attach request\n"); if ((ret = putmsg(fd, &ctrl, NULL, RS_HIPRI)) < 0) { printf("error = %d\n", errno); perror("test"); exit(2); } else printf("Putmsg succeeded!\n"); do_lmi_get_msg(fd);}voiddetach_req(int fd){ int ret; struct strbuf ctrl; char cbuf[BUFSIZE]; union LMI_primitives *p = (union LMI_primitives *) cbuf; ctrl.maxlen = BUFSIZE; ctrl.len = sizeof(p->detach_req); ctrl.buf = cbuf; p->lmi_primitive = LMI_DETACH_REQ; printf("\nAttempting detach request\n"); if ((ret = putmsg(fd, &ctrl, NULL, RS_HIPRI)) < 0) { printf("error = %d\n", errno); perror("test"); exit(2); } else printf("Putmsg succeeded!\n"); do_lmi_get_msg(fd);}voidenable_req(int fd){ int ret; struct strbuf ctrl; char cbuf[BUFSIZE]; union LMI_primitives *p = (union LMI_primitives *) cbuf; ctrl.maxlen = BUFSIZE; ctrl.len = sizeof(p->enable_req); ctrl.buf = cbuf; p->lmi_primitive = LMI_ENABLE_REQ; printf("\nAttempting enable request\n"); if ((ret = putmsg(fd, &ctrl, NULL, RS_HIPRI)) < 0) { printf("error = %d\n", errno); perror("test"); exit(2); } else printf("Putmsg succeeded!\n"); do_lmi_get_msg(fd);}voiddisable_req(int fd){ int ret; struct strbuf ctrl; char cbuf[BUFSIZE]; union LMI_primitives *p = (union LMI_primitives *) cbuf; ctrl.maxlen = BUFSIZE; ctrl.len = sizeof(p->disable_req); ctrl.buf = cbuf; p->lmi_primitive = LMI_DISABLE_REQ; printf("\nAttempting disable request\n"); if ((ret = putmsg(fd, &ctrl, NULL, RS_HIPRI)) < 0) { printf("error = %d\n", errno); perror("test"); exit(2); } else printf("Putmsg succeeded!\n"); do_lmi_get_msg(fd);}voidsdl_connect(int fd){ int ret; struct strbuf ctrl; char cbuf[BUFSIZE]; union SDL_primitives *p = (union SDL_primitives *) cbuf; ctrl.maxlen = BUFSIZE; ctrl.len = sizeof(p->connect_req); ctrl.buf = cbuf; p->sdl_primitive = SDL_CONNECT_REQ; p->connect_req.sdl_flags = SDL_RX_DIRECTION | SDL_TX_DIRECTION; printf("\nAttempting CONNECT request\n"); if ((ret = putmsg(fd, &ctrl, NULL, RS_HIPRI)) < 0) { printf("error = %d\n", errno); perror("test"); exit(2); } else printf("Putmsg succeeded!\n"); // do_lmi_get_msg(fd);}void
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -