Diffstat (limited to 'noncore/settings/networksettings2/bluetooth') (more/less context) (ignore whitespace changes)
6 files changed, 311 insertions, 20 deletions
diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth.pro b/noncore/settings/networksettings2/bluetooth/bluetooth.pro index 180bda9..2e1e138 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetooth.pro +++ b/noncore/settings/networksettings2/bluetooth/bluetooth.pro @@ -1,21 +1,22 @@ TEMPLATE = lib CONFIG += qt warn_on release DESTDIR = $(OPIEDIR)/plugins/networksettings2 HEADERS = bluetooth_NN.h \ bluetoothBNEP_NNI.h \ bluetoothRFCOMM_NNI.h \ bluetoothBNEPedit.h \ bluetoothRFCOMMedit.h SOURCES = bluetooth_NN.cpp \ bluetoothBNEP_NNI.cpp \ bluetoothRFCOMM_NNI.cpp \ bluetoothBNEPedit.cpp \ + bluetoothBNEPrun.cpp \ bluetoothRFCOMMedit.cpp INCLUDEPATH += $(OPIEDIR)/include ../ ../networksettings2 DEPENDPATH += $(OPIEDIR)/include ../ ../networksettings2 LIBS += -lqpe INTERFACES = bluetoothBNEPGUI.ui bluetoothRFCOMMGUI.ui TARGET = bluetooth VERSION = 1.0.0 include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp index 73312c6..d8420b9 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp @@ -1,37 +1,50 @@ #include "bluetoothBNEPedit.h" #include "bluetoothBNEP_NNI.h" #include "bluetooth_NN.h" -ABluetoothBNEP::ABluetoothBNEP( BluetoothBNEPNetNode * PNN ) : ANetNodeInstance( PNN ) { +ABluetoothBNEP::ABluetoothBNEP( BluetoothBNEPNetNode * PNN ) : + ANetNodeInstance( PNN ), Data() { GUI = 0; RT = 0; + Data.AllowAll = 1; } -void ABluetoothBNEP::setSpecificAttribute( QString & , QString & ) { +void ABluetoothBNEP::setSpecificAttribute( QString & S, QString & A ) { + if( S == "bdaddress" ) { + Data.BDAddress << A; + } else if ( S == "allowall" ) { + Data.AllowAll = 1; + } } -void ABluetoothBNEP::saveSpecificAttribute( QTextStream & ) { +void ABluetoothBNEP::saveSpecificAttribute( QTextStream & TS ) { + TS << "allowall=" << Data.AllowAll << endl; + for ( QStringList::Iterator it = Data.BDAddress.begin(); + it != Data.BDAddress.end(); + ++it ) { + TS << "bdaddress=" << (*it) << endl; + } } QWidget * ABluetoothBNEP::edit( QWidget * parent ) { - GUI = new BluetoothBNEPEdit( parent ); - GUI->showData( Data ); - return GUI; + GUI = new BluetoothBNEPEdit( parent ); + GUI->showData( Data ); + return GUI; } QString ABluetoothBNEP::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void ABluetoothBNEP::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } bool ABluetoothBNEP::hasDataFor( const QString & ) { return 0; } bool ABluetoothBNEP::generateDataForCommonFile( SystemFile & , long ){ return 0; } diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h index 037b7b1..03c6903 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h @@ -1,8 +1,11 @@ #ifndef BLUETOOTHBNEP_DATA_H #define BLUETOOTHBNEP_DATA_H +#include <qstringlist.h> + typedef struct BluetoothBNEPData { - long x; + bool AllowAll; + QStringList BDAddress; } BluetoothBNEPData_t; #endif diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPedit.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPedit.cpp index 9a3156b..195dbae 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPedit.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPedit.cpp @@ -1,26 +1,48 @@ #include <qtopia/qcopenvelope_qws.h> +#include <qlistview.h> +#include <qcheckbox.h> #include <GUIUtils.h> #include "bluetoothBNEPedit.h" BluetoothBNEPEdit::BluetoothBNEPEdit( QWidget * Parent ) : BluetoothBNEPGUI( Parent ){ } QString BluetoothBNEPEdit::acceptable( void ) { + if( ( ! AnyPAN_CB->isChecked() ) && + BTPANServers_LV->firstChild() == 0 ) { + return tr("<p>No bluetooth device addresses specified</p>"); + } + return QString(); } -bool BluetoothBNEPEdit::commit( BluetoothBNEPData & ) { - return 0; +bool BluetoothBNEPEdit::commit( BluetoothBNEPData & Data ) { + QListViewItem * it = BTPANServers_LV->firstChild(); + Data.BDAddress.clear(); + while( it ) { + Data.BDAddress << it->text(0); + it = it->nextSibling(); + } + return 0; } -void BluetoothBNEPEdit::showData( BluetoothBNEPData & ) { +void BluetoothBNEPEdit::showData( BluetoothBNEPData & Data ) { + QListViewItem * lvit; + BTPANServers_LV->clear(); + + for ( QStringList::Iterator it = Data.BDAddress.begin(); + it != Data.BDAddress.end(); + ++it ) { + lvit = new QListViewItem(BTPANServers_LV); + lvit->setText( 0, (*it) ); + } } void BluetoothBNEPEdit::SLOT_StartBTMgr( void ) { QCopEnvelope e( "QPE/System", "execute(QString)" ); e << QString( "bluetooth-manager" ); } diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.cpp new file mode 100644 index 0000000..24e4b7b --- a/dev/null +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.cpp @@ -0,0 +1,249 @@ +#include <qfile.h> +#include <qfileinfo.h> +#include <qtextstream.h> +#include <resources.h> +#include "bluetoothBNEPrun.h" + +QDict<QString> * BluetoothBNEPRun::PANConnections = 0; + +void BluetoothBNEPRun::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 ); + + Log(("Detecting for %s\n", NC->name().latin1() )); + + if( F.open( IO_ReadOnly ) ) { + // could open file -> read interface and assign + QString X; + bool accepted = 0; + QTextStream TS(&F); + X = TS.readLine(); + Log(("%s exists : %s\n", S.latin1(), X.latin1() )); + // find interface + if( handlesInterface( X ) ) { + + Log(("Handles interface %s, PANC %p\n", X.latin1(), PANConnections )); + if( PANConnections == 0 ) { + // load connections that are active + // format : bnep0 00:60:57:02:71:A2 PANU + FILE * OutputOfCmd = popen( "pand --show", "r" ) ; + + PANConnections = new QDict<QString>; + + if( OutputOfCmd ) { + char ch; + // could fork + // read all data + QString Line = ""; + while( 1 ) { + if( fread( &ch, 1, 1, OutputOfCmd ) < 1 ) { + // eof + break; + } + if( ch == '\n' || ch == '\r' ) { + if( ! Line.isEmpty() ) { + if( Line.startsWith( "bnep" ) ) { + QStringList SL = QStringList::split( " ", Line ); + Log(("Detected PAN %s %s\n", + SL[0].latin1(), SL[1].latin1() )); + PANConnections->insert( SL[0], new QString(SL[1])); + } + Line=""; + } + } else { + Line += ch; + } + } + } + + pclose( OutputOfCmd ); + } + + // check if this runtime allows connection to node + if( ! Data.AllowAll ) { + // has addresses + for ( QStringList::Iterator it = Data.BDAddress.begin(); + ! accepted && it != Data.BDAddress.end(); + ++ it ) { + for( QDictIterator<QString> it2( *(PANConnections) ); + it2.current(); + ++ it2 ) { + if( X == it2.currentKey() && + (*it) == *(it2.current()) + ) { + // found + Log(("%s accepts connections to %s\n", + NC->name().latin1(), + it2.current()->latin1() )); + accepted = 1; + break; + } + } + } + } else { + Log(("%s accepts any connection\n", NC->name().latin1() )); + // accept any + accepted = 1; + } + + if( accepted ) { + // matches and is allowed for this node + for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); + It.current(); + ++It ) { + Run = It.current(); + if( X == Run->Name ) { + Log(("%s Assigned %p\n", NC->name().latin1(), Run )); + Run->assignNode( netNode() ); + assignInterface( Run ); + NC->setCurrentState( IsUp ); + return; + } + } + } + } + } + + Log(("Assigned %p\n", assignedInterface() )); + 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<InterfaceInfo> It(Sys.interfaces()); + It.current(); + ++It ) { + Run = It.current(); + + Log(("%s %d %d=%d %d\n", + Run->Name.latin1(), + handlesInterface( Run->Name ), + Run->CardType, ARPHRD_ETHER, + ! Run->IsUp )); + + if( handlesInterface( Run->Name ) && + Run->CardType == ARPHRD_ETHER && + ! Run->IsUp + ) { + Log(("Released(OFF)\n" )); + // proper type, and Not UP -> free + NC->setCurrentState( Off ); + return; + } + } + // no free found + Log(("None available\n" )); + + NC->setCurrentState( Unavailable ); +} + +bool BluetoothBNEPRun::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 ); + Log(("Assing %p\n", 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 BluetoothBNEPRun::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 * BluetoothBNEPRun::getInterface( void ) { + + System & S = NSResources->system(); + InterfaceInfo * best = 0, * Run; + + for( QDictIterator<InterfaceInfo> It(S.interfaces()); + It.current(); + ++It ) { + Run = It.current(); + if( handlesInterface( Run->Name ) && + Run->CardType == ARPHRD_ETHER + ) { + // this is a bluetooth card + if( Run->assignedNode() == netNode() ) { + // assigned to us + return Run; + } else if( Run->assignedNode() == 0 ) { + // free + best = Run; + } + } + } + return best; // can be 0 +} + +bool BluetoothBNEPRun::handlesInterface( const QString & S ) { + return Pat.match( S ) >= 0; +} diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h index c168429..ce03cbb 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h @@ -1,31 +1,34 @@ #include <asdevice.h> #include "bluetoothBNEPdata.h" class BluetoothBNEPRun : public AsDevice { public : BluetoothBNEPRun( ANetNodeInstance * NNI, - BluetoothBNEPData & Data ) : AsDevice( NNI ) + BluetoothBNEPData & D ) : + AsDevice( NNI ), + Data( D), + Pat( "bnep[0-6]" ) { } virtual AsDevice * asDevice( void ) { return (AsDevice *)this; } virtual AsDevice * device( void ) { return asDevice(); } protected : - void detectState( NodeCollection * ) - { } - - bool setState( NodeCollection * , Action_t, bool ) - { return 0; } + void detectState( NodeCollection * ); + bool setState( NodeCollection * , Action_t, bool ); + bool canSetState( State_t , Action_t ); + bool handlesInterface( const QString & ); - bool canSetState( State_t , Action_t ) - { return 0; } +private : - bool handlesInterface( const QString & ) - { return 0; } + InterfaceInfo * getInterface( void ); + BluetoothBNEPData & Data; + static QDict<QString> * PANConnections; + QRegExp Pat; }; |