summaryrefslogtreecommitdiff
path: root/libopie2/opienet/onetwork.cpp
Unidiff
Diffstat (limited to 'libopie2/opienet/onetwork.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp36
1 files changed, 32 insertions, 4 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
@@ -29,39 +29,41 @@
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
@@ -482,24 +484,32 @@ void OWirelessNetworkInterface::init()
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
@@ -897,31 +907,29 @@ OStationList* OWirelessNetworkInterface::scanNetwork()
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 )
@@ -1118,39 +1126,59 @@ OStationList* OWirelessNetworkInterface::scanNetwork()
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;
1138 if ( we->u.freq.m > 1000 )
1130 stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; 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 }