summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ChangeLog2
-rw-r--r--examples/opienet/miniwellenreiter/miniwellenreiter.cpp2
-rw-r--r--examples/opienet/onetworkdemo/onetworkdemo.cpp2
-rw-r--r--libopie2/opienet/onetutils.cpp19
-rw-r--r--libopie2/opienet/onetutils.h8
-rw-r--r--libopie2/opienet/onetwork.cpp43
-rw-r--r--libopie2/opienet/onetwork.h7
-rw-r--r--noncore/applets/networkapplet/networkapplet.cpp6
-rw-r--r--noncore/net/opiestumbler/opiestumbler.cpp2
9 files changed, 47 insertions, 44 deletions
diff --git a/ChangeLog b/ChangeLog
index 04a585a..ab65cde 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,125 +1,127 @@
2005-??-?? Opie 1.2.1
New Features
------------
* OpieStumbler: Scans WiFi networks using the wireless extension scanning (skyhusker)
* Opie-Reader: Support for document formats ArriereGo and Reb, add flite output (tim,pohly)
* Opie-Networksettings: Add support for wlan-ng devices and improve WEP handling (Dirk Opfer)
* Wellenreiter: Remove Joining networks - use OpieStumbler for that (mickeyl)
Fixed Bugs
----------
* #1476 - Wrong order of application entries in the O-menu (skyhusker)
* #1535 - Missing line break and unnecessary location shown with Today-Calendar plugin (deller)
* #1565 - crash-fix in odevice.cpp while scanning the distribution table (deller)
* #1614 - Make Opie-console start in $HOME instead of / (skyhusker)
* n.a. - always show volume and wireless applet popups inside visible screen (deller)
* n.a. - scale O-Menu-Applets appropriately (mickeyl)
* n.a. - libopienet: fix bugs in wireless scanning and setting SSID (skyhusker)
* n.a. - Wellenreiter: relax WE version matching test a bit (mickeyl)
* n.a. - scale BluezApplet appropriately and use larger icons (mickeyl)
* n.a. - memoryapplet: fix crash in memoryapplet on kernels without swap support (seneca cunningham)
* n.a. - networksettings: ignore hostap control interfaces wifi* (mickeyl)
Internal
--------
* Make BluezApplet use OTaskbarApplet (mickeyl)
* Rewrite OFileNotification to use the upcoming inotify interface instead of the deprecated dnotify (mickeyl)
* libopienet: Skip hostap control interfaces 'wifi' and improve robustness in ONetworkInterface (mickeyl)
+ * libopieui: Remove OVersatileView and OVersatileViewItem (mickeyl)
+ * libopienet: Miscellaneous API cleanups (mickeyl)
2005-03-25 Opie 1.2.0
Fixed Bugs
----------
* #1613 - AdvancedFM - scale toolbar icons appropriately (drw)
* #1620 - OFileSelector - show the button on press and not on press on hold (alwin)
* #1473 - Opie-Eye - Same as #1620 but we lack a common FileSystem Button class (zecke)
* n.a. - PackageManager - fix bug where messages show up multiple times in install dialog (drw)
* n.a. - make qpeglobal.h include qglobal.h (zecke)
2005-03-20 Opie 1.2.0-rc1
New Features
------------
* Launcher: Support a static background pixmap (mickeyl)
* LauncherSettings: Choose whether to have a static background pixmap (mickeyl)
* PackageManager supports the 'lists_dir' ipkg configuration option (drw)
* Added hi-res inline images for large resolution devices (drw)
* Improved launcher icons for consistency (ar)
* Datebook: Added plugin system to datebook so holidays and birthdays from contacts may displayed in datebook (alwin)
Fixed Bugs
----------
* #1236 - VCards contained empty home and work address entries causing Palms to crash (eilers)
* #1412 - Launcher Settings - fixed default settings for background in Edit tab dialog (drw)
* #1472 - Opie textedit now check for unsaved changes on ESC key (ljp)
* #1474 - Implement GUI for Scrollbars on the Left in Appearance (zecke)
* #1482 - Fix double '/' in paths (zecke)
* #1536 - Autosave of custom locations in opie backup (ar)
* #1539 - Fixed displaying too long path in the delete dialog in opie-eye (zecke)
* #1540 - Implemented deletion of DocLnks in opie-eye (zecke)
* #1542 - Fixed Todo crash when priority < 1 or > 5 (drw)
* #1550 - Browse for alarm sound start in QPEDIR/sounds/ (zecke)
* #1554 - Fixed Opie-Console name in .desktop file (mickeyl)
* #1556 - Start to look for sound files in /opt/QtPalmtop/sounds (zecke)
* #1558 - Fixed opie-login breaking opie startup (mickeyl)
* #1560 - Fixed Opie-Console picking up the wrong shell (bluelightning)
* #1570 - Confirmation needed befor Restore a backup and overwrite local data (ar)
* #1591 - Addressbook sortorder changed by clicking on column 0 (eilers)
* #1599 - Security - change recommendation for opie-multiauth to opie-securityplugin (gints)
* #1604 - Checkbook crashed on startup (drw)
* #1608 - Addressbook crashed after search, which may caused by not initialzed member variable (eilers)
* #1608 - QueryByExampe-Datediff on SQL database did not worked properly (eilers)
* n.a. - Netsystemtime - fixed UI to prevent error dialog from displaying when it shouldn't, get rid of some compiler warnings (drw)
* n.a. - PackageManager - fixed where last package in status file was not shown as installed when it should be (drw)
* n.a. - PackageManager - fixed bug where lists_dir was not being honored at startup (drw)
* n.a. - PackageManager - provided default value for lists_dir when none is entered in configuration dialog (drw)
* n.a. - OTabWidget - fixed scroll buttons, fix display position of tabs (drw)
* n.a. - AddressBook - fixed sorting by 'File As' name (drw)
* n.a. - AddressBook - fixed category handling for 'All' and 'Unfiled' (eilers)
* n.a. - AddressBook - fixed letter picker record selection and sort records afterwards (drw)
Internal
--------
* Worked around bug in Qt/Embedded 2.3.10: qt_version() returns 231 (mickeyl)
* Killed the need for weak symbols in QtE (zecke)
* Added optional building libqpe without inline images (mickeyl)
* OColorButton - fixed so does not emit a colorSelected signal inside of resizeEvent (drw)
2005-02-03 Opie 1.1.9
New Features
------------
* Number of icon columns in Launcher is customizable through Launcher.conf (hrw,zecke,mickeyl)
* Number of icon columns in Launcher is customizable through LauncherSettings (mickeyl)
* Usability enhancements in OpieIRC (skyhusker)
Fixed Bugs
----------
* #1501 - Fixed bug in todo sql backend (eilers)
* #1505 - Added more Swap sizes in memoryapplet (mickeyl)
* #1525 - Hopefully fixed double alarms and not removing alarms set with the Clock application (zecke)
* #1533 - Security Owner Dialog (shown in case of unsuccessfull authentiacation) wasn't able to display information in non latin1 encoding (zecke)
* n.a. - Removed hard coded font sizes in a couple of inputmethods (mickeyl)
* n.a. - Removed MediumDlg appearing prior to FirstUsage wizard (i.e. calibration) (mickeyl)
* n.a. - Fixed numerous buglets in OpieIRC (skyhusker)
Internal
--------
* Added the Qtopia 1.7 SDK macros for quick-apps to easa compilation of 3rd party apps against our headers (mickeyl)
* You can now use the Opie build system in combination with a OpenEmbedded staging area which makes a nice cross development environment (mickeyl)
* Made Opie compilable with Qt/Embedded 2.3.10 (ar)
* Changed Launcher to get default orientation from ODevice w/ QWS_DISPLAY overriding (mickeyl)
* Build tree cleanups (mickeyl)
2004-11-26 Opie 1.1.8
New Features
------------
* PackageManager supports installation of local ipkg files (drw)
* PackageManager supports linking of applications to root (drw)
* PackageManager supports src/gz feeds (drw,wimpie)
* Added a syslog information tab to sysinfo (mickeyl)
* Added new, more consistent, PIM icons + a GIMP teplate (ar)
diff --git a/examples/opienet/miniwellenreiter/miniwellenreiter.cpp b/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
index ebd3b5f..ba9d2ca 100644
--- a/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
+++ b/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
@@ -1,150 +1,150 @@
#include <qdict.h>
#include <qsocketnotifier.h>
#include <qstring.h>
#include <opie2/onetwork.h>
#include <qapplication.h>
#include <opie2/opcap.h>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace Opie::Net;
//======================== Station help class ===============================
class Station
{
public:
Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {};
~Station() {};
QString type;
int channel;
bool wep;
int beacons;
};
QDict<Station> stations;
//======================== Application class ===============================
class Wellenreiter : public QApplication
{
Q_OBJECT
public:
Wellenreiter( int argc, char** argv ) : QApplication( argc, argv ), channel( 1 )
{
ONetwork* net = ONetwork::instance();
if ( argc < 3 )
{
printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] );
printf( "\n" );
printf( "Valid wireless interfaces (detected) are:\n" );
ONetwork::InterfaceIterator it = net->iterator();
while ( it.current() )
{
if ( it.current()->isWireless() )
{
printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(),
(const char*) it.current()->macAddress().toString(),
- (const char*) it.current()->ipV4Address() );
+ (const char*) it.current()->ipV4Address().toString() );
}
++it;
}
exit( -1 );
}
printf( "*******************************************************************\n" );
printf( "* Wellenreiter mini edition 1.0.0 (C) 2003 Michael 'Mickey' Lauer *\n" );
printf( "*******************************************************************\n" );
printf( "\n\n" );
QString interface( argv[1] );
QString driver( argv[2] );
printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver );
// sanity checks before downcasting
ONetworkInterface* iface = net->interface( interface );
if ( !iface )
{
printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface );
exit( -1 );
}
if ( !iface->isWireless() )
{
printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface );
exit( -1 );
}
// downcast should be safe now
wiface = (OWirelessNetworkInterface*) iface;
printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() );
// ifconfig +promisc the interface to receive all packets
if ( !wiface->promiscuousMode() )
{
printf( "Interface status is not promisc... switching to promisc... " );
wiface->setPromiscuousMode( true );
if ( !wiface->promiscuousMode() )
{
printf( "failed (%s). Exiting.\n", strerror( errno ) );
exit( -1 );
}
else
{
printf( "ok.\n" );
}
}
else
printf( "Interface status is already promisc - good.\n" );
// connect a monitoring strategy to the interface
if ( driver == "orinoco" )
new OOrinocoMonitoringInterface( wiface, false );
else
if ( driver == "hostap" )
new OHostAPMonitoringInterface( wiface, false );
else
if ( driver == "wlan-ng" )
new OWlanNGMonitoringInterface( wiface, false );
else
{
printf( "Unknown driver. Exiting\n" );
exit( -1 );
}
// enable monitoring mode
printf( "Enabling monitor mode...\n" );
wiface->setMode( "monitor" );
// open a packet capturer
cap = new OPacketCapturer();
cap->open( interface );
if ( !cap->isOpen() )
{
printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) );
exit( -1 );
}
// set capturer to non-blocking mode
cap->setBlocking( false );
// start channel hopper
//wiface->setChannelHopping( 1000 );
// connect
connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) );
// timer
startTimer( 1000 );
}
~Wellenreiter() {};
public slots:
virtual void timerEvent(QTimerEvent* e)
diff --git a/examples/opienet/onetworkdemo/onetworkdemo.cpp b/examples/opienet/onetworkdemo/onetworkdemo.cpp
index b3a1115..e8958dc 100644
--- a/examples/opienet/onetworkdemo/onetworkdemo.cpp
+++ b/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -1,158 +1,158 @@
/*
=. This file is part of the Opie Project
.=l. Copyright (C) 2004 Opie Team <opie-devel@handhelds.org>
.>+-=
_;:, .> :=|. This library is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This library is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* OPIE */
#include <opie2/onetwork.h>
#include <opie2/ostation.h>
#include <opie2/omanufacturerdb.h>
#include <opie2/odebug.h>
/* STD */
#include <unistd.h>
using namespace Opie::Net;
int main( int argc, char** argv )
{
odebug << "OPIE Network Demo" << oendl;
ONetwork* net = ONetwork::instance();
ONetwork::InterfaceIterator it = net->iterator();
while ( it.current() )
{
odebug << "DEMO: ONetwork contains Interface '" << it.current()->name() << "'" << oendl;
ONetworkInterfaceDriverInfo info = it.current()->driverInfo();
odebug << "DEMO: DriverName reported as '" << info.name() << "'" << oendl;
odebug << "DEMO: DriverVersion reported as '" << info.version() << "'" << oendl;
odebug << "DEMO: DriverFirmware reported as '" << info.firmware() << "'" << oendl;
odebug << "DEMO: DriverBus reported as '" << info.bus() << "'" << oendl;
odebug << "DEMO: Datalink code is '" << it.current()->dataLinkType() << "'" << oendl;
odebug << "DEMO: MAC Address is '" << it.current()->macAddress().toString() << "'" << oendl;
odebug << "DEMO: MAC Address is '" << it.current()->macAddress().toString(true) << "'" << oendl;
odebug << "DEMO: MAC Manufacturer seems to be '" << it.current()->macAddress().manufacturer() << "'" << oendl;
odebug << "DEMO: Manufacturertest1 = '" << OManufacturerDB::instance()->lookupExt( "08:00:87" ) << "'" << oendl;
odebug << "DEMO: Manufacturertest2 = '" << OManufacturerDB::instance()->lookupExt( "E2:0C:0F" ) << "'" << oendl;
- odebug << "Demo: IPv4 Address is '" << it.current()->ipV4Address() << "'" << oendl;
+ odebug << "Demo: IPv4 Address is '" << it.current()->ipV4Address().toString() << "'" << oendl;
if ( it.current()->isWireless() )
{
OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() );
odebug << "DEMO: '" << iface->name() << "' seems to feature the wireless extensions." << oendl;
odebug << "DEMO: Current SSID is '" << iface->SSID() << "'" << oendl;
odebug << "DEMO: Antenna is tuned to '" << iface->frequency() << "', that is channel " << iface->channel() << "" << oendl;
//if ( iface->mode() == OWirelessNetworkInterface::adhoc )
//{
//odebug << "DEMO: Associated AP has MAC Address '" << iface->associatedAP().toString() << "'" << oendl;
//}
/*
// nickname
odebug << "DEMO: Current NickName is '" << iface->nickName() << "'" << oendl;
iface->setNickName( "MyNickName" );
if ( iface->nickName() != "MyNickName" )
odebug << "DEMO: Warning! Can't change nickname" << oendl;
else
odebug << "DEMO: Nickname change successful." << oendl;
/*
// operation mode
odebug << "DEMO: Current OperationMode is '" << iface->mode() << "'" << oendl;
iface->setMode( "adhoc" );
if ( iface->mode() != "adhoc" )
odebug << "DEMO: Warning! Can't change operation mode" << oendl;
else
odebug << "DEMO: Operation Mode change successful." << oendl;
// RF channel
odebug << "DEMO: Current Channel is '" << iface->channel() << "'" << oendl;
iface->setChannel( 1 );
if ( iface->channel() != 1 )
odebug << "DEMO: Warning! Can't change RF channel" << oendl;
else
odebug << "DEMO: RF channel change successful." << oendl;
iface->setMode( "managed" );
*/
/*
// network scan
OStationList* stations = iface->scanNetwork();
if ( stations )
{
odebug << "DEMO: # of stations around = " << stations->count() << "" << oendl;
OStation* station;
for ( station = stations->first(); station != 0; station = stations->next() )
{
odebug << "DEMO: station dump following..." << oendl;
station->dump();
}
}
else
{
odebug << "DEMO: Warning! Scan didn't work!" << oendl;
}
/*
// first some wrong calls to check if this is working
iface->setPrivate( "seppel", 10 );
iface->setPrivate( "monitor", 0 );
// now the real deal
iface->setPrivate( "monitor", 2, 2, 3 );
// trying to set hw address to 12:34:56:AB:CD:EF
/*
OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" );
iface->setUp( false );
iface->setMacAddress( addr );
iface->setUp( true );
odebug << "DEMO: MAC Address now is '" << iface->macAddress().toString() << "'" << oendl;
*/
// monitor test
odebug << "DEMO: current interface mode is '" << iface->mode() << "'" << oendl;
iface->setMode( "monitor" );
odebug << "DEMO: current interface mode is '" << iface->mode() << "'" << oendl;
sleep( 1 );
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp
index c8c494a..9c3e650 100644
--- a/libopie2/opienet/onetutils.cpp
+++ b/libopie2/opienet/onetutils.cpp
@@ -1,234 +1,247 @@
/*
                This file is part of the Opie Project
-
-              (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de>
- =.
+ =. (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; version 2 of the License.
     ._= =}       :
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <opie2/onetutils.h>
#include <opie2/onetwork.h>
#include <opie2/omanufacturerdb.h>
#include <net/if.h>
#include <assert.h>
#include <stdio.h>
namespace Opie {
namespace Net {
/*======================================================================================
* OMacAddress
*======================================================================================*/
// static initializer for broadcast and unknown MAC Adresses
const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast );
const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 };
const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown );
//TODO: Incorporate Ethernet Manufacturer database here! (inline or so)
OMacAddress::OMacAddress()
{
memcpy( _bytes, __unknown, 6 );
}
OMacAddress::OMacAddress( unsigned char* p )
{
memcpy( _bytes, p, 6 );
}
OMacAddress::OMacAddress( const unsigned char* p )
{
memcpy( _bytes, p, 6 );
}
OMacAddress::OMacAddress( struct ifreq& ifr )
{
memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 );
}
OMacAddress::~OMacAddress()
{
}
//#ifdef QT_NO_DEBUG
//inline
//#endif
const unsigned char* OMacAddress::native() const
{
return (const unsigned char*) &_bytes;
}
OMacAddress OMacAddress::fromString( const QString& str )
{
QString addr( str );
unsigned char buf[6];
bool ok = true;
int index = 14;
for ( int i = 5; i >= 0; --i )
{
buf[i] = addr.right( 2 ).toUShort( &ok, 16 );
if ( !ok ) return OMacAddress::unknown;
addr.truncate( index );
index -= 3;
}
return (const unsigned char*) &buf;
}
QString OMacAddress::toString( bool substitute ) const
{
QString manu;
manu.sprintf( "%.2X:%.2X:%.2X", _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff );
QString serial;
serial.sprintf( ":%.2X:%.2X:%.2X", _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff );
if ( !substitute ) return manu+serial;
// fallback - if no vendor is found, just use the number
QString textmanu = OManufacturerDB::instance()->lookup( manu );
return textmanu.isNull() ? manu+serial : textmanu+serial;
}
QString OMacAddress::manufacturer() const
{
return OManufacturerDB::instance()->lookupExt( toString() );
}
bool operator==( const OMacAddress &m1, const OMacAddress &m2 )
{
return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0;
}
/*======================================================================================
* OHostAddress
*======================================================================================*/
+OHostAddress::OHostAddress()
+ :QHostAddress()
+{
+}
+
+
+OHostAddress::OHostAddress( Q_UINT32 ip4Addr )
+ :QHostAddress( ip4Addr )
+{
+}
+
+
+OHostAddress::~OHostAddress()
+{
+}
/*======================================================================================
* OPrivateIOCTL
*======================================================================================*/
OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs )
:QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs )
{
}
OPrivateIOCTL::~OPrivateIOCTL()
{
}
int OPrivateIOCTL::numberGetArgs() const
{
return _getargs & IW_PRIV_SIZE_MASK;
}
int OPrivateIOCTL::typeGetArgs() const
{
return _getargs & IW_PRIV_TYPE_MASK >> 12;
}
int OPrivateIOCTL::numberSetArgs() const
{
return _setargs & IW_PRIV_SIZE_MASK;
}
int OPrivateIOCTL::typeSetArgs() const
{
return _setargs & IW_PRIV_TYPE_MASK >> 12;
}
void OPrivateIOCTL::invoke() const
{
( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl );
}
void OPrivateIOCTL::setParameter( int num, u_int32_t value )
{
u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name;
arglist[num] = value;
}
namespace Internal {
/*======================================================================================
* assorted functions
*======================================================================================*/
void dumpBytes( const unsigned char* data, int num )
{
printf( "Dumping %d bytes @ 0x%p", num, data );
printf( "-------------------------------------------\n" );
for ( int i = 0; i < num; ++i )
{
printf( "%02x ", data[i] );
if ( !((i+1) % 32) ) printf( "\n" );
}
printf( "\n\n" );
}
int stringToMode( const QString& mode )
{
if ( mode == "auto" ) return IW_MODE_AUTO;
else if ( mode == "adhoc" ) return IW_MODE_ADHOC;
else if ( mode == "managed" ) return IW_MODE_INFRA;
else if ( mode == "master" ) return IW_MODE_MASTER;
else if ( mode == "repeater" ) return IW_MODE_REPEAT;
else if ( mode == "secondary" ) return IW_MODE_SECOND;
else if ( mode == "monitor" ) return IW_MODE_MONITOR;
else assert( 0 );
}
QString modeToString( int mode )
{
switch ( mode )
{
case IW_MODE_AUTO: return "auto";
case IW_MODE_ADHOC: return "adhoc";
case IW_MODE_INFRA: return "managed";
case IW_MODE_MASTER: return "master";
case IW_MODE_REPEAT: return "repeater";
case IW_MODE_SECOND: return "second";
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h
index 25c9238..f08738c 100644
--- a/libopie2/opienet/onetutils.h
+++ b/libopie2/opienet/onetutils.h
@@ -1,191 +1,191 @@
/*
                This file is part of the Opie Project
-              (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
- =.
+ =. (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; version 2 of the License.
     ._= =}       :
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef ONETUTILS_H
#define ONETUTILS_H
#include <qdict.h>
#include <qmap.h>
#include <qstring.h>
#include <qhostaddress.h>
#include <qobject.h>
#include <sys/types.h>
struct ifreq;
namespace Opie {
namespace Net {
class OWirelessNetworkInterface;
/*======================================================================================
* OMacAddress
*======================================================================================*/
class OMacAddress
{
public:
// QString c'tor? -zecke
OMacAddress();
OMacAddress( unsigned char* );
OMacAddress( const unsigned char* );
OMacAddress( struct ifreq& );
~OMacAddress();
QString manufacturer() const;
QString toString( bool substitute = false ) const;
const unsigned char* native() const;
// no c'tor but this one why not make it a c'tor. it could also replace the others or is this the problem?
static OMacAddress fromString( const QString& );
public:
static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff
static const OMacAddress& unknown; // 44:44:44:44:44:44
private:
unsigned char _bytes[6];
friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
class Private;
Private *d;
};
bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
/*======================================================================================
* OHostAddress
*======================================================================================*/
class OHostAddress : public QHostAddress
{
- /*public:
+ public:
OHostAddress();
+ OHostAddress( Q_UINT32 ip4Addr );
~OHostAddress();
- */
+
private:
class Private;
Private *d;
};
/*======================================================================================
* ONetworkInterfaceDriverInfo
*======================================================================================*/
class ONetworkInterfaceDriverInfo
{
public:
ONetworkInterfaceDriverInfo( const QString& name = "<unknown>",
const QString& version = "<unknown>",
const QString& firmware = "<unknown>",
const QString& bus = "<unknown>" ) :
_name( name ), _version( version ), _firmware( firmware ), _bus( bus ) { };
~ONetworkInterfaceDriverInfo() { };
QString name() const { return _name; };
QString version() const { return _version; };
QString firmware() const { return _firmware; };
QString bus() const { return _bus; };
private:
const QString _name;
const QString _version;
const QString _firmware;
const QString _bus;
};
/*======================================================================================
* OPrivateIOCTL
*======================================================================================*/
class OPrivateIOCTL : public QObject
{
public:
OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs );
~OPrivateIOCTL();
int numberGetArgs() const;
int typeGetArgs() const;
int numberSetArgs() const;
int typeSetArgs() const;
// FIXME return int? as ::ioctl does? -zecke
void invoke() const;
void setParameter( int, u_int32_t );
private:
u_int32_t _ioctl;
u_int16_t _getargs;
u_int16_t _setargs;
class Private;
Private *d;
};
/*======================================================================================
* Miscellaneous
*======================================================================================*/
namespace Internal {
void dumpBytes( const unsigned char* data, int num );
QString modeToString( int );
int stringToMode( const QString& );
}
}
}
#define IW_PRIV_TYPE_MASK 0x7000
#define IW_PRIV_TYPE_NONE 0x0000
#define IW_PRIV_TYPE_BYTE 0x1000
#define IW_PRIV_TYPE_CHAR 0x2000
#define IW_PRIV_TYPE_INT 0x4000
#define IW_PRIV_TYPE_FLOAT 0x5000
#define IW_PRIV_TYPE_ADDR 0x6000
#define IW_PRIV_SIZE_FIXED 0x0800
#define IW_PRIV_SIZE_MASK 0x07FF
#define IW_HEADER_TYPE_NULL 0 /* Not available */
#define IW_HEADER_TYPE_CHAR 2 /* char [IFNAMSIZ] */
#define IW_HEADER_TYPE_UINT 4 /* __u32 */
#define IW_HEADER_TYPE_FREQ 5 /* struct iw_freq */
#define IW_HEADER_TYPE_ADDR 6 /* struct sockaddr */
#define IW_HEADER_TYPE_POINT 8 /* struct iw_point */
#define IW_HEADER_TYPE_PARAM 9 /* struct iw_param */
#define IW_HEADER_TYPE_QUAL 10 /* struct iw_quality */
#define IW_EV_POINT_OFF (((char *) &(((struct iw_point *) NULL)->length)) - \
(char *) NULL)
#ifndef ARPHRD_IEEE80211
#define ARPHRD_IEEE80211 801
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 1deb051..0649ca2 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -1,423 +1,404 @@
/*
                This file is part of the Opie Project
-              Copyright (C) 2003-2005 by Michael 'Mickey' Lauer <mickey@Vanille.de>
- =.
+ =. Copyright (C) 2003-2005 by Michael 'Mickey' Lauer <mickey@Vanille.de>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; version 2 of the License.
     ._= =}       :
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* OPIE */
#include <opie2/onetwork.h>
#include <opie2/ostation.h>
#include <opie2/odebug.h>
using namespace Opie::Core;
/* QT */
#include <qfile.h>
#include <qtextstream.h>
#include <qapplication.h>
/* STD */
#include <assert.h>
#include <arpa/inet.h>
#include <errno.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <net/if_arp.h>
#include <net/ethernet.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/types.h>
#include <linux/sockios.h>
#define u64 __u64
#define u32 __u32
#define u16 __u16
#define u8 __u8
#include <linux/ethtool.h>
#ifndef NODEBUG
#include <opie2/odebugmapper.h>
using namespace Opie::Net::Internal;
DebugMapper* debugmapper = new DebugMapper();
#endif
/*======================================================================================
* ONetwork
*======================================================================================*/
namespace Opie {
namespace Net {
ONetwork* ONetwork::_instance = 0;
ONetwork::ONetwork()
{
odebug << "ONetwork::ONetwork()" << oendl;
odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl;
synchronize();
}
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" );
bool hasFile = f.open( IO_ReadOnly );
if ( !hasFile )
{
odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl;
return;
}
QTextStream s( &f );
s.readLine();
s.readLine();
while ( !s.atEnd() )
{
s >> str;
str.truncate( str.find( ':' ) );
odebug << "ONetwork: found interface '" << str << "'" << oendl;
if ( str.startsWith( "wifi" ) )
{
odebug << "ONetwork: ignoring hostap control interface" << oendl;
s.readLine();
continue;
}
ONetworkInterface* iface = 0;
if ( isWirelessInterface( str ) )
{
iface = new OWirelessNetworkInterface( this, (const char*) str );
odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl;
}
else
{
iface = new ONetworkInterface( this, (const char*) str );
}
_interfaces.insert( str, iface );
s.readLine();
}
}
short ONetwork::wirelessExtensionCompileVersion()
{
return WIRELESS_EXT;
}
int ONetwork::count() const
{
return _interfaces.count();
}
ONetworkInterface* ONetwork::interface( const QString& iface ) const
{
return _interfaces[iface];
}
ONetwork* ONetwork::instance()
{
if ( !_instance ) _instance = new ONetwork();
return _instance;
}
ONetwork::InterfaceIterator ONetwork::iterator() const
{
return ONetwork::InterfaceIterator( _interfaces );
}
bool ONetwork::isPresent( const char* name ) const
{
int sfd = socket( AF_INET, SOCK_STREAM, 0 );
struct ifreq ifr;
memset( &ifr, 0, sizeof( struct ifreq ) );
strcpy( (char*) &ifr.ifr_name, name );
int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr );
return result != -1;
}
bool ONetwork::isWirelessInterface( const char* name ) const
{
int sfd = socket( AF_INET, SOCK_STREAM, 0 );
struct iwreq iwr;
memset( &iwr, 0, sizeof( struct iwreq ) );
strcpy( (char*) &iwr.ifr_name, name );
int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
return result != -1;
}
/*======================================================================================
* ONetworkInterface
*======================================================================================*/
ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
:QObject( parent, name ),
_sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
{
odebug << "ONetworkInterface::ONetworkInterface()" << oendl;
init();
}
struct ifreq& ONetworkInterface::ifr() const
{
return _ifr;
}
void ONetworkInterface::init()
{
odebug << "ONetworkInterface::init()" << oendl;
-
memset( &_ifr, 0, sizeof( struct ifreq ) );
if ( _sfd == -1 )
{
odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl;
return;
}
}
bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
{
#ifndef NODEBUG
int result = ::ioctl( _sfd, call, &ifreq );
if ( result == -1 )
odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call )
<< "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl;
else
odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call )
<< "' - Status: Ok." << oendl;
return ( result != -1 );
#else
return ::ioctl( _sfd, call, &ifreq ) != -1;
#endif
}
bool ONetworkInterface::ioctl( int call ) const
{
strcpy( _ifr.ifr_name, name() );
return ioctl( call, _ifr );
}
bool ONetworkInterface::isLoopback() const
{
ioctl( SIOCGIFFLAGS );
return _ifr.ifr_flags & IFF_LOOPBACK;
}
bool ONetworkInterface::setUp( bool b )
{
ioctl( SIOCGIFFLAGS );
if ( b ) _ifr.ifr_flags |= IFF_UP;
else _ifr.ifr_flags &= (~IFF_UP);
return ioctl( SIOCSIFFLAGS );
}
bool ONetworkInterface::isUp() const
{
ioctl( SIOCGIFFLAGS );
return _ifr.ifr_flags & IFF_UP;
}
void ONetworkInterface::setIPV4Address( const QHostAddress& addr )
{
struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
sa->sin_family = AF_INET;
sa->sin_port = 0;
sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
ioctl( SIOCSIFADDR );
}
-QString ONetworkInterface::ipV4Address() const
+OHostAddress ONetworkInterface::ipV4Address() const
{
- if ( ioctl( SIOCGIFADDR ) )
- {
- struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
- //FIXME: Use QHostAddress here
- return QString( inet_ntoa( sa->sin_addr ) );
- }
- else
- return "<unknown>";
-
+ struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
+ return ioctl( SIOCGIFADDR ) ? OHostAddress( ntohl( sa->sin_addr.s_addr ) ) : OHostAddress();
}
void ONetworkInterface::setMacAddress( const OMacAddress& addr )
{
_ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 );
ioctl( SIOCSIFHWADDR );
}
OMacAddress ONetworkInterface::macAddress() const
{
if ( ioctl( SIOCGIFHWADDR ) )
{
return OMacAddress( _ifr );
}
else
{
return OMacAddress::unknown;
}
}
void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr )
{
struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
sa->sin_family = AF_INET;
sa->sin_port = 0;
sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
ioctl( SIOCSIFNETMASK );
}
-QString ONetworkInterface::ipV4Netmask() const
+OHostAddress ONetworkInterface::ipV4Netmask() const
{
- if ( ioctl( SIOCGIFNETMASK ) )
- {
- struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
- //FIXME: Use QHostAddress here
- return QString( inet_ntoa( sa->sin_addr ) );
- }
- else
- return "<unknown>";
+ struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
+ return ioctl( SIOCGIFNETMASK ) ? OHostAddress( ntohl( sa->sin_addr.s_addr ) ) : OHostAddress();
}
int ONetworkInterface::dataLinkType() const
{
if ( ioctl( SIOCGIFHWADDR ) )
{
return _ifr.ifr_hwaddr.sa_family;
}
else
{
return -1;
}
}
void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
{
_mon = m;
odebug << "ONetwork::setMonitoring(): Installed monitoring driver '" << m->name() << "' on interface '" << name() << "'" << oendl;
}
OMonitoringInterface* ONetworkInterface::monitoring() const
{
return _mon;
}
ONetworkInterface::~ONetworkInterface()
{
odebug << "ONetworkInterface::~ONetworkInterface()" << oendl;
if ( _sfd != -1 ) ::close( _sfd );
}
bool ONetworkInterface::setPromiscuousMode( bool b )
{
ioctl( SIOCGIFFLAGS );
if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
else _ifr.ifr_flags &= (~IFF_PROMISC);
return ioctl( SIOCSIFFLAGS );
}
bool ONetworkInterface::promiscuousMode() const
{
ioctl( SIOCGIFFLAGS );
return _ifr.ifr_flags & IFF_PROMISC;
}
bool ONetworkInterface::isWireless() const
{
return ioctl( SIOCGIWNAME );
}
ONetworkInterfaceDriverInfo ONetworkInterface::driverInfo() const
{
struct ethtool_drvinfo info;
info.cmd = ETHTOOL_GDRVINFO;
_ifr.ifr_data = (caddr_t) &info;
return ioctl( SIOCETHTOOL ) ? ONetworkInterfaceDriverInfo( info.driver, info.version, info.fw_version, info.bus_info) : ONetworkInterfaceDriverInfo();
}
/*======================================================================================
* OChannelHopper
*======================================================================================*/
OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
:QObject( 0, "Mickey's funky hopper" ),
_iface( iface ), _interval( 0 ), _tid( 0 )
{
int _maxChannel = iface->channels();
// generate fancy hopping sequence honoring the device capabilities
if ( _maxChannel >= 1 ) _channels.append( 1 );
if ( _maxChannel >= 7 ) _channels.append( 7 );
if ( _maxChannel >= 13 ) _channels.append( 13 );
if ( _maxChannel >= 2 ) _channels.append( 2 );
if ( _maxChannel >= 8 ) _channels.append( 8 );
if ( _maxChannel >= 3 ) _channels.append( 3 );
if ( _maxChannel >= 14 ) _channels.append( 14 );
if ( _maxChannel >= 9 ) _channels.append( 9 );
if ( _maxChannel >= 4 ) _channels.append( 4 );
if ( _maxChannel >= 10 ) _channels.append( 10 );
if ( _maxChannel >= 5 ) _channels.append( 5 );
if ( _maxChannel >= 11 ) _channels.append( 11 );
if ( _maxChannel >= 6 ) _channels.append( 6 );
if ( _maxChannel >= 12 ) _channels.append( 12 );
//FIXME: Add 802.11a/g channels
_channel = _channels.begin();
}
OChannelHopper::~OChannelHopper()
@@ -454,193 +435,201 @@ void OChannelHopper::setInterval( int interval )
if ( _interval )
killTimer( _tid );
_tid = 0;
_interval = interval;
if ( _interval )
{
_tid = startTimer( interval );
}
}
int OChannelHopper::interval() const
{
return _interval;
}
/*======================================================================================
* OWirelessNetworkInterface
*======================================================================================*/
OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name )
:ONetworkInterface( parent, name ), _hopper( 0 )
{
odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl;
init();
}
OWirelessNetworkInterface::~OWirelessNetworkInterface()
{
}
struct iwreq& OWirelessNetworkInterface::iwr() const
{
return _iwr;
}
void OWirelessNetworkInterface::init()
{
odebug << "OWirelessNetworkInterface::init()" << oendl;
memset( &_iwr, 0, sizeof( struct iwreq ) );
buildInformation();
buildPrivateList();
dumpInformation();
}
bool OWirelessNetworkInterface::isAssociated() const
{
//FIXME: handle different modes
return !(associatedAP() == OMacAddress::unknown);
}
void OWirelessNetworkInterface::setAssociatedAP( const OMacAddress& mac ) const
{
_iwr.u.ap_addr.sa_family = ARPHRD_ETHER;
::memcpy(_iwr.u.ap_addr.sa_data, mac.native(), ETH_ALEN);
wioctl( SIOCSIWAP );
}
OMacAddress OWirelessNetworkInterface::associatedAP() const
{
if ( ioctl( SIOCGIWAP ) )
return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0];
else
return OMacAddress::unknown;
}
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".
//ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
//ML: _too much_ space. This is damn shitty crap *sigh*
//ML: We allocate a large memory region in RAM and check whether the
//ML: driver pollutes this extra space. The complaint will be made on stdout,
//ML: so please forward this...
struct iwreq wrq;
int len = sizeof( struct iw_range )*2;
char buffer[len];
memset( buffer, 0, len );
memcpy( wrq.ifr_name, name(), IFNAMSIZ);
wrq.u.data.pointer = (caddr_t) buffer;
wrq.u.data.length = sizeof buffer;
wrq.u.data.flags = 0;
- if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
+ int result = ::ioctl( _sfd, SIOCGIWRANGE, &wrq );
+ if ( result == -1 )
+ {
+ owarn << "OWirelessNetworkInterface::buildInformation(): SIOCGIWRANGE failed (" << strerror( errno ) << ") - retrying with smaller buffer..." << oendl;
+ wrq.u.data.length = sizeof( struct iw_range );
+ result = ::ioctl( _sfd, SIOCGIWRANGE, &wrq );
+ }
+
+ if ( result == -1 )
{
owarn << "OWirelessNetworkInterface::buildInformation(): Can't get driver information (" << strerror( errno ) << ") - using default values." << oendl;
_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
_channels.insert( 2432, 5 ); // 2.432 GHz
_channels.insert( 2437, 6 ); // 2.437 GHz
_channels.insert( 2442, 7 ); // 2.442 GHz
_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>
int max = 0;
for ( int r = sizeof( struct iw_range ); r < len; r++ )
if (buffer[r] != 0)
max = r;
if (max > 0)
{
owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name()
<< "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl;
}
// </check if the driver overwrites stuff>
struct iw_range range;
memcpy( &range, buffer, sizeof range );
odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl;
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 );
odebug << "OWirelessNetworkInterface::buildInformation: Adding frequency " << freq << " as channel " << i+1 << oendl;
_channels.insert( freq, i+1 );
}
}
memcpy( &_range, buffer, sizeof( struct iw_range ) );
odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl;
}
short OWirelessNetworkInterface::wirelessExtensionDriverVersion() const
{
return _range.we_version_compiled;
}
void OWirelessNetworkInterface::buildPrivateList()
{
odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl;
struct iw_priv_args priv[IW_MAX_PRIV_DEF];
_iwr.u.data.pointer = (char*) &priv;
_iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
_iwr.u.data.flags = 0;
if ( !wioctl( SIOCGIWPRIV ) )
{
owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information (" << strerror( errno ) << ")." << oendl;
return;
}
for ( int i = 0; i < _iwr.u.data.length; ++i )
{
new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
}
odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl;
}
void OWirelessNetworkInterface::dumpInformation() const
{
odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl;
odebug << " - driver's idea of maximum throughput is " << _range.throughput
<< " bps = " << ( _range.throughput / 8 ) << " byte/s = " << ( _range.throughput / 8 / 1024 )
<< " Kb/s = " << QString().sprintf("%f.2", float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 )
<< " Mb/s" << oendl;
odebug << " - driver for '" << name() << "' (V" << _range.we_version_source
<< ") has been compiled against WE V" << _range.we_version_compiled << oendl;
if ( _range.we_version_compiled != WIRELESS_EXT )
{
owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl;
}
odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl;
}
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index f0c4450..b13c7a3 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -1,100 +1,99 @@
/*
                This file is part of the Opie Project
-              Copyright (C) 2003-2005 by Michael 'Mickey' Lauer <mickey@Vanille.de>
- =.
+ =. Copyright (C) 2003-2005 by Michael 'Mickey' Lauer <mickey@Vanille.de>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; version 2 of the License.
     ._= =}       :
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef ONETWORK_H
#define ONETWORK_H
/* OPIE */
#include <opie2/onetutils.h>
#include <opie2/ostation.h>
/* QT */
#include <qvaluelist.h>
#include <qdict.h>
#include <qmap.h>
#include <qobject.h>
#include <qhostaddress.h>
/* STD */
// hacky workarounds until we have a true user space wireless.h
#include <net/if.h>
#define _LINUX_IF_H
#include <linux/wireless.h>
#ifndef IW_MAX_PRIV_DEF
#define IW_MAX_PRIV_DEF 128
#endif
namespace Opie {
namespace Net {
class ONetworkInterface;
class OWirelessNetworkInterface;
class OChannelHopper;
class OMonitoringInterface;
/*======================================================================================
* ONetwork
*======================================================================================*/
/**
* @brief A container class for all network interfaces
*
* This class provides access to all available network interfaces of your computer.
*
* @author Michael 'Mickey' Lauer <mickey@vanille.de>
*/
class ONetwork : public QObject
{
Q_OBJECT
public:
typedef QDict<ONetworkInterface> InterfaceMap;
typedef QDictIterator<ONetworkInterface> InterfaceIterator;
public:
/**
* @returns the number of available interfaces
*/
int count() const;
/**
* @returns a pointer to the (one and only) @ref ONetwork instance.
*/
static ONetwork* instance();
/**
* @returns an iterator usable for iterating through all network interfaces.
*/
InterfaceIterator iterator() const;
/**
* @returns true, if the @a interface is present.
*/
bool isPresent( const char* interface ) const;
/**
* @returns true, if the @a interface supports the wireless extension protocol.
*/
bool isWirelessInterface( const char* interface ) const;
@@ -105,212 +104,212 @@ class ONetwork : public QObject
ONetworkInterface* interface( const QString& interface ) const;
/**
* @internal Rebuild the internal interface database
* @note Sometimes it might be useful to call this from client code,
* e.g. after issuing a cardctl insert
*/
void synchronize();
/**
* @returns the wireless extension version used at compile time.
**/
static short wirelessExtensionCompileVersion();
protected:
ONetwork();
private:
static ONetwork* _instance;
InterfaceMap _interfaces;
class Private;
Private *d;
};
/*======================================================================================
* ONetworkInterface
*======================================================================================*/
/**
* @brief A network interface wrapper.
*
* This class provides a wrapper for a network interface. All the cumbersume details of
* Linux ioctls are hidden under a convenient high-level interface.
* @warning Most of the setting methods contained in this class require the appropriate
* process permissions to work.
*
* @author Michael 'Mickey' Lauer <mickey@vanille.de>
*/
class ONetworkInterface : public QObject
{
friend class OMonitoringInterface;
friend class OCiscoMonitoringInterface;
friend class OWlanNGMonitoringInterface;
friend class OHostAPMonitoringInterface;
friend class OOrinocoMonitoringInterface;
public:
/**
* Constructor. Normally you don't create @ref ONetworkInterface objects yourself,
* but access them via @ref ONetwork::interface().
*/
ONetworkInterface( QObject* parent, const char* name );
/**
* Destructor.
*/
virtual ~ONetworkInterface();
/**
* Associates a @a monitoring interface with this network interface.
* @note This is currently only useful with @ref OWirelessNetworkInterface objects.
*/
void setMonitoring( OMonitoringInterface* monitoring );
/**
* @returns the currently associated monitoring interface or 0, if no monitoring is associated.
*/
OMonitoringInterface* monitoring() const;
/**
* Setting an interface to promiscuous mode enables the device to receive
* all packets on the shared medium - as opposed to packets which are addressed to this interface.
*/
bool setPromiscuousMode( bool );
/**
* @returns true if the interface is set to promiscuous mode.
*/
bool promiscuousMode() const;
/**
* Setting an interface to up enables it to receive packets.
*/
bool setUp( bool );
/**
* @returns true if the interface is up.
*/
bool isUp() const;
/**
* @returns true if the interface is a loopback interface.
*/
bool isLoopback() const;
/**
* @returns true if the interface is featuring supports the wireless extension protocol.
*/
bool isWireless() const;
/**
* Associate the IP address @ addr with the interface.
*/
void setIPV4Address( const QHostAddress& addr );
/**
* @returns the IPv4 address associated with the interface.
*/
- QString ipV4Address() const; //TODO: make this return an OHostAddress
+ OHostAddress ipV4Address() const;
/**
* Associate the MAC address @a addr with the interface.
* @note It can be necessary to shut down the interface prior to calling this method.
* @note This operation needs root privileges
* @warning This is not supported by all drivers.
*/
void setMacAddress( const OMacAddress& addr );
/**
* @returns the MAC address associated with the interface.
*/
OMacAddress macAddress() const;
/**
* Associate the IPv4 @a netmask with the interface.
*/
void setIPV4Netmask( const QHostAddress& netmask );
/**
* @returns the IPv4 netmask associated with the interface.
*/
- QString ipV4Netmask() const; //TODO: make this return an OHostAddress
+ OHostAddress ipV4Netmask() const;
/**
* @returns the data link type currently associated with the interface.
* @see #include <net/if_arp.h> for possible values.
*/
int dataLinkType() const;
/**
* @returns a ONetworkInterfaceDriverInfo driver information block
* @note This operation needs root privileges
* @warning This is not supported by all drivers
*/
ONetworkInterfaceDriverInfo driverInfo() const;
protected:
const int _sfd;
mutable ifreq _ifr;
OMonitoringInterface* _mon;
protected:
struct ifreq& ifr() const;
virtual void init();
bool ioctl( int call ) const;
bool ioctl( int call, struct ifreq& ) const;
private:
class Private;
Private *d;
};
/*======================================================================================
* OChannelHopper
*======================================================================================*/
/**
* @brief A radio frequency channel hopper.
*
* This class provides a channel hopper for radio frequencies. A channel hopper frequently
* changes the radio frequency channel of its associated @ref OWirelessNetworkInterface.
* This is necessary when in monitoring mode and scanning for other devices, because
* the radio frequency hardware can only detect packets sent on the same frequency.
*
* @author Michael 'Mickey' Lauer <mickey@vanille.de>
*/
class OChannelHopper : public QObject
{
Q_OBJECT
public:
/**
* Constructor.
*/
OChannelHopper( OWirelessNetworkInterface* );
/**
* Destructor.
*/
virtual ~OChannelHopper();
/**
* @returns true, if the channel hopper is hopping channels
*/
bool isActive() const;
/**
* @returns the last hopped channel
*/
int channel() const;
/**
* Set the channel hopping @a interval.
* An interval of 0 deactivates the channel hopper.
*/
void setInterval( int interval );
/**
* @returns the channel hopping interval
*/
int interval() const;
signals:
/**
* This signal is emitted right after the channel hopper performed a hop
*/
void hopped( int );
protected:
virtual void timerEvent( QTimerEvent* );
private:
OWirelessNetworkInterface* _iface;
int _interval;
int _tid;
QValueList<int> _channels;
QValueList<int>::Iterator _channel;
class Private;
Private *d;
};
/*======================================================================================
* OWirelessNetworkInterface
*======================================================================================*/
diff --git a/noncore/applets/networkapplet/networkapplet.cpp b/noncore/applets/networkapplet/networkapplet.cpp
index 534a8d0..bd6ca66 100644
--- a/noncore/applets/networkapplet/networkapplet.cpp
+++ b/noncore/applets/networkapplet/networkapplet.cpp
@@ -1,200 +1,200 @@
/*
                This file is part of the Opie Project
=. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "networkapplet.h"
/* OPIE */
#include <opie2/odebug.h>
#include <opie2/onetwork.h>
#include <opie2/otaskbarapplet.h>
#include <qpe/applnk.h>
#include <qpe/resource.h>
using namespace Opie::Core;
using namespace Opie::Ui;
using namespace Opie::Net;
/* QT */
#include <qpainter.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qobjectlist.h>
/* STD */
#include <assert.h>
IfaceUpDownButton::IfaceUpDownButton( QWidget* parent, const char* name )
:QToolButton( parent, name )
{
_iface = ONetwork::instance()->interface( name );
assert( _iface );
setToggleButton( true );
//setAutoRaise( true );
setOnIconSet( QIconSet( Resource::loadPixmap( "up" ) ) );
setOffIconSet( QIconSet( Resource::loadPixmap( "down" ) ) );
setOn( _iface->isUp() );
//setFixedWidth( 16 );
connect( this, SIGNAL( clicked() ), this, SLOT( clicked() ) );
}
IfaceUpDownButton::~IfaceUpDownButton()
{
}
void IfaceUpDownButton::clicked()
{
_iface->setUp( isOn() );
setOn( _iface->isUp() ); // it might not have worked...
repaint();
}
IfaceIPAddress::IfaceIPAddress( QWidget* parent, const char* name )
:QLineEdit( parent, name )
{
setFont( QFont( "fixed" ) );
_iface = ONetwork::instance()->interface( name );
setFixedWidth( 105 );
- setText( _iface->ipV4Address() );
+ setText( _iface->ipV4Address().toString() );
connect( this, SIGNAL( returnPressed() ), this, SLOT( returnPressed() ) );
}
IfaceIPAddress::~IfaceIPAddress()
{
}
void IfaceIPAddress::returnPressed()
{
QHostAddress a;
a.setAddress( text() );
QHostAddress mask;
- mask.setAddress( _iface->ipV4Netmask() ); // setIPV4Address destroys the netmask...
+ mask.setAddress( _iface->ipV4Netmask().toString() ); // setIPV4Address destroys the netmask...
_iface->setIPV4Address( a );
_iface->setIPV4Netmask( mask ); // recover the old netmask
- setText( _iface->ipV4Address() );
+ setText( _iface->ipV4Address().toString() );
repaint();
}
NetworkAppletControl::NetworkAppletControl( OTaskbarApplet* parent, const char* name )
:QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), l(0)
{
setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
l = new QVBoxLayout( this, 4, 2 );
}
void NetworkAppletControl::build()
{
ONetwork::InterfaceIterator it = ONetwork::instance()->iterator();
while ( it.current() )
{
QHBoxLayout* h = new QHBoxLayout( l );
QLabel* symbol = new QLabel( this );
symbol->setPixmap( Resource::loadPixmap( guessDevice( it.current() ) ) );
h->addWidget( symbol );
symbol->show();
QLabel* name = new QLabel( it.current()->name(), this );
name->setFixedWidth( 35 );
h->addWidget( name );
name->show();
IfaceIPAddress* ip = new IfaceIPAddress( this, it.current()->name() );
h->addWidget( ip );
ip->show();
IfaceUpDownButton* tb = new IfaceUpDownButton( this, it.current()->name() );
tb->show();
h->addWidget( tb );
++it;
}
}
NetworkAppletControl::~NetworkAppletControl()
{
}
QString NetworkAppletControl::guessDevice( ONetworkInterface* iface )
{
if ( iface->isWireless() )
return "networksettings/wlan";
if ( iface->isLoopback() )
return "networksettings/lo";
if ( QString( iface->name() ).contains( "usb" ) )
return "networksettings/usb";
if ( QString( iface->name() ).contains( "ir" ) )
return "networksettings/irda";
//TODO: Insert neat symbol and check for tunnel devices
return "networksettings/lan";
}
void NetworkAppletControl::showEvent( QShowEvent* e )
{
odebug << "showEvent" << oendl;
build();
QWidget::showEvent( e );
}
void NetworkAppletControl::hideEvent( QHideEvent* e )
{
odebug << "hideEvent" << oendl;
QWidget::hideEvent( e );
delete l;
// delete all child widgets from this frame
QObjectList* list = const_cast<QObjectList*>( children() );
QObjectListIt it(*list);
QObject* obj;
while ( (obj=it.current()) )
{
++it;
delete obj;
}
list = const_cast<QObjectList*>( children() );
if ( list )
owarn << "D'oh! We still have " << list->count() << " children..." << oendl;
// renew layout
l = new QVBoxLayout( this, 4, 2 );
diff --git a/noncore/net/opiestumbler/opiestumbler.cpp b/noncore/net/opiestumbler/opiestumbler.cpp
index 8dedd67..f231fca 100644
--- a/noncore/net/opiestumbler/opiestumbler.cpp
+++ b/noncore/net/opiestumbler/opiestumbler.cpp
@@ -243,106 +243,106 @@ void OpieStumbler::slotShowDetails()
void OpieStumbler::slotLoadManufacturers()
{
m_db = Opie::Net::OManufacturerDB::instance();
}
QString OpieStumbler::manufacturer( const QString &mac, bool extended )
{
QString retval;
if ( m_db )
if ( extended )
retval = m_db->lookupExt(mac);
else
retval = m_db->lookup(mac);
if ( retval.isEmpty() )
retval = tr("Unknown");
return retval;
}
void OpieStumbler::slotJoinNetwork()
{
slotStopScanning();
OWirelessNetworkInterface *wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_interface));
if( !wiface )
return;
QListIterator<StumblerStation> it(m_stationsHistory);
for(; it.current() && it.current()->st->macAddress.toString() != m_mac; ++it );
if( !it.current() )
return;
Opie::Net::OStation *station = it.current()->st;
odebug << "Bringing interface down" << oendl;
wiface->setUp(FALSE);
odebug << "Setting mode to " << (station->type == "adhoc" ? "adhoc" : "managed") << oendl;
wiface->setMode(station->type == "adhoc" ? "adhoc" : "managed" );
odebug << "Setting channel to " << station->channel << oendl;
wiface->setChannel(station->channel);
odebug << "Setting SSID to " << station->ssid << oendl;
wiface->setSSID(station->ssid);
wiface->commit();
odebug << "Bringing interface up" << oendl;
wiface->setUp(TRUE);
//Wait 5 sec for association
QTimer::singleShot(5000, this, SLOT(slotAssociated()));
}
void OpieStumbler::slotAssociated()
{
OWirelessNetworkInterface *wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_interface));
if( !wiface )
return;
if (!wiface->isAssociated()) {
Global::statusMessage(tr("Could not Join"));
return;
}
Global::statusMessage(tr("Joined"));
if(m_proc) {
m_proc->kill();
delete m_proc;
}
m_proc = new Opie::Core::OProcess(this);
*m_proc << "udhcpc" << "-f" << "-n" << "-i" << m_interface;
m_proc->start(Opie::Core::OProcess::DontCare);
QTimer::singleShot(5000, this, SLOT(slotCheckDHCP()));
}
void OpieStumbler::slotCheckDHCP()
{
if(!m_proc->isRunning()) {
Global::statusMessage(tr("Could not Obtain an Address"));
delete m_proc;
m_proc = NULL;
return;
}
m_listCurrent->show();
OWirelessNetworkInterface *wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_interface));
- Global::statusMessage(tr("Obtained IP ") + wiface->ipV4Address());
+ Global::statusMessage(tr("Obtained IP ") + wiface->ipV4Address().toString());
}