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: ")
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")
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,
83 char *bridge_modes[6] = {
84 _("Wireless Bridge Point to MultiPoint"),
86 _("Access Point client"),
87 _("Wireless Bridge Point to Point"),
93 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x02, 0x08,
98 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x01,
102 char ForwarbBcast[] =
103 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x02,
106 char SendBackBcast[] =
107 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x03,
110 char SendBackUnicast[] =
111 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x04,
115 char bridgeOperationalMode[] =
116 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01,
119 char bridgeRemoteBridgeBSSID[] =
120 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x02,
124 extern WINDOW *main_sub;
125 varbind varbinds[15];
126 struct in_addr ip, mask, gw;
127 unsigned char message[1024], filter, primary_port, dhcp, RemoteBSSID[6],
128 bridge_mode, traps, fw_bcast, sb_ucast;
129 char m_filter = 0, m_bridge_mode = 0, m_primary_port = 0, m_traps = 0,
130 m_dhcp = 0, m_ip = 0, m_mask = 0, m_gw = 0, m_remote_bssid = 0,
131 /*m_config_port = 0, */m_trap_port = 0, m_fw_bcast = 0, /*m_sb_bcast = 0,*/
133 char *pr_ports[2] = {
136 } /*, *cf_trap_ports[3] = {
143 unsigned int trap_port = 0;
145 /* Determine the advanced MIB subtype of the device from its MAC address. */
146 varbinds[0].type = NULL_VALUE;
147 varbinds[0].oid = operEthernetAddress;
148 varbinds[0].len_oid = sizeof(operEthernetAddress);
149 varbinds[0].len_val = 0;
151 print_help(WAIT_RET);
152 /* if (snmp(varbinds, 1, GET) <= 0) {
153 print_helperr(ERR_RET);
157 for (i = 1; i < 15; i++) {
158 varbinds[i].type = NULL_VALUE;
159 varbinds[i].len_val = 0;
160 varbinds[i].len_oid = sizeof(sysTrapSwitch);
163 varbinds[1].oid = IPFilter;
164 varbinds[2].oid = PrimaryPort;
165 varbinds[3].oid = operDHCP;
166 varbinds[4].oid = operIPAddress;
167 varbinds[5].oid = operIPMask;
168 varbinds[6].oid = operGateway;
169 varbinds[7].oid = bridgeOperationalMode;
170 varbinds[8].oid = sysTrapSwitch;
171 varbinds[9].oid = bridgeRemoteBridgeBSSID;
172 varbinds[10].oid = ForwarbBcast;
173 varbinds[11].oid = SendBackUnicast;
174 varbinds[12].oid = SendBackBcast;
176 if (snmp(varbinds, 13, GET) < 13) {
177 print_helperr(ERR_RET);
181 print_top(NULL, _("Bridging"));
183 sb_ucast = *(varbinds[11].value);
184 // sb_ucast = varbinds[11].len_val;
185 sprintf(message, "%s%s", SB_UCAST, (sb_ucast == 2) ? ON : OFF);
186 mvwaddstr(main_sub, 10, 0, message);
190 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
191 varbinds[0].value[0] & 0xFF,
192 varbinds[0].value[1] & 0xFF,
193 varbinds[0].value[2] & 0xFF,
194 varbinds[0].value[3] & 0xFF,
195 varbinds[0].value[4] & 0xFF,
196 varbinds[0].value[5] & 0xFF);
197 mvwaddstr(main_sub, 0, 0, message);
199 filter = *(varbinds[1].value);
200 sprintf(message, "%s%s", IP_FILTER, (filter == 1) ? ON : OFF);
201 mvwaddstr(main_sub, 3, 0, message);
203 primary_port = *(varbinds[2].value);
204 if (primary_port < 1 || primary_port > 2) {
207 sprintf(message, "%s%s", PR_PORT, pr_ports[primary_port - 1]);
208 mvwaddstr(main_sub, 4, 0, message);
210 dhcp = *(varbinds[3].value);
211 sprintf(message, "%s%s", DHCP, (dhcp == 1) ? ON : OFF);
212 mvwaddstr(main_sub, 5, 0, message);
214 memcpy(&ip.s_addr, varbinds[4].value, 4);
215 sprintf(message, "%s%s", IPADDR, inet_ntoa(ip));
216 mvwaddstr(main_sub, 1, 0, message);
218 memcpy(&mask.s_addr, varbinds[5].value, 4);
219 sprintf(message, "%s%s", NETMASK, inet_ntoa(mask));
220 mvwaddstr(main_sub, 1, 24, message);
222 memcpy(&gw.s_addr, varbinds[6].value, 4);
223 sprintf(message, "%s%s", GATEWAY, inet_ntoa(gw));
224 mvwaddstr(main_sub, 2, 0, message);
226 memcpy(RemoteBSSID, varbinds[9].value, 6);
228 if ((bridge_mode = *(varbinds[7].value)) != 2) {
229 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", REMOTE_MAC,
230 *(RemoteBSSID + 0) & 0xFF, *(RemoteBSSID + 1) & 0xFF,
231 *(RemoteBSSID + 2) & 0xFF, *(RemoteBSSID + 3) & 0xFF,
232 *(RemoteBSSID + 4) & 0xFF, *(RemoteBSSID + 5) & 0xFF);
233 mvwaddstr(main_sub, 7, 0, message);
237 sprintf(message, "%s%s", OPER, bridge_modes[bridge_mode - 1]);
238 mvwaddstr(main_sub, 6, 0, message);
240 traps = *(varbinds[8].value);
241 sprintf(message, "%s%s", TRAPS, (traps == 1) ? ON : OFF);
242 mvwaddstr(main_sub, 8, 0, message);
244 fw_bcast = *(varbinds[10].value);
245 sprintf(message, "%s%s", FW_BCAST, (fw_bcast == 1) ? ON : OFF);
246 mvwaddstr(main_sub, 9, 0, message);
256 get_ip(&ip, 1, strlen(IPADDR), HELP);
261 get_mask(&mask, 1, strlen(IPADDR) + 16 + strlen(NETMASK), HELP);
266 get_ip(&gw, 2, strlen(GATEWAY), HELP);
271 filter = on_off(3, strlen(IP_FILTER));
272 clear_main_new(3, 4);
273 print_menusel(3, 0, IP_FILTER, (filter == 1) ? ON : OFF);
278 primary_port = menu_choose(4, strlen(PR_PORT), pr_ports, 2) + 1;
279 clear_main_new(4, 5);
280 print_menusel(4, 0, PR_PORT, pr_ports[primary_port - 1]);
285 dhcp = on_off(5, strlen(DHCP));
286 clear_main_new(5, 6);
287 print_menusel(5, 0, DHCP, (dhcp == 1) ? ON : OFF);
292 bridge_mode = menu_choose(6, strlen(OPER), bridge_modes, 5) + 1;
293 clear_main_new(6, 8);
294 print_menusel(6, 0, OPER, bridge_modes[bridge_mode - 1]);
295 if (bridge_mode != 2) {
296 sprintf(message, "%02X%02X%02X%02X%02X%02X",
297 *(RemoteBSSID + 0) & 0xFF,
298 *(RemoteBSSID + 1) & 0xFF,
299 *(RemoteBSSID + 2) & 0xFF,
300 *(RemoteBSSID + 3) & 0xFF,
301 *(RemoteBSSID + 4) & 0xFF,
302 *(RemoteBSSID + 5) & 0xFF);
303 print_menusel(7, 0, REMOTE_MAC, message);
309 if (bridge_mode == 2)
311 get_mac(RemoteBSSID, 7, strlen(REMOTE_MAC));
316 traps = on_off(8, strlen(TRAPS));
317 clear_main_new(8, 9);
318 print_menusel(8, 0, TRAPS, (traps == 1) ? ON : OFF);
323 config_port = menu_choose(9, strlen(CF_PORT), cf_trap_ports, 3);
324 clear_main_new(9, 10);
325 print_menusel(9, 0, CF_PORT, cf_trap_ports[config_port]);
330 fw_bcast = on_off(9, strlen(FW_BCAST));
331 clear_main_new(9, 10);
332 print_menusel(9, 0, FW_BCAST, (fw_bcast == 1) ? ON : OFF);
337 sb_bcast = on_off(12, strlen(SB_BCAST));
338 clear_main_new(12, 13);
339 print_menusel(12, 0, SB_BCAST, (sb_bcast == 1) ? ON : OFF);
344 sb_ucast = on_off(10, strlen(SB_UCAST));
345 sb_ucast = (sb_ucast == 2) ? 1 : 2;
346 clear_main_new(10, 11);
347 print_menusel(10, 0, SB_UCAST, (sb_ucast == 2) ? ON : OFF);
354 varbinds[i].oid = IPFilter;
355 varbinds[i].len_oid = sizeof(IPFilter);
356 varbinds[i].type = INT_VALUE;
357 varbinds[i].value = (char *) &filter;
358 varbinds[i].len_val = 1;
361 if (m_primary_port) {
362 varbinds[i].oid = PrimaryPort;
363 varbinds[i].len_oid = sizeof(PrimaryPort);
364 varbinds[i].type = INT_VALUE;
365 varbinds[i].value = (char *) &primary_port;
366 varbinds[i].len_val = 1;
370 varbinds[i].oid = operDHCP;
371 varbinds[i].len_oid = sizeof(operDHCP);
372 varbinds[i].type = INT_VALUE;
373 varbinds[i].value = (char *) &dhcp;
374 varbinds[i].len_val = 1;
378 varbinds[i].oid = operIPAddress;
379 varbinds[i].len_oid = sizeof(operIPAddress);
380 ip.s_addr = htonl(ip.s_addr);
381 ip.s_addr = swap4(ip.s_addr);
382 varbinds[i].value = (char *) &ip.s_addr;
383 varbinds[i].len_val = 4;
384 varbinds[i].type = INT_VALUE;
388 varbinds[i].oid = operIPMask;
389 varbinds[i].len_oid = sizeof(operIPMask);
390 mask.s_addr = htonl(mask.s_addr);
391 mask.s_addr = swap4(mask.s_addr);
392 varbinds[i].value = (char *) &mask.s_addr;
393 varbinds[i].len_val = 4;
394 varbinds[i].type = INT_VALUE;
398 varbinds[i].oid = operGateway;
399 gw.s_addr = htonl(gw.s_addr);
400 gw.s_addr = swap4(gw.s_addr);
401 varbinds[i].len_oid = sizeof(operGateway);
402 varbinds[i].value = (char *) &gw.s_addr;
403 varbinds[i].len_val = 4;
404 varbinds[i].type = INT_VALUE;
408 varbinds[i].oid = sysTrapSwitch;
409 varbinds[i].len_oid = sizeof(sysTrapSwitch);
410 varbinds[i].value = &traps;
411 varbinds[i].len_val = 1;
412 varbinds[i].type = INT_VALUE;
416 varbinds[i].oid = bridgeOperationalMode;
417 varbinds[i].len_oid = sizeof(bridgeOperationalMode);
418 varbinds[i].value = (char *) &bridge_mode;
419 varbinds[i].len_val = 1;
420 varbinds[i].type = INT_VALUE;
423 if (m_remote_bssid) {
424 varbinds[i].oid = bridgeRemoteBridgeBSSID;
425 varbinds[i].len_oid = sizeof(bridgeRemoteBridgeBSSID);
426 varbinds[i].value = RemoteBSSID;
427 varbinds[i].len_val = 6;
428 varbinds[i].type = STRING_VALUE;
431 /* if (m_config_port) {
432 varbinds[i].oid = ConfigPort;
433 varbinds[i].len_oid = sizeof(ConfigPort);
434 varbinds[i].type = INT_VALUE;
436 varbinds[i].value = (char *) &config_port;
437 varbinds[i].len_val = 1;
441 varbinds[i].oid = ForwarbBcast;
442 varbinds[i].len_oid = sizeof(ForwarbBcast);
443 varbinds[i].type = INT_VALUE;
444 varbinds[i].value = (char *) &fw_bcast;
445 varbinds[i].len_val = 1;
449 varbinds[i].oid = SendBackBcast;
450 varbinds[i].len_oid = sizeof(SendBackBcast);
451 varbinds[i].type = INT_VALUE;
452 varbinds[i].value = (char *) &sb_ucast;
453 varbinds[i].len_val = 1;
455 varbinds[i].oid = SendBackUnicast;
456 varbinds[i].len_oid = sizeof(SendBackUnicast);
457 varbinds[i].type = INT_VALUE;
458 varbinds[i].value = (char *) &sb_ucast;
459 varbinds[i].len_val = 1;
465 len_val = (trap_port > 0x7fff) ? 3 : (trap_port > 0x7f) ? 2 : 1;
466 varbinds[i].oid = TrapPort;
467 varbinds[i].len_oid = sizeof(TrapPort);
468 varbinds[i].type = STRING_VALUE;
469 varbinds[i].value = (char *) &trap_port;
470 varbinds[i].len_val = len_val;
474 print_help(WAIT_SET);
475 if (snmp(varbinds, i, SET) <= 0)
476 print_helperr(ERR_SET);
478 print_help(DONE_SET);
489 print_top(NULL, NULL);