#include <fcntl.h>
#include <signal.h>
#include <string.h>
+#include <sys/time.h>
#include <sys/wait.h>
#include "ap-utils.h"
-#include "ap-curses.h"
-#define ERR_RET_PRESS _("Unable to get data from AP. Press Q to continue.")
-#define QHELP _("Q - quit to menu.")
-#define PIPE _("pipe error. Press any key.")
-#define FCNTL _("fcntl error. Press any key.")
-#define FORK _("fork error. Press any key.")
+#define ETH_STAT _("Ethernet Statistics")
+#define W_STAT _("Wireless Statistics")
extern WINDOW *main_sub;
extern short ap_type;
+extern int wait_mode, poll_delay;
void EthStat()
{
- struct EthernetRxStatistics *EthRxStat = NULL;
- struct EthernetTxStatistics *EthTxStat = NULL;
+ struct EthRxStatistics_s *EthRxStat = NULL;
+ struct EthTxStatistics_s *EthTxStat = NULL;
- char EthRx[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01,
- 0x07, 0x01, 0x00
+ char EthRxStatistics[] = {
+ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x07, 0x01, 0x00
};
-
- char EthTx[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01,
- 0x07, 0x02, 0x00
+ char EthTxStatistics[] = {
+ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x07, 0x02, 0x00
};
- char c;
+
char message[1024];
- pid_t pid;
- int j, child_pipe[2];
varbind varbinds[2];
+ int i;
if (ap_type == ATMEL12350) {
- EthRx[5] = 0xE0;
- EthRx[6] = 0x3E;
- EthTx[5] = 0xE0;
- EthTx[6] = 0x3E;
+ EthRxStatistics[5] = 0xE0;
+ EthRxStatistics[6] = 0x3E;
+ EthTxStatistics[5] = 0xE0;
+ EthTxStatistics[6] = 0x3E;
}
- if (pipe(child_pipe) == -1) {
- print_helperr(PIPE);
- goto exit;
- }
-
- if (fcntl(child_pipe[0], F_SETFL, O_NONBLOCK) == -1) {
- print_helperr(FCNTL);
- goto exit;
- }
- print_title(_("Ethernet Statistics"));
- print_help(QHELP);
+ print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, ETH_STAT);
noecho();
- switch (pid = fork()) {
- case -1:
- print_helperr(FORK);
- goto exit;
- case 0:
- close(child_pipe[1]);
- varbinds[0].oid = EthRx;
- varbinds[0].len_oid = sizeof(EthRx);
- varbinds[1].oid = EthTx;
- varbinds[1].len_oid = sizeof(EthTx);
-
- start:
- varbinds[0].value = EthTx;
+ if (wait_mode == WAIT_TIMEOUT)
+ print_help(QT_HELP);
+
+ varbinds[0].oid = EthRxStatistics;
+ varbinds[0].len_oid = sizeof(EthRxStatistics);
+ varbinds[1].oid = EthTxStatistics;
+ varbinds[1].len_oid = sizeof(EthTxStatistics);
+
+ while (1) {
+// varbinds[0].value = EthRxStatistics;
varbinds[0].len_val = 0;
varbinds[0].type = NULL_VALUE;
- varbinds[1].value = EthTx;
+// varbinds[1].value = EthTxStatistics;
varbinds[1].len_val = 0;
varbinds[1].type = NULL_VALUE;
- if (snmp(varbinds, 2, GET) <= 0) {
- print_helperr(ERR_RET_PRESS);
- goto exit_child;
+ if (wait_mode == WAIT_FOREVER)
+ print_help(WAIT_RET);
+
+ if (snmp(varbinds, 2, GET) < 2) {
+ print_helperr(ERR_RET);
+ getch();
+ goto quit;
}
+ if (wait_mode == WAIT_FOREVER)
+ print_help(QT_HELP);
+
if (varbinds[0].len_val == 64) {
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 {
- print_helperr(_("EthRxStat packet error. Press Q to continue."));
- goto exit_child;
+ print_helperr(_("EthRxStat packet error. Press any key."));
+ getch();
+ goto quit;
}
if (varbinds[1].len_val == 56) {
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 {
- print_helperr(_("EthTxStat packet error. Press Q to continue."));
- goto exit_child;
+ print_helperr(_("EthTxStat packet error. Press any key."));
+ getch();
+ goto quit;
}
mvwaddstr(main_sub, 1, 2, _("Received:"));
mvwaddstr(main_sub, 1, 30, _("Transmitted:"));
swap4(EthTxStat->TotalCollisionsTx));
mvwaddstr(main_sub, 18, 2, message);
wrefresh(main_sub);
- exit_child:
- switch (j = read(child_pipe[0], &c, 1)) {
- case -1:
- break;
- default:
- exit(0);
+
+ i = wait_key(poll_delay);
+ if (i == -1)
+ goto quit;
+
+ switch((char) i) {
+ case 'q':
+ case 'Q':
+ goto quit;
+ case 't':
+ case 'T':
+ wait_mode = (wait_mode == WAIT_FOREVER ?
+ WAIT_TIMEOUT : WAIT_FOREVER);
+ print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF,
+ ETH_STAT);
}
- sleep(1);
- goto start;
- default:
- close(child_pipe[0]);
- while (getch() != 'q');
- write(child_pipe[1], "0", 1);
- wait((int *) 0);
- close(child_pipe[1]);
- goto quit;
+
+ /* either timeout for user input (i == 0) or invalid key => continue */
}
- exit:
- getch();
quit:
if (EthRxStat)
free(EthRxStat);
free(EthTxStat);
wclear(main_sub);
- print_title("");
+ print_top(NULL, NULL);
clear_main(0);
return;
}
void WirelessStat()
{
- struct WirelessStatistics *WirelessStat = NULL;
+ struct wirelessStatistics_s *WirelessStat = NULL;
- char Wireless[] =
- { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x03, 0x01,
- 0x00
+ char wirelessStatistics[] = {
+ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x03, 0x01, 0x00
};
- char message[80], c;
- pid_t pid;
- int j, child_pipe[2];
+ char message[80];
+ int i;
varbind varbinds[1];
if (ap_type == ATMEL12350) {
- Wireless[5] = 0xE0;
- Wireless[6] = 0x3E;
+ wirelessStatistics[5] = 0xE0;
+ wirelessStatistics[6] = 0x3E;
}
- if (pipe(child_pipe) == -1) {
- print_helperr(PIPE);
- goto exit;
- }
-
- if (fcntl(child_pipe[0], F_SETFL, O_NONBLOCK) == -1) {
- print_helperr(FCNTL);
- goto exit;
- }
- print_title(_("Wireless Statistics"));
- print_help(QHELP);
+ print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, W_STAT);
noecho();
- switch (pid = fork()) {
- case -1:
- print_helperr(FORK);
- goto exit_child;
- case 0:
- close(child_pipe[1]);
- varbinds[0].oid = Wireless;
- varbinds[0].len_oid = sizeof(Wireless);
-
- start:
- varbinds[0].value = Wireless;
+ if (wait_mode == WAIT_TIMEOUT)
+ print_help(QT_HELP);
+
+ varbinds[0].oid = wirelessStatistics;
+ varbinds[0].len_oid = sizeof(wirelessStatistics);
+
+ while (1) {
+ varbinds[0].value = wirelessStatistics;
varbinds[0].len_val = 0;
varbinds[0].type = NULL_VALUE;
+ if (wait_mode == WAIT_FOREVER)
+ print_help(WAIT_RET);
+
if (snmp(varbinds, 1, GET) <= 0) {
- print_helperr(ERR_RET_PRESS);
- goto exit_child;
+ print_helperr(ERR_RET);
+ getch();
+ goto quit;
}
- if (varbinds[0].len_val == 88) {
+ if (wait_mode == WAIT_FOREVER)
+ print_help(QT_HELP);
+
+ 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 {
print_helperr
- (_("WirelessStat packet error. Press Q to continue."));
- goto exit;
+ (_("WirelessStat packet error. Press any key."));
+ getch();
+ goto quit;
}
sprintf(message,
swap4(WirelessStat->InvalidPLCP));
mvwaddstr(main_sub, 15, 1, message);
+ /* ATMEL12350 MIB EZYNET modification has in addition the following */
+ if (varbinds[0].len_val == 104) {
+ mvwaddstr(main_sub, 16, 1, "TransmittedPackets:");
+ sprintf(message, "* at 11 Mbps %10u",
+ swap4(WirelessStat->TransmittedPackets_11Mbps));
+ mvwaddstr(main_sub, 17, 1, message);
+ sprintf(message, "* at 5.5 Mbps %10u",
+ swap4(WirelessStat->TransmittedPackets_55Mbps));
+ mvwaddstr(main_sub, 18, 1, message);
+ sprintf(message, "* at 2 Mbps %10u",
+ swap4(WirelessStat->TransmittedPackets_2Mbps));
+ mvwaddstr(main_sub, 19, 1, message);
+ sprintf(message, "* at 1 Mbps %10u",
+ swap4(WirelessStat->TransmittedPackets_1Mbps));
+ mvwaddstr(main_sub, 20, 1, message);
+ }
wrefresh(main_sub);
- exit_child:
- switch (j = read(child_pipe[0], &c, 1)) {
- case -1:
- break;
- default:
- exit(0);
+
+ i = wait_key(poll_delay);
+ if (i == -1)
+ goto quit;
+
+ switch((char) i) {
+ case 'q':
+ case 'Q':
+ goto quit;
+ case 't':
+ case 'T':
+ wait_mode = (wait_mode == WAIT_FOREVER ?
+ WAIT_TIMEOUT : WAIT_FOREVER);
+ print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF,
+ W_STAT);
}
- sleep(1);
- goto start;
- default:
- close(child_pipe[0]);
- while (getch() != 'q');
- write(child_pipe[1], "0", 1);
- wait((int *) 0);
- close(child_pipe[1]);
- goto quit;
+
+ /* either timeout for user input (i == 0) or invalid key => continue */
}
- exit:
- getch();
quit:
if (WirelessStat)
free(WirelessStat);
wclear(main_sub);
- print_title("");
+ print_top(NULL, NULL);
clear_main(0);
}
char oid_dot11WEPExcludedCount[] =
{ 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x05, 0x01, 0x06, 0x01 };
- char message[80], c;
- pid_t pid;
- int j, child_pipe[2], i;
+ char message[80];
+ int i;
varbind varbinds[16];
curs_set(0);
- if (pipe(child_pipe) == -1) {
- print_helperr(_("pipe error. Press any key"));
- goto exit;
- }
-
- if (fcntl(child_pipe[0], F_SETFL, O_NONBLOCK) == -1) {
- print_helperr(_("fcntl error. Press any key"));
- goto exit;
- }
- print_title(_("Wireless Statistics"));
- print_help(_("Q - quit to menu."));
+ print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, W_STAT);
noecho();
- switch (pid = fork()) {
- case -1:
- print_helperr(_("fork error. Press any key"));
- goto exit_child;
- case 0:
- close(child_pipe[1]);
- varbinds[0].oid = oid_dot11TransmittedFragmentCount;
- varbinds[0].len_oid = sizeof(oid_dot11TransmittedFragmentCount);
- varbinds[1].oid = oid_dot11MulticastTransmittedFrameCount;
- varbinds[1].len_oid =
- sizeof(oid_dot11MulticastTransmittedFrameCount);
- varbinds[2].oid = oid_dot11FailedCount;
- varbinds[2].len_oid = sizeof(oid_dot11FailedCount);
- varbinds[3].oid = oid_dot11RetryCount;
- varbinds[3].len_oid = sizeof(oid_dot11RetryCount);
- varbinds[4].oid = oid_dot11MultipleRetryCount;
- varbinds[4].len_oid = sizeof(oid_dot11MultipleRetryCount);
- varbinds[5].oid = oid_dot11FrameDuplicateCount;
- varbinds[5].len_oid = sizeof(oid_dot11FrameDuplicateCount);
- varbinds[6].oid = oid_dot11RTSSuccessCount;
- varbinds[6].len_oid = sizeof(oid_dot11RTSSuccessCount);
- varbinds[7].oid = oid_dot11RTSFailureCount;
- varbinds[7].len_oid = sizeof(oid_dot11RTSFailureCount);
- varbinds[8].oid = oid_dot11ACKFailureCount;
- varbinds[8].len_oid = sizeof(oid_dot11ACKFailureCount);
- varbinds[9].oid = oid_dot11ReceivedFragmentCount;
- varbinds[9].len_oid = sizeof(oid_dot11ReceivedFragmentCount);
- varbinds[10].oid = oid_dot11MulticastReceivedFrameCount;
- varbinds[10].len_oid =
- sizeof(oid_dot11MulticastReceivedFrameCount);
- varbinds[11].oid = oid_dot11FCSErrorCount;
- varbinds[11].len_oid = sizeof(oid_dot11FCSErrorCount);
- varbinds[12].oid = oid_dot11TransmittedFrameCount;
- varbinds[12].len_oid = sizeof(oid_dot11TransmittedFrameCount);
- varbinds[13].oid = oid_dot11WEPUndecryptableCount;
- varbinds[13].len_oid = sizeof(oid_dot11WEPUndecryptableCount);
- varbinds[14].oid = oid_dot11WEPICVErrorCount;
- varbinds[14].len_oid = sizeof(oid_dot11WEPICVErrorCount);
- varbinds[15].oid = oid_dot11WEPExcludedCount;
- varbinds[15].len_oid = sizeof(oid_dot11WEPExcludedCount);
-
- start:
+ if (wait_mode == WAIT_TIMEOUT)
+ print_help(QT_HELP);
+
+ varbinds[0].oid = oid_dot11TransmittedFragmentCount;
+ varbinds[0].len_oid = sizeof(oid_dot11TransmittedFragmentCount);
+ varbinds[1].oid = oid_dot11MulticastTransmittedFrameCount;
+ varbinds[1].len_oid = sizeof(oid_dot11MulticastTransmittedFrameCount);
+ varbinds[2].oid = oid_dot11FailedCount;
+ varbinds[2].len_oid = sizeof(oid_dot11FailedCount);
+ varbinds[3].oid = oid_dot11RetryCount;
+ varbinds[3].len_oid = sizeof(oid_dot11RetryCount);
+ varbinds[4].oid = oid_dot11MultipleRetryCount;
+ varbinds[4].len_oid = sizeof(oid_dot11MultipleRetryCount);
+ varbinds[5].oid = oid_dot11FrameDuplicateCount;
+ varbinds[5].len_oid = sizeof(oid_dot11FrameDuplicateCount);
+ varbinds[6].oid = oid_dot11RTSSuccessCount;
+ varbinds[6].len_oid = sizeof(oid_dot11RTSSuccessCount);
+ varbinds[7].oid = oid_dot11RTSFailureCount;
+ varbinds[7].len_oid = sizeof(oid_dot11RTSFailureCount);
+ varbinds[8].oid = oid_dot11ACKFailureCount;
+ varbinds[8].len_oid = sizeof(oid_dot11ACKFailureCount);
+ varbinds[9].oid = oid_dot11ReceivedFragmentCount;
+ varbinds[9].len_oid = sizeof(oid_dot11ReceivedFragmentCount);
+ varbinds[10].oid = oid_dot11MulticastReceivedFrameCount;
+ varbinds[10].len_oid = sizeof(oid_dot11MulticastReceivedFrameCount);
+ varbinds[11].oid = oid_dot11FCSErrorCount;
+ varbinds[11].len_oid = sizeof(oid_dot11FCSErrorCount);
+ varbinds[12].oid = oid_dot11TransmittedFrameCount;
+ varbinds[12].len_oid = sizeof(oid_dot11TransmittedFrameCount);
+ varbinds[13].oid = oid_dot11WEPUndecryptableCount;
+ varbinds[13].len_oid = sizeof(oid_dot11WEPUndecryptableCount);
+ varbinds[14].oid = oid_dot11WEPICVErrorCount;
+ varbinds[14].len_oid = sizeof(oid_dot11WEPICVErrorCount);
+ varbinds[15].oid = oid_dot11WEPExcludedCount;
+ varbinds[15].len_oid = sizeof(oid_dot11WEPExcludedCount);
+
+ while (1) {
for (i = 0; i < 16; i++) {
varbinds[i].value = oid_dot11TransmittedFragmentCount;
varbinds[i].len_val = 0;
varbinds[i].type = 0x05;
}
- if (snmp(varbinds, 16, GET) <= 0) {
- print_helperr(ERR_RET_PRESS);
- goto exit_child;
+
+ if (wait_mode == WAIT_FOREVER)
+ print_help(WAIT_RET);
+
+ if (snmp(varbinds, 16, GET) < 16) {
+ print_helperr(ERR_RET);
+ getch();
+ goto quit;
}
+ if (wait_mode == WAIT_FOREVER)
+ print_help(QT_HELP);
+
sprintf(message, "FragmentTx %10lu FragmentRx %10lu",
(long) swap4(*varbinds[0].value), (long) swap4(*varbinds[9].value));
mvwaddstr(main_sub, 1, 1, message);
(long) swap4(*(varbinds[14].value)));
mvwaddstr(main_sub, 10, 1, message);
wrefresh(main_sub);
- exit_child:
- switch (j = read(child_pipe[0], &c, 1)) {
- case -1:
- break;
- default:
- exit(0);
+
+ i = wait_key(poll_delay);
+ if (i == -1)
+ goto quit;
+
+ switch((char) i) {
+ case 'q':
+ case 'Q':
+ goto quit;
+ case 't':
+ case 'T':
+ wait_mode = (wait_mode == WAIT_FOREVER ?
+ WAIT_TIMEOUT : WAIT_FOREVER);
+ print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF,
+ W_STAT);
}
- sleep(1);
- goto start;
- default:
- close(child_pipe[0]);
- while (getch() != 'q');
- write(child_pipe[1], "0", 1);
- wait((int *) 0);
- close(child_pipe[1]);
- goto quit;
+
+ /* either timeout for user input (i == 0) or invalid key => continue */
}
- exit:
- getch();
quit:
wclear(main_sub);
- print_title("");
+ print_top(NULL, NULL);
clear_main(0);
}
+