X-Git-Url: https://git.decadent.org.uk/gitweb/?p=ap-utils.git;a=blobdiff_plain;f=src%2Fap-mrtg.c;fp=src%2Fap-mrtg.c;h=7dec50ace31fcf7d28dfc20e701c1777a432dc14;hp=296a37ac4f5dbccb45d923eb0cebb51421c0355e;hb=1aac4ac30a9a0d6cd2182013d2b3fd48b65ed2fd;hpb=5c77e013a46530bb3650f61d768dfed0dd3b72cb diff --git a/src/ap-mrtg.c b/src/ap-mrtg.c index 296a37a..7dec50a 100644 --- a/src/ap-mrtg.c +++ b/src/ap-mrtg.c @@ -32,36 +32,31 @@ #define ERR_STR_V "\n\n-\n\n" #define ERR_STR_N "999999999\n999999999\n-\n\n" -short ap_type = ATMEL410; +short ap_type; char *community = NULL; -int sockfd; struct in_addr ap_ip; void usage() { printf(_("\nUsage:\n")); - printf(_ - ("\tap-mrtg -i ip -c community -t type [-b bssid] [-n name] [-a aptype] [-v] [-h] [-r]\n\n")); - printf(_ - ("Get stats from AP and return it in MRTG parsable format\n\n")); + printf(_("\tap-mrtg -i ip -c community -t type [-b bssid] [-n name] " + "[-v] [-h] [-r]\n\n")); + printf(_("Get stats from AP and return it in MRTG parsable format\n\n")); printf(_("-i ip - AP ip address\n")); printf(_("-c community - SNMP community string\n")); - printf(_ - ("-t type - statistics type ireless, thernet, associated tations or ink quality in client mode\n")); - printf(_ - ("-b bssid - mac address of the AP to which get link quality, only if type=l\n")); - printf(_("-n name - AP name - for check only\n")); - printf(_("-a aptype - AP type - 410 (default) or 510 for ATMEL12350's, like the ME-102\n")); - printf(_ - ("-v - report MRTG about problems connecting to AP\n")); + printf(_("-t type - statistics type ireless, thernet, " + "associated tations or ink quality (last one will only ")); + printf(_("work with ATMEL410 MIB devices in AP Client mode)\n")); + printf(_("-b bssid - mac address of the AP from which get link quality" + ", only if type=l\n")); + printf(_("-n name - AP name - for check only\n")); + printf(_("-v - report MRTG about problems connecting to AP\n")); printf(_("-r - reset AP when getting LinkQuality stats\n")); printf(_("-h - print this help screen\n\n")); printf(_("ap-mrtg %s Copyright (c) 2002-2003 Roman Festchook\n\n"), VERSION); - } - int main(int argc, char **argv) { extern char *optarg; @@ -81,43 +76,41 @@ int main(int argc, char **argv) unsigned char essid[32]; } *app = NULL; - char Wireless[] = - { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x03, 0x01, - 0x00 + char sysDescr_NWN[] = { + 0x2B, 0x06, 0x01, 0x02, 0x01, 0x01, 0x01, 0x00 + }; + char sysDescr_ATMEL[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x01, 0x00 }; - char EthRx[] = - { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x07, 0x01, - 0x00 + char bridgeOperationalMode[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01, 0x00 }; - char EthTx[] = - { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x07, 0x02, - 0x00 + char EthRxStatistics[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x07, 0x01, 0x00 }; - char operAccessPointName[] = - { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x01, 0x0A, - 0x00 + char EthTxStatistics[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x07, 0x02, 0x00 }; - char StasNum[] = - { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x05, 0x01, - 0x00 + char operAccessPointName[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x01, 0x0A, 0x00 }; - char KnownAP[] = - { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x07, - 0x01, 0x00 + char wirelessStatistics[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x03, 0x01, 0x00 }; - char bridgeOperationalMode[] = - { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, - 0x01, 0x04, 0x01, 0x00 + char AssociatedSTAsNum[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x05, 0x01, 0x00 + }; + char wirelessKnownAPs[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x07, 0x01, 0x00 }; - struct EthernetRxStatistics *EthRxStat = NULL; - struct EthernetTxStatistics *EthTxStat = NULL; - struct WirelessStatistics *WirelessStat = NULL; + struct EthRxStatistics_s *EthRxStat = NULL; + struct EthTxStatistics_s *EthTxStat = NULL; + struct wirelessStatistics_s *WirelessStat = NULL; varbind varbinds[2]; int i, reset_flag=0; char message[12], bssid_flag, stat_type = 0, *ERR_STR = - ERR_STR_N, *bssid = NULL, *name = NULL; - struct sockaddr_in client; + ERR_STR_N, *bssid = NULL, *name = NULL, *cp; #ifdef HAVE_GETTEXT setlocale(LC_ALL, ""); @@ -125,11 +118,6 @@ int main(int argc, char **argv) textdomain("ap-utils"); #endif - memset(&client, 0, sizeof client); - client.sin_family = AF_INET; - client.sin_port = INADDR_ANY; - client.sin_addr.s_addr = INADDR_ANY; - if (argc < 4) { usage(); exit(0); @@ -137,10 +125,11 @@ int main(int argc, char **argv) do { opterr = 0; - switch (opt = getopt(argc, argv, "i:c:t:b:n:a:rv")) { + switch (opt = getopt(argc, argv, "i:c:t:b:n:rv")) { case 'i': - if (inet_aton(optarg, &ap_ip) == 0) { - printf(_("Invalid IP-address\n")); + for (cp = optarg, i = 0; *cp && (cp = index(cp, '.')); cp++, i++); + if (i < 3 || inet_aton(optarg, &ap_ip) == 0) { + printf(_("Error: invalid IP-address.\n")); return 1; } break; @@ -165,30 +154,6 @@ int main(int argc, char **argv) case 'r': reset_flag=1; break; - case 'a': - if ( strcmp( optarg, "510\0" ) == 0) { - Wireless[5] = 0xE0; - Wireless[6] = 0x3E; - EthRx[5] = 0xE0; - EthRx[6] = 0x3E; - EthTx[5] = 0xE0; - EthTx[6] = 0x3E; - operAccessPointName[5] = 0xE0; - operAccessPointName[6] = 0x3E; - StasNum[5] = 0xE0; - StasNum[6] = 0x3E; - KnownAP[5] = 0xE0; - KnownAP[6] = 0x3E; - bridgeOperationalMode[5] = 0xE0; - bridgeOperationalMode[6] = 0x3E; - } else if (strcmp(optarg, "410") == 0) { - /* nothing - hard-coded defaults are fine */ - } else { - /* Invalid AP-Type */ - printf(_("Invalid AP-Type '%s' - valid types are 510 or 410\n"), optarg); - return 1; - } - break; case -1: break; default: @@ -202,32 +167,84 @@ int main(int argc, char **argv) goto quit; } + /* + * Part detecting ap_type (ATMEL AP MIB type) follows. + * We could use get_mib_details() here with advantage, but it would + * have to involve 1. putting it to separate file in lib/ and + * 2. patch it so it would not contain curses-related commands (TODO) + */ + + /* determine private MIB type according to enterprises ID */ + varbinds[0].oid = sysDescr_NWN; + varbinds[0].len_oid = sizeof(sysDescr_NWN); + varbinds[0].value = NULL; + varbinds[0].len_val = 0; + varbinds[0].type = NULL_VALUE; + if (snmp(varbinds, 1, GET) > 0) { + ap_type = NWN; + } else { + varbinds[0].oid = sysDescr_ATMEL; + varbinds[0].len_oid = sizeof(sysDescr_ATMEL); + varbinds[0].value = NULL; + varbinds[0].len_val = 0; + varbinds[0].type = NULL_VALUE; + if (snmp(varbinds, 1, GET) > 0) { + ap_type = ATMEL410; + } else { + sysDescr_ATMEL[5] = 0xE0; + sysDescr_ATMEL[6] = 0x3E; + varbinds[0].oid = sysDescr_ATMEL; + varbinds[0].len_oid = sizeof(sysDescr_ATMEL); + varbinds[0].value = NULL; + varbinds[0].len_val = 0; + varbinds[0].type = NULL_VALUE; + if (snmp(varbinds, 1, GET) > 0) { + ap_type = ATMEL12350; + } else { + printf(_("Unable to determine AP MIB type " + "(no response from AP).")); + return 1; + } + } + } - if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { - perror(_("Create socket error")); + if (ap_type == NWN) { + printf("NWN devices are not yet supported."); return 1; } - if (bind(sockfd, (struct sockaddr *) &client, SIZE) == -1) { - perror(_("Bind socket error")); - return 1; + + if (ap_type == ATMEL12350) { + bridgeOperationalMode[5] = 0xE0; + bridgeOperationalMode[6] = 0x3E; + EthRxStatistics[5] = 0xE0; + EthRxStatistics[6] = 0x3E; + EthTxStatistics[5] = 0xE0; + EthTxStatistics[6] = 0x3E; + operAccessPointName[5] = 0xE0; + operAccessPointName[6] = 0x3E; + wirelessStatistics[5] = 0xE0; + wirelessStatistics[6] = 0x3E; + AssociatedSTAsNum[5] = 0xE0; + AssociatedSTAsNum[6] = 0x3E; + wirelessKnownAPs[5] = 0xE0; + wirelessKnownAPs[6] = 0x3E; } switch (stat_type) { case 'e': - - varbinds[0].oid = EthRx; - varbinds[0].len_oid = sizeof(EthRx); - varbinds[0].value = EthRx; + varbinds[0].oid = EthRxStatistics; + varbinds[0].len_oid = sizeof(EthRxStatistics); + varbinds[0].value = EthRxStatistics; varbinds[0].len_val = 0; varbinds[0].type = NULL_VALUE; - varbinds[1].oid = EthTx; - varbinds[1].len_oid = sizeof(EthTx); - varbinds[1].value = EthTx; + varbinds[1].oid = EthTxStatistics; + varbinds[1].len_oid = sizeof(EthTxStatistics); + varbinds[1].value = EthTxStatistics; varbinds[1].len_val = 0; varbinds[1].type = NULL_VALUE; - if (snmp(varbinds, 2, GET) <= 0) { + if (snmp(varbinds, 2, GET) < 2) { printf(ERR_STR); return 1; } @@ -236,7 +253,7 @@ int main(int argc, char **argv) if (EthRxStat) free(EthRxStat); EthRxStat = - (struct EthernetRxStatistics *) malloc(varbinds[0]. + (struct EthRxStatistics_s *) malloc(varbinds[0]. len_val); memcpy(EthRxStat, varbinds[0].value, varbinds[0].len_val); } else { @@ -248,7 +265,7 @@ int main(int argc, char **argv) if (EthTxStat) free(EthTxStat); EthTxStat = - (struct EthernetTxStatistics *) malloc(varbinds[1]. + (struct EthTxStatistics_s *) malloc(varbinds[1]. len_val); memcpy(EthTxStat, varbinds[1].value, varbinds[1].len_val); } else { @@ -263,9 +280,9 @@ int main(int argc, char **argv) free(EthTxStat); break; case 'w': - varbinds[0].oid = Wireless; - varbinds[0].len_oid = sizeof(Wireless); - varbinds[0].value = Wireless; + varbinds[0].oid = wirelessStatistics; + varbinds[0].len_oid = sizeof(wirelessStatistics); + varbinds[0].value = wirelessStatistics; varbinds[0].len_val = 0; varbinds[0].type = NULL_VALUE; @@ -274,11 +291,15 @@ int main(int argc, char **argv) return 1; } - if (varbinds[0].len_val == 88) { + if (varbinds[0].len_val == 88 || varbinds[0].len_val == 104) { + /* + * 88 ... using traditional ATMEL 12350 MIB + * 104 .. using functionally enhanced ATMEL 12350 MIB by EZYNET + */ if (WirelessStat) free(WirelessStat); WirelessStat = - (struct WirelessStatistics *) malloc(varbinds[0].len_val); + (struct wirelessStatistics_s *) malloc(varbinds[0].len_val); memcpy(WirelessStat, varbinds[0].value, varbinds[0].len_val); } else { printf(ERR_STR); @@ -294,9 +315,9 @@ int main(int argc, char **argv) break; case 's': - varbinds[0].oid = StasNum; - varbinds[0].len_oid = sizeof(StasNum); - varbinds[0].value = StasNum; + varbinds[0].oid = AssociatedSTAsNum; + varbinds[0].len_oid = sizeof(AssociatedSTAsNum); + varbinds[0].value = AssociatedSTAsNum; varbinds[0].len_val = 0; varbinds[0].type = NULL_VALUE; @@ -309,7 +330,6 @@ int main(int argc, char **argv) break; case 'l': - varbinds[0].oid = bridgeOperationalMode; varbinds[0].len_oid = sizeof(bridgeOperationalMode); varbinds[0].len_val = 0; @@ -320,7 +340,7 @@ int main(int argc, char **argv) return 1; } - if (*(varbinds[0].value) != 3) { + if (!(ap_type == ATMEL410 && *(varbinds[0].value) == 3)) { printf(ERR_STR); return 1; } @@ -332,9 +352,9 @@ int main(int argc, char **argv) } sleep(10); } - - varbinds[0].oid = KnownAP; - varbinds[0].len_oid = sizeof(KnownAP); + + varbinds[0].oid = wirelessKnownAPs; + varbinds[0].len_oid = sizeof(wirelessKnownAPs); varbinds[0].type = NULL_VALUE; varbinds[0].len_val = 0; @@ -373,7 +393,6 @@ int main(int argc, char **argv) printf("-\n"); - if ( name != NULL ) { varbinds[0].oid = operAccessPointName; varbinds[0].len_oid = sizeof(operAccessPointName); @@ -394,9 +413,6 @@ int main(int argc, char **argv) printf("-\n"); } - close(sockfd); - - quit: if (community) free(community); @@ -408,4 +424,3 @@ int main(int argc, char **argv) free(name); return 0; } -