Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

interface.c

Go to the documentation of this file.
00001 /* Linux Prism II Stumbler - Utility Scan for 802_11 networks under Linux
00002  * 
00003  * File : interface.c
00004  * Project : WifiScanner (c) 2002 Hervé Schauer Consultants
00005  * Usage : This utility is written for use with IEEE 802.11 adapters based
00006  * on Intersil's PRISM II chipset (PCMCIA).
00007  * 
00008  * Base code was from prismstumbler Jan Fernquist <Jan.B.Fernquist@telia.com>
00009  * and wlanctl from www.linux-wlan.org
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  * 
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  * 
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00024  *
00025  * $Id: interface.c,v 1.20 2005/01/27 16:24:55 poggij Exp $
00026  */
00027 
00028 #include <include.h>
00029 #include <src/interface.h>
00030 #include <src/analyse.h>
00031 
00032 extern WINDOW *Title_WND, *Panel_WND, *Sum_WND, *RealTime_WND;
00033 extern Statistics_t Stats;
00034 
00035 //extern UINT8 DebugLevel;
00036 extern ConfigStruct config;
00037 extern UINT8 CursesIsInUse;
00038 
00039 #ifdef WITH_THREAD
00040 extern pthread_mutex_t screen_mutex;
00041 extern UINT8 stop_sniffing;
00042 #endif
00043 
00044 /*
00045  * Function to initialise the screen
00046  */
00047 void InitScreen(UINT8 CheckScreenSize)
00048 {
00049   initscr();
00050   cbreak();
00051   noecho();
00052   nonl();
00053   intrflush(stdscr, FALSE);
00054   keypad(stdscr, TRUE);
00055 
00056   if ((CheckScreenSize)
00057       && ((LINES < ROW_MINI_NEEDED) || (COLS < COL_MINI_NEEDED))) {
00058     endwin();
00059     fprintf(stderr,
00060             "\nSorry, This program requires a screen size of at least %d columns by %d lines\n",
00061             COL_MINI_NEEDED, ROW_MINI_NEEDED);
00062     fprintf(stderr, "Please resize your window\n\n");
00063     exit(1);
00064   }
00065 
00066   Title_WND = subwin(stdscr, ROW_WND_TITLE, COL_WND_TITLE, 0, 0);
00067   Panel_WND =
00068       subwin(stdscr, ROW_WND_PANEL, COL_WND_PANEL, ROW_WND_TITLE, 0);
00069   Sum_WND =
00070       subwin(stdscr, ROW_WND_SUM, COL_WND_SUM, ROW_WND_TITLE,
00071              COL_WND_PANEL);
00072   RealTime_WND =
00073       subwin(stdscr, ROW_WND_REALTIME, COL_WND_REALTIME,
00074              (ROW_WND_TITLE + ROW_WND_PANEL), 0);
00075 
00076   scrollok(RealTime_WND, TRUE);
00077   scrollok(Panel_WND, TRUE);
00078   //nodelay (RealTime_WND, TRUE);
00079   //werase(Sum_WND);
00080 
00081   box(Sum_WND, '|', '-');
00082   mvwprintw(Sum_WND, 0, 3, " Summary ");
00083   mvwprintw(Sum_WND, 1, 2, "AP     :");
00084   mvwprintw(Sum_WND, 2, 2, "STA    :");
00085   mvwprintw(Sum_WND, 3, 2, "BEACON :");
00086   mvwprintw(Sum_WND, 4, 2, "SSID   :");
00087   mvwprintw(Sum_WND, 5, 2, "Channel:");
00088   mvwprintw(Sum_WND, 6, 2, "Invalid:");
00089   mvwprintw(Sum_WND, 7, 2, "Crypted:");
00090   mvwprintw(Sum_WND, 8, 2, "Weak   :");
00091   mvwprintw(Sum_WND, 9, 2, "Last IV:");
00092   mvwprintw(Sum_WND, 10, 2, "Packets:");
00093 
00094   mvwprintw(Sum_WND, 12, 2, "Scan 00 - ABCDS");
00095   mvwprintw(Sum_WND, 13, 2, "|_____________  _|");
00096   mvwprintw(Sum_WND, 14, 3, "0000000001111  1");
00097   mvwprintw(Sum_WND, 15, 3, "1234567890123  4");
00098   mvwprintw(Sum_WND, 17, 3, "IDS is OFF");
00099 
00100   box(Panel_WND, '|', '-');
00101 
00102   wprintw(Title_WND,
00103           "WifiScanner v%s (c) 2002 Hervé Schauer Consultants (%s)\n",
00104           WIFISCANNER_VERSION, WIFISCANNER_BUG);
00105   RefreshAllWND();
00106 }
00107 
00108 void RefreshAllWND(void)
00109 {
00110 #ifdef WITH_THREAD
00111   pthread_mutex_lock(&screen_mutex);
00112 #endif
00113   wrefresh(Sum_WND);
00114   wrefresh(Panel_WND);
00115   wrefresh(RealTime_WND);
00116   wrefresh(Title_WND);
00117   refresh();
00118 #ifdef WITH_THREAD
00119   pthread_mutex_unlock(&screen_mutex);
00120 #endif
00121 }
00122 
00123 /* Write Stats in Summary Window */
00124 void WriteSummary(void)
00125 {
00126   char DisplayBit[5];
00127 
00128   DoSummary();
00129 
00130 #ifdef WITH_THREAD
00131   pthread_mutex_lock(&screen_mutex);
00132 #endif
00133   mvwprintw(Sum_WND, 1, 11, "%d", Stats.AP);
00134   mvwprintw(Sum_WND, 2, 11, "%d", Stats.STA);
00135   mvwprintw(Sum_WND, 3, 11, "%d", Stats.Beacon);
00136   mvwprintw(Sum_WND, 4, 11, "%d", Stats.SSID);
00137   mvwprintw(Sum_WND, 5, 11, "%d", Stats.Channel);
00138   mvwprintw(Sum_WND, 6, 11, "%d", Stats.INVLD);
00139   mvwprintw(Sum_WND, 7, 11, "%d", Stats.CryptedPackets);
00140   mvwprintw(Sum_WND, 8, 11, "%d", Stats.WeakIV);
00141 //  mvwprintw (Sum_WND, 9, 11, "%02X:%02X:%02X:%02X", Stats.IV[3], Stats.IV[2],
00142 //           Stats.IV[1], Stats.IV[0]);
00143   mvwprintw(Sum_WND, 9, 11, "%02X:%02X:%02X[%1X]", Stats.IV[2],
00144             Stats.IV[1], Stats.IV[0], (Stats.IV[3] & 0x03));
00145   mvwprintw(Sum_WND, 10, 11, "%d", Stats.Packets);
00146 
00147   if (IS_BIT_SET(config.DoNotDisplay, 0))
00148     DisplayBit[0] = 'A';
00149   else
00150     DisplayBit[0] = 'a';
00151 
00152   if (IS_BIT_SET(config.DoNotDisplay, 1))
00153     DisplayBit[1] = 'B';
00154   else
00155     DisplayBit[1] = 'b';
00156 
00157   if (IS_BIT_SET(config.DoNotDisplay, 2))
00158     DisplayBit[2] = 'C';
00159   else
00160     DisplayBit[2] = 'c';
00161 
00162   if (IS_BIT_SET(config.DoNotDisplay, 3))
00163     DisplayBit[3] = 'D';
00164   else
00165     DisplayBit[3] = 'd';
00166 
00167   if (IS_BIT_SET(config.DoNotDisplay, 4))
00168     DisplayBit[4] = 'S';
00169   else
00170     DisplayBit[4] = 's';
00171 
00172   DisplayBit[5] = 0;
00173   mvwprintw(Sum_WND, 12, 12, "%s", DisplayBit);
00174 
00175   wrefresh(Sum_WND);
00176 #ifdef WITH_THREAD
00177   pthread_mutex_unlock(&screen_mutex);
00178 #endif
00179 }
00180 
00181 
00182 /***
00183  * Function to refresh screen only one time per second
00184  *  This function is threaded, so it do more sleep than work ;-)
00185  ***/
00186 #ifdef WITH_THREAD
00187 void RefreshRealTime_WND_th(void)
00188 {
00189   struct tm *ascii_now;         // The timestamp in ASCII (human readable)
00190   struct timeb binary_now;
00191 
00192   while (!stop_sniffing) {
00193     ftime(&binary_now);
00194     ascii_now = localtime(&binary_now.time);
00195     pthread_mutex_lock(&screen_mutex);
00196     mvwprintw(Panel_WND, ROW_WND_PANEL - 1, 3,
00197               "Last Updt %02d:%02d:%02d ", ascii_now->tm_hour,
00198               ascii_now->tm_min, ascii_now->tm_sec);
00199     wrefresh(RealTime_WND);
00200     pthread_mutex_unlock(&screen_mutex);
00201     // Sleep for less than 1 second, but wake up at HH:MM:SS:000
00202     if (config.DebugLevel >= 2)
00203       usleep((1000 - binary_now.millitm) * 100);
00204     else
00205       usleep((1000 - binary_now.millitm) * 1000);
00206   }
00207   pthread_exit(0);
00208 }
00209 
00210 /***
00211  * This function is to give compatibility
00212  * and because wben debug is more or egual than 2 we refresh every packets
00213  ***/
00214 void RefreshRealTime_WND(UINT8 GotItOne)
00215 {
00216 /*
00217   if ((config.DebugLevel >= 2) && ()) {
00218     pthread_mutex_lock(&screen_mutex);
00219     wrefresh(RealTime_WND);
00220     pthread_mutex_unlock(&screen_mutex);
00221   }
00222  */
00223 }
00224 
00225 #else
00226 
00227 void RefreshRealTime_WND(UINT8 GotItOne)
00228 {
00229   static time_t now, last_time = 0;
00230   struct tm *ascii_now;         // The timestamp in ASCII (human readable)
00231   struct timeb binary_now;
00232   static UINT8 NeedToRefresh = FALSE;
00233 
00234   time(&now);
00235 
00236   if (GotItOne)
00237     NeedToRefresh = TRUE;
00238 
00239   if (((now != last_time) && (NeedToRefresh))
00240       || (config.DebugLevel >= 2)) {
00241     ftime(&binary_now);
00242     last_time = now;
00243     ascii_now = localtime(&binary_now.time);
00244     ascii_now = localtime(&now);
00245     mvwprintw(Panel_WND, ROW_WND_PANEL - 1, 3,
00246               "Last Updt %02d:%02d:%02d ", ascii_now->tm_hour,
00247               ascii_now->tm_min, ascii_now->tm_sec);
00248 
00249     wrefresh(RealTime_WND);
00250     NeedToRefresh = FALSE;
00251   }
00252 }
00253 #endif
00254 
00255 // Function to exit from ncurses environment
00256 void EndCurses(void)
00257 {
00258   CursesIsInUse = FALSE;
00259   endwin();
00260 }

Generated on Fri Feb 25 12:02:37 2005 for WifiScanner by  doxygen 1.4.1