]> git.sur5r.net Git - gsconf/blob - shell_port.c
A bunch of fixes for various compiler warnings
[gsconf] / shell_port.c
1 #include "shell.h"
2
3 void shell_port(char ** argv, int elem) {
4         
5         int n, i, m, o;
6         
7         if (elem == 1) {
8                 printf(" port [show|diag|mirror] \n");
9                 return;
10         }
11         if (strncmp(argv[1], "show", 4) == 0) {
12                 printf("Port\tSpeed\t\tBytes In\t\tBytes Out\n");
13                 for (n = 0; n< 5; n++) {
14                         printf("%i\t%s\t%8lu\t\t%8lu\n", n,
15                         (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 Cable": "???")))),
16                         settings.portStatistics[n].bytesIn,
17                         settings.portStatistics[n].bytesOut
18                         );
19                 }
20         } else if (strncmp(argv[1], "diag", 4) == 0) {
21                 if (elem != 3) {
22                         printf("Port needed\n");
23                         return;
24                 }
25                 
26                 n = atoi(argv[2]);
27                 
28                 if ((n < 1) | (n > 5)) {
29                         printf("Invalid Port\n");
30                         return;
31                 }
32                 
33                 password();
34                 i = gs105e_cableDiagnostics((char) n);
35                 
36                 printError(i);
37                 if (i != 0)
38                         return;
39                 if (settings.portStatistics[n].cableError) {
40                         printf("\033[91mError detected: %s in %i m\033[0m\n", 
41                         (settings.portStatistics[n].cableError == 0x03 ? "short circuit" : (settings.portStatistics[n].cableError == 0x02 ? "Only one pair Connected!": "damaged")),
42                         settings.portStatistics[n].errorDist
43                         );
44                         
45                 }else{
46                         if (settings.portStatistics[n].errorDist == 0 )
47                                 printf("\033[92mSeems no Cable is connected!?\033[0m\n");
48                         else
49                                 printf("\033[92mCable is fine!\033[0m\n", settings.portStatistics[n].errorDist);
50                 }
51         } else if (strncmp(argv[1], "mirror", 6) == 0) {
52                 
53                 if (elem == 3) {
54                         if (strncmp(argv[2], "off", 3) == 0) {
55                                 password();
56                                 printError(gs105e_mirrorPorts(0, 0));
57                                 return;
58                                 
59                         }
60                 }
61                 
62                 if (elem < 4) {
63                         printf("port mirror output input [input.....]\n");
64                         return;
65                 }
66                 
67                 n = atoi(argv[2]);
68                 
69                 if ((n < 1) | (n > 5)) {
70                         printf("Invalid Port %i\n", n);
71                         return;
72                 }
73                 
74                 o = 0;
75                 
76                 for (m = 3; m < elem; m++) {
77                         i = atoi(argv[m]);
78                         if ((i < 1) | (i > 5)) {
79                                 printf("Invalid Port %i\n", i);
80                                 return;
81                         }
82                         
83                         if (i == n) {
84                                 printf("Output can't be input port!\n");
85                                 return;
86                         }
87                         
88                         o |= (0x80 >> (i - 1));
89                 }
90                 password();
91                 printError(gs105e_mirrorPorts(n, o));
92                 
93         }
94 }