00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef ONETWORK_H
00031 #define ONETWORK_H
00032
00033
00034 #include <opie2/onetutils.h>
00035 #include <opie2/ostation.h>
00036
00037
00038 #include <qvaluelist.h>
00039 #include <qdict.h>
00040 #include <qmap.h>
00041 #include <qobject.h>
00042 #include <qhostaddress.h>
00043
00044
00045
00046 #include <net/if.h>
00047 #define _LINUX_IF_H
00048 #include <linux/wireless.h>
00049 #ifndef IW_MAX_PRIV_DEF
00050 #define IW_MAX_PRIV_DEF 128
00051 #endif
00052
00053 namespace Opie {
00054 namespace Net {
00055 class ONetworkInterface;
00056 class OWirelessNetworkInterface;
00057 class OChannelHopper;
00058 class OMonitoringInterface;
00059
00060
00061
00062
00063
00071 class ONetwork : public QObject
00072 {
00073 Q_OBJECT
00074
00075 public:
00076 typedef QDict<ONetworkInterface> InterfaceMap;
00077 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
00078
00079 public:
00083 int count() const;
00087 static ONetwork* instance();
00091 InterfaceIterator iterator() const;
00095 bool isPresent( const char* interface ) const;
00099 bool isWirelessInterface( const char* interface ) const;
00104 ONetworkInterface* interface( const QString& interface ) const;
00110 void synchronize();
00114 static short wirelessExtensionCompileVersion();
00115
00116 protected:
00117 ONetwork();
00118
00119 private:
00120 static ONetwork* _instance;
00121 InterfaceMap _interfaces;
00122 class Private;
00123 Private *d;
00124 };
00125
00126
00127
00128
00129
00130
00141 class ONetworkInterface : public QObject
00142 {
00143 friend class OMonitoringInterface;
00144 friend class OCiscoMonitoringInterface;
00145 friend class OWlanNGMonitoringInterface;
00146 friend class OHostAPMonitoringInterface;
00147 friend class OOrinocoMonitoringInterface;
00148
00149 public:
00154 ONetworkInterface( QObject* parent, const char* name );
00158 virtual ~ONetworkInterface();
00163 void setMonitoring( OMonitoringInterface* monitoring );
00167 OMonitoringInterface* monitoring() const;
00172 bool setPromiscuousMode( bool );
00176 bool promiscuousMode() const;
00180 bool setUp( bool );
00184 bool isUp() const;
00188 bool isLoopback() const;
00192 bool isWireless() const;
00196 void setIPV4Address( const QHostAddress& addr );
00200 OHostAddress ipV4Address() const;
00207 void setMacAddress( const OMacAddress& addr );
00211 OMacAddress macAddress() const;
00215 void setIPV4Netmask( const QHostAddress& netmask );
00219 OHostAddress ipV4Netmask() const;
00224 int dataLinkType() const;
00230 ONetworkInterfaceDriverInfo driverInfo() const;
00231
00232 protected:
00233 const int _sfd;
00234 mutable ifreq _ifr;
00235 OMonitoringInterface* _mon;
00236
00237 protected:
00238 struct ifreq& ifr() const;
00239 virtual void init();
00240 bool ioctl( int call ) const;
00241 bool ioctl( int call, struct ifreq& ) const;
00242 private:
00243 class Private;
00244 Private *d;
00245 };
00246
00247
00248
00249
00250
00261 class OChannelHopper : public QObject
00262 {
00263 Q_OBJECT
00264
00265 public:
00269 OChannelHopper( OWirelessNetworkInterface* );
00273 virtual ~OChannelHopper();
00277 bool isActive() const;
00281 int channel() const;
00286 void setInterval( int interval );
00290 int interval() const;
00291
00292 signals:
00296 void hopped( int );
00297
00298 protected:
00299 virtual void timerEvent( QTimerEvent* );
00300
00301 private:
00302 OWirelessNetworkInterface* _iface;
00303 int _interval;
00304 int _tid;
00305 QValueList<int> _channels;
00306 QValueList<int>::Iterator _channel;
00307 class Private;
00308 Private *d;
00309 };
00310
00311
00312
00313
00314
00315
00323 class OWirelessNetworkInterface : public ONetworkInterface
00324 {
00325 friend class OMonitoringInterface;
00326 friend class OCiscoMonitoringInterface;
00327 friend class OWlanNGMonitoringInterface;
00328 friend class OHostAPMonitoringInterface;
00329 friend class OOrinocoMonitoringInterface;
00330
00331 friend class OPrivateIOCTL;
00332
00333 public:
00337 OWirelessNetworkInterface( QObject* parent, const char* name );
00341 virtual ~OWirelessNetworkInterface();
00348 virtual void setChannel( int channel ) const;
00352 virtual int channel() const;
00356 virtual double frequency() const;
00362 virtual int channels() const;
00369 virtual void setMode( const QString& mode );
00385 virtual QString mode() const;
00390 virtual void setChannelHopping( int interval = 0 );
00394 virtual int channelHopping() const;
00398 virtual OChannelHopper* channelHopper() const;
00402 virtual void setNickName( const QString& nickname );
00406 virtual QString nickName() const;
00411 virtual void setPrivate( const QString& command, int number, ... );
00415 virtual bool hasPrivate( const QString& command );
00416 virtual void getPrivate( const QString& command );
00421 virtual bool isAssociated() const;
00424 virtual void setAssociatedAP( const OMacAddress& mac ) const;
00429 virtual OMacAddress associatedAP() const;
00434 virtual void setSSID( const QString& ssid );
00438 virtual QString SSID() const;
00443 virtual OStationList* scanNetwork();
00449 virtual int signalStrength() const;
00453 short wirelessExtensionDriverVersion() const;
00457 void commit() const;
00458
00459 protected:
00460 void buildInformation();
00461 void buildPrivateList();
00462 void dumpInformation() const;
00463 virtual void init();
00464 struct iwreq& iwr() const;
00465 bool wioctl( int call ) const;
00466 bool wioctl( int call, struct iwreq& ) const;
00467
00468 protected:
00469 mutable struct iwreq _iwr;
00470 QMap<int,int> _channels;
00471 struct iw_range _range;
00472
00473 private:
00474 OChannelHopper* _hopper;
00475 class Private;
00476 Private *d;
00477 };
00478
00479
00480
00481
00482
00483
00484
00485 class OMonitoringInterface
00486 {
00487 public:
00488 OMonitoringInterface();
00489 OMonitoringInterface( ONetworkInterface*, bool _prismHeader );
00490 virtual ~OMonitoringInterface();
00491
00492 public:
00493 virtual void setEnabled( bool );
00494 virtual void setChannel( int );
00495
00496 virtual QString name() const = 0;
00497
00498 protected:
00499 OWirelessNetworkInterface* _if;
00500 bool _prismHeader;
00501 private:
00502 class Private;
00503 Private *d;
00504
00505 };
00506
00507
00508
00509
00510
00511
00512
00513 class OCiscoMonitoringInterface : public OMonitoringInterface
00514 {
00515 public:
00516 OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader );
00517 virtual ~OCiscoMonitoringInterface();
00518
00519 virtual void setEnabled( bool );
00520 virtual QString name() const;
00521 virtual void setChannel( int );
00522 private:
00523 class Private;
00524 Private *d;
00525
00526 };
00527
00528
00529
00530
00531
00532
00533
00534 class OWlanNGMonitoringInterface : public OMonitoringInterface
00535 {
00536 public:
00537 OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader );
00538 virtual ~OWlanNGMonitoringInterface();
00539
00540 public:
00541 virtual void setEnabled( bool );
00542 virtual QString name() const;
00543 virtual void setChannel( int );
00544 private:
00545 class Private;
00546 Private *d;
00547
00548 };
00549
00550
00551
00552
00553
00554
00555
00556 class OHostAPMonitoringInterface : public OMonitoringInterface
00557 {
00558 public:
00559 OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader );
00560 virtual ~OHostAPMonitoringInterface();
00561
00562 public:
00563 virtual void setEnabled( bool );
00564 virtual QString name() const;
00565
00566 private:
00567 class Private;
00568 Private *d;
00569 };
00570
00571
00572
00573
00574
00575
00576
00577 class OOrinocoMonitoringInterface : public OMonitoringInterface
00578 {
00579 public:
00580 OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader );
00581 virtual ~OOrinocoMonitoringInterface();
00582
00583 public:
00584 virtual void setChannel( int );
00585 virtual void setEnabled( bool );
00586 virtual QString name() const;
00587
00588 private:
00589 class Private;
00590 Private *d;
00591 };
00592
00593 }
00594 }
00595
00596 #endif // ONETWORK_H
00597