[kismac] [binaervarianz] r187 - in branches/usb-drivers/Sources: Core Driver/USBJack WaveDrivers

  • From: svn@xxxxxxxxxxxxxxxx
  • To: kismac@xxxxxxxxxxxxx
  • Date: Fri, 08 Sep 2006 06:09:01 +0200

Author: gkruse
Date: 2006-09-08 06:08:53 +0200 (Fri, 08 Sep 2006)
New Revision: 187

Modified:
   branches/usb-drivers/Sources/Core/WaveHelper.m
   branches/usb-drivers/Sources/Driver/USBJack/RalinkJack.h
   branches/usb-drivers/Sources/Driver/USBJack/RalinkJack.mm
   branches/usb-drivers/Sources/Driver/USBJack/USBJack.h
   branches/usb-drivers/Sources/Driver/USBJack/USBJack.mm
   branches/usb-drivers/Sources/Driver/USBJack/rt2570.h
   branches/usb-drivers/Sources/WaveDrivers/WaveDriverUSBIntersil.mm
Log:
some build fixes, people should be able to build with the compile.command now.  
Also, it should be possible to use multiple usb devices at the same time, but I 
wouldn't reccomend it.  Other random stuff

Modified: branches/usb-drivers/Sources/Core/WaveHelper.m
===================================================================
--- branches/usb-drivers/Sources/Core/WaveHelper.m      2006-09-08 03:33:13 UTC 
(rev 186)
+++ branches/usb-drivers/Sources/Core/WaveHelper.m      2006-09-08 04:08:53 UTC 
(rev 187)
@@ -280,7 +280,7 @@
         name = [driverProps objectForKey:@"deviceName"];
         
         //the driver does not exist. go for it
-        if (![_waveDrivers objectForKey:name]) {
+   //     if (![_waveDrivers objectForKey:name]) {
         
             //ugly hack but it works, this makes sure that the airport card is 
used only once
             //prefers the viha driver
@@ -325,9 +325,11 @@
                 NSLog(@"Error could not instanciate driver %@", interfaceName);
                 return NO;
             }
-        }
+        //} 
+            NSLog(@"Driver %@ was created.", interfaceName);
     }
 
+   
     return YES;
 }
 

Modified: branches/usb-drivers/Sources/Driver/USBJack/RalinkJack.h
===================================================================
--- branches/usb-drivers/Sources/Driver/USBJack/RalinkJack.h    2006-09-08 
03:33:13 UTC (rev 186)
+++ branches/usb-drivers/Sources/Driver/USBJack/RalinkJack.h    2006-09-08 
04:08:53 UTC (rev 187)
@@ -11,8 +11,28 @@
 
 #import <Cocoa/Cocoa.h>
 #import "USBJack.h"
-#include "rt2570.h"
 
+//this stuff goes here for now because something is funkey with the include 
order
+#define        NUM_EEPROM_BBP_PARMS            19
+#define        NUM_EEPROM_BBP_TUNING_PARMS     7
+#define UCHAR unsigned char
+
+typedef struct _BBP_TUNING_PARAMETERS_STRUC
+{
+       UCHAR                   BBPTuningThreshold;
+       UCHAR                   R24LowerValue;
+       UCHAR                   R24HigherValue;
+       UCHAR                   R25LowerValue;
+       UCHAR                   R25HigherValue;
+       UCHAR                   R61LowerValue;
+       UCHAR                   R61HigherValue;
+       UCHAR                   BBPR17LowSensitivity;
+       UCHAR                   BBPR17MidSensitivity;
+       UCHAR                   RSSIToDbmOffset;
+       bool                    LargeCurrentRSSI;
+}
+BBP_TUNING_PARAMETERS_STRUC, *PBBP_TUNING_PARAMETERS_STRUC;
+
 class RalinkJack: public USBJack
 {
 public:
@@ -64,11 +84,10 @@
     bool _massagePacket(int len);
     
 private:
-        int temp;
-        unsigned short EEPROMDefaultValue[NUM_EEPROM_BBP_PARMS];
-        unsigned short EEPROMBBPTuningParameters[NUM_EEPROM_BBP_TUNING_PARMS];
-        BBP_TUNING_PARAMETERS_STRUC                    BBPTuningParameters;
-        unsigned char RfType;
-
+    int temp;
+    unsigned short EEPROMDefaultValue[NUM_EEPROM_BBP_PARMS];
+    unsigned short EEPROMBBPTuningParameters[NUM_EEPROM_BBP_TUNING_PARMS];
+    BBP_TUNING_PARAMETERS_STRUC                        BBPTuningParameters;
+    unsigned char RfType;
 };
 #endif

