]> git.sur5r.net Git - gsconf/commitdiff
added sys [name|password|restart] and vlan enable
authoradvielsack@gmail.com <advielsack@gmail.com@11042eb7-4a36-49e9-8ab2-01d26d512705>
Sun, 8 Jan 2012 13:47:13 +0000 (13:47 +0000)
committeradvielsack@gmail.com <advielsack@gmail.com@11042eb7-4a36-49e9-8ab2-01d26d512705>
Sun, 8 Jan 2012 13:47:13 +0000 (13:47 +0000)
git-svn-id: http://gsconf.googlecode.com/svn/trunk@6 11042eb7-4a36-49e9-8ab2-01d26d512705

Makefile
gs105e.c
gs105e.h
shell.c
shell.h
shell_port.c
shell_sys.c [new file with mode: 0644]
shell_vlan.c

index 9e9fcf5b03b2155b5c083c621912bd74b0868161..c5481872b8f27580eea3d19f47ed817922e4573a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 CC=gcc
 CFLAGS=-I.
 DEPS = 
-OBJ = socket.o main.o gs105e.o shell.o shell_ip.o shell_vlan.o shell_port.o
+OBJ = socket.o main.o gs105e.o shell.o shell_ip.o shell_vlan.o shell_sys.o shell_port.o
 
 %.o: %.c $(DEPS)
        $(CC) -c -o $@ $< $(CFLAGS)
index bcd90080921b6882364ea5993c5a46071c8d11e2..a5b9aa60300345753050f02d0d3bcd3000ae9fae 100644 (file)
--- a/gs105e.c
+++ b/gs105e.c
@@ -90,7 +90,7 @@ void makeHeader(unsigned int queryType) {
         gs105e_queryData[1] = queryType % 256;
         
         memcpy(&gs105e_queryData[8], myMac, 6);
-        if (memcpy(settings.mac, "\x00\x00\x00\x00\x00\x00", 6))
+        if (memcmp(settings.mac, "\x00\x00\x00\x00\x00\x00", 6))
                 memcpy(&gs105e_queryData[14], settings.mac, 6);
         
         memcpy(&gs105e_queryData[24], "\x4e\x53\x44\x50", 4); //Magic!! :-O
@@ -226,6 +226,9 @@ void gs105e_interpret_slice(unsigned int ID, char * data, int len) {
                 case ACT_DHCP:;
                         settings.dhcp = data[1] & 0x03;
                         break;
+                case GS_VLANSETTING:;
+                        settings.vlanType = data[0];
+                        break;
         }
 }
 
@@ -304,7 +307,12 @@ int gs105e_actRecv(void) {
 }
 int gs105e_act() {
         gs105e_query();
-        return gs105e_actRecv();
+        int n = gs105e_actRecv();
+        if (n < 0){
+                gs105e_query();
+                n = gs105e_actRecv();
+        }
+        return n;
 }
 
 
