2 * bridge.c from Access Point SNMP Utils for Linux
4 * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License Version 2 from
8 * June 1991 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <sys/types.h>
26 #define IPADDR _("[I] IP: ")
27 #define NETMASK _("[N] Netmask: ")
28 #define GATEWAY _("[G] Gateway: ")
29 #define IP_FILTER _("[F] Filter non-IP traffic: ")
30 #define PR_PORT _("[P] Primary port: ")
31 #define SB_ATTMAC _("Attached station MAC: ")
32 #define DHCP _("[D] DHCP client: ")
33 #define OPER _("[O] Operational mode: ")
34 #define REMOTE_MAC _("[M] Preferred BSSID (remote MAC addr.): ")
35 //#define CF_PORT _("[C] Configuration-enabled port(s): ")
36 #define TRAP_PORT _("[T] Trap-sending port(s): ")
37 #define FW_BCAST _("[R] Forward broadcast traffic: ")
38 //#define SB_BCAST _("[B] Isolate wireless clients (broadcast traffic): ")
39 #define SB_UCAST _("[U] Isolate wireless clients: ")
40 #define HELP _("INGFPDOMSCTRBU - set; W - write conf; Q - quit to menu")
47 char sysTrapSwitch[] =
48 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x03,
52 char operIPAddress[] =
53 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x01,
57 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x02,
60 char operEthernetAddress[] =
61 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x03,
65 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x04,
69 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x05,
73 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x06,
76 /* char ConfigPort[] =
77 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x02, 0x07,
80 */ /* This one is ATMEL12350 TELLUS MIB specific. */
82 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x02, 0x08,
87 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x01,
91 /* These 3 are ATMEL12350 MIB specific. */
92 char ForwardBroadcast[] =
93 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x02,
96 char SendBackBcast[] =
97 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x03,
100 char SendBackUnicast[] =
101 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x04,
105 char bridgeOperationalMode[] =
106 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01,
109 char bridgeRemoteBridgeBSSID[] =
110 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x02,
114 extern WINDOW *main_sub;
115 varbind varbinds[15];
116 struct in_addr ip, mask, gw;
117 unsigned char message[1024], filter, primary_port, dhcp, RemoteBSSID[6],
118 bridge_mode, traps, fw_bcast, sb_ucast;
119 char m_filter = 0, m_bridge_mode = 0, m_primary_port = 0, m_traps = 0,
120 m_dhcp = 0, m_ip = 0, m_mask = 0, m_gw = 0, m_remote_bssid = 0,
121 /*m_config_port = 0, */m_trap_port = 0, m_fw_bcast = 0, /*m_sb_bcast = 0,*/
123 char *bridge_modes[6] = {
124 _("Wireless Bridge Point to MultiPoint"),
126 _("Access Point client"),
127 _("Wireless Bridge Point to Point"),
133 } /*, *cf_trap_ports[3] = {
140 unsigned int trap_port = 0;
142 /* Determine the advanced MIB subtype of the device from its MAC address. */
143 varbinds[0].type = NULL_VALUE;
144 varbinds[0].oid = operEthernetAddress;
145 varbinds[0].len_oid = sizeof(operEthernetAddress);
146 varbinds[0].len_val = 0;
148 print_help(WAIT_RET);
149 /* if (snmp(varbinds, 1, GET) <= 0) {
150 print_helperr(ERR_RET);
154 for (i = 1; i < 15; i++) {
155 varbinds[i].type = NULL_VALUE;
156 varbinds[i].len_val = 0;
157 varbinds[i].len_oid = sizeof(sysTrapSwitch);
160 varbinds[1].oid = IPFilter;
161 varbinds[2].oid = PrimaryPort;
162 varbinds[3].oid = operDHCP;
163 varbinds[4].oid = operIPAddress;
164 varbinds[5].oid = operIPMask;
165 varbinds[6].oid = operGateway;
166 varbinds[7].oid = bridgeOperationalMode;
167 varbinds[8].oid = sysTrapSwitch;
168 varbinds[9].oid = bridgeRemoteBridgeBSSID;
169 varbinds[10].oid = ForwardBroadcast;
170 varbinds[11].oid = SendBackUnicast;
171 varbinds[12].oid = SendBackBcast;
173 if (snmp(varbinds, 13, GET) <= 0) {
174 print_helperr(ERR_RET);
178 print_top(NULL, _("Bridging"));
180 sb_ucast = *(varbinds[11].value);
181 // sb_ucast = varbinds[11].len_val;
182 sprintf(message, "%s%s", SB_UCAST, (sb_ucast == 2) ? ON : OFF);
183 mvwaddstr(main_sub, 10, 0, message);
187 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
188 varbinds[0].value[0] & 0xFF,
189 varbinds[0].value[1] & 0xFF,
190 varbinds[0].value[2] & 0xFF,
191 varbinds[0].value[3] & 0xFF,
192 varbinds[0].value[4] & 0xFF,
193 varbinds[0].value[5] & 0xFF);
194 mvwaddstr(main_sub, 0, 0, message);
196 filter = *(varbinds[1].value);
197 sprintf(message, "%s%s", IP_FILTER, (filter == 1) ? ON : OFF);
198 mvwaddstr(main_sub, 3, 0, message);
200 primary_port = *(varbinds[2].value);
201 if (primary_port < 1 || primary_port > 2) {
204 sprintf(message, "%s%s", PR_PORT, pr_ports[primary_port - 1]);
205 mvwaddstr(main_sub, 4, 0, message);
207 dhcp = *(varbinds[3].value);
208 sprintf(message, "%s%s", DHCP, (dhcp == 1) ? ON : OFF);
209 mvwaddstr(main_sub, 5, 0, message);
211 memcpy(&ip.s_addr, varbinds[4].value, 4);
212 sprintf(message, "%s%s", IPADDR, inet_ntoa(ip));
213 mvwaddstr(main_sub, 1, 0, message);
215 memcpy(&mask.s_addr, varbinds[5].value, 4);
216 sprintf(message, "%s%s", NETMASK, inet_ntoa(mask));
217 mvwaddstr(main_sub, 1, 24, message);
219 memcpy(&gw.s_addr, varbinds[6].value, 4);
220 sprintf(message, "%s%s", GATEWAY, inet_ntoa(gw));
221 mvwaddstr(main_sub, 2, 0, message);
223 memcpy(RemoteBSSID, varbinds[9].value, 6);
225 if ((bridge_mode = *(varbinds[7].value)) != 2) {
226 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", REMOTE_MAC,
227 *(RemoteBSSID + 0) & 0xFF, *(RemoteBSSID + 1) & 0xFF,
228 *(RemoteBSSID + 2) & 0xFF, *(RemoteBSSID + 3) & 0xFF,
229 *(RemoteBSSID + 4) & 0xFF, *(RemoteBSSID + 5) & 0xFF);
230 mvwaddstr(main_sub, 7, 0, message);
234 sprintf(message, "%s%s", OPER, bridge_modes[bridge_mode - 1]);
235 mvwaddstr(main_sub, 6, 0, message);
237 traps = *(varbinds[8].value);
238 sprintf(message, "%s%s", TRAPS, (traps == 1) ? ON : OFF);
239 mvwaddstr(main_sub, 8, 0, message);
241 fw_bcast = *(varbinds[10].value);
242 sprintf(message, "%s%s", FW_BCAST, (fw_bcast == 1) ? ON : OFF);
243 mvwaddstr(main_sub, 9, 0, message);
253 get_ip(&ip, 1, strlen(IPADDR), HELP);
258 get_mask(&mask, 1, strlen(IPADDR) + 16 + strlen(NETMASK), HELP);
263 get_ip(&gw, 2, strlen(GATEWAY), HELP);
268 filter = on_off(3, strlen(IP_FILTER));
269 clear_main_new(3, 4);
270 print_menusel(3, 0, IP_FILTER, (filter == 1) ? ON : OFF);
275 primary_port = menu_choose(4, strlen(PR_PORT), pr_ports, 2) + 1;
276 clear_main_new(4, 5);
277 print_menusel(4, 0, PR_PORT, pr_ports[primary_port - 1]);
282 dhcp = on_off(5, strlen(DHCP));
283 clear_main_new(5, 6);
284 print_menusel(5, 0, DHCP, (dhcp == 1) ? ON : OFF);
289 bridge_mode = menu_choose(6, strlen(OPER), bridge_modes, 5) + 1;
290 clear_main_new(6, 8);
291 print_menusel(6, 0, OPER, bridge_modes[bridge_mode - 1]);
292 if (bridge_mode != 2) {
293 sprintf(message, "%02X%02X%02X%02X%02X%02X",
294 *(RemoteBSSID + 0) & 0xFF,
295 *(RemoteBSSID + 1) & 0xFF,
296 *(RemoteBSSID + 2) & 0xFF,
297 *(RemoteBSSID + 3) & 0xFF,
298 *(RemoteBSSID + 4) & 0xFF,
299 *(RemoteBSSID + 5) & 0xFF);
300 print_menusel(7, 0, REMOTE_MAC, message);
306 if (bridge_mode == 2)
308 get_mac(RemoteBSSID, 7, strlen(REMOTE_MAC));
313 traps = on_off(8, strlen(TRAPS));
314 clear_main_new(8, 9);
315 print_menusel(8, 0, TRAPS, (traps == 1) ? ON : OFF);
320 config_port = menu_choose(9, strlen(CF_PORT), cf_trap_ports, 3);
321 clear_main_new(9, 10);
322 print_menusel(9, 0, CF_PORT, cf_trap_ports[config_port]);
327 fw_bcast = on_off(9, strlen(FW_BCAST));
328 clear_main_new(9, 10);
329 print_menusel(9, 0, FW_BCAST, (fw_bcast == 1) ? ON : OFF);
334 sb_bcast = on_off(12, strlen(SB_BCAST));
335 clear_main_new(12, 13);
336 print_menusel(12, 0, SB_BCAST, (sb_bcast == 1) ? ON : OFF);
341 sb_ucast = on_off(10, strlen(SB_UCAST));
342 sb_ucast = (sb_ucast == 2) ? 1 : 2;
343 clear_main_new(10, 11);
344 print_menusel(10, 0, SB_UCAST, (sb_ucast == 2) ? ON : OFF);
351 varbinds[i].oid = IPFilter;
352 varbinds[i].len_oid = sizeof(IPFilter);
353 varbinds[i].type = INT_VALUE;
354 varbinds[i].value = (char *) &filter;
355 varbinds[i].len_val = 1;
358 if (m_primary_port) {
359 varbinds[i].oid = PrimaryPort;
360 varbinds[i].len_oid = sizeof(PrimaryPort);
361 varbinds[i].type = INT_VALUE;
362 varbinds[i].value = (char *) &primary_port;
363 varbinds[i].len_val = 1;
367 varbinds[i].oid = operDHCP;
368 varbinds[i].len_oid = sizeof(operDHCP);
369 varbinds[i].type = INT_VALUE;
370 varbinds[i].value = (char *) &dhcp;
371 varbinds[i].len_val = 1;
375 varbinds[i].oid = operIPAddress;
376 varbinds[i].len_oid = sizeof(operIPAddress);
377 ip.s_addr = htonl(ip.s_addr);
378 ip.s_addr = swap4(ip.s_addr);
379 varbinds[i].value = (char *) &ip.s_addr;
380 varbinds[i].len_val = 4;
381 varbinds[i].type = INT_VALUE;
385 varbinds[i].oid = operIPMask;
386 varbinds[i].len_oid = sizeof(operIPMask);
387 mask.s_addr = htonl(mask.s_addr);
388 mask.s_addr = swap4(mask.s_addr);
389 varbinds[i].value = (char *) &mask.s_addr;
390 varbinds[i].len_val = 4;
391 varbinds[i].type = INT_VALUE;
395 varbinds[i].oid = operGateway;
396 gw.s_addr = htonl(gw.s_addr);
397 gw.s_addr = swap4(gw.s_addr);
398 varbinds[i].len_oid = sizeof(operGateway);
399 varbinds[i].value = (char *) &gw.s_addr;
400 varbinds[i].len_val = 4;
401 varbinds[i].type = INT_VALUE;
405 varbinds[i].oid = sysTrapSwitch;
406 varbinds[i].len_oid = sizeof(sysTrapSwitch);
407 varbinds[i].value = &traps;
408 varbinds[i].len_val = 1;
409 varbinds[i].type = INT_VALUE;
413 varbinds[i].oid = bridgeOperationalMode;
414 varbinds[i].len_oid = sizeof(bridgeOperationalMode);
415 varbinds[i].value = (char *) &bridge_mode;
416 varbinds[i].len_val = 1;
417 varbinds[i].type = INT_VALUE;
420 if (m_remote_bssid) {
421 varbinds[i].oid = bridgeRemoteBridgeBSSID;
422 varbinds[i].len_oid = sizeof(bridgeRemoteBridgeBSSID);
423 varbinds[i].value = RemoteBSSID;
424 varbinds[i].len_val = 6;
425 varbinds[i].type = STRING_VALUE;
428 /* if (m_config_port) {
429 varbinds[i].oid = ConfigPort;
430 varbinds[i].len_oid = sizeof(ConfigPort);
431 varbinds[i].type = INT_VALUE;
433 varbinds[i].value = (char *) &config_port;
434 varbinds[i].len_val = 1;
438 varbinds[i].oid = ForwardBroadcast;
439 varbinds[i].len_oid = sizeof(ForwardBroadcast);
440 varbinds[i].type = INT_VALUE;
441 varbinds[i].value = (char *) &fw_bcast;
442 varbinds[i].len_val = 1;
446 varbinds[i].oid = SendBackBcast;
447 varbinds[i].len_oid = sizeof(SendBackBcast);
448 varbinds[i].type = INT_VALUE;
449 varbinds[i].value = (char *) &sb_ucast;
450 varbinds[i].len_val = 1;
452 varbinds[i].oid = SendBackUnicast;
453 varbinds[i].len_oid = sizeof(SendBackUnicast);
454 varbinds[i].type = INT_VALUE;
455 varbinds[i].value = (char *) &sb_ucast;
456 varbinds[i].len_val = 1;
462 len_val = (trap_port > 0x7fff) ? 3 : (trap_port > 0x7f) ? 2 : 1;
463 varbinds[i].oid = TrapPort;
464 varbinds[i].len_oid = sizeof(TrapPort);
465 varbinds[i].type = STRING_VALUE;
466 varbinds[i].value = (char *) &trap_port;
467 varbinds[i].len_val = len_val;
471 print_help(WAIT_SET);
472 if (snmp(varbinds, i, SET) <= 0)
473 print_helperr(ERR_SET);
475 print_help(DONE_SET);
486 print_top(NULL, NULL);