A bunch of fixes for various compiler warnings
[gsconf] / shell_vlan.c
1 #include "shell.h"
2
3 void shell_vlan(char ** argv, int elem) {
4
5         int n, m, o;
6         
7         if (elem == 1) {
8                 printf(" vlan [show|enable|show|add|del|assign|revoke] \n");
9                 return;
10         }
11         
12         if (strncmp(argv[1], "enable", 6) == 0) {
13                 password();
14                 printError(gs105e_vlanEnable());
15                 return;
16         }
17         
18         if (settings.vlanType != 4) {
19                 printf("Type vlan enable once to configure vlan\n");
20                 return;
21         }
22         
23         if (strncmp(argv[1], "show", 4) == 0) {
24                 struct vlan * vl = settings.vlans;
25                 
26                 if (vl == NULL) {
27                         printf("NO Vlans\n");
28                         return;
29                 } else
30                         printf("Vlans\n");
31                 
32                 while (vl != NULL) {
33                         printf("%u\t", vl->id);
34                         for (n = 0; n < 5; n++)
35                                 printf("%s\t", vl->members & (0x80 >> n) ? (vl->tag & (0x80 >> n) ? "\033[93mT\033[0m" : "\033[92mU\033[0m") : "\033[91m-\033[0m" /*, (unsigned int) vl->members*/);
36                         printf("\n");
37                         vl = vl->next;
38                 }
39                 
40         }else if (strncmp(argv[1], "add", 3) == 0) {
41                 if (elem != 3) {
42                         printf("You need to provide a vlan ID to add!\n");
43                         return;
44                 }
45                 n = atoi(argv[2]);
46                 if (n <= 0) {
47                         printf("Invalid id!\n");
48                         return;
49                 }
50                 password();
51                 printError(gs105e_addVlan(n));
52         }else if (strncmp(argv[1], "del", 3) == 0) {
53                 
54                 if (elem != 3) {
55                         printf("You need to provide a vlan ID to add!\n");
56                         return;
57                 }
58                 n = atoi(argv[2]);
59                 
60                 struct vlan * vl = settings.vlans;
61                 
62                 while (vl != NULL) {
63                         if (vl->id == n)
64                                 break;
65                         vl = vl->next;
66                 }
67                 if (vl == NULL)
68                         n = 0;
69                 
70                 if (n <= 0) {
71                         printf("Invalid id!\n");
72                         return;
73                 }
74                 password();
75                 printError(gs105e_delVlan(n));
76         }else if (strncmp(argv[1], "assign", 6) == 0) {
77                 if (elem != 5) {
78                         printf("vlan assign [vlan ID] [port ID] [T|U]\n");
79                         return;
80                 }       
81                 int n = atoi(argv[2]);
82                 struct vlan * vl = settings.vlans;
83                 
84                 while (vl != NULL) {
85                         if (vl->id == n)
86                                 break;
87                         vl = vl->next;
88                 }
89                 if (vl == NULL)
90                         n = 0;
91                 
92                 if (n <= 0) {
93                         printf("Invalid Vlan ID\n");
94                         return;
95                 }
96                 
97                 m = atoi(argv[3]);
98                 
99                 if ((m < 1) | (m > 5)) {
100                         printf("Invalid Port ID\n");
101                         return;
102                 }         
103                 o = m;
104                 m  = (0x80 >> ((m & 0xFF) - 1))  | (int)vl->members;
105                 printf("%i  %i\n", (int)vl->tag, (unsigned int)(~((unsigned char)m)));
106                 if (strncmp(argv[4], "T", 1) == 0) {
107                         o = (int)vl->tag | (0x80 >> ((o & 0xFF) - 1));
108                 }else if (strncmp(argv[4], "U", 1) == 0) {
109                         o = (int)vl->tag &(~((0x80 >> ((o & 0xFF) - 1))));
110                 }
111                 password();
112                 printError(gs105e_setVlanMembers(n, m, o));
113                 
114         }else if (strncmp(argv[1], "revoke", 6) == 0) {
115                 if (elem != 4) {
116                         printf("vlan revoke [vlan ID] [port ID]\n");
117                         return;
118                 }       
119                 int n = atoi(argv[2]);
120                 struct vlan * vl = settings.vlans;
121                 
122                 while (vl != NULL) {
123                         if (vl->id == n)
124                                 break;
125                         vl = vl->next;
126                 }
127                 if (vl == NULL)
128                         n = 0;
129                 
130                 if (n <= 0) {
131                         printf("Invalid Vlan ID\n");
132                         return;
133                 }
134                 
135                 m = atoi(argv[3]);
136                 
137                 if ((m < 1) | (m > 5)) {
138                         printf("Invalid Port ID\n");
139                         return;
140                 }         
141                 
142                 m  = (~(0x80 >> ((m & 0xFF) - 1)))  & (int)vl->members;
143                 
144
145                 o = (int)vl->tag &(~((char)m));
146
147                 password();
148                 printError(gs105e_setVlanMembers(n, m, o));
149                 
150         }
151 }