From bdf95351d3563e4039ee2cc229452d78b3b6a612 Mon Sep 17 00:00:00 2001 From: "advielsack@gmail.com" Date: Sat, 7 Jan 2012 12:01:32 +0000 Subject: [PATCH] added port diag command git-svn-id: http://gsconf.googlecode.com/svn/trunk@5 11042eb7-4a36-49e9-8ab2-01d26d512705 --- gs105e.c | 17 +++++++++++++---- main.c | 32 -------------------------------- shell.c | 21 +++++++++++++++++++++ shell_port.c | 33 ++++++++++++++++++++++++++++++++- 4 files changed, 66 insertions(+), 37 deletions(-) diff --git a/gs105e.c b/gs105e.c index ccee5d7..bcd9008 100644 --- a/gs105e.c +++ b/gs105e.c @@ -220,8 +220,8 @@ void gs105e_interpret_slice(unsigned int ID, char * data, int len) { break; case GS_PORTDIAG:; p = &settings.portStatistics[data[0]]; - p->cableError = toUInt4(&data[1]); - p->errorDist = toUInt4(&data[5]); + p->cableError = (char)toUInt4(&data[1]); + p->errorDist = (char)toUInt4(&data[5]); break; case ACT_DHCP:; settings.dhcp = data[1] & 0x03; @@ -289,7 +289,16 @@ int gs105e_actRecv(void) { return -1; } + + if (data[2] == 0) { + for (n = 32; n < len; ) { + id = (data[n] * 256) + data[n + 1]; + slLen = (data[n+2] * 256) + data[n + 3]; + + gs105e_interpret_slice(id, &data[n + 4], slLen); + n += slLen + 4; + } return data[2]; } } @@ -349,10 +358,10 @@ int gs105e_mirrorPorts(int outputPort, int mirrorMask) { } int gs105e_cableDiagnostics(int port) { - makeHeader(QR_EXEC); + makeHeader(QR_REQ); char data[1] = {port}; - addActData(ACT_PORTMIRROR, 3, data); + addActData(GS_PORTDIAG, 1, data); return gs105e_act(); } diff --git a/main.c b/main.c index 2e39ff0..3150ae7 100644 --- a/main.c +++ b/main.c @@ -8,10 +8,7 @@ #include int shellHandler = 0; -/*void shellHandlers[] = { - -}*/ int main () { @@ -24,35 +21,6 @@ int main () { gs105e_init(); shell(); - /* - printf("Model: %s\n", settings.model); - struct vlan * vl = settings.vlans; - - if (vl == NULL) { - printf("NO Vlans\n"); - } else - printf("Vlans\n"); - - while (vl != NULL) { - printf("%u\t", vl->id); - for (n = 0; n < 5; n++) - printf("%c\t", vl->members & (0x80 >> n) ? (vl->tag & (0x80 >> n) ? 'T' : 'U') : '-', (unsigned int) vl->members); - printf("\n"); - vl = vl->next; - } - - for (n = 0; n < 5; n++) { - printf("Port %u\t%s\t\t%lu Bytes in\t\t%lu Bytes out\n", n + 1, - (settings.portStatistics[n].state == 0x05 ? "1000 Mbit/s" : (settings.portStatistics[n].state == 0x04 ? "100 Mbit/s" : (settings.portStatistics[n].state == 0x03 ? "10 Mbit/s": (settings.portStatistics[n].state == 0x00 ? "no connection": "???")))), settings.portStatistics[n].bytesIn, settings.portStatistics[n].bytesOut); - } - - - - //settings.password = "password"; - - //gs105e_mirrorPorts(3, MSK_PORT1|MSK_PORT4); - - */ } diff --git a/shell.c b/shell.c index 284acc0..eceb152 100644 --- a/shell.c +++ b/shell.c @@ -97,6 +97,27 @@ int shell (void) { struct gs105e_discovered * ddev; char * dev = "nodev"; + + n = gs105e_discover(); + printf("Discovered \033[92m%i\033[0m devices\n", n); + + ddev = gs105e_devs; + + printf("ID\tName\t\tMAC\t\tIP\n"); + + while (ddev != NULL) { + printf("%i\t%s\t\t%X:%X:%X:%X:%X:%X\t%u.%u.%u.%u\n", ddev->id, ddev->name, ddev->mac[0]&0xff, ddev->mac[1]&0xff, ddev->mac[2]&0xff, ddev->mac[3]&0xff, ddev->mac[4]&0xff, ddev->mac[5]&0xff, ddev->ip[0]&0xff, ddev->ip[1]&0xff, ddev->ip[2]&0xff, ddev->ip[3]&0xff); + ddev = ddev->next; + } + + if (n == 1) { + printf("only one switch, selecting 1\n"); + + memcpy(settings.mac, gs105e_devs->mac, 6); + gs105e_queryAll(); + dev = gs105e_devs->name; + } + while (1) { printf("\033[96mgs (\033[93m%s\033[96m)# \033[0m", dev); cmd[0] = 0; diff --git a/shell_port.c b/shell_port.c index 258d966..4e69179 100644 --- a/shell_port.c +++ b/shell_port.c @@ -2,7 +2,7 @@ void shell_port(char ** argv, int elem) { - int n; + int n, i; if (elem == 1) { @@ -17,5 +17,36 @@ void shell_port(char ** argv, int elem) { settings.portStatistics[n].bytesOut ); } + } else if (strncmp(argv[1], "diag", 4) == 0) { + if (elem != 3) { + printf("Port needed\n"); + return; + } + + n = atoi(argv[2]); + + if (n < 1 | n > 5) { + printf("Invalid Port\n"); + return; + } + + password(); + i = gs105e_cableDiagnostics((char) n); + + printError(i); + if (i != 0) + return; + if (settings.portStatistics[n].cableError) { + printf("\033[91mError detected: %s in %i m\033[0m\n", + (settings.portStatistics[n].cableError == 0x03 ? "short circuit" : (settings.portStatistics[n].cableError == 0x02 ? "Only one pair Connected!": "damaged")), + settings.portStatistics[n].errorDist + ); + + }else{ + if (settings.portStatistics[n].errorDist == 0 ) + printf("\033[92mSeems no Cable is connected!?\033[0m\n"); + else + printf("\033[92mCable is fine!\033[0m\n", settings.portStatistics[n].errorDist); + } } } -- 2.39.5