📄 sdlconf.c
字号:
/***************************************************************************** @(#) sdlconf.c,v openss7-0_9_2_E(0.9.2.4) 2006/12/18 10:51:44 ----------------------------------------------------------------------------- Copyright (c) 2001-2003 OpenSS7 Corporation <http://www.openss7.com> Copyright (c) 1997-2000 Brian F. G. Bidulock <bidulock@openss7.org> All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ----------------------------------------------------------------------------- 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). ----------------------------------------------------------------------------- Commercial licensing and support of this software is available from OpenSS7 Corporation at a fee. See http://www.openss7.com/ ----------------------------------------------------------------------------- Last Modified 2006/12/18 10:51:44 by brian *****************************************************************************/#ident "@(#) sdlconf.c,v openss7-0_9_2_E(0.9.2.4) 2006/12/18 10:51:44"static char const ident[] = "sdlconf.c,v openss7-0_9_2_E(0.9.2.4) 2006/12/18 10:51:44";#include <stropts.h>#include <stdlib.h>#include <unistd.h>#include <stdio.h>#include <string.h>#include <errno.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/poll.h>#include <sys/time.h>#include <sys/ioctl.h>#include <sys/stat.h>#include <fcntl.h>#include <getopt.h>#include <time.h>#include <signal.h>#include <syslog.h>#include <ss7/lmi.h>#include <ss7/lmi_ioctl.h>#include <ss7/sdli.h>#include <ss7/sdli_ioctl.h>#include <ss7/sdti.h>#include <ss7/sdti_ioctl.h>struct key_val { char *key; unsigned long val;};static struct key_val type_names[] = { {"default", SDL_TYPE_NONE}, {"v35", SDL_TYPE_V35}, {"ds0", SDL_TYPE_DS0}, {"ds0a", SDL_TYPE_DS0A}, {"e1", SDL_TYPE_E1}, {"t1", SDL_TYPE_T1}, {"j1", SDL_TYPE_J1}, {"atm", SDL_TYPE_ATM}, {"packet", SDL_TYPE_PACKET}};static struct key_val gtype_names[] = { {"default", SDL_GTYPE_NONE}, {"t1", SDL_GTYPE_T1}, {"e1", SDL_GTYPE_E1}, {"j1", SDL_GTYPE_J1}, {"atm", SDL_GTYPE_ATM}, {"eth", SDL_GTYPE_ETH}, {"ip", SDL_GTYPE_IP}, {"udp", SDL_GTYPE_UDP}, {"tcp", SDL_GTYPE_TCP}, {"rtp", SDL_GTYPE_RTP}, {"sctp", SDL_GTYPE_SCTP}};static struct key_val mode_names[] = { {"default", SDL_MODE_NONE}, {"dsu", SDL_MODE_DSU}, {"csu", SDL_MODE_CSU}, {"dte", SDL_MODE_DTE}, {"dce", SDL_MODE_DCE}, {"client", SDL_MODE_CLIENT}, {"server", SDL_MODE_SERVER}, {"peer", SDL_MODE_PEER}, {"echo", SDL_MODE_ECHO}, {"rem_lb", SDL_MODE_REM_LB}, {"loc_lb", SDL_MODE_LOC_LB}, {"lb_echo", SDL_MODE_LB_ECHO}, {"test", SDL_MODE_TEST}};static struct key_val gmode_names[] = { {"default", SDL_GMODE_NONE}, {"loc_lb", SDL_GMODE_LOC_LB}, {"rem_lb", SDL_GMODE_REM_LB}};static struct key_val gcrc_names[] = { {"default", SDL_GCRC_NONE}, {"crc4", SDL_GCRC_CRC4}, {"crc5", SDL_GCRC_CRC5}, {"crc6", SDL_GCRC_CRC6}, {"crc6j", SDL_GCRC_CRC6J}};static struct key_val clock_names[] = { {"default", SDL_CLOCK_NONE}, {"int", SDL_CLOCK_INT}, {"ext", SDL_CLOCK_EXT}, {"loop", SDL_CLOCK_LOOP}, {"master", SDL_CLOCK_MASTER}, {"slave", SDL_CLOCK_SLAVE}, {"dpll", SDL_CLOCK_DPLL}, {"abr", SDL_CLOCK_ABR}, {"shaper", SDL_CLOCK_SHAPER}, {"tick", SDL_CLOCK_TICK}};static struct key_val coding_names[] = { {"default", SDL_CODING_NONE}, {"nrz", SDL_CODING_NRZ}, {"nrzi", SDL_CODING_NRZI}, {"ami", SDL_CODING_AMI}, {"b6zs", SDL_CODING_B6ZS}, {"b8zs", SDL_CODING_B8ZS}, {"hbd3", SDL_CODING_HDB3}, {"aal1", SDL_CODING_AAL1}, {"aal2", SDL_CODING_AAL2}, {"aal5", SDL_CODING_AAL5}};static struct key_val framing_names[] = { {"default", SDL_FRAMING_NONE}, {"ccs", SDL_FRAMING_CCS}, {"cas", SDL_FRAMING_CAS}, {"d4", SDL_FRAMING_D4}, {"esf", SDL_FRAMING_ESF}, {"sf", SDL_FRAMING_SF}};static struct key_val rate_names[] = { {"default", SDL_RATE_NONE}, {"ds0a", SDL_RATE_DS0A}, {"ds0", SDL_RATE_DS0}, {"t1", SDL_RATE_T1}, {"j1", SDL_RATE_J1}, {"e1", SDL_RATE_E1}};static struct key_val grate_names[] = { {"default", SDL_GRATE_NONE}, {"t1", SDL_GRATE_T1}, {"j1", SDL_GRATE_J1}, {"e1", SDL_GRATE_E1}};static struct key_val txlevel_names[] = { {"default", SDL_TXLEVEL_NONE}, {"DSX-1 0-133ft", SDL_TXLEVEL_DSX_133FT}, {"DSX-1 133-266ft", SDL_TXLEVEL_DSX_266FT}, {"DSX-1 266-399ft", SDL_TXLEVEL_DSX_399FT}, {"DSX-1 399-533ft", SDL_TXLEVEL_DSX_533FT}, {"DSX-1 533-666ft", SDL_TXLEVEL_DSX_666FT}, {"0dB CSU", SDL_TXLEVEL_CSU_0DB}, {"-7.5dB CSU", SDL_TXLEVEL_CSU_8DB}, {"-15dB CSU", SDL_TXLEVEL_CSU_15DB}, {"-22.5dB CSU", SDL_TXLEVEL_CSU_23DB}, {"75 Ohm, Normal", SDL_TXLEVEL_75OHM_NM}, {"120 Ohm, Normal", SDL_TXLEVEL_120OHM_NM}, {"75 Ohm, Protected", SDL_TXLEVEL_75OHM_PR}, {"120 Ohm, Protected", SDL_TXLEVEL_120OHM_PR}, {"75 Ohm, High Return Loss", SDL_TXLEVEL_75OHM_HRL}, {"120 Ohm, High Return Loss", SDL_TXLEVEL_120OHM_HRL}, {"0Db Monitor", SDL_TXLEVEL_MON_0DB}, {"12dB Monitor", SDL_TXLEVEL_MON_12DB}, {"20dB Monitor", SDL_TXLEVEL_MON_20DB}, {"26dB Monitor", SDL_TXLEVEL_MON_26DB}, {"30dB Monitor", SDL_TXLEVEL_MON_30DB}, {"32dB Monitor", SDL_TXLEVEL_MON_32DB},};sdl_config_t config = { .ifname = NULL, .ifflags = 0, .iftype = SDL_TYPE_NONE, .ifrate = SDL_RATE_NONE, .ifgtype = SDL_GTYPE_NONE, .ifgrate = SDL_GRATE_NONE, .ifmode = SDL_MODE_NONE, .ifgmode = SDL_GMODE_NONE, .ifgcrc = SDL_GCRC_NONE, .ifclock = SDL_CLOCK_NONE, .ifcoding = SDL_CODING_NONE, .ifframing = SDL_FRAMING_NONE, .ifblksize = 0, .ifleads = 0, .ifbpv = 0, .ifalarms = 0, .ifrxlevel = 0, .iftxlevel = SDL_TXLEVEL_NONE, .ifsync = 0, .ifsyncsrc = {1, 2, 3, 4},};struct optname_struct { struct key_val *name; size_t size; volatile sdl_ulong *valp;};enum { CFG_TYPE, CFG_GTYPE, CFG_MODE, CFG_GMODE, CFG_GCRC, CFG_CLOCK, CFG_CODING, CFG_FRAMING, CFG_RATE, CFG_GRATE, CFG_TXLEVEL, CFG_SYNCSRC,};struct optname_struct optnames[] = { {type_names, sizeof(type_names) / sizeof(struct key_val), &config.iftype}, {gtype_names, sizeof(gtype_names) / sizeof(struct key_val), &config.ifgtype}, {mode_names, sizeof(mode_names) / sizeof(struct key_val), &config.ifmode}, {gmode_names, sizeof(gmode_names) / sizeof(struct key_val), &config.ifgmode}, {gcrc_names, sizeof(gcrc_names) / sizeof(struct key_val), &config.ifgcrc}, {clock_names, sizeof(clock_names) / sizeof(struct key_val), &config.ifclock}, {coding_names, sizeof(coding_names) / sizeof(struct key_val), &config.ifcoding}, {framing_names, sizeof(framing_names) / sizeof(struct key_val), &config.ifframing}, {rate_names, sizeof(rate_names) / sizeof(struct key_val), &config.ifrate}, {grate_names, sizeof(grate_names) / sizeof(struct key_val), &config.ifgrate}, {txlevel_names, sizeof(txlevel_names) / sizeof(struct key_val), &config.iftxlevel}};int card = 0;int span = 0;int slot = 1;int output = 1;char devname[256] = "/dev/x400p-sl";char cfgfile[256] = "/etc/sysconfig/ss7/sdl.config";voidcopying(int argc, char *argv[]){ if (!output) return; fprintf(stdout, "\\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\\n\");}voidversion(int argc, char *argv[]){ if (!output) return; fprintf(stdout, "\\n\%1$s:\n\ %2$s\n\ Copyright (c) 2003-2006 OpenSS7 Corporation. All Rights Reserved.\n\\n\ Distributed by OpenSS7 Corporation under GPL Version 2,\n\ incorporated here by reference.\n\\n\ See `%1$s --copying' for copying permission.\n\\n\", argv[0], ident);}voidusage(int argc, char *argv[]){ if (!output) return; fprintf(stderr, "\Usage:\n\ %1$s [options] {-g, --get} {-d, --device} [{-c, --card} card] [{-p, --span} span] [{-t, --slot} slot]\n\ %1$s [options] {-s, --set} {-d, --device} [{-c, --card} card] [{-p, --span} span] [{-t, --slot} slot] [set-options]\n\ %1$s [options] {-f, --file} config_file\n\ %1$s {-h, --help}\n\ %1$s {-V, --version}\n\ %1$s {-C, --copying}\n\", argv[0]);}voidhelp(int argc, char *argv[]){ if (!output) return; fprintf(stdout, "\\n\Usage:\n\ %1$s [options] {-g, --get} {-d, --device} [{-c, --card} card] [{-p, --span} span] [{-t, --slot} slot]\n\ %1$s [options] {-s, --set} {-d, --device} [{-c, --card} card] [{-p, --span} span] [{-t, --slot} slot] [set-options]\n\ %1$s [options] {-f, --file} config_file\n\ %1$s {-h, --help}\n\ %1$s {-V, --version}\n\ %1$s {-C, --copying}\n\Arguments:\n\ (none)\n\General Options:\n\ -q, --quiet (default: off)\n\ suppress output\n\ -v, --verbose (default: off)\n\ increase verbosity of output\n\Command Options:\n\ -g, --get\n\ get (display) device configuration\n\ -s, --set\n\ set (configure) device configuration\n\ -f, --file file (default: %2$s)\n\ read device configuration from file\n\ -h, --help\n\ prints this usage information and exits\n\ -V, --version\n\ prints the version and exits\n\ -C, --copying\n\ prints the copying permissions and exits\n\Set/Get Options:\n\ -d, --device devname (default: %3$s)\n\ device name\n\ -c, --card card (default: %4$d)\n\ card in host (numbered from 0)\n\ -p, --span span (default: %5$d)\n\ span on card (numbered from 0)\n\ -t, --slot slot (default: %6$d)\n\ timeslot (numbered from 1, 0 for entire span)\n\Set Options:\n\ --clock (default: %7$s)\n\ span clock source: default int ext loop master slave dpll abr shaper tick\n\ --rate (default: %8$u)\n\ channel interface rate: 56000 64000 1544000 2048000\n\ --type (default: %9$s)\n\ channel interface type: default v35 ds0 ds0a e1 t1 j1 atm packet\n\ --mode (default: %10$s)\n\ channel interface mode: default dsu csu dte dce client server peer echo rem_lb loc_lb lb_echo test\n\ --grate (default: %11$u)\n\ span interface rate: 1544000 2048000 10000000 100000000\n\ --gtype (default: %12$s)\n\ span interface type: default t1 e1 j1 atm eth ip udp tcp rtp sctp\n\ --gmode (default: %13$s)\n\ span interface mode: default loc_lb rem_lb\n\ --gcrc (default: %14$s)\n\ span CRC calulation: default crc4 crc5 crc6 crc6j\n\ --coding (default: %15$s)\n\ span coding: default nrz nrzi ami b6zs b8zs aal1 aal2 aal5 hbd3\n\ --framing (default: %16$s)\n\ span framing: ccs cas sf esf\n\ --syncsrc sync1,sync2,sync3,sync4\n\ span synchronization: 0 - self, 1 - span1 ...\n\", argv[0], cfgfile, devname, card, span, slot, clock_names[config.ifclock].key, config.ifrate, type_names[config.iftype].key, mode_names[config.ifmode].key, config.ifgrate, gtype_names[config.ifgtype].key, gmode_names[config.ifgmode].key, gcrc_names[config.ifgcrc].key, coding_names[config.ifcoding].key, framing_names[config.ifframing].key);}voidshow_config_long(sdl_config_t * cfg, int get){ char *unknown = "unknown"; printf("Configuration:\n"); printf(" %s card %d, span %d, slot %d\n", devname, card, span, slot); printf(" iftype: %s(%u)\n", (cfg->iftype < optnames[CFG_TYPE].size) ? optnames[CFG_TYPE].name[cfg->iftype].key : unknown, cfg->iftype); printf(" ifrate: %u\n", cfg->ifrate); printf(" ifgtype: %s(%u)\n", (cfg->ifgtype < optnames[CFG_GTYPE].size) ? optnames[CFG_GTYPE].name[cfg->ifgtype].key : unknown, cfg->ifgtype); printf(" ifgrate: %u\n", cfg->ifgrate); printf(" ifmode: %s(%u)\n", (cfg->ifmode < optnames[CFG_MODE].size) ? optnames[CFG_MODE].name[cfg->ifmode].key : unknown, cfg->ifmode); printf(" ifgmode: %s(%u)\n", (cfg->ifgmode < optnames[CFG_GMODE].size) ? optnames[CFG_GMODE].name[cfg->ifgmode].key : unknown, cfg->ifgmode); printf(" ifgcrc: %s(%u)\n", (cfg->ifgcrc < optnames[CFG_GCRC].size) ? optnames[CFG_GCRC].name[cfg->ifgcrc].key : unknown, cfg->ifgcrc); printf(" ifclock: %s(%u)\n", (cfg->ifclock < optnames[CFG_CLOCK].size) ? optnames[CFG_CLOCK].name[cfg->ifclock].key : unknown, cfg->ifclock); printf(" ifcoding: %s(%u)\n", (cfg->ifcoding < optnames[CFG_CODING].size) ? optnames[CFG_CODING].name[cfg->ifcoding].key : unknown, cfg->ifcoding); printf(" ifframing: %s(%u)\n", (cfg->ifframing < optnames[CFG_FRAMING].size) ? optnames[CFG_FRAMING].name[cfg->ifframing].key : unknown, cfg->ifframing); printf(" ifblksize: %u\n", cfg->ifblksize); printf(" iftxlevel: %u\n", cfg->iftxlevel); printf(" ifsyncsrc: %u %u %u %u\n", cfg->ifsyncsrc[0], cfg->ifsyncsrc[1], cfg->ifsyncsrc[2], cfg->ifsyncsrc[3]); if (get) { printf(" ifleads:"); if (cfg->ifleads & SDL_LEAD_DTR) printf(" dtr"); if (cfg->ifleads & SDL_LEAD_RTS) printf(" rts"); if (cfg->ifleads & SDL_LEAD_DCD) printf(" dcd"); if (cfg->ifleads & SDL_LEAD_CTS) printf(" cts"); if (cfg->ifleads & SDL_LEAD_DSR) printf(" dsr"); printf("\n"); printf(" ifalarms:");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -