[kismac] [binaervarianz] r134 - in trunk: . Sources/Controller Sources/Core Sources/WaveDrivers

  • From: svn@xxxxxxxxxxxxxxxx
  • To: kismac@xxxxxxxxxxxxx
  • Date: Fri, 21 Apr 2006 10:00:59 +0200

Author: gkruse
Date: 2006-04-21 10:00:57 +0200 (Fri, 21 Apr 2006)
New Revision: 134

Modified:
   trunk/CHANGES
   trunk/Sources/Controller/ScanController.h
   trunk/Sources/Controller/ScanController.m
   trunk/Sources/Core/WaveScanner.h
   trunk/Sources/Core/WaveScanner.mm
   trunk/Sources/WaveDrivers/WaveDriver.h
   trunk/Sources/WaveDrivers/WaveDriver.m
   trunk/Sources/WaveDrivers/WaveDriverUSBIntersil.mm
Log:
R134: - Patch to receive notifications on sleep and to let drivers know we are 
going down in flames



Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES       2006-04-21 01:47:24 UTC (rev 133)
+++ trunk/CHANGES       2006-04-21 08:00:57 UTC (rev 134)
@@ -1,7 +1,9 @@
-R132: - updates changes and authors files (thanks Elio)
-
-R131: - build script checks for existance of Univeral SDK
-
+R134: - Patch to receive notifications on sleep and to let drivers know we are 
going down in flames
+
+R132: - updates changes and authors files (thanks Elio)
+
+R131: - build script checks for existance of Univeral SDK
+
 R130: - Building Universal binaries by default now
        updating changes and authors file (not done yet)
 

Modified: trunk/Sources/Controller/ScanController.h
===================================================================
--- trunk/Sources/Controller/ScanController.h   2006-04-21 01:47:24 UTC (rev 
133)
+++ trunk/Sources/Controller/ScanController.h   2006-04-21 08:00:57 UTC (rev 
134)
@@ -30,6 +30,12 @@
 #import "ScanHierarch.h"
 #import "PrefsController.h"
 #import "GrowlController.h"
+//sleep studd
+#include <mach/mach_port.h>
+#include <mach/mach_interface.h>
+#include <mach/mach_init.h>
+#include <IOKit/pwr_mgt/IOPMLib.h>
+#include <IOKit/IOMessage.h>
 
 typedef enum {
     tabInvalid = -1,
@@ -49,6 +55,8 @@
 @class ColoredRowTableView;
 @class MapView;
 
+io_connect_t  root_port;    // a reference to the Root Power Domain IOService
+
 //This is the main class. it basically provides an interface between the base 
and the gui
 @interface ScanController : NSObject {
     NSString            *_fileName;             //filename for the currently 
open capture
@@ -100,7 +108,7 @@
        
     IBOutlet NSTextField        *_headerField;
     IBOutlet NSSearchField      *_searchField;
-     IBOutlet NSPopUpButton            *_searchTypeMenu;
+    IBOutlet NSPopUpButton             *_searchTypeMenu;
     
     IBOutlet NSButton           *_networksButton;
     IBOutlet NSButton           *_trafficButton;
@@ -197,4 +205,7 @@
 - (IBAction)debugTestWPAHashingFunction:(id)sender;
 - (IBAction)debugExportTrafficView:(id)sender;
 
+void NotifySleep( void * refCon, io_service_t service,
+                      natural_t messageType, void * messageArgument );
+
 @end

Modified: trunk/Sources/Controller/ScanController.m
===================================================================
--- trunk/Sources/Controller/ScanController.m   2006-04-21 01:47:24 UTC (rev 
133)
+++ trunk/Sources/Controller/ScanController.m   2006-04-21 08:00:57 UTC (rev 
134)
@@ -173,6 +173,22 @@
        NSLog(@"Registering with Growl");
     aGrowlController = [[GrowlController alloc] init];
        [aGrowlController registerGrowl];
+    
+    IONotificationPortRef  notifyPortRef;   // notification port allocated by 
IORegisterForSystemPower
+    io_object_t            notifierObject;  // notifier object, used to 
deregister later
+    
+    // register to receive system sleep notifications
+    root_port = IORegisterForSystemPower( scanner, &notifyPortRef, 
NotifySleep, &notifierObject );
+    if ( root_port == nil )
+    {
+        printf("IORegisterForSystemPower failed\n");
+    }
+    
+    // add the notification port to the application runloop
+    CFRunLoopAddSource( CFRunLoopGetCurrent(),
+                        IONotificationPortGetRunLoopSource(notifyPortRef),
+                        kCFRunLoopCommonModes );
+    
 }
 
 #pragma mark -
@@ -609,4 +625,27 @@
                [NSApp terminate:self];
     }
 }
