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>
25 #include "ap-curses.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(s): ")
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: ")
41 #define HELP _("INGFPDOMSCTRBU - set; W - write conf; Q - quit to menu")
48 char sysTrapSwitch[] =
49 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x03,
53 char operIPAddress[] =
54 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x01,
58 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x02,
61 char operEthernetAddress[] =
62 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x03,
66 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x04,
70 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x05,
74 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x06,
77 /* char ConfigPort[] =
78 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x02, 0x07,
81 */ /* This one is ATMEL12350 TELLUS MIB specific. */
83 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x02, 0x08,
88 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x01,
92 /* These 3 are ATMEL12350 MIB specific. */
93 char ForwardBroadcast[] =
94 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x02,
97 char SendBackBcast[] =
98 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x03,
101 char SendBackUnicast[] =
102 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x04,
106 char bridgeOperationalMode[] =
107 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01,
110 char bridgeRemoteBridgeBSSID[] =
111 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x02,
115 extern WINDOW *main_sub;
116 varbind varbinds[15];
117 struct in_addr ip, mask, gw;
118 unsigned char message[1024], filter, primary_port, dhcp, RemoteBSSID[6],
119 bridge_mode, traps, fw_bcast, sb_ucast;
120 char m_filter = 0, m_bridge_mode = 0, m_primary_port = 0, m_traps = 0,
121 m_dhcp = 0, m_ip = 0, m_mask = 0, m_gw = 0, m_remote_bssid = 0,
122 /*m_config_port = 0, */m_trap_port = 0, m_fw_bcast = 0, /*m_sb_bcast = 0,*/
124 char *bridge_modes[6] = {
125 _("Wireless Bridge Point to MultiPoint"),
127 _("Access Point client"),
128 _("Wireless Bridge Point to Point"),
134 } /*, *cf_trap_ports[3] = {
141 unsigned int trap_port = 0;
143 /* Determine the advanced MIB subtype of the device from its MAC address. */
144 varbinds[0].type = NULL_VALUE;
145 varbinds[0].oid = operEthernetAddress;
146 varbinds[0].len_oid = sizeof(operEthernetAddress);
147 varbinds[0].len_val = 0;
149 print_help(WAIT_RET);
150 /* if (snmp(varbinds, 1, GET) <= 0) {
151 print_helperr(ERR_RET);
155 for (i = 1; i < 15; i++) {
156 varbinds[i].type = NULL_VALUE;
157 varbinds[i].len_val = 0;
158 varbinds[i].len_oid = sizeof(sysTrapSwitch);
161 varbinds[1].oid = IPFilter;
162 varbinds[2].oid = PrimaryPort;
163 varbinds[3].oid = operDHCP;
164 varbinds[4].oid = operIPAddress;
165 varbinds[5].oid = operIPMask;
166 varbinds[6].oid = operGateway;
167 varbinds[7].oid = bridgeOperationalMode;
168 varbinds[8].oid = sysTrapSwitch;
169 varbinds[9].oid = bridgeRemoteBridgeBSSID;
170 varbinds[10].oid = ForwardBroadcast;
171 varbinds[11].oid = SendBackUnicast;
172 varbinds[12].oid = SendBackBcast;
174 if (snmp(varbinds, 13, GET) <= 0) {
175 print_helperr(ERR_RET);
179 print_title(_("Bridging"));
181 sb_ucast = *(varbinds[11].value);
182 // sb_ucast = varbinds[11].len_val;
183 sprintf(message, "%s%s", SB_UCAST, (sb_ucast == 2) ? ON : OFF);
184 mvwaddstr(main_sub, 10, 0, message);
188 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
189 varbinds[0].value[0] & 0xFF,
190 varbinds[0].value[1] & 0xFF,
191 varbinds[0].value[2] & 0xFF,
192 varbinds[0].value[3] & 0xFF,
193 varbinds[0].value[4] & 0xFF,
194 varbinds[0].value[5] & 0xFF);
195 mvwaddstr(main_sub, 0, 0, message);
197 filter = *(varbinds[1].value);
198 sprintf(message, "%s%s", IP_FILTER, (filter == 1) ? ON : OFF);
199 mvwaddstr(main_sub, 3, 0, message);
201 primary_port = *(varbinds[2].value);
202 if (primary_port < 1 || primary_port > 2) {
205 sprintf(message, "%s%s", PR_PORT, pr_ports[primary_port - 1]);
206 mvwaddstr(main_sub, 4, 0, message);
208 dhcp = *(varbinds[3].value);
209 sprintf(message, "%s%s", DHCP, (dhcp == 1) ? ON : OFF);
210 mvwaddstr(main_sub, 5, 0, message);
212 memcpy(&ip.s_addr, varbinds[4].value, 4);
213 sprintf(message, "%s%s", IPADDR, inet_ntoa(ip));
214 mvwaddstr(main_sub, 1, 0, message);
216 memcpy(&mask.s_addr, varbinds[5].value, 4);
217 sprintf(message, "%s%s", NETMASK, inet_ntoa(mask));
218 mvwaddstr(main_sub, 1, 24, message);
220 memcpy(&gw.s_addr, varbinds[6].value, 4);
221 sprintf(message, "%s%s", GATEWAY, inet_ntoa(gw));
222 mvwaddstr(main_sub, 2, 0, message);
224 memcpy(RemoteBSSID, varbinds[9].value, 6);
226 if ((bridge_mode = *(varbinds[7].value)) != 2) {
227 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", REMOTE_MAC,
228 *(RemoteBSSID + 0) & 0xFF, *(RemoteBSSID + 1) & 0xFF,
229 *(RemoteBSSID + 2) & 0xFF, *(RemoteBSSID + 3) & 0xFF,
230 *(RemoteBSSID + 4) & 0xFF, *(RemoteBSSID + 5) & 0xFF);
231 mvwaddstr(main_sub, 7, 0, message);
235 sprintf(message, "%s%s", OPER, bridge_modes[bridge_mode - 1]);
236 mvwaddstr(main_sub, 6, 0, message);
238 traps = *(varbinds[8].value);
239 sprintf(message, "%s%s", TRAPS, (traps == 1) ? ON : OFF);
240 mvwaddstr(main_sub, 8, 0, message);
242 fw_bcast = *(varbinds[10].value);
243 sprintf(message, "%s%s", FW_BCAST, (fw_bcast == 1) ? ON : OFF);
244 mvwaddstr(main_sub, 9, 0, message);
254 get_ip(&ip, 1, strlen(IPADDR), HELP);
259 get_mask(&mask, 1, strlen(IPADDR) + 16 + strlen(NETMASK), HELP);
264 get_ip(&gw, 2, strlen(GATEWAY), HELP);
269 filter = on_off(3, strlen(IP_FILTER));
270 clear_main_new(3, 4);
271 print_menusel(3, 0, IP_FILTER, (filter == 1) ? ON : OFF);
276 primary_port = menu_choose(4, strlen(PR_PORT), pr_ports, 2) + 1;
277 clear_main_new(4, 5);
278 print_menusel(4, 0, PR_PORT, pr_ports[primary_port - 1]);
283 dhcp = on_off(5, strlen(DHCP));
284 clear_main_new(5, 6);
285 print_menusel(5, 0, DHCP, (dhcp == 1) ? ON : OFF);
290 bridge_mode = menu_choose(6, strlen(OPER), bridge_modes, 5) + 1;
291 clear_main_new(6, 8);
292 print_menusel(6, 0, OPER, bridge_modes[bridge_mode - 1]);
293 if (bridge_mode != 2) {
294 sprintf(message, "%02X%02X%02X%02X%02X%02X",
295 *(RemoteBSSID + 0) & 0xFF,
296 *(RemoteBSSID + 1) & 0xFF,
297 *(RemoteBSSID + 2) & 0xFF,
298 *(RemoteBSSID + 3) & 0xFF,
299 *(RemoteBSSID + 4) & 0xFF,
300 *(RemoteBSSID + 5) & 0xFF);
301 print_menusel(7, 0, REMOTE_MAC, message);
307 if (bridge_mode == 2)
309 get_mac(RemoteBSSID, 7, strlen(REMOTE_MAC));
314 traps = on_off(8, strlen(TRAPS));
315 clear_main_new(8, 9);
316 print_menusel(8, 0, TRAPS, (traps == 1) ? ON : OFF);
321 config_port = menu_choose(9, strlen(CF_PORT), cf_trap_ports, 3);
322 clear_main_new(9, 10);
323 print_menusel(9, 0, CF_PORT, cf_trap_ports[config_port]);
328 fw_bcast = on_off(9, strlen(FW_BCAST));
329 clear_main_new(9, 10);
330 print_menusel(9, 0, FW_BCAST, (fw_bcast == 1) ? ON : OFF);
335 sb_bcast = on_off(12, strlen(SB_BCAST));
336 clear_main_new(12, 13);
337 print_menusel(12, 0, SB_BCAST, (sb_bcast == 1) ? ON : OFF);
342 sb_ucast = on_off(10, strlen(SB_UCAST));
343 sb_ucast = (sb_ucast == 2) ? 1 : 2;
344 clear_main_new(10, 11);
345 print_menusel(10, 0, SB_UCAST, (sb_ucast == 2) ? ON : OFF);
352 varbinds[i].oid = IPFilter;
353 varbinds[i].len_oid = sizeof(IPFilter);
354 varbinds[i].type = INT_VALUE;
355 varbinds[i].value = (char *) &filter;
356 varbinds[i].len_val = 1;
359 if (m_primary_port) {
360 varbinds[i].oid = PrimaryPort;
361 varbinds[i].len_oid = sizeof(PrimaryPort);
362 varbinds[i].type = INT_VALUE;
363 varbinds[i].value = (char *) &primary_port;
364 varbinds[i].len_val = 1;
368 varbinds[i].oid = operDHCP;
369 varbinds[i].len_oid = sizeof(operDHCP);
370 varbinds[i].type = INT_VALUE;
371 varbinds[i].value = (char *) &dhcp;
372 varbinds[i].len_val = 1;
376 varbinds[i].oid = operIPAddress;
377 varbinds[i].len_oid = sizeof(operIPAddress);
378 ip.s_addr = htonl(ip.s_addr);
379 ip.s_addr = swap4(ip.s_addr);
380 varbinds[i].value = (char *) &ip.s_addr;
381 varbinds[i].len_val = 4;
382 varbinds[i].type = INT_VALUE;
386 varbinds[i].oid = operIPMask;
387 varbinds[i].len_oid = sizeof(operIPMask);
388 mask.s_addr = htonl(mask.s_addr);
389 mask.s_addr = swap4(mask.s_addr);
390 varbinds[i].value = (char *) &mask.s_addr;
391 varbinds[i].len_val = 4;
392 varbinds[i].type = INT_VALUE;
396 varbinds[i].oid = operGateway;
397 gw.s_addr = htonl(gw.s_addr);
398 gw.s_addr = swap4(gw.s_addr);
399 varbinds[i].len_oid = sizeof(operGateway);
400 varbinds[i].value = (char *) &gw.s_addr;
401 varbinds[i].len_val = 4;
402 varbinds[i].type = INT_VALUE;
406 varbinds[i].oid = sysTrapSwitch;
407 varbinds[i].len_oid = sizeof(sysTrapSwitch);
408 varbinds[i].value = &traps;
409 varbinds[i].len_val = 1;
410 varbinds[i].type = INT_VALUE;
414 varbinds[i].oid = bridgeOperationalMode;
415 varbinds[i].len_oid = sizeof(bridgeOperationalMode);
416 varbinds[i].value = (char *) &bridge_mode;
417 varbinds[i].len_val = 1;
418 varbinds[i].type = INT_VALUE;
421 if (m_remote_bssid) {
422 varbinds[i].oid = bridgeRemoteBridgeBSSID;
423 varbinds[i].len_oid = sizeof(bridgeRemoteBridgeBSSID);
424 varbinds[i].value = RemoteBSSID;
425 varbinds[i].len_val = 6;
426 varbinds[i].type = STRING_VALUE;
429 /* if (m_config_port) {
430 varbinds[i].oid = ConfigPort;
431 varbinds[i].len_oid = sizeof(ConfigPort);
432 varbinds[i].type = INT_VALUE;
434 varbinds[i].value = (char *) &config_port;
435 varbinds[i].len_val = 1;
439 varbinds[i].oid = ForwardBroadcast;
440 varbinds[i].len_oid = sizeof(ForwardBroadcast);
441 varbinds[i].type = INT_VALUE;
442 varbinds[i].value = (char *) &fw_bcast;
443 varbinds[i].len_val = 1;
447 varbinds[i].oid = SendBackBcast;
448 varbinds[i].len_oid = sizeof(SendBackBcast);
449 varbinds[i].type = INT_VALUE;
450 varbinds[i].value = (char *) &sb_ucast;
451 varbinds[i].len_val = 1;
453 varbinds[i].oid = SendBackUnicast;
454 varbinds[i].len_oid = sizeof(SendBackUnicast);
455 varbinds[i].type = INT_VALUE;
456 varbinds[i].value = (char *) &sb_ucast;
457 varbinds[i].len_val = 1;
463 len_val = (trap_port > 0x7fff) ? 3 : (trap_port > 0x7f) ? 2 : 1;
464 varbinds[i].oid = TrapPort;
465 varbinds[i].len_oid = sizeof(TrapPort);
466 varbinds[i].type = STRING_VALUE;
467 varbinds[i].value = (char *) &trap_port;
468 varbinds[i].len_val = len_val;
472 print_help(WAIT_SET);
473 if (snmp(varbinds, i, SET) <= 0)
474 print_helperr(ERR_SET);
476 print_help(DONE_SET);