@@ -351,7 +359,7 @@ int gs105e_restart(int vlanId) {
 
 int gs105e_mirrorPorts(int outputPort, int mirrorMask) {
         makeHeader(QR_EXEC);
-        char data[3] = {outputPort, 0,  mirrorMask};
+        char data[3] = {(char)outputPort, 0, (char) mirrorMask};
         
         addActData(ACT_PORTMIRROR, 3, data);
         return gs105e_act();
@@ -373,6 +381,14 @@ int gs105e_setName(char * data) {
         return gs105e_act();
 }
 
+int gs105e_setPassword(char * data) {
+        makeHeader(QR_EXEC);
+        
+        
+        addActData(GS_NEWPASSWORD, strlen(data), data);
+        return gs105e_act();
+}
+
 int gs105e_dhcpSettings(int action) {
         makeHeader(QR_EXEC);
         char data[1] = {(char)action};
@@ -381,6 +397,14 @@ int gs105e_dhcpSettings(int action) {
         return gs105e_act();
 }
 
+int gs105e_vlanEnable(void) {
+        makeHeader(QR_EXEC);
+        char data[1] = {4};
+        
+        addActData(GS_VLANSETTING, 1, data);
+        return gs105e_act();        
+}
+
 void addDiscoveredDevice(int id) {
         
         struct gs105e_discovered * ddev = gs105e_devs;
@@ -469,6 +493,7 @@ void gs105e_queryAll(void) {
         addQuery(ACT_DHCP);
         addQuery(GS_PORTSTATUS);        
         addQuery(GS_VLAN);
+        addQuery(GS_VLANSETTING);
         
         gs105e_query ();
          gs105e_receive();       
index e89828d405a9ae15c91c33406dfdec3af3c86bc3..f62e5e7555ede378c343dc38b638043f047d753a 100644 (file)
--- a/gs105e.h
+++ b/gs105e.h
@@ -21,6 +21,8 @@
 #define GS_PORTDIAG 0x1c00
 #define ACT_DHCP 0x000b
 
+#define GS_VLANSETTING 0x2000
+
 
 #define ACT_ADDVLAN 0x2800
 #define ACT_DELVLAN 0x2c00
@@ -85,6 +87,7 @@ struct gs105e_settings {
         char dhcp;
         
         struct vlan * vlans;
+        char vlanType;
         
 
         
@@ -115,6 +118,7 @@ struct gs105e_discovered * gs105e_devs ;
 struct gs105e_settings settings;
 
 void debug(void);
+int gs105e_setPassword(char * data);
 
 void gs105e_init(void) ;
 void makeHeader(unsigned int queryType);
diff --git a/shell.c b/shell.c
index eceb152184c93961feefddc1128a9671fb8de511..da91eb96aee2873730b9a4893567e1666be89bfa 100644 (file)
--- a/shell.c
+++ b/shell.c
@@ -77,10 +77,17 @@ void shell_set(char ** argv, int elem) {
         }
 }
 
+char * copyString(char * data) {
+        char * ret = (char * )malloc(strlen(data) + 1);
+        memcpy(ret, data, strlen(data) + 1);
+        ret[strlen(data)] = 0;
+        return ret;
+}
+
 void password(void) {
         if (settings.password == NULL) {
                printf("\033[91mWarning: As the protocol of the switch wants it that way, all configuration packets are send as broadcasts, meaning everyone on this net can sniff your password!\033[0m\n");
-                settings.password = getpass("Password: ");
+                settings.password = copyString(getpass("Password: "));
         }
 }
 
@@ -209,6 +216,10 @@ int shell (void) {
                         shell_port(argv, elem);
                 }
                 
+                if (strncmp(argv[0], "sys", 3) == 0) {
+                        shell_sys(argv, elem);
+                }
+                
 
                 
                 
diff --git a/shell.h b/shell.h
index 743062e8b8eb2cfc5ed9f645b86a616bc97f8ee8..111487b425c6dfb86c2aa4dcfd42afc8f1aa809c 100644 (file)
--- a/shell.h
+++ b/shell.h
 #include <pwd.h>
 
 void shell_ip(char ** argv, int elem);
-
+char * copyString(char * data);
 
 int shell(void);
 void password(void) ;
 void printError(int errCode);
 void printIp(char * data);
 void shell_port(char ** argv, int elem);
+void shell_sys(char ** argv, int elem);
 
 #endif
index 4e69179b58095fbc1e48779acfdb7a8c69d3b55e..d9400290b6afde6a028f8610eba95dc25b45054b 100644 (file)
@@ -2,7 +2,7 @@
 
 void shell_port(char ** argv, int elem) {
         
-        int n, i;
+        int n, i, m, o;
         
         if (elem == 1) {
         
@@ -48,5 +48,47 @@ void shell_port(char ** argv, int elem) {
                         else
                                 printf("\033[92mCable is fine!\033[0m\n", settings.portStatistics[n].errorDist);
                 }
+        } else if (strncmp(argv[1], "mirror", 6) == 0) {
+                
+                if (elem == 3) {
+                        if (strncmp(argv[2], "off", 3) == 0) {
+                                password();
+                                printError(gs105e_mirrorPorts(0, 0));
+                                return;
+                                
+                        }
+                }
+                
+                if (elem < 4) {
+                        printf("port mirror output input [input.....]\n");
+                        return;
+                }
+                
+                n = atoi(argv[2]);
+                
+                if (n < 1 | n > 5) {
+                        printf("Invalid Port %i\n", n);
+                        return;
+                }
+                
+                o = 0;
+                
+                for (m = 3; m < elem; m++) {
+                        i = atoi(argv[m]);
+                        if (i < 1 | i > 5) {
+                                printf("Invalid Port %i\n", i);
+                                return;
+                        }
+                        
+                        if (i == n) {
+                                printf("Output can't be input port!\n");
+                                return;
+                        }
+                        
+                        o |= (0x80 >> (i - 1));
+                }
+                password();
+                printError(gs105e_mirrorPorts(n, o));
+                
         }
 }
diff --git a/shell_sys.c b/shell_sys.c
new file mode 100644 (file)
index 0000000..c72b8f5
--- /dev/null
@@ -0,0 +1,52 @@
+#include "shell.h"
+
+
+
+void shell_sys(char ** argv, int elem) {
+        int n, i, m, o;
+        
+        if (elem == 1) {
+                printf("\n");
+                return;
+        }
+        
+        if (strncmp(argv[1], "show", 4) == 0) {
+                printf("Name: \t\t%s\n", settings.name);
+                printf("Model: \t\t%s\n", settings.model);
+                printf("SW-Version:\t %s\n", settings.swVersion);
+        }else if (strncmp(argv[1], "name", 4) == 0) {
+                if (elem != 3) {
+                        printf("Please provide a name\n");
+                        return;
+                }
+                
+                password();
+                printError(gs105e_setName(argv[2]));
+                
+        }else if (strncmp(argv[1], "password", 4) == 0) {
+        
+                password();
+                
+                char * newPwd = copyString(getpass("New Password: "));
+                if (strlen(newPwd) == 0) {
+                        printf("Password musst be at least one character!\n");
+                        return;
+                }
+                char * newPwdConf = copyString(getpass("New Password: "));
+                printf("%p %p\n", settings.password, newPwd);
+                if (strncmp(newPwd, newPwdConf, strlen(newPwd)) == 0 && strlen(newPwd) == strlen(newPwdConf)) {
+                        int e = gs105e_setPassword(newPwd);
+                        printError(e);
+                        if (e != 0)
+                                return;
+                        settings.password = newPwd;
+                }else {
+                        printf("Passwords do not match!\n");
+                }
+        }else if (strncmp(argv[1], "restart", 4) == 0) {
+                password();
+                printError(gs105e_restart());
+        }
+        
+        
+}
index 83f004a0a0ba3d625a44c80e099f9e3f98263748..80dfcb102254c3e27e2043b1c266d1026a7321f8 100644 (file)
@@ -8,6 +8,18 @@ void shell_vlan(char ** argv, int elem) {
         
                 return;
         }
+        
+        if (strncmp(argv[1], "enable", 6) == 0) {
+                password();
+                printError(gs105e_vlanEnable());
+                return;
+        }
+        
+        if (settings.vlanType != 4) {
+                printf("Type vlan enable once to configure vlan\n");
+                return;
+        }
+        
         if (strncmp(argv[1], "show", 4) == 0) {
                 struct vlan * vl = settings.vlans;