summaryrefslogtreecommitdiff
path: root/libopie2/opienet/onetwork.cpp
Side-by-side diff
Diffstat (limited to 'libopie2/opienet/onetwork.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp113
1 files changed, 97 insertions, 16 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index dc2e388..be45924 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -75,8 +75,9 @@ void ONetwork::synchronize()
{
// gather available interfaces by inspecting /proc/net/dev
//FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
//FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
+ //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev
_interfaces.clear();
QString str;
QFile f( "/proc/net/dev" );
@@ -187,11 +188,11 @@ void ONetworkInterface::init()
bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
{
int result = ::ioctl( _sfd, call, &ifreq );
if ( result == -1 )
- qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
+ qDebug( "ONetworkInterface::ioctl (%s) call %d (0x%04X) - Status: Failed: %d (%s)", name(), call, call, result, strerror( errno ) );
else
- qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call );
+ qDebug( "ONetworkInterface::ioctl (%s) call %d (0x%04X) - Status: Ok.", name(), call, call );
return ( result != -1 );
}
@@ -453,10 +454,18 @@ struct iwreq& OWirelessNetworkInterface::iwr() const
void OWirelessNetworkInterface::init()
{
qDebug( "OWirelessNetworkInterface::init()" );
memset( &_iwr, 0, sizeof( struct iwreq ) );
- buildChannelList();
+ buildInformation();
buildPrivateList();
+ dumpInformation();
+}
+
+
+bool OWirelessNetworkInterface::isAssociated() const
+{
+ //FIXME: handle different modes
+ return associatedAP() != "44:44:44:44:44:44";
}
QString OWirelessNetworkInterface::associatedAP() const
@@ -481,9 +490,9 @@ QString OWirelessNetworkInterface::associatedAP() const
return mac;
}
-void OWirelessNetworkInterface::buildChannelList()
+void OWirelessNetworkInterface::buildInformation()
{
//ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
//ML: The HostAP drivers need more than sizeof struct_iw range to complete
//ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
@@ -504,9 +513,9 @@ void OWirelessNetworkInterface::buildChannelList()
wrq.u.data.flags = 0;
if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
{
- qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) );
+ qDebug( "OWirelessNetworkInterface::buildInformation(): SIOCGIWRANGE failed (%s) - using default values.", strerror( errno ) );
_channels.insert( 2412, 1 ); // 2.412 GHz
_channels.insert( 2417, 2 ); // 2.417 GHz
_channels.insert( 2422, 3 ); // 2.422 GHz
_channels.insert( 2427, 4 ); // 2.427 GHz
@@ -516,8 +525,10 @@ void OWirelessNetworkInterface::buildChannelList()
_channels.insert( 2447, 8 ); // 2.447 GHz
_channels.insert( 2452, 9 ); // 2.452 GHz
_channels.insert( 2457, 10 ); // 2.457 GHz
_channels.insert( 2462, 11 ); // 2.462 GHz
+
+ memset( &_range, 0, sizeof( struct iw_range ) );
}
else
{
// <check if the driver overwrites stuff>
@@ -526,25 +537,26 @@ void OWirelessNetworkInterface::buildChannelList()
if (buffer[r] != 0)
max = r;
if (max > 0)
{
- qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'"
- "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) );
+ qWarning( "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '%s' sucks!\n"
+ "It overwrote the buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) );
}
// </check if the driver overwrites stuff>
struct iw_range range;
memcpy( &range, buffer, sizeof range );
- qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency );
+ qDebug( "OWirelessNetworkInterface::buildInformation(): Interface %s reported to have %d channels.", name(), range.num_frequency );
for ( int i = 0; i < range.num_frequency; ++i )
{
int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
_channels.insert( freq, i+1 );
}
}
- qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." );
+ memcpy( &_range, buffer, sizeof( struct iw_range ) );
+ qDebug( "OWirelessNetworkInterface::buildInformation(): Information block constructed." );
free(buffer);
}
@@ -571,8 +583,19 @@ void OWirelessNetworkInterface::buildPrivateList()
qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." );
}
+void OWirelessNetworkInterface::dumpInformation() const
+{
+ qDebug( "OWirelessNetworkInterface::() -------------- dumping information block ----------------" );
+
+ qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s", _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 );
+ qDebug( " - driver for '%s' has been compiled against WE V%d (source=V%d)", name(), _range.we_version_compiled, _range.we_version_source );
+
+ qDebug( "OWirelessNetworkInterface::() ---------------------------------------------------------" );
+}
+
+
int OWirelessNetworkInterface::channel() const
{
//FIXME: When monitoring enabled, then use it
//FIXME: to gather the current RF channel
@@ -660,11 +683,9 @@ void OWirelessNetworkInterface::setMode( const QString& mode )
else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA;
else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER;
else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT;
else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND;
- #if WIRELESS_EXT > 14
else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR;
- #endif
else
{
qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode );
return;
@@ -686,11 +707,9 @@ QString OWirelessNetworkInterface::mode() const
case IW_MODE_INFRA: return "managed";
case IW_MODE_MASTER: return "master";
case IW_MODE_REPEAT: return "repeater";
case IW_MODE_SECOND: return "secondary";
- #if WIRELESS_EXT > 14
case IW_MODE_MONITOR: return "monitor";
- #endif
default: assert( 0 ); // shouldn't happen
}
}
@@ -707,9 +726,10 @@ void OWirelessNetworkInterface::setMonitorMode( bool b )
bool OWirelessNetworkInterface::monitorMode() const
{
qDebug( "dataLinkType = %d", dataLinkType() );
return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 );
- // 802 is the header type for PRISM - Linux support for this is pending...
+ //FIXME: 802 is the header type for PRISM - Linux support for this is pending...
+ //FIXME: What is 119, by the way?
}
void OWirelessNetworkInterface::setNickName( const QString& nickname )
@@ -799,15 +819,76 @@ void OWirelessNetworkInterface::setSSID( const QString& ssid )
wioctl( SIOCSIWESSID );
}
+int OWirelessNetworkInterface::scanNetwork()
+{
+ _iwr.u.param.flags = IW_SCAN_DEFAULT;
+ _iwr.u.param.value = 0;
+ if ( !wioctl( SIOCSIWSCAN ) )
+ {
+ return -1;
+ }
+
+ int timeout = 1000000;
+
+ qDebug( "ONetworkInterface::scanNetwork() - scan started." );
+
+ bool results = false;
+ struct timeval tv;
+ tv.tv_sec = 0;
+ tv.tv_usec = 250000; // initial timeout ~ 250ms
+ char buffer[IW_SCAN_MAX_DATA];
+
+ while ( !results && timeout > 0 )
+ {
+ timeout -= tv.tv_usec;
+ select( 0, 0, 0, 0, &tv );
+
+ _iwr.u.data.pointer = &buffer[0];
+ _iwr.u.data.flags = 0;
+ _iwr.u.data.length = sizeof buffer;
+ if ( wioctl( SIOCGIWSCAN ) )
+ {
+ results = true;
+ continue;
+ }
+ else if ( errno == EAGAIN)
+ {
+ qDebug( "ONetworkInterface::scanNetwork() - scan in progress..." );
+ #if 0
+ if ( qApp )
+ {
+ qApp->processEvents( 100 );
+ continue;
+ }
+ #endif
+ tv.tv_sec = 0;
+ tv.tv_usec = 100000;
+ continue;
+ }
+ }
+
+ qDebug( "ONetworkInterface::scanNetwork() - scan finished." );
+
+ if ( results )
+ {
+ qDebug( " - results are in!" );
+ }
+ else
+ {
+ qDebug( " - no results :(" );
+ }
+}
+
+
bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
{
int result = ::ioctl( _sfd, call, &iwreq );
if ( result == -1 )
- qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
+ qDebug( "ONetworkInterface::wioctl (%s) call %d (0x%04X) - Status: Failed: %d (%s)", name(), call, call, result, strerror( errno ) );
else
- qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call );
+ qDebug( "ONetworkInterface::wioctl (%s) call %d (0x%04X) - Status: Ok.", name(), call, call );
return ( result != -1 );
}