Modified: branches/usb-drivers/Sources/Driver/USBJack/RalinkJack.mm
===================================================================
--- branches/usb-drivers/Sources/Driver/USBJack/RalinkJack.mm   2006-09-08 
03:33:13 UTC (rev 186)
+++ branches/usb-drivers/Sources/Driver/USBJack/RalinkJack.mm   2006-09-08 
04:08:53 UTC (rev 187)
@@ -8,8 +8,8 @@
  */
 
 #include "RalinkJack.h"
+#include "rt2570.h"
 
-
 IOReturn RalinkJack::_init() {
     unsigned long                      Index;
 //     unsigned char                   buffer[22];
@@ -19,7 +19,7 @@
     IOReturn                ret;
     
        NSLog(@"--> NICInitializeAsic");
-    
+
        do
        {
                //NdisMSleep(1000);
@@ -83,7 +83,7 @@
             NSLog(@"LNA 3 mode\n");
             RTUSBWriteMACRegister(PHY_CSR2, 0x3002); // LNA 3 mode
         }
-        //power save stuff
+/*        //power save stuff
         RTUSBWriteMACRegister(MAC_CSR11, 2);
         RTUSBWriteMACRegister(MAC_CSR22, 0x53);
         RTUSBWriteMACRegister(MAC_CSR15, 0x01ee);
@@ -102,7 +102,7 @@
         RTUSBReadMACRegister(PHY_CSR4, &temp);
         RTUSBWriteMACRegister(PHY_CSR4, temp | 1);
         //NdisMSleep(100);//wait for PLL to become stable
-                    
+  */                  
         i = 0;
         do
         {
@@ -684,9 +684,10 @@
        //      PortCfg.VgcLowerBound   = r17;
         
                // 2004-3-4 per David's request, R7 starts at upper bound
-               //r17 = PortCfg.BbpTuning.VgcUpperBound;
-       //      PortCfg.LastR17Value = r17;
-       //      RTUSBWriteBBPRegister(17, r17);
+        NSLog(@"It is this %d,", r17);
+               r17 = 128;
+           NSLog(@"It is this %d,", r17);
+               RTUSBWriteBBPRegister(17, r17);
         
                // 2004-2-2 per David's request, lower R17 low-bound for very 
good quality NIC
        //      PortCfg.VgcLowerBound -= 6;  
@@ -851,11 +852,13 @@
 
 bool RalinkJack::startCapture(UInt16 channel) {
     setChannel(channel);
+    RTUSBWriteMACRegister(MAC_CSR20, 0x0002); //turn on led
     RTUSBWriteMACRegister(TXRX_CSR2, 0x004e); //enable monitor mode?
     return true;   
 }
 
 bool RalinkJack::stopCapture(){
+    RTUSBWriteMACRegister(MAC_CSR20, 0x0000); //turn off led
     RTUSBWriteMACRegister(TXRX_CSR2, 0x00ff); //disable rx
     return true;
 }
@@ -870,7 +873,7 @@
     tempFrame = (WLFrame *)frame;
     
     //flash the led for fun
-    RTUSBWriteMACRegister(MAC_CSR20, 0x0004);        //put led under software 
control
+    RTUSBWriteMACRegister(MAC_CSR20, 0x0007);        //put led under software 
control
 
     pData = (unsigned char*)&_recieveBuffer;
 
@@ -903,7 +906,7 @@
         }
 
         memcpy(&_recieveBuffer, frame, sizeof(_recieveBuffer));
-        RTUSBWriteMACRegister(MAC_CSR20, 0x0002);        //put led under 
software control
+        RTUSBWriteMACRegister(MAC_CSR20, 0x0002);  
         return true;         //override if needed
    // }
    // return false;

Modified: branches/usb-drivers/Sources/Driver/USBJack/USBJack.h
===================================================================
--- branches/usb-drivers/Sources/Driver/USBJack/USBJack.h       2006-09-08 
03:33:13 UTC (rev 186)
+++ branches/usb-drivers/Sources/Driver/USBJack/USBJack.h       2006-09-08 
04:08:53 UTC (rev 187)
@@ -115,6 +115,7 @@
     io_iterator_t              _deviceAddedIter;
     io_iterator_t              _deviceRemovedIter;
     IOUSBInterfaceInterface**   _interface;
+    IOUSBDeviceInterface**      _dev;           //save this so we can't use 
the same device twice!
     union _usbout               _outputBuffer;
     union _usbin                _inputBuffer;
     union _usbin                _recieveBuffer;

Modified: branches/usb-drivers/Sources/Driver/USBJack/USBJack.mm
===================================================================
--- branches/usb-drivers/Sources/Driver/USBJack/USBJack.mm      2006-09-08 
03:33:13 UTC (rev 186)
+++ branches/usb-drivers/Sources/Driver/USBJack/USBJack.mm      2006-09-08 
04:08:53 UTC (rev 187)
@@ -756,7 +756,7 @@
     kern_return_t              kr;
     io_service_t               usbDevice;
     IOCFPlugInInterface        **plugInInterface=NULL;
-    IOUSBDeviceInterface       **dev=NULL;
+    IOUSBDeviceInterface    **dev=NULL;
     HRESULT                    res;
     SInt32                     score;
     UInt16                     vendor;
@@ -798,11 +798,11 @@
             me = (IntersilJack*)refCon;
             me->deviceType = intersil;
         }