+
+void NotifySleep( void * refCon, io_service_t service,
+                  natural_t messageType, void * messageArgument ){
+
+    switch ( messageType )
+    {
+        
+        case kIOMessageSystemWillSleep:
+            NSLog(@"Going to Sleep, Shutting down dirvers");
+            [(WaveScanner*)refCon sleepDrivers: YES];
+            IOAllowPowerChange( root_port, (long)messageArgument );
+            break;
+        case kIOMessageSystemHasPoweredOn:
+            NSLog(@"System Woken up, Resetting Drivers");
+            [(WaveScanner*)refCon sleepDrivers: NO];
+            break;
+            
+        default:
+            break;
+            
+    }
+}
+
 @end

Modified: trunk/Sources/Core/WaveScanner.h
===================================================================
--- trunk/Sources/Core/WaveScanner.h    2006-04-21 01:47:24 UTC (rev 133)
+++ trunk/Sources/Core/WaveScanner.h    2006-04-21 08:00:57 UTC (rev 134)
@@ -80,6 +80,7 @@
     int  aPacketType;
     bool aScanRange;
     bool _scanning;
+    bool _shouldResumeScan;
     bool _injecting;
     bool _deauthing;
     double aFreq;
@@ -91,8 +92,9 @@
 
     ImportController *_im;
 
-    IBOutlet id aController;
+    IBOutlet ScanController* aController;
     IBOutlet WaveContainer* _container;
+   
 }
 
 - (void)readPCAPDump:(NSString*)dumpFile;
@@ -105,6 +107,7 @@
 - (void) setFrequency:(double)newFreq;
 - (bool) startScanning;
 - (bool) stopScanning;
+- (bool) sleepDrivers: (bool)isSleepy;
 - (void) setGeigerInterval:(int)newGeigerInt sound:(NSString*) newSound;
 - (NSTimeInterval) scanInterval;
 

Modified: trunk/Sources/Core/WaveScanner.mm
===================================================================
--- trunk/Sources/Core/WaveScanner.mm   2006-04-21 01:47:24 UTC (rev 133)
+++ trunk/Sources/Core/WaveScanner.mm   2006-04-21 08:00:57 UTC (rev 134)
@@ -304,6 +304,35 @@
     return YES;
 }
 
+- (bool)sleepDrivers: (bool)isSleepy{
+    WaveDriver *w;
+    NSArray *a;
+    unsigned int i;
+    
+    a = [WaveHelper getWaveDrivers];
+    [WaveHelper secureReplace:&_drivers withObject:a];
+        
+    for (i = 0; i < [_drivers count]; i++) {
+        w = [_drivers objectAtIndex:i];
+        if (isSleepy) {
+            [w sleepDriver];
+        }
+        else {
+            [w wakeDriver];
+        }
+    }
+    if (isSleepy) {
+        _shouldResumeScan = _scanning;
+        [aController stopScan];
+    }else {
+        if (_shouldResumeScan) {
+            [aController startScan];
+        }
+    }
+
+    return YES;
+}
+
 - (void)doChannelHop:(NSTimer*)timer {
     unsigned int i;
     

Modified: trunk/Sources/WaveDrivers/WaveDriver.h
===================================================================
--- trunk/Sources/WaveDrivers/WaveDriver.h      2006-04-21 01:47:24 UTC (rev 
133)
+++ trunk/Sources/WaveDrivers/WaveDriver.h      2006-04-21 08:00:57 UTC (rev 
134)
@@ -82,6 +82,8 @@
 - (bool) setChannel:  (unsigned short)newChannel;
 - (bool) startCapture:(unsigned short)newChannel;
 - (bool) stopCapture;
+- (bool) sleepDriver;
+- (bool) wakeDriver;
 
 // for active scanning
 - (NSArray*) networksInRange;

Modified: trunk/Sources/WaveDrivers/WaveDriver.m
===================================================================
--- trunk/Sources/WaveDrivers/WaveDriver.m      2006-04-21 01:47:24 UTC (rev 
133)
+++ trunk/Sources/WaveDrivers/WaveDriver.m      2006-04-21 08:00:57 UTC (rev 
134)
@@ -202,6 +202,14 @@
     return YES;
 }
 
+- (bool) sleepDriver{
+    return YES;
+}
+
+- (bool) wakeDriver{
+    return YES;
+}
+
 - (void)hopToNextChannel {
     int channel = _currentChannel+1, i;
    

Modified: trunk/Sources/WaveDrivers/WaveDriverUSBIntersil.mm
===================================================================
--- trunk/Sources/WaveDrivers/WaveDriverUSBIntersil.mm  2006-04-21 01:47:24 UTC 
(rev 133)
+++ trunk/Sources/WaveDrivers/WaveDriverUSBIntersil.mm  2006-04-21 08:00:57 UTC 
(rev 134)
@@ -121,6 +121,17 @@
     return _driver->stopCapture();
 }
 
+- (bool) sleepDriver{
+    delete _driver; 
+    return YES;
+}
+
+- (bool) wakeDriver{
+    _driver = new USBIntersilJack;
+    _driver->startMatching();
+    return YES;
+}
+
 #pragma mark -
 
 - (WLFrame*) nextFrame {


Other related posts:

  • » [kismac] [binaervarianz] r134 - in trunk: . Sources/Controller Sources/Core Sources/WaveDrivers