-rw-r--r-- | libopie2/opiecore/oglobalsettings.cpp | 6 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 3 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 8 |
3 files changed, 13 insertions, 4 deletions
diff --git a/libopie2/opiecore/oglobalsettings.cpp b/libopie2/opiecore/oglobalsettings.cpp index 184ee69..1799529 100644 --- a/libopie2/opiecore/oglobalsettings.cpp +++ b/libopie2/opiecore/oglobalsettings.cpp @@ -1,547 +1,547 @@ /* This file is part of the Opie Project Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> Inspired by the KDE globalsettings which are Copyright (C) 2000 David Faure <faure@kde.org> =. .=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. */ /* OPIE */ #include <opie2/oglobalsettings.h> #include <opie2/oconfig.h> #include <opie2/oglobal.h> /* QT */ #include <qdir.h> #include <qpixmap.h> #include <qfontinfo.h> /* UNIX */ #include <stdlib.h> QString* OGlobalSettings::s_desktopPath = 0; QString* OGlobalSettings::s_autostartPath = 0; QString* OGlobalSettings::s_trashPath = 0; QString* OGlobalSettings::s_documentPath = 0; QFont *OGlobalSettings::_generalFont = 0; QFont *OGlobalSettings::_fixedFont = 0; QFont *OGlobalSettings::_toolBarFont = 0; QFont *OGlobalSettings::_menuFont = 0; QFont *OGlobalSettings::_windowTitleFont = 0; QFont *OGlobalSettings::_taskbarFont = 0; QColor *OGlobalSettings::OpieGray = 0; QColor *OGlobalSettings::OpieHighlight = 0; QColor *OGlobalSettings::OpieAlternate = 0; OGlobalSettings::OMouseSettings *OGlobalSettings::s_mouseSettings = 0; //FIXME: Add manipulators to the accessors int OGlobalSettings::dndEventDelay() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, "General" ); return c->readNumEntry("DndDelay", 2); } bool OGlobalSettings::singleClick() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, "OPIE" ); return c->readBoolEntry("SingleClick", OPIE_DEFAULT_SINGLECLICK); } bool OGlobalSettings::insertTearOffHandle() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, "OPIE" ); return c->readBoolEntry("InsertTearOffHandle", OPIE_DEFAULT_INSERTTEAROFFHANDLES); } bool OGlobalSettings::changeCursorOverIcon() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, "OPIE" ); return c->readBoolEntry("ChangeCursor", OPIE_DEFAULT_CHANGECURSOR); } bool OGlobalSettings::visualActivate() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, "OPIE" ); return c->readBoolEntry("VisualActivate", OPIE_DEFAULT_VISUAL_ACTIVATE); } unsigned int OGlobalSettings::visualActivateSpeed() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, "OPIE" ); return c->readNumEntry( "VisualActivateSpeed", OPIE_DEFAULT_VISUAL_ACTIVATE_SPEED ); } int OGlobalSettings::autoSelectDelay() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, "OPIE" ); return c->readNumEntry("AutoSelectDelay", OPIE_DEFAULT_AUTOSELECTDELAY); } OGlobalSettings::Completion OGlobalSettings::completionMode() { int completion; OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, "General" ); completion = c->readNumEntry("completionMode", -1); if ((completion < (int) CompletionNone) || (completion > (int) CompletionPopupAuto)) { completion = (int) CompletionPopup; // Default } return (Completion) completion; } bool OGlobalSettings::showContextMenusOnPress () { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs (c, "ContextMenus"); return cgs.config()->readBoolEntry("ShowOnPress", true); } int OGlobalSettings::contextMenuKey () { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs (c, "Shortcuts"); //OShortcut cut (cgs.config()->readEntry ("PopupMenuContext", "Menu")); //return cut.keyCodeQt(); return 0; // FIXME } OGlobalSettings::Debug OGlobalSettings::debugMode() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, "General" ); int debug = c->readNumEntry( "debugMode", -1 ); if ( (debug < (int) DebugNone) || (debug > (int) DebugSocket) ) { debug = (int) DebugStdErr; // Default } return (Debug) debug; } QString OGlobalSettings::debugOutput() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, "General" ); QString deflt = QString::null; switch( debugMode() ) { case DebugNone: break; // no additional information needed case DebugFiles: deflt = "/var/log/opiedebug.log"; break; // file to save output in case DebugMsgBox: break; // no additional information needed case DebugStdErr: break; // no additional information needed case DebugSysLog: break; // no additional information needed case DebugSocket: deflt = "127.0.0.1:8913"; break; // address to send packets to } return c->readEntry( "debugOutput"+ QString::number(debugMode()), deflt ); } QColor OGlobalSettings::toolBarHighlightColor() { initColors(); OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("Toolbar style") ); return c->readColorEntry("HighlightColor", OpieHighlight); } QColor OGlobalSettings::inactiveTitleColor() { if (!OpieGray) OpieGray = new QColor(220, 220, 220); OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); return c->readColorEntry( "inactiveBackground", OpieGray ); } QColor OGlobalSettings::inactiveTextColor() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); return c->readColorEntry( "inactiveForeground", &Qt::darkGray ); } QColor OGlobalSettings::activeTitleColor() { initColors(); OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); return c->readColorEntry( "activeBackground", OpieHighlight); } QColor OGlobalSettings::activeTextColor() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); return c->readColorEntry( "activeForeground", &Qt::white ); } int OGlobalSettings::contrast() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("OPIE") ); return c->readNumEntry( "contrast", 7 ); } // following functions should work in OPIE - how to sync with appearance changes? QColor OGlobalSettings::baseColor() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); return c->readColorEntry( "Base", &Qt::white ); } QColor OGlobalSettings::textColor() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); return c->readColorEntry( "Text", &Qt::black ); } QColor OGlobalSettings::highlightedTextColor() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); return c->readColorEntry( "HighlightedText", &Qt::white ); } QColor OGlobalSettings::highlightColor() { initColors(); OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); return c->readColorEntry( "Highlight", OpieHighlight ); } QColor OGlobalSettings::alternateBackgroundColor() { initColors(); OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); *OpieAlternate = calculateAlternateBackgroundColor( baseColor() ); return c->readColorEntry( "alternateBackground", OpieAlternate ); } QColor OGlobalSettings::calculateAlternateBackgroundColor(const QColor& base) { if (base == Qt::white) return QColor(238,246,255); else { int h, s, v; base.hsv( &h, &s, &v ); if (v > 128) return base.dark(106); else if (base != Qt::black) return base.light(110); return QColor(32,32,32); } } QColor OGlobalSettings::linkColor() { initColors(); OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); return c->readColorEntry( "linkColor", OpieGray ); } QColor OGlobalSettings::visitedLinkColor() { OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); return c->readColorEntry( "visitedLinkColor", &Qt::magenta ); } // FIXME: font stuff currently uses a different format in OPIE, so the // functions below are not yet applicable. The whole font stuff for OPIE // has to be revised anyway QFont OGlobalSettings::generalFont() { if (_generalFont) return *_generalFont; _generalFont = new QFont("helvetica", 10); _generalFont->setPixelSize(10); _generalFont->setStyleHint(QFont::SansSerif); OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); *_generalFont = c->readFontEntry("font", _generalFont); return *_generalFont; } QFont OGlobalSettings::fixedFont() { if (_fixedFont) return *_fixedFont; _fixedFont = new QFont("courier", 12); _fixedFont->setPixelSize(12); _fixedFont->setStyleHint(QFont::TypeWriter); OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("General") ); *_fixedFont = c->readFontEntry("fixed", _fixedFont); return *_fixedFont; } QFont OGlobalSettings::toolBarFont() { if(_toolBarFont) return *_toolBarFont; _toolBarFont = new QFont("helvetica", 10); _toolBarFont->setPixelSize(10); _toolBarFont->setStyleHint(QFont::SansSerif); OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("General") ); *_toolBarFont = c->readFontEntry("toolBarFont", _toolBarFont); return *_toolBarFont; } QFont OGlobalSettings::menuFont() { if(_menuFont) return *_menuFont; _menuFont = new QFont("helvetica", 12); _menuFont->setPixelSize(12); _menuFont->setStyleHint(QFont::SansSerif); OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("General") ); *_menuFont = c->readFontEntry("menuFont", _menuFont); return *_menuFont; } QFont OGlobalSettings::windowTitleFont() { if(_windowTitleFont) return *_windowTitleFont; _windowTitleFont = new QFont("helvetica", 12, QFont::Bold); _windowTitleFont->setPixelSize(12); _windowTitleFont->setStyleHint(QFont::SansSerif); OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); *_windowTitleFont = c->readFontEntry("activeFont", _windowTitleFont); // inconsistency return *_windowTitleFont; } QFont OGlobalSettings::taskbarFont() { if(_taskbarFont) return *_taskbarFont; _taskbarFont = new QFont("helvetica", 8); _taskbarFont->setPixelSize(8); _taskbarFont->setStyleHint(QFont::SansSerif); OConfig *c = OGlobal::config(); OConfigGroupSaver cgs( c, QString::fromLatin1("General") ); *_taskbarFont = c->readFontEntry("taskbarFont", _taskbarFont); return *_taskbarFont; } // FIXME: the whole path stuff has to be revised for OPIE void OGlobalSettings::initStatic() // should be called initPaths(). Don't put anything else here. { if ( s_desktopPath != 0 ) return; s_desktopPath = new QString(); s_autostartPath = new QString(); s_trashPath = new QString(); s_documentPath = new QString(); OConfig *config = OGlobal::config(); //bool dollarExpansion = config->isDollarExpansion(); //config->setDollarExpansion(true); OConfigGroupSaver cgs( config, "Paths" ); // Desktop Path *s_desktopPath = QDir::homeDirPath() + "/" + "Desktop" + "/"; *s_desktopPath = config->readEntry( "Desktop", *s_desktopPath); if ( (*s_desktopPath)[0] != '/' ) s_desktopPath->prepend( QDir::homeDirPath() + "/" ); *s_desktopPath = QDir::cleanDirPath( *s_desktopPath ); if ( s_desktopPath->right(1) != "/") *s_desktopPath += "/"; // Trash Path *s_trashPath = *s_desktopPath + QObject::tr("Trash") + "/"; *s_trashPath = config->readEntry( "Trash" , *s_trashPath); if ( (*s_trashPath)[0] != '/' ) s_trashPath->prepend( QDir::homeDirPath() + "/" ); *s_trashPath = QDir::cleanDirPath( *s_trashPath ); if ( s_trashPath->right(1) != "/") *s_trashPath += "/"; // We need to save it in any case, in case the language changes later on, if ( !config->hasKey( "Trash" ) ) { //config->writePathEntry( "Trash", *s_trashPath, true, true ); config->writeEntry( "Trash", *s_trashPath ); //config->sync(); } /* // Autostart Path *s_autostartPath = OGlobal::dirs()->localkdedir() + "Autostart" + "/"; *s_autostartPath = config->readEntry( "Autostart" , *s_autostartPath); if ( (*s_autostartPath)[0] != '/' ) s_autostartPath->prepend( QDir::homeDirPath() + "/" ); *s_autostartPath = QDir::cleanDirPath( *s_autostartPath ); if ( s_autostartPath->right(1) != "/") *s_autostartPath += "/"; */ // Document Path *s_documentPath = QString::null; *s_documentPath = config->readEntry( "Documents" , *s_documentPath); if ( (*s_documentPath)[0] != '/' ) s_documentPath->prepend( QDir::homeDirPath() + "/" ); *s_documentPath = QDir::cleanDirPath( *s_documentPath ); if ( s_documentPath->right(1) != "/") *s_documentPath += "/"; //config->setDollarExpansion(dollarExpansion); // Make sure this app gets the notifications about those paths //if (kapp) //kapp->addKipcEventMask(KIPC::SettingsChanged); } void OGlobalSettings::initColors() { - if ( not OpieHighlight ) OpieHighlight = new QColor( 156, 118, 32 ); - if ( not OpieAlternate ) OpieAlternate = new QColor( 238, 246, 255 ); - if ( not OpieGray ) OpieGray = new QColor( 220, 210, 215 ); + if ( !OpieHighlight ) OpieHighlight = new QColor( 156, 118, 32 ); + if ( !OpieAlternate ) OpieAlternate = new QColor( 238, 246, 255 ); + if ( !OpieGray ) OpieGray = new QColor( 220, 210, 215 ); } void OGlobalSettings::rereadFontSettings() { delete _generalFont; _generalFont = 0L; delete _fixedFont; _fixedFont = 0L; delete _menuFont; _menuFont = 0L; delete _toolBarFont; _toolBarFont = 0L; delete _windowTitleFont; _windowTitleFont = 0L; delete _taskbarFont; _taskbarFont = 0L; } void OGlobalSettings::rereadPathSettings() { qDebug( "OGlobalSettings::rereadPathSettings" ); delete s_autostartPath; s_autostartPath = 0L; delete s_trashPath; s_trashPath = 0L; delete s_desktopPath; s_desktopPath = 0L; delete s_documentPath; s_documentPath = 0L; } OGlobalSettings::OMouseSettings & OGlobalSettings::mouseSettings() { if ( ! s_mouseSettings ) { s_mouseSettings = new OMouseSettings; OMouseSettings & s = *s_mouseSettings; // for convenience OConfigGroupSaver cgs( OGlobal::config(), "Mouse" ); QString setting = OGlobal::config()->readEntry("MouseButtonMapping"); if (setting == "RightHanded") s.handed = OMouseSettings::RightHanded; else if (setting == "LeftHanded") s.handed = OMouseSettings::LeftHanded; else { // FIXME: Implement for Opie / Qt Embedded } } return *s_mouseSettings; } void OGlobalSettings::rereadMouseSettings() { delete s_mouseSettings; s_mouseSettings = 0L; } // FIXME: This won't be necessary, or will it? :-D bool OGlobalSettings::isMultiHead() { QCString multiHead = getenv("OPIE_MULTIHEAD"); if (!multiHead.isEmpty()) { return (multiHead.lower() == "true"); } return false; } diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 25c70e0..998b50e 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp @@ -1,792 +1,793 @@ /* This file is part of the Opie Project Copyright (C) 2003 by the Wellenreiter team: Martin J. Muench <mjm@remote-exploit.org> Max Moser <mmo@remote-exploit.org 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. */ /* OPIE */ #include <opie2/onetwork.h> /* QT */ #include <qfile.h> #include <qtextstream.h> /* UNIX */ #include <arpa/inet.h> #include <cerrno> #include <cstring> #include <cstdlib> #include <math.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <sys/types.h> #include <unistd.h> +#include <linux/sockios.h> #include <linux/wireless.h> using namespace std; /*====================================================================================== * ONetwork *======================================================================================*/ ONetwork* ONetwork::_instance = 0; ONetwork::ONetwork() { qDebug( "ONetwork::ONetwork()" ); synchronize(); } void ONetwork::synchronize() { // gather available interfaces by inspecting /proc/net/dev // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices _interfaces.clear(); QString str; QFile f( "/proc/net/dev" ); bool hasFile = f.open( IO_ReadOnly ); if ( !hasFile ) { qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); return; } QTextStream s( &f ); s.readLine(); s.readLine(); while ( !s.atEnd() ) { s >> str; str.truncate( str.find( ':' ) ); qDebug( "ONetwork: found interface '%s'", (const char*) str ); ONetworkInterface* iface; if ( isWirelessInterface( str ) ) { iface = new OWirelessNetworkInterface( str ); qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); } else { iface = new ONetworkInterface( str ); } _interfaces.insert( str, iface ); s.readLine(); } } ONetworkInterface* ONetwork::interface( 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::isWirelessInterface( const char* name ) const { int sfd = socket( AF_INET, SOCK_DGRAM, 0 ); iwreqstruct iwr; memset( &iwr, 0, sizeof( iwreqstruct ) ); strcpy( (char*) &iwr.ifr_name, name ); int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); if ( result == -1 ) qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); else qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); return ( result != -1 ); } /*====================================================================================== * ONetworkInterface *======================================================================================*/ ONetworkInterface::ONetworkInterface( const QString& name ) :_name( name ), _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) { qDebug( "ONetworkInterface::ONetworkInterface()" ); init(); } ifreqstruct& ONetworkInterface::ifr() const { return _ifr; } void ONetworkInterface::init() { qDebug( "ONetworkInterface::init()" ); memset( &_ifr, 0, sizeof( struct ifreq ) ); if ( _sfd == -1 ) { qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", (const char*) _name ); return; } } bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const { int result = ::ioctl( _sfd, call, &ifreq ); if ( result == -1 ) qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); else qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); return ( result != -1 ); } bool ONetworkInterface::ioctl( int call ) const { strcpy( _ifr.ifr_name, (const char*) _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; } QString 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>"; } OMacAddress ONetworkInterface::macAddress() const { if ( ioctl( SIOCGIFHWADDR ) ) { return OMacAddress( _ifr ); } else { return OMacAddress::unknown; } } void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) { _mon = m; qDebug( "ONetwork::setMonitoring(): Installed monitoring interface '%s'", (const char*) m->name() ); } OMonitoringInterface* ONetworkInterface::monitoring() const { return _mon; } const QString& ONetworkInterface::name() const { return _name; } ONetworkInterface::~ONetworkInterface() { qDebug( "ONetworkInterface::~ONetworkInterface()" ); 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 ); } /*====================================================================================== * OChannelHopper *======================================================================================*/ OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) :QObject( 0, "Mickey's funky hopper" ), _iface( iface ), _interval( 0 ), _channel( 1 ), _tid( 0 ), _maxChannel( iface->channels()+1 ) { } OChannelHopper::~OChannelHopper() { } bool OChannelHopper::isActive() const { return _tid; } int OChannelHopper::channel() const { return _channel; } void OChannelHopper::timerEvent( QTimerEvent* ) { if ( !--_channel ) _channel = _maxChannel; _iface->setChannel( _channel ); qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", _channel, (const char*) _iface->name() ); } void OChannelHopper::setInterval( int interval ) { if ( interval == _interval ) return; if ( _interval ) killTimer( _tid ); _tid = 0; _interval = interval; if ( _interval ) { _tid = startTimer( interval ); } } int OChannelHopper::interval() const { return _interval; } /*====================================================================================== * OWirelessNetworkInterface *======================================================================================*/ OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) :ONetworkInterface( name ), _hopper( 0 ) { qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); init(); } OWirelessNetworkInterface::~OWirelessNetworkInterface() { } iwreqstruct& OWirelessNetworkInterface::iwr() const { return _iwr; } void OWirelessNetworkInterface::init() { qDebug( "OWirelessNetworkInterface::init()" ); memset( &_iwr, 0, sizeof( struct iwreq ) ); // IEEE802.11(b) radio frequency channels //FIXME: get these directly from the interface //FIXME: check if these channels are off-by-one iwrangestruct range; _iwr.u.data.pointer = (char*) ⦥ _iwr.u.data.length = sizeof( iwrangestruct ); if ( !wioctl( SIOCGIWRANGE ) ) { qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); return; } for ( int i = 0; i < range.num_frequency; ++i ) { int freq = (int) ( double( range.freq[i].m ) * pow( 10, range.freq[i].e ) / 1000000.0 ); _channels.insert( freq, i+1 ); } } QString OWirelessNetworkInterface::associatedAP() const { //FIXME: use OMacAddress QString mac; if ( ioctl( SIOCGIWAP ) ) { mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", _ifr.ifr_hwaddr.sa_data[0]&0xff, _ifr.ifr_hwaddr.sa_data[1]&0xff, _ifr.ifr_hwaddr.sa_data[2]&0xff, _ifr.ifr_hwaddr.sa_data[3]&0xff, _ifr.ifr_hwaddr.sa_data[4]&0xff, _ifr.ifr_hwaddr.sa_data[5]&0xff ); } else { mac = "<Unknown>"; } return mac; } int OWirelessNetworkInterface::channel() const { //FIXME: When monitoring enabled, then use it //FIXME: to gather the current RF channel //FIXME: Until then, get active channel from hopper. if ( _hopper && _hopper->isActive() ) return _hopper->channel(); if ( !wioctl( SIOCGIWFREQ ) ) { return -1; } else { return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000) ]; } } void OWirelessNetworkInterface::setChannel( int c ) const { if ( !_mon ) { memset( &_iwr, 0, sizeof( iwreqstruct ) ); _iwr.u.freq.m = c; _iwr.u.freq.e = 0; wioctl( SIOCSIWFREQ ); } else { _mon->setChannel( c ); } } double OWirelessNetworkInterface::frequency() const { if ( !wioctl( SIOCGIWFREQ ) ) { return -1.0; } else { return double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000000.0; } } int OWirelessNetworkInterface::channels() const { return _channels.count(); } void OWirelessNetworkInterface::setChannelHopping( int interval ) { if ( !_hopper ) _hopper = new OChannelHopper( this ); _hopper->setInterval( interval ); //FIXME: When and by whom will the channel hopper be deleted? } int OWirelessNetworkInterface::channelHopping() const { return _hopper->interval(); } void OWirelessNetworkInterface::setMonitorMode( bool b ) { if ( _mon ) _mon->setEnabled( b ); else qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); } bool OWirelessNetworkInterface::monitorMode() const { return _mon ? _mon->enabled() : false; } QString OWirelessNetworkInterface::nickName() const { char str[IW_ESSID_MAX_SIZE]; _iwr.u.data.pointer = &str[0]; _iwr.u.data.length = IW_ESSID_MAX_SIZE; if ( !wioctl( SIOCGIWNICKN ) ) { return "<unknown>"; } else { str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string return str; } } QString OWirelessNetworkInterface::SSID() const { char str[IW_ESSID_MAX_SIZE]; _iwr.u.essid.pointer = &str[0]; _iwr.u.essid.length = IW_ESSID_MAX_SIZE; if ( !wioctl( SIOCGIWESSID ) ) { return "<unknown>"; } else { return str; } } void OWirelessNetworkInterface::setSSID( const QString& ssid ) { _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); _iwr.u.essid.length = ssid.length(); wioctl( SIOCSIWESSID ); } bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const { int result = ::ioctl( _sfd, call, &iwreq ); if ( result == -1 ) qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); else qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); return ( result != -1 ); } bool OWirelessNetworkInterface::wioctl( int call ) const { strcpy( _iwr.ifr_name, (const char*) _name ); return wioctl( call, _iwr ); } /*====================================================================================== * OMonitoringInterface *======================================================================================*/ OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) ) { } OMonitoringInterface::~OMonitoringInterface() { } void OMonitoringInterface::setChannel( int c ) { // use standard WE channel switching protocol memset( &_if->_iwr, 0, sizeof( iwreqstruct ) ); _if->_iwr.u.freq.m = c; _if->_iwr.u.freq.e = 0; _if->wioctl( SIOCSIWFREQ ); } bool OMonitoringInterface::enabled() const { return _enabled; } void OMonitoringInterface::setEnabled( bool b ) { // open a packet capturer here or leave this to // the client code? /* if ( b ) { OPacketCapturer* opcap = new OPacketCapturer(); opcap->open( _if->name() ); } */ _enabled = b; } /*====================================================================================== * OCiscoMonitoringInterface *======================================================================================*/ OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) :OMonitoringInterface( iface ) { iface->setMonitoring( this ); } OCiscoMonitoringInterface::~OCiscoMonitoringInterface() { } void OCiscoMonitoringInterface::setEnabled( bool b ) { QString fname; fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); QFile f( fname ); if ( !f.exists() ) return; if ( f.open( IO_WriteOnly ) ) { QTextStream s( &f ); s << "Mode: r"; s << "Mode: y"; s << "XmitPower: 1"; OMonitoringInterface::setEnabled( b ); } // flushing and closing will be done automatically when f goes out of scope } QString OCiscoMonitoringInterface::name() const { return "cisco"; } void OCiscoMonitoringInterface::setChannel( int ) { // cisco devices automatically switch channels when in monitor mode } /*====================================================================================== * OWlanNGMonitoringInterface *======================================================================================*/ OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) :OMonitoringInterface( iface ) { iface->setMonitoring( this ); } OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() { } void OWlanNGMonitoringInterface::setEnabled( bool b ) { //FIXME: do nothing if its already in the same mode QString enable = b ? "true" : "false"; QString cmd; cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); system( cmd ); OMonitoringInterface::setEnabled( b ); } QString OWlanNGMonitoringInterface::name() const { return "wlan-ng"; } void OWlanNGMonitoringInterface::setChannel( int ) { // wlan-ng devices automatically switch channels when in monitor mode } /*====================================================================================== * OHostAPMonitoringInterface *======================================================================================*/ OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) :OMonitoringInterface( iface ) { iface->setMonitoring( this ); } OHostAPMonitoringInterface::~OHostAPMonitoringInterface() { } void OHostAPMonitoringInterface::setEnabled( bool b ) { // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring #if WIRELESS_EXT > 14 _if->_iwr.u.mode = IW_MODE_MONITOR; _if->wioctl( SIOCSIWMODE ); #else - int* args = (int*) &_if._iwr.u.name; + int* args = (int*) &_if->_iwr.u.name; args[0] = 2; args[1] = 0; _if->wioctl( SIOCDEVPRIVATE ); #endif OMonitoringInterface::setEnabled( b ); } QString OHostAPMonitoringInterface::name() const { return "hostap"; } /*====================================================================================== * OOrinocoNetworkInterface *======================================================================================*/ OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) :OMonitoringInterface( iface ) { iface->setMonitoring( this ); } OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() { } void OOrinocoMonitoringInterface::setChannel( int c ) { // call iwpriv <device> monitor 2 <channel> int* args = (int*) &_if->_iwr.u.name; args[0] = 2; args[1] = c; _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); } void OOrinocoMonitoringInterface::setEnabled( bool b ) { if ( b ) { setChannel( 1 ); } else { // call iwpriv <device> monitor 0 0 int* args = (int*) &_if->_iwr.u.name; args[0] = 0; args[1] = 0; _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); } OMonitoringInterface::setEnabled( b ); } QString OOrinocoMonitoringInterface::name() const { return "orinoco"; } diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index 936ac85..56da5f4 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h @@ -1,310 +1,318 @@ /* This file is part of the Opie Project Copyright (C) 2003 by the Wellenreiter team: Martin J. Muench <mjm@remote-exploit.org> Max Moser <mmo@remote-exploit.org 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. */ #ifndef ONETWORK_H #define ONETWORK_H /* QT */ #include <qdict.h> #include <qmap.h> #include <qobject.h> #include <qhostaddress.h> /* OPIE */ #include <opie2/onetutils.h> // ML: Yeah, I hate to include kernel headers, but it's necessary here // ML: Recent RedHat and MandrakePatches to the Kernel and WE broke something // ML: #include <net/if.h> e.g. conflicts with #include <linux/wireless.h> + +#ifndef IFNAMSIZ #define IFNAMSIZ 16 +#endif + #include <linux/wireless.h> #include <net/if.h> +#ifndef SIOCIWFIRSTPRIV +#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE +#endif + class ONetworkInterface; class OWirelessNetworkInterface; class OChannelHopper; class OMonitoringInterface; typedef struct ifreq ifreqstruct; typedef struct iwreq iwreqstruct; typedef struct iw_event iweventstruct; typedef struct iw_freq iwfreqstruct; typedef struct iw_priv_args iwprivargsstruct; typedef struct iw_range iwrangestruct; /*====================================================================================== * ONetwork *======================================================================================*/ class ONetwork : public QObject { Q_OBJECT public: typedef QDict<ONetworkInterface> InterfaceMap; typedef QDictIterator<ONetworkInterface> InterfaceIterator; public: static ONetwork* instance(); InterfaceIterator iterator() const; bool isWirelessInterface( const char* ) const; ONetworkInterface* interface( QString ) const; protected: ONetwork(); void synchronize(); private: static ONetwork* _instance; InterfaceMap _interfaces; }; /*====================================================================================== * ONetworkInterface *======================================================================================*/ class ONetworkInterface { friend class OMonitoringInterface; friend class OCiscoMonitoringInterface; friend class OWlanNGMonitoringInterface; friend class OHostAPMonitoringInterface; friend class OOrinocoMonitoringInterface; public: ONetworkInterface( const QString& name ); virtual ~ONetworkInterface(); const QString& name() const; void setMonitoring( OMonitoringInterface* ); OMonitoringInterface* monitoring() const; bool setPromiscuousMode( bool ); bool promiscuousMode() const; bool setUp( bool ); bool isUp() const; bool isLoopback() const; bool isWireless() const; QString ipV4Address() const; OMacAddress macAddress() const; protected: const QString _name; const int _sfd; mutable ifreqstruct _ifr; OMonitoringInterface* _mon; protected: ifreqstruct& ifr() const; virtual void init(); bool ioctl( int call ) const; bool ioctl( int call, ifreqstruct& ) const; }; /*====================================================================================== * OChannelHopper *======================================================================================*/ class OChannelHopper : public QObject { public: OChannelHopper( OWirelessNetworkInterface* ); virtual ~OChannelHopper(); bool isActive() const; int channel() const; virtual void timerEvent( QTimerEvent* ); void setInterval( int ); int interval() const; private: OWirelessNetworkInterface* _iface; int _interval; int _channel; int _tid; int _maxChannel; }; /*====================================================================================== * OWirelessNetworkInterface *======================================================================================*/ class OWirelessNetworkInterface : public ONetworkInterface { friend class OMonitoringInterface; friend class OCiscoMonitoringInterface; friend class OWlanNGMonitoringInterface; friend class OHostAPMonitoringInterface; friend class OOrinocoMonitoringInterface; public: enum Mode { AdHoc, Managed, Monitor }; OWirelessNetworkInterface( const QString& name ); virtual ~OWirelessNetworkInterface(); virtual void setChannel( int ) const; virtual int channel() const; virtual double frequency() const; virtual int channels() const; //virtual double frequency(int) const; virtual void setMode( Mode ) {}; virtual bool mode() const {}; virtual void setMonitorMode( bool ); virtual bool monitorMode() const; virtual void setChannelHopping( int interval = 0 ); virtual int channelHopping() const; virtual void setNickName( const QString& ) {}; virtual QString nickName() const; virtual bool isAssociated() const {}; virtual QString associatedAP() const; virtual void setSSID( const QString& ); virtual QString SSID() const; protected: mutable iwreqstruct _iwr; QMap<int,int> _channels; protected: virtual void init(); iwreqstruct& iwr() const; bool wioctl( int call ) const; bool wioctl( int call, iwreqstruct& ) const; private: OChannelHopper* _hopper; }; /*====================================================================================== * OMonitoringInterface *======================================================================================*/ class OMonitoringInterface { public: OMonitoringInterface(); OMonitoringInterface( ONetworkInterface* ); virtual ~OMonitoringInterface(); public: virtual void setEnabled( bool ); virtual bool enabled() const; virtual void setChannel( int ); virtual QString name() const = 0; protected: bool _enabled; const OWirelessNetworkInterface* _if; }; /*====================================================================================== * OCiscoMonitoring *======================================================================================*/ class OCiscoMonitoringInterface : public OMonitoringInterface { public: OCiscoMonitoringInterface( ONetworkInterface* ); virtual ~OCiscoMonitoringInterface(); virtual void setEnabled( bool ); virtual QString name() const; virtual void setChannel( int ); }; /*====================================================================================== * OWlanNGMonitoringInterface *======================================================================================*/ class OWlanNGMonitoringInterface : public OMonitoringInterface { public: OWlanNGMonitoringInterface( ONetworkInterface* ); virtual ~OWlanNGMonitoringInterface(); public: virtual void setEnabled( bool ); virtual QString name() const; virtual void setChannel( int ); }; /*====================================================================================== * OHostAPMonitoringInterface *======================================================================================*/ class OHostAPMonitoringInterface : public OMonitoringInterface { public: OHostAPMonitoringInterface( ONetworkInterface* ); virtual ~OHostAPMonitoringInterface(); public: virtual void setEnabled( bool ); virtual QString name() const; }; /*====================================================================================== * OOrinocoMonitoringInterface *======================================================================================*/ class OOrinocoMonitoringInterface : public OMonitoringInterface { public: OOrinocoMonitoringInterface( ONetworkInterface* ); virtual ~OOrinocoMonitoringInterface(); public: virtual void setChannel( int ); virtual void setEnabled( bool ); virtual QString name() const; }; #endif // ONETWORK_H |