summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp21
-rw-r--r--libopie2/opienet/onetwork.cpp51
-rw-r--r--libopie2/opienet/onetwork.h58
3 files changed, 105 insertions, 25 deletions
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
index f801b15..fd68772 100644
--- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
+++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -1,62 +1,75 @@
1#include <opie2/onetwork.h> 1#include <opie2/onetwork.h>
2 2
3int main( int argc, char** argv ) 3int main( int argc, char** argv )
4{ 4{
5 qDebug( "OPIE Network Demo" ); 5 qDebug( "OPIE Network Demo" );
6 6
7 ONetwork* net = ONetwork::instance(); 7 ONetwork* net = ONetwork::instance();
8 8
9 ONetwork::InterfaceIterator it = net->iterator(); 9 ONetwork::InterfaceIterator it = net->iterator();
10 10
11 while ( it.current() ) 11 while ( it.current() )
12 { 12 {
13 qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() ); 13 qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() );
14 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() ); 14 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() );
15 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString(true) ); 15 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString(true) );
16 qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() ); 16 qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() );
17 if ( it.current()->isWireless() ) 17 if ( it.current()->isWireless() )
18 { 18 {
19 OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() ); 19 OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() );
20 qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() ); 20 qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() );
21 qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() ); 21 qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() );
22 qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() );
23 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() );
24 23
25 //if ( iface->mode() == OWirelessNetworkInterface::adhoc ) 24 //if ( iface->mode() == OWirelessNetworkInterface::adhoc )
26 //{ 25 //{
27 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() );
28 //} 27 //}
29 28
30 // try to set monitor mode 29 // nickname
30 qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() );
31 iface->setNickName( "MyNickName" );
32 if ( iface->nickName() != "MyNickName" )
33 qDebug( "DEMO: Warning! Can't change nickname" );
34 else
35 qDebug( "DEMO: Nickname change successful." );
36
37 // operation mode
38 qDebug( "DEMO: Current OperationMode is '%s'", (const char*) iface->mode() );
39 iface->setMode( "adhoc" );
40 if ( iface->mode() != "adhoc" )
41 qDebug( "DEMO: Warning! Can't change operation mode" );
42 else
43 qDebug( "DEMO: Operation Mode change successful." );
44
45 iface->setMode( "managed" );
31 46
32 /* 47 /*
33 48
34 // first some wrong calls to check if this is working 49 // first some wrong calls to check if this is working
35 iface->setPrivate( "seppel", 10 ); 50 iface->setPrivate( "seppel", 10 );
36 iface->setPrivate( "monitor", 0 ); 51 iface->setPrivate( "monitor", 0 );
37 52
38 // now the real deal 53 // now the real deal
39 iface->setPrivate( "monitor", 2, 2, 3 ); 54 iface->setPrivate( "monitor", 2, 2, 3 );
40 55
41 */
42
43 // trying to set hw address to 12:34:56:AB:CD:EF 56 // trying to set hw address to 12:34:56:AB:CD:EF
44 57
45 /* 58 /*
46 59
47 OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" ); 60 OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" );
48 iface->setUp( false ); 61 iface->setUp( false );
49 iface->setMacAddress( addr ); 62 iface->setMacAddress( addr );
50 iface->setUp( true ); 63 iface->setUp( true );
51 qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() ); 64 qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() );
52 65
53 */ 66 */
54 67
55 68
56 } 69 }
57 ++it; 70 ++it;
58 } 71 }
59 72
60 return 0; 73 return 0;
61 74
62} 75}
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 95e7043..2dfff1d 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -21,48 +21,49 @@
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/onetwork.h> 36#include <opie2/onetwork.h>
37 37
38/* QT */ 38/* QT */
39 39
40#include <qfile.h> 40#include <qfile.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42 42
43/* UNIX */ 43/* UNIX */
44 44
45#include <assert.h>
45#include <arpa/inet.h> 46#include <arpa/inet.h>
46#include <cerrno> 47#include <cerrno>
47#include <cstring> 48#include <cstring>
48#include <cstdlib> 49#include <cstdlib>
49#include <math.h> 50#include <math.h>
50#include <sys/ioctl.h> 51#include <sys/ioctl.h>
51#include <sys/socket.h> 52#include <sys/socket.h>
52#include <sys/types.h> 53#include <sys/types.h>
53#include <unistd.h> 54#include <unistd.h>
54#include <linux/sockios.h> 55#include <linux/sockios.h>
55#include <net/if_arp.h> 56#include <net/if_arp.h>
56#include <stdarg.h> 57#include <stdarg.h>
57 58
58using namespace std; 59using namespace std;
59 60
60/*====================================================================================== 61/*======================================================================================
61 * ONetwork 62 * ONetwork
62 *======================================================================================*/ 63 *======================================================================================*/
63 64
64ONetwork* ONetwork::_instance = 0; 65ONetwork* ONetwork::_instance = 0;
65 66
66ONetwork::ONetwork() 67ONetwork::ONetwork()
67{ 68{
68 qDebug( "ONetwork::ONetwork()" ); 69 qDebug( "ONetwork::ONetwork()" );
@@ -618,65 +619,115 @@ int OWirelessNetworkInterface::channels() const
618} 619}
619 620
620 621
621void OWirelessNetworkInterface::setChannelHopping( int interval ) 622void OWirelessNetworkInterface::setChannelHopping( int interval )
622{ 623{
623 if ( !_hopper ) _hopper = new OChannelHopper( this ); 624 if ( !_hopper ) _hopper = new OChannelHopper( this );
624 _hopper->setInterval( interval ); 625 _hopper->setInterval( interval );
625 //FIXME: When and by whom will the channel hopper be deleted? 626 //FIXME: When and by whom will the channel hopper be deleted?
626 //TODO: rely on QObject hierarchy 627 //TODO: rely on QObject hierarchy
627} 628}
628 629
629 630
630int OWirelessNetworkInterface::channelHopping() const 631int OWirelessNetworkInterface::channelHopping() const
631{ 632{
632 return _hopper->interval(); 633 return _hopper->interval();
633} 634}
634 635
635 636
636OChannelHopper* OWirelessNetworkInterface::channelHopper() const 637OChannelHopper* OWirelessNetworkInterface::channelHopper() const
637{ 638{
638 return _hopper; 639 return _hopper;
639} 640}
640 641
641 642
643void OWirelessNetworkInterface::setMode( const QString& mode )
644{
645 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO;
646 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC;
647 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA;
648 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER;
649 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT;
650 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND;
651 #if WIRELESS_EXT > 14
652 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR;
653 #endif
654 else
655 {
656 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode );
657 return;
658 }
659 wioctl( SIOCSIWMODE );
660}
661
662
663QString OWirelessNetworkInterface::mode() const
664{
665 if ( !wioctl( SIOCGIWMODE ) )
666 {
667 return "<unknown>";
668 }
669 switch ( _iwr.u.mode )
670 {
671 case IW_MODE_AUTO: return "auto";
672 case IW_MODE_ADHOC: return "adhoc";
673 case IW_MODE_INFRA: return "managed";
674 case IW_MODE_MASTER: return "master";
675 case IW_MODE_REPEAT: return "repeater";
676 case IW_MODE_SECOND: return "secondary";
677 #if WIRELESS_EXT > 14
678 case IW_MODE_MONITOR: return "monitor";
679 #endif
680 default: assert( 0 ); // shouldn't happen
681 }
682}
683
684
642void OWirelessNetworkInterface::setMonitorMode( bool b ) 685void OWirelessNetworkInterface::setMonitorMode( bool b )
643{ 686{
644 if ( _mon ) 687 if ( _mon )
645 _mon->setEnabled( b ); 688 _mon->setEnabled( b );
646 else 689 else
647 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 690 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
648} 691}
649 692
650 693
651bool OWirelessNetworkInterface::monitorMode() const 694bool OWirelessNetworkInterface::monitorMode() const
652{ 695{
653 qDebug( "dataLinkType = %d", dataLinkType() ); 696 qDebug( "dataLinkType = %d", dataLinkType() );
654 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); 697 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 );
655 // 802 is the header type for PRISM - Linux support for this is pending... 698 // 802 is the header type for PRISM - Linux support for this is pending...
656} 699}
657 700
658 701
702void OWirelessNetworkInterface::setNickName( const QString& nickname )
703{
704 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
705 _iwr.u.essid.length = nickname.length();
706 wioctl( SIOCSIWNICKN );
707}
708
709
659QString OWirelessNetworkInterface::nickName() const 710QString OWirelessNetworkInterface::nickName() const
660{ 711{
661 char str[IW_ESSID_MAX_SIZE]; 712 char str[IW_ESSID_MAX_SIZE];
662 _iwr.u.data.pointer = &str[0]; 713 _iwr.u.data.pointer = &str[0];
663 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 714 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
664 if ( !wioctl( SIOCGIWNICKN ) ) 715 if ( !wioctl( SIOCGIWNICKN ) )
665 { 716 {
666 return "<unknown>"; 717 return "<unknown>";
667 } 718 }
668 else 719 else
669 { 720 {
670 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 721 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
671 return str; 722 return str;
672 } 723 }
673} 724}
674 725
675 726
676void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) 727void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
677{ 728{
678 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); 729 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
679 if ( !priv ) 730 if ( !priv )
680 { 731 {
681 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); 732 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call );
682 return; 733 return;
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index f052317..a29b29d 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -13,60 +13,60 @@
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef ONETWORK_H 34#ifndef ONETWORK_H
35#define ONETWORK_H 35#define ONETWORK_H
36 36
37/* OPIE */
38
39#include <opie2/onetutils.h>
40
37/* QT */ 41/* QT */
38 42
39#include <qvaluelist.h> 43#include <qvaluelist.h>
40#include <qdict.h> 44#include <qdict.h>
41#include <qmap.h> 45#include <qmap.h>
42#include <qobject.h> 46#include <qobject.h>
43#include <qhostaddress.h> 47#include <qhostaddress.h>
44 48
45/* OPIE */
46
47#include <opie2/onetutils.h>
48
49#ifndef IFNAMSIZ 49#ifndef IFNAMSIZ
50#define IFNAMSIZ 16 50#define IFNAMSIZ 16
51#endif 51#endif
52#ifndef IW_MAX_PRIV_DEF 52#ifndef IW_MAX_PRIV_DEF
53#define IW_MAX_PRIV_DEF 128 53#define IW_MAX_PRIV_DEF 128
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 need a user header for the Wireless Extensions, something like <net/wireless.h> 59// ML: We really need a user header for the Wireless Extensions, something like <net/wireless.h>
60// ML: I will drop Jean a mail on that subject 60// ML: I will drop Jean a 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
66class ONetworkInterface; 66class ONetworkInterface;
67class OWirelessNetworkInterface; 67class OWirelessNetworkInterface;
68class OChannelHopper; 68class OChannelHopper;
69class OMonitoringInterface; 69class OMonitoringInterface;
70 70
71/*====================================================================================== 71/*======================================================================================
72 * ONetwork 72 * ONetwork
@@ -79,54 +79,54 @@ class OMonitoringInterface;
79 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 79 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
80 */ 80 */
81class ONetwork : public QObject 81class ONetwork : public QObject
82{ 82{
83 Q_OBJECT 83 Q_OBJECT
84 84
85 public: 85 public:
86 typedef QDict<ONetworkInterface> InterfaceMap; 86 typedef QDict<ONetworkInterface> InterfaceMap;
87 typedef QDictIterator<ONetworkInterface> InterfaceIterator; 87 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
88 88
89 public: 89 public:
90 /** 90 /**
91 * @returns the number of available interfaces 91 * @returns the number of available interfaces
92 */ 92 */
93 int count() const; 93 int count() const;
94 /** 94 /**
95 * @returns a pointer to the (one and only) @ref ONetwork instance. 95 * @returns a pointer to the (one and only) @ref ONetwork instance.
96 */ 96 */
97 static ONetwork* instance(); 97 static ONetwork* instance();
98 /** 98 /**
99 * @returns an iterator usable for iterating through all network interfaces. 99 * @returns an iterator usable for iterating through all network interfaces.
100 */ 100 */
101 InterfaceIterator iterator() const; 101 InterfaceIterator iterator() const;
102 /** 102 /**
103 * @returns true, if the @p interface supports the wireless extension protocol. 103 * @returns true, if the @a interface supports the wireless extension protocol.
104 */ 104 */
105 // FIXME QString? -zecke 105 // FIXME QString? -zecke
106 bool isWirelessInterface( const char* interface ) const; 106 bool isWirelessInterface( const char* interface ) const;
107 /** 107 /**
108 * @returns a pointer to the @ref ONetworkInterface object for the specified @p interface or 0, if not found 108 * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found
109 * @see ONetworkInterface 109 * @see ONetworkInterface
110 */ 110 */
111 // FIXME: const QString& is prefered over QString!!! -zecke 111 // FIXME: const QString& is prefered over QString!!! -zecke
112 ONetworkInterface* interface( const QString& interface ) const; 112 ONetworkInterface* interface( const QString& interface ) const;
113 /** 113 /**
114 * @internal Rebuild the internal interface database 114 * @internal Rebuild the internal interface database
115 * @note Sometimes it might be useful to call this from client code, 115 * @note Sometimes it might be useful to call this from client code,
116 * e.g. after issuing a cardctl insert 116 * e.g. after issuing a cardctl insert
117 */ 117 */
118 void synchronize(); 118 void synchronize();
119 119
120 protected: 120 protected:
121 ONetwork(); 121 ONetwork();
122 122
123 private: 123 private:
124 static ONetwork* _instance; 124 static ONetwork* _instance;
125 InterfaceMap _interfaces; 125 InterfaceMap _interfaces;
126}; 126};
127 127
128 128
129/*====================================================================================== 129/*======================================================================================
130 * ONetworkInterface 130 * ONetworkInterface
131 *======================================================================================*/ 131 *======================================================================================*/
132 132
@@ -177,67 +177,67 @@ class ONetworkInterface : public QObject
177 bool promiscuousMode() const; 177 bool promiscuousMode() const;
178 /** 178 /**
179 * Setting an interface to up enables it to receive packets. 179 * Setting an interface to up enables it to receive packets.
180 */ 180 */
181 bool setUp( bool ); 181 bool setUp( bool );
182 /** 182 /**
183 * @returns true if the interface is up. 183 * @returns true if the interface is up.
184 */ 184 */
185 bool isUp() const; 185 bool isUp() const;
186 /** 186 /**
187 * @returns true if the interface is a loopback interface. 187 * @returns true if the interface is a loopback interface.
188 */ 188 */
189 bool isLoopback() const; 189 bool isLoopback() const;
190 /** 190 /**
191 * @returns true if the interface is featuring supports the wireless extension protocol. 191 * @returns true if the interface is featuring supports the wireless extension protocol.
192 */ 192 */
193 bool isWireless() const; 193 bool isWireless() const;
194 /** 194 /**
195 * Associate the IP address @ addr with the interface. 195 * Associate the IP address @ addr with the interface.
196 */ 196 */
197 void setIPV4Address( const QHostAddress& addr ); 197 void setIPV4Address( const QHostAddress& addr );
198 /** 198 /**
199 * @returns the IPv4 address associated with the interface. 199 * @returns the IPv4 address associated with the interface.
200 */ 200 */
201 QString ipV4Address() const; 201 QString ipV4Address() const; //TODO: make this return an OHostAddress
202 /** 202 /**
203 * Associate the MAC address @a addr with the interface. 203 * Associate the MAC address @a addr with the interface.
204 * @note It can be necessary to shut down the interface prior to calling this method. 204 * @note It can be necessary to shut down the interface prior to calling this method.
205 * @warning This is not supported by all drivers. 205 * @warning This is not supported by all drivers.
206 */ 206 */
207 void setMacAddress( const OMacAddress& addr ); 207 void setMacAddress( const OMacAddress& addr );
208 /** 208 /**
209 * @returns the MAC address associated with the interface. 209 * @returns the MAC address associated with the interface.
210 */ 210 */
211 OMacAddress macAddress() const; 211 OMacAddress macAddress() const;
212 /** 212 /**
213 * Associate the IPv4 @a netmask with the interface. 213 * Associate the IPv4 @a netmask with the interface.
214 */ 214 */
215 void setIPV4Netmask( const QHostAddress& netmask ); 215 void setIPV4Netmask( const QHostAddress& netmask );
216 /** 216 /**
217 * @returns the IPv4 netmask associated with the interface. 217 * @returns the IPv4 netmask associated with the interface.
218 */ 218 */
219 QString ipV4Netmask() const; 219 QString ipV4Netmask() const; //TODO: make this return an OHostAddress
220 /** 220 /**
221 * @returns the data link type currently associated with the interface. 221 * @returns the data link type currently associated with the interface.
222 * @see #include <net/if_arp.h> for possible values. 222 * @see #include <net/if_arp.h> for possible values.
223 */ 223 */
224 int dataLinkType() const; 224 int dataLinkType() const;
225 225
226 protected: 226 protected:
227 const int _sfd; 227 const int _sfd;
228 mutable ifreq _ifr; 228 mutable ifreq _ifr;
229 OMonitoringInterface* _mon; 229 OMonitoringInterface* _mon;
230 230
231 protected: 231 protected:
232 struct ifreq& ifr() const; 232 struct ifreq& ifr() const;
233 virtual void init(); 233 virtual void init();
234 bool ioctl( int call ) const; 234 bool ioctl( int call ) const;
235 bool ioctl( int call, struct ifreq& ) const; 235 bool ioctl( int call, struct ifreq& ) const;
236}; 236};
237 237
238/*====================================================================================== 238/*======================================================================================
239 * OChannelHopper 239 * OChannelHopper
240 *======================================================================================*/ 240 *======================================================================================*/
241 241
242/** 242/**
243 * @brief A radio frequency channel hopper. 243 * @brief A radio frequency channel hopper.
@@ -296,134 +296,150 @@ class OChannelHopper : public QObject
296 QValueList<int>::Iterator _channel; 296 QValueList<int>::Iterator _channel;
297}; 297};
298 298
299 299
300/*====================================================================================== 300/*======================================================================================
301 * OWirelessNetworkInterface 301 * OWirelessNetworkInterface
302 *======================================================================================*/ 302 *======================================================================================*/
303 303
304/** 304/**
305 * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. 305 * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol.
306 * 306 *
307 * This class provides a high-level encapsulation of the Linux wireless extension API. 307 * This class provides a high-level encapsulation of the Linux wireless extension API.
308 */ 308 */
309class OWirelessNetworkInterface : public ONetworkInterface 309class OWirelessNetworkInterface : public ONetworkInterface
310{ 310{
311 friend class OMonitoringInterface; 311 friend class OMonitoringInterface;
312 friend class OCiscoMonitoringInterface; 312 friend class OCiscoMonitoringInterface;
313 friend class OWlanNGMonitoringInterface; 313 friend class OWlanNGMonitoringInterface;
314 friend class OHostAPMonitoringInterface; 314 friend class OHostAPMonitoringInterface;
315 friend class OOrinocoMonitoringInterface; 315 friend class OOrinocoMonitoringInterface;
316 316
317 friend class OPrivateIOCTL; 317 friend class OPrivateIOCTL;
318 318
319 public: 319 public:
320 enum Mode { AdHoc, Managed, Monitor };
321
322 /** 320 /**
323 * Constructor. 321 * Constructor.
324 */ 322 */
325 OWirelessNetworkInterface( QObject* parent, const char* name ); 323 OWirelessNetworkInterface( QObject* parent, const char* name );
326 /** 324 /**
327 * Destructor. 325 * Destructor.
328 */ 326 */
329 virtual ~OWirelessNetworkInterface(); 327 virtual ~OWirelessNetworkInterface();
330 /** 328 /**
331 * Setting the @a channel of the interface changes the radio frequency (RF) 329 * Setting the @a channel of the interface changes the radio frequency (RF)
332 * of the corresponding wireless network device. 330 * of the corresponding wireless network device.
333 */ 331 */
334 virtual void setChannel( int channel ) const; 332 virtual void setChannel( int channel ) const;
335 /** 333 /**
336 * @returns the channel index of the current radio frequency. 334 * @returns the channel index of the current radio frequency.
337 */ 335 */
338 virtual int channel() const; 336 virtual int channel() const;
339 /** 337 /**
340 * @returns the current radio frequency (in MHz). 338 * @returns the current radio frequency (in MHz).
341 */ 339 */
342 virtual double frequency() const; 340 virtual double frequency() const;
343 /** 341 /**
344 * @returns the number of radio frequency channels for the 342 * @returns the number of radio frequency channels for the
345 * corresponding wireless network device. 343 * corresponding wireless network device.
346 * @note European devices usually have 14 channels, while American typically feature 11 channels. 344 * @note European devices usually have 14 channels, while American typically feature 11 channels.
347 */ 345 */
348 virtual int channels() const; 346 virtual int channels() const;
349 //virtual double frequency(int) const; 347 /**
350 348 * Set the IEEE 802.11 operation @a mode.
351 virtual void setMode( Mode ) {}; //FIXME: Implement and document this 349 * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master
352 virtual bool mode() const {}; //FIXME: Implement and document this 350 * @warning Not all drivers support the all modes.
353 351 * @note You might have to change the SSID to get the operation mode change into effect.
352 */
353 virtual void setMode( const QString& mode );
354 /**
355 * @returns the current IEEE 802.11 operation mode.
356 * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown
357 */
358 virtual QString mode() const;
354 /** 359 /**
355 * Setting the monitor mode on a wireless network interface enables 360 * Setting the monitor mode on a wireless network interface enables
356 * listening to IEEE 802.11 data and management frames which normally 361 * listening to IEEE 802.11 data and management frames which normally
357 * are handled by the device firmware. This can be used to detect 362 * are handled by the device firmware. This can be used to detect
358 * other wireless network devices, e.g. Access Points or Ad-hoc stations. 363 * other wireless network devices, e.g. Access Points or Ad-hoc stations.
359 * @warning Standard wireless network drives don't support the monitor mode. 364 * @warning Standard wireless network drives don't support the monitor mode.
360 * @warning You need a patched driver for this to work. 365 * @warning You need a patched driver for this to work.
361 * @note Enabling the monitor mode is highly driver dependent and requires 366 * @note Enabling the monitor mode is highly driver dependent and requires
362 * the proper @ref OMonitoringInterface to be associated with the interface. 367 * the proper @ref OMonitoringInterface to be associated with the interface.
363 * @see OMonitoringInterface 368 * @see OMonitoringInterface
364 */ 369 */
365 virtual void setMonitorMode( bool ); 370 virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" );
366 /** 371 /**
367 * @returns true if the device is listening in IEEE 802.11 monitor mode 372 * @returns true if the device is listening in IEEE 802.11 monitor mode
368 */ 373 */
369 virtual bool monitorMode() const; 374 virtual bool monitorMode() const; //FIXME: ==> mode()
370 /** 375 /**
371 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. 376 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping.
372 * @see OChannelHopper 377 * @see OChannelHopper
373 */ 378 */
374 virtual void setChannelHopping( int interval = 0 ); 379 virtual void setChannelHopping( int interval = 0 );
375 /** 380 /**
376 * @returns the channel hopping interval or 0, if channel hopping is disabled. 381 * @returns the channel hopping interval or 0, if channel hopping is disabled.
377 */ 382 */
378 virtual int channelHopping() const; 383 virtual int channelHopping() const;
379 /** 384 /**
380 * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before 385 * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before
381 */ 386 */
382 virtual OChannelHopper* channelHopper() const; 387 virtual OChannelHopper* channelHopper() const;
383 /** 388 /**
384 * Set the station @a nickname. 389 * Set the station @a nickname.
385 */ 390 */
386 virtual void setNickName( const QString& nickname ) {}; //FIXME: Implement this 391 virtual void setNickName( const QString& nickname );
387 /** 392 /**
388 * @returns the current station nickname. 393 * @returns the current station nickname.
389 */ 394 */
390 virtual QString nickName() const; 395 virtual QString nickName() const;
391 /** 396 /**
392 * Invoke the private IOCTL @a command with a @number of parameters on the network interface. 397 * Invoke the private IOCTL @a command with a @number of parameters on the network interface.
393 * @see OPrivateIOCTL 398 * @see OPrivateIOCTL
394 */ 399 */
395 virtual void setPrivate( const QString& command, int number, ... ); 400 virtual void setPrivate( const QString& command, int number, ... );
396 /** 401 /**
397 * @returns true if the interface is featuring the private IOCTL @command. 402 * @returns true if the interface is featuring the private IOCTL @command.
398 */ 403 */
399 virtual bool hasPrivate( const QString& command ); 404 virtual bool hasPrivate( const QString& command );
400 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this 405 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this
401 406
402 virtual bool isAssociated() const {}; //FIXME: Implement and document this 407 virtual bool isAssociated() const {}; //FIXME: Implement and document this
403 virtual QString associatedAP() const; //FIXME: Implement and document this 408 /**
404 409 * @returns the MAC address of the Access Point if the
405 virtual void setSSID( const QString& ); 410 * device is in infrastructure mode. @returns a (more or less random) CELL
411 * address if the device is in adhoc mode.
412 */
413 virtual QString associatedAP() const;
414 /**
415 * Set the @a ssid (Service Set ID) string. This is used to decide
416 * which network to associate with (use "any" to let the driver decide).
417 */
418 virtual void setSSID( const QString& ssid );
419 /**
420 * @returns the current SSID (Service Set ID).
421 */
406 virtual QString SSID() const; 422 virtual QString SSID() const;
407 423
408 protected: 424 protected:
409 void buildChannelList(); 425 void buildChannelList();
410 void buildPrivateList(); 426 void buildPrivateList();
411 virtual void init(); 427 virtual void init();
412 struct iwreq& iwr() const; 428 struct iwreq& iwr() const;
413 bool wioctl( int call ) const; 429 bool wioctl( int call ) const;
414 bool wioctl( int call, struct iwreq& ) const; 430 bool wioctl( int call, struct iwreq& ) const;
415 431
416 protected: 432 protected:
417 mutable struct iwreq _iwr; 433 mutable struct iwreq _iwr;
418 QMap<int,int> _channels; 434 QMap<int,int> _channels;
419 435
420 private: 436 private:
421 OChannelHopper* _hopper; 437 OChannelHopper* _hopper;
422}; 438};
423 439
424 440
425/*====================================================================================== 441/*======================================================================================
426 * OMonitoringInterface 442 * OMonitoringInterface
427 *======================================================================================*/ 443 *======================================================================================*/
428 444
429 445