From db9f0e2a7fd93157d95f421534fcc3015abe53e0 Mon Sep 17 00:00:00 2001 From: wimpie Date: Sat, 10 Apr 2004 13:06:13 +0000 Subject: *** empty log message *** --- (limited to 'noncore/settings/networksettings2/wlan') diff --git a/noncore/settings/networksettings2/wlan/wlanGUI.ui b/noncore/settings/networksettings2/wlan/wlanGUI.ui index 9614369..1aec138 100644 --- a/noncore/settings/networksettings2/wlan/wlanGUI.ui +++ b/noncore/settings/networksettings2/wlan/wlanGUI.ui @@ -11,8 +11,8 @@ 0 0 - 192 - 329 + 209 + 307 @@ -32,7 +32,7 @@ spacing - 0 + 1 QTabWidget @@ -73,25 +73,43 @@ QLayoutWidget name - Layout6 + Layout11 - layoutMargin + layoutSpacing margin - 1 + 0 spacing - 6 + 1 - - QLabel + + QComboBox + + + text + Auto + + + + + text + Managed + + + + + text + Ad-Hoc + + name - essidLabel + Mode_CB enabled @@ -101,52 +119,30 @@ sizePolicy 1 - 1 + 0 - - text - ESS-ID - - - QComboBox - - - text - any - - + + QLabel name - ESSID_CB - - - sizePolicy - - 7 - 0 - + essidLabel_2 - editable + enabled true - currentItem - 0 - - - sizeLimit - 5 - - - autoCompletion - true + sizePolicy + + 1 + 1 + - duplicatesEnabled - false + text + Name @@ -171,35 +167,18 @@ Mode - - QComboBox - - - text - Infrastructure - - - - - text - Auto - - - - - text - Managed - - - - - text - Ad-Hoc - - + + QLineEdit name - Mode_CB + ESSID_LE + + + + QLabel + + name + essidLabel enabled @@ -209,9 +188,24 @@ sizePolicy 1 - 0 + 1 + + text + ESS-ID + + + + QLineEdit + + name + NodeName_LE + + + text + <UseHostName> + @@ -244,7 +238,7 @@ text - Specify &Access Point + Specify Access Point @@ -310,60 +304,6 @@ - - QLayoutWidget - - name - Layout7 - - - layoutMargin - - - - margin - 1 - - - spacing - 6 - - - QCheckBox - - name - SpecifyChannel_CB - - - text - Specific &Channel - - - - QSpinBox - - name - ChannelNr_SB - - - enabled - false - - - maxValue - 15 - - - minValue - 1 - - - value - 1 - - - - name @@ -410,7 +350,7 @@ QCheckBox name - EnableWEB_CB + EnableWEP_CB text @@ -511,6 +451,10 @@ name Key2_LE + + enabled + false + QLineEdit @@ -518,6 +462,10 @@ name Key4_LE + + enabled + false + QLineEdit @@ -525,6 +473,10 @@ name Key3_LE + + enabled + false + @@ -532,7 +484,7 @@ QCheckBox name - CheckBox4 + AcceptNonEncrypted_CB enabled @@ -589,7 +541,7 @@ QLayoutWidget name - Layout12 + Layout13 layoutSpacing @@ -603,26 +555,15 @@ spacing 2 - - QLabel - - name - TextLabel1_3 - - - text - Station - - - + QLabel name - Channel_LBL + Frequency_LBL frameShape - Panel + Box frameShadow @@ -633,48 +574,34 @@ 0 - - QLabel - - name - TextLabel4_3 - - - text - Channel - - QLabel name - TextLabel3_3 + TextLabel9_2 text - Mode + AP - + QLabel name - TextLabel2_3 + Channel_LBL - text - ESSID + frameShape + Box - - - QLabel - name - TextLabel9_2 + frameShadow + Plain - text - AP + indent + 0 @@ -685,7 +612,7 @@ frameShape - Panel + Box frameShadow @@ -696,7 +623,18 @@ 0 - + + QLabel + + name + TextLabel4_2_2 + + + text + Rate + + + QLabel name @@ -711,7 +649,7 @@ frameShape - Panel + Box frameShadow @@ -722,26 +660,34 @@ 0 - + QLabel name - TextLabel4_2_2 + AP_LBL - text - Rate + frameShape + Box + + + frameShadow + Plain + + + indent + 0 - + QLabel name - AP_LBL + Mode_LBL frameShape - Panel + Box frameShadow @@ -760,7 +706,7 @@ frameShape - Panel + Box frameShadow @@ -771,23 +717,59 @@ 0 - + QLabel name - Mode_LBL + TextLabel3_3 - frameShape - Panel + text + Mode + + + QLabel - frameShadow - Plain + name + TextLabel4_3 - indent - 0 + text + Channel + + + + QLabel + + name + TextLabel1_3 + + + text + Station + + + + QLabel + + name + TextLabel2_3 + + + text + ESSID + + + + QLabel + + name + TextLabel4_3_2 + + + text + Frequency @@ -799,6 +781,10 @@ GroupBox1 + margin + 0 + + title Link Quality @@ -815,7 +801,7 @@ spacing - 2 + 0 QLabel @@ -847,7 +833,7 @@ progress - 0 + 10 @@ -858,7 +844,7 @@ progress - 0 + 10 @@ -872,27 +858,6 @@ Signal - - - name - Spacer28 - - - orientation - Horizontal - - - sizeType - Fixed - - - sizeHint - - 16 - 20 - - - QProgressBar @@ -909,7 +874,7 @@ progress - 0 + 10 @@ -935,6 +900,62 @@ + + QLayoutWidget + + name + Layout21 + + + + margin + 0 + + + spacing + 6 + + + QCheckBox + + name + Refresh_CB + + + sizePolicy + + 1 + 5 + + + + text + Live feed + + + + + name + Spacer16 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + @@ -942,7 +963,7 @@ - EnableWEB_CB + EnableWEP_CB toggled(bool) KeyButtonGroup setEnabled(bool) @@ -960,16 +981,41 @@ setEnabled(bool) - SpecifyChannel_CB + EnableWEP_CB + toggled(bool) + AcceptNonEncrypted_CB + setEnabled(bool) + + + Key1_RB + toggled(bool) + Key1_LE + setEnabled(bool) + + + Key2_RB + toggled(bool) + Key2_LE + setEnabled(bool) + + + Key3_RB toggled(bool) - ChannelNr_SB + Key3_LE setEnabled(bool) - EnableWEB_CB + Key4_RB toggled(bool) - CheckBox4 + Key4_LE setEnabled(bool) + + Refresh_CB + toggled(bool) + WLanGUI + SLOT_AutoRefresh(bool) + + SLOT_AutoRefresh(bool) diff --git a/noncore/settings/networksettings2/wlan/wlan_NNI.cpp b/noncore/settings/networksettings2/wlan/wlan_NNI.cpp index 78e756c..61969f2 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NNI.cpp +++ b/noncore/settings/networksettings2/wlan/wlan_NNI.cpp @@ -1,3 +1,4 @@ +#include #include "wlanedit.h" #include "wlan_NNI.h" #include "wlan_NN.h" @@ -5,16 +6,66 @@ AWLan::AWLan( WLanNetNode * PNN ) : ANetNodeInstance( PNN ) { GUI = 0; RT = 0; + Data.ESSID = ""; + Data.NodeName = tr(""); + Data.Mode = 0; + Data.SpecificAP = 0; + Data.APMac = ""; + Data.Encrypted = 0; + Data.AcceptNonEncrypted = 0; + Data.Key[0] = ""; + Data.Key[1] = ""; + Data.Key[2] = ""; + Data.Key[3] = ""; } -void AWLan::setSpecificAttribute( QString & , QString & ) { +void AWLan::setSpecificAttribute( QString & A, QString & V ) { + if( A == "essid" ) { + Data.ESSID = V; + } else if( A == "nodename" ) { + Data.NodeName = V; + } else if( A == "mode" ) { + Data.Mode = V.toShort(); + } else if( A == "specificap" ) { + Data.SpecificAP = (V=="yes"); + } else if( A == "apmac" ) { + Data.APMac = V; + } else if( A == "encrypted" ) { + Data.Encrypted = (V=="yes"); + } else if( A == "acceptnonencrypted" ) { + Data.AcceptNonEncrypted = (V=="yes"); + } else if( A == "key0" ) { + Data.Key[0] = V; + } else if( A == "key1" ) { + Data.Key[1] = V; + } else if( A == "key2" ) { + Data.Key[2] = V; + } else if( A == "key3" ) { + Data.Key[3] = V; + } } -void AWLan::saveSpecificAttribute( QTextStream & ) { +void AWLan::saveSpecificAttribute( QTextStream & S ) { + S << "essid=" << quote( Data.ESSID ) << endl; + S << "nodename=" << quote( Data.NodeName ) << endl; + S << "mode=" << Data.Mode << endl; + S << "specificap=" + << ((Data.SpecificAP) ? "yes" : "no") + << endl; + S << "apmac=" << Data.APMac << endl; + S << "encrypted=" + << ((Data.Encrypted) ? "yes" : "no") + << endl; + S << "acceptnonencrypted=" + << ((Data.AcceptNonEncrypted) ? "yes" : "no") + << endl; + for( int i = 0 ;i < 4 ; i ++ ) { + S << "key" << i << "=" << Data.Key[i] << endl; + } } QWidget * AWLan::edit( QWidget * parent ) { - GUI = new WLanEdit( parent ); + GUI = new WLanEdit( parent, this ); GUI->showData( Data ); return GUI; } @@ -29,8 +80,61 @@ void AWLan::commit( void ) { } bool AWLan::generateDataForCommonFile( - SystemFile &, + SystemFile & S, long ) { - return 1; + + S << " wireless_essid \"" + << Data.ESSID + << "\"" + << endl; + + if( ! Data.NodeName.isEmpty() ) { + if( Data.NodeName == tr("") ) { + char Buf[100]; + if( gethostname(Buf, sizeof(Buf) ) == 0 ) { + Buf[99] = '\0'; // just to make sure + S << " wireless_nick " + << Buf + << endl; + } + } else { + S << " wireless_nick \"" + << Data.NodeName + << "\"" + << endl; + } + } + + char * M; + switch ( Data.Mode ) { + case 0 : + M = "Auto"; + break; + case 1 : + M = "Managed"; + break; + case 2 : + M = "Ad-Hoc"; + break; + } + + S << " wireless_mode " + << M + << endl; + if( Data.Encrypted ) { + for( int i = 0; i < 4; i ++ ) { + if( ! Data.Key[i].isEmpty() ) { + S << " wireless_key" + << i + << " " + << Data.Key[i] + << endl; + } + } + S << " wireless_keymode " + << ((Data.AcceptNonEncrypted) ? "open" : "restricted") + << endl; + } + return 0; } diff --git a/noncore/settings/networksettings2/wlan/wlan_NNI.h b/noncore/settings/networksettings2/wlan/wlan_NNI.h index d861d13..2211c47 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NNI.h +++ b/noncore/settings/networksettings2/wlan/wlan_NNI.h @@ -28,7 +28,7 @@ public : { return (void *)&Data; } virtual bool hasDataFor( const QString & ) - { return 0; } + { return 1; } virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr ); protected : diff --git a/noncore/settings/networksettings2/wlan/wlandata.h b/noncore/settings/networksettings2/wlan/wlandata.h index ba1f2c2..36990a9 100644 --- a/noncore/settings/networksettings2/wlan/wlandata.h +++ b/noncore/settings/networksettings2/wlan/wlandata.h @@ -3,15 +3,14 @@ #include typedef struct WLanData { - QString Device; - QString LockFile; - long Speed; - short Parity; - short DataBits; - short StopBits; - bool HardwareControl; - bool SoftwareControl; - + QString ESSID; + QString NodeName; + short Mode; + bool SpecificAP; + QString APMac; + bool Encrypted; + QString Key[4]; + bool AcceptNonEncrypted; } WLanData_t; #endif diff --git a/noncore/settings/networksettings2/wlan/wlanedit.cpp b/noncore/settings/networksettings2/wlan/wlanedit.cpp index c884886..8d3979e 100644 --- a/noncore/settings/networksettings2/wlan/wlanedit.cpp +++ b/noncore/settings/networksettings2/wlan/wlanedit.cpp @@ -1,16 +1,115 @@ +#include +#include +#include +#include +#include +#include #include +#include +#include + #include "wlanedit.h" +#include "wlan_NN.h" +#include "wlan_NNI.h" + +WLanEdit::WLanEdit( QWidget * Parent, ANetNodeInstance * TNNI ) : + WLanGUI( Parent ), RefreshTimer(this){ + + InterfaceInfo * II; + + NNI = TNNI; + Dev = NNI->runtime()->device(); + WE = 0; + if( ( II = Dev->assignedInterface() ) ) { + // show data + WE = new WExtensions( II->Name ); + + if( WE->doesHaveWirelessExtensions() ) { + QString S; + Station_LBL->setText( WE->station() ); + ESSID_LBL->setText( WE->essid() ); + Mode_LBL->setText( WE->mode() ); + S.setNum( WE->frequency() ); + Frequency_LBL->setText( S ); + S.setNum( WE->channel() ); + Channel_LBL->setText( S ); + S.setNum( WE->rate() ); + Rate_LBL->setText( S ); + AP_LBL->setText( WE->ap() ); + + SLOT_Refresh(); + + connect( &RefreshTimer, SIGNAL( timeout() ), + this, SLOT( SLOT_Refresh() ) ); + } + } +} -WLanEdit::WLanEdit( QWidget * Parent ) : WLanGUI( Parent ){ +WLanEdit::~WLanEdit( void ) { + if( WE ) + delete WE; } QString WLanEdit::acceptable( void ) { + if( ESSID_LE->text().isEmpty() ) { + return QString("ESSID is mandatory"); + } + if( SpecifyAP_CB->isChecked() && + APMac_LE->text().isEmpty() ) { + return QString("APMac must have value"); + } return QString(); } void WLanEdit::showData( WLanData_t & Data ) { + Mode_CB->setCurrentItem( Data.Mode ); + ESSID_LE->setText( Data.ESSID ); + NodeName_LE->setText( Data.NodeName ); + SpecifyAP_CB->setChecked( Data.SpecificAP ); + APMac_LE->setText( Data.APMac ); + + EnableWEP_CB->setChecked( Data.Encrypted ); + AcceptNonEncrypted_CB->setChecked( Data.AcceptNonEncrypted ); + Key1_LE->setText( Data.Key[0] ); + Key2_LE->setText( Data.Key[1] ); + Key3_LE->setText( Data.Key[2] ); + Key4_LE->setText( Data.Key[3] ); } bool WLanEdit::commit( WLanData_t & Data ) { + bool SM = 0; + + TXTM( Data.ESSID, ESSID_LE, SM ); + TXTM( Data.NodeName, NodeName_LE, SM ); + TXTM( Data.APMac, APMac_LE, SM ); + TXTM( Data.Key[0], Key1_LE, SM ); + TXTM( Data.Key[1], Key2_LE, SM ); + TXTM( Data.Key[2], Key3_LE, SM ); + TXTM( Data.Key[3], Key4_LE, SM ); + CBM( Data.SpecificAP, SpecifyAP_CB, SM ); + CBM( Data.Encrypted, EnableWEP_CB, SM ); + CBM( Data.AcceptNonEncrypted, AcceptNonEncrypted_CB, SM ); + CIM( Data.Mode, Mode_CB, SM ); return 0; } + +void WLanEdit::SLOT_Refresh( void ) { + if( WE ) { + int signal, noise, quality; + WE->stats( signal, noise, quality); + + Signal_PB->setProgress( signal ); + Noise_PB->setProgress( noise ); + Quality_PB->setProgress( quality ); + } +} + +void WLanEdit::SLOT_AutoRefresh( bool ar ) { + if( ar ) { + RefreshTimer.start( 1000 ); + SLOT_Refresh(); + } else { + RefreshTimer.stop(); + } +} + diff --git a/noncore/settings/networksettings2/wlan/wlanedit.h b/noncore/settings/networksettings2/wlan/wlanedit.h index b7442d5..e550c14 100644 --- a/noncore/settings/networksettings2/wlan/wlanedit.h +++ b/noncore/settings/networksettings2/wlan/wlanedit.h @@ -1,12 +1,32 @@ +#include +#include #include "wlandata.h" #include "wlanGUI.h" +class ANetNodeInstance; +class AsDevice; +class WExtensions; + class WLanEdit : public WLanGUI { public : - WLanEdit( QWidget * parent ); + WLanEdit( QWidget * parent, ANetNodeInstance * NNI ); + ~WLanEdit( void ); QString acceptable( void ); void showData( WLanData_t & Data ); bool commit( WLanData_t & Data ); + +public slots : + + void SLOT_AutoRefresh( bool ); + void SLOT_Refresh( void ); + +private : + + ANetNodeInstance * NNI; + AsDevice * Dev; + QTimer RefreshTimer; + WExtensions * WE; + }; diff --git a/noncore/settings/networksettings2/wlan/wlanrun.cpp b/noncore/settings/networksettings2/wlan/wlanrun.cpp index 79f11f7..3f1d4a9 100644 --- a/noncore/settings/networksettings2/wlan/wlanrun.cpp +++ b/noncore/settings/networksettings2/wlan/wlanrun.cpp @@ -1,5 +1,185 @@ + +#include +#include +#include +#include #include "wlanrun.h" +void WLanRun::detectState( NodeCollection * NC ) { + + // unavailable : no card found + // available : card found and assigned to us or free + // up : card found and assigned to us and up + + QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); + System & Sys = NSResources->system(); + InterfaceInfo * Run; + + QFile F( S ); + + if( F.open( IO_ReadOnly ) ) { + // could open file -> read interface and assign + QString X; + QTextStream TS(&F); + X = TS.readLine(); + // find interface + if( handlesInterface( X ) ) { + for( QDictIterator It(Sys.interfaces()); + It.current(); + ++It ) { + Run = It.current(); + if( X == Run->Name ) { + Run->assignNode( netNode() ); + assignInterface( Run ); + NC->setCurrentState( IsUp ); + return; + } + } + } + } + + if( ( Run = assignedInterface() ) ) { + // we already have an interface assigned -> still present ? + if( ! Run->IsUp ) { + // usb is still free -> keep assignment + NC->setCurrentState( Available ); + return; + } // else interface is up but NOT us -> some other profile + } + + // nothing (valid) assigned to us + assignInterface( 0 ); + + // find possible interface + for( QDictIterator It(Sys.interfaces()); + It.current(); + ++It ) { + Run = It.current(); + if( handlesInterface( *Run ) && + ( Run->CardType == ARPHRD_ETHER +#ifdef ARPHRD_IEEE1394 + || Run->CardType == ARPHRD_IEEE1394 +#endif + ) && + ! Run->IsUp + ) { + // proper type, and Not UP -> free + NC->setCurrentState( Off ); + return; + } + } + // no free found + + NC->setCurrentState( Unavailable ); + +} + +bool WLanRun::setState( NodeCollection * NC, Action_t A, bool ) { + + // we only handle activate and deactivate + switch( A ) { + case Activate : + { + if( NC->currentState() != Off ) { + return 0; + } + InterfaceInfo * N = getInterface(); + if( ! N ) { + // no interface available + NC->setCurrentState( Unavailable ); + return 0; + } + // because we were OFF the interface + // we get back is NOT assigned + N->assignNode( netNode() ); + assignInterface( N ); + NC->setCurrentState( Available ); + return 1; + } + case Deactivate : + if( NC->currentState() == IsUp ) { + // bring down first + if( ! connection()->setState( Down ) ) + // could not ... + return 0; + } else if( NC->currentState() != Available ) { + return 1; + } + assignedInterface()->assignNode( 0 ); // release + assignInterface( 0 ); + NC->setCurrentState( Off ); + return 1; + default : + // FT + break; + } + return 0; +} + +bool WLanRun::canSetState( State_t Curr, Action_t A ) { + // we only handle up down activate and deactivate + switch( A ) { + case Activate : + { // at least available + if( Curr == Available ) { + return 1; + } + // or we can make one available + InterfaceInfo * N = getInterface(); + if( ! N || N->assignedNode() != 0 ) { + // non available or assigned + return 0; + } + return 1; + } + case Deactivate : + return ( Curr >= Available ); + default : + // FT + break; + } + return 0; +} + +// get interface that is free or assigned to us +InterfaceInfo * WLanRun::getInterface( void ) { + + System & S = NSResources->system(); + InterfaceInfo * best = 0, * Run; + + for( QDictIterator It(S.interfaces()); + It.current(); + ++It ) { + Run = It.current(); + if( handlesInterface( *Run ) && + ( Run->CardType == ARPHRD_ETHER +#ifdef ARPHRD_IEEE1394 + || Run->CardType == ARPHRD_IEEE1394 +#endif + ) + ) { + // this is a LAN card + if( Run->assignedNode() == netNode() ) { + // assigned to us + return Run; + } else if( Run->assignedNode() == 0 ) { + // free + best = Run; + } + } + } + return best; // can be 0 +} + bool WLanRun::handlesInterface( const QString & S ) { + InterfaceInfo * II; + II = NSResources->system().interface( S ); + if( ( II = NSResources->system().interface( S ) ) ) { + return handlesInterface( *II ); + } return Pat.match( S ) >= 0; } + +bool WLanRun::handlesInterface( const InterfaceInfo & II ) { + return ( Pat.match( II.Name ) < 0 ); +} diff --git a/noncore/settings/networksettings2/wlan/wlanrun.h b/noncore/settings/networksettings2/wlan/wlanrun.h index f46bcb7..25d5b96 100644 --- a/noncore/settings/networksettings2/wlan/wlanrun.h +++ b/noncore/settings/networksettings2/wlan/wlanrun.h @@ -21,20 +21,17 @@ public : protected : - void detectState( NodeCollection * ) - { } - - bool setState( NodeCollection *, Action_t ) - { return 0; } - - bool canSetState( State_t, Action_t ) - { return 0; } - + void detectState( NodeCollection * ); + bool setState( NodeCollection *, Action_t, bool ); + bool canSetState( State_t, Action_t ); bool handlesInterface( const QString & I ); + bool handlesInterface( const InterfaceInfo & II ); private : + InterfaceInfo * getInterface( void ); QRegExp Pat; + WLanData * Data; }; #endif -- cgit v0.9.0.2