7 files changed, 185 insertions, 42 deletions
diff --git a/noncore/settings/networksettings2/gprs/opie-networksettings2plugin-network.control b/noncore/settings/networksettings2/gprs/opie-networksettings2plugin-network.control index 902ebff..7e904bb 100644 --- a/noncore/settings/networksettings2/gprs/opie-networksettings2plugin-network.control +++ b/noncore/settings/networksettings2/gprs/opie-networksettings2plugin-network.control @@ -1,9 +1,9 @@ -Package: opie-networksettings2plugin-GPRS +Package: opie-networksettings2plugin-gprs Files: plugins/networksettings2/libGPRS.so* Priority: optional Section: opie/settings Maintainer: Wim Delvaux <wimpie@handhelds.org> Architecture: arm Depends: opie-networksettings2, libopiecore2, libopienet2 Description: Setup GPRS network Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp index 141484c..9512579 100644 --- a/noncore/settings/networksettings2/networksettings2/system.cpp +++ b/noncore/settings/networksettings2/networksettings2/system.cpp @@ -15,115 +15,128 @@ #include <opie2/oprocess.h> #include <qdir.h> #include <qregexp.h> #include <qstringlist.h> #include <qfile.h> #include <qtextstream.h> #include <qapplication.h> #include "resources.h" #include "system.h" #define PROCNETDEV "/proc/net/dev" #ifndef ARPHRD_IEEE80211 #define ARPHRD_IEEE80211 801 #endif static char Dig2Hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; // get HIGH nibble of byte #define HN(x) Dig2Hex[(((x)&0xf0)>>4)] // get LOW nibble of byte #define LN(x) Dig2Hex[((x)&0x0f)] System::System( void ) : QObject(), ProbedInterfaces() { - probeInterfaces(); } System::~System( void ) { if( ProcDevNet ) delete ProcDevNet; } -int System::runAsRoot( QStringList & S ) { +QDict<InterfaceInfo> & System::interfaces( void ) { + if( ProbedInterfaces.count() == 0 ) { + probeInterfaces(); + } + return ProbedInterfaces; +} + +int System::runAsRoot( QStringList & S, MyProcess * Prc ) { char * usr = getenv("USER"); if( S.count() == 0 ) { // loophole to start shell return 8888; } if( usr == 0 || strcmp( usr, "root" ) ) { // unknown or non-root user -> use SUDO S.prepend( "sudo" ); } if( getenv( "NS2TESTMODE" ) ) { owarn << "TESTMODE !!! execute " << S.join( " ") << oendl; } else { - MyProcess * P = new MyProcess(); - emit processEvent( tr("Command : ") + S.join( " " ) ); + MyProcess * P; - P->process() << S; - - connect( P, - SIGNAL( stdoutLine( const QString & ) ), - this, - SIGNAL( stdoutLine( const QString & ) ) ); - - connect( P, - SIGNAL( stderrLine( const QString & ) ), - this, - SIGNAL( stderrLine( const QString & ) ) ); + if( Prc ) { + P = Prc; + } else { + P = new MyProcess(); + emit processEvent( tr("Command : ") + S.join( " " ) ); + + connect( P, + SIGNAL( stdoutLine( const QString & ) ), + this, + SIGNAL( stdoutLine( const QString & ) ) ); + + connect( P, + SIGNAL( stderrLine( const QString & ) ), + this, + SIGNAL( stderrLine( const QString & ) ) ); + + connect( P, + SIGNAL(processExited(MyProcess*) ), + this, SLOT + (SLOT_ProcessExited(MyProcess*) ) ); + } - connect( P, - SIGNAL(processExited(MyProcess*) ), - this, SLOT - (SLOT_ProcessExited(MyProcess*) ) ); + P->process() << S; Log(("Executing %s\n", S.join( " " ).latin1() )); if( ! P->process().start( OProcess::DontCare, OProcess::AllOutput ) ) { owarn << "Error starting " << S << oendl; - delete P; + if( ! Prc ) + delete P; // error starting app return 1; } owarn << "Started " << S << oendl; } // all is fine return 0; } int System::execAsUser( QStringList & SL ) { MyProcess * P = new MyProcess(); CurrentQPEUser CU = NSResources->currentUser(); char * usr = getenv("USER"); if( strcmp( usr, "root" ) == 0 ) { // find user running qpe if( CU.UserName.isEmpty() ) { // if we come here, the exec was not successfull Log(("User not known \n" )); return 0; } } // now we are ready to exec the requested command setuid( CU.Uid ); setgid( CU.Gid ); for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) { QString X; QStringList SL; X = CU.EnvList[i]; diff --git a/noncore/settings/networksettings2/networksettings2/system.h b/noncore/settings/networksettings2/networksettings2/system.h index e67d695..f7a7274 100644 --- a/noncore/settings/networksettings2/networksettings2/system.h +++ b/noncore/settings/networksettings2/networksettings2/system.h @@ -67,69 +67,68 @@ public : { Collection = NNI; } NodeCollection * Collection; // connection taking care of me QString Name; // name of interface int CardType; // type of card QString MACAddress; // MAC address QString Address; // IP Address QString BCastAddress; // Broadcast Address QString Netmask; // Netmask QString DstAddress; // Peer address (if P-t-P) bool IsUp; // interface is UP bool HasMulticast; // Supports Multicast bool IsPointToPoint; // IsPointToPoint card QString RcvBytes; QString SndBytes; QString RcvErrors; QString SndErrors; QString RcvDropped; QString SndDropped; QString Collisions; }; class System : public QObject { Q_OBJECT public : System( void ); ~System( void ); - QDict<InterfaceInfo> & interfaces( void ) - { return ProbedInterfaces; } + QDict<InterfaceInfo> & interfaces( void ); InterfaceInfo * interface( const QString& N ) - { return ProbedInterfaces[N]; } + { return interfaces()[N]; } // exec command as root - int runAsRoot( QStringList & S ); + int runAsRoot( QStringList & S, MyProcess * Prc = 0 ); // exec command as user int execAsUser( QStringList & Cmd ); // refresh stats for this interface void refreshStatistics( InterfaceInfo & ); // reloads interfaces void probeInterfaces( void ); InterfaceInfo * findInterface( const QString & DevName ); private slots : void SLOT_ProcessExited( MyProcess * ); signals : void stdoutLine( const QString & ); void stderrLine( const QString & ); void processEvent( const QString & ); private : QDict<InterfaceInfo> ProbedInterfaces; FILE * OutputOfCmd; QFile * ProcDevNet; }; #endif diff --git a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp index 2d4885c..5a890da 100644 --- a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp +++ b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp @@ -1,61 +1,67 @@ #include <opie2/odebug.h> #include <opie2/oledbox.h> +#include <opie2/ofiledialog.h> + using namespace Opie::Core; using namespace Opie::Ui; #include <qpe/resource.h> +#include <qapplication.h> #include <qcheckbox.h> +#include <qcombobox.h> +#include <qdialog.h> +#include <qdir.h> +#include <qfile.h> #include <qgroupbox.h> -#include <qlabel.h> -#include <qprogressbar.h> #include <qheader.h> -#include <qmessagebox.h> -#include <qapplication.h> -#include <qlistbox.h> -#include <qdialog.h> -#include <qlayout.h> -#include <qcombobox.h> #include <qlabel.h> +#include <qlayout.h> +#include <qlistbox.h> #include <qlistview.h> +#include <qmessagebox.h> +#include <qprogressbar.h> #include <qpushbutton.h> +#include <qtextstream.h> #include <Opietooth.h> #include <OTDriver.h> #include <OTPeer.h> #include <OTGateway.h> #include <OTSDPAttribute.h> #include <OTSDPService.h> #include <OTInquiry.h> +#include <system.h> + using namespace Opietooth2; namespace Opietooth2 { class PeerLVI : public QListViewItem { public : PeerLVI( OTPeer * P, QListView * it ) : QListViewItem (it) { Peer = P; } ~PeerLVI( void ) { } inline OTPeer * peer( void ) { return Peer; } private : OTPeer * Peer; }; class ChannelLVI : public QListViewItem { public : ChannelLVI( int Ch, QListViewItem * it ) : QListViewItem (it) { Channel = Ch; } ~ChannelLVI( void ) { } @@ -84,74 +90,179 @@ private : OTDriver * Driver; }; class LinkKeyLVI : public QListViewItem { public : LinkKeyLVI( int Ch, QListView * it ) : QListViewItem (it) { LinkKey = Ch; } ~LinkKeyLVI( void ) { } inline int index( void ) { return LinkKey; } private : int LinkKey; }; }; // // // // // OTSniffing::OTSniffing( QWidget * parent ) : OTSniffGUI( parent ) { OT = OTGateway::getOTGateway(); - + HciDump = 0; + Sys = new System(); } OTSniffing::~OTSniffing() { + printf( "CLOSE \n" ); + if ( HciDump ) { + HciDump->process().kill(); + delete HciDump; + } + delete Sys; } -void OTSniffing::SLOT_Trace( void ) { +void OTSniffing::SLOT_Trace( bool ) { + HciDump = new MyProcess(); + QStringList SL; + + SL << "hcidump"; + switch( DataFormat_CB->currentItem() ) { + case 0 : // Hex + SL << "-x"; + break; + case 1 : // Ascii + SL << "-a"; + break; + case 2 : // both + SL << "-X"; + break; + } + + SL << "-i"; + SL << OT->scanWith()->devname(); + + connect( HciDump, + SIGNAL( stdoutLine( const QString & ) ), + this, + SLOT( SLOT_Show( const QString & ) ) ); + + connect( HciDump, + SIGNAL(processExited(MyProcess*) ), + this, + SLOT( SLOT_ProcessExited(MyProcess*) ) ); + + if( ! Sys->runAsRoot( SL, HciDump ) ) { + QMessageBox::warning(0, + tr("Run hcidump"), + tr("Cannot start %1").arg(SL.join(" ")) + ); + delete HciDump; + HciDump = 0; + } + +} + +void OTSniffing::SLOT_Show( const QString & S ) { + printf( "%s\n", S.latin1() ); + Output_LB->insertItem( S ); + Output_LB->setCurrentItem( Output_LB->count()-1 ); + Output_LB->ensureCurrentVisible(); +} + +void OTSniffing::SLOT_ProcessExited( MyProcess * ) { + printf( "Exited\n" ); + delete HciDump; + HciDump = 0; +} + +void OTSniffing::SLOT_Save( void ) { + QString S = OFileDialog::getSaveFileName( + OFileSelector::Extended, + QDir::home().path(), + QString::null, + MimeTypes(), + this ); + + if( ! S.isEmpty() ) { + QFile F( S ); + if( ! F.open( IO_WriteOnly ) ) { + QMessageBox::warning(0, + tr("Save log"), + tr("Cannot open %1").arg(S) + ); + return; + } + QTextStream TS( &F ); + TS << S << endl; + } +} + +void OTSniffing::SLOT_Load( void ) { + QString S = OFileDialog::getOpenFileName( + OFileSelector::Extended, + QDir::home().path(), + QString::null, + MimeTypes(), + this ); + + if( ! S.isEmpty() ) { + QFile F( S ); + if( ! F.open( IO_ReadOnly ) ) { + QMessageBox::warning(0, + tr("Save log"), + tr("Cannot open %1").arg(S) + ); + return; + } + QTextStream TS ( &F ); + SLOT_ClearLog(); + S = TS.read(); + Output_LB->insertStringList( QStringList::split( "\n", S ) ); + } } void OTSniffing::SLOT_ClearLog( void ) { + Output_LB->clear(); } // // // // // OTPairing::OTPairing( QWidget * parent, OTIcons * _IC ) : OTPairingGUI( parent ) { OT = OTGateway::getOTGateway(); Icons = (_IC ) ? _IC : new OTIcons(); MyIcons = (_IC == 0 ); // unpairing can only be done if bluetooth is disabled Unpair_But->setEnabled( ! OT->isEnabled() ); if( ! OT->isEnabled() ) { Unpair_LBL->hide(); } else { Unpair_LBL->show(); } // open linkkey file and load pairs LinkKeyArray Keys = OT->getLinkKeys(); LinkKeyLVI * it; OTPeer * P; OTDriver * D; for( unsigned int i = 0 ; i < Keys.count(); i ++ ) { @@ -1000,38 +1111,41 @@ void OTMain::SLOT_Scan( void ) { } void OTMain::SLOT_StateChange( OTDriver * D, bool Up ) { for( int i = 0; i < DeviceList_CB->count(); i ++ ) { if( DeviceList_CB->text(i) == D->devname() ) { DeviceList_CB->changeItem( Icons->loadPixmap( (Up) ? "bluezon" : "bluezoff" ), D->devname(), i ); return; } } } void OTMain::SLOT_Pairing( void ) { QDialog * Dlg = new QDialog( this, 0, TRUE ); QVBoxLayout * V = new QVBoxLayout( Dlg ); OTPairing * Pair = new OTPairing( Dlg, Icons ); V->addWidget( Pair ); Dlg->showMaximized(); Dlg->setCaption( tr("Manage pairing" ) ); Dlg->exec(); delete Dlg; } void OTMain::SLOT_Sniffing( void ) { if( SnifWindow == 0 ) { - SnifWindow = new OTSniffing( this ); + SnifWindow = new QDialog( this, 0, FALSE ); + QVBoxLayout * V = new QVBoxLayout( SnifWindow ); + OTSniffing * SN = new OTSniffing( SnifWindow ); + V->addWidget( SN ); } SnifWindow->showMaximized(); SnifWindow->show(); } diff --git a/noncore/settings/networksettings2/opietooth2/Opietooth.h b/noncore/settings/networksettings2/opietooth2/Opietooth.h index 211ae65..2b20975 100644 --- a/noncore/settings/networksettings2/opietooth2/Opietooth.h +++ b/noncore/settings/networksettings2/opietooth2/Opietooth.h @@ -1,69 +1,86 @@ #ifndef OPIETOOTH_H #define OPIETOOTH_H #include <OTIcons.h> -namespace Opie { namespace Ui { class OLedBox; }; }; +class MyProcess; +class System; + +namespace Opie { + + namespace Ui { + + class OLedBox; + + }; + +}; #include <OTSniffGUI.h> namespace Opietooth2 { class OTGateway; class OTDriver; class OTInquiry; class OTPeer; class PeerLVI; class OTSniffing : public OTSniffGUI { Q_OBJECT public : OTSniffing( QWidget * parent ); ~OTSniffing(); private slots : - void SLOT_Trace( void ); + void SLOT_Trace( bool ); void SLOT_ClearLog( void ); + void SLOT_Load( void ); + void SLOT_Save( void ); + void SLOT_ProcessExited( MyProcess * ); + void SLOT_Show( const QString & ); signals : protected : private : OTGateway * OT; + MyProcess * HciDump; + System * Sys; }; }; #include <OTPairingGUI.h> namespace Opietooth2 { class OTPairing : public OTPairingGUI { Q_OBJECT public : OTPairing( QWidget * parent, OTIcons * _Ic = 0 ); ~OTPairing(); private slots : void SLOT_Unpair( void ); signals : protected : private : bool MyIcons; OTIcons * Icons; OTGateway * OT; }; }; @@ -188,36 +205,36 @@ private : namespace Opietooth2 { class OTMain : public OTMainGUI { Q_OBJECT public : OTMain( QWidget * parent ); ~OTMain(); public slots : private slots : void SLOT_Pairing( void ); void SLOT_Manage( void ); void SLOT_Sniffing( void ); void SLOT_Scan( void ); void SLOT_EnableBluetooth( bool ); void SLOT_DriverListChanged(); void SLOT_DeviceIsEnabled( bool ); void SLOT_StateChange( OTDriver * , bool ); signals : protected : private : // load scanned devices OTIcons * Icons; OTGateway * OT; - OTSniffing * SnifWindow; + QDialog * SnifWindow; }; }; #endif diff --git a/noncore/settings/networksettings2/opietooth2/libopietooth2.control b/noncore/settings/networksettings2/opietooth2/libopietooth2.control index fd01fb5..c2c8eb8 100644 --- a/noncore/settings/networksettings2/opietooth2/libopietooth2.control +++ b/noncore/settings/networksettings2/opietooth2/libopietooth2.control @@ -1,9 +1,9 @@ Package: libopietooth2 Files: lib/libopietooth2.so.* apps/Settings/opietooth-manager.desktop pics/opietooth/*.png pics/opietooth/icons/*.png Priority: optional Section: opie/system Maintainer: wim delvaux <wim.delvaux@handhelds.org> Architecture: arm Version: $QPE_VERSION$EXTRAVERSION -Depends: task-opie-minimal, libbluetooth1, opie-bluepin | opie-multiauth-bluepingplugin, bluez-utils-nodbus +Depends: task-opie-minimal, opie-networksettings2, libbluetooth1, opie-bluepin | opie-multiauth-bluepingplugin, bluez-utils-nodbus Description: Opie bluetooth support library version 2 diff --git a/noncore/settings/networksettings2/opietooth2/opietooth2.pro b/noncore/settings/networksettings2/opietooth2/opietooth2.pro index cfb527d..e0057a9 100644 --- a/noncore/settings/networksettings2/opietooth2/opietooth2.pro +++ b/noncore/settings/networksettings2/opietooth2/opietooth2.pro @@ -1,37 +1,37 @@ TEMPLATE = lib CONFIG += qt warn_on release #CONFIG += qt warn_on debug DESTDIR = $(OPIEDIR)/lib$(PROJMAK) HEADERS = OTDevice.h \ OTDriver.h \ OTGateway.h \ OTHCISocket.h \ OTInquiry.h \ OTDeviceAddress.h \ OTIcons.h \ OTUUID.h \ OTSDPAttribute.h \ OTSDPService.h \ OTPeer.h \ Opietooth.h SOURCES = OTDevice.cpp \ OTDriver.cpp \ OTDriverList.cpp \ OTHCISocket.cpp \ OTInquiry.cpp \ OTDeviceAddress.cpp \ OTUUID.cpp \ OTSDPAttribute.cpp \ OTSDPService.cpp \ OTIcons.cpp \ OTPeer.cpp \ OTGateway.cpp \ Opietooth.cpp -INCLUDEPATH += $(OPIEDIR)/include +INCLUDEPATH += $(OPIEDIR)/include ../networksettings2 DEPENDPATH += $(OPIEDIR)/include -LIBS += -lqpe -lopiecore2 -lbluetooth +LIBS += -lqpe -lopiecore2 -lbluetooth -lnetworksettings2 INTERFACES = OTMainGUI.ui OTSniffGUI.ui OTScanGUI.ui OTManageGUI.ui OTPairingGUI.ui TARGET = opietooth2 VERSION = 1.0.0 include ( $(OPIEDIR)/include.pro ) |