-     /*   else if (i < dIntersilDeviceCount + dZydasDeviceCount) {
+        else if (i < dIntersilDeviceCount + dZydasDeviceCount) {
             NSLog(@"Zydas USB Device found (vendor = 0x%x, product = 0x%x)\n", 
vendor, product);
+            me = (USBJack*)refCon;
             me->deviceType = zydas;
-            me = (ZydasJack*) me;
-        }*/
+        }
         else if (i < dIntersilDeviceCount + dZydasDeviceCount + 
dRalinkDeviceCount) {
             NSLog(@"Ralink 2500 USB Device found (vendor = 0x%x, product = 
0x%x)\n", vendor, product);
             me = (RalinkJack*)refCon;
@@ -817,7 +817,12 @@
         // need to open the device in order to change its state
         kr = (*dev)->USBDeviceOpen(dev);
         if (kIOReturnSuccess != kr) {
-            NSLog(@"unable to open device: %08x\n", kr);
+            if (kr == kIOReturnExclusiveAccess) {
+                NSLog(@"Device already in use.");
+            }
+            else {
+                NSLog(@"unable to open device: %08x\n", kr);
+            }
             (*dev)->Release(dev);
             continue;
         }
@@ -837,10 +842,13 @@
             (*dev)->Release(dev);
             continue;
         }
+
+   //I think we need to hold onto the device to maintain exclusive access
+   //     kr = (*dev)->USBDeviceClose(dev);
+   //     kr = (*dev)->Release(dev);
+   //we will release it in the destructor
+        me->_dev = dev;
         
-        kr = (*dev)->USBDeviceClose(dev);
-        kr = (*dev)->Release(dev);
-        
         break;
     }
 }
@@ -852,7 +860,8 @@
     USBJack     *me = (USBJack*)refCon;
     
     while ((obj = IOIteratorNext(iterator)) != nil) {
-        count++;
+        //count++;
+        //we need to not release devices that don't belong to us!?
         //NSLog(@"Device removed.\n");
         kr = IOObjectRelease(obj);
     }
