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;
48 char sysTrapSwitch[] = {
49 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x03, 0x00
52 char operIPAddress[] = {
53 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x01, 0x00
56 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x02, 0x00
58 char operEthernetAddress[] = {
59 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x03, 0x00
61 char operGateway[] = {
62 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x04, 0x00
65 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x05, 0x00
67 char operPrimaryPort[] = {
68 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x06, 0x00
71 /* This one is ATMEL410 SBRIDGES MIB and ATMEL12350 all MIBs specific. */
72 char operConfigurationPort[] = {
73 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x07, 0x00
76 /* This one is ATMEL12350 GEMTEK MIB and ATMEL12350 EZYNET MIB specific. */
77 char operTrapPort[] = {
78 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x02, 0x08, 0x00
81 char operIPFilter[] = {
82 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x01, 0x00
85 char *bridge_modes[6] = {
86 _("Wireless Bridge Point to MultiPoint"),
88 _("Access Point client"),
89 _("Wireless Bridge Point to Point"),
94 /* These 3 are ATMEL410 SBRIDGES MIB and ATMEL12350 all MIBs specific. */
95 char operForwarbBcast[] = {
96 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x02, 0x00
98 char operSendBackBcast[] = {
99 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x03, 0x00
101 char operSendBackUnicast[] = {
102 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x04, 0x00
105 char bridgeOperationalMode[] = {
106 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01, 0x00
108 char bridgeRemoteBridgeBSSID[] = {
109 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x02, 0x00
112 extern WINDOW *main_sub;
113 varbind varbinds[15];
114 struct in_addr ip, mask, gw;
115 unsigned char message[1024], filter, primary_port, dhcp, RemoteBSSID[6],
116 bridge_mode, traps, config_port, fw_bcast, sb_bcast,
118 char m_filter = 0, m_bridge_mode = 0, m_primary_port = 0, m_traps = 0,
119 m_dhcp = 0, m_ip = 0, m_mask = 0, m_gw = 0, m_remote_bssid = 0,
120 m_config_port = 0, m_trap_port = 0, m_fw_bcast = 0, m_sb_bcast = 0,
122 char *pr_ports[2] = {
125 }, *cf_trap_ports[3] = {
128 _("Wireless (can be risky)")
131 unsigned int trap_port = 0;
133 if (ap_type == ATMEL12350) {
134 sysTrapSwitch[5] = 0xE0;
135 sysTrapSwitch[6] = 0x3E;
136 operIPAddress[5] = 0xE0;
137 operIPAddress[6] = 0x3E;
138 operIPMask[5] = 0xE0;
139 operIPMask[6] = 0x3E;
140 operEthernetAddress[5] = 0xE0;
141 operEthernetAddress[6] = 0x3E;
142 operGateway[5] = 0xE0;
143 operGateway[6] = 0x3E;
146 operPrimaryPort[5] = 0xE0;
147 operPrimaryPort[6] = 0x3E;
148 operConfigurationPort[5] = 0xE0;
149 operConfigurationPort[6] = 0x3E;
150 operIPFilter[5] = 0xE0;
151 operIPFilter[6] = 0x3E;
152 operForwarbBcast[5] = 0xE0;
153 operForwarbBcast[6] = 0x3E;
154 operSendBackBcast[5] = 0xE0;
155 operSendBackBcast[6] = 0x3E;
156 operSendBackUnicast[5] = 0xE0;
157 operSendBackUnicast[6] = 0x3E;
158 bridgeOperationalMode[5] = 0xE0;
159 bridgeOperationalMode[6] = 0x3E;
160 bridgeRemoteBridgeBSSID[5] = 0xE0;
161 bridgeRemoteBridgeBSSID[6] = 0x3E;
164 for (i = 0; i < 15; i++) {
165 varbinds[i].type = NULL_VALUE;
166 varbinds[i].len_val = 0;
167 varbinds[i].len_oid = sizeof(sysTrapSwitch);
172 varbinds[i++].oid = sysTrapSwitch;
173 varbinds[i++].oid = operIPAddress;
174 varbinds[i++].oid = operIPMask;
175 varbinds[i++].oid = operEthernetAddress;
176 varbinds[i++].oid = operGateway;
177 varbinds[i++].oid = operDHCP;
178 varbinds[i++].oid = operPrimaryPort;
179 varbinds[i++].oid = operIPFilter;
180 varbinds[i++].oid = bridgeOperationalMode;
181 varbinds[i++].oid = bridgeRemoteBridgeBSSID;
182 if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
183 (ap_type == ATMEL12350)) {
184 varbinds[i++].oid = operConfigurationPort;
185 varbinds[i++].oid = operForwarbBcast;
186 varbinds[i++].oid = operSendBackBcast;
187 varbinds[i++].oid = operSendBackUnicast;
189 if (ap_type == ATMEL12350 &&
190 (ap_vendorext == GEMTEK || ap_vendorext == EZYNET)) {
191 varbinds[i++].oid = operTrapPort;
194 print_help(WAIT_RET);
195 if (snmp(varbinds, i, GET) < i) {
196 print_helperr(ERR_RET);
200 print_top(NULL, _("Bridging"));
202 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
203 varbinds[3].value[0] & 0xFF,
204 varbinds[3].value[1] & 0xFF,
205 varbinds[3].value[2] & 0xFF,
206 varbinds[3].value[3] & 0xFF,
207 varbinds[3].value[4] & 0xFF,
208 varbinds[3].value[5] & 0xFF);
209 mvwaddstr(main_sub, 0, 0, message);
211 memcpy(&ip.s_addr, varbinds[1].value, 4);
212 sprintf(message, "%s%s", IPADDR, inet_ntoa(ip));
213 mvwaddstr(main_sub, 1, 0, message);
215 memcpy(&mask.s_addr, varbinds[2].value, 4);
216 sprintf(message, "%s%s", NETMASK, inet_ntoa(mask));
217 mvwaddstr(main_sub, 1, 24, message);
219 memcpy(&gw.s_addr, varbinds[4].value, 4);
220 sprintf(message, "%s%s", GATEWAY, inet_ntoa(gw));
221 mvwaddstr(main_sub, 2, 0, message);
223 filter = *(varbinds[7].value);
224 sprintf(message, "%s%s", IP_FILTER, (filter == 1) ? ON : OFF);
225 mvwaddstr(main_sub, 3, 0, message);
228 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
229 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", SB_ATTMAC,
230 *(varbinds[6].value +0) & 0xFF, *(varbinds[6].value +1) & 0xFF,
231 *(varbinds[6].value +2) & 0xFF, *(varbinds[6].value +3) & 0xFF,
232 *(varbinds[6].value +4) & 0xFF, *(varbinds[6].value +5) & 0xFF);
235 primary_port = *(varbinds[6].value);
236 if (primary_port < 1 || primary_port > 2) {
239 sprintf(message, "%s%s", PR_PORT, pr_ports[primary_port - 1]);
243 mvwaddstr(main_sub, 4, 0, message);
245 dhcp = *(varbinds[5].value);
246 sprintf(message, "%s%s", DHCP, (dhcp == 1) ? ON : OFF);
247 mvwaddstr(main_sub, 5, 0, message);
249 memcpy(RemoteBSSID, varbinds[9].value, 6);
250 if ((bridge_mode = *(varbinds[8].value)) != 2) {
251 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", REMOTE_MAC,
252 *(RemoteBSSID + 0) & 0xFF, *(RemoteBSSID + 1) & 0xFF,
253 *(RemoteBSSID + 2) & 0xFF, *(RemoteBSSID + 3) & 0xFF,
254 *(RemoteBSSID + 4) & 0xFF, *(RemoteBSSID + 5) & 0xFF);
255 mvwaddstr(main_sub, 7, 0, message);
259 sprintf(message, "%s%s", OPER, bridge_modes[bridge_mode - 1]);
260 mvwaddstr(main_sub, 6, 0, message);
262 traps = *(varbinds[0].value);
263 sprintf(message, "%s%s", TRAPS, (traps == 1) ? ON : OFF);
264 mvwaddstr(main_sub, 8, 0, message);
266 if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
267 ap_type == ATMEL12350) {
268 config_port = *(varbinds[10].value);
269 sprintf(message, "%s%s", CF_PORT, cf_trap_ports[config_port]);
270 mvwaddstr(main_sub, 9, 0, message);
272 fw_bcast = *(varbinds[11].value);
273 sprintf(message, "%s%s", FW_BCAST, (fw_bcast == 1) ? ON : OFF);
274 mvwaddstr(main_sub, 10, 0, message);
276 sb_bcast = *(varbinds[12].value);
277 sprintf(message, "%s%s", SB_BCAST, (sb_bcast == 1) ? ON : OFF);
278 mvwaddstr(main_sub, 11, 0, message);
280 sb_ucast = *(varbinds[13].value);
281 sprintf(message, "%s%s", SB_UCAST, (sb_ucast == 1) ? ON : OFF);
282 mvwaddstr(main_sub, 12, 0, message);
285 if (ap_type == ATMEL12350 &&
286 (ap_vendorext == GEMTEK || ap_vendorext == EZYNET)) {
287 for (i = 0; i < varbinds[14].len_val;
288 trap_port += varbinds[14].value[i] *
289 (1 << ((varbinds[14].len_val - i - 1) * 8)), i++);
290 sprintf(message, "%s%u", TRAP_PORT, trap_port);
291 mvwaddstr(main_sub, 13, 0, message);
302 get_ip(&ip, 1, strlen(IPADDR), HELP);
307 get_mask(&mask, 1, strlen(IPADDR) + 16 + strlen(NETMASK), HELP);
312 get_ip(&gw, 2, strlen(GATEWAY), HELP);
317 filter = on_off(3, strlen(IP_FILTER));
318 clear_main_new(3, 4);
319 print_menusel(3, 0, IP_FILTER, (filter == 1) ? ON : OFF);
325 if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES)
328 primary_port = menu_choose(4, strlen(PR_PORT), pr_ports, 2) + 1;
329 clear_main_new(4, 5);
330 print_menusel(4, 0, PR_PORT, pr_ports[primary_port - 1]);
335 dhcp = on_off(5, strlen(DHCP));
336 clear_main_new(5, 6);
337 print_menusel(5, 0, DHCP, (dhcp == 1) ? ON : OFF);
342 bridge_mode = menu_choose(6, strlen(OPER), bridge_modes, 5) + 1;
343 clear_main_new(6, 8);
344 print_menusel(6, 0, OPER, bridge_modes[bridge_mode - 1]);
345 if (bridge_mode != 2) {
346 sprintf(message, "%02X%02X%02X%02X%02X%02X",
347 *(RemoteBSSID + 0) & 0xFF,
348 *(RemoteBSSID + 1) & 0xFF,
349 *(RemoteBSSID + 2) & 0xFF,
350 *(RemoteBSSID + 3) & 0xFF,
351 *(RemoteBSSID + 4) & 0xFF,
352 *(RemoteBSSID + 5) & 0xFF);
353 print_menusel(7, 0, REMOTE_MAC, message);
359 if (bridge_mode == 2)
362 get_mac(RemoteBSSID, 7, strlen(REMOTE_MAC));
363 /* mvwaddstr(main_sub, 7, 21, " : : : : : ");
364 for (i = 0; i < 6; i++) {
365 get_value(message, 7, 21 + i * 3, 3, ANY_STRING, 0, 0, NULL);
366 RemoteBSSID[i] = strtol(message, NULL, 16);
368 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", REMOTE_MAC,
369 *(RemoteBSSID + 0) & 0xFF, *(RemoteBSSID + 1) & 0xFF,
370 *(RemoteBSSID + 2) & 0xFF, *(RemoteBSSID + 3) & 0xFF,
371 *(RemoteBSSID + 4) & 0xFF, *(RemoteBSSID + 5) & 0xFF);
377 traps = on_off(8, strlen(TRAPS));
378 clear_main_new(8, 9);
379 print_menusel(8, 0, TRAPS, (traps == 1) ? ON : OFF);
384 if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
385 ap_type == ATMEL12350) {
386 config_port = menu_choose(9, strlen(CF_PORT), cf_trap_ports, 3);
387 clear_main_new(9, 10);
388 print_menusel(9, 0, CF_PORT, cf_trap_ports[config_port]);
394 if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
395 ap_type == ATMEL12350) {
396 fw_bcast = on_off(10, strlen(FW_BCAST));
397 clear_main_new(10, 11);
398 print_menusel(10, 0, FW_BCAST, (fw_bcast == 1) ? ON : OFF);
404 if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
405 ap_type == ATMEL12350) {
406 sb_bcast = on_off(11, strlen(SB_BCAST));
407 clear_main_new(11, 12);
408 print_menusel(11, 0, SB_BCAST, (sb_bcast == 1) ? ON : OFF);
414 if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
415 ap_type == ATMEL12350) {
416 sb_ucast = on_off(12, strlen(SB_UCAST));
417 clear_main_new(12, 13);
418 print_menusel(12, 0, SB_UCAST, (sb_ucast == 1) ? ON : OFF);
424 if (ap_type == ATMEL12350 &&
425 (ap_vendorext == GEMTEK || ap_vendorext == EZYNET)) {
426 get_value(message, 13, strlen(TRAP_PORT), 6, INT_STRING,
428 trap_port = atoi(message);
436 varbinds[i].oid = operIPFilter;
437 varbinds[i].len_oid = sizeof(operIPFilter);
438 varbinds[i].type = INT_VALUE;
439 varbinds[i].value = (char *) &filter;
440 varbinds[i].len_val = 1;
443 if (m_primary_port) {
444 varbinds[i].oid = operPrimaryPort;
445 varbinds[i].len_oid = sizeof(operPrimaryPort);
446 varbinds[i].type = INT_VALUE;
447 varbinds[i].value = (char *) &primary_port;
448 varbinds[i].len_val = 1;
452 varbinds[i].oid = operDHCP;
453 varbinds[i].len_oid = sizeof(operDHCP);
454 varbinds[i].type = INT_VALUE;
455 varbinds[i].value = (char *) &dhcp;
456 varbinds[i].len_val = 1;
460 varbinds[i].oid = operIPAddress;
461 varbinds[i].len_oid = sizeof(operIPAddress);
462 ip.s_addr = htonl(ip.s_addr);
463 ip.s_addr = swap4(ip.s_addr);
464 varbinds[i].value = (char *) &ip.s_addr;
465 varbinds[i].len_val = 4;
466 varbinds[i].type = INT_VALUE;
470 varbinds[i].oid = operIPMask;
471 varbinds[i].len_oid = sizeof(operIPMask);
472 mask.s_addr = htonl(mask.s_addr);
473 mask.s_addr = swap4(mask.s_addr);
474 varbinds[i].value = (char *) &mask.s_addr;
475 varbinds[i].len_val = 4;
476 varbinds[i].type = INT_VALUE;
480 varbinds[i].oid = operGateway;
481 gw.s_addr = htonl(gw.s_addr);
482 gw.s_addr = swap4(gw.s_addr);
483 varbinds[i].len_oid = sizeof(operGateway);
484 varbinds[i].value = (char *) &gw.s_addr;
485 varbinds[i].len_val = 4;
486 varbinds[i].type = INT_VALUE;
490 varbinds[i].oid = sysTrapSwitch;
491 varbinds[i].len_oid = sizeof(sysTrapSwitch);
492 varbinds[i].value = &traps;
493 varbinds[i].len_val = 1;
494 varbinds[i].type = INT_VALUE;
498 varbinds[i].oid = bridgeOperationalMode;
499 varbinds[i].len_oid = sizeof(bridgeOperationalMode);
500 varbinds[i].value = (char *) &bridge_mode;
501 varbinds[i].len_val = 1;
502 varbinds[i].type = INT_VALUE;
505 if (m_remote_bssid) {
506 varbinds[i].oid = bridgeRemoteBridgeBSSID;
507 varbinds[i].len_oid = sizeof(bridgeRemoteBridgeBSSID);
508 varbinds[i].value = RemoteBSSID;
509 varbinds[i].len_val = 6;
510 varbinds[i].type = STRING_VALUE;
514 varbinds[i].oid = operConfigurationPort;
515 varbinds[i].len_oid = sizeof(operConfigurationPort);
516 varbinds[i].type = INT_VALUE;
517 varbinds[i].value = (char *) &config_port;
518 varbinds[i].len_val = 1;
522 varbinds[i].oid = operForwarbBcast;
523 varbinds[i].len_oid = sizeof(operForwarbBcast);
524 varbinds[i].type = INT_VALUE;
525 varbinds[i].value = (char *) &fw_bcast;
526 varbinds[i].len_val = 1;
530 varbinds[i].oid = operSendBackBcast;
531 varbinds[i].len_oid = sizeof(operSendBackBcast);
532 varbinds[i].type = INT_VALUE;
533 varbinds[i].value = (char *) &sb_bcast;
534 varbinds[i].len_val = 1;
538 varbinds[i].oid = operSendBackUnicast;
539 varbinds[i].len_oid = sizeof(operSendBackUnicast);
540 varbinds[i].type = INT_VALUE;
541 varbinds[i].value = (char *) &sb_ucast;
542 varbinds[i].len_val = 1;
548 len_val = (trap_port > 0x7fff) ? 3 : (trap_port > 0x7f) ? 2 : 1;
549 varbinds[i].oid = operTrapPort;
550 varbinds[i].len_oid = sizeof(operTrapPort);
551 varbinds[i].type = STRING_VALUE;
552 varbinds[i].value = (char *) &trap_port;
553 varbinds[i].len_val = len_val;
557 print_help(WAIT_SET);
558 if (snmp(varbinds, i, SET) <= 0)
559 print_helperr(ERR_SET);
561 print_help(DONE_SET);
572 print_top(NULL, NULL);