]> git.sur5r.net Git - gsconf/commitdiff
added port diag command
authoradvielsack@gmail.com <advielsack@gmail.com@11042eb7-4a36-49e9-8ab2-01d26d512705>
Sat, 7 Jan 2012 12:01:32 +0000 (12:01 +0000)
committeradvielsack@gmail.com <advielsack@gmail.com@11042eb7-4a36-49e9-8ab2-01d26d512705>
Sat, 7 Jan 2012 12:01:32 +0000 (12:01 +0000)
git-svn-id: http://gsconf.googlecode.com/svn/trunk@5 11042eb7-4a36-49e9-8ab2-01d26d512705

gs105e.c
main.c
shell.c
shell_port.c

index ccee5d759a646cd01891a1c4f79783441ccb3cc5..bcd90080921b6882364ea5993c5a46071c8d11e2 100644 (file)
--- 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 2e39ff0bb351218da205a1f89d40c81c213196a8..3150ae7f008bcdab9120349359ae00180783af4a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -8,10 +8,7 @@
 #include <pwd.h>
 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 284acc0528ff39baf070facf15116127a7ea74d8..eceb152184c93961feefddc1128a9671fb8de511 100644 (file)
--- 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;
index 258d966a37a0db7363d0e30d1e42f025e2c3ff7d..4e69179b58095fbc1e48779acfdb7a8c69d3b55e 100644 (file)
@@ -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);
+                }
         }
 }