📄 cli.c
字号:
/******************************************************************************
Copyright (c) 2005, Infineon Technologies. All rights reserved.
No Warranty
Because the program is licensed free of charge, there is no warranty for
the program, to the extent permitted by applicable law. Except when
otherwise stated in writing the copyright holders and/or other parties
provide the program "as is" without warranty of any kind, either
expressed or implied, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpose. The
entire risk as to the quality and performance of the program is with
you. should the program prove defective, you assume the cost of all
necessary servicing, repair or correction.
In no event unless required by applicable law or agreed to in writing
will any copyright holder, or any other party who may modify and/or
redistribute the program as permitted above, be liable to you for
damages, including any general, special, incidental or consequential
damages arising out of the use or inability to use the program
(including but not limited to loss of data or data being rendered
inaccurate or losses sustained by you or third parties or a failure of
the program to operate with any other programs), even if such holder or
other party has been advised of the possibility of such damages.
******************************************************************************
Module : clc.c
Date : 2005-06-23
Creator : Bolo Tsai
Description :
Remarks:
*****************************************************************************/
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <time.h>
#include <fcntl.h>
#include "cli.h"
#include "swfct.h"
#define MAX_ARG_NUM 16 // mod - 06/27/05,bolo; org: 11
#define MAX_CMD_LEN 256 // mod - 06/27/05,bolo; org: 80
/* Function prototypes */
void CmdReadPortLink(int argc, char **argv);
void CmdWritePortLink(int argc, char **argv);
void CmdTrunkConfig(int argc, char **argv);
void CmdMirrorGetConfig(int argc, char **argv);
void CmdMirrorSetConfig(int argc, char **argv);
void CmdPortVLANConfig(int argc, char **argv);
void CmdTagVLANConfig(int argc, char **argv);
void CmdVLANOptionConfig(int argc, char **argv);
void CmdPortPriConfig(int argc, char **argv);
void CmdVLANPriConfig(int argc, char **argv);
void CmdTOSPriConfig(int argc, char **argv);
void CmdSrvPriConfig(int argc, char **argv);
void CmdBroadcastStormConfig(int argc, char **argv);
void CmdTxBandWidthConfig(int argc, char **argv);
void CmdRxBandWidthConfig(int argc, char **argv);
void CmdPortSecurityConfig(int argc, char **argv);
void CmdSecurityOptionConfig(int argc, char **argv);
void CmdLearnTableRead(int argc, char **argv);
void CmdLearnTableWrite(int argc, char **argv);
void CmdIGMPConfig(int argc, char **argv);
void CmdIGMPOptConfig(int argc, char **argv);
void CmdIGMPTableRead(int argc, char **argv);
void CmdIGMPTableWrite(int argc, char **argv);
void CmdGetPortCounter(int argc, char **argv);
#ifdef EEPROM
void CmdEEPROMRead(int argc, char **argv);
void CmdEEPROMWrite(int argc, char **argv);
#endif
void CmdSWIRegRead(int argc, char **argv);
void CmdSWIRegWrite(int argc, char **argv);
void CmdReadPhy(int argc, char **argv);
void CmdWritePhy(int argc, char **argv);
void CmdResetSwitch(int argc, char **argv);
void CmdExit(int argc, char **argv);
void CmdHelp(int argc, char **argv);
/******************************* Variables ******************************/
static int bufidx = 0, argcnt;
static char *argarray[MAX_ARG_NUM];
static char clibuf[MAX_CMD_LEN];
static int NumCmd;
char version[] = CLI_VERSION; // mov - 09/12/05,mod - 08/23/05,bolo
/* Command Table */
CLI_ENTRY cli_tab[] =
{
// "rln <ptno {0..5}>"
{"rln", 3, CmdReadPortLink, "Read the port link ability", 2, 2 ," <ptno <{0..5}>"},
// "wln <ptno {0..5}> <-a/-m> <100/10> <-f/-h> <-c/-n>"
{"wln", 3, CmdWritePortLink, "Write the port link ability", 2, 6 ," <ptno {0..5}> <-a/-m> <100/10> <-f/-h> <-c/-n>"},
// "trk <-o/-O>"
{"trk", 3, CmdTrunkConfig, "Set trunk function", 2, 2 ," <-o/-O>"},
// "getmi <ptno {0..5}>"
{"getmi", 5, CmdMirrorGetConfig, "Get the mirror configuration", 2, 2 ," <ptno {0..5}>"},
// "setmi <ptno {0..5}> <r[0..3]> <t[0..3]> <tyop>"
{"setmi", 5, CmdMirrorSetConfig, "Set the mirror configuration", 4, 11 ," <ptno {0..5}> <r[0..3]> <t[0..3]> <tyop>"},
// "pvlan <grpno {0..5}> <pd-d..-d>"
{"pvlan", 5, CmdPortVLANConfig, "Set the port VLAN configuration", 3, 3 ," <grpno {0..5}> <pd-d..-d>"}, // mod - 08/12/05 for the port VID, org: 2, 3
// "tvlan <flno {0..15}> <v[0..4095]> <f[0..15]> <-v/-V> <q[0..7]> <td-d..-d> <pd-d..-d>"
{"tvlan", 5, CmdTagVLANConfig, "Set the tag VLAN configuration", 8, 8 ," <flno {0..15}> <v[0..4095]> <f[0..15]> <-v/-V> <q[0..7]> <td-d..-d> <pd-d..-d>"},
// "vlanop <option{0..8}> <0xhh>"
{"vlanop", 6, CmdVLANOptionConfig, "Set the VLAN option", 3, 3 ," <option {0..8}> <0xhh>"},
// "portprq <ptno {0..5}> <-o/-O> <m[0..3]> <v[0..4095]" // mod - 08/12/05 for the port VID <v[0..4095]>
{"portprq", 7, CmdPortPriConfig, "Set the port priority queue & PVID", 4, 5 ," <ptno {0..5}> <-o/-O> <m[0..3]> <v[0..4095]"},
// "vlanprq <ptno {0..5}> <vd-d..-d> <q[0..7]> <m[0..3]}> <-ip/-vp>"
{"vlanprq", 7, CmdVLANPriConfig, "Set the VLAN priority queue", 5, 6 ," <ptno {0..5}> <vd-d..-d> <q[0..7]> <m[0..3]}> <-ip/-vp>"},
// "tosprq <sd-d..-d> <q[0..7]> <m[0..3]"
{"tosprq", 6, CmdTOSPriConfig, "Set the IPv4 TOS priority queue", 4, 4 ," <sd-d..-d> <q[0..7]> <m[0..3]"},
// "srvprq <sd-d..-d> <q[0..63]> <m[0..3]>"
{"srvprq", 6, CmdSrvPriConfig, "Set the IPv4 Service priority queue", 4, 4 ," <sd-d..-d> <q[0..63]> <m[0..3]>"},
// "brdstm <-s/-S> <-d/-D> <H0..8191> <h0..8191> <-m/-M>"
{"brdstm", 6, CmdBroadcastStormConfig, "Set the broadcast storm protection function", 5, 6 ," <-s/-S> <-d/-D> <H0..8191> <h0..8191> <-m/-M>"},
// "txbw <ptno {0..5}> <-o/-O> <[1..1526]>"
{"txbw", 4, CmdTxBandWidthConfig, "Set the transmit bandwidth control function", 4, 4 ," <ptno {0..5}> <-o/-O> <[1..1526]>"},
// "rxbw <ptno {0..5}> <-o/-O> <[1..1526]>"
{"rxbw", 4, CmdRxBandWidthConfig, "Set the receive bandwidth control function", 4, 4 ," <ptno {0..5}> <-o/-O> <[1..1526]>"},
// "seci <ptno {0..5}> <s[1..6]> <-c/-C>"
{"seci", 4, CmdPortSecurityConfig, "Set the port security function", 3, 4, " <ptno {0..5}> <s[1..6]> <-c/-C>"},
// "secop <id-d-d> <vd-d-d-d>"
{"secop", 5, CmdSecurityOptionConfig, "Set the port security option", 3, 3 ," <id-d-d> <vd-d-d-d>"},
// "rlrntbl <s1..s8> <pd-d..-d> <f0..f15> <%x-%x..-%x>"
{"rlrntbl", 7, CmdLearnTableRead, "Read the learning table", 5, 5 ," <s1..s8> <pd-d..-d> <f0..f15> <%x-%x..-%x>"},
// "wlrntbl <-c/-o/-d> <-l/-s> <i0xhhh> <pd-d..-d> <f[0..15]> <%x-%x..-%x>"
{"wlrntbl", 7, CmdLearnTableWrite, "Write the learning table", 7, 7 ," <-c/-o/-d> <-l/-s> <i0xhhh> <pd-d..-d> <f[0..15]> <%x-%x..-%x>"},
// "igc <-i/-I> <-c/-C> <q[0.255]> <r[1..3]> <pd-d..-d>"
{"igc", 3, CmdIGMPConfig, "Set the IGMP function", 5, 6 ," <-i/-I> <-c/-C> <q[0.255]> <r[1..3]> <pd-d..-d>"},
// "igop <option {0..7}> <v[0/1],v[0..3],v[0..2]>"
{"igop", 4, CmdIGMPOptConfig, "Set the IGMP option", 3, 3 ," <option {0..7}> <v[0/1],v[0..3],v[0..2]>"},
// "rigtbl <entry {0..31}>"
{"rigtbl", 6, CmdIGMPTableRead, "Read the IGMP table", 2, 2 ," <entry {0..31}>"},
// "wigtbl <entry {0..31}> <pd-d..-d>"
{"wigtbl", 6, CmdIGMPTableWrite, "Write the IGMP table", 3, 3 ," <entry {0..31}> <pd-d..-d>"},
// "getcnt <ptno {0..5}> <-c>"
{"getcnt", 6, CmdGetPortCounter, "Get the port statistics counters", 2, 3 ," <ptno {0..5}> <-c>"},
#ifdef EEPROM
// "ree <[0..0x9c]>"
{"ree", 3, CmdEEPROMRead, "Read the specific EEPROM content", 2, 2 ," <[0..0x9c]>"},
// "wee <[0..0x9c]> <val>"
{"wee", 3, CmdEEPROMWrite, "Write the specific EEPROM content", 3, 3 ," <[0..0x9c]> <val>"},
#endif
// "rsmi <[0..0x288]>"
{"rsmi", 4, CmdSWIRegRead, "Read the internal registers thru SMI", 2, 2 ," <[0..0x288]>"},
// "wsmi <[0..0x288]> <val>"
{"wsmi", 4, CmdSWIRegWrite, "Write the internal registers thru SMI", 3, 3 ," <[0..0x288]> <val>"},
// "rphy <ptno {0..4}> <reg {0..5}>"
{"rphy", 4, CmdReadPhy, "Read the specific PHY register", 3, 3 ," <ptno {0..4}> <reg {0..5}>"},
// "wphy <ptno {0..4}> <reg {0..5}> <val>"
{"wphy", 4, CmdWritePhy, "Write the specific PHY register", 4, 4 ," <ptno {0..4}> <reg {0..5}> <val>"},
// "reset"
{"reset", 5, CmdResetSwitch, "Reset the switch controller", 1, 1 ," "},
// "help", add - 06/29/05,bolo
{"exit", 4, CmdExit, "Quit the switch console program", 1, 2 ," "},
// "help"
{"help", 4, CmdHelp, "List the command usage (all/individual)", 1, 2 ," "},
};
/************************************************************************************/
/* CmdReadPortLink: read the link capability of the port */
/************************************************************************************/
void CmdReadPortLink(int argc, char **argv)
{
char *NwayShow[2] = {"Link down", "Link up"};
char *SpeedShow[2] = {"10Mbps", "100Mbps"};
char *DuplexShow[2] = {"Half Duplex", "Full Duplex"};
char *FlowCtrlShow[2] = {"Off", "On"};
int port_no;
word nway, speed, duplex, flowctrl;
// option description:
// port_no: the port number (0..5)
// Get the port_no.
sscanf(argv[1], "%d", &port_no);
if ((port_no < 0) || (port_no > 5)) {
printf("ArgErr: the port_no must be in 0..5 !\n");
return;
}
SWPortLink(port_no, READ_MODE, (word *)&nway, (word *)&speed, (word *)&duplex, (word *)&flowctrl);
// nway = speed = duplex = flowctrl = 1;
printf("Port-%d NWAY SPEED DUPLEX FLOWCTRL\n",port_no);
printf(" %s %s %s %s\n",NwayShow[nway], SpeedShow[speed], DuplexShow[duplex], FlowCtrlShow[flowctrl]);
}
/************************************************************************************/
/* CmdWritePortLink: write the link capability of the port */
/************************************************************************************/
void CmdWritePortLink(int argc, char **argv)
{
int i;
int port_no;
word nway, speed, duplex, flowctrl;
// option description:
// port_no: the port number (0..5)
// nway: -a (auto NWAY negotiation), -m (force NWAY mode)
// speed: 100 (select 100Mbps), 10 (select 10Mbps)
// duplex: -f (select full duplex), -h (select half duplex)
// flowctrl: -c (enable flow control), -n (diable flow control)
nway = speed = duplex = flowctrl = 1;
// Get the port_no.
sscanf(argv[1], "%d", &port_no);
if ((port_no < 0) || (port_no > 5)) {
printf("ArgErr: the port_no must be in 0..5 !\n");
return;
}
if (argc > 2) {
for (i = 0; i < argc; i++) {
if (strcmp(argv[2+i], "-m") == 0)
nway = 0;
if (strcmp(argv[2+i], "10") == 0)
speed = 0;
if (strcmp(argv[2+i], "-h") == 0)
duplex = 0;
if (strcmp(argv[2+i], "-n") == 0)
flowctrl = 0;
}
}
SWPortLink(port_no, WRITE_MODE, (word *)&nway, (word *)&speed, (word *)&duplex, (word *)&flowctrl);
printf("PortLinkConfig: port[%d],nway=%d,speed=%d,duplex=%d,flow=%d\n", port_no, nway, speed, duplex, flowctrl);
}
/************************************************************************************/
/* CmdTrunkConfig: */
/************************************************************************************/
void CmdTrunkConfig(int argc, char **argv)
{
int trunkSwitch = 1;
if (strcmp(argv[1], "-O") == 0)
trunkSwitch = 0;
SWTrunkConfig(trunkSwitch);
printf("TrunkConfig: trunkSwitch=%d\n", trunkSwitch);
}
/************************************************************************************/
/* CmdMirrorGetConfig: */
/************************************************************************************/
void CmdMirrorGetConfig(int argc, char **argv)
{
int port_no;
word receiveOption, transmitOption, typeOption;
// option description:
// port_no: the port number (0..5)
// Get the port_no.
sscanf(argv[1], "%d", &port_no);
if ((port_no < 0) || (port_no > 5)) {
printf("ArgErr: the port_no must be in 0..5 !\n");
return;
}
SWMirrorGetConfig(port_no, &receiveOption, &transmitOption, &typeOption);
printf("CmdMirrorGetConfig: port[%d], rxop=%#x, txop=%#x, typeop=%#x\n", port_no, receiveOption, transmitOption, typeOption);
}
/************************************************************************************/
/* CmdMirrorSetConfig: */
/************************************************************************************/
void CmdMirrorSetConfig(int argc, char **argv)
{
int i, port_no;
word receiveOption, transmitOption;
int typeOption[8];
// option description:
// port_no: the port number (0..5)
// receiveOption: r0 (not mirrored), r1 (rx mirrored on portx), r2 (rx DA mirrored on portx), r3 (rx SA mirrored on portx)
// transmitOption: t0 (not mirrored), t1 (rx mirrored on portx), t2 (rx DA mirrored on portx), t3 (rx SA mirrored on portx)
// typeOption: -d (mirror disable) -c (mirror CRC), -x (mirror rx error), -p (mirror pause), -l (mirror long),
// -s (mirrot short), -u (mirror tx unmonitored packets), -k (keep the configuration)
// Get the port_no.
sscanf(argv[1], "%d", &port_no);
if ((port_no < 0) || (port_no > 5)) {
printf("ArgErr: the port_no must be in 0..5 !\n");
return;
}
// Get the receive mirror option.
sscanf(argv[2], "r%d", &receiveOption);
if ((receiveOption < 0) || (receiveOption > 3)) {
printf("ArgErr: the receive option must be in 0..3 !\n");
return;
}
// Get the transmit mirror option.
sscanf(argv[3], "t%d", &transmitOption);
if ((transmitOption < 0) || (transmitOption > 3)) {
printf("ArgErr: the transmit option must be in 0..3 !\n");
return;
}
for (i = 0; i < 8; i++) {
typeOption[i] = 0;
}
if (argc > 4) {
for (i = 0; i < argc; i++) {
if (strcmp(argv[4+i], "-c") == 0)
typeOption[0] = SWI_MIRROR1_OPT_CRC;
if (strcmp(argv[4+i], "-x") == 0)
typeOption[1] = SWI_MIRROR1_OPT_RXER;
if (strcmp(argv[4+i], "-p") == 0)
typeOption[2] = SWI_MIRROR1_OPT_PAUSE;
if (strcmp(argv[4+i], "-l") == 0)
typeOption[3] = SWI_MIRROR1_OPT_LONG;
if (strcmp(argv[4+i], "-s") == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -