X-Git-Url: https://git.decadent.org.uk/gitweb/?p=ap-utils.git;a=blobdiff_plain;f=src%2Fbridge.c;fp=src%2Fbridge.c;h=30961f8c6d524514721ff77afdc90fe6cd9e0cd2;hp=7833cc510ffb38f72cc0f5cafcdd8274a7a21e60;hb=1aac4ac30a9a0d6cd2182013d2b3fd48b65ed2fd;hpb=5c77e013a46530bb3650f61d768dfed0dd3b72cb diff --git a/src/bridge.c b/src/bridge.c index 7833cc5..30961f8 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -2,6 +2,7 @@ * bridge.c from Access Point SNMP Utils for Linux * * Copyright (c) 2002 Roman Festchook + * Copyright (c) 2005 Jan Rafaj * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 2 from @@ -33,16 +34,27 @@ #define OPER _("[O] Operational mode: ") #define REMOTE_MAC _("[M] Preferred BSSID (remote MAC addr.): ") #define CF_PORT _("[C] Configuration-enabled port(s): ") -#define TRAP_PORT _("[T] Trap-sending port(s): ") +#define TRAP_PORT _("[T] Trap-sending port: ") #define FW_BCAST _("[R] Forward broadcast traffic: ") #define SB_BCAST _("[B] Isolate wireless clients (broadcast traffic): ") #define SB_UCAST _("[U] Isolate wireless clients (unicast traffic): ") -#define HELP _("INGFPDOMSCTRBU - set; W - write conf; Q - quit to menu") +#define HELP _("INGFPDOMSCRBUT - set; W - write conf; Q - quit to menu") extern short ap_type, ap_vendorext; + void bridging() { + +char *bridge_modes[6] = { + _("Wireless Bridge Point to MultiPoint"), + _("Access Point"), + _("Access Point client"), + _("Wireless Bridge Point to Point"), + _("Repeater"), + _("unknown") +}; + char sysTrapSwitch[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x03, 0x00 }; @@ -62,30 +74,33 @@ void bridging() char operDHCP[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x05, 0x00 }; - char PrimaryPort[] = { + char operPrimaryPort[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x06, 0x00 }; - /* This one is ATMEL12350 MIB specific. */ - char ConfigPort[] = { - 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x02, 0x07, 0x00 + + /* This one is ATMEL410 SBRIDGES MIB and ATMEL12350 all MIBs specific. */ + char operConfigurationPort[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x07, 0x00 }; - /* This one is ATMEL12350 TELLUS MIB specific. */ - char TrapPort[] = { + + /* This one is ATMEL12350 GEMTEK MIB and ATMEL12350 EZYNET MIB specific. */ + char operTrapPort[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x02, 0x08, 0x00 }; - char IPFilter[] = { + char operIPFilter[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x01, 0x00 }; - /* These 3 are ATMEL12350 MIB specific. */ - char ForwardBroadcast[] = { - 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x03, 0x02, 0x00 + + /* These 3 are ATMEL410 SBRIDGES MIB and ATMEL12350 all MIBs specific. */ + char operForwarbBcast[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x02, 0x00 }; - char SendBackBcast[] = { - 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x03, 0x03, 0x00 + char operSendBackBcast[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x03, 0x00 }; - char SendBackUnicast[] = { - 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x03, 0x04, 0x00 + char operSendBackUnicast[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x04, 0x00 }; char bridgeOperationalMode[] = { @@ -105,45 +120,46 @@ void bridging() m_dhcp = 0, m_ip = 0, m_mask = 0, m_gw = 0, m_remote_bssid = 0, m_config_port = 0, m_trap_port = 0, m_fw_bcast = 0, m_sb_bcast = 0, m_sb_ucast = 0; - char *bridge_modes[6] = { - _("Wireless Bridge Point to MultiPoint"), - _("Access Point"), - _("Access Point client"), - _("Wireless Bridge Point to Point"), - _("Repeater"), - ("unknown") - }, *pr_ports[2] = { + char *pr_ports[2] = { _("Ethernet"), _("Wireless") - }, *cf_trap_ports[3] = { - _("Both"), + }, *cf_ports[3] = { _("Ethernet"), - _("Wireless") + _("Wireless (can be risky)"), + _("Both") }; int i; unsigned int trap_port = 0; if (ap_type == ATMEL12350) { - operEthernetAddress[5] = 0xE0; - operEthernetAddress[6] = 0x3E; - IPFilter[5] = 0xE0; - IPFilter[6] = 0x3E; - PrimaryPort[5] = 0xE0; - PrimaryPort[6] = 0x3E; - operDHCP[5] = 0xE0; - operDHCP[6] = 0x3E; + sysTrapSwitch[5] = 0xE0; + sysTrapSwitch[6] = 0x3E; operIPAddress[5] = 0xE0; operIPAddress[6] = 0x3E; operIPMask[5] = 0xE0; operIPMask[6] = 0x3E; + operEthernetAddress[5] = 0xE0; + operEthernetAddress[6] = 0x3E; operGateway[5] = 0xE0; operGateway[6] = 0x3E; + operDHCP[5] = 0xE0; + operDHCP[6] = 0x3E; + operPrimaryPort[5] = 0xE0; + operPrimaryPort[6] = 0x3E; + operConfigurationPort[5] = 0xE0; + operConfigurationPort[6] = 0x3E; + operIPFilter[5] = 0xE0; + operIPFilter[6] = 0x3E; + operForwarbBcast[5] = 0xE0; + operForwarbBcast[6] = 0x3E; + operSendBackBcast[5] = 0xE0; + operSendBackBcast[6] = 0x3E; + operSendBackUnicast[5] = 0xE0; + operSendBackUnicast[6] = 0x3E; bridgeOperationalMode[5] = 0xE0; bridgeOperationalMode[6] = 0x3E; bridgeRemoteBridgeBSSID[5] = 0xE0; bridgeRemoteBridgeBSSID[6] = 0x3E; - sysTrapSwitch[5] = 0xE0; - sysTrapSwitch[6] = 0x3E; } for (i = 0; i < 15; i++) { @@ -154,27 +170,30 @@ void bridging() i = 0; - varbinds[i++].oid = operEthernetAddress; - varbinds[i++].oid = IPFilter; - varbinds[i++].oid = PrimaryPort; - varbinds[i++].oid = operDHCP; + varbinds[i++].oid = sysTrapSwitch; varbinds[i++].oid = operIPAddress; varbinds[i++].oid = operIPMask; + varbinds[i++].oid = operEthernetAddress; varbinds[i++].oid = operGateway; + varbinds[i++].oid = operDHCP; + varbinds[i++].oid = operPrimaryPort; + varbinds[i++].oid = operIPFilter; varbinds[i++].oid = bridgeOperationalMode; - varbinds[i++].oid = sysTrapSwitch; varbinds[i++].oid = bridgeRemoteBridgeBSSID; - if (ap_type == ATMEL12350) { - varbinds[i++].oid = ConfigPort; - varbinds[i++].oid = ForwardBroadcast; - varbinds[i++].oid = SendBackBcast; - varbinds[i++].oid = SendBackUnicast; - if (ap_vendorext == TELLUS || ap_vendorext == VERNET) - varbinds[i++].oid = TrapPort; + if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) || + (ap_type == ATMEL12350)) { + varbinds[i++].oid = operConfigurationPort; + varbinds[i++].oid = operForwarbBcast; + varbinds[i++].oid = operSendBackBcast; + varbinds[i++].oid = operSendBackUnicast; + } + if (ap_type == ATMEL12350 && + (ap_vendorext == GEMTEK || ap_vendorext == EZYNET)) { + varbinds[i++].oid = operTrapPort; } print_help(WAIT_RET); - if (snmp(varbinds, i, GET) <= 0) { + if (snmp(varbinds, i, GET) < i) { print_helperr(ERR_RET); goto exit; } @@ -182,50 +201,54 @@ void bridging() print_top(NULL, _("Bridging")); sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC, - varbinds[0].value[0] & 0xFF, - varbinds[0].value[1] & 0xFF, - varbinds[0].value[2] & 0xFF, - varbinds[0].value[3] & 0xFF, - varbinds[0].value[4] & 0xFF, - varbinds[0].value[5] & 0xFF); + varbinds[3].value[0] & 0xFF, + varbinds[3].value[1] & 0xFF, + varbinds[3].value[2] & 0xFF, + varbinds[3].value[3] & 0xFF, + varbinds[3].value[4] & 0xFF, + varbinds[3].value[5] & 0xFF); mvwaddstr(main_sub, 0, 0, message); - memcpy(&ip.s_addr, varbinds[4].value, 4); + memcpy(&ip.s_addr, varbinds[1].value, 4); sprintf(message, "%s%s", IPADDR, inet_ntoa(ip)); mvwaddstr(main_sub, 1, 0, message); - memcpy(&mask.s_addr, varbinds[5].value, 4); + memcpy(&mask.s_addr, varbinds[2].value, 4); sprintf(message, "%s%s", NETMASK, inet_ntoa(mask)); mvwaddstr(main_sub, 1, 24, message); - memcpy(&gw.s_addr, varbinds[6].value, 4); + memcpy(&gw.s_addr, varbinds[4].value, 4); sprintf(message, "%s%s", GATEWAY, inet_ntoa(gw)); mvwaddstr(main_sub, 2, 0, message); - filter = *(varbinds[1].value); + filter = *(varbinds[7].value); sprintf(message, "%s%s", IP_FILTER, (filter == 1) ? ON : OFF); mvwaddstr(main_sub, 3, 0, message); - if (ap_vendorext == SBRIDGES) { +/* + if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) { sprintf(message, "%s%02X%02X%02X%02X%02X%02X", SB_ATTMAC, - *(varbinds[2].value +0) & 0xFF, *(varbinds[2].value +1) & 0xFF, - *(varbinds[2].value +2) & 0xFF, *(varbinds[2].value +3) & 0xFF, - *(varbinds[2].value +4) & 0xFF, *(varbinds[2].value +5) & 0xFF); + *(varbinds[6].value +0) & 0xFF, *(varbinds[6].value +1) & 0xFF, + *(varbinds[6].value +2) & 0xFF, *(varbinds[6].value +3) & 0xFF, + *(varbinds[6].value +4) & 0xFF, *(varbinds[6].value +5) & 0xFF); } else { - primary_port = *(varbinds[2].value); +*/ + primary_port = *(varbinds[6].value); if (primary_port < 1 || primary_port > 2) { primary_port = 1; } sprintf(message, "%s%s", PR_PORT, pr_ports[primary_port - 1]); +/* } +*/ mvwaddstr(main_sub, 4, 0, message); - dhcp = *(varbinds[3].value); + dhcp = *(varbinds[5].value); sprintf(message, "%s%s", DHCP, (dhcp == 1) ? ON : OFF); mvwaddstr(main_sub, 5, 0, message); memcpy(RemoteBSSID, varbinds[9].value, 6); - if ((bridge_mode = *(varbinds[7].value)) != 2) { + if ((bridge_mode = *(varbinds[8].value)) != 2) { sprintf(message, "%s%02X%02X%02X%02X%02X%02X", REMOTE_MAC, *(RemoteBSSID + 0) & 0xFF, *(RemoteBSSID + 1) & 0xFF, *(RemoteBSSID + 2) & 0xFF, *(RemoteBSSID + 3) & 0xFF, @@ -237,35 +260,40 @@ void bridging() sprintf(message, "%s%s", OPER, bridge_modes[bridge_mode - 1]); mvwaddstr(main_sub, 6, 0, message); - traps = *(varbinds[8].value); + traps = *(varbinds[0].value); sprintf(message, "%s%s", TRAPS, (traps == 1) ? ON : OFF); mvwaddstr(main_sub, 8, 0, message); - if (ap_type == ATMEL12350) { + if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) || + ap_type == ATMEL12350) { config_port = *(varbinds[10].value); - sprintf(message, "%s%s", CF_PORT, cf_trap_ports[config_port]); + if (config_port == 0) /* happens with ATMEL12350 EZYNET firmware only */ + config_port = 3; + sprintf(message, "%s%s", CF_PORT, cf_ports[config_port - 1]); mvwaddstr(main_sub, 9, 0, message); - if (ap_vendorext == TELLUS || ap_vendorext == VERNET) { - for (i = 0; i < varbinds[14].len_val; - trap_port += varbinds[14].value[i] * - (1 << ((varbinds[14].len_val - i - 1) * 8)), i++); - sprintf(message, "%s%u", TRAP_PORT, trap_port); - mvwaddstr(main_sub, 10, 0, message); - } - fw_bcast = *(varbinds[11].value); sprintf(message, "%s%s", FW_BCAST, (fw_bcast == 1) ? ON : OFF); - mvwaddstr(main_sub, 11, 0, message); + mvwaddstr(main_sub, 10, 0, message); sb_bcast = *(varbinds[12].value); sprintf(message, "%s%s", SB_BCAST, (sb_bcast == 1) ? ON : OFF); - mvwaddstr(main_sub, 12, 0, message); + mvwaddstr(main_sub, 11, 0, message); sb_ucast = *(varbinds[13].value); sprintf(message, "%s%s", SB_UCAST, (sb_ucast == 1) ? ON : OFF); + mvwaddstr(main_sub, 12, 0, message); + } + + if (ap_type == ATMEL12350 && + (ap_vendorext == GEMTEK || ap_vendorext == EZYNET)) { + for (i = 0; i < varbinds[14].len_val; + trap_port += varbinds[14].value[i] * + (1 << ((varbinds[14].len_val - i - 1) * 8)), i++); + sprintf(message, "%s%u", TRAP_PORT, trap_port); mvwaddstr(main_sub, 13, 0, message); } + wrefresh(main_sub); noecho(); @@ -296,12 +324,14 @@ void bridging() continue; case 'P': case 'p': - if (ap_vendorext != SBRIDGES) { - primary_port = menu_choose(4, strlen(PR_PORT), pr_ports, 2) + 1; - clear_main_new(4, 5); - print_menusel(4, 0, PR_PORT, pr_ports[primary_port - 1]); - m_primary_port = 1; - } +/* + if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) + continue; +*/ + primary_port = menu_choose(4, strlen(PR_PORT), pr_ports, 2) + 1; + clear_main_new(4, 5); + print_menusel(4, 0, PR_PORT, pr_ports[primary_port - 1]); + m_primary_port = 1; continue; case 'D': case 'd': @@ -354,63 +384,68 @@ void bridging() continue; case 'C': case 'c': - if (ap_type == ATMEL12350) { - config_port = menu_choose(9, strlen(CF_PORT), cf_trap_ports, 3); + if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) || + ap_type == ATMEL12350) { + config_port = menu_choose(9, strlen(CF_PORT), cf_ports, 3) + 1; clear_main_new(9, 10); - print_menusel(9, 0, CF_PORT, cf_trap_ports[config_port]); + print_menusel(9, 0, CF_PORT, cf_ports[config_port - 1]); m_config_port = 1; } continue; - case 'T': - case 't': - if (ap_vendorext == TELLUS || ap_vendorext == VERNET) { - get_value(message, 10, strlen(TRAP_PORT), 6, INT_STRING, - 0, 65535, HELP); - trap_port = atoi(message); - m_trap_port = 1; - } - continue; case 'R': case 'r': - if (ap_type == ATMEL12350) { - fw_bcast = on_off(11, strlen(FW_BCAST)); - clear_main_new(11, 12); - print_menusel(11, 0, FW_BCAST, (fw_bcast == 1) ? ON : OFF); + if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) || + ap_type == ATMEL12350) { + fw_bcast = on_off(10, strlen(FW_BCAST)); + clear_main_new(10, 11); + print_menusel(10, 0, FW_BCAST, (fw_bcast == 1) ? ON : OFF); m_fw_bcast = 1; } continue; case 'B': case 'b': - if (ap_type == ATMEL12350) { - sb_bcast = on_off(12, strlen(SB_BCAST)); - clear_main_new(12, 13); - print_menusel(12, 0, SB_BCAST, (sb_bcast == 1) ? ON : OFF); + if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) || + ap_type == ATMEL12350) { + sb_bcast = on_off(11, strlen(SB_BCAST)); + clear_main_new(11, 12); + print_menusel(11, 0, SB_BCAST, (sb_bcast == 1) ? ON : OFF); m_sb_bcast = 1; } continue; case 'U': case 'u': - if (ap_type == ATMEL12350) { - sb_ucast = on_off(13, strlen(SB_UCAST)); - clear_main_new(13, 14); - print_menusel(13, 0, SB_UCAST, (sb_ucast == 1) ? ON : OFF); + if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) || + ap_type == ATMEL12350) { + sb_ucast = on_off(12, strlen(SB_UCAST)); + clear_main_new(12, 13); + print_menusel(12, 0, SB_UCAST, (sb_ucast == 1) ? ON : OFF); m_sb_ucast = 1; } continue; + case 'T': + case 't': + if (ap_type == ATMEL12350 && + (ap_vendorext == GEMTEK || ap_vendorext == EZYNET)) { + get_value(message, 13, strlen(TRAP_PORT), 6, INT_STRING, + 0, 65535, HELP); + trap_port = atoi(message); + m_trap_port = 1; + } + continue; case 'w': case 'W': i = 0; if (m_filter) { - varbinds[i].oid = IPFilter; - varbinds[i].len_oid = sizeof(IPFilter); + varbinds[i].oid = operIPFilter; + varbinds[i].len_oid = sizeof(operIPFilter); varbinds[i].type = INT_VALUE; varbinds[i].value = (char *) &filter; varbinds[i].len_val = 1; i++; } if (m_primary_port) { - varbinds[i].oid = PrimaryPort; - varbinds[i].len_oid = sizeof(PrimaryPort); + varbinds[i].oid = operPrimaryPort; + varbinds[i].len_oid = sizeof(operPrimaryPort); varbinds[i].type = INT_VALUE; varbinds[i].value = (char *) &primary_port; varbinds[i].len_val = 1; @@ -479,32 +514,32 @@ void bridging() i++; } if (m_config_port) { - varbinds[i].oid = ConfigPort; - varbinds[i].len_oid = sizeof(ConfigPort); + varbinds[i].oid = operConfigurationPort; + varbinds[i].len_oid = sizeof(operConfigurationPort); varbinds[i].type = INT_VALUE; varbinds[i].value = (char *) &config_port; varbinds[i].len_val = 1; i++; } if (m_fw_bcast) { - varbinds[i].oid = ForwardBroadcast; - varbinds[i].len_oid = sizeof(ForwardBroadcast); + varbinds[i].oid = operForwarbBcast; + varbinds[i].len_oid = sizeof(operForwarbBcast); varbinds[i].type = INT_VALUE; varbinds[i].value = (char *) &fw_bcast; varbinds[i].len_val = 1; i++; } if (m_sb_bcast) { - varbinds[i].oid = SendBackBcast; - varbinds[i].len_oid = sizeof(SendBackBcast); + varbinds[i].oid = operSendBackBcast; + varbinds[i].len_oid = sizeof(operSendBackBcast); varbinds[i].type = INT_VALUE; varbinds[i].value = (char *) &sb_bcast; varbinds[i].len_val = 1; i++; } if (m_sb_ucast) { - varbinds[i].oid = SendBackUnicast; - varbinds[i].len_oid = sizeof(SendBackUnicast); + varbinds[i].oid = operSendBackUnicast; + varbinds[i].len_oid = sizeof(operSendBackUnicast); varbinds[i].type = INT_VALUE; varbinds[i].value = (char *) &sb_ucast; varbinds[i].len_val = 1; @@ -514,8 +549,8 @@ void bridging() int len_val; len_val = (trap_port > 0x7fff) ? 3 : (trap_port > 0x7f) ? 2 : 1; - varbinds[i].oid = TrapPort; - varbinds[i].len_oid = sizeof(TrapPort); + varbinds[i].oid = operTrapPort; + varbinds[i].len_oid = sizeof(operTrapPort); varbinds[i].type = STRING_VALUE; varbinds[i].value = (char *) &trap_port; varbinds[i].len_val = len_val; @@ -523,10 +558,13 @@ void bridging() } print_help(WAIT_SET); - if (snmp(varbinds, i, SET) <= 0) + if (snmp(varbinds, i, SET) <= 0) { print_helperr(ERR_SET); - else + } else { + wbkgd(main_sub, A_NORMAL); + wrefresh(main_sub); print_help(DONE_SET); + } goto exit; case 'Q': case 'q': @@ -540,4 +578,3 @@ void bridging() print_top(NULL, NULL); clear_main(0); } -