summaryrefslogtreecommitdiff
path: root/libopie2/opienet/onetwork.cpp
Unidiff
Diffstat (limited to 'libopie2/opienet/onetwork.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp51
1 files changed, 51 insertions, 0 deletions
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;