@@ -1003,7 +1012,10 @@
 }
 
 USBJack::~USBJack() {
+    NSLog(@"I'm being destroyed!!!");
     stopRun();
+    (*_dev)->USBDeviceClose(_dev);
+    (*_dev)->Release(_dev);
     _interface = NULL;
     _frameSize = 0;
 
@@ -1011,4 +1023,5 @@
     pthread_cond_destroy(&_wait_cond);
     pthread_mutex_destroy(&_recv_mutex);
     pthread_cond_destroy(&_recv_cond);
+    
 }
\ No newline at end of file

Modified: branches/usb-drivers/Sources/Driver/USBJack/rt2570.h
===================================================================
--- branches/usb-drivers/Sources/Driver/USBJack/rt2570.h        2006-09-08 
03:33:13 UTC (rev 186)
+++ branches/usb-drivers/Sources/Driver/USBJack/rt2570.h        2006-09-08 
04:08:53 UTC (rev 187)
@@ -291,7 +291,7 @@
        USHORT                  Frag:4;                         // Fragment 
number
        USHORT                  Sequence:12;            // Sequence number
 }      HEADER_802_11, *PHEADER_802_11;
-
+/*
 typedef struct _BBP_TUNING_PARAMETERS_STRUC
 {
        UCHAR                   BBPTuningThreshold;
@@ -307,8 +307,8 @@
        bool                    LargeCurrentRSSI;
 }
 BBP_TUNING_PARAMETERS_STRUC, *PBBP_TUNING_PARAMETERS_STRUC;
+*/
 
-
 //
 // Control/Status Registers    (CSR)
 //

Modified: branches/usb-drivers/Sources/WaveDrivers/WaveDriverUSBIntersil.mm
===================================================================
--- branches/usb-drivers/Sources/WaveDrivers/WaveDriverUSBIntersil.mm   
2006-09-08 03:33:13 UTC (rev 186)
+++ branches/usb-drivers/Sources/WaveDrivers/WaveDriverUSBIntersil.mm   
2006-09-08 04:08:53 UTC (rev 187)
@@ -33,29 +33,35 @@
 @implementation WaveDriverUSBIntersil
 
 - (id)init {
+    int timeoutCount = 0;
     self=[super init];
     if(!self) return Nil;
 
     _driver = new RalinkJack;
+    //make start matching a class function so we can call it before we try to 
make an instance
     _driver->startMatching();
     
-    while(!_driver->getDeviceType())        //wait until the device is found
+    while(!_driver->getDeviceType() && timeoutCount++ < 10)        //wait 
until the device is found
         usleep(100);
     
+    usleep(1000);  //we should really do locking, but since this is temp 
anyway...
+    
     switch(_driver->getDeviceType()){       //cast ourself to the approp type
         case intersil:
+            delete(_driver);
             _driver = new IntersilJack;
             _driver->startMatching();
             break;
         case ralink:
-       //     _driver = new RalinkJack;
-       //     _driver->startMatching();
+          //  delete(_driver);
+           // _driver = new RalinkJack;
+           // _driver->startMatching();
             break;
-  /*      case zydas:
-            _driver = (ZydasJack*)_driver;
-            break;*/
+        case zydas:
+            break;
         default:
             NSLog(@"The impossible happened!");
+            return Nil;
     }
     
     _driver->_init();
@@ -79,15 +85,15 @@
 }
 
 + (bool) allowsMultipleInstances {
-    return NO;  //may be later
+    return YES;  //may be later
 }
 
 + (NSString*) description {
-    return NSLocalizedString(@"USB device with Prism2 chipset, passive mode", 
"long driver description");
+    return NSLocalizedString(@"USB device, passive mode", "long driver 
description");
 }
 
 + (NSString*) deviceName {
-    return NSLocalizedString(@"Prism2 USB device", "short driver description");
+    return NSLocalizedString(@"USB device", "short driver description");
 }
 
 #pragma mark -


Other related posts:

  • » [kismac] [binaervarianz] r187 - in branches/usb-drivers/Sources: Core Driver/USBJack WaveDrivers