diff -u tleds-1.05b/Makefile tleds-1.05b+wifi/Makefile --- tleds-1.05b/Makefile 1998-04-02 06:04:17.000000000 -0500 +++ tleds-1.05b+wifi/Makefile 2005-05-11 13:15:13.000000000 -0400 @@ -9,7 +9,7 @@ # For 2.1.x kernels, you have to include -DKERNEL2_1 option for gcc -GCCOPTS = -D_GNU_SOURCE -O3 -Wall +GCCOPTS = -D_GNU_SOURCE -O3 -Wall -DKERNEL2_1 # The first one is if you want to include X code xtleds: tleds.c Makefile diff -u tleds-1.05b/tleds.1 tleds-1.05b+wifi/tleds.1 --- tleds-1.05b/tleds.1 1998-03-22 15:01:00.000000000 -0500 +++ tleds-1.05b+wifi/tleds.1 2005-05-12 23:19:43.898401789 -0400 @@ -11,7 +11,7 @@ .B interface_name .br .B xtleds -.RB [ \-bchkqv +.RB [ \-bchkqvw ] .RB [ \-d .B N @@ -20,17 +20,18 @@ .SH DESCRIPTION These programs help you monitor network traffic. They blink Scroll-Lock LED (Light Emitting Diode) -when a network packet leaves the machine, and Num-Lock LED when one is -received. +when a network packet leaves the machine, Num-Lock LED when one is +received, and optionally Caps-Lock LED when a wireless network is +associated with an access point. .PP .I tleds can be started on Virtual Terminal (VT) without X-libraries (Xlib) installed. After started, the user can switch to X and tleds will be able to blink -LEDs if there is "Xleds 2 3" in the Keyboard section of the /etc/X11/XF86Config. +LEDs if there is "Xleds 1 2 3" in the Keyboard section of the /etc/X11/XF86Config. .PP .I xtleds can be started/run both on X and VT, and needs libX11.so You will need the line -"Xleds 2 3" in the XF86Config (see also BUGS) +"Xleds 1 2 3" in the XF86Config (see also BUGS) .PP tleds and xtleds when started from VT, and run as non root, need their tty to do @@ -101,6 +102,9 @@ -q Is pretty quiet. Doesn't tell you in the start what it will do. .TP +-w +Monitors wireless network interfaces' association status with CapsLock LED. +.TP -v Gives version information. .SH EXAMPLES diff -u tleds-1.05b/tleds.c tleds-1.05b+wifi/tleds.c --- tleds-1.05b/tleds.c 1998-10-05 16:32:56.000000000 -0400 +++ tleds-1.05b+wifi/tleds.c 2005-05-12 23:23:42.487086623 -0400 @@ -38,7 +38,7 @@ XkbDisable # Needed when EUID non root and Xfree v3.2 or v3.3 Xleds 2 3 # This line is a must. */ -#define VERSION "1.05beta10" +#define VERSION "1.05beta10+wifi" #define MYNAME "tleds" /* Supported kernel version */ @@ -91,11 +91,13 @@ #define CURRENTTTY "/dev/tty0" #define MAXVT 12 #define NETDEVFILENAME "/proc/net/dev" +#define NETWIRELESSFILENAME "/proc/net/wireless" #define TERMINATESTR "Program (and child) terminated.\n" #define DEEPSLEEP 10 #define REMINDVTDELAY 15 #define DEFPPPDELAY 200 #define DEFETHDELAY 50 +#define WIFIDELAY 1 #define CAPSLOCKLED 1 #define NUMLOCKLED 2 #define SCROLLLOCKLED 3 @@ -114,7 +116,7 @@ void create_pid_file (pid_t pid, const char* name); void detach_all_vt_leds (int wantDetach); ulong detach_vt_leds (int tty, int wantDetach); -char* find_device_line (char* buffer, char* netDeviceName); +char* find_device_line (char* buffer, char* netDeviceName, const char* fileName); inline int find_max_VT (); pid_t get_old_pid (); int get_sleeptime (int isDefinedByUser, char* interfaceName); @@ -136,6 +138,7 @@ /* Global and static variables */ static const char devFileName [] = NETDEVFILENAME; +static const char wirelessFileName [] = NETWIRELESSFILENAME; static char pidFileName [30] = ""; /* 30 should be enough */ static char rootPidFileName [30] = ""; #if (! REMOVE_X_CODE) @@ -147,9 +150,11 @@ static char ttyLEDs [MAXVT] = {}; static ushort previousActive = (ushort)(MAXVT + 1); static int remindVTcoef = 0; +static int checkwificoef = 0; +static int checkwificount = 0; /* first try right away */ static int opt_b = FALSE, opt_d = FALSE, opt_h = FALSE, opt_k = FALSE, opt_q = FALSE, opt_v = FALSE, - opt_V = FALSE, opt_c = FALSE; + opt_V = FALSE, opt_c = FALSE, opt_w = FALSE; /* The code */ int main (int argc, char* argv []) @@ -192,13 +197,16 @@ return 0; } if (! opt_q) { - printf("Setting keyboard LEDs based on %s %s %s %s\n", + printf("Setting keyboard LEDs based on %s %s %s %s", "changes of Receive/Transmit\npackets of", interfaceName, "in", devFileName); - printf("Delay between updates is %d milliseconds.\n", + if (opt_w) + printf(" and change of wireless network\nassociation status in %s", + wirelessFileName); + printf("\nDelay between updates is %d milliseconds.\n", sleeptime); } -if (! find_device_line(buffer, interfaceName) && !opt_q) { +if (! find_device_line(buffer, interfaceName, devFileName) && !opt_q) { printf( "There is currently no such interface as %s in %s.\n%s\n", interfaceName, devFileName, @@ -262,17 +270,33 @@ sleeptimeval.tv_sec = (int)((long)sleeptime * 1000L) / 1000000L; sleeptimeval.tv_usec = (int)((long)sleeptime * 1000L) % 1000000L; remindVTcoef = (int)( (long)REMINDVTDELAY * 1000L / (long)sleeptime ); +checkwificoef = (int)( (long)WIFIDELAY * 1000L / (long)sleeptime ); +checkwificount = checkwificoef + 1; /* first time is immediately after starting */ wasInDeepSleep = TRUE; /* The main loop */ while (1) { - if ((tmpPointer = find_device_line(buffer, interfaceName))) { + if ((tmpPointer = find_device_line(buffer, interfaceName, devFileName))) { if (wasInDeepSleep) { wasInDeepSleep = FALSE; detach_all_vt_leds(TRUE); } list = split_on_blank(tmpPointer); report_traffic(list); + + /* wifi */ + if (opt_w) { + if (checkwificount++ >= checkwificoef) { + checkwificount = 0; + if ((tmpPointer = find_device_line(buffer, interfaceName, wirelessFileName))) { + led(CAPSLOCKLED, SET, FINISH); + } + else { + led(CAPSLOCKLED, CLEAR, FINISH); + } + } + } + my_sleep(sleeptimeval); } else { if (! wasInDeepSleep) { @@ -286,21 +310,25 @@ return 0; /* Yeah right, never gets this far. */ } -char* find_device_line (char* buffer, char* netDeviceName) +char* find_device_line (char* buffer, char* netDeviceName, const char* fileName) { -static long fileOffset = 0L; +/*static long fileOffset = 0L;*/ register FILE* devFile; -if (! (devFile = fopen(devFileName, "r")) ) { - perror(devFileName); +if (! (devFile = fopen(fileName, "r")) ) { + perror(fileName); exit(1); } -/* Skip two lines. (the header) */ +/* Skip two lines. (the header) */ /* Two choices how to do this. Didn't find any differences in speed. */ #if 0 fgets(buffer, MAXLEN, devFile); -fgets(buffer, MAXLEN, devFile); +fgets(buffer, MAXLEN, devFile); +/* Er, why? having to strstr two extra lines is Not Important compared + * to counting on MAXLEN being close to the length of the lines in the + * file! */ #else +/* if (fileOffset) { fseek(devFile, fileOffset, SEEK_SET); } else { @@ -309,6 +337,7 @@ fgets(buffer, MAXLEN, devFile); fileOffset += (long)strlen(buffer); } +*/ #endif while ( fgets(buffer, MAXLEN, devFile) ) { @@ -439,6 +468,12 @@ else ledVal &= ~LED_NUM; break; + case CAPSLOCKLED: + if (mode == SET) + ledVal |= LED_CAP; + else + ledVal &= ~LED_CAP; + break; default: perror("tleds: wrong led-value"); exit(1); @@ -458,6 +493,7 @@ /* Well, we know from report_traffic(), LED_SCR is processed later. OK, kludge. */ ledReminder = ledVal & ~LED_SCR; + /*ledReminder = ledVal & ~LED_CAP;*/ } } } @@ -520,6 +556,8 @@ } ledVal &= ~LED_SCR; ledVal &= ~LED_NUM; +if (opt_w) + ledVal &= ~LED_CAP; if (!wantDetach && !is_on_X(tty)) { ioctl(tty, KDGKBLED, &ledVal); ledVal |= 0x08; /* Reattach. */ @@ -576,6 +614,8 @@ clear_led(NUMLOCKLED); clear_led(SCROLLLOCKLED); XCloseDisplay(myDisplay); /* X */ + if (opt_w) + clear_led(CAPSLOCKLED); #endif } detach_all_vt_leds(FALSE); /* re-attach */ @@ -710,7 +750,7 @@ { int c; -while(EOF != (c = getopt(argc, argv, "bcd:hkqvV"))) { +while(EOF != (c = getopt(argc, argv, "bcd:hkqvVw"))) { switch (c) { case 'V': opt_V = TRUE; @@ -738,6 +778,9 @@ case 'v': opt_v = TRUE; break; + case 'w': + opt_w = TRUE; + break; default: opt_h = TRUE; /* assert(0); */ @@ -763,6 +806,12 @@ fprintf(stderr, "You have to be EUID root for -c. -c removed.\n"); } +if (opt_c && opt_w) { + opt_c = FALSE; + if (! opt_q) + fprintf(stderr, + "-w option uses CapsLED. -c removed.\n"); +} } int get_sleeptime (int isDefinedByUser, char* interfaceName) @@ -815,7 +864,7 @@ printf("Usage: %s [-bchkqv] [-d ] \n", name); printf("Example: %s -d 300 ppp0\n", name); -printf("Options:\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", +printf("Options:\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", "\t-b\tDon't go to the background.", "\t-c\tFix the CapsLED in VTs. Only for EUID root.", "\t-d N\tSet update delay.", @@ -824,6 +873,7 @@ "\t-k\tKill (old) (x)tleds running.", "\t-q\tBe quiet.", "\t-v\tPrint version information.", + "\t-w\tDisplay wireless network association state on CapsLED.", "\t\t(`cat /proc/net/dev` to see your interfaces.)"); }