summaryrefslogtreecommitdiff
authorwimpie <wimpie>2005-01-09 00:32:10 (UTC)
committer wimpie <wimpie>2005-01-09 00:32:10 (UTC)
commite54346d28b19d3ac671802a25e8c03f346693291 (patch) (side-by-side diff)
tree0f8d6561e24a7ba36fd8a6ab1869aa470e1fdb36
parent60a617583d0ccc793d9ea4465998d90ec208db58 (diff)
downloadopie-e54346d28b19d3ac671802a25e8c03f346693291.zip
opie-e54346d28b19d3ac671802a25e8c03f346693291.tar.gz
opie-e54346d28b19d3ac671802a25e8c03f346693291.tar.bz2
Updated dependencies
NS2->app requires OT2Lib and NS2Lib OT2Lib requires NS2Lib Most plugins only require NS2Lib Except BTPlugin which requires als OT2Lib Also renamed owarn -> odebug
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp8
-rw-r--r--noncore/settings/networksettings2/bluetooth/config.in2
-rw-r--r--noncore/settings/networksettings2/config.in2
-rw-r--r--noncore/settings/networksettings2/editconnection.cpp1
-rw-r--r--noncore/settings/networksettings2/gprs/GPRSrun.cpp8
-rw-r--r--noncore/settings/networksettings2/network/networkrun.cpp33
-rw-r--r--noncore/settings/networksettings2/networksettings.cpp6
-rw-r--r--noncore/settings/networksettings2/networksettings2/config.in2
-rw-r--r--noncore/settings/networksettings2/networksettings2/system.cpp16
-rw-r--r--noncore/settings/networksettings2/networksettings2/systemfile.cpp18
-rwxr-xr-xnoncore/settings/networksettings2/opie-networksettings2.postinst2
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTDevice.cpp6
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTDriver.cpp16
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTDriverList.cpp4
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTGateway.cpp14
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTHCISocket.cpp14
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTInquiry.cpp18
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTPeer.cpp20
-rw-r--r--noncore/settings/networksettings2/opietooth2/Opietooth.cpp12
-rw-r--r--noncore/settings/networksettings2/opietooth2/config.in4
-rwxr-xr-xnoncore/settings/networksettings2/opietooth2/libopietooth2.postinst2
-rw-r--r--noncore/settings/networksettings2/opietooth2/opietooth2.pro7
-rw-r--r--noncore/settings/networksettings2/profile/profilerun.cpp2
-rw-r--r--noncore/settings/networksettings2/usb/usbrun.cpp43
24 files changed, 131 insertions, 129 deletions
diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp
index ef6878a..3df7f5c 100644
--- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp
+++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp
@@ -1,164 +1,164 @@
#include <qapplication.h>
#include <resources.h>
#include <OTDevice.h>
#include <OTGateway.h>
#include "bluetoothRFCOMMrun.h"
using Opietooth2::OTGateway;
using Opietooth2::OTDevice;
using Opietooth2::OTDeviceAddress;
BluetoothRFCOMMRun::~BluetoothRFCOMMRun( void ) {
if( OT ) {
OTGateway::releaseOTGateway();
}
}
State_t BluetoothRFCOMMRun::detectState( void ) {
if( ! OT ) {
OT = OTGateway::getOTGateway();
}
if( deviceNrOfConnection() >= 0 ) {
return Available;
}
- owarn << "Bluetooth "
+ odebug << "Bluetooth "
<< OT->isEnabled()
<< oendl;
return ( OT->isEnabled() ) ? Off : Unavailable;
}
QString BluetoothRFCOMMRun::setMyState( NodeCollection *,
Action_t A,
bool ) {
if( OT ) {
OTGateway::getOTGateway();
}
if( A == Activate ) {
// from OFF to Available
RFCOMMChannel * Ch = getChannel( );
System & Sys = NSResources->system();
if( Ch ) {
// connect to this peer
DeviceNr = OT->getFreeRFCommDevice();
QStringList S;
S << "rfcomm"
<< "bind"
<< QString().setNum( DeviceNr )
<< Ch->BDAddress
<< QString().setNum( Ch->Channel );
if( Sys.runAsRoot( S ) ) {
return QString( "Error starting %1").arg(S.join(" "));
}
// here rfcomm should be running -> we will detect state later
return QString();
} else {
Log(( "No channel selected -> cancel\n" ));
return QString( "No channel selected. Operation cancelled" );
}
}
if( A == Deactivate ) {
if( DeviceNr >= 0 ) {
if( OT->releaseRFCommDevice( DeviceNr ) ) {
return QString( "Cannot release RFCOMM connection" );
}
DeviceNr = -1;
}
}
return QString();
}
#include <qlistbox.h>
#include <qframe.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qdialog.h>
RFCOMMChannel * BluetoothRFCOMMRun::getChannel( void ) {
if( Data->Devices.count() == 1 ) {
// only one device -> return channel
return Data->Devices[0];
}
RFCOMMChannel * Ch = 0;
QDialog * Dlg = new QDialog( qApp->mainWidget(), 0, TRUE );
QVBoxLayout * V = new QVBoxLayout( Dlg );
QLabel * L = new QLabel(
qApp->translate( "BluetoothRFCOMMRun",
"Select device to connect to"),
Dlg );
QListBox * LB = new QListBox( Dlg );
for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) {
LB->insertItem( QString( "%1 (%2 Chnl %3)" ).
arg( Data->Devices[i]->Name ).
arg( Data->Devices[i]->BDAddress ).
arg( Data->Devices[i]->Channel ) );
}
V->addWidget( L );
V->addWidget( LB );
Dlg->resize( 100, 100 );
Dlg->move( 20,
(qApp->desktop()->height()-100)/2 );
if( Dlg->exec() == QDialog::Accepted ) {
unsigned int i = 0;
for( i = 0; i < Data->Devices.count(); i ++ ) {
if( LB->isSelected(i) ) {
- owarn << "Selected " << Data->Devices[i]->Name << oendl;
+ odebug << "Selected " << Data->Devices[i]->Name << oendl;
Ch = Data->Devices[i];
break;
}
}
}
delete Dlg;
return Ch;
}
QString BluetoothRFCOMMRun::deviceFile( void ) {
if( deviceNrOfConnection() >= 0 ) {
OTDevice * OTD = OT->getOTDevice();
// there is a connection
return OTD->getRFCommDevicePattern().arg(DeviceNr);
}
return QString();
}
int BluetoothRFCOMMRun::deviceNrOfConnection( void ) {
if( ! OT ) {
OT = OTGateway::getOTGateway();
}
DeviceNr = -1;
for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) {
- owarn << "Check for rfcomm on "
+ odebug << "Check for rfcomm on "
<< Data->Devices[i]->BDAddress
<< " "
<< Data->Devices[i]->Channel
<< oendl;
if( ( DeviceNr = OT->connectedToRFCommChannel(
OTDeviceAddress( Data->Devices[i]->BDAddress ),
Data->Devices[i]->Channel ) ) >= 0 ) {
- owarn << "Up "
+ odebug << "Up "
<< oendl;
break;
}
}
return DeviceNr;
}
diff --git a/noncore/settings/networksettings2/bluetooth/config.in b/noncore/settings/networksettings2/bluetooth/config.in
index 398cff1..1a76f96 100644
--- a/noncore/settings/networksettings2/bluetooth/config.in
+++ b/noncore/settings/networksettings2/bluetooth/config.in
@@ -1,4 +1,4 @@
config NS2BT
boolean "opie-networksettings2plugin-bluetooth (set up BLUETOOTH)"
default "n" if NS2
- depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && NS2CORE && NS2OPIETOOTH
+ depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && NS2CORE && NS2OPIETOOTH && LIBBLUEZ_DEP
diff --git a/noncore/settings/networksettings2/config.in b/noncore/settings/networksettings2/config.in
index d2b5f26..0236bab 100644
--- a/noncore/settings/networksettings2/config.in
+++ b/noncore/settings/networksettings2/config.in
@@ -1,21 +1,21 @@
source noncore/settings/networksettings2/networksettings2/config.in
source noncore/settings/networksettings2/opietooth2/config.in
source noncore/settings/networksettings2/opietooth2_applet/config.in
config NS2
- boolean
+ boolean "opie-networksettings2 application"
default "y"
depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && NS2CORE && NS2OPIETOOTH
source noncore/settings/networksettings2/profile/config.in
source noncore/settings/networksettings2/network/config.in
source noncore/settings/networksettings2/lancard/config.in
source noncore/settings/networksettings2/ppp/config.in
source noncore/settings/networksettings2/wlan/config.in
source noncore/settings/networksettings2/usb/config.in
source noncore/settings/networksettings2/irda/config.in
source noncore/settings/networksettings2/vpn/config.in
source noncore/settings/networksettings2/bluetooth/config.in
source noncore/settings/networksettings2/cable/config.in
source noncore/settings/networksettings2/modem/config.in
source noncore/settings/networksettings2/gprs/config.in
diff --git a/noncore/settings/networksettings2/editconnection.cpp b/noncore/settings/networksettings2/editconnection.cpp
index 0c3ead6..717d9e9 100644
--- a/noncore/settings/networksettings2/editconnection.cpp
+++ b/noncore/settings/networksettings2/editconnection.cpp
@@ -62,193 +62,192 @@ public:
QListViewItem( parent, S ) { }
MyQListViewItem( QListViewItem *parent, const QString & S ) :
QListViewItem( parent, S ) { }
virtual void paintCell( QPainter *p, const QColorGroup &cg,
int column, int width, int alignment );
};
void MyQListViewItem::paintCell( QPainter *p, const QColorGroup &cg,
int column, int width, int alignment )
{
QColorGroup _cg( cg );
QColor c = _cg.text();
if ( ! isSelectable() )
_cg.setColor( QColorGroup::Text, Qt::lightGray );
QListViewItem::paintCell( p, _cg, column, width, alignment );
_cg.setColor( QColorGroup::Text, c );
}
//
//
// REAL GUI
//
//
bool EditConnection::AutoCollapse = 1;
EditConnection::EditConnection( QWidget* parent ) :
EditConnectionGUI( parent, 0, TRUE ), TmpCollection() {
Tab_TB->setTabEnabled( Setup_FRM, FALSE );
Setup_FRM->setEnabled( FALSE );
TmpIsValid = 0;
SelectedNodes = 0;
AutoCollapse_CB->setChecked( AutoCollapse );
Mapping = new QPtrDict<ANetNode>;
Mapping->setAutoDelete( FALSE );
Nodes_LV->header()->hide();
// popluate tree with all NetNodes
buildFullTree();
}
NodeCollection * EditConnection::getTmpCollection( void ) {
if( TmpIsValid )
// content is stil OK
return &(TmpCollection);
// reset collection -> delete all NEW NetNodes
for( QListIterator<ANetNodeInstance> it(TmpCollection);
it.current();
++it ) {
if( it.current()->isNew() ) {
delete it.current();
}
}
TmpCollection.clear();
// update content
QListViewItem * it = Nodes_LV->firstChild();
ANetNode * NN;
// start iter (if there is a collection)
/*
a node collection is sorted from the toplevel
node to the deepest node
*/
ANetNodeInstance * NNI =
(SelectedNodes) ? SelectedNodes->first() : 0 ;
TmpCollection.setModified( 0 );
// the listview always starts with the toplevel
// hierarchy. This is always a controller item
while ( it ) {
NN = (*Mapping)[it];
if( NN == 0 ) {
// this item is a controller ->
// has radio items as children ->
// find selected one
it = it->firstChild();
while( it ) {
if( ((QCheckListItem *)it)->isOn() ) {
// this radio is selected -> go deeper
break;
}
it = it->nextSibling();
}
if( ! it ) {
- owarn << "Radio not selected" << oendl;
TmpIsValid = 0;
return 0;
}
// it now contains selected radio
NN = (*Mapping)[it];
}
// NN here contains the netnode of the
// current item -> this node needs to
// be stored in the collection
if( NNI == 0 ||
it->text(0) != NNI->nodeClass()->name() ) {
// new item not in previous collection
ANetNodeInstance * NNI = NN->createInstance();
NNI->initialize();
// this node type not in collection
TmpCollection.append( NNI );
// master collection changed because new item in it
TmpCollection.setModified( 1 );
// no more valid items in old list
NNI = 0;
} else {
// already in list -> copy pointer
TmpCollection.append( NNI );
NNI = SelectedNodes->next();
}
// go deeper to next level
// this level is can be a new controller
// or an item
it = it->firstChild();
}
TmpIsValid = 1;
return &(TmpCollection);
}
// pass a connection NodeCollection to be edited
void EditConnection::setConnection( NodeCollection * NC ) {
ANetNodeInstance * NNI;
ANetNode * NN;
SelectedNodes = NC;
Name_LE->setText( NC->name() );
NNI = NC->first();
// show configure tabl
Tab_TB->setCurrentPage( 1 );
// valid colledction
Tab_TB->setTabEnabled( Setup_FRM, FALSE );
Setup_FRM->setEnabled( FALSE );
// select items in collection
QListViewItem * it = Nodes_LV->firstChild();
bool Found;
TmpIsValid = 0;
while ( it ) {
NN = (*Mapping)[it];
if( NN == 0 ) {
// this item is a controller ->
// has radio items as children ->
// find selected one
it = it->firstChild();
Found = 0;
while( it ) {
if( NNI && it->text(0) == NNI->nodeClass()->name() ) {
// this radio is part of the collection
((QCheckListItem *)it)->setOn( 1 );
updateGUI( it, NNI->nodeClass() );
// check its children
Found = 1;
it = it->firstChild();
NNI = SelectedNodes->next();
// do not bother to check other items
break;
}
it = it->nextSibling();
}
if( ! Found ) {
// this means that this level is NOT present in collection
// probably INCOMPATIBEL collection OR Missing plugin
QMessageBox::warning(
0,
tr( "Error presentig Connection" ),
tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ).
arg(NNI->nodeClass()->name()) );
return;
}
// it now contains selected radio
NN = (*Mapping)[it];
diff --git a/noncore/settings/networksettings2/gprs/GPRSrun.cpp b/noncore/settings/networksettings2/gprs/GPRSrun.cpp
index e842b99..cccc71a 100644
--- a/noncore/settings/networksettings2/gprs/GPRSrun.cpp
+++ b/noncore/settings/networksettings2/gprs/GPRSrun.cpp
@@ -1,105 +1,105 @@
#include <sys/types.h>
#include <signal.h>
#include <errno.h>
#include <qdir.h>
#include <system.h>
#include <resources.h>
#include <netnode.h>
#include "GPRSrun.h"
State_t GPRSRun::detectState( void ) {
// is pppd still running ?
// is rfcomm still active
NodeCollection * NC = nodeCollection();
InterfaceInfo * I = NC->assignedInterface();
QDir D("/var/run");
if( I ) {
// has some pppx attached
return ( I->IsUp ) ? IsUp : Available;
}
// check ppp itself and figure out interface
- owarn << "Check for ppp " << NC->name() << oendl;
+ odebug << "Check for ppp " << NC->name() << oendl;
if( D.exists( QString("ppp-")+removeSpaces(NC->name())+".pid") ) {
// get pid and check if pppd is still running
QFile F( D.path()+"/ppp-"+removeSpaces(NC->name())+".pid");
- owarn << "PPP PID " << F.name() << oendl;
+ odebug << "PPP PID " << F.name() << oendl;
if( F.open( IO_ReadOnly ) ) {
QTextStream TS(&F);
QString X = TS.readLine();
PPPPid = X.toULong();
int rv;
rv = ::kill( PPPPid, 0 );
if( rv == 0 ||
( rv < 0 && errno == EPERM )
) {
// pppd is still up
X = TS.readLine();
I = NSResources->system().findInterface(X);
- owarn << "ppp running : IFace " << X << " = " << (long)I << oendl;
+ odebug << "ppp running : IFace " << X << " = " << (long)I << oendl;
if( I ) {
NC->assignInterface( I );
return (I->IsUp) ? IsUp : Available;
}
return Available;
} else {
// pppd is down
PPPPid = 0;
}
} // else pppd is down
}
NC->assignInterface( 0 );
return Unknown;
}
QString GPRSRun::setMyState( NodeCollection * NC, Action_t A , bool ) {
if( A == Up ) {
// start ppp on deviceFile
QStringList SL;
SL << "pon"
<< removeSpaces( NC->name() )
<< NC->device()->deviceFile();
if( ! NSResources->system().execAsUser( SL ) ) {
return QString("Cannot start pppd for %1").arg(NC->name());
}
} else if ( A == Down ) {
if( PPPPid == 0 ) {
detectState();
}
if( PPPPid ) {
QStringList SL;
SL << "poff"
<< removeSpaces( NC->name() );
if( ! NSResources->system().execAsUser( SL ) ) {
return QString("Cannot terminate pppd for %1").arg(NC->name());
}
NC->assignInterface( 0 );
- owarn << "ppp stopped " << oendl;
+ odebug << "ppp stopped " << oendl;
PPPPid = 0;
}
}
return QString();
}
bool GPRSRun::handlesInterface( const QString & S ) {
return Pat.match( S ) >= 0;
}
bool GPRSRun::handlesInterface( InterfaceInfo * I ) {
return handlesInterface( I->Name );
}
diff --git a/noncore/settings/networksettings2/network/networkrun.cpp b/noncore/settings/networksettings2/network/networkrun.cpp
index c17aa7f..2c93d9d 100644
--- a/noncore/settings/networksettings2/network/networkrun.cpp
+++ b/noncore/settings/networksettings2/network/networkrun.cpp
@@ -1,51 +1,50 @@
#include <system.h>
#include <netnode.h>
#include <resources.h>
#include "networkrun.h"
State_t NetworkRun::detectState( void ) {
InterfaceInfo * II = nodeCollection()->assignedInterface();
Log(( "Interface %p : %d\n", II, (II) ? II->IsUp : 0 ));
if( II && II->IsUp ) {
// device has assigned interface
return IsUp;
}
// had no interface or interface is no longer up -> release
nodeCollection()->assignInterface( 0 );
return Unknown;
}
QString NetworkRun::setMyState( NodeCollection * NC, Action_t A, bool ) {
// we handle UP and DOWN
InterfaceInfo * II = NC->assignedInterface();
+ if( ! II ) {
+ Log(( "no interface assigned." ));
+ return QString();
+ }
+
+ QStringList SL;
+
if( A == Up ) {
// we can bring UP if lower level is available
- QStringList SL;
- SL << "ifup"
- << QString().sprintf( "%s=%s-c%d-allowed",
- II->Name.latin1(), II->Name.latin1(),
- nodeCollection()->number() );
- if( ! NSResources->system().runAsRoot( SL ) ) {
- return QString("Cannot call %1").arg(SL.join(" "));
- }
+ SL << "ifup";
+ } else if( A == Down ) {
+ SL << "ifdown";
+ } else {
return QString();
}
- if( A == Down ) {
- QStringList SL;
- if( II ) {
- SL << "ifdown"
- << II->Name.latin1();
+ SL << QString().sprintf( "%s=%s-c%d-allowed",
+ II->Name.latin1(), II->Name.latin1(),
+ nodeCollection()->number() );
+
if( ! NSResources->system().runAsRoot( SL ) ) {
return QString( "Cannot call %1" ).arg( SL.join( " " ));
}
- } else {
- Log(( "no interface assigned." ));
- }
- }
+
return QString();
}
diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp
index 9680a96..78b6cce 100644
--- a/noncore/settings/networksettings2/networksettings.cpp
+++ b/noncore/settings/networksettings2/networksettings.cpp
@@ -16,443 +16,439 @@
#include <qiconview.h>
#include <qtimer.h>
#include <qpe/qpeapplication.h>
#include <qtoolbutton.h>
#include <qevent.h>
#include "networksettings.h"
#include "netnode.h"
#include "editconnection.h"
NetworkSettings::NetworkSettings( QWidget *parent,
const char *name,
WFlags fl ) : NetworkSettingsGUI(parent,name,fl),
NSD() {
UpdateTimer = new QTimer( this );
// set pixmaps
Add_TB->setPixmap( NSResources->getPixmap( "add" ) );
Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) );
CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) );
GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) );
Disable_TB->setPixmap( NSResources->getPixmap( "disabled" ) );
Up_TB->setPixmap( NSResources->getPixmap( "more" ) );
Down_TB->setPixmap( NSResources->getPixmap( "less" ) );
QVBoxLayout* V = new QVBoxLayout( LED_Frm );
QHBoxLayout * H = new QHBoxLayout( 0 );
V->addStretch(1);
V->addLayout( H );
Leds[0] = new Opie::Ui::OLedBox( red, LED_Frm );
H->addWidget( Leds[0], 0, Qt::AlignVCenter );
Leds[1] = new Opie::Ui::OLedBox( red, LED_Frm );
H->addWidget( Leds[1], 0, Qt::AlignVCenter );
Leds[2] = new Opie::Ui::OLedBox( red, LED_Frm );
H->addWidget( Leds[2], 0, Qt::AlignVCenter );
V->addStretch(1);
SLOT_ToProfile();
// populate main Listbox
Profiles_LB->clear();
QPEApplication::setStylusOperation(
Profiles_LB->viewport(), QPEApplication::RightOnHold );
connect( Profiles_LB,
SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)),
this, SLOT(SLOT_EditNode(QListBoxItem*)) );
{ Name2Connection_t & M = NSResources->connections();
NodeCollection * NC;
// for all connections
for( QDictIterator<NodeCollection> it(M);
it.current();
++it ) {
NC = it.current();
Profiles_LB->insertItem( NC->devicePixmap(),
NC->name() );
}
}
if( Profiles_LB->count() ) {
Profiles_LB->setSelected( 0, TRUE );
}
// if no profiles -> auto popup editing
if( NSResources->connections().count() == 0 ) {
QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) );
}
connect( &(NSResources->system()),
SIGNAL( stdoutLine(const QString &) ),
this, SLOT( SLOT_CmdMessage(const QString &) ) );
connect( &(NSResources->system()),
SIGNAL( stderrLine(const QString &) ),
this, SLOT( SLOT_CmdMessage(const QString &) ) );
connect( &(NSResources->system()),
SIGNAL( processEvent(const QString &) ),
this, SLOT( SLOT_CmdMessage(const QString &) ) );
UpdateTimer->start( 5000 );
connect( UpdateTimer, SIGNAL( timeout() ),
this, SLOT( SLOT_RefreshStates() ) );
/* Add QCopChannel */
connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)),
this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) );
}
NetworkSettings::~NetworkSettings() {
QString S;
- owarn << "Dispose NS" << oendl;
if( NSD.isModified() ) {
- owarn << "Modified" << oendl;
S = NSD.saveSettings();
if( ! S.isEmpty() ) {
S.insert( 0, "<p>" );
S.append( "</p>" );
// problem saving
QMessageBox::warning(
0,
tr( "Saving setup" ), S );
}
SLOT_GenerateConfig();
NSD.setModified( 0 );
}
}
void NetworkSettings::SLOT_CmdMessage( const QString & S ) {
Messages_LB->insertItem( S );
Messages_LB->setCurrentItem( Messages_LB->count()-1 );
Messages_LB->ensureCurrentVisible();
}
void NetworkSettings::SLOT_RefreshStates( void ) {
QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember
if( LBI ) {
NodeCollection * NC;
NSResources->system().probeInterfaces();
// update current selection only
NC = NSResources->findConnection( LBI->text() );
if( NC ) {
State_t OldS = NC->state();
State_t NewS = NC->state(1);
if( OldS != NewS ) {
updateProfileState( LBI );
}
}
}
/* -> LATER !!
bool is;
NodeCollection * NC;
for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) {
NC = NSResources->findConnection( Profiles_LB->text(i) );
if( NC ) {
State_t OldS = NC->state();
State_t NewS = NC->state(1);
if( OldS != NewS ) {
is = Profiles_LB->isSelected(i);
Profiles_LB->changeItem( NC->statePixmap(NewS),
NC->name(),
i );
if( is ) {
Profiles_LB->setSelected( i, TRUE );
}
}
}
}
if( ci >= 0 )
Profiles_LB->setCurrentItem( ci );
*/
}
void NetworkSettings::SLOT_AddNode( void ) {
SLOT_EditNode( 0 );
}
void NetworkSettings::SLOT_DeleteNode( void ) {
QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
if ( ! LBI )
return;
if( QMessageBox::warning(
0,
tr( "Removing profile" ),
tr( "Remove selected profile ?" ),
1, 0 ) == 1 ) {
NSResources->removeConnection( LBI->text() );
delete LBI;
NSD.setModified( 1 );
}
}
void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) {
QString OldName = "";
EditConnection EC( this );
if( LBI ) {
NodeCollection * NC = NSResources->findConnection( LBI->text() );
if( ! NC ) {
return;
}
OldName = NC->name();
EC.setConnection( NC );
}
EC.showMaximized();
// disable refresh timer
UpdateTimer->stop();
// we need to retry
while( 1 ) {
if( EC.exec() == QDialog::Accepted ) {
// toplevel item -> store
NodeCollection * NC = EC.connection();
if( NC->isModified() ) {
if( LBI ) {
if( NC->name() != OldName ) {
// find if new name is free
NodeCollection * LCN = NSResources->findConnection(
NC->name() );
if( LCN ) {
QMessageBox::warning(
0,
tr( "In System Config" ),
tr( "Name %1 already exists" ).arg(NC->name())
);
continue; // restart exec
} // else new name
// new name -> remove item
NSResources->removeConnection( OldName );
NSResources->addConnection( NC, 0 );
} // else not changed
// must add it here since change will trigger event
Profiles_LB->changeItem( NC->devicePixmap(),
NC->name(),
Profiles_LB->index( LBI )
);
} else {
// new item
int ci = Profiles_LB->count();
NSResources->addConnection( NC, 0 );
NC->setNumber( NSResources->assignConnectionNumber() );
Profiles_LB->insertItem( NC->devicePixmap(), NC->name() );
Profiles_LB->setSelected( ci, TRUE );
}
updateProfileState( LBI );
}
} else {
// cancelled : reset connection
if( LBI ) {
NodeCollection * NC = NSResources->findConnection( LBI->text() );
NC->reassign();
}
}
break;
}
// reenable
UpdateTimer->start( 5000 );
}
void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) {
if( LBI == 0 )
return;
NodeCollection * NC = NSResources->findConnection( LBI->text() );
if( NC->description().isEmpty() ) {
Description_LBL->setText( tr( "<<No description>>" ) );
} else {
Description_LBL->setText( NC->description() );
}
Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() );
bool FrmActive = 1;
bool IsEnabled = 1;
int leds = 0;
- owarn << "State " << NC->state() << oendl;
switch( NC->state() ) {
case Disabled : // no further work
IsEnabled = 0;
FrmActive = 0;
- owarn << "LEds " << leds << oendl;
break;
case Unknown :
case Unchecked :
case Unavailable :
FrmActive = 0;
break;
case Off :
leds = 1;
break;
case Available :
leds = 2;
break;
case IsUp :
leds = 3;
break;
}
Disable_TB->setOn( ! IsEnabled );
LED_Frm->setEnabled( FrmActive );
for( int i = 0 ; i < leds; i ++ ) {
Leds[i]->setColor( red );
Leds[i]->setOn( true );
}
for( int i = leds ; i < 3; i ++ ) {
Leds[i]->setColor( red );
Leds[i]->setOn( false );
}
Up_TB->setEnabled( leds < 3 && leds != 0 );
Down_TB->setEnabled( leds > 0 );
}
void NetworkSettings::SLOT_CheckState( void ) {
QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
if ( ! LBI )
return;
updateProfileState( LBI );
}
void NetworkSettings::updateProfileState( QListBoxItem * LBI ) {
if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) {
SLOT_ShowNode( LBI );
}
}
void NetworkSettings::SLOT_GenerateConfig( void ) {
QString S = NSD.generateSettings();
if( ! S.isEmpty() ) {
S.insert( 0, "<p>" );
S.append( "</p>" );
QMessageBox::warning(
0,
tr( "Generate config" ),
S);
}
}
void NetworkSettings::SLOT_Disable( bool T ) {
QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
QString Msg;
if ( ! LBI )
return;
NodeCollection * NC = NSResources->findConnection( LBI->text() );
- owarn << "Prepare to disable" << oendl;
+ Log(( "Prepare to %sable\n", (T) ? "en" : "dis" ));
Msg = NC->setState( (T) ? Disable : Enable );
if( ! Msg.isEmpty() ) {
Msg.insert( 0, "<p>" );
Msg.append( "</p>" );
QMessageBox::warning(
0,
tr( "Activating profile" ),
Msg );
return;
}
// reload new state
NC->state( true );
updateProfileState( LBI );
}
void NetworkSettings::SLOT_Up( void ) {
// bring more up
QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
QString Msg;
int led = -1;
if ( ! LBI )
return;
NodeCollection * NC =
NSResources->findConnection( LBI->text() );
switch( NC->state() ) {
case Disabled : // cannot modify this state
case Unknown : // cannot modify this state
case Unchecked : // cannot modify this state
case Unavailable : // cannot modify this state
case IsUp : // highest UP state
return;
case Off : // -> activate
led = 1;
Down_TB->setEnabled( true );
Log(( "Activate interface %s\n", NC->name().latin1() ));
Msg = NC->setState( Activate );
break;
case Available : // -> up
led = 2;
Log(( "Bring up interface %s\n", NC->name().latin1() ));
Msg = NC->setState( Up );
if( Msg.isEmpty() ) {
Up_TB->setEnabled( false );
}
break;
}
if( ! Msg.isEmpty() ) {
Msg.insert( 0, "<p>" );
Msg.append( "</p>" );
QMessageBox::warning(
0,
tr( "Increase availability" ),
Msg );
return;
}
updateProfileState( LBI );
// set color of led we should change
if( led > 0 ) {
Leds[led]->setColor( blue );
Leds[led]->setOn( true );
}
}
void NetworkSettings::SLOT_Down( void ) {
// bring more down
QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
int led = -1;
QString Msg;
if ( ! LBI )
return;
NodeCollection * NC =
NSResources->findConnection( LBI->text() );
switch( NC->state() ) {
case Disabled : // cannot modify this state
case Unknown : // cannot modify this state
case Unchecked : // cannot modify this state
case Unavailable : // cannot modify this state
case Off : // highest DOWN state
break;
case Available : // -> down
led = 0;
Log(( "Deactivate interface %s\n", NC->name().latin1() ));
Msg = NC->setState( Deactivate );
diff --git a/noncore/settings/networksettings2/networksettings2/config.in b/noncore/settings/networksettings2/networksettings2/config.in
index b384e18..56e971e 100644
--- a/noncore/settings/networksettings2/networksettings2/config.in
+++ b/noncore/settings/networksettings2/networksettings2/config.in
@@ -1,5 +1,5 @@
config NS2CORE
- boolean "opie-networksettings2 (TCP/IP network settings)"
+ boolean "opie-networksettings2 library"
default "y"
depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2UI
diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp
index e642c08..f027d35 100644
--- a/noncore/settings/networksettings2/networksettings2/system.cpp
+++ b/noncore/settings/networksettings2/networksettings2/system.cpp
@@ -1,381 +1,381 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#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() {
ProcDevNet = 0;
}
System::~System( void ) {
if( ProcDevNet )
delete ProcDevNet;
}
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 "
+ odebug << "TESTMODE !!! execute "
<< S.join( " ")
<< oendl;
} else {
MyProcess * P;
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*) ) );
}
P->process() << S;
Log(("Executing %s\n", S.join( " " ).latin1() ));
if( ! P->process().start( OProcess::DontCare,
OProcess::AllOutput ) ) {
- owarn << "Error starting " << S << oendl;
+ odebug << "Error starting " << S << oendl;
if( ! Prc )
delete P;
// error starting app
return 0;
}
- owarn << "Started " << S << oendl;
+ odebug << "Started " << S << oendl;
}
// all is fine
return 1;
}
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];
SL = QStringList::split( "=", X );
P->process().setEnvironment( SL[0], SL[1] );
}
P->process() << SL;
emit processEvent( tr("Command : ") + SL.join( " " ) );
Log(("Executing as user %s : %s\n",
CU.UserName.latin1(),
SL.join( " " ).latin1() ));
int rv = ( P->process().start( OProcess::DontCare,
OProcess::NoCommunication ) );
delete P;
if( rv ) {
// if we come here, the exec was not successfull
Log(("Could not exec : %d\n", errno ));
}
return ! rv;
}
void System::SLOT_ProcessExited( MyProcess * P ) {
QString R;
for( QValueListConstIterator<QCString> it = P->process().args().begin();
it != P->process().args().end();
++it ) {
R += (*it);
R += " ";
}
R += "Returned with " + QString().setNum( P->process().exitStatus() );
emit processEvent( R );
delete P;
}
void System::refreshStatistics( InterfaceInfo & I ) {
if( ! ProcDevNet ) {
return;
}
// cannot seek on dev
ProcDevNet->close();
ProcDevNet->open( IO_ReadOnly );
QString line;
QTextStream procTs(ProcDevNet);
QStringList SL;
int loc = -1;
int version;
procTs.readLine();
line = procTs.readLine();
// get version
if( line.find("compressed") )
version = 3;
else if( line.find( "bytes" ) )
version = 2;
else
version = 1;
while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
if( (loc = line.find(":") ) == -1) {
continue;
}
if( I.Name != line.left(loc) )
continue;
// tokenize
SL = QStringList::split( ' ', line, FALSE );
// update data
switch( version ) {
case 1 :
I.RcvBytes = SL[1];
I.RcvErrors = SL[3];
I.RcvDropped = SL[4];
I.SndBytes = SL[6];
I.SndErrors = SL[8];
I.SndDropped = SL[9];
I.Collisions = SL[11];
break;
case 2 :
I.RcvBytes = SL[1];
I.RcvErrors = SL[3];
I.RcvDropped = SL[4];
I.SndBytes = SL[7];
I.SndErrors = SL[9];
I.SndDropped = SL[10];
I.Collisions = SL[12];
break;
case 3 :
I.RcvBytes = SL[1];
I.RcvErrors = SL[3];
I.RcvDropped = SL[4];
I.SndBytes = SL[9];
I.SndErrors = SL[11];
I.SndDropped = SL[12];
I.Collisions = SL[14];
break;
}
break;
}
}
//
// THIS UPDATES THE LIST -> INTERFACES ARE NOT DELETED BUT
// FLAGGED AS ! 'IsUp' IF NO LONGER PRESENT
//
void System::probeInterfaces( void ) {
// probe interfaces
int sockfd;
// get list of all interfaces
struct ifreq ifrs;
InterfaceInfo * IFI;
// flag all as 'down'
for( QDictIterator<InterfaceInfo> it( ProbedInterfaces );
it.current();
++it ) {
it.current()->IsUp = 0;
}
sockfd = socket(PF_INET, SOCK_DGRAM, 0);
if(sockfd == -1) {
- owarn << "Cannot open INET socket "
+ odebug << "Cannot open INET socket "
<< errno
<< " "
<< strerror( errno )
<< oendl;
return;
}
// read interfaces from /proc/dev/net
// SIOCGIFCONF does not return ALL interfaces ???!?
ProcDevNet = new QFile(PROCNETDEV);
if( ! ProcDevNet->open(IO_ReadOnly) ) {
- owarn << "Cannot open "
+ odebug << "Cannot open "
<< PROCNETDEV
<< " "
<< errno
<< " "
<< strerror( errno )
<< oendl;
delete ProcDevNet;
ProcDevNet =0;
::close( sockfd );
return;
}
QString line;
QString NicName;
QTextStream procTs(ProcDevNet);
int loc = -1;
procTs.readLine(); // eat a line
procTs.readLine(); // eat a line
while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
if((loc = line.find(":")) == -1) {
continue;
}
NicName = line.left(loc);
// set name for ioctl
strcpy( ifrs.ifr_name, NicName.latin1() );
if ( ! ( IFI = ProbedInterfaces.find( NicName ) ) ) {
// new nic
Log(("New NIC found : %s\n", NicName.latin1()));
IFI = new InterfaceInfo;
IFI->Name = line.left(loc);
IFI->Collection = 0;
ProbedInterfaces.insert( IFI->Name, IFI );
// get dynamic info
if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) {
IFI->IsPointToPoint = ((ifrs.ifr_flags & IFF_POINTOPOINT) == IFF_POINTOPOINT);
} else {
IFI->IsPointToPoint = 0;
}
// settings that never change
IFI->DstAddress = "";
if( IFI->IsPointToPoint ) {
if( ioctl(sockfd, SIOCGIFDSTADDR, &ifrs) >= 0 ) {
IFI->DstAddress =
inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_dstaddr)->sin_addr);
}
}
IFI->CardType = 999999;
IFI->MACAddress = "";
if( ioctl(sockfd, SIOCGIFHWADDR, &ifrs) >= 0 ) {
Log(("Family for NIC %s : %d\n", IFI->Name.latin1(),
ifrs.ifr_hwaddr.sa_family ));
IFI->CardType = ifrs.ifr_hwaddr.sa_family;
switch( ifrs.ifr_hwaddr.sa_family ) {
case ARPHRD_ETHER : // regular MAC address
// valid address -> convert to regular ::: format
// length = 6 bytes = 12 DIGITS -> 6 :
IFI->MACAddress.sprintf(
"%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
HN( ifrs.ifr_hwaddr.sa_data[0] ),
LN( ifrs.ifr_hwaddr.sa_data[0] ),
HN( ifrs.ifr_hwaddr.sa_data[1] ),
LN( ifrs.ifr_hwaddr.sa_data[1] ),
HN( ifrs.ifr_hwaddr.sa_data[2] ),
LN( ifrs.ifr_hwaddr.sa_data[2] ),
HN( ifrs.ifr_hwaddr.sa_data[3] ),
LN( ifrs.ifr_hwaddr.sa_data[3] ),
HN( ifrs.ifr_hwaddr.sa_data[4] ),
LN( ifrs.ifr_hwaddr.sa_data[4] ),
HN( ifrs.ifr_hwaddr.sa_data[5] ),
LN( ifrs.ifr_hwaddr.sa_data[5] )
);
break;
#ifdef ARPHRD_IEEE1394
case ARPHRD_IEEE1394 : // Firewire Eth address
IFI->MACAddress.sprintf(
"%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-00-00",
HN( ifrs.ifr_hwaddr.sa_data[0] ),
LN( ifrs.ifr_hwaddr.sa_data[0] ),
HN( ifrs.ifr_hwaddr.sa_data[1] ),
LN( ifrs.ifr_hwaddr.sa_data[1] ),
HN( ifrs.ifr_hwaddr.sa_data[2] ),
LN( ifrs.ifr_hwaddr.sa_data[2] ),
HN( ifrs.ifr_hwaddr.sa_data[3] ),
LN( ifrs.ifr_hwaddr.sa_data[3] ),
HN( ifrs.ifr_hwaddr.sa_data[4] ),
LN( ifrs.ifr_hwaddr.sa_data[4] ),
@@ -416,172 +416,172 @@ void System::probeInterfaces( void ) {
IFI->IsUp = ((ifrs.ifr_flags & IFF_UP) == IFF_UP);
IFI->HasMulticast = ((ifrs.ifr_flags & IFF_MULTICAST) == IFF_MULTICAST);
} else {
IFI->IsUp = 0;
IFI->HasMulticast = 0;
}
if( ioctl(sockfd, SIOCGIFADDR, &ifrs) >= 0 ) {
IFI->Address =
inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_addr)->sin_addr);
} else {
IFI->Address = "";
IFI->IsUp = 0;
}
if( ioctl(sockfd, SIOCGIFBRDADDR, &ifrs) >= 0 ) {
IFI->BCastAddress =
inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_broadaddr)->sin_addr);
} else {
IFI->BCastAddress = "";
}
if( ioctl(sockfd, SIOCGIFNETMASK, &ifrs) >= 0 ) {
IFI->Netmask =
inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_netmask)->sin_addr);
} else {
IFI->Netmask = "";
}
Log(("NIC %s UP ? %d\n", NicName.latin1(), IFI->IsUp ));
}
::close( sockfd );
}
InterfaceInfo * System::findInterface( const QString & N ) {
InterfaceInfo * Run;
// has PAN connection UP interface ?
for( QDictIterator<InterfaceInfo> It(ProbedInterfaces);
It.current();
++It ) {
Run = It.current();
if( N == Run->Name ) {
// this PAN connection is up
return Run;
}
}
return 0;
}
#include <stdarg.h>
static FILE * logf = 0;
void VLog( char * Format, ... ) {
va_list l;
va_start(l, Format );
if( logf == (FILE *)0 ) {
QString S = getenv("NS2LOG");
if( S == "stderr" ) {
logf = stderr;
} else if( S.isEmpty() ) {
logf = fopen( "/tmp/ns2log", "a" );
} else {
logf = fopen( S, "a" );
}
if( ! logf ) {
fprintf( stderr, "Cannot open logfile %s : %d\n",
S.latin1(), errno );
logf = (FILE *)1;
} else {
fprintf( logf, "____ OPEN LOGFILE ____\n");
}
}
if( (unsigned long)logf > 1 ) {
vfprintf( logf, Format, l );
}
va_end( l );
fflush( logf );
}
void LogClose( void ) {
if( (long)logf > 1 ) {
fprintf( logf, "____ CLOSE LOGFILE ____\n");
if( logf != stderr ) {
fclose( logf );
}
logf = 0;
}
}
QString removeSpaces( const QString & X ) {
QString Y;
Y = X.simplifyWhiteSpace();
Y.replace( QRegExp(" "), "_" );
- owarn << X << " **" << Y << "**" << oendl;
+ odebug << X << " **" << Y << "**" << oendl;
return Y;
}
//
//
//
//
//
MyProcess::MyProcess() : QObject(), StdoutBuffer(), StderrBuffer() {
P = new OProcess();
connect( P,
SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int ) ),
this,
SLOT( SLOT_Stdout(Opie::Core::OProcess*,char*,int) ) );
connect( P,
SIGNAL( receivedStderr(Opie::Core::OProcess*, char*, int ) ),
this,
SLOT( SLOT_Stderr(Opie::Core::OProcess*,char*,int) ) );
connect( P,
SIGNAL( processExited(Opie::Core::OProcess*) ),
this,
SLOT( SLOT_ProcessExited(Opie::Core::OProcess*) ) );
}
MyProcess::~MyProcess() {
delete P;
}
void MyProcess::SLOT_Stdout( Opie::Core::OProcess * , char * Buf, int len ) {
char * LB = (char *)alloca( len + 1 );
memcpy( LB, Buf, len );
LB[len] = '\0';
// now input is zero terminated
StdoutBuffer += LB;
- owarn << "Received " << len << " bytes on stdout" << oendl;
+ odebug << "Received " << len << " bytes on stdout" << oendl;
// see if we have some lines (allow empty lines)
QStringList SL = QStringList::split( "\n", StdoutBuffer, TRUE );
for( unsigned int i = 0; i < SL.count()-1; i ++ ) {
Log(( "Stdout : \"%s\"\n", SL[i].latin1() ) );
emit stdoutLine( SL[i] );
}
// last line is rest
StdoutBuffer = SL[ SL.count()-1 ];
}
void MyProcess::SLOT_Stderr( Opie::Core::OProcess * , char * Buf, int len ) {
char * LB = (char *)alloca( len + 1 );
memcpy( LB, Buf, len );
LB[len] = '\0';
// now input is zero terminated
StderrBuffer += LB;
- owarn << "Received " << len << " bytes on stderr" << oendl;
+ odebug << "Received " << len << " bytes on stderr" << oendl;
// see if we have some lines (allow empty lines)
QStringList SL = QStringList::split( "\n", StderrBuffer, TRUE );
for( unsigned int i = 0; i < SL.count()-1; i ++ ) {
Log(( "Stderr : \"%s\"\n", SL[i].latin1() ) );
emit stderrLine( SL[i] );
}
// last line is rest
StderrBuffer = SL[ SL.count()-1 ];
}
void MyProcess::SLOT_ProcessExited( Opie::Core::OProcess * ) {
emit processExited( this );
}
diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.cpp b/noncore/settings/networksettings2/networksettings2/systemfile.cpp
index 8deef94..1b1988e 100644
--- a/noncore/settings/networksettings2/networksettings2/systemfile.cpp
+++ b/noncore/settings/networksettings2/networksettings2/systemfile.cpp
@@ -6,230 +6,230 @@
#include <qtextstream.h>
#include "resources.h"
#include "systemfile.h"
#define TEMPLATEDIR "NS2templates/"
QString TemplDir;
SystemFile::SystemFile( const QString & N,
const QString & P,
bool KDI ){
Name = N;
Path = P;
InAppend = 0;
F = 0;
// get template info
{ QString S;
QFileInfo FI;
// find location of templates
TemplDir = QPEApplication::qpeDir() + "etc/" + TEMPLATEDIR;
FI.setFile( TemplDir );
if( ! FI.isDir() ) {
// try current dir
TemplDir = "./" TEMPLATEDIR;
FI.setFile( TemplDir );
if( ! FI.isDir() ) {
hasPreSection =
hasPostSection =
hasPreNodeSection =
hasPostNodeSection =
hasPreDeviceSection =
hasPostDeviceSection = 0;
return;
}
}
// have found location
S = TemplDir + Name + "/presection";
FI.setFile( S );
hasPreSection = ( FI.exists() && FI.isReadable() );
S = TemplDir + Name + "/postsection";
FI.setFile( S );
hasPostSection = ( FI.exists() && FI.isReadable() );
S = TemplDir + Name + "/prenodesection";
FI.setFile( S );
hasPreNodeSection = ( FI.exists() && FI.isReadable() );
S = TemplDir + Name + "/postnodesection";
FI.setFile( S );
hasPostNodeSection = ( FI.exists() && FI.isReadable() );
S = TemplDir + Name + "/predevicesection";
FI.setFile( S );
hasPreDeviceSection = ( FI.exists() && FI.isReadable() );
S = TemplDir + Name + "/postdevicesection";
FI.setFile( S );
hasPostDeviceSection = ( FI.exists() && FI.isReadable() );
}
KnowsDeviceInstances = KDI;
}
SystemFile::SystemFile( const QString & N, bool KDI ){
Name = N;
Path = "";
InAppend = 0;
F =0;
KnowsDeviceInstances = KDI;
hasPreSection =
hasPostSection =
hasPreNodeSection =
hasPostNodeSection =
hasPreDeviceSection =
hasPostDeviceSection = 0;
}
SystemFile::~SystemFile( void ) {
close();
}
bool SystemFile::open( void ) {
QString Prefix = getenv( "NS2OUTPUTTO" );
if( Prefix != "stderr" /* && Name != "interfaces" */ ) {
// generate files where the need to be
if( F ) {
F->close();
delete F;
}
F = new QFile( Prefix + Path + ((InAppend)?"":"bup") );
Log(( "Open systemfile %s\n", F->name().latin1() ));
if( ! F->open( ((InAppend)?IO_Append : 0 ) | IO_WriteOnly ) ) {
return 0;
}
} else {
if( ! F ) {
- owarn << "!!!!!!!!!!!!!!!!!! " << oendl;
- owarn << "!!!! TESTMODE !!!!" << oendl;
- owarn << "!!!!!!!!!!!!!!!!!! " << oendl;
- owarn << "!!!!" << oendl;
- owarn << "!!!! GENERATE " << Path << oendl;
+ odebug << "!!!!!!!!!!!!!!!!!! " << oendl;
+ odebug << "!!!! TESTMODE !!!!" << oendl;
+ odebug << "!!!!!!!!!!!!!!!!!! " << oendl;
+ odebug << "!!!!" << oendl;
+ odebug << "!!!! GENERATE " << Path << oendl;
if( InAppend ) {
- owarn << "!!!! In APPEND mode" << oendl;
+ odebug << "!!!! In APPEND mode" << oendl;
}
- owarn << "!!!!" << oendl;
- owarn << "!!!!!!!!!!!!!!!!!!" << oendl;
+ odebug << "!!!!" << oendl;
+ odebug << "!!!!!!!!!!!!!!!!!!" << oendl;
F = new QFile();
F->open( IO_WriteOnly, stderr );
}
}
setDevice( F );
return 1;
}
bool SystemFile::close( void ) {
if( ! F || ! F->isOpen() ) {
return 1 ;
}
QString Prefix = getenv( "NS2OUTPUTTO" );
if( Prefix == "stderr" ) {
return 1;
}
QString OldP = Prefix + Path + "bup";
F->close();
delete F;
F = 0;
if( ! InAppend ) {
- owarn << "Rename " << OldP << " to " << Path << oendl;
+ odebug << "Rename " << OldP << " to " << Path << oendl;
return ( rename( OldP.latin1(), Path.latin1() ) >= 0 );
}
return 1;
}
bool SystemFile::preSection( void ) {
if( hasPreSection ) {
QFile Fl( TemplDir + Name + "/presection" );
if( ! Fl.open( IO_ReadOnly ) )
return 0; // error
// copy file to this file
F->writeBlock( Fl.readAll() );
}
return 1;
}
bool SystemFile::postSection( void ) {
if( hasPostSection ) {
QFile Fl( TemplDir + Name + "/postsection" );
if( ! Fl.open( IO_ReadOnly ) )
return 0; // error
// copy file to this file
F->writeBlock( Fl.readAll() );
}
return 1;
}
bool SystemFile::preNodeSection( ANetNodeInstance * NNI, long ) {
if( hasPreNodeSection ) {
QFile Fl( TemplDir + Name + "/prenodesection" );
if( ! Fl.open( IO_ReadOnly ) )
return 0; // error
QTextStream TX( &Fl );
QString Out;
QString S = TX.readLine();
while( ! TX.eof() ) {
Out = S.
arg(NNI->nodeClass()->name());
(*this) << Out << endl;
S = TX.readLine();
}
}
return 1;
}
bool SystemFile::postNodeSection( ANetNodeInstance * NNI, long ) {
if( hasPostNodeSection ) {
QFile Fl( TemplDir + Name + "/postnodesection" );
if( ! Fl.open( IO_ReadOnly ) )
return 0; // error
QTextStream TX( &Fl );
QString Out;
QString S = TX.readLine();
while( ! TX.eof() ) {
Out = S.
arg(NNI->name());
(*this) << Out << endl;
S = TX.readLine();
}
}
return 1;
}
bool SystemFile::preDeviceSection( ANetNode * NN ) {
if( hasPreDeviceSection ) {
QFile Fl( TemplDir + Name + "/predevicesection" );
if( ! Fl.open( IO_ReadOnly ) )
return 0; // error
QTextStream TX( &Fl );
QString Out;
QString S = TX.readLine();
while( ! TX.eof() ) {
Out = S.arg(NN->name());
(*this) << Out << endl;
S = TX.readLine();
}
}
return 1;
}
bool SystemFile::postDeviceSection( ANetNode * NN ) {
if( hasPostDeviceSection ) {
QFile Fl( TemplDir + Name + "/postdevicesection" );
if( ! Fl.open( IO_ReadOnly ) )
return 0; // error
QTextStream TX( &Fl );
QString Out;
QString S = TX.readLine();
while( ! TX.eof() ) {
Out = S.arg(NN->name());
(*this) << Out << endl;
S = TX.readLine();
}
}
return 1;
}
diff --git a/noncore/settings/networksettings2/opie-networksettings2.postinst b/noncore/settings/networksettings2/opie-networksettings2.postinst
index ce43274..d1d98ac 100755
--- a/noncore/settings/networksettings2/opie-networksettings2.postinst
+++ b/noncore/settings/networksettings2/opie-networksettings2.postinst
@@ -1,9 +1,9 @@
#!/bin/sh
QTPB=/opt/QtPalmtop/bin
[ ! -L ${QTPB}/networksettings2-request ] && ln -sf ${QTPB}/networksettings2 ${QTPB}/networksettings2-request
-qcop QPE/TaskBar "reloadApps()"
+${QTPB}/qcop QPE/TaskBar "reloadApps()"
exit 0
diff --git a/noncore/settings/networksettings2/opietooth2/OTDevice.cpp b/noncore/settings/networksettings2/opietooth2/OTDevice.cpp
index 62f17a0..c6f7d5e 100644
--- a/noncore/settings/networksettings2/opietooth2/OTDevice.cpp
+++ b/noncore/settings/networksettings2/opietooth2/OTDevice.cpp
@@ -10,247 +10,247 @@
#include <OTDevice.h>
using namespace Opie::Core;
using namespace Opietooth2;
using Opie::Core::OProcess;
OTDevice::OTDevice( OTGateway * _OT ) : QObject(0, "device") {
// initialize
OT = _OT;
// detect bluetooth type
QString a, b; // fake
unsigned long c; // fake
detectDeviceType( a, b, c );
if( needsAttach() ) {
// requires HCIATTACH
// pid of hciattach
m_hciattachPid = getPidOfHCIAttach();
m_hciattach = 0;
if( m_hciattachPid == 0 ) {
// no pid -> not attached
m_deviceNr = -1;
} else {
// system enabled
// currently no way to figure out which attach produce which
// hci
m_deviceNr = 0;
}
} else {
m_deviceNr = 0;
}
}
OTDevice::~OTDevice(){
if( needsAttach() && m_hciattach ) {
// does not auto stop bluetooth
m_hciattach->detach();
delete m_hciattach;
}
}
bool OTDevice::attach(){
if( needsAttach() && m_hciattachPid == 0 ) {
QString Dev, Mode;
unsigned long Spd;
detectDeviceType( Dev, Mode, Spd );
// not yet started
m_hciattach = new OProcess();
*m_hciattach << "hciattach";
*m_hciattach << "-p"; // so that it prints its pid
*m_hciattach << Dev
<< Mode
<< QString().setNum(Spd);
connect( m_hciattach,
SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
this, SLOT
(slotStdOut(Opie::Core::OProcess*,char*,int) ) );
connect( m_hciattach,
SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ),
this, SLOT
(slotStdErr(Opie::Core::OProcess*,char*,int) ) );
// we need to start this in 'dontcare' mode because
// if qpe exists we want the hci to keep running
if( ! m_hciattach->start( OProcess::DontCare,
OProcess::AllOutput
) ){
emit error( tr( "Could not start hciattach" ) );
delete m_hciattach;
m_hciattach = 0;
return FALSE;
}
}
return TRUE;
}
bool OTDevice::detach(){
if( needsAttach() && m_hciattachPid ) {
if( m_hciattach ) {
delete m_hciattach;
m_hciattach = 0;
}
if( kill( m_hciattachPid, 9) < 0 ) {
- owarn << "could not stop " << errno << oendl;
+ odebug << "could not stop " << errno << oendl;
emit error( tr( "Could not stop process" ) );
return FALSE;
}
m_hciattachPid = 0;
emit isEnabled( m_deviceNr, 0 );
m_deviceNr = -1;
}
return TRUE;
}
bool OTDevice::isAttached()const{
return ! needsAttach() || m_hciattachPid != 0;
}
bool OTDevice::checkAttach(){
if( ! needsAttach() ) {
m_deviceNr = 0;
emit isEnabled( 0, 1 );
return TRUE;
}
if( m_hciattachPid ) {
QString S;
S.setNum( m_hciattachPid );
QDir D( "/proc" );
if( !D.exists( S ) ) {
// down
m_hciattachPid = 0;
emit isEnabled( m_deviceNr, 0 );
m_deviceNr = -1;
}
} else {
// check
m_hciattachPid = getPidOfHCIAttach();
if ( m_hciattachPid ) {
m_deviceNr = 0;
emit isEnabled( m_deviceNr, 1 );
}
}
return m_hciattachPid != 0;
}
void OTDevice::slotStdOut(OProcess* proc, char* , int ) {
if( proc == m_hciattach ) {
m_hciattach->detach();
// system enabled
// currently no way to figure out which attach produce which
// hci
if( m_deviceNr == -1 ) {
m_deviceNr = 0;
emit isEnabled( m_deviceNr, 1 );
}
}
}
void OTDevice::slotStdErr(OProcess* proc, char* chars, int len) {
if(proc == m_hciattach && len >= 1 ){
// collect output
QCString string( chars, len+1 ); // \0 == +1
QString m_output;
m_output.append( string.data() );
- owarn << m_output << oendl;
+ odebug << m_output << oendl;
}
}
pid_t OTDevice::getPidOfHCIAttach( void ) {
if( needsAttach() ) {
// not yet attached -> perhaps now ?
// load /proc dir and check if command name contains hciattach
QRegExp R("[0-9]+");
QDir ProcDir( "/proc" );
QFileInfo FI;
QStringList EL = ProcDir.entryList( QDir::Dirs );
// print it out
for ( QStringList::Iterator it = EL.begin();
it != EL.end();
++it ) {
if( R.match( (*it) ) >= 0 ) {
// is pid
// get command being executed
FI.setFile( ProcDir.path()+"/"+ (*it) + "/exe" );
// get the link
if( FI.readLink().right( 9 ) == "hciattach" ) {
// this is hci attach process
return (*it).toULong();
break;
}
}
}
}
return 0;
}
void OTDevice::detectDeviceType( QString & Device,
QString & Mode,
unsigned long & Speed ) {
// detect device type and determine parms
- owarn << "Detecting device" << oendl;
+ odebug << "Detecting device" << oendl;
switch ( ODevice::inst()->model() ) {
case Model_iPAQ_H39xx:
Device = "/dev/tts/1";
Mode = "bcsp";
Speed = 921600;
NeedsAttach = 1;
break;
case Model_iPAQ_H5xxx:
Device = "/dev/tts/1";
Mode = "any";
Speed = 921600;
NeedsAttach = 1;
break;
case Model_GenuineIntel :
Device = "";
Mode = "";
Speed = 0;
NeedsAttach = 0;
break;
default:
Device = "/dev/ttySB0";
Mode = "bcsp";
Speed = 230400;
NeedsAttach = 1;
break;
}
}
QString OTDevice::getRFCommDevicePattern( void ) {
QDir D( "/dev/bluetooth/rfcomm" );
if( D.exists() ) {
// devfs
return QString( "/dev/bluetooth/rfcomm/%1" );
}
// regular 'dev' directory
return QString( "/dev/rfcomm%1" );
}
diff --git a/noncore/settings/networksettings2/opietooth2/OTDriver.cpp b/noncore/settings/networksettings2/opietooth2/OTDriver.cpp
index 8bd7919..a7ee662 100644
--- a/noncore/settings/networksettings2/opietooth2/OTDriver.cpp
+++ b/noncore/settings/networksettings2/opietooth2/OTDriver.cpp
@@ -57,193 +57,193 @@ static char *major_devices[] = { "Miscellaneous",
"Phone",
"LAN Access",
"Audio/Video",
"Peripheral",
"Imaging",
"Uncategorized" };
typedef struct {
short Minor;
const char * Description;
} ClassMap_t;
static ClassMap_t MapMiscClass[] = {
{ -1, "" }
};
static ClassMap_t MapUnclassifiedClass[] = {
{ -1, "" }
};
static ClassMap_t MapComputerClass[] = {
{ 0, "Uncategorized" } ,
{ 1, "Desktop workstation" } ,
{ 2, "Server" } ,
{ 3, "Laptop" } ,
{ 4, "Handheld" } ,
{ 5, "Palm" } ,
{ 6, "Wearable" },
{ -1, 0 }
};
static ClassMap_t MapPhoneClass[] = {
{ 0, "Uncategorized" },
{ 1, "Cellular" },
{ 2, "Cordless" },
{ 3, "Smart phone" },
{ 4, "Wired modem or voice gateway" },
{ 5, "Common ISDN Access" },
{ 6, "Sim Card Reader" },
{ -1, 0 }
};
static ClassMap_t MapAVClass[] = {
{ 0, "Uncategorized" },
{ 1, "Device conforms to the Headset profile" },
{ 2, "Hands-free" },
{ 3, 0 },
{ 4, "Microphone" },
{ 5, "Loudspeaker" },
{ 6, "Headphones" },
{ 7, "Portable Audio" },
{ 8, "Car Audio" },
{ 9, "Set-top box" },
{ 10, "HiFi Audio Device" },
{ 11, "VCR" },
{ 12, "Video Camera" },
{ 13, "Camcorder" },
{ 14, "Video Monitor" },
{ 15, "Video Display and Loudspeaker" },
{ 16, "Video Conferencing" },
{ 17, 0 },
{ 18, "Gaming/Toy" },
{ -1, 0 }
};
static ClassMap_t MapPeripheralClass[] = {
{ 16, "Keyboard" },
{ 32, "Pointing device" },
{ 48, "Combo keyboard/pointing device" },
{ -1, 0 }
};
typedef struct {
int Major;
ClassMap_t * Map;
} MainClassMap_t;
static MainClassMap_t MainClasses[] = {
{ 0, MapMiscClass },
{ 1, MapComputerClass },
{ 2, MapPhoneClass },
{ 3, 0 }, // special case
{ 4, MapAVClass },
{ 5, MapPeripheralClass },
{ 6, 0 }, // special case
{ 63, MapUnclassifiedClass },
{ -1, 0 }
};
OTDriver::OTDriver( OTGateway * _OT, struct hci_dev_info* di) : QObject( _OT ), Address() {
OT = _OT;
IsUp = 0;
Socket = 0;
init(di);
- owarn << "Driver " << devname() << oendl;
+ odebug << "Driver " << devname() << oendl;
AutoClose = new QTimer( this );
connect( AutoClose,
SIGNAL( timeout() ),
this,
SLOT( SLOT_CloseFd() )
);
}
OTDriver::~OTDriver() {
closeSocket();
SLOT_CloseFd();
}
void OTDriver::SLOT_CloseFd( void ){
if ( isOpen() ) {
AutoClose->stop();
::close( fd() );
setfd( -1 );
}
}
void OTDriver::init(struct hci_dev_info* di) {
Dev = di->name;
setDevId(di->dev_id);
setType(di->type);
setFlags(di->flags);
Address.setBDAddr( di->bdaddr );
setFeatures(di->features);
setfd( -1 ); // not open
Manufacturer = "";
}
// internal reinitialize
void OTDriver::reinit() {
bool Old;
Old = IsUp;
if( currentState() < 0 )
return;
if( Old != IsUp ) {
// state changes
emit stateChange( this, IsUp );
}
}
// requested by application
int OTDriver::currentState() {
struct hci_dev_info di;
// uint16_t tmp_dev_id = device_info.dev_id;
// bzero(&device_info,sizeof(struct hci_dev_info));
// device_info.dev_id = tmp_dev_id;
memset( &di, 0, sizeof( di ) );
di.dev_id = Dev_id;
if( ioctl( OT->getSocket(), HCIGETDEVINFO, (void*)&di) < 0 ) {
SLOT_CloseFd();
return -1;
} else {
// load new info
init(&di);
}
return IsUp;
}
bool OTDriver::open() {
// (re)start single shot close
AutoClose->start( 30000, TRUE );
if( isOpen() )
// is open
return 1;
setfd(hci_open_dev(devId()));
if (fd() < 0) {
emit error( tr( "Can't open device %1. %2 : %3" ).
arg( devname() ).
arg( errno ).
arg( strerror(errno) )
);
return 0;
}
return 1;
}
QString OTDriver::name() {
char name[1000];
@@ -292,216 +292,216 @@ QString OTDriver::revision() {
return tr("Cannot open");
}
if (hci_read_local_version(fd(), &ver, 1000) < 0) {
emit error( tr( "Can't read revision info on %1. %2 : %3" ).
arg( devname() ).
arg( errno ).
arg( strerror(errno) ) );
return QString();
}
setManufacturer(ver.manufacturer);
switch (ver.manufacturer) {
case 0:
return getRevEricsson();
break;
case 10:
return getRevCsr(ver.hci_rev);
break;
default:
return tr( "Unsupported manufacturer" );
break;
}
}
QString OTDriver::getRevEricsson() {
char revision[102];
struct hci_request rq;
if( ! open() ) {
return QString( "Cannot open" );
}
memset(&rq, 0, sizeof(rq));
rq.ogf = 0x3f;
rq.ocf = 0x000f;
rq.cparam = NULL;
rq.clen = 0;
rq.rparam = &revision;
rq.rlen = sizeof(revision);
if (hci_send_req(fd(), &rq, 1000) < 0) {
emit error( tr( "Can't read revision info on %1. %2 : %3" ).
arg( devname() ).
arg( errno ).
arg( strerror(errno) ) );
return QString();
}
return QString( revision+1 );
}
QString OTDriver::getRevCsr( unsigned short rev) {
int i;
for (i = 0; csr_map[i].str; i++)
if (csr_map[i].rev == rev) {
return QString( csr_map[i].str );
}
return tr( "Unknown firmware" );
}
int OTDriver::reset() {
if( ! open() ) {
return 0;
}
if( ioctl(fd(), HCIDEVRESET, devId()) < 0 ) {
if( errno != EALREADY ) {
emit error( tr( "Reset failed for %1. %2 : %3" ).
arg( devname() ).
arg( errno ).
arg( strerror(errno) ) );
if (errno == EACCES) {
return EACCES;
}
}
}
return 0;
}
void OTDriver::setUp( bool M ) {
if( M && ! isUp() ) {
bringUp();
} else if( ! M && isUp() ) {
bringDown();
}
}
void OTDriver::bringUp() {
- owarn << "bringUp : " << Dev << oendl;
+ odebug << "bringUp : " << Dev << oendl;
if( ! open() ) {
return;
}
if (! isUp()) {
if( ioctl(fd(), HCIDEVUP, devId()) < 0 ) {
if( errno != EALREADY ) {
emit error( tr( "Cannot bring interface %1 up. %2 : %3" ).
arg( devname() ).
arg( errno ).
arg( strerror(errno) ) );
}
return;
}
// have to wait a bit for the 'up' to become active
QTimer::singleShot( 3000, this, SLOT( reinit() ) );
}
}
void OTDriver::bringDown() {
- owarn << "bringDown : " << Dev << oendl;
+ odebug << "bringDown : " << Dev << oendl;
if( ! open() ) {
return;
}
if ( isUp() ) {
if( ioctl(fd(), HCIDEVDOWN, devId()) < 0 ) {
if( errno != EALREADY ) {
emit error( tr( "Cannot bring interface %1 down. %2 : %3" ).
arg( devname() ).
arg( errno ).
arg( strerror(errno) ) );
}
return;
}
reinit();
}
}
void OTDriver::setScanMode(bool iscan, bool pscan) {
struct hci_dev_req dr;
if( ! open() ) {
return;
}
dr.dev_id = devId();
dr.dev_opt = SCAN_DISABLED;
if( iscan&&(!pscan) )
dr.dev_opt = SCAN_INQUIRY;
else if( pscan&&(!iscan) )
dr.dev_opt = SCAN_PAGE;
else if( pscan&&iscan )
dr.dev_opt = SCAN_PAGE | SCAN_INQUIRY;
if( ioctl(fd(), HCISETSCAN, (unsigned long)&dr) < 0 ) {
if( errno != EALREADY ) {
emit error( tr( "Can't set scan mode on %1. %2 : %3" ).
arg( devname() ).
arg( errno ).
arg( strerror(errno) ) );
}
return;
}
reinit();
}
void OTDriver::changeDevName(const char* name) {
if( ! open() ) {
return;
}
if (hci_write_local_name(fd(), name, 1000) < 0) {
emit error( tr( "Can't change local name on %1. %2 : %3" ).
arg( devname() ).
arg( errno ).
arg( strerror(errno) ) );
}
}
void OTDriver::changeAuthentication(bool _auth) {
struct hci_dev_req dr;
if( ! open() ) {
return;
}
dr.dev_id = devId();
dr.dev_opt = _auth?AUTH_ENABLED:AUTH_DISABLED;
if (ioctl(fd(),HCISETAUTH,(unsigned long)&dr) < 0) {
if( errno != EALREADY ) {
emit error( tr( "Can't change authentication on %1. %2 : %3" ).
arg( devname() ).
arg( errno ).
arg( strerror(errno) ) );
}
return;
}
reinit();
}
void OTDriver::changeEncryption(bool _encrypt) {
struct hci_dev_req dr;
if( ! open() ) {
return;
}
dr.dev_id = devId();
dr.dev_opt = _encrypt?ENCRYPT_P2P:ENCRYPT_DISABLED;
@@ -568,177 +568,177 @@ void OTDriver::getClass( QString & service,
} else {
service = "unspecified";
}
MainClassMap_t * MCM = MainClasses;
int major = cls[1] & 0x1f;
int minor = cls[0] >> 2;
if( (unsigned)(cls[1] & 0x1f) > sizeof(*major_devices)) {
device = tr("Invalid Device Class");
return;
}
device = major_devices[cls[1] & 0x1f];
while( MCM->Major != -1 ) {
if( major == MCM->Major ) {
// this class
ClassMap_t * CM = MCM->Map;
if( MCM->Map ) {
while( CM->Minor != -1 ) {
if( minor == CM->Minor ) {
break;
}
CM ++;
}
device = CM->Description;
} else {
// special case
if( major == 3 ) {
/* lan access */
if( minor == 0 ) {
device = "Uncategorized";
} else {
switch( minor / 8 ) {
case 0:
device = "Fully available";
break;
case 1:
device = "1-17% utilized";
break;
case 2:
device = "17-33% utilized";
break;
case 3:
device = "33-50% utilized";
break;
case 4:
device = "50-67% utilized";
break;
case 5:
device = "67-83% utilized";
break;
case 6:
device = "83-99% utilized";
break;
case 7:
device = "No service available";
break;
}
}
} else if( major == 6 ) { /* imaging */
if (minor & 4)
device = "Display";
if (minor & 8)
device = "Camera";
if (minor & 16)
device = "Scanner";
if (minor & 32)
device = "Printer";
}
}
break;
}
MCM ++;
}
if( MCM->Major == -1 ) {
device = "Unknown (reserved) minor device class";
}
}
QString OTDriver::strType() {
return QString( hci_dtypetostr(Type) );
}
void OTDriver::setFeatures( unsigned char * _f) {
Features = lmp_featurestostr(_f, NULL, 255);
}
void OTDriver::setManufacturer(int compid) {
Manufacturer = bt_compidtostr(compid);
}
OTHCISocket * OTDriver::openSocket( void ) {
if( ! Socket ) {
- owarn << "Open HCI socket to " << devname() << oendl;
+ odebug << "Open HCI socket to " << devname() << oendl;
Socket = new OTHCISocket( this );
}
return Socket;
}
void OTDriver::closeSocket( void ) {
if( Socket ) {
- owarn << "Close HCI socket to " << devname() << oendl;
+ odebug << "Close HCI socket to " << devname() << oendl;
delete Socket;
Socket = 0;
}
}
QString OTDriver::getPeerName( const OTDeviceAddress & PAddr ) {
QString S;
char name[100 ];
if( ! open() ) {
return QString("N/A");
}
if( hci_read_remote_name( fd(),
&(PAddr.getBDAddr()),
sizeof(name),
name,
100000 ) < 0 ) {
return QString( "N/A" );
}
return QString( name );
}
long OTDriver::getLinkQuality( const OTDeviceAddress & Addr ) {
struct hci_conn_info_req *cr;
struct hci_request rq;
read_rssi_rp rp;
uint16_t handle;
if( ! open() ) {
return 0;
}
cr = (struct hci_conn_info_req *)malloc(
sizeof(*cr) + sizeof(struct hci_conn_info));
if (!cr)
return 0;
bacpy( &(cr->bdaddr), &(Addr.getBDAddr()) );
cr->type = ACL_LINK;
if (ioctl( fd(), HCIGETCONNINFO, (unsigned long) cr) < 0) {
- owarn << "Get connection info failed" << oendl;
+ odebug << "Get connection info failed" << oendl;
free(cr);
return 0;
}
handle = htobs(cr->conn_info->handle);
free(cr);
memset(&rq, 0, sizeof(rq));
rq.ogf = OGF_STATUS_PARAM;
rq.ocf = OCF_READ_RSSI;
rq.cparam = &handle;
rq.clen = 2;
rq.rparam = &rp;
rq.rlen = GET_LINK_QUALITY_RP_SIZE;
if (hci_send_req( fd(), &rq, 100) < 0) {
- owarn << "Get connection info failed" << oendl;
+ odebug << "Get connection info failed" << oendl;
return 0;
}
if( rp.status ) {
- owarn << QString().sprintf("HCI get_link_quality cmd failed (0x%2.2X)", rp.status) << oendl;
+ odebug << QString().sprintf("HCI get_link_quality cmd failed (0x%2.2X)", rp.status) << oendl;
return 0;
}
return rp.rssi+50;
}
diff --git a/noncore/settings/networksettings2/opietooth2/OTDriverList.cpp b/noncore/settings/networksettings2/opietooth2/OTDriverList.cpp
index f703834..e5af742 100644
--- a/noncore/settings/networksettings2/opietooth2/OTDriverList.cpp
+++ b/noncore/settings/networksettings2/opietooth2/OTDriverList.cpp
@@ -1,86 +1,86 @@
/***************************************************************************
* Copyright (C) 2003 by Mattia Merzi *
* ottobit@ferrara.linux.it *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include <malloc.h>
#include <bluezlib.h>
#include <opie2/odebug.h>
#include <OTDriverList.h>
#include <OTGateway.h>
#include <OTDriver.h>
using namespace Opietooth2;
OTDriverList::OTDriverList( OTGateway * _OT ) : QVector<OTDriver>() {
OT = _OT;
setAutoDelete( true );
}
OTDriverList::~OTDriverList() {
}
void OTDriverList::update() {
struct hci_dev_list_req *dl;
struct hci_dev_req *dr;
struct hci_dev_info di;
int cur;
dl = 0;
cur = 0;
do {
cur += 5;
dl = (struct hci_dev_list_req*)
::realloc( dl, sizeof( struct hci_dev_list_req ) +
( cur * sizeof(struct hci_dev_req) )
);
if( dl == 0 ) {
// memory problem
exit(1);
}
dl->dev_num = cur;
if( ioctl( OT->getSocket(), HCIGETDEVLIST, (void*)dl) ) {
- owarn << "WARNING : cannot read device list. "
+ odebug << "WARNING : cannot read device list. "
<< errno
<< strerror( errno ) << oendl;
return;
}
// if num == cur perhaps we did not get all devices yet
} while( dl->dev_num == cur );
if( dl->dev_num != count() ) {
// new or missing devices
clear();
dr = dl->dev_req;
resize( dl->dev_num );
for( cur=0; cur < dl->dev_num; cur ++) {
memset( &di, 0, sizeof( di ) );
di.dev_id = (dr+cur)->dev_id;
// get device info
if( ioctl( OT->getSocket(), HCIGETDEVINFO, (void*)&di) != 0 )
continue; // uh ?
insert( cur, new OTDriver( OT, &di ) );
}
- owarn << "Found " << count() << " devices" << oendl;
+ odebug << "Found " << count() << " devices" << oendl;
::free( dl );
}
}
diff --git a/noncore/settings/networksettings2/opietooth2/OTGateway.cpp b/noncore/settings/networksettings2/opietooth2/OTGateway.cpp
index 6531cf6..e8137dd 100644
--- a/noncore/settings/networksettings2/opietooth2/OTGateway.cpp
+++ b/noncore/settings/networksettings2/opietooth2/OTGateway.cpp
@@ -61,430 +61,430 @@ OTGateway::OTGateway( void ) : QObject( 0, "OTGateway" ),
// load all peers we have ever seen
loadKnownPeers();
// iterate over drivers and find active connections
// adding/updating peers
loadActiveConnections();
// check every 4 seconds the state of BT
timerEvent(0);
RefreshTimer = -1;
setRefreshTimer( 4000 );
// load known link keys
readLinkKeys();
}
// close bluetooth system
OTGateway::~OTGateway( void ) {
if( AllPeersModified ) {
saveKnownPeers();
}
if( Scanning )
delete Scanning;
if( TheOTDevice )
delete TheOTDevice;
if( HciCtl >= 0 ) {
::close( HciCtl );
}
}
void OTGateway::setRefreshTimer( int T ) {
if( RefreshTimer != -1 ) {
killTimer( RefreshTimer );
}
if( T == 0 )
T = 4000;
RefreshTimer = startTimer( T );
}
OTDevice * OTGateway::getOTDevice( ) {
if( TheOTDevice == 0 ) {
// load bluetooth device and check state
TheOTDevice = new OTDevice( this );
connect( TheOTDevice,
SIGNAL( isEnabled( int, bool ) ),
this,
SLOT( SLOT_Enabled( int, bool ) ) );
connect( TheOTDevice,
SIGNAL( error( const QString & ) ),
this,
SLOT( SLOT_ShowError( const QString & ) ) );
}
return TheOTDevice;
}
// start bluetooth (if stopped)
// return TRUE if started
void OTGateway::SLOT_SetEnabled( bool Mode ) {
if( Mode ) {
SLOT_Enable();
return;
}
SLOT_Disable();
}
void OTGateway::SLOT_Enable() {
getOTDevice()->attach();
}
void OTGateway::SLOT_Disable() {
getOTDevice()->detach();
}
bool OTGateway::needsEnabling() {
return getOTDevice()->needsAttach();
}
bool OTGateway::isEnabled() {
if( getOTDevice()->deviceNr() >= 0 &&
driver( getOTDevice()->deviceNr() )->isUp() )
return TRUE;
// else check system
return getOTDevice()->isAttached();
}
void OTGateway::SLOT_ShowError( const QString & S ) {
- owarn << S << oendl;
+ odebug << S << oendl;
if( ErrorConnectCount > 0 ) {
// pass error
emit error( QString( "<p>" ) + S + "</p>" );
return;
}
QMessageBox::warning( 0,
tr("OTGateway error"),
S );
}
void OTGateway::connectNotify( const char * S ) {
if( S && strcmp( S, "error(const QString&)" ) == 0 ) {
ErrorConnectCount ++;
}
}
void OTGateway::disconnectNotify( const char * S ) {
if( S && strcmp( S, "error(const QString&)" ) == 0 ) {
ErrorConnectCount --;
}
}
void OTGateway::timerEvent( QTimerEvent * ) {
OTDriver * D;
unsigned int oldc = AllDrivers.count();
bool old;
AllDrivers.update();
if( oldc != AllDrivers.count() ) {
updateDrivers();
} else {
for( unsigned int i = 0;
i < AllDrivers.count();
i ++ ) {
D = AllDrivers[i];
old = D->isUp();
if( D->currentState() >= 0 ) {
if( old != D->isUp() ) {
emit stateChange( D, D->isUp() );
}
} else {
// if one driver is unable to provide info
// we refresh all devices
updateDrivers();
return;
}
}
}
}
void OTGateway::SLOT_Enabled( int id, bool Up ) {
- owarn << "device " << id << " state " << Up << oendl;
+ odebug << "device " << id << " state " << Up << oendl;
if( Up ) {
// device is up -> detect it
updateDrivers();
if( (unsigned)id >= AllDrivers.count() ) {
// to make sure that the driver really IS detected
AllDrivers[id]->bringUp();
}
} // if DOWN device already down
emit deviceEnabled( Up );
}
void OTGateway::updateDrivers( void ) {
OTDriver * D;
AllDrivers.update();
- owarn << "updated drivers. now " << AllDrivers.count() << oendl;
+ odebug << "updated drivers. now " << AllDrivers.count() << oendl;
// connect signals for each driver
for( unsigned int i = 0;
i < AllDrivers.count();
i ++ ) {
D = AllDrivers[i];
connect( D,
SIGNAL( error( const QString & ) ),
this,
SLOT( SLOT_ShowError( const QString & ) )
);
connect( D,
SIGNAL( stateChange( OTDriver *, bool ) ),
this,
SIGNAL( stateChange( OTDriver *, bool ) )
);
connect( D,
SIGNAL( driverDisappeared( OTDriver * ) ),
this,
SLOT( SLOT_DriverDisappeared( OTDriver * ) )
);
}
// verify main device too
if( TheOTDevice )
TheOTDevice->checkAttach();
// set to default scanning hardware
setScanWith( 0 );
emit driverListChanged();
}
void OTGateway::SLOT_DriverDisappeared( OTDriver * D ) {
- owarn << "Driver " << D->devname() << " when offline" << oendl;
+ odebug << "Driver " << D->devname() << " when offline" << oendl;
updateDrivers();
}
void OTGateway::scanNeighbourhood( OTDriver * D ) {
if( Scanning ) {
stopScanOfNeighbourhood();
}
if( D ) {
setScanWith( D );
}
Scanning = new OTInquiry( scanWith() );
connect( Scanning,
SIGNAL( peerFound( OTPeer *, bool )),
this,
SLOT( SLOT_PeerDetected( OTPeer *, bool ) )
);
connect( Scanning,
SIGNAL( finished()),
this,
SLOT( SLOT_FinishedDetecting() )
);
// start scanning
Scanning->inquire( 30.0 );
}
OTPeer* OTGateway::findPeer( const OTDeviceAddress & Addr ) {
for( unsigned int i = 0 ; i < AllPeers.count(); i ++ ) {
if( AllPeers[i]->address() == Addr ) {
return AllPeers[i];
}
}
return 0;
}
OTDriver* OTGateway::findDriver( const OTDeviceAddress & Addr ) {
for( unsigned int i = 0 ; i < AllDrivers.count(); i ++ ) {
if( AllDrivers[i]->address() == Addr ) {
return AllDrivers[i];
}
}
return 0;
}
void OTGateway::SLOT_PeerDetected( OTPeer * P, bool IsNew ) {
if( IsNew ) {
// new peer
- owarn << "New peer " << P->name() << oendl;
+ odebug << "New peer " << P->name() << oendl;
addPeer( P );
}
emit detectedPeer( P, IsNew );
}
void OTGateway::addPeer( OTPeer * P ) {
AllPeers.resize( AllPeers.size()+1);
AllPeers.insert( AllPeers.size()-1, P );
AllPeersModified = 1;
}
void OTGateway::removePeer( OTPeer * P ) {
int i = AllPeers.find( P );
if( i ) {
AllPeers.remove( i );
AllPeersModified = 1;
}
}
void OTGateway::stopScanOfNeighbourhood( void ) {
if( Scanning ) {
delete Scanning;
Scanning = 0;
}
}
void OTGateway::SLOT_FinishedDetecting() {
stopScanOfNeighbourhood();
emit finishedDetecting();
}
const char * OTGateway::deviceTypeToName( int cls ) {
switch ( (cls & 0x001F00) >> 8) {
case 0x00:
return "misc";
case 0x01:
return "computer";
case 0x02:
return "phone";
case 0x03:
return "lan";
case 0x04:
return "av";
case 0x05:
return "peripheral";
case 0x06:
return "imaging";
case 0x07:
default :
break;
}
return "unknown";
}
PANConnectionVector OTGateway::getPANConnections( void ) {
PANConnectionVector V;
struct bnep_connlist_req req;
struct bnep_conninfo ci[48];
V.setAutoDelete(TRUE);
int ctl = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_BNEP);
if (ctl < 0) {
- owarn << "Failed to open control socket" << oendl;
+ odebug << "Failed to open control socket" << oendl;
return V;
}
req.cnum = 48;
req.ci = ci;
if (ioctl(ctl, BNEPGETCONNLIST, &req)) {
- owarn << "Failed to get connection list" << oendl;
+ odebug << "Failed to get connection list" << oendl;
::close( ctl );
return V;
}
for ( unsigned i=0; i < req.cnum; i++) {
V.resize( V.size() + 1 );
if( ci[i].role == BNEP_SVC_PANU ) {
// we are the client
V.insert( V.size()-1, new OTPANConnection(
ci[i].device,
batostr((bdaddr_t *) ci[i].dst)
) );
}
}
::close( ctl );
return V;
}
struct link_key {
bdaddr_t sba;
bdaddr_t dba;
uint8_t key[16];
uint8_t type;
time_t time;
};
void OTGateway::readLinkKeys( void ) {
struct link_key k;
int rv;
AllKeys.truncate(0);
QFile F( "/etc/bluetooth/link_key" );
if( ! F.open( IO_ReadOnly ) ) {
emit error( tr("Cannot open link_key file") );
return;
}
while( 1 ) {
rv = F.readBlock( (char *)&k, sizeof( k ) );
if( rv == 0 )
// EOF
break;
if( rv < 0 ) {
emit error( tr("Read error in link key file") );
}
AllKeys.resize( AllKeys.size()+1 );
AllKeys[ AllKeys.size()-1 ].From.setBDAddr( k.sba );
AllKeys[ AllKeys.size()-1 ].To.setBDAddr( k.dba );
}
}
bool OTGateway::removeLinkKey( unsigned int Index ) {
OTLinkKey & LK = AllKeys[Index];
struct link_key k;
int rv;
QFile F( "/etc/bluetooth/link_key" );
QFile OutF( "/etc/bluetooth/newlink_key" );
if( ! F.open( IO_ReadOnly ) ) {
emit error( tr("Cannot open link_key file") );
return 0;
}
if( ! OutF.open( IO_WriteOnly | IO_Truncate ) ) {
emit error( tr("Cannot open temporary link_key file") );
return 0;
}
while( 1 ) {
rv = F.readBlock( (char *)&k, sizeof( k ) );
if( rv == 0 )
// EOF
break;
if( rv < 0 ) {
emit error( tr("Read error in link key file") );
return 0;
}
if( LK.from() != OTDeviceAddress( k.sba ) ||
LK.to() != OTDeviceAddress( k.dba ) ) {
// copy
OutF.writeBlock( (char *)&k, sizeof( k ) );
} // else remove this key
}
// rename files
QDir D( "/etc/bluetooth" );
diff --git a/noncore/settings/networksettings2/opietooth2/OTHCISocket.cpp b/noncore/settings/networksettings2/opietooth2/OTHCISocket.cpp
index 471c3bf..1997b44 100644
--- a/noncore/settings/networksettings2/opietooth2/OTHCISocket.cpp
+++ b/noncore/settings/networksettings2/opietooth2/OTHCISocket.cpp
@@ -1,274 +1,274 @@
//-*-c++-*-
/***************************************************************************
* Copyright (C) 2003 by Fred Schaettgen *
* kdebluetooth@schaettgen.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include <qbuffer.h>
#include <qtimer.h>
#include <qdatastream.h>
#include <opie2/odebug.h>
#include <bluezlib.h>
// #include "deviceaddress.h"
#include <OTHCISocket.h>
#include <OTDriver.h>
using namespace Opietooth2;
OTHCISocket::OTHCISocket( OTDriver * D ) :
QObject( D, D->devname() ) {
BStatusSet = false;
Driver = D;
HCIReadNotifier = 0;
}
OTHCISocket::~OTHCISocket() {
close();
}
void OTHCISocket::close() {
- owarn << "OTHCISocket::close()" << oendl;
+ odebug << "OTHCISocket::close()" << oendl;
if( HCIReadNotifier ) {
delete HCIReadNotifier;
}
if( HCISocket.isValid() ) {
HCISocket.close();
}
}
bool OTHCISocket::open() {
- owarn << "OTHCISocket::open()" << oendl;
+ odebug << "OTHCISocket::open()" << oendl;
int s;
s = ::socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (s < 0) {
emit error( tr( "Error creating socket on %1 : %2 %3").
arg( Driver->devname() ).
arg( errno ).
arg( strerror(errno) )
);
return false;
}
/* Bind socket to the HCI device */
struct sockaddr_hci sa;
sa.hci_family = AF_BLUETOOTH;
sa.hci_dev = Driver->devId();
if (bind(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
::close(s);
emit error( tr( "Error binding to socket to %1 : %2 %3").
arg( Driver->devname() ).
arg( errno ).
arg( strerror(errno) )
);
return false;
}
struct hci_filter flt;
hci_filter_clear(&flt);
hci_filter_set_ptype(HCI_EVENT_PKT, &flt);
hci_filter_all_events(&flt);
if( setsockopt(s, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0 ) {
::close(s);
emit error( tr( "HCI filter setup failed on %1 : %2 %3").
arg( Driver->devname() ).
arg( errno ).
arg( strerror(errno) )
);
return false;
}
if( HCIReadNotifier ) {
delete HCIReadNotifier;
}
HCISocket.setSocket(s, QSocketDevice::Datagram);
HCIReadNotifier = new QSocketNotifier(
s, QSocketNotifier::Read, this);
connect( HCIReadNotifier,
SIGNAL(activated(int)),
this,
SLOT(slotSocketActivated())
);
//connect(hciSocket, SIGNAL(error(int)),
// this, SLOT(slotSocketError(int)));
//connect(hciSocket, SIGNAL(connectionClosed()),
// this, SLOT(slotConnectionClosed()));
//hciSocket->setSocket(s);
return true;
}
void OTHCISocket::slotSocketError(int e) {
close();
emit error( tr( "HCI socket error 0x%1 on %1 : %2 %3").
arg(e,2,16).
arg( Driver->devname() ).
arg( errno ).
arg( strerror(errno) )
);
}
void OTHCISocket::slotSocketActivated() {
QSocketDevice::Error err = HCISocket.error();
if( (err == QSocketDevice::NoError ) &&
( HCISocket.isValid() ) ) {
//kdDebug() << "HCI socket ready read." << endl;
unsigned char buf[512];
int psize = HCISocket.readBlock((char*)buf, 512);
if (psize <= 0) {
slotSocketError(HCISocket.error());
HCISocket.close();
return;
}
//unsigned char packetType = buf[0];
unsigned char eventCode = buf[1];
unsigned char len = buf[2];
if (psize-3 == len) {
QByteArray databuf;
databuf.duplicate((char*)(buf+3), len);
emit event(eventCode, databuf);
if (eventCode == EVT_CMD_STATUS) {
updateStatus( databuf );
}
} else {
- owarn << "Error reading hci packet: packetSize("
+ odebug << "Error reading hci packet: packetSize("
<< psize
<< ")-3 != dataSize("
<< len
<< ")"
<< oendl;
}
} else if (err == QSocketDevice::NoError) {
slotConnectionClosed();
} else {
HCISocket.close();
slotSocketError(err);
}
}
void OTHCISocket::updateStatus(const QByteArray& data) {
QDataStream stream(data, IO_ReadOnly);
stream.setByteOrder(QDataStream::LittleEndian);
Q_UINT8 status, dummy;
Q_UINT16 opcode;
BStatusSet = true;
stream >> status >> dummy >> opcode;
//kdDebug() << "updatestatus opcode=" << uint32_t(opcode) << endl;
LastStatus = status;
LastStatusOgf = cmd_opcode_ogf(opcode);
LastStatusOcf = cmd_opcode_ocf(opcode);
}
void OTHCISocket::slotConnectionClosed() {
- owarn << "HCI connection closed." << oendl;
+ odebug << "HCI connection closed." << oendl;
emit connectionClosed();
}
void OTHCISocket::readEvent() {
if (HCIReadNotifier) {
slotSocketActivated();
}
}
bool OTHCISocket::sendCommand( unsigned char ogf,
unsigned short ocf,
QByteArray buf
) {
QBuffer packet;
QDataStream stream(&packet);
stream.setByteOrder(QDataStream::LittleEndian);
packet.open(IO_WriteOnly);
if (buf.size() > 255) return false;
//kdDebug() << "sendCommand. ogf=" << ogf << " ocf=" << ocf << endl;
Q_UINT16 opcode = cmd_opcode_pack(ogf, ocf);
Q_UINT8 pType = HCI_COMMAND_PKT;
Q_UINT8 buflen = buf.size();
stream << pType << opcode << buflen;
stream.writeRawBytes(buf.data(), buflen);
packet.close();
HCISocket.writeBlock((const char*)packet.buffer(),
packet.buffer().size());
return true;
}
bool OTHCISocket::readStatus( unsigned char ogf,
unsigned short ocf,
int *status,
int timeout_ms) {
QTimer timer;
timer.start(timeout_ms, true);
BStatusSet = false;
while (timer.isActive() && HCISocket.isValid()) {
- owarn << "OTHCISocket::readStatus()" << oendl;
+ odebug << "OTHCISocket::readStatus()" << oendl;
bool timeout = false;
if( HCISocket.bytesAvailable() == 0) {
int rv = HCISocket.waitForMore(timeout_ms);
timeout = (rv == 0);
}
if (!timeout) {
slotSocketActivated();
}
if( BStatusSet == true &&
ogf == LastStatusOgf &&
ocf == LastStatusOcf) {
*status = LastStatus;
- owarn << "OTHCISocket::readStatus(ogf="
+ odebug << "OTHCISocket::readStatus(ogf="
<< ogf
<< ",ocf="
<< ocf
<< ",timeout="
<< LastStatus
<< ")"
<< oendl;
return true;
}
}
- owarn << "OTHCISocket::readStatus(ogf="
+ odebug << "OTHCISocket::readStatus(ogf="
<< ogf
<< ",ocf="
<< ocf
<< ",timeout="
<< LastStatus
<< ") : timeout "
<< oendl;
return false;
}
int OTHCISocket::socket() {
return HCISocket.socket();
}
diff --git a/noncore/settings/networksettings2/opietooth2/OTInquiry.cpp b/noncore/settings/networksettings2/opietooth2/OTInquiry.cpp
index 8e94bbc..2bc63c7 100644
--- a/noncore/settings/networksettings2/opietooth2/OTInquiry.cpp
+++ b/noncore/settings/networksettings2/opietooth2/OTInquiry.cpp
@@ -1,219 +1,219 @@
//-*-c++-*-
/***************************************************************************
* Copyright (C) 2003 by Fred Schaettgen *
* kdebluetooth@schaettgen.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include <qcstring.h>
#include <qsocket.h>
#include <qdatetime.h>
#include <qtimer.h>
#include <qthread.h>
#include <qapplication.h>
#include <bluezlib.h>
#include <OTGateway.h>
#include <OTDriver.h>
#include <OTPeer.h>
#include <OTHCISocket.h>
#include <OTInquiry.h>
#include <opie2/odebug.h>
using namespace Opietooth2;
#define max(a,b) (((a)>(b)) ? (a) : (b))
#define min(a,b) (((a)>(b)) ? (b) : (a))
OTInquiry::OTInquiry( OTDriver * Drv ) : QObject( Drv ) {
reset();
InquiryTimeoutTimer = new QTimer(this);
connect( InquiryTimeoutTimer,
SIGNAL(timeout()),
this,
SLOT(slotInquiryTimeout()));
Driver = Drv;
Socket = Drv->openSocket();
Socket->open();
connect( Socket,
SIGNAL( event(unsigned char, QByteArray)),
this,
SLOT(slotHCIEvent(unsigned char, QByteArray)));
}
OTInquiry::~OTInquiry() {
stopInquiring();
}
void OTInquiry::stopInquiring( void ) {
if( Socket ) {
- owarn << "Stop inquiry" << oendl;
+ odebug << "Stop inquiry" << oendl;
Driver->closeSocket();
Socket = 0;
}
}
bool OTInquiry::inquire( double timeout, int numResponses, int lap) {
QByteArray cmdBuf(5);
cmdBuf[0] = lap & 0xFF;
cmdBuf[1] = (lap >> 8) & 0xFF;
cmdBuf[2] = (lap >> 16) & 0xFF;
cmdBuf[3] = max(0x01, min(0x30, int(timeout/1.28)));
cmdBuf[4] = (unsigned char)numResponses;
- owarn << "Send HCI inquiry command. wait for " << cmdBuf[3] << oendl;
+ odebug << "Send HCI inquiry command. wait for " << cmdBuf[3] << oendl;
Socket->sendCommand(0x01, 0x0001, cmdBuf);
int status;
if( Socket->readStatus(0x01, 0x0001, &status)) {
if (status == 0) {
SuccessfullyStarted = true;
InquiryTimeoutTimer->start( int(1000*(timeout+1.0)), true);
return true;
}
else {
QString S =QString().sprintf( "%x", status );
- owarn << "OTInquiry::inquiry() failed: 0x" << S << oendl;
+ odebug << "OTInquiry::inquiry() failed: 0x" << S << oendl;
emit finished();
return false;
}
} else {
- owarn << "OTInquiry::inquiry(): Timeout." << oendl;
+ odebug << "OTInquiry::inquiry(): Timeout." << oendl;
return false;
}
}
bool OTInquiry::isInquiring() {
return InquiryTimeoutTimer->isActive();
}
bool OTInquiry::isFinished() {
return SuccessfullyStarted && SuccessfullyEnded;
}
void OTInquiry::reset() {
SuccessfullyStarted = false;
SuccessfullyEnded = false;
//addrCache.clear();
//infoQueue.clear();
}
void OTInquiry::onPeerFound( OTPeer * Peer, bool IsNew ) {
emit peerFound( Peer, IsNew );
}
void OTInquiry::slotInquiryTimeout() {
emit error( tr( "Timeout while waiting for end of inquiry.") );
}
void OTInquiry::slotHCIEvent(unsigned char eventCode, QByteArray buf) {
- owarn << "OTInquiry: hci packet received: eventCode="
+ odebug << "OTInquiry: hci packet received: eventCode="
<< (unsigned int)eventCode
<< " packetLength="
<< (unsigned int)buf.size()
<< oendl;
unsigned char *data = (unsigned char*)buf.data();
switch (eventCode) {
case EVT_INQUIRY_COMPLETE:
{ unsigned char status = data[0];
- owarn << "EVT_INQUIRY_COMPLETE status=" << status << oendl;
+ odebug << "EVT_INQUIRY_COMPLETE status=" << status << oendl;
InquiryTimeoutTimer->stop();
if (status == 0) {
if( SuccessfullyStarted == true) {
- owarn << "OTInquiry ended successfully" << oendl;
+ odebug << "OTInquiry ended successfully" << oendl;
SuccessfullyEnded = true;
}
emit finished();
}
else {
emit error( tr( "OTInquiry completed with error (code %1)" ).
arg(status));
}
}
break;
case EVT_INQUIRY_RESULT:
{ int numResults = data[0];
OTPeer * P = 0;
bool IsNew;
OTDeviceAddress Addr;
QString N;
inquiry_info *results = (inquiry_info*)(data+1);
for (int n=0; n<numResults; n++) {
Addr.setBDAddr( results[n].bdaddr );
- owarn << "INQUIRY_RESULT: "
+ odebug << "INQUIRY_RESULT: "
<< Addr.toString()
<< oendl;
P = Driver->gateway()->findPeer( Addr );
if( P ) {
// peer known
if( P->state() != OTPeer::Peer_Up ) {
P->setState( OTPeer::Peer_Up );
}
IsNew = 0;
} else {
IsNew = 1;
// push the address to the address queue
// where it can be consumed by nextNeighbour()
P = new OTPeer( Driver->gateway() );
P->setState( OTPeer::Peer_Up ); // we just detected it
P->setAddress( Addr );
//if( addrCache.find(info.addr) == addrCache.end()) {
// addrCache.insert(info.addr);
P->setDeviceClass( (results[n].dev_class[0] << 16) |
(results[n].dev_class[1] << 8) |
(results[n].dev_class[2] << 0) );
// infoQueue.push_back(info);
P->setName( Driver->getPeerName( Addr ) );
}
// call the handler. Emits a signal if not overwritten
onPeerFound( P, IsNew );
// }
}
}
break;
case EVT_CMD_STATUS :
{ int status = data[0];
int numHciCmdPkts = data[1];
int cmdOpcode = *((uint16_t*)(data+2));
- owarn << "EVT_CMD_STATUS status="
+ odebug << "EVT_CMD_STATUS status="
<< status
<< " numPkts="
<< numHciCmdPkts
<< " cmdOpcode="
<< cmdOpcode
<< oendl;
if (cmdOpcode == OCF_INQUIRY) {
}
}
break;
}
}
diff --git a/noncore/settings/networksettings2/opietooth2/OTPeer.cpp b/noncore/settings/networksettings2/opietooth2/OTPeer.cpp
index 0d7e943..2272f04 100644
--- a/noncore/settings/networksettings2/opietooth2/OTPeer.cpp
+++ b/noncore/settings/networksettings2/opietooth2/OTPeer.cpp
@@ -1,366 +1,366 @@
//-*-c++-*-
/***************************************************************************
* Copyright (C) 2003 by Fred Schaettgen *
* kdebluetooth@schaettgen.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include <assert.h>
#include <sys/poll.h>
#include <string.h>
#include <bluezlib.h>
#include <qarray.h>
#include <qtextstream.h>
#include <opie2/odebug.h>
#include <OTDeviceAddress.h>
#include <OTSDPAttribute.h>
#include <OTSDPService.h>
#include <OTPeer.h>
#include <OTGateway.h>
#include <OTDriver.h>
using namespace Opietooth2;
OTPeer::OTPeer( OTGateway * _OT ) {
OT = _OT;
State = Peer_Unknown;
ConnectedTo = 0;
}
OTPeer::OTPeer( QTextStream & TS, OTGateway * _OT ) {
OT = _OT;
State = Peer_Unknown;
ConnectedTo = 0;
load( TS );
}
OTPeer::~OTPeer( ) {
}
void OTPeer::updateServices( void ) {
sdp_session_t *session;
serviceList.clear();
- owarn << "Get services from " << Addr.toString() << oendl;
+ odebug << "Get services from " << Addr.toString() << oendl;
session = sdp_connect( &(OTDeviceAddress::any.getBDAddr()),
&(Addr.getBDAddr()),
0);
if (!session) {
- owarn << "sdp_connect("
+ odebug << "sdp_connect("
<< Addr.toString()
<< ") failed"
<< oendl;
return; // error
}
uint32_t range = 0x0000ffff;
sdp_list_t* attrId = sdp_list_append(0, &range);
// search all public features
uuid_t grp;
sdp_uuid16_create( &grp, PUBLIC_BROWSE_GROUP );
sdp_list_t * search = sdp_list_append(0, &grp );
// get data from peer
sdp_list_t* seq;
if (sdp_service_search_attr_req( session,
search,
SDP_ATTR_REQ_RANGE,
attrId,
&seq ) ) {
- owarn << "Service Search failed" << oendl;
+ odebug << "Service Search failed" << oendl;
sdp_close(session);
return;
}
sdp_list_free(attrId, 0);
sdp_list_free(search, 0);
// process result
sdp_list_t* next = NULL;
for (; seq; seq = next) {
sdp_record_t *rec = (sdp_record_t *) seq->data;
sdp_list_t* attrlist = rec->attrlist;
AttributeVector alist;
OTSDPService * service;
service = new OTSDPService();
for (; attrlist; attrlist = attrlist->next) {
int attrID = ((sdp_data_t*)(attrlist->data))->attrId;
service->addAttribute(
attrID,
new OTSDPAttribute( (sdp_data_t*)(attrlist->data) )
);
}
serviceList.resize( serviceList.size() + 1 );
serviceList.insert( serviceList.size() - 1, service );
next = seq->next;
free(seq);
sdp_record_free(rec);
}
sdp_close(session);
}
bool OTPeer::hasServiceClassID( const OTUUID & uuid) {
for( unsigned int i = 0;
i < serviceList.count();
i ++ ) {
if( serviceList[i]->hasClassID(uuid))
return true;
}
return false;
}
/** Get a vector of Rfcomm channels of the services having "uuid" in the class ID List*/
QArray<int> OTPeer::rfcommList( const OTUUID & uuid) {
QArray<int> rfcommList;
unsigned int channel;
for( unsigned int i = 0;
i < serviceList.count();
i ++ ) {
if( serviceList[i]->hasClassID(uuid)) {
if( serviceList[i]->rfcommChannel(channel) ) {
rfcommList.resize( rfcommList.size()+1 );
rfcommList[rfcommList.size()-1] = channel;
}
}
}
return rfcommList;
}
void OTPeer::save( QTextStream & TS ) {
TS << "bdaddr " << address().toString() << endl;
TS << "name " << name() << endl;
TS << "class " << deviceClass() << endl;
}
void OTPeer::load( QTextStream & TS ) {
QString S;
S = TS.readLine();
setAddress( OTDeviceAddress( S.mid( 7 ) ) );
S = TS.readLine();
setName( S.mid( 5 ) );
S = TS.readLine();
setDeviceClass( S.mid( 6 ).toLong() );
}
#define MAGICNR -99999
#define POLLDELAY 1000
#define PREMAGICNR (MAGICNR+POLLDELAY)
void OTPeer::findOutState( int timeoutInSec, bool Force ) {
ProbeFD = -1;
if( Force && ConnectedTo == 0 ) {
State = OTPeer::Peer_Unknown;
} // else keep state or is connected to us
if( State == OTPeer::Peer_Unknown ) {
ProbePhase = 0;
ProbeTimeout = timeoutInSec*1000;
- owarn << "Ping " << address().toString() << oendl;
+ odebug << "Ping " << address().toString() << oendl;
startTimer( POLLDELAY );
} else {
ProbeTimeout = 0;
startTimer( 0 );
}
}
#define PINGSIZE 20
void OTPeer::timerEvent( QTimerEvent * ev ) {
ProbeTimeout -= POLLDELAY;
if( State == OTPeer::Peer_Unknown ) {
switch( ProbePhase ) {
case 0 : // connect nonblock
{ struct sockaddr_l2 addr;
if (( ProbeFD = ::socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_L2CAP)) < 0) {
ProbeTimeout = 0;
break;
}
memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
addr.l2_bdaddr = OTDeviceAddress::any.getBDAddr();
if( ::bind( ProbeFD, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
ProbeTimeout = 0;
break;
}
// non blocking
if( ::fcntl( ProbeFD, F_SETFL, O_NONBLOCK ) < 0 ) {
ProbeTimeout = 0;
break;
}
// to this peer
addr.l2_bdaddr = address().getBDAddr();
if( ::connect( ProbeFD, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
if( errno != EAGAIN && errno != EINPROGRESS ) {
ProbeTimeout = 0;
break;
} // wait for connect to fail or succeed
}
}
ProbePhase = 1; // wait for connect
break;
case 1 :
{ struct pollfd pf[1];
char buf[L2CAP_CMD_HDR_SIZE + PINGSIZE + 20];
int n;
pf[0].fd = ProbeFD;
pf[0].events = POLLOUT;
if( (n = ::poll(pf, 1, 0)) < 0 ) {
- owarn << address().toString()
+ odebug << address().toString()
<< " : errno "
<< errno
<< " "
<< strerror(errno)<<oendl;
ProbeTimeout = 0;
break;
}
if( ! n ) {
// not ready -> try again
break;
}
// send ping
for( unsigned int i = L2CAP_CMD_HDR_SIZE; i < sizeof(buf); i++)
buf[i] = (i % 40) + 'A';
l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf;
/* Build command header */
cmd->code = L2CAP_ECHO_REQ;
cmd->ident = *(char *)this; // get some byte
cmd->len = PINGSIZE;
/* Send Echo Request */
if( ::send(ProbeFD, buf, PINGSIZE + L2CAP_CMD_HDR_SIZE, 0) <= 0) {
if( errno == EACCES ) {
// permission denied means that we could not
// connect because the device does not allow us
// but it is UP
- owarn << address().toString()
+ odebug << address().toString()
<< " good send error "
<< errno
<< " "
<< strerror( errno)
<< oendl;
State = OTPeer::Peer_Up;
ProbeTimeout = 0;
break;
} else if( errno != EBUSY ) {
- owarn << address().toString()
+ odebug << address().toString()
<< " : errno "
<< errno
<< " "
<< strerror(errno)
<< oendl;
ProbeTimeout = 0;
break;
} // else want some more
}
ProbePhase = 2; // wait for ping reply
}
break;
case 2 : // wait for reply
{ struct pollfd pf[1];
char buf[L2CAP_CMD_HDR_SIZE + PINGSIZE + 20];
l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf;
int n;
pf[0].fd = ProbeFD;
pf[0].events = POLLIN;
if( (n = ::poll(pf, 1, 0)) < 0 ) {
- owarn << address().toString()
+ odebug << address().toString()
<< " : errno "
<< errno
<< " "
<< strerror(errno)
<<oendl;
ProbeTimeout = 0;
break;
}
if( ! n ) {
// not ready -> try again
break;
}
if( (n = ::recv( ProbeFD, buf, sizeof(buf), 0)) < 0) {
- owarn << address().toString()
+ odebug << address().toString()
<< "errno "
<< errno
<< " "
<< strerror(errno)
<< oendl;
ProbeTimeout = 0;
break;
}
/* Check for our id */
if( cmd->ident != *(char *)this )
// not our reply
break;
- owarn << "reply from "
+ odebug << "reply from "
<< address().toString()
<< oendl;
// whatever reply we get is a valid reply
State = OTPeer::Peer_Up;
ProbeTimeout = 0;
}
break;
}
if( State != OTPeer::Peer_Unknown ) {
ProbeTimeout = 0;
}
}
if( ProbeTimeout <= 0 ) {
// regular timeout
emit peerStateReport( this );
if( State == Peer_Unknown ) {
State = Peer_Down;
}
if( ProbeFD >= 0 ) {
// requested to stop by caller -> stop probing
::close( ProbeFD );
}
// no more waiting
killTimer( ev->timerId() );
} // else sleep some more
}
void OTPeer::stopFindingOutState( void ) {
ProbeTimeout = PREMAGICNR;
}
diff --git a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp
index b14cc2f..8323549 100644
--- a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp
+++ b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp
@@ -444,262 +444,262 @@ int OTScan::getDevice( OTPeer *& Peer,
bool IsUp = 0;
unsigned int i;
// check if bluetooth is up
OTDriverList & DL = OT->getDriverList();
for( i = 0;
i < DL.count();
i ++ ) {
if( DL[i]->isUp() ) {
// one device that is up found
IsUp = 1;
break;
}
}
// use this driver
OT->setScanWith( OT->driver(i) );
// create dialog
QDialog * Dlg = new QDialog( Parent, 0, TRUE );
QVBoxLayout * V = new QVBoxLayout( Dlg );
OTScan * Scn = new OTScan( Dlg );
connect( Scn,
SIGNAL( selected() ),
Dlg,
SLOT( accept() )
);
if( Filter ) {
Scn->setScanFilter( Filter );
}
V->addWidget( Scn );
Dlg->setCaption( tr("Scan Neighbourhood" ) );
Dlg->showMaximized();
int rv = Dlg->exec();
if( rv == QDialog::Accepted ) {
// get peer
Peer = Scn->selectedPeer();
if( Peer == 0 ) {
// no peer selected
rv = QDialog::Rejected;
} else {
Channel = Scn->selectedChannel();
}
}
delete Dlg;
return rv;
}
void OTScan::setScanFilter( const UUIDVector & V ) {
Filter = V;
}
void OTScan::resetScanFilter( void ) {
Filter.truncate(0);
}
void OTScan::SLOT_DoScan( bool DoIt ) {
if( DoIt ) {
OT->scanNeighbourhood();
} else {
OT->stopScanOfNeighbourhood();
}
scanMode( DoIt );
}
// double clicked on a device
void OTScan::SLOT_Selected( QListViewItem * it ) {
if( ! it )
return;
if( Filter.count() > 0 ) {
// filter on service
if( it->depth() == 0 ) {
// select a service and not a device
return;
}
// store result
SelectedPeer = ((PeerLVI *)it->parent())->peer();
SelectedChannel = ((ChannelLVI *)it)->channel();
} else {
// click on device
if( it->depth() != 0 ) {
return;
}
SelectedPeer = ((PeerLVI *)it)->peer();
SelectedChannel = 0;
}
- owarn << "Selected " << SelectedPeer->address().toString() <<
+ odebug << "Selected " << SelectedPeer->address().toString() <<
" Channel " << SelectedChannel << oendl;
emit selected();
}
void OTScan::SLOT_FinishedDetecting( ) {
scanMode( false );
}
void OTScan::SLOT_CleanupOld( ) {
// iterate over all peers and find those that
// are down and have no pairing info
OTPeer * TheP;
const LinkKeyArray & Keys = OT->getLinkKeys();
QListViewItem * Lit = DetectedPeers_LV->firstChild();
while( Lit ) {
TheP = ((PeerLVI *)Lit)->peer();
if( TheP->state() == OTPeer::Peer_Down ) {
unsigned int k;
// what about linkkeys ?
for( k = 0; k < Keys.count(); k ++ ) {
if( TheP->address() == Keys[k].to() ||
TheP->address() == Keys[k].from()
) {
// part of linkkey
- owarn << "LINKKEY " << TheP->address().toString() << oendl;
+ odebug << "LINKKEY " << TheP->address().toString() << oendl;
break;
}
}
if( k == Keys.count() ) {
- owarn << "RM LINKKEY " << TheP->address().toString() << oendl;
+ odebug << "RM LINKKEY " << TheP->address().toString() << oendl;
// not found -> remember to remove this peer
QListViewItem * Nit;
OT->removePeer( TheP );
Nit = Lit->nextSibling();
delete Lit;
Lit = Nit;
continue;
}
} else {
- owarn << "NODOWN " << TheP->address().toString() << oendl;
+ odebug << "NODOWN " << TheP->address().toString() << oendl;
}
Lit = Lit->nextSibling();
}
}
void OTScan::SLOT_NewPeer( OTPeer * P, bool IsNew ){
PeerLVI * it = 0;
if( IsNew ) {
it = new PeerLVI( P, DetectedPeers_LV );
} else {
// find peer in table
QListViewItem * Lit = DetectedPeers_LV->firstChild();
while( Lit ) {
if( ((PeerLVI *)Lit)->peer() == P ) {
// this item
it = (PeerLVI *)Lit;
break;
}
Lit = Lit->nextSibling();
}
if( ! it ) {
- owarn << "Should not occur" << oendl;
+ odebug << "Should not occur" << oendl;
return;
}
}
// update/show info
it->setText( 0, P->name() );
it->setPixmap(0, Icons->deviceIcon(
OT->deviceTypeToName( P->deviceClass() ) ) );
// tell peer to report its state async
connect( P,
SIGNAL( peerStateReport( OTPeer *)),
this,
SLOT( SLOT_PeerState( OTPeer *))
);
if( IsNew ) {
// find state
refreshState( (PeerLVI *)it, 1 );
} else {
// update staet
SLOT_PeerState( P );
}
}
void OTScan::SLOT_PeerState( OTPeer * P ) {
PeerLVI * it = (PeerLVI *)DetectedPeers_LV->firstChild();
while( it ) {
if( it->peer() == P ) {
break;
}
it = (PeerLVI * )it->nextSibling();
}
if( ! it )
return;
switch( P->state() ) {
case OTPeer::Peer_Unknown :
case OTPeer::Peer_Down :
it->setPixmap( 1, 0 );
break;
case OTPeer::Peer_Up :
it->setPixmap( 1, Icons->loadPixmap(
( P->connectedTo() ) ? "connected" : "notconnected" ) );
if( it == Current && ! StrengthTimer->isActive() ) {
// start showing strength
StrengthTimer->start( 1000, FALSE );
SLOT_UpdateStrength();
}
break;
}
}
void OTScan::SLOT_RefreshState( void ) {
QListViewItem * it = DetectedPeers_LV->firstChild();
while( it ) {
if( it->isSelected() ) {
break;
}
it = it->nextSibling();
}
if( ! it )
return;
refreshState( (PeerLVI *)it, 1 );
}
void OTScan::refreshState( PeerLVI * it, bool Force ) {
it->setPixmap( 1, Icons->loadPixmap( "find" ) );
it->peer()->findOutState( 30, Force );
}
void OTScan::SLOT_Show( QListViewItem * it ) {
if( ! it || it->depth() > 0 )
return;
QString S;
Current = (PeerLVI *)it;
Strength_PB->setProgress( 0 ); // reset
Address_LBL->setText( Current->peer()->address().toString() );
Peer_GB->setTitle( Current->peer()->name() );
const LinkKeyArray & Keys = OT->getLinkKeys();
Paired_Led->setOn( FALSE );
for( unsigned int i = 0;
i < Keys.count();
i ++ ) {
if( Current->peer()->address() == Keys[i].to() ) {
Paired_Led->setOn( TRUE );
@@ -836,193 +836,193 @@ void OTScan::SLOT_RefreshServices( void ) {
ff < Filter.count();
ff ++ ) {
if( UIDV[j] == Filter[ff] ) {
FilterOut = 0;
break;
}
}
if( FilterOut ) {
// not in filter list
continue;
}
} // else show
ID = UIDV[j].toShort();
if( ID >= 0x1200 && ID <= 0x12ff ) {
// use this profile
unsigned int ch;
bool has;
has = V[i]->rfcommChannel( ch );
SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI );
SIt->setText(0, V[i]->name() );
Pm = Icons->serviceIcon( ID, R );
SIt->setPixmap(0, Pm );
break;
}
}
}
}
}
scanMode( false );
}
void OTScan::scanMode( bool M ) {
// avoid infinite loop because it triggers DoScan
Detect_But->blockSignals( TRUE );
Detect_But->setOn( M );
Detect_But->setText( (M) ? tr("Scanning") : tr("Scan") );
Detect_But->blockSignals( FALSE );
}
//
//
//
//
//
OTManage::OTManage( QWidget * parent, OTIcons * _IC ) :
OTManageGUI( parent ) {
OT = OTGateway::getOTGateway();
Icons = (_IC ) ? _IC : new OTIcons();
MyIcons = (_IC == 0 );
AllDrivers_LV->setSorting(-1);
connect( OT,
SIGNAL( driverListChanged() ),
this,
SLOT( SLOT_DriverListChanged() )
);
connect( OT,
SIGNAL( stateChange( OTDriver *, bool ) ),
this,
SLOT( SLOT_StateChange( OTDriver *, bool ) )
);
SLOT_DriverListChanged();
AllDrivers_LV->header()->hide();
}
OTManage::~OTManage() {
if( MyIcons )
delete Icons;
OTGateway::releaseOTGateway();
}
void OTManage::SLOT_ShowDriver( QListViewItem * It ) {
if( It == 0 || It->depth() > 0 )
// not toplevel
return;
DriverLVI * it = (DriverLVI *) It;
DriverIsUp_CB->setChecked( it->driver()->isUp() );
}
void OTManage::SLOT_UpDriver( bool Up ) {
QListViewItem * it = AllDrivers_LV->firstChild();
while( it ) {
if( it->isSelected() ) {
OTDriver * D = ((DriverLVI *)it)->driver();
- owarn << "UP driver " << D->devname() << oendl;
+ odebug << "UP driver " << D->devname() << oendl;
// this
D->setUp( Up );
return;
}
it = it->nextSibling();
}
}
void OTManage::SLOT_StateChange( OTDriver * D, bool Up ) {
QListViewItem * it = AllDrivers_LV->firstChild();
while( it ) {
if( ((DriverLVI *)it)->driver() == D ) {
it->setPixmap( 0,
Icons->loadPixmap( ( Up ) ? "bluezon" : "bluezoff" ) );
return;
}
it = it->nextSibling();
}
}
void OTManage::SLOT_DriverListChanged( ) {
DriverLVI * It;
QListViewItem * Sub;
QListViewItem * First = 0;
OTDriver* D;
OTDriverList & DL = OT->getDriverList();
AllDrivers_LV->clear();
for( unsigned int i = 0;
i < DL.count();
i ++ ) {
D = DL[i];
It = new DriverLVI( D, AllDrivers_LV );
if( ! First )
First = It;
It->setText( 0, D->devname() );
It->setPixmap( 0,
Icons->loadPixmap( (D->isUp()) ?
"bluezon" : "bluezoff" ) );
Sub = new QListViewItem( It );
Sub->setText( 0, tr( "Name" ) );
Sub->setText( 1, D->name() );
Sub = new QListViewItem( It );
Sub->setText( 0, tr( "Address" ) );
Sub->setText( 1, D->address().toString() );
Sub = new QListViewItem( It );
Sub->setText( 0, tr( "Revision" ) );
Sub->setText( 1, D->revision() );
Sub = new QListViewItem( It );
Sub->setText( 0, tr( "Manufacturer" ) );
Sub->setText( 1, D->manufacturer() );
QString Service, Device;
D->getClass( Service, Device );
Sub = new QListViewItem( It );
Sub->setText( 0, tr( "Service classes" ) );
Sub->setText( 1, Service );
Sub = new QListViewItem( It );
Sub->setText( 0, tr( "Device class" ) );
Sub->setText( 1, Device );
}
if( DL.count() ) {
AllDrivers_LV->setCurrentItem( First );
DriverIsUp_CB->setEnabled( TRUE );
} else {
DriverIsUp_CB->setChecked( FALSE );
DriverIsUp_CB->setEnabled( FALSE );
}
}
void OTManage::SLOT_SetRefreshTimer( int v ) {
OT->setRefreshTimer( v * 1000 );
}
//
//
//
//
//
OTMain::OTMain( QWidget * parent ) : OTMainGUI( parent ) {
Icons = new OTIcons();
SnifWindow = 0;
OT = OTGateway::getOTGateway();
connect( OT,
SIGNAL( deviceEnabled( bool ) ),
diff --git a/noncore/settings/networksettings2/opietooth2/config.in b/noncore/settings/networksettings2/opietooth2/config.in
index 720f49a..084e8c0 100644
--- a/noncore/settings/networksettings2/opietooth2/config.in
+++ b/noncore/settings/networksettings2/opietooth2/config.in
@@ -1,5 +1,5 @@
config NS2OPIETOOTH
- boolean "opie-networksettings2 bluetooth library"
+ boolean "Opietooth2 bluetooth library"
default "y"
- depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE
+ depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBBLUEZ_DEP && NS2CORE
diff --git a/noncore/settings/networksettings2/opietooth2/libopietooth2.postinst b/noncore/settings/networksettings2/opietooth2/libopietooth2.postinst
index cd605c2..2713c61 100755
--- a/noncore/settings/networksettings2/opietooth2/libopietooth2.postinst
+++ b/noncore/settings/networksettings2/opietooth2/libopietooth2.postinst
@@ -1,10 +1,10 @@
#!/bin/sh
QTPB=/opt/QtPalmtop/bin
[ ! -L ${QTPB}/networksettings2-opietooth ] && ln -sf ${QTPB}/networksettings2 ${QTPB}/networksettings2-opietooth
# qcop QPE/Taskbar "linkChanged(opietooth)"
-qcop QPE/Taskbar "reloadApps()"
+${QTPB}/qcop QPE/Taskbar "reloadApps()"
exit 0
diff --git a/noncore/settings/networksettings2/opietooth2/opietooth2.pro b/noncore/settings/networksettings2/opietooth2/opietooth2.pro
index e0057a9..16277cf 100644
--- a/noncore/settings/networksettings2/opietooth2/opietooth2.pro
+++ b/noncore/settings/networksettings2/opietooth2/opietooth2.pro
@@ -1,37 +1,44 @@
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 ../networksettings2
DEPENDPATH += $(OPIEDIR)/include
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 )
+
+!isEmpty( LIBBLUEZ_INC_DIR ) {
+ INCLUDEPATH += $$LIBBLUEZ_INC_DIR
+}
+!isEmpty( LIBBLUEZ_LIB_DIR ) {
+ LIBS += -L$$LIBBLUEZ_LIB_DIR
+}
diff --git a/noncore/settings/networksettings2/profile/profilerun.cpp b/noncore/settings/networksettings2/profile/profilerun.cpp
index ab57a00..acb67bd 100644
--- a/noncore/settings/networksettings2/profile/profilerun.cpp
+++ b/noncore/settings/networksettings2/profile/profilerun.cpp
@@ -1,27 +1,27 @@
#include <resources.h>
#include "profilerun.h"
State_t ProfileRun::detectState( void ) {
if( Data->Disabled ) {
return Disabled;
}
return Unknown;
}
QString ProfileRun::setMyState( NodeCollection * NC, Action_t A, bool ) {
- owarn << "Profile " << Data->Disabled << oendl;
+ odebug << "Profile " << Data->Disabled << oendl;
if( A == Disable ) {
if( ! Data->Disabled ) {
Data->Disabled = 1;
NC->setModified( 1 );
}
} else if( A == Enable ) {
if( Data->Disabled ) {
Data->Disabled = 0;
NC->setModified( 1 );
}
}
return QString();
}
diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp
index eb439c1..de8c8a2 100644
--- a/noncore/settings/networksettings2/usb/usbrun.cpp
+++ b/noncore/settings/networksettings2/usb/usbrun.cpp
@@ -1,119 +1,120 @@
#include <qfile.h>
#include <qfileinfo.h>
#include <qtextstream.h>
#include <resources.h>
#include "usbrun.h"
State_t USBRun::detectState( void ) {
// unavailable : no card found
// available : card found and assigned to us or free
// up : card found and assigned to us and up
NodeCollection * NC = nodeCollection();
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;
QTextStream TS(&F);
X = TS.readLine();
Log(("%s exists\n", S.latin1() ));
// find interface
if( handlesInterface( X ) ) {
for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
It.current();
++It ) {
Run = It.current();
if( X == Run->Name ) {
NC->assignInterface( Run );
return IsUp;
}
}
}
}
Log(("Assigned %p\n", NC->assignedInterface() ));
+
if( ( Run = NC->assignedInterface() ) ) {
// we already have an interface assigned -> still present ?
if( ! Run->IsUp ) {
// usb is still free -> keep assignment
return Available;
} // else interface is up but NOT us -> some other profile
}
// nothing (valid) assigned to us
NC->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
- ) {
+ if( getInterface() ) {
// proper type, and Not UP -> free
// usb cables are currently always available when requested
// until we can detect if we are plugged in
return Available;
}
- }
return Unavailable;
}
QString USBRun::setMyState( NodeCollection * NC, Action_t A, bool ) {
- // nothing needs to be done to 'activate' or 'deactivate'
- // a cable
+ InterfaceInfo * I = getInterface();
+
+ if( ! I ) {
+ return QString("No usb device available");
+ }
+
+ Log(( "Grabbed USB interface %s\n", I->Name.latin1() ));
+ // grab this interface
+ NC->assignInterface( I );
+
return QString();
}
// get interface that is free or assigned to us
InterfaceInfo * USBRun::getInterface( void ) {
System & S = NSResources->system();
InterfaceInfo * best = 0, * Run;
- QRegExp R( "usb[0-9abcdef]" );
for( QDictIterator<InterfaceInfo> It(S.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
) {
// this is a USB card
if( Run->assignedConnection() == netNode()->connection() ) {
// assigned to us
return Run;
- } else if( Run->assignedConnection() == 0 ) {
+ } else if( ! Run->IsUp &&
+ Run->assignedConnection() == 0 ) {
// free
best = Run;
- }
+ } // UP or not assigned to us
}
}
return best; // can be 0
}
bool USBRun::handlesInterface( const QString & S ) {
return Pat.match( S ) >= 0;
}
bool USBRun::handlesInterface( InterfaceInfo * I ) {
return handlesInterface( I->Name );
}