summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp18
-rw-r--r--libopie2/opienet/onetutils.cpp28
-rw-r--r--libopie2/opienet/onetutils.h3
-rw-r--r--libopie2/opienet/onetwork.cpp50
-rw-r--r--libopie2/opienet/onetwork.h8
5 files changed, 73 insertions, 34 deletions
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
index b010ac5..020fc23 100644
--- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
+++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -19,25 +19,43 @@ int main( int argc, char** argv )
19 qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() ); 19 qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() );
20 qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() ); 20 qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() );
21 qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() ); 21 qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() );
22 qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() ); 22 qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() );
23 23
24 //if ( iface->mode() == OWirelessNetworkInterface::adhoc ) 24 //if ( iface->mode() == OWirelessNetworkInterface::adhoc )
25 //{ 25 //{
26 qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP() ); 26 qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP() );
27 //} 27 //}
28 28
29 // try to set monitor mode 29 // try to set monitor mode
30 30
31 /*
32
31 // first some wrong calls to check if this is working 33 // first some wrong calls to check if this is working
32 iface->setPrivate( "seppel", 10 ); 34 iface->setPrivate( "seppel", 10 );
33 iface->setPrivate( "monitor", 0 ); 35 iface->setPrivate( "monitor", 0 );
34 36
35 // now the real deal 37 // now the real deal
36 iface->setPrivate( "monitor", 2, 2, 3 ); 38 iface->setPrivate( "monitor", 2, 2, 3 );
39
40 */
41
42 // trying to set hw address to 12:34:56:AB:CD:EF
43
44 /*
45
46 OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" );
47 iface->setUp( false );
48 iface->setMacAddress( addr );
49 iface->setUp( true );
50 qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() );
51
52 */
53
54
37 } 55 }
38 ++it; 56 ++it;
39 } 57 }
40 58
41 return 0; 59 return 0;
42 60
43} 61}
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp
index b317810..0fb21ff 100644
--- a/libopie2/opienet/onetutils.cpp
+++ b/libopie2/opienet/onetutils.cpp
@@ -53,45 +53,71 @@ using namespace std;
53 53
54// static initializer for broadcast and unknown MAC Adresses 54// static initializer for broadcast and unknown MAC Adresses
55const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 55const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
56const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); 56const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast );
57const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; 57const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 };
58const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); 58const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown );
59 59
60 60
61//TODO: Incorporate Ethernet Manufacturer database here! 61//TODO: Incorporate Ethernet Manufacturer database here!
62 62
63OMacAddress::OMacAddress( unsigned char* p ) 63OMacAddress::OMacAddress( unsigned char* p )
64{ 64{
65 memcpy( _bytes, p, 6 ); // D'OH! memcpy in my sources... eeek... 65 memcpy( _bytes, p, 6 );
66} 66}
67 67
68 68
69OMacAddress::OMacAddress( const unsigned char* p ) 69OMacAddress::OMacAddress( const unsigned char* p )
70{ 70{
71 memcpy( _bytes, p, 6 ); 71 memcpy( _bytes, p, 6 );
72} 72}
73 73
74 74
75OMacAddress::OMacAddress( struct ifreq& ifr ) 75OMacAddress::OMacAddress( struct ifreq& ifr )
76{ 76{
77 memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); 77 memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 );
78} 78}
79 79
80 80
81OMacAddress::~OMacAddress() 81OMacAddress::~OMacAddress()
82{ 82{
83} 83}
84 84
85 85
86#ifdef QT_NO_DEBUG
87inline
88#endif
89const unsigned char* OMacAddress::native() const
90{
91 return (const unsigned char*) &_bytes;
92}
93
94
95OMacAddress OMacAddress::fromString( const QString& str )
96{
97 QString addr( str );
98 unsigned char buf[6];
99 bool ok = true;
100 int index = 14;
101 for ( int i = 5; i >= 0; --i )
102 {
103 buf[i] = addr.right( 2 ).toUShort( &ok, 16 );
104 if ( !ok ) return OMacAddress::unknown;
105 addr.truncate( index );
106 index -= 3;
107 }
108 return (const unsigned char*) &buf;
109}
110
111
86QString OMacAddress::toString() const 112QString OMacAddress::toString() const
87{ 113{
88 QString s; 114 QString s;
89 s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 115 s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
90 _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff, 116 _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff,
91 _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); 117 _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff );
92 return s; 118 return s;
93} 119}
94 120
95 121
96bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) 122bool operator==( const OMacAddress &m1, const OMacAddress &m2 )
97{ 123{
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h
index 8be042b..73d52cc 100644
--- a/libopie2/opienet/onetutils.h
+++ b/libopie2/opienet/onetutils.h
@@ -47,24 +47,27 @@ class OWirelessNetworkInterface;
47 * OMacAddress 47 * OMacAddress
48 *======================================================================================*/ 48 *======================================================================================*/
49 49
50class OMacAddress 50class OMacAddress
51{ 51{
52 public: 52 public:
53 OMacAddress( unsigned char* ); 53 OMacAddress( unsigned char* );
54 OMacAddress( const unsigned char* ); 54 OMacAddress( const unsigned char* );
55 OMacAddress( struct ifreq& ); 55 OMacAddress( struct ifreq& );
56 ~OMacAddress(); 56 ~OMacAddress();
57 57
58 QString toString() const; 58 QString toString() const;
59 const unsigned char* native() const;
60
61 static OMacAddress fromString( const QString& );
59 62
60 public: 63 public:
61 static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff 64 static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff
62 static const OMacAddress& unknown; // 44:44:44:44:44:44 65 static const OMacAddress& unknown; // 44:44:44:44:44:44
63 66
64 private: 67 private:
65 unsigned char _bytes[6]; 68 unsigned char _bytes[6];
66 69
67 friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); 70 friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
68 71
69}; 72};
70 73
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index f52279a..e916c44 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -215,24 +215,32 @@ QString ONetworkInterface::ipV4Address() const
215{ 215{
216 if ( ioctl( SIOCGIFADDR ) ) 216 if ( ioctl( SIOCGIFADDR ) )
217 { 217 {
218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
219 //FIXME: Use QHostAddress here 219 //FIXME: Use QHostAddress here
220 return QString( inet_ntoa( sa->sin_addr ) ); 220 return QString( inet_ntoa( sa->sin_addr ) );
221 } 221 }
222 else 222 else
223 return "<unknown>"; 223 return "<unknown>";
224} 224}
225 225
226 226
227void ONetworkInterface::setMacAddress( const OMacAddress& addr )
228{
229 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
230 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 );
231 ioctl( SIOCSIFHWADDR );
232}
233
234
227OMacAddress ONetworkInterface::macAddress() const 235OMacAddress ONetworkInterface::macAddress() const
228{ 236{
229 if ( ioctl( SIOCGIFHWADDR ) ) 237 if ( ioctl( SIOCGIFHWADDR ) )
230 { 238 {
231 return OMacAddress( _ifr ); 239 return OMacAddress( _ifr );
232 } 240 }
233 else 241 else
234 { 242 {
235 return OMacAddress::unknown; 243 return OMacAddress::unknown;
236 } 244 }
237} 245}
238 246
@@ -638,24 +646,31 @@ void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ..
638 va_start( argp, numargs ); 646 va_start( argp, numargs );
639 for ( int i = 0; i < numargs; ++i ) 647 for ( int i = 0; i < numargs; ++i )
640 { 648 {
641 priv->setParameter( i, va_arg( argp, int ) ); 649 priv->setParameter( i, va_arg( argp, int ) );
642 } 650 }
643 va_end( argp ); 651 va_end( argp );
644 priv->invoke(); 652 priv->invoke();
645} 653}
646 654
647 655
648void OWirelessNetworkInterface::getPrivate( const QString& call ) 656void OWirelessNetworkInterface::getPrivate( const QString& call )
649{ 657{
658 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." );
659}
660
661
662bool OWirelessNetworkInterface::hasPrivate( const QString& call )
663{
664 return child( (const char*) call );
650} 665}
651 666
652 667
653QString OWirelessNetworkInterface::SSID() const 668QString OWirelessNetworkInterface::SSID() const
654{ 669{
655 char str[IW_ESSID_MAX_SIZE]; 670 char str[IW_ESSID_MAX_SIZE];
656 _iwr.u.essid.pointer = &str[0]; 671 _iwr.u.essid.pointer = &str[0];
657 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 672 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
658 if ( !wioctl( SIOCGIWESSID ) ) 673 if ( !wioctl( SIOCGIWESSID ) )
659 { 674 {
660 return "<unknown>"; 675 return "<unknown>";
661 } 676 }
@@ -825,47 +840,34 @@ OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface
825 iface->setMonitoring( this ); 840 iface->setMonitoring( this );
826} 841}
827 842
828OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 843OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
829{ 844{
830} 845}
831 846
832void OHostAPMonitoringInterface::setEnabled( bool b ) 847void OHostAPMonitoringInterface::setEnabled( bool b )
833{ 848{
834 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 849 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
835 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 850 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
836 851
852 //TODO: check wireless extensions version on runtime and use
853 //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15
854
837 if ( b ) 855 if ( b )
838 { 856 {
839 #if WIRELESS_EXT > 14 857 _if->setPrivate( "monitor", 1, 2 );
840 _if->_iwr.u.mode = IW_MODE_MONITOR;
841 _if->wioctl( SIOCSIWMODE );
842 #else
843 int* args = (int*) &_if->_iwr.u.name;
844 args[0] = 2;
845 args[1] = 0;
846 _if->wioctl( SIOCDEVPRIVATE );
847 #endif
848 } 858 }
849 else 859 else
850 { 860 {
851 #if WIRELESS_EXT > 14 861 _if->setPrivate( "monitor", 1, 0 );
852 _if->_iwr.u.mode = IW_MODE_INFRA;
853 _if->wioctl( SIOCSIWMODE );
854 #else
855 int* args = (int*) &_if->_iwr.u.name;
856 args[0] = 0;
857 args[1] = 0;
858 _if->wioctl( SIOCDEVPRIVATE );
859 #endif
860 } 862 }
861} 863}
862 864
863 865
864QString OHostAPMonitoringInterface::name() const 866QString OHostAPMonitoringInterface::name() const
865{ 867{
866 return "hostap"; 868 return "hostap";
867} 869}
868 870
869 871
870/*====================================================================================== 872/*======================================================================================
871 * OOrinocoNetworkInterface 873 * OOrinocoNetworkInterface
@@ -876,41 +878,33 @@ OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* ifa
876{ 878{
877 iface->setMonitoring( this ); 879 iface->setMonitoring( this );
878} 880}
879 881
880 882
881OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 883OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
882{ 884{
883} 885}
884 886
885 887
886void OOrinocoMonitoringInterface::setChannel( int c ) 888void OOrinocoMonitoringInterface::setChannel( int c )
887{ 889{
888 // call iwpriv <device> monitor 2 <channel> 890 _if->setPrivate( "monitor", 2, 2, c );
889 int* args = (int*) &_if->_iwr.u.name;
890 args[0] = 2;
891 args[1] = c;
892 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
893} 891}
894 892
895 893
896void OOrinocoMonitoringInterface::setEnabled( bool b ) 894void OOrinocoMonitoringInterface::setEnabled( bool b )
897{ 895{
898 if ( b ) 896 if ( b )
899 { 897 {
900 setChannel( 1 ); 898 setChannel( 1 );
901 } 899 }
902 else 900 else
903 { 901 {
904 // call iwpriv <device> monitor 0 0 902 _if->setPrivate( "monitor", 2, 0, 0 );
905 int* args = (int*) &_if->_iwr.u.name;
906 args[0] = 0;
907 args[1] = 0;
908 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
909 } 903 }
910} 904}
911 905
912 906
913QString OOrinocoMonitoringInterface::name() const 907QString OOrinocoMonitoringInterface::name() const
914{ 908{
915 return "orinoco"; 909 return "orinoco";
916} 910}
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index 4cadbeb..e249aee 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -54,28 +54,24 @@
54#endif 54#endif
55 55
56// ML: Yeah, I hate to include kernel headers, but it's necessary here 56// ML: Yeah, I hate to include kernel headers, but it's necessary here
57// ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> 57// ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h>
58// ML: which conflicts with the user header <net/if.h> 58// ML: which conflicts with the user header <net/if.h>
59// ML: We really a user header for the Wireless Extensions, something like <net/wireless.h> 59// ML: We really a user header for the Wireless Extensions, something like <net/wireless.h>
60// ML: I will drop Jean an mail on that subject 60// ML: I will drop Jean an mail on that subject
61 61
62#include <net/if.h> 62#include <net/if.h>
63#define _LINUX_IF_H 63#define _LINUX_IF_H
64#include <linux/wireless.h> 64#include <linux/wireless.h>
65 65
66#ifndef SIOCIWFIRSTPRIV
67#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
68#endif
69
70class ONetworkInterface; 66class ONetworkInterface;
71class OWirelessNetworkInterface; 67class OWirelessNetworkInterface;
72class OChannelHopper; 68class OChannelHopper;
73class OMonitoringInterface; 69class OMonitoringInterface;
74 70
75/*====================================================================================== 71/*======================================================================================
76 * ONetwork 72 * ONetwork
77 *======================================================================================*/ 73 *======================================================================================*/
78 74
79class ONetwork : public QObject 75class ONetwork : public QObject
80{ 76{
81 Q_OBJECT 77 Q_OBJECT
@@ -116,24 +112,25 @@ class ONetworkInterface : public QObject
116 ONetworkInterface( QObject* parent, const char* name ); 112 ONetworkInterface( QObject* parent, const char* name );
117 virtual ~ONetworkInterface(); 113 virtual ~ONetworkInterface();
118 114
119 void setMonitoring( OMonitoringInterface* ); 115 void setMonitoring( OMonitoringInterface* );
120 OMonitoringInterface* monitoring() const; 116 OMonitoringInterface* monitoring() const;
121 bool setPromiscuousMode( bool ); 117 bool setPromiscuousMode( bool );
122 bool promiscuousMode() const; 118 bool promiscuousMode() const;
123 bool setUp( bool ); 119 bool setUp( bool );
124 bool isUp() const; 120 bool isUp() const;
125 bool isLoopback() const; 121 bool isLoopback() const;
126 bool isWireless() const; 122 bool isWireless() const;
127 QString ipV4Address() const; 123 QString ipV4Address() const;
124 void setMacAddress( const OMacAddress& );
128 OMacAddress macAddress() const; 125 OMacAddress macAddress() const;
129 int dataLinkType() const; 126 int dataLinkType() const;
130 127
131 protected: 128 protected:
132 const int _sfd; 129 const int _sfd;
133 mutable ifreq _ifr; 130 mutable ifreq _ifr;
134 OMonitoringInterface* _mon; 131 OMonitoringInterface* _mon;
135 132
136 protected: 133 protected:
137 struct ifreq& ifr() const; 134 struct ifreq& ifr() const;
138 virtual void init(); 135 virtual void init();
139 bool ioctl( int call ) const; 136 bool ioctl( int call ) const;
@@ -195,24 +192,25 @@ class OWirelessNetworkInterface : public ONetworkInterface
195 virtual bool mode() const {}; 192 virtual bool mode() const {};
196 193
197 virtual void setMonitorMode( bool ); 194 virtual void setMonitorMode( bool );
198 virtual bool monitorMode() const; 195 virtual bool monitorMode() const;
199 196
200 virtual void setChannelHopping( int interval = 0 ); 197 virtual void setChannelHopping( int interval = 0 );
201 virtual int channelHopping() const; 198 virtual int channelHopping() const;
202 199
203 virtual void setNickName( const QString& ) {}; 200 virtual void setNickName( const QString& ) {};
204 virtual QString nickName() const; 201 virtual QString nickName() const;
205 202
206 virtual void setPrivate( const QString&, int, ... ); 203 virtual void setPrivate( const QString&, int, ... );
204 virtual bool hasPrivate( const QString& );
207 virtual void getPrivate( const QString& ); 205 virtual void getPrivate( const QString& );
208 206
209 virtual bool isAssociated() const {}; 207 virtual bool isAssociated() const {};
210 virtual QString associatedAP() const; 208 virtual QString associatedAP() const;
211 209
212 virtual void setSSID( const QString& ); 210 virtual void setSSID( const QString& );
213 virtual QString SSID() const; 211 virtual QString SSID() const;
214 212
215 protected: 213 protected:
216 void buildChannelList(); 214 void buildChannelList();
217 void buildPrivateList(); 215 void buildPrivateList();
218 virtual void init(); 216 virtual void init();
@@ -240,25 +238,25 @@ class OMonitoringInterface
240 OMonitoringInterface(); 238 OMonitoringInterface();
241 OMonitoringInterface( ONetworkInterface* ); 239 OMonitoringInterface( ONetworkInterface* );
242 virtual ~OMonitoringInterface(); 240 virtual ~OMonitoringInterface();
243 241
244 public: 242 public:
245 virtual void setEnabled( bool ); 243 virtual void setEnabled( bool );
246 virtual bool enabled() const; 244 virtual bool enabled() const;
247 virtual void setChannel( int ); 245 virtual void setChannel( int );
248 246
249 virtual QString name() const = 0; 247 virtual QString name() const = 0;
250 248
251 protected: 249 protected:
252 const OWirelessNetworkInterface* _if; 250 OWirelessNetworkInterface* _if;
253 251
254}; 252};
255 253
256 254
257/*====================================================================================== 255/*======================================================================================
258 * OCiscoMonitoring 256 * OCiscoMonitoring
259 *======================================================================================*/ 257 *======================================================================================*/
260 258
261 259
262class OCiscoMonitoringInterface : public OMonitoringInterface 260class OCiscoMonitoringInterface : public OMonitoringInterface
263{ 261{
264 public: 262 public: