summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp38
-rw-r--r--libopie2/opienet/onetwork.h3
-rw-r--r--libopie2/opienet/ostation.h2
3 files changed, 38 insertions, 5 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 546be9e..0a74019 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -1,103 +1,105 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003-2005 by Michael 'Mickey' Lauer <mickey@Vanille.de> 3              Copyright (C) 2003-2005 by Michael 'Mickey' Lauer <mickey@Vanille.de>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; version 2 of the License. 11 - .   .-<_>     .<> Foundation; version 2 of the License.
12     ._= =}       : 12     ._= =}       :
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31/* OPIE */ 31/* OPIE */
32 32
33#include <opie2/onetwork.h> 33#include <opie2/onetwork.h>
34#include <opie2/ostation.h> 34#include <opie2/ostation.h>
35#include <opie2/odebug.h> 35#include <opie2/odebug.h>
36 36
37/* QT */ 37/* QT */
38 38
39#include <qfile.h> 39#include <qfile.h>
40#include <qtextstream.h> 40#include <qtextstream.h>
41#include <qapplication.h>
41 42
42/* UNIX */ 43/* UNIX */
43 44
44#include <assert.h> 45#include <assert.h>
45#include <arpa/inet.h> 46#include <arpa/inet.h>
46#include <errno.h> 47#include <errno.h>
47#include <string.h> 48#include <string.h>
48#include <stdlib.h> 49#include <stdlib.h>
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>
57#include <net/ethernet.h>
56#include <stdarg.h> 58#include <stdarg.h>
57 59
58#ifndef NODEBUG 60#ifndef NODEBUG
59#include <opie2/odebugmapper.h> 61#include <opie2/odebugmapper.h>
60 62
61using namespace Opie::Core; 63using namespace Opie::Core;
62using namespace Opie::Net::Internal; 64using namespace Opie::Net::Internal;
63DebugMapper* debugmapper = new DebugMapper(); 65DebugMapper* debugmapper = new DebugMapper();
64#endif 66#endif
65 67
66/*====================================================================================== 68/*======================================================================================
67 * ONetwork 69 * ONetwork
68 *======================================================================================*/ 70 *======================================================================================*/
69 71
70namespace Opie { 72namespace Opie {
71namespace Net { 73namespace Net {
72ONetwork* ONetwork::_instance = 0; 74ONetwork* ONetwork::_instance = 0;
73 75
74ONetwork::ONetwork() 76ONetwork::ONetwork()
75{ 77{
76 odebug << "ONetwork::ONetwork()" << oendl; 78 odebug << "ONetwork::ONetwork()" << oendl;
77 odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; 79 odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl;
78 synchronize(); 80 synchronize();
79} 81}
80 82
81void ONetwork::synchronize() 83void ONetwork::synchronize()
82{ 84{
83 // gather available interfaces by inspecting /proc/net/dev 85 // gather available interfaces by inspecting /proc/net/dev
84 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 86 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
85 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices 87 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
86 //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev 88 //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev
87 89
88 _interfaces.clear(); 90 _interfaces.clear();
89 QString str; 91 QString str;
90 QFile f( "/proc/net/dev" ); 92 QFile f( "/proc/net/dev" );
91 bool hasFile = f.open( IO_ReadOnly ); 93 bool hasFile = f.open( IO_ReadOnly );
92 if ( !hasFile ) 94 if ( !hasFile )
93 { 95 {
94 odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; 96 odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl;
95 return; 97 return;
96 } 98 }
97 QTextStream s( &f ); 99 QTextStream s( &f );
98 s.readLine(); 100 s.readLine();
99 s.readLine(); 101 s.readLine();
100 while ( !s.atEnd() ) 102 while ( !s.atEnd() )
101 { 103 {
102 s >> str; 104 s >> str;
103 str.truncate( str.find( ':' ) ); 105 str.truncate( str.find( ':' ) );
@@ -446,96 +448,104 @@ void OChannelHopper::setInterval( int interval )
446 448
447 449
448int OChannelHopper::interval() const 450int OChannelHopper::interval() const
449{ 451{
450 return _interval; 452 return _interval;
451} 453}
452 454
453 455
454/*====================================================================================== 456/*======================================================================================
455 * OWirelessNetworkInterface 457 * OWirelessNetworkInterface
456 *======================================================================================*/ 458 *======================================================================================*/
457 459
458OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) 460OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name )
459 :ONetworkInterface( parent, name ), _hopper( 0 ) 461 :ONetworkInterface( parent, name ), _hopper( 0 )
460{ 462{
461 odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl; 463 odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl;
462 init(); 464 init();
463} 465}
464 466
465 467
466OWirelessNetworkInterface::~OWirelessNetworkInterface() 468OWirelessNetworkInterface::~OWirelessNetworkInterface()
467{ 469{
468} 470}
469 471
470 472
471struct iwreq& OWirelessNetworkInterface::iwr() const 473struct iwreq& OWirelessNetworkInterface::iwr() const
472{ 474{
473 return _iwr; 475 return _iwr;
474} 476}
475 477
476 478
477void OWirelessNetworkInterface::init() 479void OWirelessNetworkInterface::init()
478{ 480{
479 odebug << "OWirelessNetworkInterface::init()" << oendl; 481 odebug << "OWirelessNetworkInterface::init()" << oendl;
480 memset( &_iwr, 0, sizeof( struct iwreq ) ); 482 memset( &_iwr, 0, sizeof( struct iwreq ) );
481 buildInformation(); 483 buildInformation();
482 buildPrivateList(); 484 buildPrivateList();
483 dumpInformation(); 485 dumpInformation();
484} 486}
485 487
486 488
487bool OWirelessNetworkInterface::isAssociated() const 489bool OWirelessNetworkInterface::isAssociated() const
488{ 490{
489 //FIXME: handle different modes 491 //FIXME: handle different modes
490 return !(associatedAP() == OMacAddress::unknown); 492 return !(associatedAP() == OMacAddress::unknown);
491} 493}
492 494
493 495
496void OWirelessNetworkInterface::setAssociatedAP( const OMacAddress& mac ) const
497{
498 _iwr.u.ap_addr.sa_family = ARPHRD_ETHER;
499 ::memcpy(_iwr.u.ap_addr.sa_data, mac.native(), ETH_ALEN);
500 wioctl( SIOCSIWAP );
501}
502
503
494OMacAddress OWirelessNetworkInterface::associatedAP() const 504OMacAddress OWirelessNetworkInterface::associatedAP() const
495{ 505{
496 if ( ioctl( SIOCGIWAP ) ) 506 if ( ioctl( SIOCGIWAP ) )
497 return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; 507 return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0];
498 else 508 else
499 return OMacAddress::unknown; 509 return OMacAddress::unknown;
500} 510}
501 511
502 512
503void OWirelessNetworkInterface::buildInformation() 513void OWirelessNetworkInterface::buildInformation()
504{ 514{
505 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck 515 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
506 //ML: The HostAP drivers need more than sizeof struct_iw range to complete 516 //ML: The HostAP drivers need more than sizeof struct_iw range to complete
507 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". 517 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
508 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate 518 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
509 //ML: _too much_ space. This is damn shitty crap *sigh* 519 //ML: _too much_ space. This is damn shitty crap *sigh*
510 //ML: We allocate a large memory region in RAM and check whether the 520 //ML: We allocate a large memory region in RAM and check whether the
511 //ML: driver pollutes this extra space. The complaint will be made on stdout, 521 //ML: driver pollutes this extra space. The complaint will be made on stdout,
512 //ML: so please forward this... 522 //ML: so please forward this...
513 523
514 struct iwreq wrq; 524 struct iwreq wrq;
515 int len = sizeof( struct iw_range )*2; 525 int len = sizeof( struct iw_range )*2;
516 char *buffer = (char*) malloc( len ); 526 char *buffer = (char*) malloc( len );
517 //FIXME: Validate if we actually got the memory block 527 //FIXME: Validate if we actually got the memory block
518 memset( buffer, 0, len ); 528 memset( buffer, 0, len );
519 memcpy( wrq.ifr_name, name(), IFNAMSIZ); 529 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
520 wrq.u.data.pointer = (caddr_t) buffer; 530 wrq.u.data.pointer = (caddr_t) buffer;
521 wrq.u.data.length = sizeof( struct iw_range ); 531 wrq.u.data.length = sizeof( struct iw_range );
522 wrq.u.data.flags = 0; 532 wrq.u.data.flags = 0;
523 533
524 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) 534 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
525 { 535 {
526 owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl; 536 owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl;
527 _channels.insert( 2412, 1 ); // 2.412 GHz 537 _channels.insert( 2412, 1 ); // 2.412 GHz
528 _channels.insert( 2417, 2 ); // 2.417 GHz 538 _channels.insert( 2417, 2 ); // 2.417 GHz
529 _channels.insert( 2422, 3 ); // 2.422 GHz 539 _channels.insert( 2422, 3 ); // 2.422 GHz
530 _channels.insert( 2427, 4 ); // 2.427 GHz 540 _channels.insert( 2427, 4 ); // 2.427 GHz
531 _channels.insert( 2432, 5 ); // 2.432 GHz 541 _channels.insert( 2432, 5 ); // 2.432 GHz
532 _channels.insert( 2437, 6 ); // 2.437 GHz 542 _channels.insert( 2437, 6 ); // 2.437 GHz
533 _channels.insert( 2442, 7 ); // 2.442 GHz 543 _channels.insert( 2442, 7 ); // 2.442 GHz
534 _channels.insert( 2447, 8 ); // 2.447 GHz 544 _channels.insert( 2447, 8 ); // 2.447 GHz
535 _channels.insert( 2452, 9 ); // 2.452 GHz 545 _channels.insert( 2452, 9 ); // 2.452 GHz
536 _channels.insert( 2457, 10 ); // 2.457 GHz 546 _channels.insert( 2457, 10 ); // 2.457 GHz
537 _channels.insert( 2462, 11 ); // 2.462 GHz 547 _channels.insert( 2462, 11 ); // 2.462 GHz
538 548
539 memset( &_range, 0, sizeof( struct iw_range ) ); 549 memset( &_range, 0, sizeof( struct iw_range ) );
540 } 550 }
541 else 551 else
@@ -861,103 +871,101 @@ QString OWirelessNetworkInterface::SSID() const
861} 871}
862 872
863 873
864void OWirelessNetworkInterface::setSSID( const QString& ssid ) 874void OWirelessNetworkInterface::setSSID( const QString& ssid )
865{ 875{
866 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 876 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
867 _iwr.u.essid.length = ssid.length()+1; // zero byte 877 _iwr.u.essid.length = ssid.length()+1; // zero byte
868 wioctl( SIOCSIWESSID ); 878 wioctl( SIOCSIWESSID );
869} 879}
870 880
871 881
872OStationList* OWirelessNetworkInterface::scanNetwork() 882OStationList* OWirelessNetworkInterface::scanNetwork()
873{ 883{
874 _iwr.u.param.flags = IW_SCAN_DEFAULT; 884 _iwr.u.param.flags = IW_SCAN_DEFAULT;
875 _iwr.u.param.value = 0; 885 _iwr.u.param.value = 0;
876 if ( !wioctl( SIOCSIWSCAN ) ) 886 if ( !wioctl( SIOCSIWSCAN ) )
877 { 887 {
878 return 0; 888 return 0;
879 } 889 }
880 890
881 OStationList* stations = new OStationList(); 891 OStationList* stations = new OStationList();
882 892
883 int timeout = 10000000; 893 int timeout = 10000000;
884 894
885 odebug << "ONetworkInterface::scanNetwork() - scan started." << oendl; 895 odebug << "ONetworkInterface::scanNetwork() - scan started." << oendl;
886 896
887 bool results = false; 897 bool results = false;
888 struct timeval tv; 898 struct timeval tv;
889 tv.tv_sec = 0; 899 tv.tv_sec = 0;
890 tv.tv_usec = 250000; // initial timeout ~ 250ms 900 tv.tv_usec = 250000; // initial timeout ~ 250ms
891 char buffer[IW_SCAN_MAX_DATA]; 901 char buffer[IW_SCAN_MAX_DATA];
892 902
893 while ( !results && timeout > 0 ) 903 while ( !results && timeout > 0 )
894 { 904 {
895 timeout -= tv.tv_usec; 905 timeout -= tv.tv_usec;
896 select( 0, 0, 0, 0, &tv ); 906 select( 0, 0, 0, 0, &tv );
897 907
898 _iwr.u.data.pointer = &buffer[0]; 908 _iwr.u.data.pointer = &buffer[0];
899 _iwr.u.data.flags = 0; 909 _iwr.u.data.flags = 0;
900 _iwr.u.data.length = sizeof buffer; 910 _iwr.u.data.length = sizeof buffer;
901 if ( wioctl( SIOCGIWSCAN ) ) 911 if ( wioctl( SIOCGIWSCAN ) )
902 { 912 {
903 results = true; 913 results = true;
904 continue; 914 continue;
905 } 915 }
906 else if ( errno == EAGAIN) 916 else if ( errno == EAGAIN)
907 { 917 {
908 odebug << "ONetworkInterface::scanNetwork() - scan in progress..." << oendl; 918 odebug << "ONetworkInterface::scanNetwork() - scan in progress..." << oendl;
909 #if 0
910 if ( qApp ) 919 if ( qApp )
911 { 920 {
912 qApp->processEvents( 100 ); 921 qApp->processEvents( 100 );
913 continue; 922 continue;
914 } 923 }
915 #endif
916 tv.tv_sec = 0; 924 tv.tv_sec = 0;
917 tv.tv_usec = 100000; 925 tv.tv_usec = 100000;
918 continue; 926 continue;
919 } 927 }
920 } 928 }
921 929
922 odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl; 930 odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl;
923 931
924 if ( results ) 932 if ( results )
925 { 933 {
926 odebug << " - result length = " << _iwr.u.data.length << oendl; 934 odebug << " - result length = " << _iwr.u.data.length << oendl;
927 if ( !_iwr.u.data.length ) 935 if ( !_iwr.u.data.length )
928 { 936 {
929 odebug << " - no results (empty neighbourhood)" << oendl; 937 odebug << " - no results (empty neighbourhood)" << oendl;
930 return stations; 938 return stations;
931 } 939 }
932 940
933 odebug << " - results are in!" << oendl; 941 odebug << " - results are in!" << oendl;
934 dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); 942 dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length );
935 943
936 // parse results 944 // parse results
937 struct iw_event iwe; 945 struct iw_event iwe;
938 struct iw_stream_descr stream; 946 struct iw_stream_descr stream;
939 unsigned int cmd_index, event_type, event_len; 947 unsigned int cmd_index, event_type, event_len;
940 char *pointer; 948 char *pointer;
941 949
942 const char standard_ioctl_hdr[] = { 950 const char standard_ioctl_hdr[] = {
943 IW_HEADER_TYPE_NULL, /* SIOCSIWCOMMIT */ 951 IW_HEADER_TYPE_NULL, /* SIOCSIWCOMMIT */
944 IW_HEADER_TYPE_CHAR, /* SIOCGIWNAME */ 952 IW_HEADER_TYPE_CHAR, /* SIOCGIWNAME */
945 IW_HEADER_TYPE_PARAM, /* SIOCSIWNWID */ 953 IW_HEADER_TYPE_PARAM, /* SIOCSIWNWID */
946 IW_HEADER_TYPE_PARAM, /* SIOCGIWNWID */ 954 IW_HEADER_TYPE_PARAM, /* SIOCGIWNWID */
947 IW_HEADER_TYPE_FREQ, /* SIOCSIWFREQ */ 955 IW_HEADER_TYPE_FREQ, /* SIOCSIWFREQ */
948 IW_HEADER_TYPE_FREQ, /* SIOCGIWFREQ */ 956 IW_HEADER_TYPE_FREQ, /* SIOCGIWFREQ */
949 IW_HEADER_TYPE_UINT, /* SIOCSIWMODE */ 957 IW_HEADER_TYPE_UINT, /* SIOCSIWMODE */
950 IW_HEADER_TYPE_UINT, /* SIOCGIWMODE */ 958 IW_HEADER_TYPE_UINT, /* SIOCGIWMODE */
951 IW_HEADER_TYPE_PARAM, /* SIOCSIWSENS */ 959 IW_HEADER_TYPE_PARAM, /* SIOCSIWSENS */
952 IW_HEADER_TYPE_PARAM, /* SIOCGIWSENS */ 960 IW_HEADER_TYPE_PARAM, /* SIOCGIWSENS */
953 IW_HEADER_TYPE_NULL, /* SIOCSIWRANGE */ 961 IW_HEADER_TYPE_NULL, /* SIOCSIWRANGE */
954 IW_HEADER_TYPE_POINT, /* SIOCGIWRANGE */ 962 IW_HEADER_TYPE_POINT, /* SIOCGIWRANGE */
955 IW_HEADER_TYPE_NULL, /* SIOCSIWPRIV */ 963 IW_HEADER_TYPE_NULL, /* SIOCSIWPRIV */
956 IW_HEADER_TYPE_POINT, /* SIOCGIWPRIV */ 964 IW_HEADER_TYPE_POINT, /* SIOCGIWPRIV */
957 IW_HEADER_TYPE_NULL, /* SIOCSIWSTATS */ 965 IW_HEADER_TYPE_NULL, /* SIOCSIWSTATS */
958 IW_HEADER_TYPE_POINT, /* SIOCGIWSTATS */ 966 IW_HEADER_TYPE_POINT, /* SIOCGIWSTATS */
959 IW_HEADER_TYPE_POINT, /* SIOCSIWSPY */ 967 IW_HEADER_TYPE_POINT, /* SIOCSIWSPY */
960 IW_HEADER_TYPE_POINT, /* SIOCGIWSPY */ 968 IW_HEADER_TYPE_POINT, /* SIOCGIWSPY */
961 IW_HEADER_TYPE_POINT, /* SIOCSIWTHRSPY */ 969 IW_HEADER_TYPE_POINT, /* SIOCSIWTHRSPY */
962 IW_HEADER_TYPE_POINT, /* SIOCGIWTHRSPY */ 970 IW_HEADER_TYPE_POINT, /* SIOCGIWTHRSPY */
963 IW_HEADER_TYPE_ADDR, /* SIOCSIWAP */ 971 IW_HEADER_TYPE_ADDR, /* SIOCSIWAP */
@@ -1082,111 +1090,131 @@ OStationList* OWirelessNetworkInterface::scanNetwork()
1082 1090
1083 /* Special processing for iw_point events */ 1091 /* Special processing for iw_point events */
1084 if(event_type == IW_HEADER_TYPE_POINT) { 1092 if(event_type == IW_HEADER_TYPE_POINT) {
1085 /* Check the length of the payload */ 1093 /* Check the length of the payload */
1086 1094
1087 if((iwe.len - (event_len + IW_EV_LCP_LEN)) > 0) 1095 if((iwe.len - (event_len + IW_EV_LCP_LEN)) > 0)
1088 /* Set pointer on variable part (warning : non aligned) */ 1096 /* Set pointer on variable part (warning : non aligned) */
1089 iwe.u.data.pointer = pointer; 1097 iwe.u.data.pointer = pointer;
1090 else 1098 else
1091 /* No data */ 1099 /* No data */
1092 iwe.u.data.pointer = NULL; 1100 iwe.u.data.pointer = NULL;
1093 /* Go to next event */ 1101 /* Go to next event */
1094 stream.current += iwe.len; 1102 stream.current += iwe.len;
1095 } 1103 }
1096 1104
1097 else { 1105 else {
1098 /* Is there more value in the event ? */ 1106 /* Is there more value in the event ? */
1099 if((pointer + event_len) <= (stream.current + iwe.len)) 1107 if((pointer + event_len) <= (stream.current + iwe.len))
1100 /* Go to next value */ 1108 /* Go to next value */
1101 stream.value = pointer; 1109 stream.value = pointer;
1102 else { 1110 else {
1103 /* Go to next event */ 1111 /* Go to next event */
1104 stream.value = NULL; 1112 stream.value = NULL;
1105 stream.current += iwe.len; 1113 stream.current += iwe.len;
1106 } 1114 }
1107 } 1115 }
1108 1116
1109 struct iw_event *we = &iwe; 1117 struct iw_event *we = &iwe;
1110 //------ 1118 //------
1111 odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl; 1119 odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl;
1112 switch (we->cmd) 1120 switch (we->cmd)
1113 { 1121 {
1114 case SIOCGIWAP: 1122 case SIOCGIWAP:
1115 { 1123 {
1116 odebug << "SIOCGIWAP" << oendl; 1124 odebug << "SIOCGIWAP" << oendl;
1117 stations->append( new OStation() ); 1125 stations->append( new OStation() );
1118 stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; 1126 stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0];
1119 break; 1127 break;
1120 } 1128 }
1121 case SIOCGIWMODE: 1129 case SIOCGIWMODE:
1122 { 1130 {
1123 odebug << "SIOCGIWMODE" << oendl; 1131 odebug << "SIOCGIWMODE" << oendl;
1124 stations->last()->type = modeToString( we->u.mode ); 1132 stations->last()->type = modeToString( we->u.mode );
1125 break; 1133 break;
1126 } 1134 }
1127 case SIOCGIWFREQ: 1135 case SIOCGIWFREQ:
1128 { 1136 {
1129 odebug << "SIOCGIWFREQ" << oendl; 1137 odebug << "SIOCGIWFREQ" << oendl;
1130 stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; 1138 if ( we->u.freq.m > 1000 )
1139 stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ];
1140 else
1141 stations->last()->channel = static_cast<int>(((double) we->u.freq.m) * pow( 10.0, we->u.freq.e ));
1131 break; 1142 break;
1132 } 1143 }
1133 case SIOCGIWESSID: 1144 case SIOCGIWESSID:
1134 { 1145 {
1135 odebug << "SIOCGIWESSID" << oendl; 1146 odebug << "SIOCGIWESSID" << oendl;
1136 we->u.essid.length = '\0'; // make sure it is zero terminated 1147 we->u.essid.length = '\0'; // make sure it is zero terminated
1137 stations->last()->ssid = static_cast<const char*> (we->u.essid.pointer); 1148 stations->last()->ssid = static_cast<const char*> (we->u.essid.pointer);
1138 odebug << "ESSID: " << stations->last()->ssid << oendl; 1149 odebug << "ESSID: " << stations->last()->ssid << oendl;
1139 break; 1150 break;
1140 } 1151 }
1152 case IWEVQUAL:
1153 {
1154 odebug << "IWEVQUAL" << oendl;
1155 stations->last()->level = static_cast<int>(we->u.qual.level);
1156 break; /* Quality part of statistics (scan) */
1157 }
1158 case SIOCGIWENCODE:
1159 {
1160 odebug << "SIOCGIWENCODE" << oendl;
1161 stations->last()->encrypted = !(we->u.data.flags & IW_ENCODE_DISABLED);
1162 break;
1163 }
1164
1165 case SIOCGIWRATE:
1166 {
1167 odebug << "SIOCGIWRATE" << oendl;
1168 stations->last()->rates.append(we->u.bitrate.value);
1169 break;
1170 }
1141 case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break; 1171 case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break;
1142 case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break;
1143 case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */ 1172 case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */
1144 case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */
1145 case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */ 1173 case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */
1146 case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */ 1174 case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */
1147 case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */ 1175 case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */
1148 default: odebug << "unhandled event" << oendl; 1176 default: odebug << "unhandled event" << oendl;
1149 } 1177 }
1150 1178
1151 } while (true); 1179 } while (true);
1152 } 1180 }
1153 else 1181 else
1154 { 1182 {
1155 odebug << " - no results (timeout) :(" << oendl; 1183 odebug << " - no results (timeout) :(" << oendl;
1156 } 1184 }
1157 return stations; 1185 return stations;
1158} 1186}
1159 1187
1160 1188
1161int OWirelessNetworkInterface::signalStrength() const 1189int OWirelessNetworkInterface::signalStrength() const
1162{ 1190{
1163 iw_statistics stat; 1191 iw_statistics stat;
1164 ::memset( &stat, 0, sizeof stat ); 1192 ::memset( &stat, 0, sizeof stat );
1165 _iwr.u.data.pointer = (char*) &stat; 1193 _iwr.u.data.pointer = (char*) &stat;
1166 _iwr.u.data.flags = 0; 1194 _iwr.u.data.flags = 0;
1167 _iwr.u.data.length = sizeof stat; 1195 _iwr.u.data.length = sizeof stat;
1168 1196
1169 if ( !wioctl( SIOCGIWSTATS ) ) 1197 if ( !wioctl( SIOCGIWSTATS ) )
1170 { 1198 {
1171 return -1; 1199 return -1;
1172 } 1200 }
1173 1201
1174 int max = _range.max_qual.qual; 1202 int max = _range.max_qual.qual;
1175 int cur = stat.qual.qual; 1203 int cur = stat.qual.qual;
1176// int lev = stat.qual.level; //FIXME: Do something with them? 1204// int lev = stat.qual.level; //FIXME: Do something with them?
1177// int noi = stat.qual.noise; //FIXME: Do something with them? 1205// int noi = stat.qual.noise; //FIXME: Do something with them?
1178 1206
1179 1207
1180 return max != 0 ? cur*100/max: -1; 1208 return max != 0 ? cur*100/max: -1;
1181} 1209}
1182 1210
1183 1211
1184bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const 1212bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
1185{ 1213{
1186 #ifndef NODEBUG 1214 #ifndef NODEBUG
1187 int result = ::ioctl( _sfd, call, &iwreq ); 1215 int result = ::ioctl( _sfd, call, &iwreq );
1188 1216
1189 if ( result == -1 ) 1217 if ( result == -1 )
1190 odebug << "ONetworkInterface::wioctl (" << name() << ") call '" 1218 odebug << "ONetworkInterface::wioctl (" << name() << ") call '"
1191 << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; 1219 << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl;
1192 else 1220 else
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index 4d9912d..fa9f39f 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -368,96 +368,99 @@ class OWirelessNetworkInterface : public ONetworkInterface
368 * @note: Important note concerning the 'monitor' mode: 368 * @note: Important note concerning the 'monitor' mode:
369 * Setting the monitor mode on a wireless network interface enables 369 * Setting the monitor mode on a wireless network interface enables
370 * listening to IEEE 802.11 data and management frames which normally 370 * listening to IEEE 802.11 data and management frames which normally
371 * are handled by the device firmware. This can be used to detect 371 * are handled by the device firmware. This can be used to detect
372 * other wireless network devices, e.g. Access Points or Ad-hoc stations. 372 * other wireless network devices, e.g. Access Points or Ad-hoc stations.
373 * @warning Standard wireless network drives don't support the monitor mode. 373 * @warning Standard wireless network drives don't support the monitor mode.
374 * @warning You need a patched driver for this to work. 374 * @warning You need a patched driver for this to work.
375 * @note Enabling the monitor mode is highly driver dependent and requires 375 * @note Enabling the monitor mode is highly driver dependent and requires
376 * the proper @ref OMonitoringInterface to be associated with the interface. 376 * the proper @ref OMonitoringInterface to be associated with the interface.
377 * @see OMonitoringInterface 377 * @see OMonitoringInterface
378 */ 378 */
379 virtual QString mode() const; 379 virtual QString mode() const;
380 /** 380 /**
381 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. 381 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping.
382 * @see OChannelHopper 382 * @see OChannelHopper
383 */ 383 */
384 virtual void setChannelHopping( int interval = 0 ); 384 virtual void setChannelHopping( int interval = 0 );
385 /** 385 /**
386 * @returns the channel hopping interval or 0, if channel hopping is disabled. 386 * @returns the channel hopping interval or 0, if channel hopping is disabled.
387 */ 387 */
388 virtual int channelHopping() const; 388 virtual int channelHopping() const;
389 /** 389 /**
390 * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before 390 * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before
391 */ 391 */
392 virtual OChannelHopper* channelHopper() const; 392 virtual OChannelHopper* channelHopper() const;
393 /** 393 /**
394 * Set the station @a nickname. 394 * Set the station @a nickname.
395 */ 395 */
396 virtual void setNickName( const QString& nickname ); 396 virtual void setNickName( const QString& nickname );
397 /** 397 /**
398 * @returns the current station nickname. 398 * @returns the current station nickname.
399 */ 399 */
400 virtual QString nickName() const; 400 virtual QString nickName() const;
401 /** 401 /**
402 * Invoke the private IOCTL @a command with a @number of parameters on the network interface. 402 * Invoke the private IOCTL @a command with a @number of parameters on the network interface.
403 * @see OPrivateIOCTL 403 * @see OPrivateIOCTL
404 */ 404 */
405 virtual void setPrivate( const QString& command, int number, ... ); 405 virtual void setPrivate( const QString& command, int number, ... );
406 /** 406 /**
407 * @returns true if the interface is featuring the private IOCTL @command. 407 * @returns true if the interface is featuring the private IOCTL @command.
408 */ 408 */
409 virtual bool hasPrivate( const QString& command ); 409 virtual bool hasPrivate( const QString& command );
410 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this 410 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this
411 /** 411 /**
412 * @returns true if the interface is associated to an access point 412 * @returns true if the interface is associated to an access point
413 * @note: This information is only valid if the interface is in managed mode. 413 * @note: This information is only valid if the interface is in managed mode.
414 */ 414 */
415 virtual bool isAssociated() const; 415 virtual bool isAssociated() const;
416 /** Set the @a mac associated AP address.
417 */
418 virtual void setAssociatedAP( const OMacAddress& mac ) const;
416 /** 419 /**
417 * @returns the MAC address of the Access Point if the device is in infrastructure mode. 420 * @returns the MAC address of the Access Point if the device is in infrastructure mode.
418 * @returns a (more or less random) cell ID address if the device is in adhoc mode. 421 * @returns a (more or less random) cell ID address if the device is in adhoc mode.
419 */ 422 */
420 virtual OMacAddress associatedAP() const; 423 virtual OMacAddress associatedAP() const;
421 /** 424 /**
422 * Set the @a ssid (Service Set ID) string. This is used to decide 425 * Set the @a ssid (Service Set ID) string. This is used to decide
423 * which network to associate with (use "any" to let the driver decide). 426 * which network to associate with (use "any" to let the driver decide).
424 */ 427 */
425 virtual void setSSID( const QString& ssid ); 428 virtual void setSSID( const QString& ssid );
426 /** 429 /**
427 * @returns the current SSID (Service Set ID). 430 * @returns the current SSID (Service Set ID).
428 */ 431 */
429 virtual QString SSID() const; 432 virtual QString SSID() const;
430 /** 433 /**
431 * Perform scanning the wireless network neighbourhood. 434 * Perform scanning the wireless network neighbourhood.
432 * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE! 435 * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE!
433 */ 436 */
434 virtual OStationList* scanNetwork(); 437 virtual OStationList* scanNetwork();
435 /** 438 /**
436 * @return signal strength to associated neighbour (in percent). 439 * @return signal strength to associated neighbour (in percent).
437 * In infrastructure mode, this is the signal strength of the Access Point. 440 * In infrastructure mode, this is the signal strength of the Access Point.
438 * In other modes the result is driver dependent. 441 * In other modes the result is driver dependent.
439 */ 442 */
440 virtual int signalStrength() const; 443 virtual int signalStrength() const;
441 /** 444 /**
442 * @returns the wireless extension version used by the interface driver. 445 * @returns the wireless extension version used by the interface driver.
443 **/ 446 **/
444 short wirelessExtensionDriverVersion() const; 447 short wirelessExtensionDriverVersion() const;
445 /** 448 /**
446 * @internal commit pending changes to the driver 449 * @internal commit pending changes to the driver
447 */ 450 */
448 void commit() const; 451 void commit() const;
449 452
450 protected: 453 protected:
451 void buildInformation(); 454 void buildInformation();
452 void buildPrivateList(); 455 void buildPrivateList();
453 void dumpInformation() const; 456 void dumpInformation() const;
454 virtual void init(); 457 virtual void init();
455 struct iwreq& iwr() const; 458 struct iwreq& iwr() const;
456 bool wioctl( int call ) const; 459 bool wioctl( int call ) const;
457 bool wioctl( int call, struct iwreq& ) const; 460 bool wioctl( int call, struct iwreq& ) const;
458 461
459 protected: 462 protected:
460 mutable struct iwreq _iwr; 463 mutable struct iwreq _iwr;
461 QMap<int,int> _channels; 464 QMap<int,int> _channels;
462 struct iw_range _range; 465 struct iw_range _range;
463 466
diff --git a/libopie2/opienet/ostation.h b/libopie2/opienet/ostation.h
index 5219d92..86c9a52 100644
--- a/libopie2/opienet/ostation.h
+++ b/libopie2/opienet/ostation.h
@@ -1,83 +1,85 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003-2005 by Michael 'Mickey' Lauer <mickey@Vanille.de> 3              Copyright (C) 2003-2005 by Michael 'Mickey' Lauer <mickey@Vanille.de>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; version 2 of the License. 11 - .   .-<_>     .<> Foundation; version 2 of the License.
12     ._= =}       : 12     ._= =}       :
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#ifndef OSTATION_H 31#ifndef OSTATION_H
32#define OSTATION_H 32#define OSTATION_H
33 33
34#include <opie2/onetutils.h> 34#include <opie2/onetutils.h>
35 35
36#include <qlist.h> 36#include <qlist.h>
37#include <qstring.h> 37#include <qstring.h>
38#include <qhostaddress.h> 38#include <qhostaddress.h>
39#include <qobject.h> 39#include <qobject.h>
40#include <qvaluelist.h>
40 41
41#include <sys/types.h> 42#include <sys/types.h>
42 43
43namespace Opie { 44namespace Opie {
44namespace Net { 45namespace Net {
45 46
46class OStation; 47class OStation;
47 48
48 49
49typedef QList<OStation> OStationList; 50typedef QList<OStation> OStationList;
50 51
51/*====================================================================================== 52/*======================================================================================
52 * OStation 53 * OStation
53 *======================================================================================*/ 54 *======================================================================================*/
54 55
55class OStation 56class OStation
56{ 57{
57 public: 58 public:
58 OStation(); 59 OStation();
59 ~OStation(); 60 ~OStation();
60 61
61 void dump(); 62 void dump();
62 63
63 /* Ethernet */ 64 /* Ethernet */
64 QString type; 65 QString type;
65 OMacAddress macAddress; 66 OMacAddress macAddress;
66 QHostAddress ipAddress; 67 QHostAddress ipAddress;
67 68
68 /* WaveLan */ 69 /* WaveLan */
69 QString ssid; 70 QString ssid;
70 OMacAddress apAddress; 71 OMacAddress apAddress;
71 int channel; 72 int channel;
72 int level; 73 int level;
73 bool encrypted; 74 bool encrypted;
75 QValueList <int> rates;
74 private: 76 private:
75 class Private; 77 class Private;
76 Private *d; 78 Private *d;
77}; 79};
78 80
79} 81}
80} 82}
81 83
82#endif // OSTATION_H 84#endif // OSTATION_H
83 85