📄 test-x400p-sdl.c
字号:
sdl_disconnect(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->disconnect_req); ctrl.buf = cbuf; p->sdl_primitive = SDL_DISCONNECT_REQ; p->connect_req.sdl_flags = SDL_RX_DIRECTION | SDL_TX_DIRECTION; printf("\nAttempting DISCONNECT 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_write(int fd){ const size_t len = 64; const uint8_t buf[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; int i, ret; i = 0; printf("\nAttempting write\n"); for (;;) { ret = write(fd, buf, len); if (ret < 0) { if (errno == EINTR || errno == ERESTART) { if (i++ < 100) continue; } if (errno == EAGAIN) { return; } printf("error = %d\n", errno); perror("test"); exit(2); } else printf("Write succeeded, wrote %d bytes!\n", ret); if (ret > 0) { int i; printf("Message[%ld]: ", (long) len); for (i = 0; i < len; i++) { printf("%02X ", buf[i]); } printf("\n"); } }}voidsdl_read(int fd){ uint8_t buf[256]; int i, ret; i = 0; printf("\nAttempting read\n"); for (;;) { ret = read(fd, buf, 256); if (ret < 0) { if (errno == EAGAIN || errno == EINTR || errno == ERESTART) { if (i++ < 100) continue; } if (errno == EBADMSG) { do_lmi_get_msg(fd); continue; } printf("error = %d\n", errno); perror("test"); break; } else printf("Read succeeded, read %d bytes!\n", ret); if (ret > 0) { int i; uint8_t *c = buf; printf("Message[%d]: ", ret); for (i = 0; i < ret; i++, c++) { printf("%02X ", *c); } printf("\n"); } }}intsdl_ioctl(int fd, int cmd, void *arg, int len){ struct strioctl ctl = { cmd, 0, len, arg }; int ret; ret = ioctl(fd, I_STR, &ctl); if (ret < 0) { printf("return = %d\n", ret); printf("error = %d\n", errno); perror("sdl_ioctl"); exit(2); } return ctl.ic_len;}voiddo_ioctl(int fd, int cmd, int arg){ int ret; ret = ioctl(fd, cmd, arg); if (ret < 0) { printf("return = %d\n", ret); printf("error = %d\n", errno); perror("do_ioctl"); exit(2); }}voidsdl_config(int fd){ unsigned char buf[256]; sdl_config_t *c = (sdl_config_t *) buf; sdl_statem_t *s = (sdl_statem_t *) buf; printf("Getting configuration\n"); sdl_ioctl(fd, SDL_IOCGCONFIG, buf, sizeof(sdl_config_t)); printf("Config:\n"); printf(" ifflags = %lu\n", c->ifflags); printf(" iftype = %lu\n", c->iftype); printf(" ifrate = %lu\n", c->ifrate); printf(" ifgtype = %lu\n", c->ifgtype); printf(" ifgrate = %lu\n", c->ifgrate); printf(" ifgcrc = %lu\n", c->ifgcrc); printf(" ifmode = %lu\n", c->ifmode); printf(" ifclock = %lu\n", c->ifclock); printf(" ifcoding = %lu\n", c->ifcoding); printf(" ifframing = %lu\n", c->ifframing); printf(" ifblksize = %lu\n", c->ifblksize); printf(" ifleads = %lu\n", c->ifleads); printf(" ifalarms = %lu\n", c->ifalarms); printf(" ifrxlevel = %lu\n", c->ifrxlevel); printf(" iftxlevel = %lu\n", c->iftxlevel); printf(" ifsync = %lu\n", c->ifsync); printf(" ifsyncsrc[0] = %lu\n", c->ifsyncsrc[0]); printf(" ifsyncsrc[1] = %lu\n", c->ifsyncsrc[1]); printf(" ifsyncsrc[2] = %lu\n", c->ifsyncsrc[2]); printf(" ifsyncsrc[3] = %lu\n", c->ifsyncsrc[3]); sdl_ioctl(fd, SDL_IOCGSTATEM, buf, sizeof(sdl_statem_t)); printf("State:\n"); printf(" tx_state = %lu\n", s->tx_state); printf(" rx_state = %lu\n", s->rx_state);}voidsdl_stats(int fd){ unsigned char buf[256]; sdl_stats_t *s = (sdl_stats_t *) buf; printf("Attempting stats collection\n"); sdl_ioctl(fd, SDL_IOCGSTATS, buf, sizeof(sdl_stats_t)); printf("Stats:\n"); printf(" rx_octets............ = %lu\n", s->rx_octets); printf(" tx_octets............ = %lu\n", s->tx_octets); printf(" rx_overruns.......... = %lu\n", s->rx_overruns); printf(" tx_underruns......... = %lu\n", s->tx_underruns); printf(" rx_buffer_overflows.. = %lu\n", s->rx_buffer_overflows); printf(" tx_buffer_overflows.. = %lu\n", s->tx_buffer_overflows); printf(" lead_cts_lost........ = %lu\n", s->lead_cts_lost); printf(" lead_dcd_lost........ = %lu\n", s->lead_dcd_lost); printf(" carrier_lost......... = %lu\n", s->carrier_lost);}intdo_tests(void){ int i, pfd[2]; uint16_t ppa[2] = { 0x0012, 0x0112 }; printf("Opening one stream\n"); if ((pfd[0] = open("/dev/x400p-sdl", O_NONBLOCK | O_RDWR)) < 0) { perror("open"); exit(2); } printf("Opening other stream\n"); if ((pfd[1] = open("/dev/x400p-sdl", O_NONBLOCK | O_RDWR)) < 0) { perror("open"); exit(2); } // do_ioctl(pfd[0], I_SRDOPT, RMSGD); // do_ioctl(pfd[1], I_SRDOPT, RMSGD); do_ioctl(pfd[0], I_SETCLTIME, 0); do_ioctl(pfd[1], I_SETCLTIME, 0); info_req(pfd[0]); info_req(pfd[1]); attach_req(pfd[0], ppa[0]); attach_req(pfd[1], ppa[1]); sdl_config(pfd[0]); sdl_config(pfd[1]); sdl_stats(pfd[0]); sdl_stats(pfd[1]); enable_req(pfd[0]); enable_req(pfd[1]); sdl_config(pfd[0]); sdl_config(pfd[1]); sdl_stats(pfd[0]); sdl_stats(pfd[1]); sdl_connect(pfd[0]); sdl_connect(pfd[1]); sdl_config(pfd[0]); sdl_config(pfd[1]); sdl_stats(pfd[0]); sdl_stats(pfd[1]); // sleep(20); sdl_read(pfd[0]); sdl_read(pfd[1]); /* * Do some reads and writes. */ for (i = 0; i < 100; i++) { sdl_write(pfd[0]); sdl_read(pfd[1]); sdl_write(pfd[1]); sdl_read(pfd[0]); } sdl_config(pfd[0]); sdl_config(pfd[1]); sdl_stats(pfd[0]); sdl_stats(pfd[1]); sdl_disconnect(pfd[1]); sdl_disconnect(pfd[0]); sdl_config(pfd[0]); sdl_config(pfd[1]); sdl_stats(pfd[0]); sdl_stats(pfd[1]); disable_req(pfd[1]); disable_req(pfd[0]); sdl_config(pfd[0]); sdl_config(pfd[1]); sdl_stats(pfd[0]); sdl_stats(pfd[1]); detach_req(pfd[1]); detach_req(pfd[0]); printf("Closing one side\n"); close(pfd[0]); printf("Closing other side\n"); close(pfd[1]); printf("Done\n"); return (0);}voidcopying(int argc, char *argv[]){ if (!verbose) return; fprintf(stdout, "\ITU-T RECOMMENDATAION Q.781 - Conformance Test Suite\n\\n\Copyright (c) 2001-2006 OpenSS7 Corporation <http://www.openss7.com/>\n\Copyright (c) 1997-2001 Brian F. G. Bidulock <bidulock@openss7.org>\n\\n\All Rights Reserved.\n\\n\Unauthorized distribution or duplication is prohibited.\n\\n\This software and related documentation is protected by copyright and distribut-\n\ed under licenses restricting its use, copying, distribution and decompilation.\n\No part of this software or related documentation may be reproduced in any form\n\by any means without the prior written authorization of the copyright holder,\n\and licensors, if any.\n\\n\The recipient of this document, by its retention and use, warrants that the re-\n\cipient will protect this information and keep it confidential, and will not\n\disclose the information contained in this document without the written permis-\n\sion of its owner.\n\\n\The author reserves the right to revise this software and documentation for any\n\reason, including but not limited to, conformity with standards promulgated by\n\various agencies, utilization of advances in the state of the technical arts, or\n\the reflection of changes in the design of any techniques, or procedures embod-\n\ied, described, or referred to herein. The author is under no obligation to\n\provide any feature listed herein.\n\\n\As an exception to the above, this software may be distributed under the GNU\n\General Public License (GPL) Version 2, so long as the software is distributed\n\with, and only used for the testing of, OpenSS7 modules, drivers, and libraries.\n\\n\U.S. GOVERNMENT RESTRICTED RIGHTS. If you are licensing this Software on behalf\n\of the U.S. Government (\"Government\"), the following provisions apply to you.\n\If the Software is supplied by the Department of Defense (\"DoD\"), it is classi-\n\fied as \"Commercial Computer Software\" under paragraph 252.227-7014 of the DoD\n\Supplement to the Federal Acquisition Regulations (\"DFARS\") (or any successor\n\regulations) and the Government is acquiring only the license rights granted\n\herein (the license rights customarily provided to non-Government users). If\n\the Software is supplied to any unit or agency of the Government other than DoD,\n\it is classified as \"Restricted Computer Software\" and the Government's rights\n\in the Software are defined in paragraph 52.227-19 of the Federal Acquisition\n\Regulations (\"FAR\") (or any successor regulations) or, in the cases of NASA, in\n\paragraph 18.52.227-86 of the NASA Supplement to the FAR (or any successor\n\regulations).\n\");}voidversion(int argc, char *argv[]){ if (!verbose) return; fprintf(stdout, "\%1$s:\n\ %2$s\n\ Copyright (c) 2001-2006 OpenSS7 Corporation. All Rights Reserved.\n\\n\ Distributed by OpenSS7 Corporation under GPL Version 2,\n\ incorporated here by reference.\n\", argv[0], ident);}voidusage(int argc, char *argv[]){ if (!verbose) return; fprintf(stderr, "\Usage:\n\ %1$s [options]\n\ %1$s {-h, --help}\n\ %1$s {-V, --version}\n\ %1$s {-C, --copying}\n\", argv[0]);}voidhelp(int argc, char *argv[]){ if (!verbose) return; fprintf(stdout, "\Usage:\n\ %1$s [options]\n\ %1$s {-h, --help}\n\ %1$s {-V, --version}\n\ %1$s {-C, --copying}\n\Arguments:\n\ (none)\n\Options:\n\ -q, --quiet\n\ suppress normal output (equivalent to --verbose=0)\n\ -v, --verbose [LEVEL]\n\ increase verbosity or set to LEVEL [default: 1]\n\ this option may be repeated.\n\ -h, --help, -?, --?\n\ print this usage message and exit\n\ -V, --version\n\ print the version and exit\n\ -C, --copying\n\ print the version and exit\n\", argv[0]);}intmain(int argc, char *argv[]){ for (;;) { int c, val;#if defined _GNU_SOURCE int option_index = 0; /* *INDENT-OFF* */ static struct option long_options[] = { {"quiet", no_argument, NULL, 'q'}, {"verbose", optional_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {"copying", no_argument, NULL, 'C'}, {"?", no_argument, NULL, 'h'}, { 0, } }; /* *INDENT-ON* */ c = getopt_long(argc, argv, "qvhVC?", long_options, &option_index);#else /* defined _GNU_SOURCE */ c = getopt(argc, argv, "qvhVC?");#endif /* defined _GNU_SOURCE */ if (c == -1) break; switch (c) { case 'v': if (optarg == NULL) { verbose++; break; } if ((val = strtol(optarg, NULL, 0)) < 0) goto bad_option; verbose = val; break; case 'H': /* -H */ case 'h': /* -h, --help */ help(argc, argv); exit(0); case 'V': version(argc, argv); exit(0); case 'C': copying(argc, argv); exit(0); case '?': default: bad_option: optind--; bad_nonopt: if (optind < argc && verbose) { fprintf(stderr, "%s: illegal syntax -- ", argv[0]); while (optind < argc) fprintf(stderr, "%s ", argv[optind++]); fprintf(stderr, "\n"); fflush(stderr); } goto bad_usage; bad_usage: usage(argc, argv); exit(2); } } /* * dont' ignore non-option arguments */ if (optind < argc) goto bad_nonopt; copying(argc, argv); do_tests(); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -