2 * bridge.c from Access Point SNMP Utils for Linux
4 * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
5 * Copyright (c) 2005 Jan Rafaj <jr-aputils at cedric dot unob dot cz>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License Version 2 from
9 * June 1991 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <sys/types.h>
27 #define IPADDR _("[I] IP: ")
28 #define NETMASK _("[N] Netmask: ")
29 #define GATEWAY _("[G] Gateway: ")
30 #define IP_FILTER _("[F] Filter non-IP traffic: ")
31 #define PR_PORT _("[P] Primary port: ")
32 #define SB_ATTMAC _("Attached station MAC: ")
33 #define DHCP _("[D] DHCP client: ")
34 #define OPER _("[O] Operational mode: ")
35 #define REMOTE_MAC _("[M] Preferred BSSID (remote MAC addr.): ")
36 #define CF_PORT _("[C] Configuration-enabled port(s): ")
37 #define TRAP_PORT _("[T] Trap-sending port: ")
38 #define FW_BCAST _("[R] Forward broadcast traffic: ")
39 #define SB_BCAST _("[B] Isolate wireless clients (broadcast traffic): ")
40 #define SB_UCAST _("[U] Isolate wireless clients (unicast traffic): ")
41 #define HELP _("INGFPDOMSCRBUT - set; W - write conf; Q - quit to menu")
43 extern short ap_type, ap_vendorext;
49 char *bridge_modes[6] = {
50 _("Wireless Bridge Point to MultiPoint"),
52 _("Access Point client"),
53 _("Wireless Bridge Point to Point"),
58 char sysTrapSwitch[] = {
59 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x03, 0x00
62 char operIPAddress[] = {
63 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x01, 0x00
66 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x02, 0x00
68 char operEthernetAddress[] = {
69 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x03, 0x00
71 char operGateway[] = {
72 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x04, 0x00
75 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x05, 0x00
77 char operPrimaryPort[] = {
78 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x06, 0x00
81 /* This one is ATMEL410 SBRIDGES MIB and ATMEL12350 all MIBs specific. */
82 char operConfigurationPort[] = {
83 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x07, 0x00
86 /* This one is ATMEL12350 GEMTEK MIB and ATMEL12350 EZYNET MIB specific. */
87 char operTrapPort[] = {
88 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x02, 0x08, 0x00
91 char operIPFilter[] = {
92 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x01, 0x00
95 /* These 3 are ATMEL410 SBRIDGES MIB and ATMEL12350 all MIBs specific. */
96 char operForwarbBcast[] = {
97 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x02, 0x00
99 char operSendBackBcast[] = {
100 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x03, 0x00
102 char operSendBackUnicast[] = {
103 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x04, 0x00
106 char bridgeOperationalMode[] = {
107 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01, 0x00
109 char bridgeRemoteBridgeBSSID[] = {
110 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x02, 0x00
113 extern WINDOW *main_sub;
114 varbind varbinds[15];
115 struct in_addr ip, mask, gw;
116 unsigned char message[1024], filter, primary_port, dhcp, RemoteBSSID[6],
117 bridge_mode, traps, config_port, fw_bcast, sb_bcast,
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 *pr_ports[2] = {
128 _("Wireless (can be risky)"),
132 unsigned int trap_port = 0;
134 if (ap_type == ATMEL12350) {
135 sysTrapSwitch[5] = 0xE0;
136 sysTrapSwitch[6] = 0x3E;
137 operIPAddress[5] = 0xE0;
138 operIPAddress[6] = 0x3E;
139 operIPMask[5] = 0xE0;
140 operIPMask[6] = 0x3E;
141 operEthernetAddress[5] = 0xE0;
142 operEthernetAddress[6] = 0x3E;
143 operGateway[5] = 0xE0;
144 operGateway[6] = 0x3E;
147 operPrimaryPort[5] = 0xE0;
148 operPrimaryPort[6] = 0x3E;
149 operConfigurationPort[5] = 0xE0;
150 operConfigurationPort[6] = 0x3E;
151 operIPFilter[5] = 0xE0;
152 operIPFilter[6] = 0x3E;
153 operForwarbBcast[5] = 0xE0;
154 operForwarbBcast[6] = 0x3E;
155 operSendBackBcast[5] = 0xE0;
156 operSendBackBcast[6] = 0x3E;
157 operSendBackUnicast[5] = 0xE0;
158 operSendBackUnicast[6] = 0x3E;
159 bridgeOperationalMode[5] = 0xE0;
160 bridgeOperationalMode[6] = 0x3E;
161 bridgeRemoteBridgeBSSID[5] = 0xE0;
162 bridgeRemoteBridgeBSSID[6] = 0x3E;
165 for (i = 0; i < 15; i++) {
166 varbinds[i].type = NULL_VALUE;
167 varbinds[i].len_val = 0;
168 varbinds[i].len_oid = sizeof(sysTrapSwitch);
173 varbinds[i++].oid = sysTrapSwitch;
174 varbinds[i++].oid = operIPAddress;
175 varbinds[i++].oid = operIPMask;
176 varbinds[i++].oid = operEthernetAddress;
177 varbinds[i++].oid = operGateway;
178 varbinds[i++].oid = operDHCP;
179 varbinds[i++].oid = operPrimaryPort;
180 varbinds[i++].oid = operIPFilter;
181 varbinds[i++].oid = bridgeOperationalMode;
182 varbinds[i++].oid = bridgeRemoteBridgeBSSID;
183 if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
184 (ap_type == ATMEL12350)) {
185 varbinds[i++].oid = operConfigurationPort;
186 varbinds[i++].oid = operForwarbBcast;
187 varbinds[i++].oid = operSendBackBcast;
188 varbinds[i++].oid = operSendBackUnicast;
190 if (ap_type == ATMEL12350 &&
191 (ap_vendorext == GEMTEK || ap_vendorext == EZYNET)) {
192 varbinds[i++].oid = operTrapPort;
195 print_help(WAIT_RET);
196 if (snmp(varbinds, i, GET) < i) {
197 print_helperr(ERR_RET);
201 print_top(NULL, _("Bridging"));
203 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
204 varbinds[3].value[0] & 0xFF,
205 varbinds[3].value[1] & 0xFF,
206 varbinds[3].value[2] & 0xFF,
207 varbinds[3].value[3] & 0xFF,
208 varbinds[3].value[4] & 0xFF,
209 varbinds[3].value[5] & 0xFF);
210 mvwaddstr(main_sub, 0, 0, message);
212 memcpy(&ip.s_addr, varbinds[1].value, 4);
213 sprintf(message, "%s%s", IPADDR, inet_ntoa(ip));
214 mvwaddstr(main_sub, 1, 0, message);
216 memcpy(&mask.s_addr, varbinds[2].value, 4);
217 sprintf(message, "%s%s", NETMASK, inet_ntoa(mask));
218 mvwaddstr(main_sub, 1, 24, message);
220 memcpy(&gw.s_addr, varbinds[4].value, 4);
221 sprintf(message, "%s%s", GATEWAY, inet_ntoa(gw));
222 mvwaddstr(main_sub, 2, 0, message);
224 filter = *(varbinds[7].value);
225 sprintf(message, "%s%s", IP_FILTER, (filter == 1) ? ON : OFF);
226 mvwaddstr(main_sub, 3, 0, message);
229 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
230 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", SB_ATTMAC,
231 *(varbinds[6].value +0) & 0xFF, *(varbinds[6].value +1) & 0xFF,
232 *(varbinds[6].value +2) & 0xFF, *(varbinds[6].value +3) & 0xFF,
233 *(varbinds[6].value +4) & 0xFF, *(varbinds[6].value +5) & 0xFF);
236 primary_port = *(varbinds[6].value);
237 if (primary_port < 1 || primary_port > 2) {
240 sprintf(message, "%s%s", PR_PORT, pr_ports[primary_port - 1]);
244 mvwaddstr(main_sub, 4, 0, message);
246 dhcp = *(varbinds[5].value);
247 sprintf(message, "%s%s", DHCP, (dhcp == 1) ? ON : OFF);
248 mvwaddstr(main_sub, 5, 0, message);
250 memcpy(RemoteBSSID, varbinds[9].value, 6);
251 if ((bridge_mode = *(varbinds[8].value)) != 2) {
252 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", REMOTE_MAC,
253 *(RemoteBSSID + 0) & 0xFF, *(RemoteBSSID + 1) & 0xFF,
254 *(RemoteBSSID + 2) & 0xFF, *(RemoteBSSID + 3) & 0xFF,
255 *(RemoteBSSID + 4) & 0xFF, *(RemoteBSSID + 5) & 0xFF);
256 mvwaddstr(main_sub, 7, 0, message);
260 sprintf(message, "%s%s", OPER, bridge_modes[bridge_mode - 1]);
261 mvwaddstr(main_sub, 6, 0, message);
263 traps = *(varbinds[0].value);
264 sprintf(message, "%s%s", TRAPS, (traps == 1) ? ON : OFF);
265 mvwaddstr(main_sub, 8, 0, message);
267 if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
268 ap_type == ATMEL12350) {
269 config_port = *(varbinds[10].value);
270 if (config_port == 0) /* happens with ATMEL12350 EZYNET firmware only */
272 sprintf(message, "%s%s", CF_PORT, cf_ports[config_port - 1]);
273 mvwaddstr(main_sub, 9, 0, message);
275 fw_bcast = *(varbinds[11].value);
276 sprintf(message, "%s%s", FW_BCAST, (fw_bcast == 1) ? ON : OFF);
277 mvwaddstr(main_sub, 10, 0, message);
279 sb_bcast = *(varbinds[12].value);
280 sprintf(message, "%s%s", SB_BCAST, (sb_bcast == 1) ? ON : OFF);
281 mvwaddstr(main_sub, 11, 0, message);
283 sb_ucast = *(varbinds[13].value);
284 sprintf(message, "%s%s", SB_UCAST, (sb_ucast == 1) ? ON : OFF);
285 mvwaddstr(main_sub, 12, 0, message);
288 if (ap_type == ATMEL12350 &&
289 (ap_vendorext == GEMTEK || ap_vendorext == EZYNET)) {
290 for (i = 0; i < varbinds[14].len_val;
291 trap_port += varbinds[14].value[i] *
292 (1 << ((varbinds[14].len_val - i - 1) * 8)), i++);
293 sprintf(message, "%s%u", TRAP_PORT, trap_port);
294 mvwaddstr(main_sub, 13, 0, message);
305 get_ip(&ip, 1, strlen(IPADDR), HELP);
310 get_mask(&mask, 1, strlen(IPADDR) + 16 + strlen(NETMASK), HELP);
315 get_ip(&gw, 2, strlen(GATEWAY), HELP);
320 filter = on_off(3, strlen(IP_FILTER));
321 clear_main_new(3, 4);
322 print_menusel(3, 0, IP_FILTER, (filter == 1) ? ON : OFF);
328 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES)
331 primary_port = menu_choose(4, strlen(PR_PORT), pr_ports, 2) + 1;
332 clear_main_new(4, 5);
333 print_menusel(4, 0, PR_PORT, pr_ports[primary_port - 1]);
338 dhcp = on_off(5, strlen(DHCP));
339 clear_main_new(5, 6);
340 print_menusel(5, 0, DHCP, (dhcp == 1) ? ON : OFF);
345 bridge_mode = menu_choose(6, strlen(OPER), bridge_modes, 5) + 1;
346 clear_main_new(6, 8);
347 print_menusel(6, 0, OPER, bridge_modes[bridge_mode - 1]);
348 if (bridge_mode != 2) {
349 sprintf(message, "%02X%02X%02X%02X%02X%02X",
350 *(RemoteBSSID + 0) & 0xFF,
351 *(RemoteBSSID + 1) & 0xFF,
352 *(RemoteBSSID + 2) & 0xFF,
353 *(RemoteBSSID + 3) & 0xFF,
354 *(RemoteBSSID + 4) & 0xFF,
355 *(RemoteBSSID + 5) & 0xFF);
356 print_menusel(7, 0, REMOTE_MAC, message);
362 if (bridge_mode == 2)
365 get_mac(RemoteBSSID, 7, strlen(REMOTE_MAC));
366 /* mvwaddstr(main_sub, 7, 21, " : : : : : ");
367 for (i = 0; i < 6; i++) {
368 get_value(message, 7, 21 + i * 3, 3, ANY_STRING, 0, 0, NULL);
369 RemoteBSSID[i] = strtol(message, NULL, 16);
371 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", REMOTE_MAC,
372 *(RemoteBSSID + 0) & 0xFF, *(RemoteBSSID + 1) & 0xFF,
373 *(RemoteBSSID + 2) & 0xFF, *(RemoteBSSID + 3) & 0xFF,
374 *(RemoteBSSID + 4) & 0xFF, *(RemoteBSSID + 5) & 0xFF);
380 traps = on_off(8, strlen(TRAPS));
381 clear_main_new(8, 9);
382 print_menusel(8, 0, TRAPS, (traps == 1) ? ON : OFF);
387 if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
388 ap_type == ATMEL12350) {
389 config_port = menu_choose(9, strlen(CF_PORT), cf_ports, 3) + 1;
390 clear_main_new(9, 10);
391 print_menusel(9, 0, CF_PORT, cf_ports[config_port - 1]);
397 if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
398 ap_type == ATMEL12350) {
399 fw_bcast = on_off(10, strlen(FW_BCAST));
400 clear_main_new(10, 11);
401 print_menusel(10, 0, FW_BCAST, (fw_bcast == 1) ? ON : OFF);
407 if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
408 ap_type == ATMEL12350) {
409 sb_bcast = on_off(11, strlen(SB_BCAST));
410 clear_main_new(11, 12);
411 print_menusel(11, 0, SB_BCAST, (sb_bcast == 1) ? ON : OFF);
417 if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
418 ap_type == ATMEL12350) {
419 sb_ucast = on_off(12, strlen(SB_UCAST));
420 clear_main_new(12, 13);
421 print_menusel(12, 0, SB_UCAST, (sb_ucast == 1) ? ON : OFF);
427 if (ap_type == ATMEL12350 &&
428 (ap_vendorext == GEMTEK || ap_vendorext == EZYNET)) {
429 get_value(message, 13, strlen(TRAP_PORT), 6, INT_STRING,
431 trap_port = atoi(message);
439 varbinds[i].oid = operIPFilter;
440 varbinds[i].len_oid = sizeof(operIPFilter);
441 varbinds[i].type = INT_VALUE;
442 varbinds[i].value = (char *) &filter;
443 varbinds[i].len_val = 1;
446 if (m_primary_port) {
447 varbinds[i].oid = operPrimaryPort;
448 varbinds[i].len_oid = sizeof(operPrimaryPort);
449 varbinds[i].type = INT_VALUE;
450 varbinds[i].value = (char *) &primary_port;
451 varbinds[i].len_val = 1;
455 varbinds[i].oid = operDHCP;
456 varbinds[i].len_oid = sizeof(operDHCP);
457 varbinds[i].type = INT_VALUE;
458 varbinds[i].value = (char *) &dhcp;
459 varbinds[i].len_val = 1;
463 varbinds[i].oid = operIPAddress;
464 varbinds[i].len_oid = sizeof(operIPAddress);
465 ip.s_addr = htonl(ip.s_addr);
466 ip.s_addr = swap4(ip.s_addr);
467 varbinds[i].value = (char *) &ip.s_addr;
468 varbinds[i].len_val = 4;
469 varbinds[i].type = INT_VALUE;
473 varbinds[i].oid = operIPMask;
474 varbinds[i].len_oid = sizeof(operIPMask);
475 mask.s_addr = htonl(mask.s_addr);
476 mask.s_addr = swap4(mask.s_addr);
477 varbinds[i].value = (char *) &mask.s_addr;
478 varbinds[i].len_val = 4;
479 varbinds[i].type = INT_VALUE;
483 varbinds[i].oid = operGateway;
484 gw.s_addr = htonl(gw.s_addr);
485 gw.s_addr = swap4(gw.s_addr);
486 varbinds[i].len_oid = sizeof(operGateway);
487 varbinds[i].value = (char *) &gw.s_addr;
488 varbinds[i].len_val = 4;
489 varbinds[i].type = INT_VALUE;
493 varbinds[i].oid = sysTrapSwitch;
494 varbinds[i].len_oid = sizeof(sysTrapSwitch);
495 varbinds[i].value = &traps;
496 varbinds[i].len_val = 1;
497 varbinds[i].type = INT_VALUE;
501 varbinds[i].oid = bridgeOperationalMode;
502 varbinds[i].len_oid = sizeof(bridgeOperationalMode);
503 varbinds[i].value = (char *) &bridge_mode;
504 varbinds[i].len_val = 1;
505 varbinds[i].type = INT_VALUE;
508 if (m_remote_bssid) {
509 varbinds[i].oid = bridgeRemoteBridgeBSSID;
510 varbinds[i].len_oid = sizeof(bridgeRemoteBridgeBSSID);
511 varbinds[i].value = RemoteBSSID;
512 varbinds[i].len_val = 6;
513 varbinds[i].type = STRING_VALUE;
517 varbinds[i].oid = operConfigurationPort;
518 varbinds[i].len_oid = sizeof(operConfigurationPort);
519 varbinds[i].type = INT_VALUE;
520 varbinds[i].value = (char *) &config_port;
521 varbinds[i].len_val = 1;
525 varbinds[i].oid = operForwarbBcast;
526 varbinds[i].len_oid = sizeof(operForwarbBcast);
527 varbinds[i].type = INT_VALUE;
528 varbinds[i].value = (char *) &fw_bcast;
529 varbinds[i].len_val = 1;
533 varbinds[i].oid = operSendBackBcast;
534 varbinds[i].len_oid = sizeof(operSendBackBcast);
535 varbinds[i].type = INT_VALUE;
536 varbinds[i].value = (char *) &sb_bcast;
537 varbinds[i].len_val = 1;
541 varbinds[i].oid = operSendBackUnicast;
542 varbinds[i].len_oid = sizeof(operSendBackUnicast);
543 varbinds[i].type = INT_VALUE;
544 varbinds[i].value = (char *) &sb_ucast;
545 varbinds[i].len_val = 1;
551 len_val = (trap_port > 0x7fff) ? 3 : (trap_port > 0x7f) ? 2 : 1;
552 varbinds[i].oid = operTrapPort;
553 varbinds[i].len_oid = sizeof(operTrapPort);
554 varbinds[i].type = STRING_VALUE;
555 varbinds[i].value = (char *) &trap_port;
556 varbinds[i].len_val = len_val;
560 print_help(WAIT_SET);
561 if (snmp(varbinds, i, SET) <= 0) {
562 print_helperr(ERR_SET);
564 wbkgd(main_sub, A_NORMAL);
566 print_help(DONE_SET);
578 print_top(NULL, NULL);