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 168 2007-07-16 08:37:47Z poggij $
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 000 - 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-2008 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[8];
00127 
00128   DoSummary();
00129 
00130 #ifdef WITH_THREAD
00131   pthread_mutex_lock(&screen_mutex);
00132 #endif
00133 
00134   mvwprintw(Sum_WND, 1, 11, "%d", Stats.AP);
00135   mvwprintw(Sum_WND, 2, 11, "%d", Stats.STA);
00136   mvwprintw(Sum_WND, 3, 11, "%d", Stats.Beacon);
00137   mvwprintw(Sum_WND, 4, 11, "%d", Stats.SSID);
00138   mvwprintw(Sum_WND, 5, 11, "%d", Stats.Channel);
00139   mvwprintw(Sum_WND, 6, 11, "%d", Stats.INVLD);
00140   mvwprintw(Sum_WND, 7, 11, "%d", Stats.CryptedPackets);
00141   mvwprintw(Sum_WND, 8, 11, "%d", Stats.WeakIV);
00142 //  mvwprintw (Sum_WND, 9, 11, "%02X:%02X:%02X:%02X", Stats.IV[3], Stats.IV[2],
00143 //           Stats.IV[1], Stats.IV[0]);
00144   mvwprintw(Sum_WND, 9, 11, "%02X:%02X:%02X[%1X]", Stats.IV[2],
00145             Stats.IV[1], Stats.IV[0], (Stats.IV[3] & 0x03));
00146   mvwprintw(Sum_WND, 10, 11, "%d", Stats.Packets);
00147 
00148   if (IS_BIT_SET(config.DoNotDisplay, DISPLAY_ACK_BIT))
00149     DisplayBit[0] = 'A';
00150   else
00151     DisplayBit[0] = 'a';
00152 
00153   if (IS_BIT_SET(config.DoNotDisplay, DISPLAY_BEACON_BIT))
00154     DisplayBit[1] = 'B';
00155   else
00156     DisplayBit[1] = 'b';
00157 
00158   if (IS_BIT_SET(config.DoNotDisplay, DISPLAY_CONTROL_BIT))
00159     DisplayBit[2] = 'C';
00160   else
00161     DisplayBit[2] = 'c';
00162 
00163   if (IS_BIT_SET(config.DoNotDisplay, DISPLAY_DATA_BIT))
00164     DisplayBit[3] = 'D';
00165   else
00166     DisplayBit[3] = 'd';
00167 
00168   if (IS_BIT_SET(config.DoNotDisplay, DISPLAY_PROBE_BIT))
00169     DisplayBit[4] = 'P';
00170   else
00171     DisplayBit[4] = 'p';
00172 
00173   if (IS_BIT_SET(config.DoNotDisplay, DISPLAY_STATION_BIT))
00174     DisplayBit[5] = 'S';
00175   else
00176     DisplayBit[5] = 's';
00177 
00178   DisplayBit[6] = 0;
00179 
00180   mvwprintw(Sum_WND, 12, 13, "%s", DisplayBit);
00181 
00182   wrefresh(Sum_WND);
00183 #ifdef WITH_THREAD
00184   pthread_mutex_unlock(&screen_mutex);
00185 #endif
00186 }
00187 
00188 
00189 /***
00190  * Function to refresh screen only one time per second
00191  *  This function is threaded, so it do more sleep than work ;-)
00192  ***/
00193 #ifdef WITH_THREAD
00194 void RefreshRealTime_WND_th(void)
00195 {
00196   struct tm *ascii_now;         // The timestamp in ASCII (human readable)
00197   struct timeb binary_now;
00198 
00199   while (!stop_sniffing) {
00200     ftime(&binary_now);
00201     ascii_now = localtime(&binary_now.time);
00202     pthread_mutex_lock(&screen_mutex);
00203     mvwprintw(Panel_WND, ROW_WND_PANEL - 1, 3,
00204               "Last Updt %02d:%02d:%02d ", ascii_now->tm_hour,
00205               ascii_now->tm_min, ascii_now->tm_sec);
00206     wrefresh(RealTime_WND);
00207     pthread_mutex_unlock(&screen_mutex);
00208     // Sleep for less than 1 second, but wake up at HH:MM:SS:000
00209     if (config.DebugLevel >= 2)
00210       usleep((1000 - binary_now.millitm) * 100);
00211     else
00212       usleep((1000 - binary_now.millitm) * 1000);
00213   }
00214   pthread_exit(0);
00215 }
00216 #endif
00217 
00218 /***
00219  * This function is to give compatibility
00220  * and because wben debug is more or egual than 2 we refresh every packets
00221  ***/
00222 void RefreshRealTime_WND(UINT8 GotItOne)
00223 {
00224 #ifdef WITH_THREAD
00225   // Nothing to do here !
00226 /*
00227   if ((config.DebugLevel >= 2) && ()) {
00228     pthread_mutex_lock(&screen_mutex);
00229     wrefresh(RealTime_WND);
00230     pthread_mutex_unlock(&screen_mutex);
00231   }
00232  */
00233 #else
00235   static time_t now, last_time = 0;
00236   struct tm *ascii_now;         // The timestamp in ASCII (human readable)
00237   struct timeb binary_now;
00238   static UINT8 NeedToRefresh = FALSE;
00239 
00240   time(&now);
00241 
00242   if (GotItOne)
00243     NeedToRefresh = TRUE;
00244 
00245   if (((now != last_time) && (NeedToRefresh))
00246       || (config.DebugLevel >= 2)) {
00247     ftime(&binary_now);
00248     last_time = now;
00249     ascii_now = localtime(&binary_now.time);
00250     ascii_now = localtime(&now);
00251     mvwprintw(Panel_WND, ROW_WND_PANEL - 1, 3,
00252               "Last Updt %02d:%02d:%02d ", ascii_now->tm_hour,
00253               ascii_now->tm_min, ascii_now->tm_sec);
00254 
00255     wrefresh(RealTime_WND);
00256     NeedToRefresh = FALSE;
00257   }
00258 #endif
00259 }
00260 
00261 // Function to exit from ncurses environment
00262 void EndCurses(void)
00263 {
00264   CursesIsInUse = FALSE;
00265   endwin();
00266 }

Generated on Fri Jul 25 17:10:34 2008 for WifiScanner by  doxygen 1.5.5