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;
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];
}
}
}
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();
}
#include <pwd.h>
int shellHandler = 0;
-/*void shellHandlers[] = {
-
-}*/
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);
-
- */
}
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;
void shell_port(char ** argv, int elem) {
- int n;
+ int n, i;
if (elem == 1) {
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);
+ }
}
}