summaryrefslogtreecommitdiff
authorwimpie <wimpie>2005-01-09 00:32:10 (UTC)
committer wimpie <wimpie>2005-01-09 00:32:10 (UTC)
commite54346d28b19d3ac671802a25e8c03f346693291 (patch) (unidiff)
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) (ignore 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.cpp41
-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.cpp51
24 files changed, 139 insertions, 137 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 @@
1#include <qapplication.h> 1#include <qapplication.h>
2#include <resources.h> 2#include <resources.h>
3#include <OTDevice.h> 3#include <OTDevice.h>
4#include <OTGateway.h> 4#include <OTGateway.h>
5#include "bluetoothRFCOMMrun.h" 5#include "bluetoothRFCOMMrun.h"
6 6
7using Opietooth2::OTGateway; 7using Opietooth2::OTGateway;
8using Opietooth2::OTDevice; 8using Opietooth2::OTDevice;
9using Opietooth2::OTDeviceAddress; 9using Opietooth2::OTDeviceAddress;
10 10
11BluetoothRFCOMMRun::~BluetoothRFCOMMRun( void ) { 11BluetoothRFCOMMRun::~BluetoothRFCOMMRun( void ) {
12 if( OT ) { 12 if( OT ) {
13 OTGateway::releaseOTGateway(); 13 OTGateway::releaseOTGateway();
14 } 14 }
15} 15}
16 16
17State_t BluetoothRFCOMMRun::detectState( void ) { 17State_t BluetoothRFCOMMRun::detectState( void ) {
18 18
19 if( ! OT ) { 19 if( ! OT ) {
20 OT = OTGateway::getOTGateway(); 20 OT = OTGateway::getOTGateway();
21 } 21 }
22 22
23 if( deviceNrOfConnection() >= 0 ) { 23 if( deviceNrOfConnection() >= 0 ) {
24 return Available; 24 return Available;
25 } 25 }
26 26
27 owarn << "Bluetooth " 27 odebug << "Bluetooth "
28 << OT->isEnabled() 28 << OT->isEnabled()
29 << oendl; 29 << oendl;
30 30
31 return ( OT->isEnabled() ) ? Off : Unavailable; 31 return ( OT->isEnabled() ) ? Off : Unavailable;
32} 32}
33 33
34QString BluetoothRFCOMMRun::setMyState( NodeCollection *, 34QString BluetoothRFCOMMRun::setMyState( NodeCollection *,
35 Action_t A, 35 Action_t A,
36 bool ) { 36 bool ) {
37 37
38 if( OT ) { 38 if( OT ) {
39 OTGateway::getOTGateway(); 39 OTGateway::getOTGateway();
40 } 40 }
41 41
42 if( A == Activate ) { 42 if( A == Activate ) {
43 // from OFF to Available 43 // from OFF to Available
44 RFCOMMChannel * Ch = getChannel( ); 44 RFCOMMChannel * Ch = getChannel( );
45 System & Sys = NSResources->system(); 45 System & Sys = NSResources->system();
46 46
47 if( Ch ) { 47 if( Ch ) {
48 // connect to this peer 48 // connect to this peer
49 DeviceNr = OT->getFreeRFCommDevice(); 49 DeviceNr = OT->getFreeRFCommDevice();
50 QStringList S; 50 QStringList S;
51 51
52 S << "rfcomm" 52 S << "rfcomm"
53 << "bind" 53 << "bind"
54 << QString().setNum( DeviceNr ) 54 << QString().setNum( DeviceNr )
55 << Ch->BDAddress 55 << Ch->BDAddress
56 << QString().setNum( Ch->Channel ); 56 << QString().setNum( Ch->Channel );
57 57
58 if( Sys.runAsRoot( S ) ) { 58 if( Sys.runAsRoot( S ) ) {
59 return QString( "Error starting %1").arg(S.join(" ")); 59 return QString( "Error starting %1").arg(S.join(" "));
60 } 60 }
61 61
62 // here rfcomm should be running -> we will detect state later 62 // here rfcomm should be running -> we will detect state later
63 return QString(); 63 return QString();
64 } else { 64 } else {
65 Log(( "No channel selected -> cancel\n" )); 65 Log(( "No channel selected -> cancel\n" ));
66 return QString( "No channel selected. Operation cancelled" ); 66 return QString( "No channel selected. Operation cancelled" );
67 } 67 }
68 } 68 }
69 69
70 if( A == Deactivate ) { 70 if( A == Deactivate ) {
71 if( DeviceNr >= 0 ) { 71 if( DeviceNr >= 0 ) {
72 if( OT->releaseRFCommDevice( DeviceNr ) ) { 72 if( OT->releaseRFCommDevice( DeviceNr ) ) {
73 return QString( "Cannot release RFCOMM connection" ); 73 return QString( "Cannot release RFCOMM connection" );
74 } 74 }
75 DeviceNr = -1; 75 DeviceNr = -1;
76 } 76 }
77 } 77 }
78 return QString(); 78 return QString();
79} 79}
80 80
81#include <qlistbox.h> 81#include <qlistbox.h>
82#include <qframe.h> 82#include <qframe.h>
83#include <qlabel.h> 83#include <qlabel.h>
84#include <qlayout.h> 84#include <qlayout.h>
85#include <qdialog.h> 85#include <qdialog.h>
86 86
87RFCOMMChannel * BluetoothRFCOMMRun::getChannel( void ) { 87RFCOMMChannel * BluetoothRFCOMMRun::getChannel( void ) {
88 88
89 if( Data->Devices.count() == 1 ) { 89 if( Data->Devices.count() == 1 ) {
90 // only one device -> return channel 90 // only one device -> return channel
91 return Data->Devices[0]; 91 return Data->Devices[0];
92 } 92 }
93 93
94 RFCOMMChannel * Ch = 0; 94 RFCOMMChannel * Ch = 0;
95 QDialog * Dlg = new QDialog( qApp->mainWidget(), 0, TRUE ); 95 QDialog * Dlg = new QDialog( qApp->mainWidget(), 0, TRUE );
96 QVBoxLayout * V = new QVBoxLayout( Dlg ); 96 QVBoxLayout * V = new QVBoxLayout( Dlg );
97 97
98 QLabel * L = new QLabel( 98 QLabel * L = new QLabel(
99 qApp->translate( "BluetoothRFCOMMRun", 99 qApp->translate( "BluetoothRFCOMMRun",
100 "Select device to connect to"), 100 "Select device to connect to"),
101 Dlg ); 101 Dlg );
102 QListBox * LB = new QListBox( Dlg ); 102 QListBox * LB = new QListBox( Dlg );
103 103
104 for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) { 104 for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) {
105 LB->insertItem( QString( "%1 (%2 Chnl %3)" ). 105 LB->insertItem( QString( "%1 (%2 Chnl %3)" ).
106 arg( Data->Devices[i]->Name ). 106 arg( Data->Devices[i]->Name ).
107 arg( Data->Devices[i]->BDAddress ). 107 arg( Data->Devices[i]->BDAddress ).
108 arg( Data->Devices[i]->Channel ) ); 108 arg( Data->Devices[i]->Channel ) );
109 } 109 }
110 110
111 V->addWidget( L ); 111 V->addWidget( L );
112 V->addWidget( LB ); 112 V->addWidget( LB );
113 113
114 Dlg->resize( 100, 100 ); 114 Dlg->resize( 100, 100 );
115 Dlg->move( 20, 115 Dlg->move( 20,
116 (qApp->desktop()->height()-100)/2 ); 116 (qApp->desktop()->height()-100)/2 );
117 117
118 if( Dlg->exec() == QDialog::Accepted ) { 118 if( Dlg->exec() == QDialog::Accepted ) {
119 unsigned int i = 0; 119 unsigned int i = 0;
120 for( i = 0; i < Data->Devices.count(); i ++ ) { 120 for( i = 0; i < Data->Devices.count(); i ++ ) {
121 if( LB->isSelected(i) ) { 121 if( LB->isSelected(i) ) {
122 owarn << "Selected " << Data->Devices[i]->Name << oendl; 122 odebug << "Selected " << Data->Devices[i]->Name << oendl;
123 Ch = Data->Devices[i]; 123 Ch = Data->Devices[i];
124 break; 124 break;
125 } 125 }
126 } 126 }
127 } 127 }
128 128
129 delete Dlg; 129 delete Dlg;
130 return Ch; 130 return Ch;
131} 131}
132 132
133QString BluetoothRFCOMMRun::deviceFile( void ) { 133QString BluetoothRFCOMMRun::deviceFile( void ) {
134 if( deviceNrOfConnection() >= 0 ) { 134 if( deviceNrOfConnection() >= 0 ) {
135 OTDevice * OTD = OT->getOTDevice(); 135 OTDevice * OTD = OT->getOTDevice();
136 // there is a connection 136 // there is a connection
137 return OTD->getRFCommDevicePattern().arg(DeviceNr); 137 return OTD->getRFCommDevicePattern().arg(DeviceNr);
138 } 138 }
139 return QString(); 139 return QString();
140} 140}
141 141
142int BluetoothRFCOMMRun::deviceNrOfConnection( void ) { 142int BluetoothRFCOMMRun::deviceNrOfConnection( void ) {
143 143
144 if( ! OT ) { 144 if( ! OT ) {
145 OT = OTGateway::getOTGateway(); 145 OT = OTGateway::getOTGateway();
146 } 146 }
147 147
148 DeviceNr = -1; 148 DeviceNr = -1;
149 for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) { 149 for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) {
150 owarn << "Check for rfcomm on " 150 odebug << "Check for rfcomm on "
151 << Data->Devices[i]->BDAddress 151 << Data->Devices[i]->BDAddress
152 << " " 152 << " "
153 << Data->Devices[i]->Channel 153 << Data->Devices[i]->Channel
154 << oendl; 154 << oendl;
155 if( ( DeviceNr = OT->connectedToRFCommChannel( 155 if( ( DeviceNr = OT->connectedToRFCommChannel(
156 OTDeviceAddress( Data->Devices[i]->BDAddress ), 156 OTDeviceAddress( Data->Devices[i]->BDAddress ),
157 Data->Devices[i]->Channel ) ) >= 0 ) { 157 Data->Devices[i]->Channel ) ) >= 0 ) {
158 owarn << "Up " 158 odebug << "Up "
159 << oendl; 159 << oendl;
160 break; 160 break;
161 } 161 }
162 } 162 }
163 return DeviceNr; 163 return DeviceNr;
164} 164}
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 @@
1 config NS2BT 1 config NS2BT
2 boolean "opie-networksettings2plugin-bluetooth (set up BLUETOOTH)" 2 boolean "opie-networksettings2plugin-bluetooth (set up BLUETOOTH)"
3 default "n" if NS2 3 default "n" if NS2
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && NS2CORE && NS2OPIETOOTH 4 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 @@
1 source noncore/settings/networksettings2/networksettings2/config.in 1 source noncore/settings/networksettings2/networksettings2/config.in
2 source noncore/settings/networksettings2/opietooth2/config.in 2 source noncore/settings/networksettings2/opietooth2/config.in
3 source noncore/settings/networksettings2/opietooth2_applet/config.in 3 source noncore/settings/networksettings2/opietooth2_applet/config.in
4 4
5config NS2 5config NS2
6 boolean 6 boolean "opie-networksettings2 application"
7 default "y" 7 default "y"
8 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && NS2CORE && NS2OPIETOOTH 8 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && NS2CORE && NS2OPIETOOTH
9 9
10 source noncore/settings/networksettings2/profile/config.in 10 source noncore/settings/networksettings2/profile/config.in
11 source noncore/settings/networksettings2/network/config.in 11 source noncore/settings/networksettings2/network/config.in
12 source noncore/settings/networksettings2/lancard/config.in 12 source noncore/settings/networksettings2/lancard/config.in
13 source noncore/settings/networksettings2/ppp/config.in 13 source noncore/settings/networksettings2/ppp/config.in
14 source noncore/settings/networksettings2/wlan/config.in 14 source noncore/settings/networksettings2/wlan/config.in
15 source noncore/settings/networksettings2/usb/config.in 15 source noncore/settings/networksettings2/usb/config.in
16 source noncore/settings/networksettings2/irda/config.in 16 source noncore/settings/networksettings2/irda/config.in
17 source noncore/settings/networksettings2/vpn/config.in 17 source noncore/settings/networksettings2/vpn/config.in
18 source noncore/settings/networksettings2/bluetooth/config.in 18 source noncore/settings/networksettings2/bluetooth/config.in
19 source noncore/settings/networksettings2/cable/config.in 19 source noncore/settings/networksettings2/cable/config.in
20 source noncore/settings/networksettings2/modem/config.in 20 source noncore/settings/networksettings2/modem/config.in
21 source noncore/settings/networksettings2/gprs/config.in 21 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
@@ -1,414 +1,413 @@
1#include <opie2/odebug.h> 1#include <opie2/odebug.h>
2#include <qlistview.h> 2#include <qlistview.h>
3#include <qwidgetstack.h> 3#include <qwidgetstack.h>
4#include <qframe.h> 4#include <qframe.h>
5#include <qcombobox.h> 5#include <qcombobox.h>
6#include <qtabwidget.h> 6#include <qtabwidget.h>
7#include <qmessagebox.h> 7#include <qmessagebox.h>
8#include <qpushbutton.h> 8#include <qpushbutton.h>
9#include <qlineedit.h> 9#include <qlineedit.h>
10#include <qheader.h> 10#include <qheader.h>
11#include <qpainter.h> 11#include <qpainter.h>
12#include <qcheckbox.h> 12#include <qcheckbox.h>
13#include <qlabel.h> 13#include <qlabel.h>
14 14
15#include "editconnection.h" 15#include "editconnection.h"
16#include "resources.h" 16#include "resources.h"
17#include "netnode.h" 17#include "netnode.h"
18 18
19// 19//
20// 20//
21// THESE TO GIVE BETTER FEEDBACK ABOUT DISABLED ITEMS 21// THESE TO GIVE BETTER FEEDBACK ABOUT DISABLED ITEMS
22// 22//
23// 23//
24 24
25class MyQCheckListItem : public QCheckListItem 25class MyQCheckListItem : public QCheckListItem
26{ 26{
27public: 27public:
28 MyQCheckListItem( QListView *parent, const QString & S, Type T ) : 28 MyQCheckListItem( QListView *parent, const QString & S, Type T ) :
29 QCheckListItem( parent, S, T ) { } 29 QCheckListItem( parent, S, T ) { }
30 MyQCheckListItem( QCheckListItem *parent, const QString & S, Type T ) : 30 MyQCheckListItem( QCheckListItem *parent, const QString & S, Type T ) :
31 QCheckListItem( parent, S, T ) { } 31 QCheckListItem( parent, S, T ) { }
32 MyQCheckListItem( QListViewItem *parent, const QString & S, Type T ) : 32 MyQCheckListItem( QListViewItem *parent, const QString & S, Type T ) :
33 QCheckListItem( parent, S, T ) { } 33 QCheckListItem( parent, S, T ) { }
34 34
35 MyQCheckListItem( QListView *parent, const QString & S ) : 35 MyQCheckListItem( QListView *parent, const QString & S ) :
36 QCheckListItem( parent, S, QCheckListItem::Controller ) { } 36 QCheckListItem( parent, S, QCheckListItem::Controller ) { }
37 MyQCheckListItem( QCheckListItem *parent, const QString & S ) : 37 MyQCheckListItem( QCheckListItem *parent, const QString & S ) :
38 QCheckListItem( parent, S, QCheckListItem::Controller ) { } 38 QCheckListItem( parent, S, QCheckListItem::Controller ) { }
39 MyQCheckListItem( QListViewItem *parent, const QString & S ) : 39 MyQCheckListItem( QListViewItem *parent, const QString & S ) :
40 QCheckListItem( parent, S, QCheckListItem::Controller ) { } 40 QCheckListItem( parent, S, QCheckListItem::Controller ) { }
41 41
42 virtual void paintCell( QPainter *p, const QColorGroup &cg, 42 virtual void paintCell( QPainter *p, const QColorGroup &cg,
43 int column, int width, int alignment ); 43 int column, int width, int alignment );
44 44
45}; 45};
46 46
47void MyQCheckListItem::paintCell( QPainter *p, const QColorGroup &cg, 47void MyQCheckListItem::paintCell( QPainter *p, const QColorGroup &cg,
48 int column, int width, int alignment ) 48 int column, int width, int alignment )
49{ 49{
50 QColorGroup _cg( cg ); 50 QColorGroup _cg( cg );
51 QColor c = _cg.text(); 51 QColor c = _cg.text();
52 if ( ! isSelectable() ) 52 if ( ! isSelectable() )
53 _cg.setColor( QColorGroup::Text, Qt::lightGray ); 53 _cg.setColor( QColorGroup::Text, Qt::lightGray );
54 QCheckListItem::paintCell( p, _cg, column, width, alignment ); 54 QCheckListItem::paintCell( p, _cg, column, width, alignment );
55 _cg.setColor( QColorGroup::Text, c ); 55 _cg.setColor( QColorGroup::Text, c );
56} 56}
57 57
58class MyQListViewItem : public QListViewItem 58class MyQListViewItem : public QListViewItem
59{ 59{
60public: 60public:
61 MyQListViewItem( QListView *parent, const QString & S ) : 61 MyQListViewItem( QListView *parent, const QString & S ) :
62 QListViewItem( parent, S ) { } 62 QListViewItem( parent, S ) { }
63 MyQListViewItem( QListViewItem *parent, const QString & S ) : 63 MyQListViewItem( QListViewItem *parent, const QString & S ) :
64 QListViewItem( parent, S ) { } 64 QListViewItem( parent, S ) { }
65 65
66 virtual void paintCell( QPainter *p, const QColorGroup &cg, 66 virtual void paintCell( QPainter *p, const QColorGroup &cg,
67 int column, int width, int alignment ); 67 int column, int width, int alignment );
68 68
69}; 69};
70 70
71void MyQListViewItem::paintCell( QPainter *p, const QColorGroup &cg, 71void MyQListViewItem::paintCell( QPainter *p, const QColorGroup &cg,
72 int column, int width, int alignment ) 72 int column, int width, int alignment )
73{ 73{
74 QColorGroup _cg( cg ); 74 QColorGroup _cg( cg );
75 QColor c = _cg.text(); 75 QColor c = _cg.text();
76 if ( ! isSelectable() ) 76 if ( ! isSelectable() )
77 _cg.setColor( QColorGroup::Text, Qt::lightGray ); 77 _cg.setColor( QColorGroup::Text, Qt::lightGray );
78 QListViewItem::paintCell( p, _cg, column, width, alignment ); 78 QListViewItem::paintCell( p, _cg, column, width, alignment );
79 _cg.setColor( QColorGroup::Text, c ); 79 _cg.setColor( QColorGroup::Text, c );
80} 80}
81 81
82// 82//
83// 83//
84// REAL GUI 84// REAL GUI
85// 85//
86// 86//
87 87
88bool EditConnection::AutoCollapse = 1; 88bool EditConnection::AutoCollapse = 1;
89 89
90EditConnection::EditConnection( QWidget* parent ) : 90EditConnection::EditConnection( QWidget* parent ) :
91 EditConnectionGUI( parent, 0, TRUE ), TmpCollection() { 91 EditConnectionGUI( parent, 0, TRUE ), TmpCollection() {
92 92
93 Tab_TB->setTabEnabled( Setup_FRM, FALSE ); 93 Tab_TB->setTabEnabled( Setup_FRM, FALSE );
94 Setup_FRM->setEnabled( FALSE ); 94 Setup_FRM->setEnabled( FALSE );
95 95
96 TmpIsValid = 0; 96 TmpIsValid = 0;
97 SelectedNodes = 0; 97 SelectedNodes = 0;
98 98
99 AutoCollapse_CB->setChecked( AutoCollapse ); 99 AutoCollapse_CB->setChecked( AutoCollapse );
100 100
101 Mapping = new QPtrDict<ANetNode>; 101 Mapping = new QPtrDict<ANetNode>;
102 Mapping->setAutoDelete( FALSE ); 102 Mapping->setAutoDelete( FALSE );
103 Nodes_LV->header()->hide(); 103 Nodes_LV->header()->hide();
104 // popluate tree with all NetNodes 104 // popluate tree with all NetNodes
105 buildFullTree(); 105 buildFullTree();
106} 106}
107 107
108NodeCollection * EditConnection::getTmpCollection( void ) { 108NodeCollection * EditConnection::getTmpCollection( void ) {
109 109
110 if( TmpIsValid ) 110 if( TmpIsValid )
111 // content is stil OK 111 // content is stil OK
112 return &(TmpCollection); 112 return &(TmpCollection);
113 113
114 // reset collection -> delete all NEW NetNodes 114 // reset collection -> delete all NEW NetNodes
115 for( QListIterator<ANetNodeInstance> it(TmpCollection); 115 for( QListIterator<ANetNodeInstance> it(TmpCollection);
116 it.current(); 116 it.current();
117 ++it ) { 117 ++it ) {
118 if( it.current()->isNew() ) { 118 if( it.current()->isNew() ) {
119 delete it.current(); 119 delete it.current();
120 } 120 }
121 } 121 }
122 TmpCollection.clear(); 122 TmpCollection.clear();
123 123
124 // update content 124 // update content
125 QListViewItem * it = Nodes_LV->firstChild(); 125 QListViewItem * it = Nodes_LV->firstChild();
126 ANetNode * NN; 126 ANetNode * NN;
127 127
128 // start iter (if there is a collection) 128 // start iter (if there is a collection)
129 /* 129 /*
130 130
131 a node collection is sorted from the toplevel 131 a node collection is sorted from the toplevel
132 node to the deepest node 132 node to the deepest node
133 133
134 */ 134 */
135 ANetNodeInstance * NNI = 135 ANetNodeInstance * NNI =
136 (SelectedNodes) ? SelectedNodes->first() : 0 ; 136 (SelectedNodes) ? SelectedNodes->first() : 0 ;
137 137
138 TmpCollection.setModified( 0 ); 138 TmpCollection.setModified( 0 );
139 139
140 // the listview always starts with the toplevel 140 // the listview always starts with the toplevel
141 // hierarchy. This is always a controller item 141 // hierarchy. This is always a controller item
142 while ( it ) { 142 while ( it ) {
143 NN = (*Mapping)[it]; 143 NN = (*Mapping)[it];
144 if( NN == 0 ) { 144 if( NN == 0 ) {
145 // this item is a controller -> 145 // this item is a controller ->
146 // has radio items as children -> 146 // has radio items as children ->
147 // find selected one 147 // find selected one
148 it = it->firstChild(); 148 it = it->firstChild();
149 while( it ) { 149 while( it ) {
150 if( ((QCheckListItem *)it)->isOn() ) { 150 if( ((QCheckListItem *)it)->isOn() ) {
151 // this radio is selected -> go deeper 151 // this radio is selected -> go deeper
152 break; 152 break;
153 } 153 }
154 it = it->nextSibling(); 154 it = it->nextSibling();
155 } 155 }
156 156
157 if( ! it ) { 157 if( ! it ) {
158 owarn << "Radio not selected" << oendl;
159 TmpIsValid = 0; 158 TmpIsValid = 0;
160 return 0; 159 return 0;
161 } 160 }
162 161
163 // it now contains selected radio 162 // it now contains selected radio
164 NN = (*Mapping)[it]; 163 NN = (*Mapping)[it];
165 } 164 }
166 165
167 // NN here contains the netnode of the 166 // NN here contains the netnode of the
168 // current item -> this node needs to 167 // current item -> this node needs to
169 // be stored in the collection 168 // be stored in the collection
170 if( NNI == 0 || 169 if( NNI == 0 ||
171 it->text(0) != NNI->nodeClass()->name() ) { 170 it->text(0) != NNI->nodeClass()->name() ) {
172 // new item not in previous collection 171 // new item not in previous collection
173 ANetNodeInstance * NNI = NN->createInstance(); 172 ANetNodeInstance * NNI = NN->createInstance();
174 NNI->initialize(); 173 NNI->initialize();
175 // this node type not in collection 174 // this node type not in collection
176 TmpCollection.append( NNI ); 175 TmpCollection.append( NNI );
177 // master collection changed because new item in it 176 // master collection changed because new item in it
178 TmpCollection.setModified( 1 ); 177 TmpCollection.setModified( 1 );
179 // no more valid items in old list 178 // no more valid items in old list
180 NNI = 0; 179 NNI = 0;
181 } else { 180 } else {
182 // already in list -> copy pointer 181 // already in list -> copy pointer
183 TmpCollection.append( NNI ); 182 TmpCollection.append( NNI );
184 NNI = SelectedNodes->next(); 183 NNI = SelectedNodes->next();
185 } 184 }
186 185
187 // go deeper to next level 186 // go deeper to next level
188 // this level is can be a new controller 187 // this level is can be a new controller
189 // or an item 188 // or an item
190 it = it->firstChild(); 189 it = it->firstChild();
191 } 190 }
192 191
193 TmpIsValid = 1; 192 TmpIsValid = 1;
194 return &(TmpCollection); 193 return &(TmpCollection);
195} 194}
196 195
197// pass a connection NodeCollection to be edited 196// pass a connection NodeCollection to be edited
198void EditConnection::setConnection( NodeCollection * NC ) { 197void EditConnection::setConnection( NodeCollection * NC ) {
199 ANetNodeInstance * NNI; 198 ANetNodeInstance * NNI;
200 ANetNode * NN; 199 ANetNode * NN;
201 200
202 SelectedNodes = NC; 201 SelectedNodes = NC;
203 Name_LE->setText( NC->name() ); 202 Name_LE->setText( NC->name() );
204 NNI = NC->first(); 203 NNI = NC->first();
205 204
206 // show configure tabl 205 // show configure tabl
207 Tab_TB->setCurrentPage( 1 ); 206 Tab_TB->setCurrentPage( 1 );
208 207
209 // valid colledction 208 // valid colledction
210 Tab_TB->setTabEnabled( Setup_FRM, FALSE ); 209 Tab_TB->setTabEnabled( Setup_FRM, FALSE );
211 Setup_FRM->setEnabled( FALSE ); 210 Setup_FRM->setEnabled( FALSE );
212 211
213 // select items in collection 212 // select items in collection
214 QListViewItem * it = Nodes_LV->firstChild(); 213 QListViewItem * it = Nodes_LV->firstChild();
215 bool Found; 214 bool Found;
216 215
217 TmpIsValid = 0; 216 TmpIsValid = 0;
218 217
219 while ( it ) { 218 while ( it ) {
220 NN = (*Mapping)[it]; 219 NN = (*Mapping)[it];
221 if( NN == 0 ) { 220 if( NN == 0 ) {
222 // this item is a controller -> 221 // this item is a controller ->
223 // has radio items as children -> 222 // has radio items as children ->
224 // find selected one 223 // find selected one
225 it = it->firstChild(); 224 it = it->firstChild();
226 Found = 0; 225 Found = 0;
227 while( it ) { 226 while( it ) {
228 if( NNI && it->text(0) == NNI->nodeClass()->name() ) { 227 if( NNI && it->text(0) == NNI->nodeClass()->name() ) {
229 // this radio is part of the collection 228 // this radio is part of the collection
230 ((QCheckListItem *)it)->setOn( 1 ); 229 ((QCheckListItem *)it)->setOn( 1 );
231 updateGUI( it, NNI->nodeClass() ); 230 updateGUI( it, NNI->nodeClass() );
232 // check its children 231 // check its children
233 Found = 1; 232 Found = 1;
234 it = it->firstChild(); 233 it = it->firstChild();
235 NNI = SelectedNodes->next(); 234 NNI = SelectedNodes->next();
236 // do not bother to check other items 235 // do not bother to check other items
237 break; 236 break;
238 } 237 }
239 it = it->nextSibling(); 238 it = it->nextSibling();
240 } 239 }
241 240
242 if( ! Found ) { 241 if( ! Found ) {
243 // this means that this level is NOT present in collection 242 // this means that this level is NOT present in collection
244 // probably INCOMPATIBEL collection OR Missing plugin 243 // probably INCOMPATIBEL collection OR Missing plugin
245 QMessageBox::warning( 244 QMessageBox::warning(
246 0, 245 0,
247 tr( "Error presentig Connection" ), 246 tr( "Error presentig Connection" ),
248 tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ). 247 tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ).
249 arg(NNI->nodeClass()->name()) ); 248 arg(NNI->nodeClass()->name()) );
250 return; 249 return;
251 } 250 }
252 251
253 // it now contains selected radio 252 // it now contains selected radio
254 NN = (*Mapping)[it]; 253 NN = (*Mapping)[it];
255 } else { 254 } else {
256 // automatic selection 255 // automatic selection
257 if( NNI == 0 || it->text(0) != NNI->nodeClass()->name() ) { 256 if( NNI == 0 || it->text(0) != NNI->nodeClass()->name() ) {
258 // should exist and be the same 257 // should exist and be the same
259 if( NNI ) { 258 if( NNI ) {
260 QMessageBox::warning( 259 QMessageBox::warning(
261 0, 260 0,
262 tr( "Error presentig Connection" ), 261 tr( "Error presentig Connection" ),
263 tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ). 262 tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ).
264 arg(NNI->nodeClass()->name()) ); 263 arg(NNI->nodeClass()->name()) );
265 } else { 264 } else {
266 QMessageBox::warning( 265 QMessageBox::warning(
267 0, 266 0,
268 tr( "Error presentig Connection" ), 267 tr( "Error presentig Connection" ),
269 tr( "<p>Missing connection\"<i>%1</i>\"</p>" ). 268 tr( "<p>Missing connection\"<i>%1</i>\"</p>" ).
270 arg(it->text(0)) ); 269 arg(it->text(0)) );
271 } 270 }
272 return; 271 return;
273 } 272 }
274 it = it->firstChild(); 273 it = it->firstChild();
275 } 274 }
276 } 275 }
277} 276}
278 277
279// get result of editing (either new OR updated collection 278// get result of editing (either new OR updated collection
280NodeCollection * EditConnection::connection( void ) { 279NodeCollection * EditConnection::connection( void ) {
281 280
282 if( SelectedNodes == 0 ) { 281 if( SelectedNodes == 0 ) {
283 // new collection 282 // new collection
284 SelectedNodes = new NodeCollection; 283 SelectedNodes = new NodeCollection;
285 } 284 }
286 285
287 // clean out old entries 286 // clean out old entries
288 SelectedNodes->clear(); 287 SelectedNodes->clear();
289 288
290 // transfer 289 // transfer
291 for( QListIterator<ANetNodeInstance> it(TmpCollection); 290 for( QListIterator<ANetNodeInstance> it(TmpCollection);
292 it.current(); 291 it.current();
293 ++it ) { 292 ++it ) {
294 SelectedNodes->append( it.current() ); 293 SelectedNodes->append( it.current() );
295 } 294 }
296 295
297 if( TmpCollection.isModified() ) 296 if( TmpCollection.isModified() )
298 SelectedNodes->setModified( 1 ); 297 SelectedNodes->setModified( 1 );
299 298
300 if( SelectedNodes->name() != Name_LE->text() ) { 299 if( SelectedNodes->name() != Name_LE->text() ) {
301 SelectedNodes->setName( Name_LE->text() ); 300 SelectedNodes->setName( Name_LE->text() );
302 SelectedNodes->setModified( 1 ); 301 SelectedNodes->setModified( 1 );
303 } 302 }
304 303
305 return SelectedNodes; 304 return SelectedNodes;
306} 305}
307 306
308// Build device tree -> start 307// Build device tree -> start
309void EditConnection::buildFullTree( void ) { 308void EditConnection::buildFullTree( void ) {
310 ANetNode * NN; 309 ANetNode * NN;
311 310
312 // toplevel item 311 // toplevel item
313 MyQCheckListItem * TheTop = new MyQCheckListItem( 312 MyQCheckListItem * TheTop = new MyQCheckListItem(
314 Nodes_LV, 313 Nodes_LV,
315 NSResources->netNode2Name("fullsetup"), 314 NSResources->netNode2Name("fullsetup"),
316 QCheckListItem::Controller ); 315 QCheckListItem::Controller );
317 TheTop->setOpen( TRUE ); 316 TheTop->setOpen( TRUE );
318 Description_LBL->setText( 317 Description_LBL->setText(
319 NSResources->netNode2Description( "fullsetup" ) ); 318 NSResources->netNode2Description( "fullsetup" ) );
320 Nodes_LV->setSelected( TheTop, TRUE ); 319 Nodes_LV->setSelected( TheTop, TRUE );
321 320
322 // find all Nodes that are toplevel nodes -> ie provide 321 // find all Nodes that are toplevel nodes -> ie provide
323 // TCP/IP Connection 322 // TCP/IP Connection
324 for( QDictIterator<ANetNode> Iter(NSResources->netNodes()); 323 for( QDictIterator<ANetNode> Iter(NSResources->netNodes());
325 Iter.current(); 324 Iter.current();
326 ++Iter ) { 325 ++Iter ) {
327 NN = Iter.current(); 326 NN = Iter.current();
328 327
329 if( ! NN->isToplevel() ) { 328 if( ! NN->isToplevel() ) {
330 continue; 329 continue;
331 } 330 }
332 331
333 MyQCheckListItem * it = new MyQCheckListItem( TheTop, 332 MyQCheckListItem * it = new MyQCheckListItem( TheTop,
334 NN->name(), 333 NN->name(),
335 QCheckListItem::RadioButton ); 334 QCheckListItem::RadioButton );
336 it->setPixmap( 0, 335 it->setPixmap( 0,
337 NSResources->getPixmap( NN->pixmapName() ) 336 NSResources->getPixmap( NN->pixmapName() )
338 ); 337 );
339 // remember that this node maps to this listitem 338 // remember that this node maps to this listitem
340 Mapping->insert( it, NN ); 339 Mapping->insert( it, NN );
341 buildSubTree( it, NN ); 340 buildSubTree( it, NN );
342 } 341 }
343} 342}
344 343
345// Build device tree -> help function 344// Build device tree -> help function
346void EditConnection::buildSubTree( QListViewItem * it, ANetNode *NN ) { 345void EditConnection::buildSubTree( QListViewItem * it, ANetNode *NN ) {
347 ANetNode::NetNodeList & NNL = NN->alternatives(); 346 ANetNode::NetNodeList & NNL = NN->alternatives();
348 347
349 if( NNL.size() > 1 ) { 348 if( NNL.size() > 1 ) {
350 // this node has alternatives -> needs radio buttons 349 // this node has alternatives -> needs radio buttons
351 it = new MyQCheckListItem( 350 it = new MyQCheckListItem(
352 it, 351 it,
353 NSResources->netNode2Name(NN->needs()[0]), 352 NSResources->netNode2Name(NN->needs()[0]),
354 QCheckListItem::Controller ); 353 QCheckListItem::Controller );
355 it->setSelectable( FALSE ); 354 it->setSelectable( FALSE );
356 } 355 }
357 356
358 for ( unsigned int i=0; i < NNL.size(); i++ ) { 357 for ( unsigned int i=0; i < NNL.size(); i++ ) {
359 QListViewItem * CI; 358 QListViewItem * CI;
360 if( NNL.size() > 1 ) { 359 if( NNL.size() > 1 ) {
361 // generate radio buttons 360 // generate radio buttons
362 CI = new MyQCheckListItem( 361 CI = new MyQCheckListItem(
363 (QCheckListItem *)it, 362 (QCheckListItem *)it,
364 NNL[i]->name(), QCheckListItem::RadioButton ); 363 NNL[i]->name(), QCheckListItem::RadioButton );
365 // remember that this node maps to this listitem 364 // remember that this node maps to this listitem
366 CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); 365 CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) );
367 Mapping->insert( CI, NNL[i] ); 366 Mapping->insert( CI, NNL[i] );
368 CI->setSelectable( FALSE ); 367 CI->setSelectable( FALSE );
369 } else { 368 } else {
370 // Single item 369 // Single item
371 CI = new MyQListViewItem( it, NNL[i]->name() ); 370 CI = new MyQListViewItem( it, NNL[i]->name() );
372 // remember that this node maps to this listitem 371 // remember that this node maps to this listitem
373 Mapping->insert( CI, NNL[i] ); 372 Mapping->insert( CI, NNL[i] );
374 CI->setSelectable( FALSE ); 373 CI->setSelectable( FALSE );
375 CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); 374 CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) );
376 } 375 }
377 buildSubTree( CI, NNL[i] ); 376 buildSubTree( CI, NNL[i] );
378 } 377 }
379} 378}
380 379
381// Clicked ok OK button 380// Clicked ok OK button
382void EditConnection::accept( void ) { 381void EditConnection::accept( void ) {
383 if( ! haveCompleteConfig( 0 ) || Name_LE->text().isEmpty() ) { 382 if( ! haveCompleteConfig( 0 ) || Name_LE->text().isEmpty() ) {
384 QMessageBox::warning( 383 QMessageBox::warning(
385 0, 384 0,
386 tr( "Closing Connection Setup" ), 385 tr( "Closing Connection Setup" ),
387 tr( "Definition not complete or no name" ) ); 386 tr( "Definition not complete or no name" ) );
388 return; 387 return;
389 } 388 }
390 389
391 // check if all devices have acceptable input 390 // check if all devices have acceptable input
392 getTmpCollection(); 391 getTmpCollection();
393 { ANetNodeInstance * NNI; 392 { ANetNodeInstance * NNI;
394 QString S; 393 QString S;
395 394
396 for( QListIterator<ANetNodeInstance> it(TmpCollection); 395 for( QListIterator<ANetNodeInstance> it(TmpCollection);
397 it.current(); 396 it.current();
398 ++it ) { 397 ++it ) {
399 NNI = it.current(); 398 NNI = it.current();
400 // widget must show its own problems 399 // widget must show its own problems
401 S = NNI->acceptable(); 400 S = NNI->acceptable();
402 if( ! S.isEmpty() ) { 401 if( ! S.isEmpty() ) {
403 QMessageBox::warning( 402 QMessageBox::warning(
404 0, 403 0,
405 tr( "Cannot save" ), 404 tr( "Cannot save" ),
406 S ); 405 S );
407 return; 406 return;
408 } 407 }
409 NNI->commit(); 408 NNI->commit();
410 409
411 if( NNI->isModified() ) { 410 if( NNI->isModified() ) {
412 TmpCollection.setModified( 1 ); 411 TmpCollection.setModified( 1 );
413 // commit the data 412 // commit the data
414 } 413 }
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 @@
1#include <sys/types.h> 1#include <sys/types.h>
2#include <signal.h> 2#include <signal.h>
3#include <errno.h> 3#include <errno.h>
4#include <qdir.h> 4#include <qdir.h>
5#include <system.h> 5#include <system.h>
6#include <resources.h> 6#include <resources.h>
7#include <netnode.h> 7#include <netnode.h>
8#include "GPRSrun.h" 8#include "GPRSrun.h"
9 9
10State_t GPRSRun::detectState( void ) { 10State_t GPRSRun::detectState( void ) {
11 11
12 // is pppd still running ? 12 // is pppd still running ?
13 // is rfcomm still active 13 // is rfcomm still active
14 NodeCollection * NC = nodeCollection(); 14 NodeCollection * NC = nodeCollection();
15 InterfaceInfo * I = NC->assignedInterface(); 15 InterfaceInfo * I = NC->assignedInterface();
16 16
17 QDir D("/var/run"); 17 QDir D("/var/run");
18 18
19 if( I ) { 19 if( I ) {
20 // has some pppx attached 20 // has some pppx attached
21 return ( I->IsUp ) ? IsUp : Available; 21 return ( I->IsUp ) ? IsUp : Available;
22 } 22 }
23 23
24 // check ppp itself and figure out interface 24 // check ppp itself and figure out interface
25 25
26 owarn << "Check for ppp " << NC->name() << oendl; 26 odebug << "Check for ppp " << NC->name() << oendl;
27 if( D.exists( QString("ppp-")+removeSpaces(NC->name())+".pid") ) { 27 if( D.exists( QString("ppp-")+removeSpaces(NC->name())+".pid") ) {
28 // get pid and check if pppd is still running 28 // get pid and check if pppd is still running
29 QFile F( D.path()+"/ppp-"+removeSpaces(NC->name())+".pid"); 29 QFile F( D.path()+"/ppp-"+removeSpaces(NC->name())+".pid");
30 30
31 owarn << "PPP PID " << F.name() << oendl; 31 odebug << "PPP PID " << F.name() << oendl;
32 if( F.open( IO_ReadOnly ) ) { 32 if( F.open( IO_ReadOnly ) ) {
33 QTextStream TS(&F); 33 QTextStream TS(&F);
34 QString X = TS.readLine(); 34 QString X = TS.readLine();
35 PPPPid = X.toULong(); 35 PPPPid = X.toULong();
36 int rv; 36 int rv;
37 37
38 rv = ::kill( PPPPid, 0 ); 38 rv = ::kill( PPPPid, 0 );
39 if( rv == 0 || 39 if( rv == 0 ||
40 ( rv < 0 && errno == EPERM ) 40 ( rv < 0 && errno == EPERM )
41 ) { 41 ) {
42 // pppd is still up 42 // pppd is still up
43 X = TS.readLine(); 43 X = TS.readLine();
44 I = NSResources->system().findInterface(X); 44 I = NSResources->system().findInterface(X);
45 45
46 owarn << "ppp running : IFace " << X << " = " << (long)I << oendl; 46 odebug << "ppp running : IFace " << X << " = " << (long)I << oendl;
47 47
48 if( I ) { 48 if( I ) {
49 NC->assignInterface( I ); 49 NC->assignInterface( I );
50 return (I->IsUp) ? IsUp : Available; 50 return (I->IsUp) ? IsUp : Available;
51 } 51 }
52 52
53 return Available; 53 return Available;
54 54
55 } else { 55 } else {
56 // pppd is down 56 // pppd is down
57 PPPPid = 0; 57 PPPPid = 0;
58 } 58 }
59 } // else pppd is down 59 } // else pppd is down
60 } 60 }
61 NC->assignInterface( 0 ); 61 NC->assignInterface( 0 );
62 return Unknown; 62 return Unknown;
63} 63}
64 64
65QString GPRSRun::setMyState( NodeCollection * NC, Action_t A , bool ) { 65QString GPRSRun::setMyState( NodeCollection * NC, Action_t A , bool ) {
66 66
67 if( A == Up ) { 67 if( A == Up ) {
68 // start ppp on deviceFile 68 // start ppp on deviceFile
69 QStringList SL; 69 QStringList SL;
70 SL << "pon" 70 SL << "pon"
71 << removeSpaces( NC->name() ) 71 << removeSpaces( NC->name() )
72 << NC->device()->deviceFile(); 72 << NC->device()->deviceFile();
73 73
74 if( ! NSResources->system().execAsUser( SL ) ) { 74 if( ! NSResources->system().execAsUser( SL ) ) {
75 return QString("Cannot start pppd for %1").arg(NC->name()); 75 return QString("Cannot start pppd for %1").arg(NC->name());
76 } 76 }
77 } else if ( A == Down ) { 77 } else if ( A == Down ) {
78 if( PPPPid == 0 ) { 78 if( PPPPid == 0 ) {
79 detectState(); 79 detectState();
80 } 80 }
81 if( PPPPid ) { 81 if( PPPPid ) {
82 QStringList SL; 82 QStringList SL;
83 83
84 SL << "poff" 84 SL << "poff"
85 << removeSpaces( NC->name() ); 85 << removeSpaces( NC->name() );
86 86
87 if( ! NSResources->system().execAsUser( SL ) ) { 87 if( ! NSResources->system().execAsUser( SL ) ) {
88 return QString("Cannot terminate pppd for %1").arg(NC->name()); 88 return QString("Cannot terminate pppd for %1").arg(NC->name());
89 } 89 }
90 NC->assignInterface( 0 ); 90 NC->assignInterface( 0 );
91 owarn << "ppp stopped " << oendl; 91 odebug << "ppp stopped " << oendl;
92 PPPPid = 0; 92 PPPPid = 0;
93 } 93 }
94 } 94 }
95 95
96 return QString(); 96 return QString();
97} 97}
98 98
99bool GPRSRun::handlesInterface( const QString & S ) { 99bool GPRSRun::handlesInterface( const QString & S ) {
100 return Pat.match( S ) >= 0; 100 return Pat.match( S ) >= 0;
101} 101}
102 102
103bool GPRSRun::handlesInterface( InterfaceInfo * I ) { 103bool GPRSRun::handlesInterface( InterfaceInfo * I ) {
104 return handlesInterface( I->Name ); 104 return handlesInterface( I->Name );
105} 105}
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 @@
1#include <system.h> 1#include <system.h>
2#include <netnode.h> 2#include <netnode.h>
3#include <resources.h> 3#include <resources.h>
4#include "networkrun.h" 4#include "networkrun.h"
5 5
6State_t NetworkRun::detectState( void ) { 6State_t NetworkRun::detectState( void ) {
7 InterfaceInfo * II = nodeCollection()->assignedInterface(); 7 InterfaceInfo * II = nodeCollection()->assignedInterface();
8 8
9 Log(( "Interface %p : %d\n", II, (II) ? II->IsUp : 0 )); 9 Log(( "Interface %p : %d\n", II, (II) ? II->IsUp : 0 ));
10 if( II && II->IsUp ) { 10 if( II && II->IsUp ) {
11 // device has assigned interface 11 // device has assigned interface
12 return IsUp; 12 return IsUp;
13 } 13 }
14 14
15 // had no interface or interface is no longer up -> release 15 // had no interface or interface is no longer up -> release
16 nodeCollection()->assignInterface( 0 ); 16 nodeCollection()->assignInterface( 0 );
17 17
18 return Unknown; 18 return Unknown;
19} 19}
20 20
21QString NetworkRun::setMyState( NodeCollection * NC, Action_t A, bool ) { 21QString NetworkRun::setMyState( NodeCollection * NC, Action_t A, bool ) {
22 // we handle UP and DOWN 22 // we handle UP and DOWN
23 InterfaceInfo * II = NC->assignedInterface(); 23 InterfaceInfo * II = NC->assignedInterface();
24 24
25 if( ! II ) {
26 Log(( "no interface assigned." ));
27 return QString();
28 }
29
30 QStringList SL;
31
25 if( A == Up ) { 32 if( A == Up ) {
26 // we can bring UP if lower level is available 33 // we can bring UP if lower level is available
27 QStringList SL; 34 SL << "ifup";
28 SL << "ifup" 35 } else if( A == Down ) {
29 << QString().sprintf( "%s=%s-c%d-allowed", 36 SL << "ifdown";
37 } else {
38 return QString();
39 }
40
41 SL << QString().sprintf( "%s=%s-c%d-allowed",
30 II->Name.latin1(), II->Name.latin1(), 42 II->Name.latin1(), II->Name.latin1(),
31 nodeCollection()->number() ); 43 nodeCollection()->number() );
32 if( ! NSResources->system().runAsRoot( SL ) ) { 44
33 return QString("Cannot call %1").arg(SL.join(" ")); 45 if( ! NSResources->system().runAsRoot( SL ) ) {
34 } 46 return QString("Cannot call %1").arg(SL.join(" "));
35 return QString(); 47 }
36 } 48
37
38 if( A == Down ) {
39 QStringList SL;
40 if( II ) {
41 SL << "ifdown"
42 << II->Name.latin1();
43 if( ! NSResources->system().runAsRoot( SL ) ) {
44 return QString( "Cannot call %1" ).arg( SL.join( " " ));
45 }
46 } else {
47 Log(( "no interface assigned." ));
48 }
49 }
50 return QString(); 49 return QString();
51} 50}
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
@@ -1,514 +1,510 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <unistd.h> 2#include <unistd.h>
3#include <errno.h> 3#include <errno.h>
4 4
5#include <opie2/odebug.h> 5#include <opie2/odebug.h>
6#include <opie2/oledbox.h> 6#include <opie2/oledbox.h>
7 7
8#include <qpe/qpeapplication.h> 8#include <qpe/qpeapplication.h>
9#include <qlistbox.h> 9#include <qlistbox.h>
10#include <qlayout.h> 10#include <qlayout.h>
11#include <qgroupbox.h> 11#include <qgroupbox.h>
12#include <qtimer.h> 12#include <qtimer.h>
13#include <qlistbox.h> 13#include <qlistbox.h>
14#include <qmessagebox.h> 14#include <qmessagebox.h>
15#include <qlabel.h> 15#include <qlabel.h>
16#include <qiconview.h> 16#include <qiconview.h>
17#include <qtimer.h> 17#include <qtimer.h>
18#include <qpe/qpeapplication.h> 18#include <qpe/qpeapplication.h>
19#include <qtoolbutton.h> 19#include <qtoolbutton.h>
20#include <qevent.h> 20#include <qevent.h>
21 21
22#include "networksettings.h" 22#include "networksettings.h"
23#include "netnode.h" 23#include "netnode.h"
24#include "editconnection.h" 24#include "editconnection.h"
25 25
26NetworkSettings::NetworkSettings( QWidget *parent, 26NetworkSettings::NetworkSettings( QWidget *parent,
27 const char *name, 27 const char *name,
28 WFlags fl ) : NetworkSettingsGUI(parent,name,fl), 28 WFlags fl ) : NetworkSettingsGUI(parent,name,fl),
29 NSD() { 29 NSD() {
30 30
31 UpdateTimer = new QTimer( this ); 31 UpdateTimer = new QTimer( this );
32 32
33 // set pixmaps 33 // set pixmaps
34 Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); 34 Add_TB->setPixmap( NSResources->getPixmap( "add" ) );
35 Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) ); 35 Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) );
36 CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) ); 36 CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) );
37 GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) ); 37 GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) );
38 38
39 Disable_TB->setPixmap( NSResources->getPixmap( "disabled" ) ); 39 Disable_TB->setPixmap( NSResources->getPixmap( "disabled" ) );
40 Up_TB->setPixmap( NSResources->getPixmap( "more" ) ); 40 Up_TB->setPixmap( NSResources->getPixmap( "more" ) );
41 Down_TB->setPixmap( NSResources->getPixmap( "less" ) ); 41 Down_TB->setPixmap( NSResources->getPixmap( "less" ) );
42 42
43 QVBoxLayout* V = new QVBoxLayout( LED_Frm ); 43 QVBoxLayout* V = new QVBoxLayout( LED_Frm );
44 QHBoxLayout * H = new QHBoxLayout( 0 ); 44 QHBoxLayout * H = new QHBoxLayout( 0 );
45 V->addStretch(1); 45 V->addStretch(1);
46 V->addLayout( H ); 46 V->addLayout( H );
47 Leds[0] = new Opie::Ui::OLedBox( red, LED_Frm ); 47 Leds[0] = new Opie::Ui::OLedBox( red, LED_Frm );
48 H->addWidget( Leds[0], 0, Qt::AlignVCenter ); 48 H->addWidget( Leds[0], 0, Qt::AlignVCenter );
49 Leds[1] = new Opie::Ui::OLedBox( red, LED_Frm ); 49 Leds[1] = new Opie::Ui::OLedBox( red, LED_Frm );
50 H->addWidget( Leds[1], 0, Qt::AlignVCenter ); 50 H->addWidget( Leds[1], 0, Qt::AlignVCenter );
51 Leds[2] = new Opie::Ui::OLedBox( red, LED_Frm ); 51 Leds[2] = new Opie::Ui::OLedBox( red, LED_Frm );
52 H->addWidget( Leds[2], 0, Qt::AlignVCenter ); 52 H->addWidget( Leds[2], 0, Qt::AlignVCenter );
53 V->addStretch(1); 53 V->addStretch(1);
54 54
55 55
56 SLOT_ToProfile(); 56 SLOT_ToProfile();
57 57
58 // populate main Listbox 58 // populate main Listbox
59 Profiles_LB->clear(); 59 Profiles_LB->clear();
60 QPEApplication::setStylusOperation( 60 QPEApplication::setStylusOperation(
61 Profiles_LB->viewport(), QPEApplication::RightOnHold ); 61 Profiles_LB->viewport(), QPEApplication::RightOnHold );
62 62
63 connect( Profiles_LB, 63 connect( Profiles_LB,
64 SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)), 64 SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)),
65 this, SLOT(SLOT_EditNode(QListBoxItem*)) ); 65 this, SLOT(SLOT_EditNode(QListBoxItem*)) );
66 66
67 { Name2Connection_t & M = NSResources->connections(); 67 { Name2Connection_t & M = NSResources->connections();
68 NodeCollection * NC; 68 NodeCollection * NC;
69 // for all connections 69 // for all connections
70 for( QDictIterator<NodeCollection> it(M); 70 for( QDictIterator<NodeCollection> it(M);
71 it.current(); 71 it.current();
72 ++it ) { 72 ++it ) {
73 NC = it.current(); 73 NC = it.current();
74 Profiles_LB->insertItem( NC->devicePixmap(), 74 Profiles_LB->insertItem( NC->devicePixmap(),
75 NC->name() ); 75 NC->name() );
76 } 76 }
77 } 77 }
78 78
79 if( Profiles_LB->count() ) { 79 if( Profiles_LB->count() ) {
80 Profiles_LB->setSelected( 0, TRUE ); 80 Profiles_LB->setSelected( 0, TRUE );
81 } 81 }
82 82
83 // if no profiles -> auto popup editing 83 // if no profiles -> auto popup editing
84 if( NSResources->connections().count() == 0 ) { 84 if( NSResources->connections().count() == 0 ) {
85 QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); 85 QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) );
86 } 86 }
87 87
88 connect( &(NSResources->system()), 88 connect( &(NSResources->system()),
89 SIGNAL( stdoutLine(const QString &) ), 89 SIGNAL( stdoutLine(const QString &) ),
90 this, SLOT( SLOT_CmdMessage(const QString &) ) ); 90 this, SLOT( SLOT_CmdMessage(const QString &) ) );
91 91
92 connect( &(NSResources->system()), 92 connect( &(NSResources->system()),
93 SIGNAL( stderrLine(const QString &) ), 93 SIGNAL( stderrLine(const QString &) ),
94 this, SLOT( SLOT_CmdMessage(const QString &) ) ); 94 this, SLOT( SLOT_CmdMessage(const QString &) ) );
95 95
96 connect( &(NSResources->system()), 96 connect( &(NSResources->system()),
97 SIGNAL( processEvent(const QString &) ), 97 SIGNAL( processEvent(const QString &) ),
98 this, SLOT( SLOT_CmdMessage(const QString &) ) ); 98 this, SLOT( SLOT_CmdMessage(const QString &) ) );
99 99
100 UpdateTimer->start( 5000 ); 100 UpdateTimer->start( 5000 );
101 connect( UpdateTimer, SIGNAL( timeout() ), 101 connect( UpdateTimer, SIGNAL( timeout() ),
102 this, SLOT( SLOT_RefreshStates() ) ); 102 this, SLOT( SLOT_RefreshStates() ) );
103 103
104 /* Add QCopChannel */ 104 /* Add QCopChannel */
105 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), 105 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)),
106 this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); 106 this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) );
107} 107}
108 108
109NetworkSettings::~NetworkSettings() { 109NetworkSettings::~NetworkSettings() {
110 QString S; 110 QString S;
111 111
112 owarn << "Dispose NS" << oendl;
113 if( NSD.isModified() ) { 112 if( NSD.isModified() ) {
114 owarn << "Modified" << oendl;
115 S = NSD.saveSettings(); 113 S = NSD.saveSettings();
116 if( ! S.isEmpty() ) { 114 if( ! S.isEmpty() ) {
117 S.insert( 0, "<p>" ); 115 S.insert( 0, "<p>" );
118 S.append( "</p>" ); 116 S.append( "</p>" );
119 // problem saving 117 // problem saving
120 QMessageBox::warning( 118 QMessageBox::warning(
121 0, 119 0,
122 tr( "Saving setup" ), S ); 120 tr( "Saving setup" ), S );
123 } 121 }
124 122
125 SLOT_GenerateConfig(); 123 SLOT_GenerateConfig();
126 NSD.setModified( 0 ); 124 NSD.setModified( 0 );
127 } 125 }
128 126
129} 127}
130 128
131void NetworkSettings::SLOT_CmdMessage( const QString & S ) { 129void NetworkSettings::SLOT_CmdMessage( const QString & S ) {
132 Messages_LB->insertItem( S ); 130 Messages_LB->insertItem( S );
133 Messages_LB->setCurrentItem( Messages_LB->count()-1 ); 131 Messages_LB->setCurrentItem( Messages_LB->count()-1 );
134 Messages_LB->ensureCurrentVisible(); 132 Messages_LB->ensureCurrentVisible();
135} 133}
136 134
137void NetworkSettings::SLOT_RefreshStates( void ) { 135void NetworkSettings::SLOT_RefreshStates( void ) {
138 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember 136 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember
139 137
140 if( LBI ) { 138 if( LBI ) {
141 NodeCollection * NC; 139 NodeCollection * NC;
142 NSResources->system().probeInterfaces(); 140 NSResources->system().probeInterfaces();
143 // update current selection only 141 // update current selection only
144 NC = NSResources->findConnection( LBI->text() ); 142 NC = NSResources->findConnection( LBI->text() );
145 if( NC ) { 143 if( NC ) {
146 State_t OldS = NC->state(); 144 State_t OldS = NC->state();
147 State_t NewS = NC->state(1); 145 State_t NewS = NC->state(1);
148 if( OldS != NewS ) { 146 if( OldS != NewS ) {
149 updateProfileState( LBI ); 147 updateProfileState( LBI );
150 } 148 }
151 } 149 }
152 } 150 }
153 151
154 152
155 /* -> LATER !! 153 /* -> LATER !!
156 bool is; 154 bool is;
157 NodeCollection * NC; 155 NodeCollection * NC;
158 156
159 for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { 157 for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) {
160 NC = NSResources->findConnection( Profiles_LB->text(i) ); 158 NC = NSResources->findConnection( Profiles_LB->text(i) );
161 if( NC ) { 159 if( NC ) {
162 State_t OldS = NC->state(); 160 State_t OldS = NC->state();
163 State_t NewS = NC->state(1); 161 State_t NewS = NC->state(1);
164 if( OldS != NewS ) { 162 if( OldS != NewS ) {
165 is = Profiles_LB->isSelected(i); 163 is = Profiles_LB->isSelected(i);
166 Profiles_LB->changeItem( NC->statePixmap(NewS), 164 Profiles_LB->changeItem( NC->statePixmap(NewS),
167 NC->name(), 165 NC->name(),
168 i ); 166 i );
169 if( is ) { 167 if( is ) {
170 Profiles_LB->setSelected( i, TRUE ); 168 Profiles_LB->setSelected( i, TRUE );
171 } 169 }
172 } 170 }
173 } 171 }
174 } 172 }
175 if( ci >= 0 ) 173 if( ci >= 0 )
176 Profiles_LB->setCurrentItem( ci ); 174 Profiles_LB->setCurrentItem( ci );
177 */ 175 */
178} 176}
179 177
180void NetworkSettings::SLOT_AddNode( void ) { 178void NetworkSettings::SLOT_AddNode( void ) {
181 SLOT_EditNode( 0 ); 179 SLOT_EditNode( 0 );
182} 180}
183 181
184void NetworkSettings::SLOT_DeleteNode( void ) { 182void NetworkSettings::SLOT_DeleteNode( void ) {
185 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); 183 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
186 184
187 if ( ! LBI ) 185 if ( ! LBI )
188 return; 186 return;
189 187
190 if( QMessageBox::warning( 188 if( QMessageBox::warning(
191 0, 189 0,
192 tr( "Removing profile" ), 190 tr( "Removing profile" ),
193 tr( "Remove selected profile ?" ), 191 tr( "Remove selected profile ?" ),
194 1, 0 ) == 1 ) { 192 1, 0 ) == 1 ) {
195 NSResources->removeConnection( LBI->text() ); 193 NSResources->removeConnection( LBI->text() );
196 delete LBI; 194 delete LBI;
197 NSD.setModified( 1 ); 195 NSD.setModified( 1 );
198 } 196 }
199} 197}
200 198
201void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { 199void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) {
202 QString OldName = ""; 200 QString OldName = "";
203 201
204 EditConnection EC( this ); 202 EditConnection EC( this );
205 203
206 if( LBI ) { 204 if( LBI ) {
207 NodeCollection * NC = NSResources->findConnection( LBI->text() ); 205 NodeCollection * NC = NSResources->findConnection( LBI->text() );
208 if( ! NC ) { 206 if( ! NC ) {
209 return; 207 return;
210 } 208 }
211 OldName = NC->name(); 209 OldName = NC->name();
212 EC.setConnection( NC ); 210 EC.setConnection( NC );
213 } 211 }
214 212
215 EC.showMaximized(); 213 EC.showMaximized();
216 // disable refresh timer 214 // disable refresh timer
217 UpdateTimer->stop(); 215 UpdateTimer->stop();
218 216
219 // we need to retry 217 // we need to retry
220 while( 1 ) { 218 while( 1 ) {
221 if( EC.exec() == QDialog::Accepted ) { 219 if( EC.exec() == QDialog::Accepted ) {
222 // toplevel item -> store 220 // toplevel item -> store
223 NodeCollection * NC = EC.connection(); 221 NodeCollection * NC = EC.connection();
224 if( NC->isModified() ) { 222 if( NC->isModified() ) {
225 if( LBI ) { 223 if( LBI ) {
226 if( NC->name() != OldName ) { 224 if( NC->name() != OldName ) {
227 // find if new name is free 225 // find if new name is free
228 NodeCollection * LCN = NSResources->findConnection( 226 NodeCollection * LCN = NSResources->findConnection(
229 NC->name() ); 227 NC->name() );
230 if( LCN ) { 228 if( LCN ) {
231 QMessageBox::warning( 229 QMessageBox::warning(
232 0, 230 0,
233 tr( "In System Config" ), 231 tr( "In System Config" ),
234 tr( "Name %1 already exists" ).arg(NC->name()) 232 tr( "Name %1 already exists" ).arg(NC->name())
235 ); 233 );
236 continue; // restart exec 234 continue; // restart exec
237 } // else new name 235 } // else new name
238 // new name -> remove item 236 // new name -> remove item
239 NSResources->removeConnection( OldName ); 237 NSResources->removeConnection( OldName );
240 NSResources->addConnection( NC, 0 ); 238 NSResources->addConnection( NC, 0 );
241 } // else not changed 239 } // else not changed
242 240
243 // must add it here since change will trigger event 241 // must add it here since change will trigger event
244 Profiles_LB->changeItem( NC->devicePixmap(), 242 Profiles_LB->changeItem( NC->devicePixmap(),
245 NC->name(), 243 NC->name(),
246 Profiles_LB->index( LBI ) 244 Profiles_LB->index( LBI )
247 ); 245 );
248 } else { 246 } else {
249 // new item 247 // new item
250 int ci = Profiles_LB->count(); 248 int ci = Profiles_LB->count();
251 NSResources->addConnection( NC, 0 ); 249 NSResources->addConnection( NC, 0 );
252 NC->setNumber( NSResources->assignConnectionNumber() ); 250 NC->setNumber( NSResources->assignConnectionNumber() );
253 Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); 251 Profiles_LB->insertItem( NC->devicePixmap(), NC->name() );
254 Profiles_LB->setSelected( ci, TRUE ); 252 Profiles_LB->setSelected( ci, TRUE );
255 } 253 }
256 updateProfileState( LBI ); 254 updateProfileState( LBI );
257 } 255 }
258 } else { 256 } else {
259 // cancelled : reset connection 257 // cancelled : reset connection
260 if( LBI ) { 258 if( LBI ) {
261 NodeCollection * NC = NSResources->findConnection( LBI->text() ); 259 NodeCollection * NC = NSResources->findConnection( LBI->text() );
262 NC->reassign(); 260 NC->reassign();
263 } 261 }
264 } 262 }
265 break; 263 break;
266 } 264 }
267 // reenable 265 // reenable
268 UpdateTimer->start( 5000 ); 266 UpdateTimer->start( 5000 );
269} 267}
270 268
271void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { 269void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) {
272 if( LBI == 0 ) 270 if( LBI == 0 )
273 return; 271 return;
274 272
275 NodeCollection * NC = NSResources->findConnection( LBI->text() ); 273 NodeCollection * NC = NSResources->findConnection( LBI->text() );
276 274
277 if( NC->description().isEmpty() ) { 275 if( NC->description().isEmpty() ) {
278 Description_LBL->setText( tr( "<<No description>>" ) ); 276 Description_LBL->setText( tr( "<<No description>>" ) );
279 } else { 277 } else {
280 Description_LBL->setText( NC->description() ); 278 Description_LBL->setText( NC->description() );
281 } 279 }
282 280
283 Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); 281 Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() );
284 282
285 bool FrmActive = 1; 283 bool FrmActive = 1;
286 bool IsEnabled = 1; 284 bool IsEnabled = 1;
287 int leds = 0; 285 int leds = 0;
288 286
289 owarn << "State " << NC->state() << oendl;
290 switch( NC->state() ) { 287 switch( NC->state() ) {
291 case Disabled : // no further work 288 case Disabled : // no further work
292 IsEnabled = 0; 289 IsEnabled = 0;
293 FrmActive = 0; 290 FrmActive = 0;
294 owarn << "LEds " << leds << oendl;
295 break; 291 break;
296 case Unknown : 292 case Unknown :
297 case Unchecked : 293 case Unchecked :
298 case Unavailable : 294 case Unavailable :
299 FrmActive = 0; 295 FrmActive = 0;
300 break; 296 break;
301 case Off : 297 case Off :
302 leds = 1; 298 leds = 1;
303 break; 299 break;
304 case Available : 300 case Available :
305 leds = 2; 301 leds = 2;
306 break; 302 break;
307 case IsUp : 303 case IsUp :
308 leds = 3; 304 leds = 3;
309 break; 305 break;
310 } 306 }
311 307
312 Disable_TB->setOn( ! IsEnabled ); 308 Disable_TB->setOn( ! IsEnabled );
313 LED_Frm->setEnabled( FrmActive ); 309 LED_Frm->setEnabled( FrmActive );
314 310
315 for( int i = 0 ; i < leds; i ++ ) { 311 for( int i = 0 ; i < leds; i ++ ) {
316 Leds[i]->setColor( red ); 312 Leds[i]->setColor( red );
317 Leds[i]->setOn( true ); 313 Leds[i]->setOn( true );
318 } 314 }
319 for( int i = leds ; i < 3; i ++ ) { 315 for( int i = leds ; i < 3; i ++ ) {
320 Leds[i]->setColor( red ); 316 Leds[i]->setColor( red );
321 Leds[i]->setOn( false ); 317 Leds[i]->setOn( false );
322 } 318 }
323 319
324 Up_TB->setEnabled( leds < 3 && leds != 0 ); 320 Up_TB->setEnabled( leds < 3 && leds != 0 );
325 Down_TB->setEnabled( leds > 0 ); 321 Down_TB->setEnabled( leds > 0 );
326} 322}
327 323
328void NetworkSettings::SLOT_CheckState( void ) { 324void NetworkSettings::SLOT_CheckState( void ) {
329 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); 325 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
330 if ( ! LBI ) 326 if ( ! LBI )
331 return; 327 return;
332 updateProfileState( LBI ); 328 updateProfileState( LBI );
333} 329}
334 330
335void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { 331void NetworkSettings::updateProfileState( QListBoxItem * LBI ) {
336 if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { 332 if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) {
337 SLOT_ShowNode( LBI ); 333 SLOT_ShowNode( LBI );
338 } 334 }
339} 335}
340 336
341void NetworkSettings::SLOT_GenerateConfig( void ) { 337void NetworkSettings::SLOT_GenerateConfig( void ) {
342 QString S = NSD.generateSettings(); 338 QString S = NSD.generateSettings();
343 if( ! S.isEmpty() ) { 339 if( ! S.isEmpty() ) {
344 S.insert( 0, "<p>" ); 340 S.insert( 0, "<p>" );
345 S.append( "</p>" ); 341 S.append( "</p>" );
346 QMessageBox::warning( 342 QMessageBox::warning(
347 0, 343 0,
348 tr( "Generate config" ), 344 tr( "Generate config" ),
349 S); 345 S);
350 } 346 }
351} 347}
352 348
353void NetworkSettings::SLOT_Disable( bool T ) { 349void NetworkSettings::SLOT_Disable( bool T ) {
354 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); 350 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
355 QString Msg; 351 QString Msg;
356 352
357 if ( ! LBI ) 353 if ( ! LBI )
358 return; 354 return;
359 355
360 NodeCollection * NC = NSResources->findConnection( LBI->text() ); 356 NodeCollection * NC = NSResources->findConnection( LBI->text() );
361 357
362 owarn << "Prepare to disable" << oendl; 358 Log(( "Prepare to %sable\n", (T) ? "en" : "dis" ));
363 Msg = NC->setState( (T) ? Disable : Enable ); 359 Msg = NC->setState( (T) ? Disable : Enable );
364 if( ! Msg.isEmpty() ) { 360 if( ! Msg.isEmpty() ) {
365 Msg.insert( 0, "<p>" ); 361 Msg.insert( 0, "<p>" );
366 Msg.append( "</p>" ); 362 Msg.append( "</p>" );
367 QMessageBox::warning( 363 QMessageBox::warning(
368 0, 364 0,
369 tr( "Activating profile" ), 365 tr( "Activating profile" ),
370 Msg ); 366 Msg );
371 return; 367 return;
372 } 368 }
373 369
374 // reload new state 370 // reload new state
375 NC->state( true ); 371 NC->state( true );
376 updateProfileState( LBI ); 372 updateProfileState( LBI );
377} 373}
378 374
379void NetworkSettings::SLOT_Up( void ) { 375void NetworkSettings::SLOT_Up( void ) {
380 // bring more up 376 // bring more up
381 377
382 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); 378 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
383 QString Msg; 379 QString Msg;
384 int led = -1; 380 int led = -1;
385 381
386 if ( ! LBI ) 382 if ( ! LBI )
387 return; 383 return;
388 384
389 NodeCollection * NC = 385 NodeCollection * NC =
390 NSResources->findConnection( LBI->text() ); 386 NSResources->findConnection( LBI->text() );
391 387
392 switch( NC->state() ) { 388 switch( NC->state() ) {
393 case Disabled : // cannot modify this state 389 case Disabled : // cannot modify this state
394 case Unknown : // cannot modify this state 390 case Unknown : // cannot modify this state
395 case Unchecked : // cannot modify this state 391 case Unchecked : // cannot modify this state
396 case Unavailable : // cannot modify this state 392 case Unavailable : // cannot modify this state
397 case IsUp : // highest UP state 393 case IsUp : // highest UP state
398 return; 394 return;
399 case Off : // -> activate 395 case Off : // -> activate
400 led = 1; 396 led = 1;
401 Down_TB->setEnabled( true ); 397 Down_TB->setEnabled( true );
402 Log(( "Activate interface %s\n", NC->name().latin1() )); 398 Log(( "Activate interface %s\n", NC->name().latin1() ));
403 Msg = NC->setState( Activate ); 399 Msg = NC->setState( Activate );
404 break; 400 break;
405 case Available : // -> up 401 case Available : // -> up
406 led = 2; 402 led = 2;
407 Log(( "Bring up interface %s\n", NC->name().latin1() )); 403 Log(( "Bring up interface %s\n", NC->name().latin1() ));
408 Msg = NC->setState( Up ); 404 Msg = NC->setState( Up );
409 if( Msg.isEmpty() ) { 405 if( Msg.isEmpty() ) {
410 Up_TB->setEnabled( false ); 406 Up_TB->setEnabled( false );
411 } 407 }
412 break; 408 break;
413 } 409 }
414 410
415 if( ! Msg.isEmpty() ) { 411 if( ! Msg.isEmpty() ) {
416 Msg.insert( 0, "<p>" ); 412 Msg.insert( 0, "<p>" );
417 Msg.append( "</p>" ); 413 Msg.append( "</p>" );
418 QMessageBox::warning( 414 QMessageBox::warning(
419 0, 415 0,
420 tr( "Increase availability" ), 416 tr( "Increase availability" ),
421 Msg ); 417 Msg );
422 return; 418 return;
423 } 419 }
424 420
425 updateProfileState( LBI ); 421 updateProfileState( LBI );
426 422
427 // set color of led we should change 423 // set color of led we should change
428 if( led > 0 ) { 424 if( led > 0 ) {
429 Leds[led]->setColor( blue ); 425 Leds[led]->setColor( blue );
430 Leds[led]->setOn( true ); 426 Leds[led]->setOn( true );
431 } 427 }
432 428
433} 429}
434 430
435void NetworkSettings::SLOT_Down( void ) { 431void NetworkSettings::SLOT_Down( void ) {
436 // bring more down 432 // bring more down
437 433
438 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); 434 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
439 int led = -1; 435 int led = -1;
440 QString Msg; 436 QString Msg;
441 437
442 if ( ! LBI ) 438 if ( ! LBI )
443 return; 439 return;
444 440
445 NodeCollection * NC = 441 NodeCollection * NC =
446 NSResources->findConnection( LBI->text() ); 442 NSResources->findConnection( LBI->text() );
447 443
448 switch( NC->state() ) { 444 switch( NC->state() ) {
449 case Disabled : // cannot modify this state 445 case Disabled : // cannot modify this state
450 case Unknown : // cannot modify this state 446 case Unknown : // cannot modify this state
451 case Unchecked : // cannot modify this state 447 case Unchecked : // cannot modify this state
452 case Unavailable : // cannot modify this state 448 case Unavailable : // cannot modify this state
453 case Off : // highest DOWN state 449 case Off : // highest DOWN state
454 break; 450 break;
455 case Available : // -> down 451 case Available : // -> down
456 led = 0; 452 led = 0;
457 Log(( "Deactivate interface %s\n", NC->name().latin1() )); 453 Log(( "Deactivate interface %s\n", NC->name().latin1() ));
458 Msg = NC->setState( Deactivate ); 454 Msg = NC->setState( Deactivate );
459 Down_TB->setEnabled( false ); 455 Down_TB->setEnabled( false );
460 break; 456 break;
461 case IsUp : // highest UP state 457 case IsUp : // highest UP state
462 led = 1; 458 led = 1;
463 Up_TB->setEnabled( true ); 459 Up_TB->setEnabled( true );
464 Log(( "Bring down interface %s\n", NC->name().latin1() )); 460 Log(( "Bring down interface %s\n", NC->name().latin1() ));
465 Msg = NC->setState( Down, 1 ); 461 Msg = NC->setState( Down, 1 );
466 if( Msg.isEmpty() ) { 462 if( Msg.isEmpty() ) {
467 // remove 'up' file to make sure 463 // remove 'up' file to make sure
468 unlink ( QString().sprintf( "/tmp/Profile-%d.up", NC->number() ).latin1() );; 464 unlink ( QString().sprintf( "/tmp/Profile-%d.up", NC->number() ).latin1() );;
469 } 465 }
470 break; 466 break;
471 } 467 }
472 468
473 if( ! Msg.isEmpty() ) { 469 if( ! Msg.isEmpty() ) {
474 Msg.insert( 0, "<p>" ); 470 Msg.insert( 0, "<p>" );
475 Msg.append( "</p>" ); 471 Msg.append( "</p>" );
476 QMessageBox::warning( 472 QMessageBox::warning(
477 0, 473 0,
478 tr( "Decrease availability" ), 474 tr( "Decrease availability" ),
479 Msg ); 475 Msg );
480 return; 476 return;
481 } 477 }
482 478
483 updateProfileState( LBI ); 479 updateProfileState( LBI );
484 480
485 // set color of led we should change 481 // set color of led we should change
486 if( led >= 0 ) { 482 if( led >= 0 ) {
487 Leds[led]->setColor( blue ); 483 Leds[led]->setColor( blue );
488 } 484 }
489} 485}
490 486
491void NetworkSettings::SLOT_ToMessages( void ) { 487void NetworkSettings::SLOT_ToMessages( void ) {
492 Profiles_LB->hide(); 488 Profiles_LB->hide();
493 Profile_GB->hide(); 489 Profile_GB->hide();
494 Messages_GB->show(); 490 Messages_GB->show();
495} 491}
496 492
497void NetworkSettings::SLOT_ToProfile( void ) { 493void NetworkSettings::SLOT_ToProfile( void ) {
498 Profiles_LB->show(); 494 Profiles_LB->show();
499 Profile_GB->show(); 495 Profile_GB->show();
500 Messages_GB->hide(); 496 Messages_GB->hide();
501} 497}
502 498
503void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { 499void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) {
504 QDataStream stream( data, IO_ReadOnly ); 500 QDataStream stream( data, IO_ReadOnly );
505 501
506 if( msg == "raise" ) { 502 if( msg == "raise" ) {
507 raise(); 503 raise();
508 return; 504 return;
509 } /* if ( msg == "someMessage(int,int,int)" ) { 505 } /* if ( msg == "someMessage(int,int,int)" ) {
510 int a,b,c; 506 int a,b,c;
511 stream >> a >> b >> c; 507 stream >> a >> b >> c;
512 ... 508 ...
513 } */ 509 } */
514} 510}
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 @@
1config NS2CORE 1config NS2CORE
2 boolean "opie-networksettings2 (TCP/IP network settings)" 2 boolean "opie-networksettings2 library"
3 default "y" 3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2UI 4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2UI
5 5
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,587 +1,587 @@
1#include <sys/types.h> 1#include <sys/types.h>
2#include <sys/wait.h> 2#include <sys/wait.h>
3 3
4#include <net/if.h> 4#include <net/if.h>
5#include <net/if_arp.h> 5#include <net/if_arp.h>
6#include <netinet/in.h> 6#include <netinet/in.h>
7#include <arpa/inet.h> 7#include <arpa/inet.h>
8#include <sys/ioctl.h> 8#include <sys/ioctl.h>
9#include <sys/socket.h> 9#include <sys/socket.h>
10#include <stdlib.h> 10#include <stdlib.h>
11#include <stdio.h> 11#include <stdio.h>
12#include <fcntl.h> 12#include <fcntl.h>
13#include <errno.h> 13#include <errno.h>
14#include <unistd.h> 14#include <unistd.h>
15 15
16#include <opie2/oprocess.h> 16#include <opie2/oprocess.h>
17 17
18#include <qdir.h> 18#include <qdir.h>
19#include <qregexp.h> 19#include <qregexp.h>
20#include <qstringlist.h> 20#include <qstringlist.h>
21#include <qfile.h> 21#include <qfile.h>
22#include <qtextstream.h> 22#include <qtextstream.h>
23#include <qapplication.h> 23#include <qapplication.h>
24 24
25#include "resources.h" 25#include "resources.h"
26#include "system.h" 26#include "system.h"
27 27
28#define PROCNETDEV "/proc/net/dev" 28#define PROCNETDEV "/proc/net/dev"
29 29
30#ifndef ARPHRD_IEEE80211 30#ifndef ARPHRD_IEEE80211
31#define ARPHRD_IEEE80211 801 31#define ARPHRD_IEEE80211 801
32#endif 32#endif
33 33
34static char Dig2Hex[] = { 34static char Dig2Hex[] = {
35 '0', '1', '2', '3', 35 '0', '1', '2', '3',
36 '4', '5', '6', '7', 36 '4', '5', '6', '7',
37 '8', '9', 'A', 'B', 37 '8', '9', 'A', 'B',
38 'C', 'D', 'E', 'F' 38 'C', 'D', 'E', 'F'
39}; 39};
40 40
41// get HIGH nibble of byte 41// get HIGH nibble of byte
42#define HN(x) Dig2Hex[(((x)&0xf0)>>4)] 42#define HN(x) Dig2Hex[(((x)&0xf0)>>4)]
43// get LOW nibble of byte 43// get LOW nibble of byte
44#define LN(x) Dig2Hex[((x)&0x0f)] 44#define LN(x) Dig2Hex[((x)&0x0f)]
45 45
46System::System( void ) : QObject(), ProbedInterfaces() { 46System::System( void ) : QObject(), ProbedInterfaces() {
47 ProcDevNet = 0; 47 ProcDevNet = 0;
48} 48}
49 49
50System::~System( void ) { 50System::~System( void ) {
51 if( ProcDevNet ) 51 if( ProcDevNet )
52 delete ProcDevNet; 52 delete ProcDevNet;
53} 53}
54 54
55QDict<InterfaceInfo> & System::interfaces( void ) { 55QDict<InterfaceInfo> & System::interfaces( void ) {
56 if( ProbedInterfaces.count() == 0 ) { 56 if( ProbedInterfaces.count() == 0 ) {
57 probeInterfaces(); 57 probeInterfaces();
58 } 58 }
59 return ProbedInterfaces; 59 return ProbedInterfaces;
60} 60}
61 61
62int System::runAsRoot( QStringList & S, MyProcess * Prc ) { 62int System::runAsRoot( QStringList & S, MyProcess * Prc ) {
63 char * usr = getenv("USER"); 63 char * usr = getenv("USER");
64 64
65 if( S.count() == 0 ) { 65 if( S.count() == 0 ) {
66 // loophole to start shell 66 // loophole to start shell
67 return 8888; 67 return 8888;
68 } 68 }
69 if( usr == 0 || strcmp( usr, "root" ) ) { 69 if( usr == 0 || strcmp( usr, "root" ) ) {
70 // unknown or non-root user -> use SUDO 70 // unknown or non-root user -> use SUDO
71 S.prepend( "sudo" ); 71 S.prepend( "sudo" );
72 } 72 }
73 73
74 if( getenv( "NS2TESTMODE" ) ) { 74 if( getenv( "NS2TESTMODE" ) ) {
75 owarn << "TESTMODE !!! execute " 75 odebug << "TESTMODE !!! execute "
76 << S.join( " ") 76 << S.join( " ")
77 << oendl; 77 << oendl;
78 } else { 78 } else {
79 MyProcess * P; 79 MyProcess * P;
80 80
81 if( Prc ) { 81 if( Prc ) {
82 P = Prc; 82 P = Prc;
83 } else { 83 } else {
84 P = new MyProcess(); 84 P = new MyProcess();
85 emit processEvent( tr("Command : ") + S.join( " " ) ); 85 emit processEvent( tr("Command : ") + S.join( " " ) );
86 86
87 connect( P, 87 connect( P,
88 SIGNAL( stdoutLine( const QString & ) ), 88 SIGNAL( stdoutLine( const QString & ) ),
89 this, 89 this,
90 SIGNAL( stdoutLine( const QString & ) ) ); 90 SIGNAL( stdoutLine( const QString & ) ) );
91 91
92 connect( P, 92 connect( P,
93 SIGNAL( stderrLine( const QString & ) ), 93 SIGNAL( stderrLine( const QString & ) ),
94 this, 94 this,
95 SIGNAL( stderrLine( const QString & ) ) ); 95 SIGNAL( stderrLine( const QString & ) ) );
96 96
97 connect( P, 97 connect( P,
98 SIGNAL(processExited(MyProcess*) ), 98 SIGNAL(processExited(MyProcess*) ),
99 this, SLOT 99 this, SLOT
100 (SLOT_ProcessExited(MyProcess*) ) ); 100 (SLOT_ProcessExited(MyProcess*) ) );
101 } 101 }
102 102
103 P->process() << S; 103 P->process() << S;
104 104
105 Log(("Executing %s\n", S.join( " " ).latin1() )); 105 Log(("Executing %s\n", S.join( " " ).latin1() ));
106 106
107 if( ! P->process().start( OProcess::DontCare, 107 if( ! P->process().start( OProcess::DontCare,
108 OProcess::AllOutput ) ) { 108 OProcess::AllOutput ) ) {
109 owarn << "Error starting " << S << oendl; 109 odebug << "Error starting " << S << oendl;
110 if( ! Prc ) 110 if( ! Prc )
111 delete P; 111 delete P;
112 // error starting app 112 // error starting app
113 return 0; 113 return 0;
114 } 114 }
115 owarn << "Started " << S << oendl; 115 odebug << "Started " << S << oendl;
116 } 116 }
117 117
118 // all is fine 118 // all is fine
119 return 1; 119 return 1;
120} 120}
121 121
122int System::execAsUser( QStringList & SL ) { 122int System::execAsUser( QStringList & SL ) {
123 MyProcess * P = new MyProcess(); 123 MyProcess * P = new MyProcess();
124 CurrentQPEUser CU = NSResources->currentUser(); 124 CurrentQPEUser CU = NSResources->currentUser();
125 char * usr = getenv("USER"); 125 char * usr = getenv("USER");
126 126
127 if( strcmp( usr, "root" ) == 0 ) { 127 if( strcmp( usr, "root" ) == 0 ) {
128 // find user running qpe 128 // find user running qpe
129 if( CU.UserName.isEmpty() ) { 129 if( CU.UserName.isEmpty() ) {
130 // if we come here, the exec was not successfull 130 // if we come here, the exec was not successfull
131 Log(("User not known \n" )); 131 Log(("User not known \n" ));
132 return 0; 132 return 0;
133 } 133 }
134 } 134 }
135 135
136 // now we are ready to exec the requested command 136 // now we are ready to exec the requested command
137 setuid( CU.Uid ); 137 setuid( CU.Uid );
138 setgid( CU.Gid ); 138 setgid( CU.Gid );
139 139
140 for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) { 140 for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) {
141 QString X; 141 QString X;
142 QStringList SL; 142 QStringList SL;
143 X = CU.EnvList[i]; 143 X = CU.EnvList[i];
144 SL = QStringList::split( "=", X ); 144 SL = QStringList::split( "=", X );
145 P->process().setEnvironment( SL[0], SL[1] ); 145 P->process().setEnvironment( SL[0], SL[1] );
146 } 146 }
147 147
148 P->process() << SL; 148 P->process() << SL;
149 149
150 emit processEvent( tr("Command : ") + SL.join( " " ) ); 150 emit processEvent( tr("Command : ") + SL.join( " " ) );
151 151
152 Log(("Executing as user %s : %s\n", 152 Log(("Executing as user %s : %s\n",
153 CU.UserName.latin1(), 153 CU.UserName.latin1(),
154 SL.join( " " ).latin1() )); 154 SL.join( " " ).latin1() ));
155 155
156 int rv = ( P->process().start( OProcess::DontCare, 156 int rv = ( P->process().start( OProcess::DontCare,
157 OProcess::NoCommunication ) ); 157 OProcess::NoCommunication ) );
158 delete P; 158 delete P;
159 159
160 if( rv ) { 160 if( rv ) {
161 // if we come here, the exec was not successfull 161 // if we come here, the exec was not successfull
162 Log(("Could not exec : %d\n", errno )); 162 Log(("Could not exec : %d\n", errno ));
163 } 163 }
164 164
165 return ! rv; 165 return ! rv;
166} 166}
167 167
168void System::SLOT_ProcessExited( MyProcess * P ) { 168void System::SLOT_ProcessExited( MyProcess * P ) {
169 QString R; 169 QString R;
170 170
171 for( QValueListConstIterator<QCString> it = P->process().args().begin(); 171 for( QValueListConstIterator<QCString> it = P->process().args().begin();
172 it != P->process().args().end(); 172 it != P->process().args().end();
173 ++it ) { 173 ++it ) {
174 R += (*it); 174 R += (*it);
175 R += " "; 175 R += " ";
176 } 176 }
177 177
178 R += "Returned with " + QString().setNum( P->process().exitStatus() ); 178 R += "Returned with " + QString().setNum( P->process().exitStatus() );
179 emit processEvent( R ); 179 emit processEvent( R );
180 delete P; 180 delete P;
181} 181}
182 182
183void System::refreshStatistics( InterfaceInfo & I ) { 183void System::refreshStatistics( InterfaceInfo & I ) {
184 if( ! ProcDevNet ) { 184 if( ! ProcDevNet ) {
185 return; 185 return;
186 } 186 }
187 // cannot seek on dev 187 // cannot seek on dev
188 ProcDevNet->close(); 188 ProcDevNet->close();
189 ProcDevNet->open( IO_ReadOnly ); 189 ProcDevNet->open( IO_ReadOnly );
190 190
191 QString line; 191 QString line;
192 QTextStream procTs(ProcDevNet); 192 QTextStream procTs(ProcDevNet);
193 QStringList SL; 193 QStringList SL;
194 int loc = -1; 194 int loc = -1;
195 int version; 195 int version;
196 196
197 procTs.readLine(); 197 procTs.readLine();
198 line = procTs.readLine(); 198 line = procTs.readLine();
199 // get version 199 // get version
200 if( line.find("compressed") ) 200 if( line.find("compressed") )
201 version = 3; 201 version = 3;
202 else if( line.find( "bytes" ) ) 202 else if( line.find( "bytes" ) )
203 version = 2; 203 version = 2;
204 else 204 else
205 version = 1; 205 version = 1;
206 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { 206 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
207 if( (loc = line.find(":") ) == -1) { 207 if( (loc = line.find(":") ) == -1) {
208 continue; 208 continue;
209 } 209 }
210 210
211 if( I.Name != line.left(loc) ) 211 if( I.Name != line.left(loc) )
212 continue; 212 continue;
213 213
214 // tokenize 214 // tokenize
215 SL = QStringList::split( ' ', line, FALSE ); 215 SL = QStringList::split( ' ', line, FALSE );
216 216
217 // update data 217 // update data
218 switch( version ) { 218 switch( version ) {
219 case 1 : 219 case 1 :
220 I.RcvBytes = SL[1]; 220 I.RcvBytes = SL[1];
221 I.RcvErrors = SL[3]; 221 I.RcvErrors = SL[3];
222 I.RcvDropped = SL[4]; 222 I.RcvDropped = SL[4];
223 I.SndBytes = SL[6]; 223 I.SndBytes = SL[6];
224 I.SndErrors = SL[8]; 224 I.SndErrors = SL[8];
225 I.SndDropped = SL[9]; 225 I.SndDropped = SL[9];
226 I.Collisions = SL[11]; 226 I.Collisions = SL[11];
227 break; 227 break;
228 case 2 : 228 case 2 :
229 I.RcvBytes = SL[1]; 229 I.RcvBytes = SL[1];
230 I.RcvErrors = SL[3]; 230 I.RcvErrors = SL[3];
231 I.RcvDropped = SL[4]; 231 I.RcvDropped = SL[4];
232 I.SndBytes = SL[7]; 232 I.SndBytes = SL[7];
233 I.SndErrors = SL[9]; 233 I.SndErrors = SL[9];
234 I.SndDropped = SL[10]; 234 I.SndDropped = SL[10];
235 I.Collisions = SL[12]; 235 I.Collisions = SL[12];
236 break; 236 break;
237 case 3 : 237 case 3 :
238 I.RcvBytes = SL[1]; 238 I.RcvBytes = SL[1];
239 I.RcvErrors = SL[3]; 239 I.RcvErrors = SL[3];
240 I.RcvDropped = SL[4]; 240 I.RcvDropped = SL[4];
241 I.SndBytes = SL[9]; 241 I.SndBytes = SL[9];
242 I.SndErrors = SL[11]; 242 I.SndErrors = SL[11];
243 I.SndDropped = SL[12]; 243 I.SndDropped = SL[12];
244 I.Collisions = SL[14]; 244 I.Collisions = SL[14];
245 break; 245 break;
246 } 246 }
247 break; 247 break;
248 } 248 }
249} 249}
250 250
251// 251//
252// THIS UPDATES THE LIST -> INTERFACES ARE NOT DELETED BUT 252// THIS UPDATES THE LIST -> INTERFACES ARE NOT DELETED BUT
253// FLAGGED AS ! 'IsUp' IF NO LONGER PRESENT 253// FLAGGED AS ! 'IsUp' IF NO LONGER PRESENT
254// 254//
255 255
256void System::probeInterfaces( void ) { 256void System::probeInterfaces( void ) {
257 257
258 // probe interfaces 258 // probe interfaces
259 int sockfd; 259 int sockfd;
260 // get list of all interfaces 260 // get list of all interfaces
261 struct ifreq ifrs; 261 struct ifreq ifrs;
262 InterfaceInfo * IFI; 262 InterfaceInfo * IFI;
263 263
264 // flag all as 'down' 264 // flag all as 'down'
265 for( QDictIterator<InterfaceInfo> it( ProbedInterfaces ); 265 for( QDictIterator<InterfaceInfo> it( ProbedInterfaces );
266 it.current(); 266 it.current();
267 ++it ) { 267 ++it ) {
268 it.current()->IsUp = 0; 268 it.current()->IsUp = 0;
269 } 269 }
270 270
271 sockfd = socket(PF_INET, SOCK_DGRAM, 0); 271 sockfd = socket(PF_INET, SOCK_DGRAM, 0);
272 if(sockfd == -1) { 272 if(sockfd == -1) {
273 owarn << "Cannot open INET socket " 273 odebug << "Cannot open INET socket "
274 << errno 274 << errno
275 << " " 275 << " "
276 << strerror( errno ) 276 << strerror( errno )
277 << oendl; 277 << oendl;
278 return; 278 return;
279 } 279 }
280 280
281 // read interfaces from /proc/dev/net 281 // read interfaces from /proc/dev/net
282 // SIOCGIFCONF does not return ALL interfaces ???!? 282 // SIOCGIFCONF does not return ALL interfaces ???!?
283 ProcDevNet = new QFile(PROCNETDEV); 283 ProcDevNet = new QFile(PROCNETDEV);
284 if( ! ProcDevNet->open(IO_ReadOnly) ) { 284 if( ! ProcDevNet->open(IO_ReadOnly) ) {
285 owarn << "Cannot open " 285 odebug << "Cannot open "
286 << PROCNETDEV 286 << PROCNETDEV
287 << " " 287 << " "
288 << errno 288 << errno
289 << " " 289 << " "
290 << strerror( errno ) 290 << strerror( errno )
291 << oendl; 291 << oendl;
292 delete ProcDevNet; 292 delete ProcDevNet;
293 ProcDevNet =0; 293 ProcDevNet =0;
294 ::close( sockfd ); 294 ::close( sockfd );
295 return; 295 return;
296 } 296 }
297 297
298 QString line; 298 QString line;
299 QString NicName; 299 QString NicName;
300 QTextStream procTs(ProcDevNet); 300 QTextStream procTs(ProcDevNet);
301 int loc = -1; 301 int loc = -1;
302 302
303 procTs.readLine(); // eat a line 303 procTs.readLine(); // eat a line
304 procTs.readLine(); // eat a line 304 procTs.readLine(); // eat a line
305 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { 305 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
306 if((loc = line.find(":")) == -1) { 306 if((loc = line.find(":")) == -1) {
307 continue; 307 continue;
308 } 308 }
309 309
310 NicName = line.left(loc); 310 NicName = line.left(loc);
311 311
312 // set name for ioctl 312 // set name for ioctl
313 strcpy( ifrs.ifr_name, NicName.latin1() ); 313 strcpy( ifrs.ifr_name, NicName.latin1() );
314 314
315 if ( ! ( IFI = ProbedInterfaces.find( NicName ) ) ) { 315 if ( ! ( IFI = ProbedInterfaces.find( NicName ) ) ) {
316 // new nic 316 // new nic
317 Log(("New NIC found : %s\n", NicName.latin1())); 317 Log(("New NIC found : %s\n", NicName.latin1()));
318 IFI = new InterfaceInfo; 318 IFI = new InterfaceInfo;
319 IFI->Name = line.left(loc); 319 IFI->Name = line.left(loc);
320 IFI->Collection = 0; 320 IFI->Collection = 0;
321 ProbedInterfaces.insert( IFI->Name, IFI ); 321 ProbedInterfaces.insert( IFI->Name, IFI );
322 322
323 // get dynamic info 323 // get dynamic info
324 if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) { 324 if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) {
325 IFI->IsPointToPoint = ((ifrs.ifr_flags & IFF_POINTOPOINT) == IFF_POINTOPOINT); 325 IFI->IsPointToPoint = ((ifrs.ifr_flags & IFF_POINTOPOINT) == IFF_POINTOPOINT);
326 } else { 326 } else {
327 IFI->IsPointToPoint = 0; 327 IFI->IsPointToPoint = 0;
328 } 328 }
329 329
330 // settings that never change 330 // settings that never change
331 IFI->DstAddress = ""; 331 IFI->DstAddress = "";
332 332
333 if( IFI->IsPointToPoint ) { 333 if( IFI->IsPointToPoint ) {
334 if( ioctl(sockfd, SIOCGIFDSTADDR, &ifrs) >= 0 ) { 334 if( ioctl(sockfd, SIOCGIFDSTADDR, &ifrs) >= 0 ) {
335 IFI->DstAddress = 335 IFI->DstAddress =
336 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_dstaddr)->sin_addr); 336 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_dstaddr)->sin_addr);
337 } 337 }
338 } 338 }
339 339
340 IFI->CardType = 999999; 340 IFI->CardType = 999999;
341 IFI->MACAddress = ""; 341 IFI->MACAddress = "";
342 342
343 if( ioctl(sockfd, SIOCGIFHWADDR, &ifrs) >= 0 ) { 343 if( ioctl(sockfd, SIOCGIFHWADDR, &ifrs) >= 0 ) {
344 Log(("Family for NIC %s : %d\n", IFI->Name.latin1(), 344 Log(("Family for NIC %s : %d\n", IFI->Name.latin1(),
345 ifrs.ifr_hwaddr.sa_family )); 345 ifrs.ifr_hwaddr.sa_family ));
346 346
347 IFI->CardType = ifrs.ifr_hwaddr.sa_family; 347 IFI->CardType = ifrs.ifr_hwaddr.sa_family;
348 switch( ifrs.ifr_hwaddr.sa_family ) { 348 switch( ifrs.ifr_hwaddr.sa_family ) {
349 case ARPHRD_ETHER : // regular MAC address 349 case ARPHRD_ETHER : // regular MAC address
350 // valid address -> convert to regular ::: format 350 // valid address -> convert to regular ::: format
351 // length = 6 bytes = 12 DIGITS -> 6 : 351 // length = 6 bytes = 12 DIGITS -> 6 :
352 IFI->MACAddress.sprintf( 352 IFI->MACAddress.sprintf(
353 "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c", 353 "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
354 HN( ifrs.ifr_hwaddr.sa_data[0] ), 354 HN( ifrs.ifr_hwaddr.sa_data[0] ),
355 LN( ifrs.ifr_hwaddr.sa_data[0] ), 355 LN( ifrs.ifr_hwaddr.sa_data[0] ),
356 HN( ifrs.ifr_hwaddr.sa_data[1] ), 356 HN( ifrs.ifr_hwaddr.sa_data[1] ),
357 LN( ifrs.ifr_hwaddr.sa_data[1] ), 357 LN( ifrs.ifr_hwaddr.sa_data[1] ),
358 HN( ifrs.ifr_hwaddr.sa_data[2] ), 358 HN( ifrs.ifr_hwaddr.sa_data[2] ),
359 LN( ifrs.ifr_hwaddr.sa_data[2] ), 359 LN( ifrs.ifr_hwaddr.sa_data[2] ),
360 HN( ifrs.ifr_hwaddr.sa_data[3] ), 360 HN( ifrs.ifr_hwaddr.sa_data[3] ),
361 LN( ifrs.ifr_hwaddr.sa_data[3] ), 361 LN( ifrs.ifr_hwaddr.sa_data[3] ),
362 HN( ifrs.ifr_hwaddr.sa_data[4] ), 362 HN( ifrs.ifr_hwaddr.sa_data[4] ),
363 LN( ifrs.ifr_hwaddr.sa_data[4] ), 363 LN( ifrs.ifr_hwaddr.sa_data[4] ),
364 HN( ifrs.ifr_hwaddr.sa_data[5] ), 364 HN( ifrs.ifr_hwaddr.sa_data[5] ),
365 LN( ifrs.ifr_hwaddr.sa_data[5] ) 365 LN( ifrs.ifr_hwaddr.sa_data[5] )
366 ); 366 );
367 break; 367 break;
368#ifdef ARPHRD_IEEE1394 368#ifdef ARPHRD_IEEE1394
369 case ARPHRD_IEEE1394 : // Firewire Eth address 369 case ARPHRD_IEEE1394 : // Firewire Eth address
370 IFI->MACAddress.sprintf( 370 IFI->MACAddress.sprintf(
371 "%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", 371 "%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",
372 HN( ifrs.ifr_hwaddr.sa_data[0] ), 372 HN( ifrs.ifr_hwaddr.sa_data[0] ),
373 LN( ifrs.ifr_hwaddr.sa_data[0] ), 373 LN( ifrs.ifr_hwaddr.sa_data[0] ),
374 HN( ifrs.ifr_hwaddr.sa_data[1] ), 374 HN( ifrs.ifr_hwaddr.sa_data[1] ),
375 LN( ifrs.ifr_hwaddr.sa_data[1] ), 375 LN( ifrs.ifr_hwaddr.sa_data[1] ),
376 HN( ifrs.ifr_hwaddr.sa_data[2] ), 376 HN( ifrs.ifr_hwaddr.sa_data[2] ),
377 LN( ifrs.ifr_hwaddr.sa_data[2] ), 377 LN( ifrs.ifr_hwaddr.sa_data[2] ),
378 HN( ifrs.ifr_hwaddr.sa_data[3] ), 378 HN( ifrs.ifr_hwaddr.sa_data[3] ),
379 LN( ifrs.ifr_hwaddr.sa_data[3] ), 379 LN( ifrs.ifr_hwaddr.sa_data[3] ),
380 HN( ifrs.ifr_hwaddr.sa_data[4] ), 380 HN( ifrs.ifr_hwaddr.sa_data[4] ),
381 LN( ifrs.ifr_hwaddr.sa_data[4] ), 381 LN( ifrs.ifr_hwaddr.sa_data[4] ),
382 HN( ifrs.ifr_hwaddr.sa_data[5] ), 382 HN( ifrs.ifr_hwaddr.sa_data[5] ),
383 LN( ifrs.ifr_hwaddr.sa_data[5] ), 383 LN( ifrs.ifr_hwaddr.sa_data[5] ),
384 HN( ifrs.ifr_hwaddr.sa_data[6] ), 384 HN( ifrs.ifr_hwaddr.sa_data[6] ),
385 LN( ifrs.ifr_hwaddr.sa_data[6] ), 385 LN( ifrs.ifr_hwaddr.sa_data[6] ),
386 HN( ifrs.ifr_hwaddr.sa_data[7] ), 386 HN( ifrs.ifr_hwaddr.sa_data[7] ),
387 LN( ifrs.ifr_hwaddr.sa_data[7] ), 387 LN( ifrs.ifr_hwaddr.sa_data[7] ),
388 HN( ifrs.ifr_hwaddr.sa_data[8] ), 388 HN( ifrs.ifr_hwaddr.sa_data[8] ),
389 LN( ifrs.ifr_hwaddr.sa_data[8] ), 389 LN( ifrs.ifr_hwaddr.sa_data[8] ),
390 HN( ifrs.ifr_hwaddr.sa_data[9] ), 390 HN( ifrs.ifr_hwaddr.sa_data[9] ),
391 LN( ifrs.ifr_hwaddr.sa_data[9] ), 391 LN( ifrs.ifr_hwaddr.sa_data[9] ),
392 HN( ifrs.ifr_hwaddr.sa_data[10] ), 392 HN( ifrs.ifr_hwaddr.sa_data[10] ),
393 LN( ifrs.ifr_hwaddr.sa_data[10] ), 393 LN( ifrs.ifr_hwaddr.sa_data[10] ),
394 HN( ifrs.ifr_hwaddr.sa_data[11] ), 394 HN( ifrs.ifr_hwaddr.sa_data[11] ),
395 LN( ifrs.ifr_hwaddr.sa_data[11] ), 395 LN( ifrs.ifr_hwaddr.sa_data[11] ),
396 HN( ifrs.ifr_hwaddr.sa_data[12] ), 396 HN( ifrs.ifr_hwaddr.sa_data[12] ),
397 LN( ifrs.ifr_hwaddr.sa_data[12] ), 397 LN( ifrs.ifr_hwaddr.sa_data[12] ),
398 HN( ifrs.ifr_hwaddr.sa_data[13] ), 398 HN( ifrs.ifr_hwaddr.sa_data[13] ),
399 LN( ifrs.ifr_hwaddr.sa_data[13] ) 399 LN( ifrs.ifr_hwaddr.sa_data[13] )
400 ); 400 );
401 break; 401 break;
402#endif 402#endif
403 case ARPHRD_PPP : // PPP 403 case ARPHRD_PPP : // PPP
404 break; 404 break;
405 case ARPHRD_IEEE80211 : // WLAN 405 case ARPHRD_IEEE80211 : // WLAN
406 break; 406 break;
407 case ARPHRD_IRDA : // IRDA 407 case ARPHRD_IRDA : // IRDA
408 break; 408 break;
409 } 409 }
410 } 410 }
411 } else // else already probed before -> just update 411 } else // else already probed before -> just update
412 Log(("Redetected NIC %s\n", NicName.latin1())); 412 Log(("Redetected NIC %s\n", NicName.latin1()));
413 413
414 // get dynamic info 414 // get dynamic info
415 if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) { 415 if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) {
416 IFI->IsUp = ((ifrs.ifr_flags & IFF_UP) == IFF_UP); 416 IFI->IsUp = ((ifrs.ifr_flags & IFF_UP) == IFF_UP);
417 IFI->HasMulticast = ((ifrs.ifr_flags & IFF_MULTICAST) == IFF_MULTICAST); 417 IFI->HasMulticast = ((ifrs.ifr_flags & IFF_MULTICAST) == IFF_MULTICAST);
418 } else { 418 } else {
419 IFI->IsUp = 0; 419 IFI->IsUp = 0;
420 IFI->HasMulticast = 0; 420 IFI->HasMulticast = 0;
421 } 421 }
422 422
423 if( ioctl(sockfd, SIOCGIFADDR, &ifrs) >= 0 ) { 423 if( ioctl(sockfd, SIOCGIFADDR, &ifrs) >= 0 ) {
424 IFI->Address = 424 IFI->Address =
425 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_addr)->sin_addr); 425 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_addr)->sin_addr);
426 } else { 426 } else {
427 IFI->Address = ""; 427 IFI->Address = "";
428 IFI->IsUp = 0; 428 IFI->IsUp = 0;
429 } 429 }
430 if( ioctl(sockfd, SIOCGIFBRDADDR, &ifrs) >= 0 ) { 430 if( ioctl(sockfd, SIOCGIFBRDADDR, &ifrs) >= 0 ) {
431 IFI->BCastAddress = 431 IFI->BCastAddress =
432 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_broadaddr)->sin_addr); 432 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_broadaddr)->sin_addr);
433 } else { 433 } else {
434 IFI->BCastAddress = ""; 434 IFI->BCastAddress = "";
435 } 435 }
436 if( ioctl(sockfd, SIOCGIFNETMASK, &ifrs) >= 0 ) { 436 if( ioctl(sockfd, SIOCGIFNETMASK, &ifrs) >= 0 ) {
437 IFI->Netmask = 437 IFI->Netmask =
438 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_netmask)->sin_addr); 438 inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_netmask)->sin_addr);
439 } else { 439 } else {
440 IFI->Netmask = ""; 440 IFI->Netmask = "";
441 } 441 }
442 Log(("NIC %s UP ? %d\n", NicName.latin1(), IFI->IsUp )); 442 Log(("NIC %s UP ? %d\n", NicName.latin1(), IFI->IsUp ));
443 } 443 }
444 444
445 ::close( sockfd ); 445 ::close( sockfd );
446} 446}
447 447
448InterfaceInfo * System::findInterface( const QString & N ) { 448InterfaceInfo * System::findInterface( const QString & N ) {
449 InterfaceInfo * Run; 449 InterfaceInfo * Run;
450 // has PAN connection UP interface ? 450 // has PAN connection UP interface ?
451 for( QDictIterator<InterfaceInfo> It(ProbedInterfaces); 451 for( QDictIterator<InterfaceInfo> It(ProbedInterfaces);
452 It.current(); 452 It.current();
453 ++It ) { 453 ++It ) {
454 Run = It.current(); 454 Run = It.current();
455 if( N == Run->Name ) { 455 if( N == Run->Name ) {
456 // this PAN connection is up 456 // this PAN connection is up
457 return Run; 457 return Run;
458 } 458 }
459 } 459 }
460 return 0; 460 return 0;
461} 461}
462 462
463#include <stdarg.h> 463#include <stdarg.h>
464static FILE * logf = 0; 464static FILE * logf = 0;
465 465
466void VLog( char * Format, ... ) { 466void VLog( char * Format, ... ) {
467 va_list l; 467 va_list l;
468 468
469 va_start(l, Format ); 469 va_start(l, Format );
470 470
471 if( logf == (FILE *)0 ) { 471 if( logf == (FILE *)0 ) {
472 QString S = getenv("NS2LOG"); 472 QString S = getenv("NS2LOG");
473 if( S == "stderr" ) { 473 if( S == "stderr" ) {
474 logf = stderr; 474 logf = stderr;
475 } else if( S.isEmpty() ) { 475 } else if( S.isEmpty() ) {
476 logf = fopen( "/tmp/ns2log", "a" ); 476 logf = fopen( "/tmp/ns2log", "a" );
477 } else { 477 } else {
478 logf = fopen( S, "a" ); 478 logf = fopen( S, "a" );
479 } 479 }
480 480
481 if( ! logf ) { 481 if( ! logf ) {
482 fprintf( stderr, "Cannot open logfile %s : %d\n", 482 fprintf( stderr, "Cannot open logfile %s : %d\n",
483 S.latin1(), errno ); 483 S.latin1(), errno );
484 logf = (FILE *)1; 484 logf = (FILE *)1;
485 } else { 485 } else {
486 fprintf( logf, "____ OPEN LOGFILE ____\n"); 486 fprintf( logf, "____ OPEN LOGFILE ____\n");
487 } 487 }
488 } 488 }
489 489
490 if( (unsigned long)logf > 1 ) { 490 if( (unsigned long)logf > 1 ) {
491 vfprintf( logf, Format, l ); 491 vfprintf( logf, Format, l );
492 } 492 }
493 va_end( l ); 493 va_end( l );
494 fflush( logf ); 494 fflush( logf );
495 495
496} 496}
497 497
498void LogClose( void ) { 498void LogClose( void ) {
499 if( (long)logf > 1 ) { 499 if( (long)logf > 1 ) {
500 fprintf( logf, "____ CLOSE LOGFILE ____\n"); 500 fprintf( logf, "____ CLOSE LOGFILE ____\n");
501 if( logf != stderr ) { 501 if( logf != stderr ) {
502 fclose( logf ); 502 fclose( logf );
503 } 503 }
504 logf = 0; 504 logf = 0;
505 } 505 }
506} 506}
507 507
508QString removeSpaces( const QString & X ) { 508QString removeSpaces( const QString & X ) {
509 QString Y; 509 QString Y;
510 Y = X.simplifyWhiteSpace(); 510 Y = X.simplifyWhiteSpace();
511 Y.replace( QRegExp(" "), "_" ); 511 Y.replace( QRegExp(" "), "_" );
512 owarn << X << " **" << Y << "**" << oendl; 512 odebug << X << " **" << Y << "**" << oendl;
513 return Y; 513 return Y;
514} 514}
515 515
516// 516//
517// 517//
518// 518//
519// 519//
520// 520//
521 521
522MyProcess::MyProcess() : QObject(), StdoutBuffer(), StderrBuffer() { 522MyProcess::MyProcess() : QObject(), StdoutBuffer(), StderrBuffer() {
523 P = new OProcess(); 523 P = new OProcess();
524 connect( P, 524 connect( P,
525 SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int ) ), 525 SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int ) ),
526 this, 526 this,
527 SLOT( SLOT_Stdout(Opie::Core::OProcess*,char*,int) ) ); 527 SLOT( SLOT_Stdout(Opie::Core::OProcess*,char*,int) ) );
528 528
529 connect( P, 529 connect( P,
530 SIGNAL( receivedStderr(Opie::Core::OProcess*, char*, int ) ), 530 SIGNAL( receivedStderr(Opie::Core::OProcess*, char*, int ) ),
531 this, 531 this,
532 SLOT( SLOT_Stderr(Opie::Core::OProcess*,char*,int) ) ); 532 SLOT( SLOT_Stderr(Opie::Core::OProcess*,char*,int) ) );
533 connect( P, 533 connect( P,
534 SIGNAL( processExited(Opie::Core::OProcess*) ), 534 SIGNAL( processExited(Opie::Core::OProcess*) ),
535 this, 535 this,
536 SLOT( SLOT_ProcessExited(Opie::Core::OProcess*) ) ); 536 SLOT( SLOT_ProcessExited(Opie::Core::OProcess*) ) );
537} 537}
538 538
539MyProcess::~MyProcess() { 539MyProcess::~MyProcess() {
540 delete P; 540 delete P;
541} 541}
542 542
543void MyProcess::SLOT_Stdout( Opie::Core::OProcess * , char * Buf, int len ) { 543void MyProcess::SLOT_Stdout( Opie::Core::OProcess * , char * Buf, int len ) {
544 char * LB = (char *)alloca( len + 1 ); 544 char * LB = (char *)alloca( len + 1 );
545 memcpy( LB, Buf, len ); 545 memcpy( LB, Buf, len );
546 LB[len] = '\0'; 546 LB[len] = '\0';
547 547
548 // now input is zero terminated 548 // now input is zero terminated
549 StdoutBuffer += LB; 549 StdoutBuffer += LB;
550 550
551 owarn << "Received " << len << " bytes on stdout" << oendl; 551 odebug << "Received " << len << " bytes on stdout" << oendl;
552 // see if we have some lines (allow empty lines) 552 // see if we have some lines (allow empty lines)
553 QStringList SL = QStringList::split( "\n", StdoutBuffer, TRUE ); 553 QStringList SL = QStringList::split( "\n", StdoutBuffer, TRUE );
554 554
555 for( unsigned int i = 0; i < SL.count()-1; i ++ ) { 555 for( unsigned int i = 0; i < SL.count()-1; i ++ ) {
556 Log(( "Stdout : \"%s\"\n", SL[i].latin1() ) ); 556 Log(( "Stdout : \"%s\"\n", SL[i].latin1() ) );
557 emit stdoutLine( SL[i] ); 557 emit stdoutLine( SL[i] );
558 } 558 }
559 559
560 // last line is rest 560 // last line is rest
561 StdoutBuffer = SL[ SL.count()-1 ]; 561 StdoutBuffer = SL[ SL.count()-1 ];
562} 562}
563 563
564void MyProcess::SLOT_Stderr( Opie::Core::OProcess * , char * Buf, int len ) { 564void MyProcess::SLOT_Stderr( Opie::Core::OProcess * , char * Buf, int len ) {
565 char * LB = (char *)alloca( len + 1 ); 565 char * LB = (char *)alloca( len + 1 );
566 memcpy( LB, Buf, len ); 566 memcpy( LB, Buf, len );
567 LB[len] = '\0'; 567 LB[len] = '\0';
568 568
569 // now input is zero terminated 569 // now input is zero terminated
570 StderrBuffer += LB; 570 StderrBuffer += LB;
571 571
572 owarn << "Received " << len << " bytes on stderr" << oendl; 572 odebug << "Received " << len << " bytes on stderr" << oendl;
573 // see if we have some lines (allow empty lines) 573 // see if we have some lines (allow empty lines)
574 QStringList SL = QStringList::split( "\n", StderrBuffer, TRUE ); 574 QStringList SL = QStringList::split( "\n", StderrBuffer, TRUE );
575 575
576 for( unsigned int i = 0; i < SL.count()-1; i ++ ) { 576 for( unsigned int i = 0; i < SL.count()-1; i ++ ) {
577 Log(( "Stderr : \"%s\"\n", SL[i].latin1() ) ); 577 Log(( "Stderr : \"%s\"\n", SL[i].latin1() ) );
578 emit stderrLine( SL[i] ); 578 emit stderrLine( SL[i] );
579 } 579 }
580 580
581 // last line is rest 581 // last line is rest
582 StderrBuffer = SL[ SL.count()-1 ]; 582 StderrBuffer = SL[ SL.count()-1 ];
583} 583}
584 584
585void MyProcess::SLOT_ProcessExited( Opie::Core::OProcess * ) { 585void MyProcess::SLOT_ProcessExited( Opie::Core::OProcess * ) {
586 emit processExited( this ); 586 emit processExited( this );
587} 587}
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
@@ -1,235 +1,235 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <qpe/qpeapplication.h> 2#include <qpe/qpeapplication.h>
3#include <qfileinfo.h> 3#include <qfileinfo.h>
4#include <qmessagebox.h> 4#include <qmessagebox.h>
5#include <qfile.h> 5#include <qfile.h>
6#include <qtextstream.h> 6#include <qtextstream.h>
7 7
8#include "resources.h" 8#include "resources.h"
9#include "systemfile.h" 9#include "systemfile.h"
10 10
11#define TEMPLATEDIR "NS2templates/" 11#define TEMPLATEDIR "NS2templates/"
12QString TemplDir; 12QString TemplDir;
13 13
14SystemFile::SystemFile( const QString & N, 14SystemFile::SystemFile( const QString & N,
15 const QString & P, 15 const QString & P,
16 bool KDI ){ 16 bool KDI ){
17 Name = N; 17 Name = N;
18 Path = P; 18 Path = P;
19 InAppend = 0; 19 InAppend = 0;
20 F = 0; 20 F = 0;
21 // get template info 21 // get template info
22 { QString S; 22 { QString S;
23 QFileInfo FI; 23 QFileInfo FI;
24 24
25 // find location of templates 25 // find location of templates
26 TemplDir = QPEApplication::qpeDir() + "etc/" + TEMPLATEDIR; 26 TemplDir = QPEApplication::qpeDir() + "etc/" + TEMPLATEDIR;
27 FI.setFile( TemplDir ); 27 FI.setFile( TemplDir );
28 if( ! FI.isDir() ) { 28 if( ! FI.isDir() ) {
29 // try current dir 29 // try current dir
30 TemplDir = "./" TEMPLATEDIR; 30 TemplDir = "./" TEMPLATEDIR;
31 FI.setFile( TemplDir ); 31 FI.setFile( TemplDir );
32 if( ! FI.isDir() ) { 32 if( ! FI.isDir() ) {
33 hasPreSection = 33 hasPreSection =
34 hasPostSection = 34 hasPostSection =
35 hasPreNodeSection = 35 hasPreNodeSection =
36 hasPostNodeSection = 36 hasPostNodeSection =
37 hasPreDeviceSection = 37 hasPreDeviceSection =
38 hasPostDeviceSection = 0; 38 hasPostDeviceSection = 0;
39 return; 39 return;
40 } 40 }
41 } 41 }
42 42
43 // have found location 43 // have found location
44 S = TemplDir + Name + "/presection"; 44 S = TemplDir + Name + "/presection";
45 FI.setFile( S ); 45 FI.setFile( S );
46 hasPreSection = ( FI.exists() && FI.isReadable() ); 46 hasPreSection = ( FI.exists() && FI.isReadable() );
47 S = TemplDir + Name + "/postsection"; 47 S = TemplDir + Name + "/postsection";
48 FI.setFile( S ); 48 FI.setFile( S );
49 hasPostSection = ( FI.exists() && FI.isReadable() ); 49 hasPostSection = ( FI.exists() && FI.isReadable() );
50 S = TemplDir + Name + "/prenodesection"; 50 S = TemplDir + Name + "/prenodesection";
51 FI.setFile( S ); 51 FI.setFile( S );
52 hasPreNodeSection = ( FI.exists() && FI.isReadable() ); 52 hasPreNodeSection = ( FI.exists() && FI.isReadable() );
53 S = TemplDir + Name + "/postnodesection"; 53 S = TemplDir + Name + "/postnodesection";
54 FI.setFile( S ); 54 FI.setFile( S );
55 hasPostNodeSection = ( FI.exists() && FI.isReadable() ); 55 hasPostNodeSection = ( FI.exists() && FI.isReadable() );
56 S = TemplDir + Name + "/predevicesection"; 56 S = TemplDir + Name + "/predevicesection";
57 FI.setFile( S ); 57 FI.setFile( S );
58 hasPreDeviceSection = ( FI.exists() && FI.isReadable() ); 58 hasPreDeviceSection = ( FI.exists() && FI.isReadable() );
59 S = TemplDir + Name + "/postdevicesection"; 59 S = TemplDir + Name + "/postdevicesection";
60 FI.setFile( S ); 60 FI.setFile( S );
61 hasPostDeviceSection = ( FI.exists() && FI.isReadable() ); 61 hasPostDeviceSection = ( FI.exists() && FI.isReadable() );
62 } 62 }
63 63
64 KnowsDeviceInstances = KDI; 64 KnowsDeviceInstances = KDI;
65} 65}
66 66
67SystemFile::SystemFile( const QString & N, bool KDI ){ 67SystemFile::SystemFile( const QString & N, bool KDI ){
68 Name = N; 68 Name = N;
69 Path = ""; 69 Path = "";
70 InAppend = 0; 70 InAppend = 0;
71 F =0; 71 F =0;
72 KnowsDeviceInstances = KDI; 72 KnowsDeviceInstances = KDI;
73 hasPreSection = 73 hasPreSection =
74 hasPostSection = 74 hasPostSection =
75 hasPreNodeSection = 75 hasPreNodeSection =
76 hasPostNodeSection = 76 hasPostNodeSection =
77 hasPreDeviceSection = 77 hasPreDeviceSection =
78 hasPostDeviceSection = 0; 78 hasPostDeviceSection = 0;
79} 79}
80 80
81SystemFile::~SystemFile( void ) { 81SystemFile::~SystemFile( void ) {
82 close(); 82 close();
83} 83}
84 84
85bool SystemFile::open( void ) { 85bool SystemFile::open( void ) {
86 QString Prefix = getenv( "NS2OUTPUTTO" ); 86 QString Prefix = getenv( "NS2OUTPUTTO" );
87 87
88 if( Prefix != "stderr" /* && Name != "interfaces" */ ) { 88 if( Prefix != "stderr" /* && Name != "interfaces" */ ) {
89 // generate files where the need to be 89 // generate files where the need to be
90 if( F ) { 90 if( F ) {
91 F->close(); 91 F->close();
92 delete F; 92 delete F;
93 } 93 }
94 94
95 F = new QFile( Prefix + Path + ((InAppend)?"":"bup") ); 95 F = new QFile( Prefix + Path + ((InAppend)?"":"bup") );
96 Log(( "Open systemfile %s\n", F->name().latin1() )); 96 Log(( "Open systemfile %s\n", F->name().latin1() ));
97 if( ! F->open( ((InAppend)?IO_Append : 0 ) | IO_WriteOnly ) ) { 97 if( ! F->open( ((InAppend)?IO_Append : 0 ) | IO_WriteOnly ) ) {
98 return 0; 98 return 0;
99 } 99 }
100 } else { 100 } else {
101 if( ! F ) { 101 if( ! F ) {
102 owarn << "!!!!!!!!!!!!!!!!!! " << oendl; 102 odebug << "!!!!!!!!!!!!!!!!!! " << oendl;
103 owarn << "!!!! TESTMODE !!!!" << oendl; 103 odebug << "!!!! TESTMODE !!!!" << oendl;
104 owarn << "!!!!!!!!!!!!!!!!!! " << oendl; 104 odebug << "!!!!!!!!!!!!!!!!!! " << oendl;
105 owarn << "!!!!" << oendl; 105 odebug << "!!!!" << oendl;
106 owarn << "!!!! GENERATE " << Path << oendl; 106 odebug << "!!!! GENERATE " << Path << oendl;
107 if( InAppend ) { 107 if( InAppend ) {
108 owarn << "!!!! In APPEND mode" << oendl; 108 odebug << "!!!! In APPEND mode" << oendl;
109 } 109 }
110 owarn << "!!!!" << oendl; 110 odebug << "!!!!" << oendl;
111 owarn << "!!!!!!!!!!!!!!!!!!" << oendl; 111 odebug << "!!!!!!!!!!!!!!!!!!" << oendl;
112 112
113 F = new QFile(); 113 F = new QFile();
114 F->open( IO_WriteOnly, stderr ); 114 F->open( IO_WriteOnly, stderr );
115 } 115 }
116 } 116 }
117 setDevice( F ); 117 setDevice( F );
118 return 1; 118 return 1;
119} 119}
120 120
121bool SystemFile::close( void ) { 121bool SystemFile::close( void ) {
122 if( ! F || ! F->isOpen() ) { 122 if( ! F || ! F->isOpen() ) {
123 return 1 ; 123 return 1 ;
124 } 124 }
125 125
126 QString Prefix = getenv( "NS2OUTPUTTO" ); 126 QString Prefix = getenv( "NS2OUTPUTTO" );
127 127
128 if( Prefix == "stderr" ) { 128 if( Prefix == "stderr" ) {
129 return 1; 129 return 1;
130 } 130 }
131 131
132 QString OldP = Prefix + Path + "bup"; 132 QString OldP = Prefix + Path + "bup";
133 133
134 F->close(); 134 F->close();
135 delete F; 135 delete F;
136 F = 0; 136 F = 0;
137 137
138 if( ! InAppend ) { 138 if( ! InAppend ) {
139 owarn << "Rename " << OldP << " to " << Path << oendl; 139 odebug << "Rename " << OldP << " to " << Path << oendl;
140 return ( rename( OldP.latin1(), Path.latin1() ) >= 0 ); 140 return ( rename( OldP.latin1(), Path.latin1() ) >= 0 );
141 } 141 }
142 return 1; 142 return 1;
143} 143}
144 144
145bool SystemFile::preSection( void ) { 145bool SystemFile::preSection( void ) {
146 if( hasPreSection ) { 146 if( hasPreSection ) {
147 QFile Fl( TemplDir + Name + "/presection" ); 147 QFile Fl( TemplDir + Name + "/presection" );
148 if( ! Fl.open( IO_ReadOnly ) ) 148 if( ! Fl.open( IO_ReadOnly ) )
149 return 0; // error 149 return 0; // error
150 // copy file to this file 150 // copy file to this file
151 F->writeBlock( Fl.readAll() ); 151 F->writeBlock( Fl.readAll() );
152 } 152 }
153 return 1; 153 return 1;
154} 154}
155 155
156bool SystemFile::postSection( void ) { 156bool SystemFile::postSection( void ) {
157 if( hasPostSection ) { 157 if( hasPostSection ) {
158 QFile Fl( TemplDir + Name + "/postsection" ); 158 QFile Fl( TemplDir + Name + "/postsection" );
159 if( ! Fl.open( IO_ReadOnly ) ) 159 if( ! Fl.open( IO_ReadOnly ) )
160 return 0; // error 160 return 0; // error
161 // copy file to this file 161 // copy file to this file
162 F->writeBlock( Fl.readAll() ); 162 F->writeBlock( Fl.readAll() );
163 } 163 }
164 return 1; 164 return 1;
165} 165}
166 166
167bool SystemFile::preNodeSection( ANetNodeInstance * NNI, long ) { 167bool SystemFile::preNodeSection( ANetNodeInstance * NNI, long ) {
168 if( hasPreNodeSection ) { 168 if( hasPreNodeSection ) {
169 QFile Fl( TemplDir + Name + "/prenodesection" ); 169 QFile Fl( TemplDir + Name + "/prenodesection" );
170 if( ! Fl.open( IO_ReadOnly ) ) 170 if( ! Fl.open( IO_ReadOnly ) )
171 return 0; // error 171 return 0; // error
172 QTextStream TX( &Fl ); 172 QTextStream TX( &Fl );
173 QString Out; 173 QString Out;
174 QString S = TX.readLine(); 174 QString S = TX.readLine();
175 while( ! TX.eof() ) { 175 while( ! TX.eof() ) {
176 Out = S. 176 Out = S.
177 arg(NNI->nodeClass()->name()); 177 arg(NNI->nodeClass()->name());
178 (*this) << Out << endl; 178 (*this) << Out << endl;
179 S = TX.readLine(); 179 S = TX.readLine();
180 } 180 }
181 } 181 }
182 return 1; 182 return 1;
183} 183}
184 184
185bool SystemFile::postNodeSection( ANetNodeInstance * NNI, long ) { 185bool SystemFile::postNodeSection( ANetNodeInstance * NNI, long ) {
186 if( hasPostNodeSection ) { 186 if( hasPostNodeSection ) {
187 QFile Fl( TemplDir + Name + "/postnodesection" ); 187 QFile Fl( TemplDir + Name + "/postnodesection" );
188 if( ! Fl.open( IO_ReadOnly ) ) 188 if( ! Fl.open( IO_ReadOnly ) )
189 return 0; // error 189 return 0; // error
190 QTextStream TX( &Fl ); 190 QTextStream TX( &Fl );
191 QString Out; 191 QString Out;
192 QString S = TX.readLine(); 192 QString S = TX.readLine();
193 while( ! TX.eof() ) { 193 while( ! TX.eof() ) {
194 Out = S. 194 Out = S.
195 arg(NNI->name()); 195 arg(NNI->name());
196 (*this) << Out << endl; 196 (*this) << Out << endl;
197 S = TX.readLine(); 197 S = TX.readLine();
198 } 198 }
199 } 199 }
200 return 1; 200 return 1;
201} 201}
202 202
203bool SystemFile::preDeviceSection( ANetNode * NN ) { 203bool SystemFile::preDeviceSection( ANetNode * NN ) {
204 if( hasPreDeviceSection ) { 204 if( hasPreDeviceSection ) {
205 QFile Fl( TemplDir + Name + "/predevicesection" ); 205 QFile Fl( TemplDir + Name + "/predevicesection" );
206 if( ! Fl.open( IO_ReadOnly ) ) 206 if( ! Fl.open( IO_ReadOnly ) )
207 return 0; // error 207 return 0; // error
208 QTextStream TX( &Fl ); 208 QTextStream TX( &Fl );
209 QString Out; 209 QString Out;
210 QString S = TX.readLine(); 210 QString S = TX.readLine();
211 while( ! TX.eof() ) { 211 while( ! TX.eof() ) {
212 Out = S.arg(NN->name()); 212 Out = S.arg(NN->name());
213 (*this) << Out << endl; 213 (*this) << Out << endl;
214 S = TX.readLine(); 214 S = TX.readLine();
215 } 215 }
216 } 216 }
217 return 1; 217 return 1;
218} 218}
219 219
220bool SystemFile::postDeviceSection( ANetNode * NN ) { 220bool SystemFile::postDeviceSection( ANetNode * NN ) {
221 if( hasPostDeviceSection ) { 221 if( hasPostDeviceSection ) {
222 QFile Fl( TemplDir + Name + "/postdevicesection" ); 222 QFile Fl( TemplDir + Name + "/postdevicesection" );
223 if( ! Fl.open( IO_ReadOnly ) ) 223 if( ! Fl.open( IO_ReadOnly ) )
224 return 0; // error 224 return 0; // error
225 QTextStream TX( &Fl ); 225 QTextStream TX( &Fl );
226 QString Out; 226 QString Out;
227 QString S = TX.readLine(); 227 QString S = TX.readLine();
228 while( ! TX.eof() ) { 228 while( ! TX.eof() ) {
229 Out = S.arg(NN->name()); 229 Out = S.arg(NN->name());
230 (*this) << Out << endl; 230 (*this) << Out << endl;
231 S = TX.readLine(); 231 S = TX.readLine();
232 } 232 }
233 } 233 }
234 return 1; 234 return 1;
235} 235}
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 @@
1#!/bin/sh 1#!/bin/sh
2 2
3QTPB=/opt/QtPalmtop/bin 3QTPB=/opt/QtPalmtop/bin
4 4
5[ ! -L ${QTPB}/networksettings2-request ] && ln -sf ${QTPB}/networksettings2 ${QTPB}/networksettings2-request 5[ ! -L ${QTPB}/networksettings2-request ] && ln -sf ${QTPB}/networksettings2 ${QTPB}/networksettings2-request
6 6
7qcop QPE/TaskBar "reloadApps()" 7${QTPB}/qcop QPE/TaskBar "reloadApps()"
8 8
9exit 0 9exit 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
@@ -1,256 +1,256 @@
1#include <qdir.h> 1#include <qdir.h>
2#include <qfileinfo.h> 2#include <qfileinfo.h>
3 3
4#include <bluezlib.h> 4#include <bluezlib.h>
5 5
6/* OPIE */ 6/* OPIE */
7#include <opie2/odevice.h> 7#include <opie2/odevice.h>
8#include <opie2/oprocess.h> 8#include <opie2/oprocess.h>
9#include <opie2/odebug.h> 9#include <opie2/odebug.h>
10 10
11#include <OTDevice.h> 11#include <OTDevice.h>
12 12
13using namespace Opie::Core; 13using namespace Opie::Core;
14using namespace Opietooth2; 14using namespace Opietooth2;
15using Opie::Core::OProcess; 15using Opie::Core::OProcess;
16 16
17OTDevice::OTDevice( OTGateway * _OT ) : QObject(0, "device") { 17OTDevice::OTDevice( OTGateway * _OT ) : QObject(0, "device") {
18 18
19 // initialize 19 // initialize
20 OT = _OT; 20 OT = _OT;
21 21
22 // detect bluetooth type 22 // detect bluetooth type
23 QString a, b; // fake 23 QString a, b; // fake
24 unsigned long c; // fake 24 unsigned long c; // fake
25 detectDeviceType( a, b, c ); 25 detectDeviceType( a, b, c );
26 26
27 if( needsAttach() ) { 27 if( needsAttach() ) {
28 // requires HCIATTACH 28 // requires HCIATTACH
29 // pid of hciattach 29 // pid of hciattach
30 m_hciattachPid = getPidOfHCIAttach(); 30 m_hciattachPid = getPidOfHCIAttach();
31 31
32 m_hciattach = 0; 32 m_hciattach = 0;
33 33
34 if( m_hciattachPid == 0 ) { 34 if( m_hciattachPid == 0 ) {
35 // no pid -> not attached 35 // no pid -> not attached
36 m_deviceNr = -1; 36 m_deviceNr = -1;
37 } else { 37 } else {
38 // system enabled 38 // system enabled
39 // currently no way to figure out which attach produce which 39 // currently no way to figure out which attach produce which
40 // hci 40 // hci
41 m_deviceNr = 0; 41 m_deviceNr = 0;
42 } 42 }
43 } else { 43 } else {
44 m_deviceNr = 0; 44 m_deviceNr = 0;
45 } 45 }
46} 46}
47 47
48OTDevice::~OTDevice(){ 48OTDevice::~OTDevice(){
49 if( needsAttach() && m_hciattach ) { 49 if( needsAttach() && m_hciattach ) {
50 // does not auto stop bluetooth 50 // does not auto stop bluetooth
51 m_hciattach->detach(); 51 m_hciattach->detach();
52 delete m_hciattach; 52 delete m_hciattach;
53 } 53 }
54} 54}
55 55
56bool OTDevice::attach(){ 56bool OTDevice::attach(){
57 57
58 if( needsAttach() && m_hciattachPid == 0 ) { 58 if( needsAttach() && m_hciattachPid == 0 ) {
59 QString Dev, Mode; 59 QString Dev, Mode;
60 unsigned long Spd; 60 unsigned long Spd;
61 61
62 detectDeviceType( Dev, Mode, Spd ); 62 detectDeviceType( Dev, Mode, Spd );
63 63
64 // not yet started 64 // not yet started
65 m_hciattach = new OProcess(); 65 m_hciattach = new OProcess();
66 *m_hciattach << "hciattach"; 66 *m_hciattach << "hciattach";
67 *m_hciattach << "-p"; // so that it prints its pid 67 *m_hciattach << "-p"; // so that it prints its pid
68 *m_hciattach << Dev 68 *m_hciattach << Dev
69 << Mode 69 << Mode
70 << QString().setNum(Spd); 70 << QString().setNum(Spd);
71 71
72 connect( m_hciattach, 72 connect( m_hciattach,
73 SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 73 SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
74 this, SLOT 74 this, SLOT
75 (slotStdOut(Opie::Core::OProcess*,char*,int) ) ); 75 (slotStdOut(Opie::Core::OProcess*,char*,int) ) );
76 76
77 connect( m_hciattach, 77 connect( m_hciattach,
78 SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), 78 SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ),
79 this, SLOT 79 this, SLOT
80 (slotStdErr(Opie::Core::OProcess*,char*,int) ) ); 80 (slotStdErr(Opie::Core::OProcess*,char*,int) ) );
81 81
82 // we need to start this in 'dontcare' mode because 82 // we need to start this in 'dontcare' mode because
83 // if qpe exists we want the hci to keep running 83 // if qpe exists we want the hci to keep running
84 if( ! m_hciattach->start( OProcess::DontCare, 84 if( ! m_hciattach->start( OProcess::DontCare,
85 OProcess::AllOutput 85 OProcess::AllOutput
86 ) ){ 86 ) ){
87 emit error( tr( "Could not start hciattach" ) ); 87 emit error( tr( "Could not start hciattach" ) );
88 delete m_hciattach; 88 delete m_hciattach;
89 m_hciattach = 0; 89 m_hciattach = 0;
90 return FALSE; 90 return FALSE;
91 } 91 }
92 } 92 }
93 93
94 return TRUE; 94 return TRUE;
95} 95}
96 96
97bool OTDevice::detach(){ 97bool OTDevice::detach(){
98 98
99 if( needsAttach() && m_hciattachPid ) { 99 if( needsAttach() && m_hciattachPid ) {
100 if( m_hciattach ) { 100 if( m_hciattach ) {
101 delete m_hciattach; 101 delete m_hciattach;
102 m_hciattach = 0; 102 m_hciattach = 0;
103 } 103 }
104 104
105 if( kill( m_hciattachPid, 9) < 0 ) { 105 if( kill( m_hciattachPid, 9) < 0 ) {
106 owarn << "could not stop " << errno << oendl; 106 odebug << "could not stop " << errno << oendl;
107 emit error( tr( "Could not stop process" ) ); 107 emit error( tr( "Could not stop process" ) );
108 return FALSE; 108 return FALSE;
109 } 109 }
110 m_hciattachPid = 0; 110 m_hciattachPid = 0;
111 emit isEnabled( m_deviceNr, 0 ); 111 emit isEnabled( m_deviceNr, 0 );
112 m_deviceNr = -1; 112 m_deviceNr = -1;
113 } 113 }
114 114
115 return TRUE; 115 return TRUE;
116} 116}
117 117
118bool OTDevice::isAttached()const{ 118bool OTDevice::isAttached()const{
119 return ! needsAttach() || m_hciattachPid != 0; 119 return ! needsAttach() || m_hciattachPid != 0;
120} 120}
121 121
122bool OTDevice::checkAttach(){ 122bool OTDevice::checkAttach(){
123 if( ! needsAttach() ) { 123 if( ! needsAttach() ) {
124 m_deviceNr = 0; 124 m_deviceNr = 0;
125 emit isEnabled( 0, 1 ); 125 emit isEnabled( 0, 1 );
126 return TRUE; 126 return TRUE;
127 } 127 }
128 128
129 if( m_hciattachPid ) { 129 if( m_hciattachPid ) {
130 QString S; 130 QString S;
131 S.setNum( m_hciattachPid ); 131 S.setNum( m_hciattachPid );
132 QDir D( "/proc" ); 132 QDir D( "/proc" );
133 if( !D.exists( S ) ) { 133 if( !D.exists( S ) ) {
134 // down 134 // down
135 m_hciattachPid = 0; 135 m_hciattachPid = 0;
136 emit isEnabled( m_deviceNr, 0 ); 136 emit isEnabled( m_deviceNr, 0 );
137 m_deviceNr = -1; 137 m_deviceNr = -1;
138 } 138 }
139 } else { 139 } else {
140 // check 140 // check
141 m_hciattachPid = getPidOfHCIAttach(); 141 m_hciattachPid = getPidOfHCIAttach();
142 if ( m_hciattachPid ) { 142 if ( m_hciattachPid ) {
143 m_deviceNr = 0; 143 m_deviceNr = 0;
144 emit isEnabled( m_deviceNr, 1 ); 144 emit isEnabled( m_deviceNr, 1 );
145 } 145 }
146 } 146 }
147 return m_hciattachPid != 0; 147 return m_hciattachPid != 0;
148} 148}
149 149
150void OTDevice::slotStdOut(OProcess* proc, char* , int ) { 150void OTDevice::slotStdOut(OProcess* proc, char* , int ) {
151 if( proc == m_hciattach ) { 151 if( proc == m_hciattach ) {
152 m_hciattach->detach(); 152 m_hciattach->detach();
153 153
154 // system enabled 154 // system enabled
155 // currently no way to figure out which attach produce which 155 // currently no way to figure out which attach produce which
156 // hci 156 // hci
157 if( m_deviceNr == -1 ) { 157 if( m_deviceNr == -1 ) {
158 m_deviceNr = 0; 158 m_deviceNr = 0;
159 emit isEnabled( m_deviceNr, 1 ); 159 emit isEnabled( m_deviceNr, 1 );
160 } 160 }
161 } 161 }
162} 162}
163 163
164void OTDevice::slotStdErr(OProcess* proc, char* chars, int len) { 164void OTDevice::slotStdErr(OProcess* proc, char* chars, int len) {
165 165
166 if(proc == m_hciattach && len >= 1 ){ 166 if(proc == m_hciattach && len >= 1 ){
167 // collect output 167 // collect output
168 QCString string( chars, len+1 ); // \0 == +1 168 QCString string( chars, len+1 ); // \0 == +1
169 QString m_output; 169 QString m_output;
170 m_output.append( string.data() ); 170 m_output.append( string.data() );
171 owarn << m_output << oendl; 171 odebug << m_output << oendl;
172 } 172 }
173} 173}
174 174
175pid_t OTDevice::getPidOfHCIAttach( void ) { 175pid_t OTDevice::getPidOfHCIAttach( void ) {
176 176
177 if( needsAttach() ) { 177 if( needsAttach() ) {
178 // not yet attached -> perhaps now ? 178 // not yet attached -> perhaps now ?
179 // load /proc dir and check if command name contains hciattach 179 // load /proc dir and check if command name contains hciattach
180 QRegExp R("[0-9]+"); 180 QRegExp R("[0-9]+");
181 QDir ProcDir( "/proc" ); 181 QDir ProcDir( "/proc" );
182 QFileInfo FI; 182 QFileInfo FI;
183 QStringList EL = ProcDir.entryList( QDir::Dirs ); 183 QStringList EL = ProcDir.entryList( QDir::Dirs );
184 184
185 // print it out 185 // print it out
186 for ( QStringList::Iterator it = EL.begin(); 186 for ( QStringList::Iterator it = EL.begin();
187 it != EL.end(); 187 it != EL.end();
188 ++it ) { 188 ++it ) {
189 if( R.match( (*it) ) >= 0 ) { 189 if( R.match( (*it) ) >= 0 ) {
190 // is pid 190 // is pid
191 191
192 // get command being executed 192 // get command being executed
193 FI.setFile( ProcDir.path()+"/"+ (*it) + "/exe" ); 193 FI.setFile( ProcDir.path()+"/"+ (*it) + "/exe" );
194 194
195 // get the link 195 // get the link
196 if( FI.readLink().right( 9 ) == "hciattach" ) { 196 if( FI.readLink().right( 9 ) == "hciattach" ) {
197 // this is hci attach process 197 // this is hci attach process
198 198
199 return (*it).toULong(); 199 return (*it).toULong();
200 break; 200 break;
201 } 201 }
202 } 202 }
203 } 203 }
204 } 204 }
205 205
206 return 0; 206 return 0;
207} 207}
208 208
209void OTDevice::detectDeviceType( QString & Device, 209void OTDevice::detectDeviceType( QString & Device,
210 QString & Mode, 210 QString & Mode,
211 unsigned long & Speed ) { 211 unsigned long & Speed ) {
212 212
213 // detect device type and determine parms 213 // detect device type and determine parms
214 owarn << "Detecting device" << oendl; 214 odebug << "Detecting device" << oendl;
215 switch ( ODevice::inst()->model() ) { 215 switch ( ODevice::inst()->model() ) {
216 case Model_iPAQ_H39xx: 216 case Model_iPAQ_H39xx:
217 Device = "/dev/tts/1"; 217 Device = "/dev/tts/1";
218 Mode = "bcsp"; 218 Mode = "bcsp";
219 Speed = 921600; 219 Speed = 921600;
220 NeedsAttach = 1; 220 NeedsAttach = 1;
221 break; 221 break;
222 222
223 case Model_iPAQ_H5xxx: 223 case Model_iPAQ_H5xxx:
224 Device = "/dev/tts/1"; 224 Device = "/dev/tts/1";
225 Mode = "any"; 225 Mode = "any";
226 Speed = 921600; 226 Speed = 921600;
227 NeedsAttach = 1; 227 NeedsAttach = 1;
228 break; 228 break;
229 229
230 case Model_GenuineIntel : 230 case Model_GenuineIntel :
231 Device = ""; 231 Device = "";
232 Mode = ""; 232 Mode = "";
233 Speed = 0; 233 Speed = 0;
234 NeedsAttach = 0; 234 NeedsAttach = 0;
235 break; 235 break;
236 236
237 default: 237 default:
238 Device = "/dev/ttySB0"; 238 Device = "/dev/ttySB0";
239 Mode = "bcsp"; 239 Mode = "bcsp";
240 Speed = 230400; 240 Speed = 230400;
241 NeedsAttach = 1; 241 NeedsAttach = 1;
242 break; 242 break;
243 } 243 }
244} 244}
245 245
246QString OTDevice::getRFCommDevicePattern( void ) { 246QString OTDevice::getRFCommDevicePattern( void ) {
247 247
248 QDir D( "/dev/bluetooth/rfcomm" ); 248 QDir D( "/dev/bluetooth/rfcomm" );
249 if( D.exists() ) { 249 if( D.exists() ) {
250 // devfs 250 // devfs
251 return QString( "/dev/bluetooth/rfcomm/%1" ); 251 return QString( "/dev/bluetooth/rfcomm/%1" );
252 } 252 }
253 253
254 // regular 'dev' directory 254 // regular 'dev' directory
255 return QString( "/dev/rfcomm%1" ); 255 return QString( "/dev/rfcomm%1" );
256} 256}
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
@@ -1,744 +1,744 @@
1/*************************************************************************** 1/***************************************************************************
2 * Copyright (C) 2003 by Mattia Merzi * 2 * Copyright (C) 2003 by Mattia Merzi *
3 * ottobit@ferrara.linux.it * 3 * ottobit@ferrara.linux.it *
4 * * 4 * *
5 * This program is free software; you can redistribute it and/or modify * 5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by * 6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or * 7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. * 8 * (at your option) any later version. *
9 ***************************************************************************/ 9 ***************************************************************************/
10 10
11#include <opie2/odebug.h> 11#include <opie2/odebug.h>
12#include <qtimer.h> 12#include <qtimer.h>
13 13
14#include <sys/poll.h> 14#include <sys/poll.h>
15#include <bluezlib.h> 15#include <bluezlib.h>
16 16
17#include <OTGateway.h> 17#include <OTGateway.h>
18#include <OTDriver.h> 18#include <OTDriver.h>
19#include <OTHCISocket.h> 19#include <OTHCISocket.h>
20 20
21using namespace Opietooth2; 21using namespace Opietooth2;
22 22
23static struct { 23static struct {
24 const char *str; 24 const char *str;
25 unsigned short rev; 25 unsigned short rev;
26} csr_map[] = { 26} csr_map[] = {
27 { "HCI 11.2 (bc01b)", 114 }, 27 { "HCI 11.2 (bc01b)", 114 },
28 { "HCI 11.3 (bc01b)", 115 }, 28 { "HCI 11.3 (bc01b)", 115 },
29 { "HCI 12.1 (bc01b)", 119 }, 29 { "HCI 12.1 (bc01b)", 119 },
30 { "HCI 12.3 (bc01b)", 134 }, 30 { "HCI 12.3 (bc01b)", 134 },
31 { "HCI 12.7 (bc01b)", 188 }, 31 { "HCI 12.7 (bc01b)", 188 },
32 { "HCI 12.8 (bc01b)", 218 }, 32 { "HCI 12.8 (bc01b)", 218 },
33 { "HCI 12.9 (bc01b)", 283 }, 33 { "HCI 12.9 (bc01b)", 283 },
34 { "HCI 13.10 (bc01b)", 309 }, 34 { "HCI 13.10 (bc01b)", 309 },
35 { "HCI 13.11 (bc01b)", 351 }, 35 { "HCI 13.11 (bc01b)", 351 },
36 { "HCI 16.4 (bc01b)", 523 }, 36 { "HCI 16.4 (bc01b)", 523 },
37 { "HCI 14.3 (bc02x)", 272 }, 37 { "HCI 14.3 (bc02x)", 272 },
38 { "HCI 14.6 (bc02x)", 336 }, 38 { "HCI 14.6 (bc02x)", 336 },
39 { "HCI 14.7 (bc02x)", 373 }, 39 { "HCI 14.7 (bc02x)", 373 },
40 { "HCI 14.8 (bc02x)", 487 }, 40 { "HCI 14.8 (bc02x)", 487 },
41 { "HCI 15.3 (bc02x)", 443 }, 41 { "HCI 15.3 (bc02x)", 443 },
42 { "HCI 16.4 (bc02x)", 525 }, 42 { "HCI 16.4 (bc02x)", 525 },
43 { NULL, 0} 43 { NULL, 0}
44}; 44};
45 45
46static char *services[] = { "Positioning", 46static char *services[] = { "Positioning",
47 "Networking", 47 "Networking",
48 "Rendering", 48 "Rendering",
49 "Capturing", 49 "Capturing",
50 "Object Transfer", 50 "Object Transfer",
51 "Audio", 51 "Audio",
52 "Telephony", 52 "Telephony",
53 "Information" }; 53 "Information" };
54 54
55static char *major_devices[] = { "Miscellaneous", 55static char *major_devices[] = { "Miscellaneous",
56 "Computer", 56 "Computer",
57 "Phone", 57 "Phone",
58 "LAN Access", 58 "LAN Access",
59 "Audio/Video", 59 "Audio/Video",
60 "Peripheral", 60 "Peripheral",
61 "Imaging", 61 "Imaging",
62 "Uncategorized" }; 62 "Uncategorized" };
63 63
64 64
65typedef struct { 65typedef struct {
66 short Minor; 66 short Minor;
67 const char * Description; 67 const char * Description;
68} ClassMap_t; 68} ClassMap_t;
69 69
70static ClassMap_t MapMiscClass[] = { 70static ClassMap_t MapMiscClass[] = {
71 { -1, "" } 71 { -1, "" }
72}; 72};
73 73
74static ClassMap_t MapUnclassifiedClass[] = { 74static ClassMap_t MapUnclassifiedClass[] = {
75 { -1, "" } 75 { -1, "" }
76}; 76};
77 77
78static ClassMap_t MapComputerClass[] = { 78static ClassMap_t MapComputerClass[] = {
79 { 0, "Uncategorized" } , 79 { 0, "Uncategorized" } ,
80 { 1, "Desktop workstation" } , 80 { 1, "Desktop workstation" } ,
81 { 2, "Server" } , 81 { 2, "Server" } ,
82 { 3, "Laptop" } , 82 { 3, "Laptop" } ,
83 { 4, "Handheld" } , 83 { 4, "Handheld" } ,
84 { 5, "Palm" } , 84 { 5, "Palm" } ,
85 { 6, "Wearable" }, 85 { 6, "Wearable" },
86 { -1, 0 } 86 { -1, 0 }
87}; 87};
88 88
89static ClassMap_t MapPhoneClass[] = { 89static ClassMap_t MapPhoneClass[] = {
90 { 0, "Uncategorized" }, 90 { 0, "Uncategorized" },
91 { 1, "Cellular" }, 91 { 1, "Cellular" },
92 { 2, "Cordless" }, 92 { 2, "Cordless" },
93 { 3, "Smart phone" }, 93 { 3, "Smart phone" },
94 { 4, "Wired modem or voice gateway" }, 94 { 4, "Wired modem or voice gateway" },
95 { 5, "Common ISDN Access" }, 95 { 5, "Common ISDN Access" },
96 { 6, "Sim Card Reader" }, 96 { 6, "Sim Card Reader" },
97 { -1, 0 } 97 { -1, 0 }
98}; 98};
99 99
100static ClassMap_t MapAVClass[] = { 100static ClassMap_t MapAVClass[] = {
101 { 0, "Uncategorized" }, 101 { 0, "Uncategorized" },
102 { 1, "Device conforms to the Headset profile" }, 102 { 1, "Device conforms to the Headset profile" },
103 { 2, "Hands-free" }, 103 { 2, "Hands-free" },
104 { 3, 0 }, 104 { 3, 0 },
105 { 4, "Microphone" }, 105 { 4, "Microphone" },
106 { 5, "Loudspeaker" }, 106 { 5, "Loudspeaker" },
107 { 6, "Headphones" }, 107 { 6, "Headphones" },
108 { 7, "Portable Audio" }, 108 { 7, "Portable Audio" },
109 { 8, "Car Audio" }, 109 { 8, "Car Audio" },
110 { 9, "Set-top box" }, 110 { 9, "Set-top box" },
111 { 10, "HiFi Audio Device" }, 111 { 10, "HiFi Audio Device" },
112 { 11, "VCR" }, 112 { 11, "VCR" },
113 { 12, "Video Camera" }, 113 { 12, "Video Camera" },
114 { 13, "Camcorder" }, 114 { 13, "Camcorder" },
115 { 14, "Video Monitor" }, 115 { 14, "Video Monitor" },
116 { 15, "Video Display and Loudspeaker" }, 116 { 15, "Video Display and Loudspeaker" },
117 { 16, "Video Conferencing" }, 117 { 16, "Video Conferencing" },
118 { 17, 0 }, 118 { 17, 0 },
119 { 18, "Gaming/Toy" }, 119 { 18, "Gaming/Toy" },
120 { -1, 0 } 120 { -1, 0 }
121}; 121};
122 122
123static ClassMap_t MapPeripheralClass[] = { 123static ClassMap_t MapPeripheralClass[] = {
124 { 16, "Keyboard" }, 124 { 16, "Keyboard" },
125 { 32, "Pointing device" }, 125 { 32, "Pointing device" },
126 { 48, "Combo keyboard/pointing device" }, 126 { 48, "Combo keyboard/pointing device" },
127 { -1, 0 } 127 { -1, 0 }
128}; 128};
129 129
130typedef struct { 130typedef struct {
131 int Major; 131 int Major;
132 ClassMap_t * Map; 132 ClassMap_t * Map;
133} MainClassMap_t; 133} MainClassMap_t;
134 134
135static MainClassMap_t MainClasses[] = { 135static MainClassMap_t MainClasses[] = {
136 { 0, MapMiscClass }, 136 { 0, MapMiscClass },
137 { 1, MapComputerClass }, 137 { 1, MapComputerClass },
138 { 2, MapPhoneClass }, 138 { 2, MapPhoneClass },
139 { 3, 0 }, // special case 139 { 3, 0 }, // special case
140 { 4, MapAVClass }, 140 { 4, MapAVClass },
141 { 5, MapPeripheralClass }, 141 { 5, MapPeripheralClass },
142 { 6, 0 }, // special case 142 { 6, 0 }, // special case
143 { 63, MapUnclassifiedClass }, 143 { 63, MapUnclassifiedClass },
144 { -1, 0 } 144 { -1, 0 }
145}; 145};
146 146
147OTDriver::OTDriver( OTGateway * _OT, struct hci_dev_info* di) : QObject( _OT ), Address() { 147OTDriver::OTDriver( OTGateway * _OT, struct hci_dev_info* di) : QObject( _OT ), Address() {
148 OT = _OT; 148 OT = _OT;
149 IsUp = 0; 149 IsUp = 0;
150 Socket = 0; 150 Socket = 0;
151 151
152 init(di); 152 init(di);
153 owarn << "Driver " << devname() << oendl; 153 odebug << "Driver " << devname() << oendl;
154 154
155 AutoClose = new QTimer( this ); 155 AutoClose = new QTimer( this );
156 connect( AutoClose, 156 connect( AutoClose,
157 SIGNAL( timeout() ), 157 SIGNAL( timeout() ),
158 this, 158 this,
159 SLOT( SLOT_CloseFd() ) 159 SLOT( SLOT_CloseFd() )
160 ); 160 );
161} 161}
162 162
163OTDriver::~OTDriver() { 163OTDriver::~OTDriver() {
164 closeSocket(); 164 closeSocket();
165 SLOT_CloseFd(); 165 SLOT_CloseFd();
166} 166}
167 167
168void OTDriver::SLOT_CloseFd( void ){ 168void OTDriver::SLOT_CloseFd( void ){
169 if ( isOpen() ) { 169 if ( isOpen() ) {
170 AutoClose->stop(); 170 AutoClose->stop();
171 ::close( fd() ); 171 ::close( fd() );
172 setfd( -1 ); 172 setfd( -1 );
173 } 173 }
174} 174}
175 175
176void OTDriver::init(struct hci_dev_info* di) { 176void OTDriver::init(struct hci_dev_info* di) {
177 177
178 Dev = di->name; 178 Dev = di->name;
179 179
180 setDevId(di->dev_id); 180 setDevId(di->dev_id);
181 setType(di->type); 181 setType(di->type);
182 setFlags(di->flags); 182 setFlags(di->flags);
183 Address.setBDAddr( di->bdaddr ); 183 Address.setBDAddr( di->bdaddr );
184 setFeatures(di->features); 184 setFeatures(di->features);
185 setfd( -1 ); // not open 185 setfd( -1 ); // not open
186 186
187 Manufacturer = ""; 187 Manufacturer = "";
188} 188}
189 189
190// internal reinitialize 190// internal reinitialize
191void OTDriver::reinit() { 191void OTDriver::reinit() {
192 bool Old; 192 bool Old;
193 Old = IsUp; 193 Old = IsUp;
194 194
195 if( currentState() < 0 ) 195 if( currentState() < 0 )
196 return; 196 return;
197 197
198 if( Old != IsUp ) { 198 if( Old != IsUp ) {
199 // state changes 199 // state changes
200 emit stateChange( this, IsUp ); 200 emit stateChange( this, IsUp );
201 } 201 }
202} 202}
203 203
204// requested by application 204// requested by application
205int OTDriver::currentState() { 205int OTDriver::currentState() {
206 struct hci_dev_info di; 206 struct hci_dev_info di;
207 207
208 // uint16_t tmp_dev_id = device_info.dev_id; 208 // uint16_t tmp_dev_id = device_info.dev_id;
209 // bzero(&device_info,sizeof(struct hci_dev_info)); 209 // bzero(&device_info,sizeof(struct hci_dev_info));
210 // device_info.dev_id = tmp_dev_id; 210 // device_info.dev_id = tmp_dev_id;
211 211
212 memset( &di, 0, sizeof( di ) ); 212 memset( &di, 0, sizeof( di ) );
213 di.dev_id = Dev_id; 213 di.dev_id = Dev_id;
214 if( ioctl( OT->getSocket(), HCIGETDEVINFO, (void*)&di) < 0 ) { 214 if( ioctl( OT->getSocket(), HCIGETDEVINFO, (void*)&di) < 0 ) {
215 SLOT_CloseFd(); 215 SLOT_CloseFd();
216 return -1; 216 return -1;
217 } else { 217 } else {
218 // load new info 218 // load new info
219 init(&di); 219 init(&di);
220 } 220 }
221 221
222 return IsUp; 222 return IsUp;
223} 223}
224 224
225bool OTDriver::open() { 225bool OTDriver::open() {
226 226
227 // (re)start single shot close 227 // (re)start single shot close
228 AutoClose->start( 30000, TRUE ); 228 AutoClose->start( 30000, TRUE );
229 229
230 if( isOpen() ) 230 if( isOpen() )
231 // is open 231 // is open
232 return 1; 232 return 1;
233 233
234 setfd(hci_open_dev(devId())); 234 setfd(hci_open_dev(devId()));
235 235
236 if (fd() < 0) { 236 if (fd() < 0) {
237 emit error( tr( "Can't open device %1. %2 : %3" ). 237 emit error( tr( "Can't open device %1. %2 : %3" ).
238 arg( devname() ). 238 arg( devname() ).
239 arg( errno ). 239 arg( errno ).
240 arg( strerror(errno) ) 240 arg( strerror(errno) )
241 ); 241 );
242 return 0; 242 return 0;
243 } 243 }
244 244
245 return 1; 245 return 1;
246} 246}
247 247
248QString OTDriver::name() { 248QString OTDriver::name() {
249 char name[1000]; 249 char name[1000];
250 250
251 if( ! open() ) { 251 if( ! open() ) {
252 return tr("Cannot open"); 252 return tr("Cannot open");
253 } 253 }
254 254
255 if (hci_read_local_name( fd(), sizeof(name), name, 1000) < 0) { 255 if (hci_read_local_name( fd(), sizeof(name), name, 1000) < 0) {
256 if (errno != ETIMEDOUT) { 256 if (errno != ETIMEDOUT) {
257 emit error( tr("Can't read local name on %1. %2 : %3. Default to %4" ). 257 emit error( tr("Can't read local name on %1. %2 : %3. Default to %4" ).
258 arg( devname() ). 258 arg( devname() ).
259 arg( errno ). 259 arg( errno ).
260 arg( strerror(errno) ). 260 arg( strerror(errno) ).
261 arg( devname() ) 261 arg( devname() )
262 ); 262 );
263 } // ETIMEDOUT error is quite normal, device is down ... I think ! :) 263 } // ETIMEDOUT error is quite normal, device is down ... I think ! :)
264 strcpy(name,devname().latin1()); 264 strcpy(name,devname().latin1());
265 } 265 }
266 return QString(name); 266 return QString(name);
267} 267}
268 268
269void OTDriver::setFlags(unsigned long flags) { 269void OTDriver::setFlags(unsigned long flags) {
270 270
271 // kdDebug() << "Setting OTDriver Values ..." << endl; 271 // kdDebug() << "Setting OTDriver Values ..." << endl;
272 IsUp = BTVALUE(hci_test_bit(HCI_UP, &flags)); 272 IsUp = BTVALUE(hci_test_bit(HCI_UP, &flags));
273 273
274 if (isUp()) { 274 if (isUp()) {
275 setIScan(BTVALUE(hci_test_bit(HCI_ISCAN, &flags))); 275 setIScan(BTVALUE(hci_test_bit(HCI_ISCAN, &flags)));
276 setPScan(BTVALUE(hci_test_bit(HCI_PSCAN, &flags))); 276 setPScan(BTVALUE(hci_test_bit(HCI_PSCAN, &flags)));
277 setAuthentication(BTVALUE(hci_test_bit(HCI_AUTH, &flags))); 277 setAuthentication(BTVALUE(hci_test_bit(HCI_AUTH, &flags)));
278 setEncryption(BTVALUE(hci_test_bit(HCI_ENCRYPT, &flags))); 278 setEncryption(BTVALUE(hci_test_bit(HCI_ENCRYPT, &flags)));
279 } else { 279 } else {
280 setIScan(BT_UNKNOWN); 280 setIScan(BT_UNKNOWN);
281 setPScan(BT_UNKNOWN); 281 setPScan(BT_UNKNOWN);
282 setAuthentication(BT_UNKNOWN); 282 setAuthentication(BT_UNKNOWN);
283 setEncryption(BT_UNKNOWN); 283 setEncryption(BT_UNKNOWN);
284 } 284 }
285} 285}
286 286
287QString OTDriver::revision() { 287QString OTDriver::revision() {
288 288
289 struct hci_version ver; 289 struct hci_version ver;
290 290
291 if( ! open() ) { 291 if( ! open() ) {
292 return tr("Cannot open"); 292 return tr("Cannot open");
293 } 293 }
294 294
295 if (hci_read_local_version(fd(), &ver, 1000) < 0) { 295 if (hci_read_local_version(fd(), &ver, 1000) < 0) {
296 emit error( tr( "Can't read revision info on %1. %2 : %3" ). 296 emit error( tr( "Can't read revision info on %1. %2 : %3" ).
297 arg( devname() ). 297 arg( devname() ).
298 arg( errno ). 298 arg( errno ).
299 arg( strerror(errno) ) ); 299 arg( strerror(errno) ) );
300 return QString(); 300 return QString();
301 } 301 }
302 302
303 setManufacturer(ver.manufacturer); 303 setManufacturer(ver.manufacturer);
304 304
305 switch (ver.manufacturer) { 305 switch (ver.manufacturer) {
306 case 0: 306 case 0:
307 return getRevEricsson(); 307 return getRevEricsson();
308 break; 308 break;
309 case 10: 309 case 10:
310 return getRevCsr(ver.hci_rev); 310 return getRevCsr(ver.hci_rev);
311 break; 311 break;
312 default: 312 default:
313 return tr( "Unsupported manufacturer" ); 313 return tr( "Unsupported manufacturer" );
314 break; 314 break;
315 } 315 }
316} 316}
317 317
318QString OTDriver::getRevEricsson() { 318QString OTDriver::getRevEricsson() {
319 319
320 char revision[102]; 320 char revision[102];
321 struct hci_request rq; 321 struct hci_request rq;
322 322
323 if( ! open() ) { 323 if( ! open() ) {
324 return QString( "Cannot open" ); 324 return QString( "Cannot open" );
325 } 325 }
326 326
327 memset(&rq, 0, sizeof(rq)); 327 memset(&rq, 0, sizeof(rq));
328 rq.ogf = 0x3f; 328 rq.ogf = 0x3f;
329 rq.ocf = 0x000f; 329 rq.ocf = 0x000f;
330 rq.cparam = NULL; 330 rq.cparam = NULL;
331 rq.clen = 0; 331 rq.clen = 0;
332 rq.rparam = &revision; 332 rq.rparam = &revision;
333 rq.rlen = sizeof(revision); 333 rq.rlen = sizeof(revision);
334 334
335 if (hci_send_req(fd(), &rq, 1000) < 0) { 335 if (hci_send_req(fd(), &rq, 1000) < 0) {
336 emit error( tr( "Can't read revision info on %1. %2 : %3" ). 336 emit error( tr( "Can't read revision info on %1. %2 : %3" ).
337 arg( devname() ). 337 arg( devname() ).
338 arg( errno ). 338 arg( errno ).
339 arg( strerror(errno) ) ); 339 arg( strerror(errno) ) );
340 return QString(); 340 return QString();
341 } 341 }
342 342
343 return QString( revision+1 ); 343 return QString( revision+1 );
344} 344}
345 345
346QString OTDriver::getRevCsr( unsigned short rev) { 346QString OTDriver::getRevCsr( unsigned short rev) {
347 347
348 int i; 348 int i;
349 349
350 for (i = 0; csr_map[i].str; i++) 350 for (i = 0; csr_map[i].str; i++)
351 if (csr_map[i].rev == rev) { 351 if (csr_map[i].rev == rev) {
352 return QString( csr_map[i].str ); 352 return QString( csr_map[i].str );
353 } 353 }
354 354
355 return tr( "Unknown firmware" ); 355 return tr( "Unknown firmware" );
356} 356}
357 357
358int OTDriver::reset() { 358int OTDriver::reset() {
359 359
360 if( ! open() ) { 360 if( ! open() ) {
361 return 0; 361 return 0;
362 } 362 }
363 363
364 if( ioctl(fd(), HCIDEVRESET, devId()) < 0 ) { 364 if( ioctl(fd(), HCIDEVRESET, devId()) < 0 ) {
365 if( errno != EALREADY ) { 365 if( errno != EALREADY ) {
366 emit error( tr( "Reset failed for %1. %2 : %3" ). 366 emit error( tr( "Reset failed for %1. %2 : %3" ).
367 arg( devname() ). 367 arg( devname() ).
368 arg( errno ). 368 arg( errno ).
369 arg( strerror(errno) ) ); 369 arg( strerror(errno) ) );
370 if (errno == EACCES) { 370 if (errno == EACCES) {
371 return EACCES; 371 return EACCES;
372 } 372 }
373 } 373 }
374 } 374 }
375 return 0; 375 return 0;
376} 376}
377 377
378void OTDriver::setUp( bool M ) { 378void OTDriver::setUp( bool M ) {
379 if( M && ! isUp() ) { 379 if( M && ! isUp() ) {
380 bringUp(); 380 bringUp();
381 } else if( ! M && isUp() ) { 381 } else if( ! M && isUp() ) {
382 bringDown(); 382 bringDown();
383 } 383 }
384} 384}
385 385
386void OTDriver::bringUp() { 386void OTDriver::bringUp() {
387 387
388 owarn << "bringUp : " << Dev << oendl; 388 odebug << "bringUp : " << Dev << oendl;
389 389
390 if( ! open() ) { 390 if( ! open() ) {
391 return; 391 return;
392 } 392 }
393 393
394 if (! isUp()) { 394 if (! isUp()) {
395 if( ioctl(fd(), HCIDEVUP, devId()) < 0 ) { 395 if( ioctl(fd(), HCIDEVUP, devId()) < 0 ) {
396 if( errno != EALREADY ) { 396 if( errno != EALREADY ) {
397 emit error( tr( "Cannot bring interface %1 up. %2 : %3" ). 397 emit error( tr( "Cannot bring interface %1 up. %2 : %3" ).
398 arg( devname() ). 398 arg( devname() ).
399 arg( errno ). 399 arg( errno ).
400 arg( strerror(errno) ) ); 400 arg( strerror(errno) ) );
401 } 401 }
402 return; 402 return;
403 } 403 }
404 // have to wait a bit for the 'up' to become active 404 // have to wait a bit for the 'up' to become active
405 QTimer::singleShot( 3000, this, SLOT( reinit() ) ); 405 QTimer::singleShot( 3000, this, SLOT( reinit() ) );
406 } 406 }
407} 407}
408 408
409void OTDriver::bringDown() { 409void OTDriver::bringDown() {
410 410
411 owarn << "bringDown : " << Dev << oendl; 411 odebug << "bringDown : " << Dev << oendl;
412 412
413 if( ! open() ) { 413 if( ! open() ) {
414 return; 414 return;
415 } 415 }
416 416
417 if ( isUp() ) { 417 if ( isUp() ) {
418 if( ioctl(fd(), HCIDEVDOWN, devId()) < 0 ) { 418 if( ioctl(fd(), HCIDEVDOWN, devId()) < 0 ) {
419 if( errno != EALREADY ) { 419 if( errno != EALREADY ) {
420 emit error( tr( "Cannot bring interface %1 down. %2 : %3" ). 420 emit error( tr( "Cannot bring interface %1 down. %2 : %3" ).
421 arg( devname() ). 421 arg( devname() ).
422 arg( errno ). 422 arg( errno ).
423 arg( strerror(errno) ) ); 423 arg( strerror(errno) ) );
424 } 424 }
425 return; 425 return;
426 } 426 }
427 reinit(); 427 reinit();
428 } 428 }
429} 429}
430 430
431void OTDriver::setScanMode(bool iscan, bool pscan) { 431void OTDriver::setScanMode(bool iscan, bool pscan) {
432 432
433 struct hci_dev_req dr; 433 struct hci_dev_req dr;
434 434
435 if( ! open() ) { 435 if( ! open() ) {
436 return; 436 return;
437 } 437 }
438 438
439 dr.dev_id = devId(); 439 dr.dev_id = devId();
440 dr.dev_opt = SCAN_DISABLED; 440 dr.dev_opt = SCAN_DISABLED;
441 441
442 if( iscan&&(!pscan) ) 442 if( iscan&&(!pscan) )
443 dr.dev_opt = SCAN_INQUIRY; 443 dr.dev_opt = SCAN_INQUIRY;
444 else if( pscan&&(!iscan) ) 444 else if( pscan&&(!iscan) )
445 dr.dev_opt = SCAN_PAGE; 445 dr.dev_opt = SCAN_PAGE;
446 else if( pscan&&iscan ) 446 else if( pscan&&iscan )
447 dr.dev_opt = SCAN_PAGE | SCAN_INQUIRY; 447 dr.dev_opt = SCAN_PAGE | SCAN_INQUIRY;
448 448
449 if( ioctl(fd(), HCISETSCAN, (unsigned long)&dr) < 0 ) { 449 if( ioctl(fd(), HCISETSCAN, (unsigned long)&dr) < 0 ) {
450 if( errno != EALREADY ) { 450 if( errno != EALREADY ) {
451 emit error( tr( "Can't set scan mode on %1. %2 : %3" ). 451 emit error( tr( "Can't set scan mode on %1. %2 : %3" ).
452 arg( devname() ). 452 arg( devname() ).
453 arg( errno ). 453 arg( errno ).
454 arg( strerror(errno) ) ); 454 arg( strerror(errno) ) );
455 } 455 }
456 return; 456 return;
457 } 457 }
458 458
459 reinit(); 459 reinit();
460} 460}
461 461
462void OTDriver::changeDevName(const char* name) { 462void OTDriver::changeDevName(const char* name) {
463 463
464 if( ! open() ) { 464 if( ! open() ) {
465 return; 465 return;
466 } 466 }
467 467
468 if (hci_write_local_name(fd(), name, 1000) < 0) { 468 if (hci_write_local_name(fd(), name, 1000) < 0) {
469 emit error( tr( "Can't change local name on %1. %2 : %3" ). 469 emit error( tr( "Can't change local name on %1. %2 : %3" ).
470 arg( devname() ). 470 arg( devname() ).
471 arg( errno ). 471 arg( errno ).
472 arg( strerror(errno) ) ); 472 arg( strerror(errno) ) );
473 } 473 }
474} 474}
475 475
476void OTDriver::changeAuthentication(bool _auth) { 476void OTDriver::changeAuthentication(bool _auth) {
477 struct hci_dev_req dr; 477 struct hci_dev_req dr;
478 478
479 if( ! open() ) { 479 if( ! open() ) {
480 return; 480 return;
481 } 481 }
482 482
483 dr.dev_id = devId(); 483 dr.dev_id = devId();
484 dr.dev_opt = _auth?AUTH_ENABLED:AUTH_DISABLED; 484 dr.dev_opt = _auth?AUTH_ENABLED:AUTH_DISABLED;
485 485
486 if (ioctl(fd(),HCISETAUTH,(unsigned long)&dr) < 0) { 486 if (ioctl(fd(),HCISETAUTH,(unsigned long)&dr) < 0) {
487 if( errno != EALREADY ) { 487 if( errno != EALREADY ) {
488 emit error( tr( "Can't change authentication on %1. %2 : %3" ). 488 emit error( tr( "Can't change authentication on %1. %2 : %3" ).
489 arg( devname() ). 489 arg( devname() ).
490 arg( errno ). 490 arg( errno ).
491 arg( strerror(errno) ) ); 491 arg( strerror(errno) ) );
492 } 492 }
493 return; 493 return;
494 } 494 }
495 reinit(); 495 reinit();
496} 496}
497 497
498void OTDriver::changeEncryption(bool _encrypt) { 498void OTDriver::changeEncryption(bool _encrypt) {
499 struct hci_dev_req dr; 499 struct hci_dev_req dr;
500 500
501 if( ! open() ) { 501 if( ! open() ) {
502 return; 502 return;
503 } 503 }
504 504
505 dr.dev_id = devId(); 505 dr.dev_id = devId();
506 dr.dev_opt = _encrypt?ENCRYPT_P2P:ENCRYPT_DISABLED; 506 dr.dev_opt = _encrypt?ENCRYPT_P2P:ENCRYPT_DISABLED;
507 507
508 if (ioctl(fd(),HCISETENCRYPT,(unsigned long)&dr) < 0) { 508 if (ioctl(fd(),HCISETENCRYPT,(unsigned long)&dr) < 0) {
509 if( errno != EALREADY ) { 509 if( errno != EALREADY ) {
510 emit error( tr( "Can't change encryption on %1. %2 : %3" ). 510 emit error( tr( "Can't change encryption on %1. %2 : %3" ).
511 arg( devname() ). 511 arg( devname() ).
512 arg( errno ). 512 arg( errno ).
513 arg( strerror(errno) ) ); 513 arg( strerror(errno) ) );
514 } 514 }
515 return; 515 return;
516 } 516 }
517 517
518 reinit(); 518 reinit();
519} 519}
520 520
521void OTDriver::changeClass ( unsigned char service, 521void OTDriver::changeClass ( unsigned char service,
522 unsigned char major, 522 unsigned char major,
523 unsigned char minor ) { 523 unsigned char minor ) {
524 unsigned long cod = 0; 524 unsigned long cod = 0;
525 cod = (service << 16) | 525 cod = (service << 16) |
526 (major << 8) | 526 (major << 8) |
527 (minor ) ; 527 (minor ) ;
528 528
529 if( ! open() ) { 529 if( ! open() ) {
530 return; 530 return;
531 } 531 }
532 532
533 if ( hci_write_class_of_dev(fd(),cod,1000) < 0 ) { 533 if ( hci_write_class_of_dev(fd(),cod,1000) < 0 ) {
534 emit error( tr( "Can't change class informations for %1. %2 : %3" ). 534 emit error( tr( "Can't change class informations for %1. %2 : %3" ).
535 arg( devname() ). 535 arg( devname() ).
536 arg( errno ). 536 arg( errno ).
537 arg( strerror(errno) ) ); 537 arg( strerror(errno) ) );
538 return; 538 return;
539 } 539 }
540} 540}
541 541
542void OTDriver::getClass( QString & service, 542void OTDriver::getClass( QString & service,
543 QString & device ) { 543 QString & device ) {
544 unsigned char cls[3]; 544 unsigned char cls[3];
545 545
546 if( ! open() ) { 546 if( ! open() ) {
547 return; 547 return;
548 } 548 }
549 549
550 if ( hci_read_class_of_dev(fd(),cls,1000) < 0 ) { 550 if ( hci_read_class_of_dev(fd(),cls,1000) < 0 ) {
551 emit error( tr( "Can't read class information for %1. %2 : %3" ). 551 emit error( tr( "Can't read class information for %1. %2 : %3" ).
552 arg( devname() ). 552 arg( devname() ).
553 arg( errno ). 553 arg( errno ).
554 arg( strerror(errno) ) ); 554 arg( strerror(errno) ) );
555 return; 555 return;
556 } 556 }
557 557
558 if( cls[2] ) { 558 if( cls[2] ) {
559 int first = 1; 559 int first = 1;
560 for ( unsigned int s = 0; s < sizeof(*services); s++) { 560 for ( unsigned int s = 0; s < sizeof(*services); s++) {
561 if (cls[2] & (1 << s)) { 561 if (cls[2] & (1 << s)) {
562 if( !first ) 562 if( !first )
563 service += ", "; 563 service += ", ";
564 service += services[s]; 564 service += services[s];
565 first = 0; 565 first = 0;
566 } 566 }
567 } 567 }
568 } else { 568 } else {
569 service = "unspecified"; 569 service = "unspecified";
570 } 570 }
571 571
572 MainClassMap_t * MCM = MainClasses; 572 MainClassMap_t * MCM = MainClasses;
573 int major = cls[1] & 0x1f; 573 int major = cls[1] & 0x1f;
574 int minor = cls[0] >> 2; 574 int minor = cls[0] >> 2;
575 575
576 if( (unsigned)(cls[1] & 0x1f) > sizeof(*major_devices)) { 576 if( (unsigned)(cls[1] & 0x1f) > sizeof(*major_devices)) {
577 device = tr("Invalid Device Class"); 577 device = tr("Invalid Device Class");
578 return; 578 return;
579 } 579 }
580 580
581 device = major_devices[cls[1] & 0x1f]; 581 device = major_devices[cls[1] & 0x1f];
582 582
583 while( MCM->Major != -1 ) { 583 while( MCM->Major != -1 ) {
584 if( major == MCM->Major ) { 584 if( major == MCM->Major ) {
585 // this class 585 // this class
586 ClassMap_t * CM = MCM->Map; 586 ClassMap_t * CM = MCM->Map;
587 if( MCM->Map ) { 587 if( MCM->Map ) {
588 while( CM->Minor != -1 ) { 588 while( CM->Minor != -1 ) {
589 if( minor == CM->Minor ) { 589 if( minor == CM->Minor ) {
590 break; 590 break;
591 } 591 }
592 CM ++; 592 CM ++;
593 } 593 }
594 device = CM->Description; 594 device = CM->Description;
595 } else { 595 } else {
596 // special case 596 // special case
597 if( major == 3 ) { 597 if( major == 3 ) {
598 /* lan access */ 598 /* lan access */
599 if( minor == 0 ) { 599 if( minor == 0 ) {
600 device = "Uncategorized"; 600 device = "Uncategorized";
601 } else { 601 } else {
602 switch( minor / 8 ) { 602 switch( minor / 8 ) {
603 case 0: 603 case 0:
604 device = "Fully available"; 604 device = "Fully available";
605 break; 605 break;
606 case 1: 606 case 1:
607 device = "1-17% utilized"; 607 device = "1-17% utilized";
608 break; 608 break;
609 case 2: 609 case 2:
610 device = "17-33% utilized"; 610 device = "17-33% utilized";
611 break; 611 break;
612 case 3: 612 case 3:
613 device = "33-50% utilized"; 613 device = "33-50% utilized";
614 break; 614 break;
615 case 4: 615 case 4:
616 device = "50-67% utilized"; 616 device = "50-67% utilized";
617 break; 617 break;
618 case 5: 618 case 5:
619 device = "67-83% utilized"; 619 device = "67-83% utilized";
620 break; 620 break;
621 case 6: 621 case 6:
622 device = "83-99% utilized"; 622 device = "83-99% utilized";
623 break; 623 break;
624 case 7: 624 case 7:
625 device = "No service available"; 625 device = "No service available";
626 break; 626 break;
627 } 627 }
628 } 628 }
629 } else if( major == 6 ) { /* imaging */ 629 } else if( major == 6 ) { /* imaging */
630 if (minor & 4) 630 if (minor & 4)
631 device = "Display"; 631 device = "Display";
632 if (minor & 8) 632 if (minor & 8)
633 device = "Camera"; 633 device = "Camera";
634 if (minor & 16) 634 if (minor & 16)
635 device = "Scanner"; 635 device = "Scanner";
636 if (minor & 32) 636 if (minor & 32)
637 device = "Printer"; 637 device = "Printer";
638 } 638 }
639 } 639 }
640 break; 640 break;
641 } 641 }
642 MCM ++; 642 MCM ++;
643 } 643 }
644 644
645 if( MCM->Major == -1 ) { 645 if( MCM->Major == -1 ) {
646 device = "Unknown (reserved) minor device class"; 646 device = "Unknown (reserved) minor device class";
647 } 647 }
648} 648}
649 649
650QString OTDriver::strType() { 650QString OTDriver::strType() {
651 return QString( hci_dtypetostr(Type) ); 651 return QString( hci_dtypetostr(Type) );
652} 652}
653 653
654void OTDriver::setFeatures( unsigned char * _f) { 654void OTDriver::setFeatures( unsigned char * _f) {
655 Features = lmp_featurestostr(_f, NULL, 255); 655 Features = lmp_featurestostr(_f, NULL, 255);
656} 656}
657 657
658void OTDriver::setManufacturer(int compid) { 658void OTDriver::setManufacturer(int compid) {
659 Manufacturer = bt_compidtostr(compid); 659 Manufacturer = bt_compidtostr(compid);
660} 660}
661 661
662OTHCISocket * OTDriver::openSocket( void ) { 662OTHCISocket * OTDriver::openSocket( void ) {
663 if( ! Socket ) { 663 if( ! Socket ) {
664 owarn << "Open HCI socket to " << devname() << oendl; 664 odebug << "Open HCI socket to " << devname() << oendl;
665 Socket = new OTHCISocket( this ); 665 Socket = new OTHCISocket( this );
666 } 666 }
667 return Socket; 667 return Socket;
668} 668}
669 669
670void OTDriver::closeSocket( void ) { 670void OTDriver::closeSocket( void ) {
671 if( Socket ) { 671 if( Socket ) {
672 owarn << "Close HCI socket to " << devname() << oendl; 672 odebug << "Close HCI socket to " << devname() << oendl;
673 delete Socket; 673 delete Socket;
674 Socket = 0; 674 Socket = 0;
675 } 675 }
676} 676}
677 677
678QString OTDriver::getPeerName( const OTDeviceAddress & PAddr ) { 678QString OTDriver::getPeerName( const OTDeviceAddress & PAddr ) {
679 QString S; 679 QString S;
680 char name[100 ]; 680 char name[100 ];
681 681
682 if( ! open() ) { 682 if( ! open() ) {
683 return QString("N/A"); 683 return QString("N/A");
684 } 684 }
685 685
686 if( hci_read_remote_name( fd(), 686 if( hci_read_remote_name( fd(),
687 &(PAddr.getBDAddr()), 687 &(PAddr.getBDAddr()),
688 sizeof(name), 688 sizeof(name),
689 name, 689 name,
690 100000 ) < 0 ) { 690 100000 ) < 0 ) {
691 return QString( "N/A" ); 691 return QString( "N/A" );
692 } 692 }
693 693
694 return QString( name ); 694 return QString( name );
695} 695}
696 696
697long OTDriver::getLinkQuality( const OTDeviceAddress & Addr ) { 697long OTDriver::getLinkQuality( const OTDeviceAddress & Addr ) {
698 struct hci_conn_info_req *cr; 698 struct hci_conn_info_req *cr;
699 struct hci_request rq; 699 struct hci_request rq;
700 read_rssi_rp rp; 700 read_rssi_rp rp;
701 uint16_t handle; 701 uint16_t handle;
702 702
703 if( ! open() ) { 703 if( ! open() ) {
704 return 0; 704 return 0;
705 } 705 }
706 706
707 cr = (struct hci_conn_info_req *)malloc( 707 cr = (struct hci_conn_info_req *)malloc(
708 sizeof(*cr) + sizeof(struct hci_conn_info)); 708 sizeof(*cr) + sizeof(struct hci_conn_info));
709 if (!cr) 709 if (!cr)
710 return 0; 710 return 0;
711 711
712 bacpy( &(cr->bdaddr), &(Addr.getBDAddr()) ); 712 bacpy( &(cr->bdaddr), &(Addr.getBDAddr()) );
713 cr->type = ACL_LINK; 713 cr->type = ACL_LINK;
714 714
715 if (ioctl( fd(), HCIGETCONNINFO, (unsigned long) cr) < 0) { 715 if (ioctl( fd(), HCIGETCONNINFO, (unsigned long) cr) < 0) {
716 owarn << "Get connection info failed" << oendl; 716 odebug << "Get connection info failed" << oendl;
717 free(cr); 717 free(cr);
718 return 0; 718 return 0;
719 } 719 }
720 720
721 handle = htobs(cr->conn_info->handle); 721 handle = htobs(cr->conn_info->handle);
722 722
723 free(cr); 723 free(cr);
724 724
725 memset(&rq, 0, sizeof(rq)); 725 memset(&rq, 0, sizeof(rq));
726 rq.ogf = OGF_STATUS_PARAM; 726 rq.ogf = OGF_STATUS_PARAM;
727 rq.ocf = OCF_READ_RSSI; 727 rq.ocf = OCF_READ_RSSI;
728 rq.cparam = &handle; 728 rq.cparam = &handle;
729 rq.clen = 2; 729 rq.clen = 2;
730 rq.rparam = &rp; 730 rq.rparam = &rp;
731 rq.rlen = GET_LINK_QUALITY_RP_SIZE; 731 rq.rlen = GET_LINK_QUALITY_RP_SIZE;
732 732
733 if (hci_send_req( fd(), &rq, 100) < 0) { 733 if (hci_send_req( fd(), &rq, 100) < 0) {
734 owarn << "Get connection info failed" << oendl; 734 odebug << "Get connection info failed" << oendl;
735 return 0; 735 return 0;
736 } 736 }
737 737
738 if( rp.status ) { 738 if( rp.status ) {
739 owarn << QString().sprintf("HCI get_link_quality cmd failed (0x%2.2X)", rp.status) << oendl; 739 odebug << QString().sprintf("HCI get_link_quality cmd failed (0x%2.2X)", rp.status) << oendl;
740 return 0; 740 return 0;
741 } 741 }
742 742
743 return rp.rssi+50; 743 return rp.rssi+50;
744} 744}
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 @@
1/*************************************************************************** 1/***************************************************************************
2 * Copyright (C) 2003 by Mattia Merzi * 2 * Copyright (C) 2003 by Mattia Merzi *
3 * ottobit@ferrara.linux.it * 3 * ottobit@ferrara.linux.it *
4 * * 4 * *
5 * This program is free software; you can redistribute it and/or modify * 5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by * 6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or * 7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. * 8 * (at your option) any later version. *
9 ***************************************************************************/ 9 ***************************************************************************/
10 10
11#include <malloc.h> 11#include <malloc.h>
12#include <bluezlib.h> 12#include <bluezlib.h>
13 13
14#include <opie2/odebug.h> 14#include <opie2/odebug.h>
15 15
16#include <OTDriverList.h> 16#include <OTDriverList.h>
17#include <OTGateway.h> 17#include <OTGateway.h>
18#include <OTDriver.h> 18#include <OTDriver.h>
19 19
20using namespace Opietooth2; 20using namespace Opietooth2;
21 21
22OTDriverList::OTDriverList( OTGateway * _OT ) : QVector<OTDriver>() { 22OTDriverList::OTDriverList( OTGateway * _OT ) : QVector<OTDriver>() {
23 23
24 OT = _OT; 24 OT = _OT;
25 setAutoDelete( true ); 25 setAutoDelete( true );
26} 26}
27 27
28OTDriverList::~OTDriverList() { 28OTDriverList::~OTDriverList() {
29} 29}
30 30
31void OTDriverList::update() { 31void OTDriverList::update() {
32 32
33 struct hci_dev_list_req *dl; 33 struct hci_dev_list_req *dl;
34 struct hci_dev_req *dr; 34 struct hci_dev_req *dr;
35 struct hci_dev_info di; 35 struct hci_dev_info di;
36 int cur; 36 int cur;
37 37
38 dl = 0; 38 dl = 0;
39 cur = 0; 39 cur = 0;
40 do { 40 do {
41 cur += 5; 41 cur += 5;
42 42
43 dl = (struct hci_dev_list_req*) 43 dl = (struct hci_dev_list_req*)
44 ::realloc( dl, sizeof( struct hci_dev_list_req ) + 44 ::realloc( dl, sizeof( struct hci_dev_list_req ) +
45 ( cur * sizeof(struct hci_dev_req) ) 45 ( cur * sizeof(struct hci_dev_req) )
46 ); 46 );
47 47
48 if( dl == 0 ) { 48 if( dl == 0 ) {
49 // memory problem 49 // memory problem
50 exit(1); 50 exit(1);
51 } 51 }
52 52
53 dl->dev_num = cur; 53 dl->dev_num = cur;
54 54
55 if( ioctl( OT->getSocket(), HCIGETDEVLIST, (void*)dl) ) { 55 if( ioctl( OT->getSocket(), HCIGETDEVLIST, (void*)dl) ) {
56 owarn << "WARNING : cannot read device list. " 56 odebug << "WARNING : cannot read device list. "
57 << errno 57 << errno
58 << strerror( errno ) << oendl; 58 << strerror( errno ) << oendl;
59 return; 59 return;
60 } 60 }
61 61
62 // if num == cur perhaps we did not get all devices yet 62 // if num == cur perhaps we did not get all devices yet
63 } while( dl->dev_num == cur ); 63 } while( dl->dev_num == cur );
64 64
65 if( dl->dev_num != count() ) { 65 if( dl->dev_num != count() ) {
66 // new or missing devices 66 // new or missing devices
67 clear(); 67 clear();
68 68
69 dr = dl->dev_req; 69 dr = dl->dev_req;
70 resize( dl->dev_num ); 70 resize( dl->dev_num );
71 71
72 for( cur=0; cur < dl->dev_num; cur ++) { 72 for( cur=0; cur < dl->dev_num; cur ++) {
73 memset( &di, 0, sizeof( di ) ); 73 memset( &di, 0, sizeof( di ) );
74 di.dev_id = (dr+cur)->dev_id; 74 di.dev_id = (dr+cur)->dev_id;
75 75
76 // get device info 76 // get device info
77 if( ioctl( OT->getSocket(), HCIGETDEVINFO, (void*)&di) != 0 ) 77 if( ioctl( OT->getSocket(), HCIGETDEVINFO, (void*)&di) != 0 )
78 continue; // uh ? 78 continue; // uh ?
79 insert( cur, new OTDriver( OT, &di ) ); 79 insert( cur, new OTDriver( OT, &di ) );
80 } 80 }
81 81
82 owarn << "Found " << count() << " devices" << oendl; 82 odebug << "Found " << count() << " devices" << oendl;
83 83
84 ::free( dl ); 84 ::free( dl );
85 } 85 }
86} 86}
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
@@ -1,650 +1,650 @@
1#include <qmessagebox.h> 1#include <qmessagebox.h>
2#include <qfile.h> 2#include <qfile.h>
3#include <qdir.h> 3#include <qdir.h>
4#include <qtextstream.h> 4#include <qtextstream.h>
5#include <qpixmap.h> 5#include <qpixmap.h>
6#include <qvector.h> 6#include <qvector.h>
7#include <qpe/resource.h> 7#include <qpe/resource.h>
8 8
9#include <opie2/odebug.h> 9#include <opie2/odebug.h>
10 10
11#include <bluezlib.h> 11#include <bluezlib.h>
12 12
13#include <OTDevice.h> 13#include <OTDevice.h>
14#include <OTDriver.h> 14#include <OTDriver.h>
15#include <OTInquiry.h> 15#include <OTInquiry.h>
16#include <OTDriverList.h> 16#include <OTDriverList.h>
17#include <OTDeviceAddress.h> 17#include <OTDeviceAddress.h>
18#include <OTGateway.h> 18#include <OTGateway.h>
19 19
20using namespace Opietooth2; 20using namespace Opietooth2;
21 21
22// single instance 22// single instance
23OTGateway * OTGateway::SingleGateway = 0; 23OTGateway * OTGateway::SingleGateway = 0;
24int OTGateway::UseCount = 0; 24int OTGateway::UseCount = 0;
25 25
26OTGateway * OTGateway::getOTGateway( void ) { 26OTGateway * OTGateway::getOTGateway( void ) {
27 if(SingleGateway == 0 ) { 27 if(SingleGateway == 0 ) {
28 SingleGateway = new OTGateway(); 28 SingleGateway = new OTGateway();
29 } 29 }
30 30
31 UseCount ++; 31 UseCount ++;
32 return SingleGateway; 32 return SingleGateway;
33} 33}
34 34
35void OTGateway::releaseOTGateway( void ) { 35void OTGateway::releaseOTGateway( void ) {
36 UseCount --; 36 UseCount --;
37 if( UseCount == 0 ) { 37 if( UseCount == 0 ) {
38 delete SingleGateway; 38 delete SingleGateway;
39 SingleGateway = 0; 39 SingleGateway = 0;
40 } 40 }
41} 41}
42 42
43// open bluetooth system 43// open bluetooth system
44OTGateway::OTGateway( void ) : QObject( 0, "OTGateway" ), 44OTGateway::OTGateway( void ) : QObject( 0, "OTGateway" ),
45 AllDrivers( this ), 45 AllDrivers( this ),
46 AllPeers() { 46 AllPeers() {
47 47
48 ErrorConnectCount = 0; 48 ErrorConnectCount = 0;
49 TheOTDevice = 0; 49 TheOTDevice = 0;
50 Scanning = 0; 50 Scanning = 0;
51 AllPeersModified = 0; 51 AllPeersModified = 0;
52 AllPeers.setAutoDelete( TRUE ); 52 AllPeers.setAutoDelete( TRUE );
53 53
54 if ( ( HciCtl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) { 54 if ( ( HciCtl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) {
55 SLOT_ShowError( tr( "error opening hci socket" ) ); 55 SLOT_ShowError( tr( "error opening hci socket" ) );
56 return; 56 return;
57 } 57 }
58 58
59 // load all known devices 59 // load all known devices
60 updateDrivers(); 60 updateDrivers();
61 61
62 // load all peers we have ever seen 62 // load all peers we have ever seen
63 loadKnownPeers(); 63 loadKnownPeers();
64 64
65 // iterate over drivers and find active connections 65 // iterate over drivers and find active connections
66 // adding/updating peers 66 // adding/updating peers
67 loadActiveConnections(); 67 loadActiveConnections();
68 68
69 // check every 4 seconds the state of BT 69 // check every 4 seconds the state of BT
70 timerEvent(0); 70 timerEvent(0);
71 RefreshTimer = -1; 71 RefreshTimer = -1;
72 setRefreshTimer( 4000 ); 72 setRefreshTimer( 4000 );
73 73
74 // load known link keys 74 // load known link keys
75 readLinkKeys(); 75 readLinkKeys();
76} 76}
77 77
78// close bluetooth system 78// close bluetooth system
79OTGateway::~OTGateway( void ) { 79OTGateway::~OTGateway( void ) {
80 80
81 if( AllPeersModified ) { 81 if( AllPeersModified ) {
82 saveKnownPeers(); 82 saveKnownPeers();
83 } 83 }
84 84
85 if( Scanning ) 85 if( Scanning )
86 delete Scanning; 86 delete Scanning;
87 87
88 if( TheOTDevice ) 88 if( TheOTDevice )
89 delete TheOTDevice; 89 delete TheOTDevice;
90 90
91 if( HciCtl >= 0 ) { 91 if( HciCtl >= 0 ) {
92 ::close( HciCtl ); 92 ::close( HciCtl );
93 } 93 }
94} 94}
95 95
96void OTGateway::setRefreshTimer( int T ) { 96void OTGateway::setRefreshTimer( int T ) {
97 if( RefreshTimer != -1 ) { 97 if( RefreshTimer != -1 ) {
98 killTimer( RefreshTimer ); 98 killTimer( RefreshTimer );
99 } 99 }
100 100
101 if( T == 0 ) 101 if( T == 0 )
102 T = 4000; 102 T = 4000;
103 RefreshTimer = startTimer( T ); 103 RefreshTimer = startTimer( T );
104} 104}
105 105
106OTDevice * OTGateway::getOTDevice( ) { 106OTDevice * OTGateway::getOTDevice( ) {
107 if( TheOTDevice == 0 ) { 107 if( TheOTDevice == 0 ) {
108 // load bluetooth device and check state 108 // load bluetooth device and check state
109 TheOTDevice = new OTDevice( this ); 109 TheOTDevice = new OTDevice( this );
110 connect( TheOTDevice, 110 connect( TheOTDevice,
111 SIGNAL( isEnabled( int, bool ) ), 111 SIGNAL( isEnabled( int, bool ) ),
112 this, 112 this,
113 SLOT( SLOT_Enabled( int, bool ) ) ); 113 SLOT( SLOT_Enabled( int, bool ) ) );
114 114
115 connect( TheOTDevice, 115 connect( TheOTDevice,
116 SIGNAL( error( const QString & ) ), 116 SIGNAL( error( const QString & ) ),
117 this, 117 this,
118 SLOT( SLOT_ShowError( const QString & ) ) ); 118 SLOT( SLOT_ShowError( const QString & ) ) );
119 } 119 }
120 120
121 return TheOTDevice; 121 return TheOTDevice;
122} 122}
123 123
124// start bluetooth (if stopped) 124// start bluetooth (if stopped)
125// return TRUE if started 125// return TRUE if started
126void OTGateway::SLOT_SetEnabled( bool Mode ) { 126void OTGateway::SLOT_SetEnabled( bool Mode ) {
127 if( Mode ) { 127 if( Mode ) {
128 SLOT_Enable(); 128 SLOT_Enable();
129 return; 129 return;
130 } 130 }
131 SLOT_Disable(); 131 SLOT_Disable();
132} 132}
133 133
134void OTGateway::SLOT_Enable() { 134void OTGateway::SLOT_Enable() {
135 getOTDevice()->attach(); 135 getOTDevice()->attach();
136} 136}
137 137
138void OTGateway::SLOT_Disable() { 138void OTGateway::SLOT_Disable() {
139 getOTDevice()->detach(); 139 getOTDevice()->detach();
140} 140}
141 141
142bool OTGateway::needsEnabling() { 142bool OTGateway::needsEnabling() {
143 return getOTDevice()->needsAttach(); 143 return getOTDevice()->needsAttach();
144} 144}
145 145
146bool OTGateway::isEnabled() { 146bool OTGateway::isEnabled() {
147 if( getOTDevice()->deviceNr() >= 0 && 147 if( getOTDevice()->deviceNr() >= 0 &&
148 driver( getOTDevice()->deviceNr() )->isUp() ) 148 driver( getOTDevice()->deviceNr() )->isUp() )
149 return TRUE; 149 return TRUE;
150 150
151 // else check system 151 // else check system
152 return getOTDevice()->isAttached(); 152 return getOTDevice()->isAttached();
153} 153}
154 154
155void OTGateway::SLOT_ShowError( const QString & S ) { 155void OTGateway::SLOT_ShowError( const QString & S ) {
156 156
157 owarn << S << oendl; 157 odebug << S << oendl;
158 158
159 if( ErrorConnectCount > 0 ) { 159 if( ErrorConnectCount > 0 ) {
160 // pass error 160 // pass error
161 emit error( QString( "<p>" ) + S + "</p>" ); 161 emit error( QString( "<p>" ) + S + "</p>" );
162 return; 162 return;
163 } 163 }
164 164
165 QMessageBox::warning( 0, 165 QMessageBox::warning( 0,
166 tr("OTGateway error"), 166 tr("OTGateway error"),
167 S ); 167 S );
168} 168}
169 169
170void OTGateway::connectNotify( const char * S ) { 170void OTGateway::connectNotify( const char * S ) {
171 if( S && strcmp( S, "error(const QString&)" ) == 0 ) { 171 if( S && strcmp( S, "error(const QString&)" ) == 0 ) {
172 ErrorConnectCount ++; 172 ErrorConnectCount ++;
173 } 173 }
174} 174}
175 175
176void OTGateway::disconnectNotify( const char * S ) { 176void OTGateway::disconnectNotify( const char * S ) {
177 if( S && strcmp( S, "error(const QString&)" ) == 0 ) { 177 if( S && strcmp( S, "error(const QString&)" ) == 0 ) {
178 ErrorConnectCount --; 178 ErrorConnectCount --;
179 } 179 }
180} 180}
181 181
182void OTGateway::timerEvent( QTimerEvent * ) { 182void OTGateway::timerEvent( QTimerEvent * ) {
183 183
184 OTDriver * D; 184 OTDriver * D;
185 unsigned int oldc = AllDrivers.count(); 185 unsigned int oldc = AllDrivers.count();
186 bool old; 186 bool old;
187 187
188 AllDrivers.update(); 188 AllDrivers.update();
189 189
190 if( oldc != AllDrivers.count() ) { 190 if( oldc != AllDrivers.count() ) {
191 updateDrivers(); 191 updateDrivers();
192 } else { 192 } else {
193 for( unsigned int i = 0; 193 for( unsigned int i = 0;
194 i < AllDrivers.count(); 194 i < AllDrivers.count();
195 i ++ ) { 195 i ++ ) {
196 D = AllDrivers[i]; 196 D = AllDrivers[i];
197 old = D->isUp(); 197 old = D->isUp();
198 if( D->currentState() >= 0 ) { 198 if( D->currentState() >= 0 ) {
199 if( old != D->isUp() ) { 199 if( old != D->isUp() ) {
200 emit stateChange( D, D->isUp() ); 200 emit stateChange( D, D->isUp() );
201 } 201 }
202 } else { 202 } else {
203 // if one driver is unable to provide info 203 // if one driver is unable to provide info
204 // we refresh all devices 204 // we refresh all devices
205 updateDrivers(); 205 updateDrivers();
206 return; 206 return;
207 } 207 }
208 } 208 }
209 } 209 }
210} 210}
211 211
212void OTGateway::SLOT_Enabled( int id, bool Up ) { 212void OTGateway::SLOT_Enabled( int id, bool Up ) {
213 owarn << "device " << id << " state " << Up << oendl; 213 odebug << "device " << id << " state " << Up << oendl;
214 if( Up ) { 214 if( Up ) {
215 // device is up -> detect it 215 // device is up -> detect it
216 updateDrivers(); 216 updateDrivers();
217 if( (unsigned)id >= AllDrivers.count() ) { 217 if( (unsigned)id >= AllDrivers.count() ) {
218 // to make sure that the driver really IS detected 218 // to make sure that the driver really IS detected
219 AllDrivers[id]->bringUp(); 219 AllDrivers[id]->bringUp();
220 } 220 }
221 } // if DOWN device already down 221 } // if DOWN device already down
222 emit deviceEnabled( Up ); 222 emit deviceEnabled( Up );
223} 223}
224 224
225void OTGateway::updateDrivers( void ) { 225void OTGateway::updateDrivers( void ) {
226 OTDriver * D; 226 OTDriver * D;
227 227
228 AllDrivers.update(); 228 AllDrivers.update();
229 229
230 owarn << "updated drivers. now " << AllDrivers.count() << oendl; 230 odebug << "updated drivers. now " << AllDrivers.count() << oendl;
231 231
232 // connect signals for each driver 232 // connect signals for each driver
233 for( unsigned int i = 0; 233 for( unsigned int i = 0;
234 i < AllDrivers.count(); 234 i < AllDrivers.count();
235 i ++ ) { 235 i ++ ) {
236 D = AllDrivers[i]; 236 D = AllDrivers[i];
237 237
238 connect( D, 238 connect( D,
239 SIGNAL( error( const QString & ) ), 239 SIGNAL( error( const QString & ) ),
240 this, 240 this,
241 SLOT( SLOT_ShowError( const QString & ) ) 241 SLOT( SLOT_ShowError( const QString & ) )
242 ); 242 );
243 243
244 connect( D, 244 connect( D,
245 SIGNAL( stateChange( OTDriver *, bool ) ), 245 SIGNAL( stateChange( OTDriver *, bool ) ),
246 this, 246 this,
247 SIGNAL( stateChange( OTDriver *, bool ) ) 247 SIGNAL( stateChange( OTDriver *, bool ) )
248 ); 248 );
249 249
250 connect( D, 250 connect( D,
251 SIGNAL( driverDisappeared( OTDriver * ) ), 251 SIGNAL( driverDisappeared( OTDriver * ) ),
252 this, 252 this,
253 SLOT( SLOT_DriverDisappeared( OTDriver * ) ) 253 SLOT( SLOT_DriverDisappeared( OTDriver * ) )
254 ); 254 );
255 } 255 }
256 256
257 // verify main device too 257 // verify main device too
258 if( TheOTDevice ) 258 if( TheOTDevice )
259 TheOTDevice->checkAttach(); 259 TheOTDevice->checkAttach();
260 260
261 // set to default scanning hardware 261 // set to default scanning hardware
262 setScanWith( 0 ); 262 setScanWith( 0 );
263 263
264 emit driverListChanged(); 264 emit driverListChanged();
265} 265}
266 266
267void OTGateway::SLOT_DriverDisappeared( OTDriver * D ) { 267void OTGateway::SLOT_DriverDisappeared( OTDriver * D ) {
268 owarn << "Driver " << D->devname() << " when offline" << oendl; 268 odebug << "Driver " << D->devname() << " when offline" << oendl;
269 updateDrivers(); 269 updateDrivers();
270} 270}
271 271
272void OTGateway::scanNeighbourhood( OTDriver * D ) { 272void OTGateway::scanNeighbourhood( OTDriver * D ) {
273 273
274 if( Scanning ) { 274 if( Scanning ) {
275 stopScanOfNeighbourhood(); 275 stopScanOfNeighbourhood();
276 } 276 }
277 277
278 if( D ) { 278 if( D ) {
279 setScanWith( D ); 279 setScanWith( D );
280 } 280 }
281 281
282 Scanning = new OTInquiry( scanWith() ); 282 Scanning = new OTInquiry( scanWith() );
283 283
284 connect( Scanning, 284 connect( Scanning,
285 SIGNAL( peerFound( OTPeer *, bool )), 285 SIGNAL( peerFound( OTPeer *, bool )),
286 this, 286 this,
287 SLOT( SLOT_PeerDetected( OTPeer *, bool ) ) 287 SLOT( SLOT_PeerDetected( OTPeer *, bool ) )
288 ); 288 );
289 connect( Scanning, 289 connect( Scanning,
290 SIGNAL( finished()), 290 SIGNAL( finished()),
291 this, 291 this,
292 SLOT( SLOT_FinishedDetecting() ) 292 SLOT( SLOT_FinishedDetecting() )
293 ); 293 );
294 294
295 // start scanning 295 // start scanning
296 Scanning->inquire( 30.0 ); 296 Scanning->inquire( 30.0 );
297} 297}
298 298
299OTPeer* OTGateway::findPeer( const OTDeviceAddress & Addr ) { 299OTPeer* OTGateway::findPeer( const OTDeviceAddress & Addr ) {
300 for( unsigned int i = 0 ; i < AllPeers.count(); i ++ ) { 300 for( unsigned int i = 0 ; i < AllPeers.count(); i ++ ) {
301 if( AllPeers[i]->address() == Addr ) { 301 if( AllPeers[i]->address() == Addr ) {
302 return AllPeers[i]; 302 return AllPeers[i];
303 } 303 }
304 } 304 }
305 return 0; 305 return 0;
306} 306}
307 307
308OTDriver* OTGateway::findDriver( const OTDeviceAddress & Addr ) { 308OTDriver* OTGateway::findDriver( const OTDeviceAddress & Addr ) {
309 for( unsigned int i = 0 ; i < AllDrivers.count(); i ++ ) { 309 for( unsigned int i = 0 ; i < AllDrivers.count(); i ++ ) {
310 if( AllDrivers[i]->address() == Addr ) { 310 if( AllDrivers[i]->address() == Addr ) {
311 return AllDrivers[i]; 311 return AllDrivers[i];
312 } 312 }
313 } 313 }
314 return 0; 314 return 0;
315} 315}
316 316
317void OTGateway::SLOT_PeerDetected( OTPeer * P, bool IsNew ) { 317void OTGateway::SLOT_PeerDetected( OTPeer * P, bool IsNew ) {
318 318
319 if( IsNew ) { 319 if( IsNew ) {
320 // new peer 320 // new peer
321 owarn << "New peer " << P->name() << oendl; 321 odebug << "New peer " << P->name() << oendl;
322 addPeer( P ); 322 addPeer( P );
323 } 323 }
324 324
325 emit detectedPeer( P, IsNew ); 325 emit detectedPeer( P, IsNew );
326} 326}
327 327
328void OTGateway::addPeer( OTPeer * P ) { 328void OTGateway::addPeer( OTPeer * P ) {
329 AllPeers.resize( AllPeers.size()+1); 329 AllPeers.resize( AllPeers.size()+1);
330 AllPeers.insert( AllPeers.size()-1, P ); 330 AllPeers.insert( AllPeers.size()-1, P );
331 AllPeersModified = 1; 331 AllPeersModified = 1;
332} 332}
333 333
334void OTGateway::removePeer( OTPeer * P ) { 334void OTGateway::removePeer( OTPeer * P ) {
335 int i = AllPeers.find( P ); 335 int i = AllPeers.find( P );
336 if( i ) { 336 if( i ) {
337 AllPeers.remove( i ); 337 AllPeers.remove( i );
338 AllPeersModified = 1; 338 AllPeersModified = 1;
339 } 339 }
340} 340}
341 341
342void OTGateway::stopScanOfNeighbourhood( void ) { 342void OTGateway::stopScanOfNeighbourhood( void ) {
343 if( Scanning ) { 343 if( Scanning ) {
344 delete Scanning; 344 delete Scanning;
345 Scanning = 0; 345 Scanning = 0;
346 } 346 }
347} 347}
348 348
349void OTGateway::SLOT_FinishedDetecting() { 349void OTGateway::SLOT_FinishedDetecting() {
350 stopScanOfNeighbourhood(); 350 stopScanOfNeighbourhood();
351 emit finishedDetecting(); 351 emit finishedDetecting();
352} 352}
353 353
354const char * OTGateway::deviceTypeToName( int cls ) { 354const char * OTGateway::deviceTypeToName( int cls ) {
355 switch ( (cls & 0x001F00) >> 8) { 355 switch ( (cls & 0x001F00) >> 8) {
356 case 0x00: 356 case 0x00:
357 return "misc"; 357 return "misc";
358 case 0x01: 358 case 0x01:
359 return "computer"; 359 return "computer";
360 case 0x02: 360 case 0x02:
361 return "phone"; 361 return "phone";
362 case 0x03: 362 case 0x03:
363 return "lan"; 363 return "lan";
364 case 0x04: 364 case 0x04:
365 return "av"; 365 return "av";
366 case 0x05: 366 case 0x05:
367 return "peripheral"; 367 return "peripheral";
368 case 0x06: 368 case 0x06:
369 return "imaging"; 369 return "imaging";
370 case 0x07: 370 case 0x07:
371 default : 371 default :
372 break; 372 break;
373 } 373 }
374 return "unknown"; 374 return "unknown";
375} 375}
376 376
377PANConnectionVector OTGateway::getPANConnections( void ) { 377PANConnectionVector OTGateway::getPANConnections( void ) {
378 PANConnectionVector V; 378 PANConnectionVector V;
379 379
380 struct bnep_connlist_req req; 380 struct bnep_connlist_req req;
381 struct bnep_conninfo ci[48]; 381 struct bnep_conninfo ci[48];
382 382
383 V.setAutoDelete(TRUE); 383 V.setAutoDelete(TRUE);
384 384
385 int ctl = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_BNEP); 385 int ctl = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_BNEP);
386 if (ctl < 0) { 386 if (ctl < 0) {
387 owarn << "Failed to open control socket" << oendl; 387 odebug << "Failed to open control socket" << oendl;
388 return V; 388 return V;
389 } 389 }
390 390
391 req.cnum = 48; 391 req.cnum = 48;
392 req.ci = ci; 392 req.ci = ci;
393 if (ioctl(ctl, BNEPGETCONNLIST, &req)) { 393 if (ioctl(ctl, BNEPGETCONNLIST, &req)) {
394 owarn << "Failed to get connection list" << oendl; 394 odebug << "Failed to get connection list" << oendl;
395 ::close( ctl ); 395 ::close( ctl );
396 return V; 396 return V;
397 } 397 }
398 398
399 for ( unsigned i=0; i < req.cnum; i++) { 399 for ( unsigned i=0; i < req.cnum; i++) {
400 V.resize( V.size() + 1 ); 400 V.resize( V.size() + 1 );
401 if( ci[i].role == BNEP_SVC_PANU ) { 401 if( ci[i].role == BNEP_SVC_PANU ) {
402 // we are the client 402 // we are the client
403 V.insert( V.size()-1, new OTPANConnection( 403 V.insert( V.size()-1, new OTPANConnection(
404 ci[i].device, 404 ci[i].device,
405 batostr((bdaddr_t *) ci[i].dst) 405 batostr((bdaddr_t *) ci[i].dst)
406 ) ); 406 ) );
407 } 407 }
408 } 408 }
409 409
410 ::close( ctl ); 410 ::close( ctl );
411 return V; 411 return V;
412} 412}
413 413
414struct link_key { 414struct link_key {
415 bdaddr_t sba; 415 bdaddr_t sba;
416 bdaddr_t dba; 416 bdaddr_t dba;
417 uint8_t key[16]; 417 uint8_t key[16];
418 uint8_t type; 418 uint8_t type;
419 time_t time; 419 time_t time;
420}; 420};
421 421
422void OTGateway::readLinkKeys( void ) { 422void OTGateway::readLinkKeys( void ) {
423 423
424 struct link_key k; 424 struct link_key k;
425 int rv; 425 int rv;
426 426
427 AllKeys.truncate(0); 427 AllKeys.truncate(0);
428 428
429 QFile F( "/etc/bluetooth/link_key" ); 429 QFile F( "/etc/bluetooth/link_key" );
430 430
431 if( ! F.open( IO_ReadOnly ) ) { 431 if( ! F.open( IO_ReadOnly ) ) {
432 emit error( tr("Cannot open link_key file") ); 432 emit error( tr("Cannot open link_key file") );
433 return; 433 return;
434 } 434 }
435 435
436 while( 1 ) { 436 while( 1 ) {
437 rv = F.readBlock( (char *)&k, sizeof( k ) ); 437 rv = F.readBlock( (char *)&k, sizeof( k ) );
438 if( rv == 0 ) 438 if( rv == 0 )
439 // EOF 439 // EOF
440 break; 440 break;
441 441
442 if( rv < 0 ) { 442 if( rv < 0 ) {
443 emit error( tr("Read error in link key file") ); 443 emit error( tr("Read error in link key file") );
444 } 444 }
445 445
446 AllKeys.resize( AllKeys.size()+1 ); 446 AllKeys.resize( AllKeys.size()+1 );
447 AllKeys[ AllKeys.size()-1 ].From.setBDAddr( k.sba ); 447 AllKeys[ AllKeys.size()-1 ].From.setBDAddr( k.sba );
448 AllKeys[ AllKeys.size()-1 ].To.setBDAddr( k.dba ); 448 AllKeys[ AllKeys.size()-1 ].To.setBDAddr( k.dba );
449 } 449 }
450} 450}
451 451
452bool OTGateway::removeLinkKey( unsigned int Index ) { 452bool OTGateway::removeLinkKey( unsigned int Index ) {
453 OTLinkKey & LK = AllKeys[Index]; 453 OTLinkKey & LK = AllKeys[Index];
454 454
455 struct link_key k; 455 struct link_key k;
456 int rv; 456 int rv;
457 457
458 QFile F( "/etc/bluetooth/link_key" ); 458 QFile F( "/etc/bluetooth/link_key" );
459 QFile OutF( "/etc/bluetooth/newlink_key" ); 459 QFile OutF( "/etc/bluetooth/newlink_key" );
460 460
461 if( ! F.open( IO_ReadOnly ) ) { 461 if( ! F.open( IO_ReadOnly ) ) {
462 emit error( tr("Cannot open link_key file") ); 462 emit error( tr("Cannot open link_key file") );
463 return 0; 463 return 0;
464 } 464 }
465 465
466 if( ! OutF.open( IO_WriteOnly | IO_Truncate ) ) { 466 if( ! OutF.open( IO_WriteOnly | IO_Truncate ) ) {
467 emit error( tr("Cannot open temporary link_key file") ); 467 emit error( tr("Cannot open temporary link_key file") );
468 return 0; 468 return 0;
469 } 469 }
470 470
471 while( 1 ) { 471 while( 1 ) {
472 rv = F.readBlock( (char *)&k, sizeof( k ) ); 472 rv = F.readBlock( (char *)&k, sizeof( k ) );
473 if( rv == 0 ) 473 if( rv == 0 )
474 // EOF 474 // EOF
475 break; 475 break;
476 476
477 if( rv < 0 ) { 477 if( rv < 0 ) {
478 emit error( tr("Read error in link key file") ); 478 emit error( tr("Read error in link key file") );
479 return 0; 479 return 0;
480 } 480 }
481 481
482 if( LK.from() != OTDeviceAddress( k.sba ) || 482 if( LK.from() != OTDeviceAddress( k.sba ) ||
483 LK.to() != OTDeviceAddress( k.dba ) ) { 483 LK.to() != OTDeviceAddress( k.dba ) ) {
484 // copy 484 // copy
485 OutF.writeBlock( (char *)&k, sizeof( k ) ); 485 OutF.writeBlock( (char *)&k, sizeof( k ) );
486 } // else remove this key 486 } // else remove this key
487 } 487 }
488 488
489 // rename files 489 // rename files
490 QDir D( "/etc/bluetooth" ); 490 QDir D( "/etc/bluetooth" );
491 491
492 D.remove( "link_key" ); 492 D.remove( "link_key" );
493 D.rename( "newlink_key", "link_key" ); 493 D.rename( "newlink_key", "link_key" );
494 494
495 // restart hcid 495 // restart hcid
496 system( "/etc/init.d/hcid stop" ); 496 system( "/etc/init.d/hcid stop" );
497 system( "/etc/init.d/hcid start" ); 497 system( "/etc/init.d/hcid start" );
498 498
499 // remove from table 499 // remove from table
500 if( Index < (AllKeys.size()-1) ) { 500 if( Index < (AllKeys.size()-1) ) {
501 // collapse array 501 // collapse array
502 AllKeys[Index] = AllKeys[AllKeys.size()-1]; 502 AllKeys[Index] = AllKeys[AllKeys.size()-1];
503 } 503 }
504 504
505 // remove last element 505 // remove last element
506 AllKeys.resize( AllKeys.size()-1 ); 506 AllKeys.resize( AllKeys.size()-1 );
507 507
508 return 1; 508 return 1;
509} 509}
510 510
511#define MAXCONNECTIONS 10 511#define MAXCONNECTIONS 10
512void OTGateway::loadActiveConnections( void ) { 512void OTGateway::loadActiveConnections( void ) {
513 513
514 struct hci_conn_list_req *cl; 514 struct hci_conn_list_req *cl;
515 struct hci_conn_info *ci; 515 struct hci_conn_info *ci;
516 OTDeviceAddress Addr; 516 OTDeviceAddress Addr;
517 OTPeer * P; 517 OTPeer * P;
518 518
519 if (!(cl = (struct hci_conn_list_req *)malloc( 519 if (!(cl = (struct hci_conn_list_req *)malloc(
520 MAXCONNECTIONS * sizeof(*ci) + sizeof(*cl)))) { 520 MAXCONNECTIONS * sizeof(*ci) + sizeof(*cl)))) {
521 emit error( tr("Can't allocate memory") ); 521 emit error( tr("Can't allocate memory") );
522 return; 522 return;
523 } 523 }
524 memset( cl, 0, MAXCONNECTIONS * sizeof(*ci) + sizeof(*cl) ); 524 memset( cl, 0, MAXCONNECTIONS * sizeof(*ci) + sizeof(*cl) );
525 525
526 for( unsigned int i = 0; 526 for( unsigned int i = 0;
527 i < AllDrivers.count(); 527 i < AllDrivers.count();
528 i ++ ) { 528 i ++ ) {
529 529
530 if( ! AllDrivers[i]->isUp() ) { 530 if( ! AllDrivers[i]->isUp() ) {
531 continue; 531 continue;
532 } 532 }
533 533
534 // driver is up -> check connections 534 // driver is up -> check connections
535 cl->dev_id = AllDrivers[i]->devId(); 535 cl->dev_id = AllDrivers[i]->devId();
536 cl->conn_num = MAXCONNECTIONS; 536 cl->conn_num = MAXCONNECTIONS;
537 ci = cl->conn_info; 537 ci = cl->conn_info;
538 538
539 if (ioctl( getSocket(), HCIGETCONNLIST, (void *) cl)) { 539 if (ioctl( getSocket(), HCIGETCONNLIST, (void *) cl)) {
540 emit error( tr("Can't get connection list") ); 540 emit error( tr("Can't get connection list") );
541 break; 541 break;
542 } 542 }
543 543
544 for ( int k = 0; k < cl->conn_num; k++, ci++) { 544 for ( int k = 0; k < cl->conn_num; k++, ci++) {
545 545
546 if( ci->state != BT_CONNECTED ) { 546 if( ci->state != BT_CONNECTED ) {
547 // not yet connected 547 // not yet connected
548 continue; 548 continue;
549 } 549 }
550 550
551 Addr.setBDAddr( ci->bdaddr ); 551 Addr.setBDAddr( ci->bdaddr );
552 P = findPeer( Addr ); 552 P = findPeer( Addr );
553 if( ! P ) { 553 if( ! P ) {
554 // peer not yet known -> add 554 // peer not yet known -> add
555 P = new OTPeer( this ); 555 P = new OTPeer( this );
556 addPeer( P ); 556 addPeer( P );
557 P->setAddress( Addr ); 557 P->setAddress( Addr );
558 // infoQueue.push_back(info); 558 // infoQueue.push_back(info);
559 P->setName( AllDrivers[i]->getPeerName( Addr ) ); 559 P->setName( AllDrivers[i]->getPeerName( Addr ) );
560 } 560 }
561 P->setState( OTPeer::Peer_Up ); 561 P->setState( OTPeer::Peer_Up );
562 P->setConnectedTo( AllDrivers[i] ); 562 P->setConnectedTo( AllDrivers[i] );
563 } 563 }
564 } 564 }
565 565
566 free( cl ); 566 free( cl );
567} 567}
568 568
569void OTGateway::loadKnownPeers( void ) { 569void OTGateway::loadKnownPeers( void ) {
570 QDir SaveDir = QDir::home(); 570 QDir SaveDir = QDir::home();
571 571
572 if( ! SaveDir.exists( "Settings" ) ) { 572 if( ! SaveDir.exists( "Settings" ) ) {
573 return; 573 return;
574 } 574 }
575 SaveDir.cd( "Settings" ); 575 SaveDir.cd( "Settings" );
576 576
577 if( ! SaveDir.exists( "opietooth" ) ) { 577 if( ! SaveDir.exists( "opietooth" ) ) {
578 return; 578 return;
579 } 579 }
580 SaveDir.cd( "opietooth" ); 580 SaveDir.cd( "opietooth" );
581 581
582 QFile F( SaveDir.path() + "/SeenDevices.conf" ); 582 QFile F( SaveDir.path() + "/SeenDevices.conf" );
583 583
584 if( F.open( IO_ReadOnly ) ) { 584 if( F.open( IO_ReadOnly ) ) {
585 QTextStream TS(&F); 585 QTextStream TS(&F);
586 long count; 586 long count;
587 587
588 count = TS.readLine().toLong(); 588 count = TS.readLine().toLong();
589 589
590 while( count > 0 ) { 590 while( count > 0 ) {
591 addPeer( new OTPeer( TS, this ) ); 591 addPeer( new OTPeer( TS, this ) );
592 count --; 592 count --;
593 } 593 }
594 } 594 }
595 595
596 AllPeersModified = 0; 596 AllPeersModified = 0;
597} 597}
598 598
599void OTGateway::saveKnownPeers( void ) { 599void OTGateway::saveKnownPeers( void ) {
600 QDir SaveDir = QDir::home(); 600 QDir SaveDir = QDir::home();
601 601
602 if( ! SaveDir.exists( "Settings" ) ) { 602 if( ! SaveDir.exists( "Settings" ) ) {
603 SaveDir.mkdir( "Settings" ); 603 SaveDir.mkdir( "Settings" );
604 } 604 }
605 SaveDir.cd( "Settings" ); 605 SaveDir.cd( "Settings" );
606 606
607 if( ! SaveDir.exists( "opietooth" ) ) { 607 if( ! SaveDir.exists( "opietooth" ) ) {
608 SaveDir.mkdir( "opietooth" ); 608 SaveDir.mkdir( "opietooth" );
609 } 609 }
610 SaveDir.cd( "opietooth" ); 610 SaveDir.cd( "opietooth" );
611 611
612 QFile F( SaveDir.path() + "/SeenDevices.conf" ); 612 QFile F( SaveDir.path() + "/SeenDevices.conf" );
613 613
614 if( F.open( IO_WriteOnly | IO_Truncate ) ) { 614 if( F.open( IO_WriteOnly | IO_Truncate ) ) {
615 QTextStream TS(&F); 615 QTextStream TS(&F);
616 QString S; 616 QString S;
617 617
618 TS << AllPeers.count() << endl; 618 TS << AllPeers.count() << endl;
619 619
620 for( unsigned int i = 0; 620 for( unsigned int i = 0;
621 i < AllPeers.count(); 621 i < AllPeers.count();
622 i ++ ) { 622 i ++ ) {
623 AllPeers[i]->save( TS ); 623 AllPeers[i]->save( TS );
624 } 624 }
625 AllPeersModified = 0; 625 AllPeersModified = 0;
626 } 626 }
627 AllPeersModified = 0; 627 AllPeersModified = 0;
628} 628}
629 629
630int OTGateway::connectedToRFCommChannel( const OTDeviceAddress & Addr, 630int OTGateway::connectedToRFCommChannel( const OTDeviceAddress & Addr,
631 int channel ) { 631 int channel ) {
632 632
633 int s; 633 int s;
634 634
635 if( (s = ::socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_RFCOMM)) < 0 ) { 635 if( (s = ::socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_RFCOMM)) < 0 ) {
636 emit error( tr("Can't open RFCOMM control socket") ); 636 emit error( tr("Can't open RFCOMM control socket") );
637 return 0; 637 return 0;
638 } 638 }
639 639
640 // get all rfcomm devices 640 // get all rfcomm devices
641 { struct rfcomm_dev_list_req *dl; 641 { struct rfcomm_dev_list_req *dl;
642 struct rfcomm_dev_info *di, *dr; 642 struct rfcomm_dev_info *di, *dr;
643 int i; 643 int i;
644 644
645 dl = (struct rfcomm_dev_list_req *)alloca( 645 dl = (struct rfcomm_dev_list_req *)alloca(
646 sizeof(*dl) + RFCOMM_MAX_DEV * sizeof(*di)); 646 sizeof(*dl) + RFCOMM_MAX_DEV * sizeof(*di));
647 memset( dl, 0, sizeof(*dl) + RFCOMM_MAX_DEV * sizeof(*di) ); 647 memset( dl, 0, sizeof(*dl) + RFCOMM_MAX_DEV * sizeof(*di) );
648 dl->dev_num = RFCOMM_MAX_DEV; 648 dl->dev_num = RFCOMM_MAX_DEV;
649 di = dl->dev_info; 649 di = dl->dev_info;
650 650
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 @@
1//-*-c++-*- 1//-*-c++-*-
2/*************************************************************************** 2/***************************************************************************
3 * Copyright (C) 2003 by Fred Schaettgen * 3 * Copyright (C) 2003 by Fred Schaettgen *
4 * kdebluetooth@schaettgen.de * 4 * kdebluetooth@schaettgen.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by * 7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or * 8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. * 9 * (at your option) any later version. *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12#include <qbuffer.h> 12#include <qbuffer.h>
13#include <qtimer.h> 13#include <qtimer.h>
14#include <qdatastream.h> 14#include <qdatastream.h>
15#include <opie2/odebug.h> 15#include <opie2/odebug.h>
16 16
17#include <bluezlib.h> 17#include <bluezlib.h>
18 18
19// #include "deviceaddress.h" 19// #include "deviceaddress.h"
20#include <OTHCISocket.h> 20#include <OTHCISocket.h>
21#include <OTDriver.h> 21#include <OTDriver.h>
22 22
23using namespace Opietooth2; 23using namespace Opietooth2;
24 24
25OTHCISocket::OTHCISocket( OTDriver * D ) : 25OTHCISocket::OTHCISocket( OTDriver * D ) :
26 QObject( D, D->devname() ) { 26 QObject( D, D->devname() ) {
27 BStatusSet = false; 27 BStatusSet = false;
28 Driver = D; 28 Driver = D;
29 HCIReadNotifier = 0; 29 HCIReadNotifier = 0;
30} 30}
31 31
32OTHCISocket::~OTHCISocket() { 32OTHCISocket::~OTHCISocket() {
33 close(); 33 close();
34} 34}
35 35
36void OTHCISocket::close() { 36void OTHCISocket::close() {
37 owarn << "OTHCISocket::close()" << oendl; 37 odebug << "OTHCISocket::close()" << oendl;
38 if( HCIReadNotifier ) { 38 if( HCIReadNotifier ) {
39 delete HCIReadNotifier; 39 delete HCIReadNotifier;
40 } 40 }
41 41
42 if( HCISocket.isValid() ) { 42 if( HCISocket.isValid() ) {
43 HCISocket.close(); 43 HCISocket.close();
44 } 44 }
45} 45}
46 46
47bool OTHCISocket::open() { 47bool OTHCISocket::open() {
48 48
49 owarn << "OTHCISocket::open()" << oendl; 49 odebug << "OTHCISocket::open()" << oendl;
50 int s; 50 int s;
51 51
52 s = ::socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); 52 s = ::socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
53 53
54 if (s < 0) { 54 if (s < 0) {
55 emit error( tr( "Error creating socket on %1 : %2 %3"). 55 emit error( tr( "Error creating socket on %1 : %2 %3").
56 arg( Driver->devname() ). 56 arg( Driver->devname() ).
57 arg( errno ). 57 arg( errno ).
58 arg( strerror(errno) ) 58 arg( strerror(errno) )
59 ); 59 );
60 return false; 60 return false;
61 } 61 }
62 62
63 /* Bind socket to the HCI device */ 63 /* Bind socket to the HCI device */
64 struct sockaddr_hci sa; 64 struct sockaddr_hci sa;
65 sa.hci_family = AF_BLUETOOTH; 65 sa.hci_family = AF_BLUETOOTH;
66 sa.hci_dev = Driver->devId(); 66 sa.hci_dev = Driver->devId();
67 if (bind(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) { 67 if (bind(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
68 ::close(s); 68 ::close(s);
69 emit error( tr( "Error binding to socket to %1 : %2 %3"). 69 emit error( tr( "Error binding to socket to %1 : %2 %3").
70 arg( Driver->devname() ). 70 arg( Driver->devname() ).
71 arg( errno ). 71 arg( errno ).
72 arg( strerror(errno) ) 72 arg( strerror(errno) )
73 ); 73 );
74 return false; 74 return false;
75 } 75 }
76 76
77 struct hci_filter flt; 77 struct hci_filter flt;
78 hci_filter_clear(&flt); 78 hci_filter_clear(&flt);
79 hci_filter_set_ptype(HCI_EVENT_PKT, &flt); 79 hci_filter_set_ptype(HCI_EVENT_PKT, &flt);
80 hci_filter_all_events(&flt); 80 hci_filter_all_events(&flt);
81 if( setsockopt(s, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0 ) { 81 if( setsockopt(s, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0 ) {
82 ::close(s); 82 ::close(s);
83 emit error( tr( "HCI filter setup failed on %1 : %2 %3"). 83 emit error( tr( "HCI filter setup failed on %1 : %2 %3").
84 arg( Driver->devname() ). 84 arg( Driver->devname() ).
85 arg( errno ). 85 arg( errno ).
86 arg( strerror(errno) ) 86 arg( strerror(errno) )
87 ); 87 );
88 return false; 88 return false;
89 } 89 }
90 90
91 if( HCIReadNotifier ) { 91 if( HCIReadNotifier ) {
92 delete HCIReadNotifier; 92 delete HCIReadNotifier;
93 } 93 }
94 94
95 HCISocket.setSocket(s, QSocketDevice::Datagram); 95 HCISocket.setSocket(s, QSocketDevice::Datagram);
96 HCIReadNotifier = new QSocketNotifier( 96 HCIReadNotifier = new QSocketNotifier(
97 s, QSocketNotifier::Read, this); 97 s, QSocketNotifier::Read, this);
98 98
99 connect( HCIReadNotifier, 99 connect( HCIReadNotifier,
100 SIGNAL(activated(int)), 100 SIGNAL(activated(int)),
101 this, 101 this,
102 SLOT(slotSocketActivated()) 102 SLOT(slotSocketActivated())
103 ); 103 );
104 104
105 //connect(hciSocket, SIGNAL(error(int)), 105 //connect(hciSocket, SIGNAL(error(int)),
106 // this, SLOT(slotSocketError(int))); 106 // this, SLOT(slotSocketError(int)));
107 //connect(hciSocket, SIGNAL(connectionClosed()), 107 //connect(hciSocket, SIGNAL(connectionClosed()),
108 // this, SLOT(slotConnectionClosed())); 108 // this, SLOT(slotConnectionClosed()));
109 //hciSocket->setSocket(s); 109 //hciSocket->setSocket(s);
110 110
111 return true; 111 return true;
112} 112}
113 113
114void OTHCISocket::slotSocketError(int e) { 114void OTHCISocket::slotSocketError(int e) {
115 close(); 115 close();
116 emit error( tr( "HCI socket error 0x%1 on %1 : %2 %3"). 116 emit error( tr( "HCI socket error 0x%1 on %1 : %2 %3").
117 arg(e,2,16). 117 arg(e,2,16).
118 arg( Driver->devname() ). 118 arg( Driver->devname() ).
119 arg( errno ). 119 arg( errno ).
120 arg( strerror(errno) ) 120 arg( strerror(errno) )
121 ); 121 );
122} 122}
123 123
124void OTHCISocket::slotSocketActivated() { 124void OTHCISocket::slotSocketActivated() {
125 125
126 QSocketDevice::Error err = HCISocket.error(); 126 QSocketDevice::Error err = HCISocket.error();
127 127
128 if( (err == QSocketDevice::NoError ) && 128 if( (err == QSocketDevice::NoError ) &&
129 ( HCISocket.isValid() ) ) { 129 ( HCISocket.isValid() ) ) {
130 //kdDebug() << "HCI socket ready read." << endl; 130 //kdDebug() << "HCI socket ready read." << endl;
131 131
132 unsigned char buf[512]; 132 unsigned char buf[512];
133 int psize = HCISocket.readBlock((char*)buf, 512); 133 int psize = HCISocket.readBlock((char*)buf, 512);
134 134
135 if (psize <= 0) { 135 if (psize <= 0) {
136 slotSocketError(HCISocket.error()); 136 slotSocketError(HCISocket.error());
137 HCISocket.close(); 137 HCISocket.close();
138 return; 138 return;
139 } 139 }
140 140
141 //unsigned char packetType = buf[0]; 141 //unsigned char packetType = buf[0];
142 unsigned char eventCode = buf[1]; 142 unsigned char eventCode = buf[1];
143 unsigned char len = buf[2]; 143 unsigned char len = buf[2];
144 144
145 if (psize-3 == len) { 145 if (psize-3 == len) {
146 146
147 QByteArray databuf; 147 QByteArray databuf;
148 databuf.duplicate((char*)(buf+3), len); 148 databuf.duplicate((char*)(buf+3), len);
149 emit event(eventCode, databuf); 149 emit event(eventCode, databuf);
150 if (eventCode == EVT_CMD_STATUS) { 150 if (eventCode == EVT_CMD_STATUS) {
151 updateStatus( databuf ); 151 updateStatus( databuf );
152 } 152 }
153 } else { 153 } else {
154 owarn << "Error reading hci packet: packetSize(" 154 odebug << "Error reading hci packet: packetSize("
155 << psize 155 << psize
156 << ")-3 != dataSize(" 156 << ")-3 != dataSize("
157 << len 157 << len
158 << ")" 158 << ")"
159 << oendl; 159 << oendl;
160 } 160 }
161 } else if (err == QSocketDevice::NoError) { 161 } else if (err == QSocketDevice::NoError) {
162 slotConnectionClosed(); 162 slotConnectionClosed();
163 } else { 163 } else {
164 HCISocket.close(); 164 HCISocket.close();
165 slotSocketError(err); 165 slotSocketError(err);
166 } 166 }
167} 167}
168 168
169void OTHCISocket::updateStatus(const QByteArray& data) { 169void OTHCISocket::updateStatus(const QByteArray& data) {
170 170
171 QDataStream stream(data, IO_ReadOnly); 171 QDataStream stream(data, IO_ReadOnly);
172 stream.setByteOrder(QDataStream::LittleEndian); 172 stream.setByteOrder(QDataStream::LittleEndian);
173 Q_UINT8 status, dummy; 173 Q_UINT8 status, dummy;
174 Q_UINT16 opcode; 174 Q_UINT16 opcode;
175 175
176 BStatusSet = true; 176 BStatusSet = true;
177 177
178 stream >> status >> dummy >> opcode; 178 stream >> status >> dummy >> opcode;
179 //kdDebug() << "updatestatus opcode=" << uint32_t(opcode) << endl; 179 //kdDebug() << "updatestatus opcode=" << uint32_t(opcode) << endl;
180 LastStatus = status; 180 LastStatus = status;
181 LastStatusOgf = cmd_opcode_ogf(opcode); 181 LastStatusOgf = cmd_opcode_ogf(opcode);
182 LastStatusOcf = cmd_opcode_ocf(opcode); 182 LastStatusOcf = cmd_opcode_ocf(opcode);
183} 183}
184 184
185void OTHCISocket::slotConnectionClosed() { 185void OTHCISocket::slotConnectionClosed() {
186 owarn << "HCI connection closed." << oendl; 186 odebug << "HCI connection closed." << oendl;
187 emit connectionClosed(); 187 emit connectionClosed();
188} 188}
189 189
190void OTHCISocket::readEvent() { 190void OTHCISocket::readEvent() {
191 191
192 if (HCIReadNotifier) { 192 if (HCIReadNotifier) {
193 slotSocketActivated(); 193 slotSocketActivated();
194 } 194 }
195} 195}
196 196
197bool OTHCISocket::sendCommand( unsigned char ogf, 197bool OTHCISocket::sendCommand( unsigned char ogf,
198 unsigned short ocf, 198 unsigned short ocf,
199 QByteArray buf 199 QByteArray buf
200 ) { 200 ) {
201 QBuffer packet; 201 QBuffer packet;
202 QDataStream stream(&packet); 202 QDataStream stream(&packet);
203 203
204 stream.setByteOrder(QDataStream::LittleEndian); 204 stream.setByteOrder(QDataStream::LittleEndian);
205 packet.open(IO_WriteOnly); 205 packet.open(IO_WriteOnly);
206 206
207 if (buf.size() > 255) return false; 207 if (buf.size() > 255) return false;
208 208
209 //kdDebug() << "sendCommand. ogf=" << ogf << " ocf=" << ocf << endl; 209 //kdDebug() << "sendCommand. ogf=" << ogf << " ocf=" << ocf << endl;
210 Q_UINT16 opcode = cmd_opcode_pack(ogf, ocf); 210 Q_UINT16 opcode = cmd_opcode_pack(ogf, ocf);
211 Q_UINT8 pType = HCI_COMMAND_PKT; 211 Q_UINT8 pType = HCI_COMMAND_PKT;
212 Q_UINT8 buflen = buf.size(); 212 Q_UINT8 buflen = buf.size();
213 213
214 stream << pType << opcode << buflen; 214 stream << pType << opcode << buflen;
215 stream.writeRawBytes(buf.data(), buflen); 215 stream.writeRawBytes(buf.data(), buflen);
216 packet.close(); 216 packet.close();
217 HCISocket.writeBlock((const char*)packet.buffer(), 217 HCISocket.writeBlock((const char*)packet.buffer(),
218 packet.buffer().size()); 218 packet.buffer().size());
219 return true; 219 return true;
220} 220}
221 221
222bool OTHCISocket::readStatus( unsigned char ogf, 222bool OTHCISocket::readStatus( unsigned char ogf,
223 unsigned short ocf, 223 unsigned short ocf,
224 int *status, 224 int *status,
225 int timeout_ms) { 225 int timeout_ms) {
226 QTimer timer; 226 QTimer timer;
227 227
228 timer.start(timeout_ms, true); 228 timer.start(timeout_ms, true);
229 BStatusSet = false; 229 BStatusSet = false;
230 230
231 while (timer.isActive() && HCISocket.isValid()) { 231 while (timer.isActive() && HCISocket.isValid()) {
232 232
233 owarn << "OTHCISocket::readStatus()" << oendl; 233 odebug << "OTHCISocket::readStatus()" << oendl;
234 bool timeout = false; 234 bool timeout = false;
235 235
236 if( HCISocket.bytesAvailable() == 0) { 236 if( HCISocket.bytesAvailable() == 0) {
237 int rv = HCISocket.waitForMore(timeout_ms); 237 int rv = HCISocket.waitForMore(timeout_ms);
238 timeout = (rv == 0); 238 timeout = (rv == 0);
239 } 239 }
240 240
241 if (!timeout) { 241 if (!timeout) {
242 slotSocketActivated(); 242 slotSocketActivated();
243 } 243 }
244 244
245 if( BStatusSet == true && 245 if( BStatusSet == true &&
246 ogf == LastStatusOgf && 246 ogf == LastStatusOgf &&
247 ocf == LastStatusOcf) { 247 ocf == LastStatusOcf) {
248 *status = LastStatus; 248 *status = LastStatus;
249 owarn << "OTHCISocket::readStatus(ogf=" 249 odebug << "OTHCISocket::readStatus(ogf="
250 << ogf 250 << ogf
251 << ",ocf=" 251 << ",ocf="
252 << ocf 252 << ocf
253 << ",timeout=" 253 << ",timeout="
254 << LastStatus 254 << LastStatus
255 << ")" 255 << ")"
256 << oendl; 256 << oendl;
257 return true; 257 return true;
258 } 258 }
259 } 259 }
260 260
261 owarn << "OTHCISocket::readStatus(ogf=" 261 odebug << "OTHCISocket::readStatus(ogf="
262 << ogf 262 << ogf
263 << ",ocf=" 263 << ",ocf="
264 << ocf 264 << ocf
265 << ",timeout=" 265 << ",timeout="
266 << LastStatus 266 << LastStatus
267 << ") : timeout " 267 << ") : timeout "
268 << oendl; 268 << oendl;
269 return false; 269 return false;
270} 270}
271 271
272int OTHCISocket::socket() { 272int OTHCISocket::socket() {
273 return HCISocket.socket(); 273 return HCISocket.socket();
274} 274}
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 @@
1//-*-c++-*- 1//-*-c++-*-
2/*************************************************************************** 2/***************************************************************************
3 * Copyright (C) 2003 by Fred Schaettgen * 3 * Copyright (C) 2003 by Fred Schaettgen *
4 * kdebluetooth@schaettgen.de * 4 * kdebluetooth@schaettgen.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by * 7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or * 8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. * 9 * (at your option) any later version. *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12 12
13#include <qcstring.h> 13#include <qcstring.h>
14#include <qsocket.h> 14#include <qsocket.h>
15#include <qdatetime.h> 15#include <qdatetime.h>
16#include <qtimer.h> 16#include <qtimer.h>
17#include <qthread.h> 17#include <qthread.h>
18#include <qapplication.h> 18#include <qapplication.h>
19 19
20#include <bluezlib.h> 20#include <bluezlib.h>
21 21
22#include <OTGateway.h> 22#include <OTGateway.h>
23#include <OTDriver.h> 23#include <OTDriver.h>
24#include <OTPeer.h> 24#include <OTPeer.h>
25#include <OTHCISocket.h> 25#include <OTHCISocket.h>
26#include <OTInquiry.h> 26#include <OTInquiry.h>
27 27
28#include <opie2/odebug.h> 28#include <opie2/odebug.h>
29 29
30using namespace Opietooth2; 30using namespace Opietooth2;
31 31
32#define max(a,b) (((a)>(b)) ? (a) : (b)) 32#define max(a,b) (((a)>(b)) ? (a) : (b))
33#define min(a,b) (((a)>(b)) ? (b) : (a)) 33#define min(a,b) (((a)>(b)) ? (b) : (a))
34 34
35OTInquiry::OTInquiry( OTDriver * Drv ) : QObject( Drv ) { 35OTInquiry::OTInquiry( OTDriver * Drv ) : QObject( Drv ) {
36 36
37 reset(); 37 reset();
38 38
39 InquiryTimeoutTimer = new QTimer(this); 39 InquiryTimeoutTimer = new QTimer(this);
40 40
41 connect( InquiryTimeoutTimer, 41 connect( InquiryTimeoutTimer,
42 SIGNAL(timeout()), 42 SIGNAL(timeout()),
43 this, 43 this,
44 SLOT(slotInquiryTimeout())); 44 SLOT(slotInquiryTimeout()));
45 45
46 Driver = Drv; 46 Driver = Drv;
47 Socket = Drv->openSocket(); 47 Socket = Drv->openSocket();
48 Socket->open(); 48 Socket->open();
49 49
50 connect( Socket, 50 connect( Socket,
51 SIGNAL( event(unsigned char, QByteArray)), 51 SIGNAL( event(unsigned char, QByteArray)),
52 this, 52 this,
53 SLOT(slotHCIEvent(unsigned char, QByteArray))); 53 SLOT(slotHCIEvent(unsigned char, QByteArray)));
54} 54}
55 55
56OTInquiry::~OTInquiry() { 56OTInquiry::~OTInquiry() {
57 stopInquiring(); 57 stopInquiring();
58} 58}
59 59
60void OTInquiry::stopInquiring( void ) { 60void OTInquiry::stopInquiring( void ) {
61 if( Socket ) { 61 if( Socket ) {
62 owarn << "Stop inquiry" << oendl; 62 odebug << "Stop inquiry" << oendl;
63 Driver->closeSocket(); 63 Driver->closeSocket();
64 Socket = 0; 64 Socket = 0;
65 } 65 }
66} 66}
67 67
68bool OTInquiry::inquire( double timeout, int numResponses, int lap) { 68bool OTInquiry::inquire( double timeout, int numResponses, int lap) {
69 69
70 QByteArray cmdBuf(5); 70 QByteArray cmdBuf(5);
71 71
72 cmdBuf[0] = lap & 0xFF; 72 cmdBuf[0] = lap & 0xFF;
73 cmdBuf[1] = (lap >> 8) & 0xFF; 73 cmdBuf[1] = (lap >> 8) & 0xFF;
74 cmdBuf[2] = (lap >> 16) & 0xFF; 74 cmdBuf[2] = (lap >> 16) & 0xFF;
75 cmdBuf[3] = max(0x01, min(0x30, int(timeout/1.28))); 75 cmdBuf[3] = max(0x01, min(0x30, int(timeout/1.28)));
76 cmdBuf[4] = (unsigned char)numResponses; 76 cmdBuf[4] = (unsigned char)numResponses;
77 77
78 owarn << "Send HCI inquiry command. wait for " << cmdBuf[3] << oendl; 78 odebug << "Send HCI inquiry command. wait for " << cmdBuf[3] << oendl;
79 79
80 Socket->sendCommand(0x01, 0x0001, cmdBuf); 80 Socket->sendCommand(0x01, 0x0001, cmdBuf);
81 81
82 int status; 82 int status;
83 83
84 if( Socket->readStatus(0x01, 0x0001, &status)) { 84 if( Socket->readStatus(0x01, 0x0001, &status)) {
85 if (status == 0) { 85 if (status == 0) {
86 SuccessfullyStarted = true; 86 SuccessfullyStarted = true;
87 InquiryTimeoutTimer->start( int(1000*(timeout+1.0)), true); 87 InquiryTimeoutTimer->start( int(1000*(timeout+1.0)), true);
88 return true; 88 return true;
89 } 89 }
90 else { 90 else {
91 QString S =QString().sprintf( "%x", status ); 91 QString S =QString().sprintf( "%x", status );
92 owarn << "OTInquiry::inquiry() failed: 0x" << S << oendl; 92 odebug << "OTInquiry::inquiry() failed: 0x" << S << oendl;
93 emit finished(); 93 emit finished();
94 return false; 94 return false;
95 } 95 }
96 } else { 96 } else {
97 owarn << "OTInquiry::inquiry(): Timeout." << oendl; 97 odebug << "OTInquiry::inquiry(): Timeout." << oendl;
98 return false; 98 return false;
99 } 99 }
100} 100}
101 101
102bool OTInquiry::isInquiring() { 102bool OTInquiry::isInquiring() {
103 return InquiryTimeoutTimer->isActive(); 103 return InquiryTimeoutTimer->isActive();
104} 104}
105 105
106bool OTInquiry::isFinished() { 106bool OTInquiry::isFinished() {
107 return SuccessfullyStarted && SuccessfullyEnded; 107 return SuccessfullyStarted && SuccessfullyEnded;
108} 108}
109 109
110void OTInquiry::reset() { 110void OTInquiry::reset() {
111 111
112 SuccessfullyStarted = false; 112 SuccessfullyStarted = false;
113 SuccessfullyEnded = false; 113 SuccessfullyEnded = false;
114 //addrCache.clear(); 114 //addrCache.clear();
115 //infoQueue.clear(); 115 //infoQueue.clear();
116} 116}
117 117
118 118
119void OTInquiry::onPeerFound( OTPeer * Peer, bool IsNew ) { 119void OTInquiry::onPeerFound( OTPeer * Peer, bool IsNew ) {
120 emit peerFound( Peer, IsNew ); 120 emit peerFound( Peer, IsNew );
121} 121}
122 122
123void OTInquiry::slotInquiryTimeout() { 123void OTInquiry::slotInquiryTimeout() {
124 emit error( tr( "Timeout while waiting for end of inquiry.") ); 124 emit error( tr( "Timeout while waiting for end of inquiry.") );
125} 125}
126 126
127void OTInquiry::slotHCIEvent(unsigned char eventCode, QByteArray buf) { 127void OTInquiry::slotHCIEvent(unsigned char eventCode, QByteArray buf) {
128 128
129 owarn << "OTInquiry: hci packet received: eventCode=" 129 odebug << "OTInquiry: hci packet received: eventCode="
130 << (unsigned int)eventCode 130 << (unsigned int)eventCode
131 << " packetLength=" 131 << " packetLength="
132 << (unsigned int)buf.size() 132 << (unsigned int)buf.size()
133 << oendl; 133 << oendl;
134 134
135 unsigned char *data = (unsigned char*)buf.data(); 135 unsigned char *data = (unsigned char*)buf.data();
136 switch (eventCode) { 136 switch (eventCode) {
137 case EVT_INQUIRY_COMPLETE: 137 case EVT_INQUIRY_COMPLETE:
138 { unsigned char status = data[0]; 138 { unsigned char status = data[0];
139 owarn << "EVT_INQUIRY_COMPLETE status=" << status << oendl; 139 odebug << "EVT_INQUIRY_COMPLETE status=" << status << oendl;
140 InquiryTimeoutTimer->stop(); 140 InquiryTimeoutTimer->stop();
141 if (status == 0) { 141 if (status == 0) {
142 if( SuccessfullyStarted == true) { 142 if( SuccessfullyStarted == true) {
143 owarn << "OTInquiry ended successfully" << oendl; 143 odebug << "OTInquiry ended successfully" << oendl;
144 SuccessfullyEnded = true; 144 SuccessfullyEnded = true;
145 } 145 }
146 emit finished(); 146 emit finished();
147 } 147 }
148 else { 148 else {
149 emit error( tr( "OTInquiry completed with error (code %1)" ). 149 emit error( tr( "OTInquiry completed with error (code %1)" ).
150 arg(status)); 150 arg(status));
151 } 151 }
152 } 152 }
153 break; 153 break;
154 case EVT_INQUIRY_RESULT: 154 case EVT_INQUIRY_RESULT:
155 { int numResults = data[0]; 155 { int numResults = data[0];
156 OTPeer * P = 0; 156 OTPeer * P = 0;
157 bool IsNew; 157 bool IsNew;
158 OTDeviceAddress Addr; 158 OTDeviceAddress Addr;
159 QString N; 159 QString N;
160 160
161 inquiry_info *results = (inquiry_info*)(data+1); 161 inquiry_info *results = (inquiry_info*)(data+1);
162 162
163 for (int n=0; n<numResults; n++) { 163 for (int n=0; n<numResults; n++) {
164 Addr.setBDAddr( results[n].bdaddr ); 164 Addr.setBDAddr( results[n].bdaddr );
165 165
166 owarn << "INQUIRY_RESULT: " 166 odebug << "INQUIRY_RESULT: "
167 << Addr.toString() 167 << Addr.toString()
168 << oendl; 168 << oendl;
169 169
170 P = Driver->gateway()->findPeer( Addr ); 170 P = Driver->gateway()->findPeer( Addr );
171 171
172 if( P ) { 172 if( P ) {
173 // peer known 173 // peer known
174 if( P->state() != OTPeer::Peer_Up ) { 174 if( P->state() != OTPeer::Peer_Up ) {
175 P->setState( OTPeer::Peer_Up ); 175 P->setState( OTPeer::Peer_Up );
176 } 176 }
177 IsNew = 0; 177 IsNew = 0;
178 } else { 178 } else {
179 IsNew = 1; 179 IsNew = 1;
180 // push the address to the address queue 180 // push the address to the address queue
181 // where it can be consumed by nextNeighbour() 181 // where it can be consumed by nextNeighbour()
182 P = new OTPeer( Driver->gateway() ); 182 P = new OTPeer( Driver->gateway() );
183 P->setState( OTPeer::Peer_Up ); // we just detected it 183 P->setState( OTPeer::Peer_Up ); // we just detected it
184 P->setAddress( Addr ); 184 P->setAddress( Addr );
185 //if( addrCache.find(info.addr) == addrCache.end()) { 185 //if( addrCache.find(info.addr) == addrCache.end()) {
186 // addrCache.insert(info.addr); 186 // addrCache.insert(info.addr);
187 187
188 P->setDeviceClass( (results[n].dev_class[0] << 16) | 188 P->setDeviceClass( (results[n].dev_class[0] << 16) |
189 (results[n].dev_class[1] << 8) | 189 (results[n].dev_class[1] << 8) |
190 (results[n].dev_class[2] << 0) ); 190 (results[n].dev_class[2] << 0) );
191 // infoQueue.push_back(info); 191 // infoQueue.push_back(info);
192 P->setName( Driver->getPeerName( Addr ) ); 192 P->setName( Driver->getPeerName( Addr ) );
193 } 193 }
194 194
195 // call the handler. Emits a signal if not overwritten 195 // call the handler. Emits a signal if not overwritten
196 onPeerFound( P, IsNew ); 196 onPeerFound( P, IsNew );
197 197
198 // } 198 // }
199 } 199 }
200 } 200 }
201 break; 201 break;
202 case EVT_CMD_STATUS : 202 case EVT_CMD_STATUS :
203 { int status = data[0]; 203 { int status = data[0];
204 int numHciCmdPkts = data[1]; 204 int numHciCmdPkts = data[1];
205 int cmdOpcode = *((uint16_t*)(data+2)); 205 int cmdOpcode = *((uint16_t*)(data+2));
206 owarn << "EVT_CMD_STATUS status=" 206 odebug << "EVT_CMD_STATUS status="
207 << status 207 << status
208 << " numPkts=" 208 << " numPkts="
209 << numHciCmdPkts 209 << numHciCmdPkts
210 << " cmdOpcode=" 210 << " cmdOpcode="
211 << cmdOpcode 211 << cmdOpcode
212 << oendl; 212 << oendl;
213 if (cmdOpcode == OCF_INQUIRY) { 213 if (cmdOpcode == OCF_INQUIRY) {
214 214
215 } 215 }
216 } 216 }
217 break; 217 break;
218 } 218 }
219} 219}
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 @@
1//-*-c++-*- 1//-*-c++-*-
2/*************************************************************************** 2/***************************************************************************
3 * Copyright (C) 2003 by Fred Schaettgen * 3 * Copyright (C) 2003 by Fred Schaettgen *
4 * kdebluetooth@schaettgen.de * 4 * kdebluetooth@schaettgen.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by * 7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or * 8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. * 9 * (at your option) any later version. *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12#include <assert.h> 12#include <assert.h>
13#include <sys/poll.h> 13#include <sys/poll.h>
14#include <string.h> 14#include <string.h>
15 15
16#include <bluezlib.h> 16#include <bluezlib.h>
17#include <qarray.h> 17#include <qarray.h>
18#include <qtextstream.h> 18#include <qtextstream.h>
19 19
20#include <opie2/odebug.h> 20#include <opie2/odebug.h>
21 21
22#include <OTDeviceAddress.h> 22#include <OTDeviceAddress.h>
23#include <OTSDPAttribute.h> 23#include <OTSDPAttribute.h>
24#include <OTSDPService.h> 24#include <OTSDPService.h>
25#include <OTPeer.h> 25#include <OTPeer.h>
26#include <OTGateway.h> 26#include <OTGateway.h>
27#include <OTDriver.h> 27#include <OTDriver.h>
28 28
29using namespace Opietooth2; 29using namespace Opietooth2;
30 30
31OTPeer::OTPeer( OTGateway * _OT ) { 31OTPeer::OTPeer( OTGateway * _OT ) {
32 OT = _OT; 32 OT = _OT;
33 State = Peer_Unknown; 33 State = Peer_Unknown;
34 ConnectedTo = 0; 34 ConnectedTo = 0;
35} 35}
36 36
37OTPeer::OTPeer( QTextStream & TS, OTGateway * _OT ) { 37OTPeer::OTPeer( QTextStream & TS, OTGateway * _OT ) {
38 OT = _OT; 38 OT = _OT;
39 State = Peer_Unknown; 39 State = Peer_Unknown;
40 ConnectedTo = 0; 40 ConnectedTo = 0;
41 41
42 load( TS ); 42 load( TS );
43} 43}
44 44
45OTPeer::~OTPeer( ) { 45OTPeer::~OTPeer( ) {
46 46
47} 47}
48 48
49void OTPeer::updateServices( void ) { 49void OTPeer::updateServices( void ) {
50 sdp_session_t *session; 50 sdp_session_t *session;
51 51
52 serviceList.clear(); 52 serviceList.clear();
53 53
54 owarn << "Get services from " << Addr.toString() << oendl; 54 odebug << "Get services from " << Addr.toString() << oendl;
55 55
56 session = sdp_connect( &(OTDeviceAddress::any.getBDAddr()), 56 session = sdp_connect( &(OTDeviceAddress::any.getBDAddr()),
57 &(Addr.getBDAddr()), 57 &(Addr.getBDAddr()),
58 0); 58 0);
59 59
60 if (!session) { 60 if (!session) {
61 owarn << "sdp_connect(" 61 odebug << "sdp_connect("
62 << Addr.toString() 62 << Addr.toString()
63 << ") failed" 63 << ") failed"
64 << oendl; 64 << oendl;
65 return; // error 65 return; // error
66 } 66 }
67 67
68 uint32_t range = 0x0000ffff; 68 uint32_t range = 0x0000ffff;
69 sdp_list_t* attrId = sdp_list_append(0, &range); 69 sdp_list_t* attrId = sdp_list_append(0, &range);
70 70
71 // search all public features 71 // search all public features
72 uuid_t grp; 72 uuid_t grp;
73 sdp_uuid16_create( &grp, PUBLIC_BROWSE_GROUP ); 73 sdp_uuid16_create( &grp, PUBLIC_BROWSE_GROUP );
74 sdp_list_t * search = sdp_list_append(0, &grp ); 74 sdp_list_t * search = sdp_list_append(0, &grp );
75 75
76 // get data from peer 76 // get data from peer
77 sdp_list_t* seq; 77 sdp_list_t* seq;
78 if (sdp_service_search_attr_req( session, 78 if (sdp_service_search_attr_req( session,
79 search, 79 search,
80 SDP_ATTR_REQ_RANGE, 80 SDP_ATTR_REQ_RANGE,
81 attrId, 81 attrId,
82 &seq ) ) { 82 &seq ) ) {
83 owarn << "Service Search failed" << oendl; 83 odebug << "Service Search failed" << oendl;
84 sdp_close(session); 84 sdp_close(session);
85 return; 85 return;
86 } 86 }
87 87
88 sdp_list_free(attrId, 0); 88 sdp_list_free(attrId, 0);
89 sdp_list_free(search, 0); 89 sdp_list_free(search, 0);
90 90
91 // process result 91 // process result
92 sdp_list_t* next = NULL; 92 sdp_list_t* next = NULL;
93 93
94 for (; seq; seq = next) { 94 for (; seq; seq = next) {
95 sdp_record_t *rec = (sdp_record_t *) seq->data; 95 sdp_record_t *rec = (sdp_record_t *) seq->data;
96 96
97 sdp_list_t* attrlist = rec->attrlist; 97 sdp_list_t* attrlist = rec->attrlist;
98 AttributeVector alist; 98 AttributeVector alist;
99 OTSDPService * service; 99 OTSDPService * service;
100 100
101 service = new OTSDPService(); 101 service = new OTSDPService();
102 102
103 for (; attrlist; attrlist = attrlist->next) { 103 for (; attrlist; attrlist = attrlist->next) {
104 int attrID = ((sdp_data_t*)(attrlist->data))->attrId; 104 int attrID = ((sdp_data_t*)(attrlist->data))->attrId;
105 service->addAttribute( 105 service->addAttribute(
106 attrID, 106 attrID,
107 new OTSDPAttribute( (sdp_data_t*)(attrlist->data) ) 107 new OTSDPAttribute( (sdp_data_t*)(attrlist->data) )
108 ); 108 );
109 } 109 }
110 110
111 serviceList.resize( serviceList.size() + 1 ); 111 serviceList.resize( serviceList.size() + 1 );
112 serviceList.insert( serviceList.size() - 1, service ); 112 serviceList.insert( serviceList.size() - 1, service );
113 113
114 next = seq->next; 114 next = seq->next;
115 free(seq); 115 free(seq);
116 sdp_record_free(rec); 116 sdp_record_free(rec);
117 } 117 }
118 sdp_close(session); 118 sdp_close(session);
119} 119}
120 120
121bool OTPeer::hasServiceClassID( const OTUUID & uuid) { 121bool OTPeer::hasServiceClassID( const OTUUID & uuid) {
122 for( unsigned int i = 0; 122 for( unsigned int i = 0;
123 i < serviceList.count(); 123 i < serviceList.count();
124 i ++ ) { 124 i ++ ) {
125 if( serviceList[i]->hasClassID(uuid)) 125 if( serviceList[i]->hasClassID(uuid))
126 return true; 126 return true;
127 } 127 }
128 return false; 128 return false;
129} 129}
130/** Get a vector of Rfcomm channels of the services having "uuid" in the class ID List*/ 130/** Get a vector of Rfcomm channels of the services having "uuid" in the class ID List*/
131QArray<int> OTPeer::rfcommList( const OTUUID & uuid) { 131QArray<int> OTPeer::rfcommList( const OTUUID & uuid) {
132 132
133 QArray<int> rfcommList; 133 QArray<int> rfcommList;
134 unsigned int channel; 134 unsigned int channel;
135 135
136 for( unsigned int i = 0; 136 for( unsigned int i = 0;
137 i < serviceList.count(); 137 i < serviceList.count();
138 i ++ ) { 138 i ++ ) {
139 if( serviceList[i]->hasClassID(uuid)) { 139 if( serviceList[i]->hasClassID(uuid)) {
140 if( serviceList[i]->rfcommChannel(channel) ) { 140 if( serviceList[i]->rfcommChannel(channel) ) {
141 rfcommList.resize( rfcommList.size()+1 ); 141 rfcommList.resize( rfcommList.size()+1 );
142 rfcommList[rfcommList.size()-1] = channel; 142 rfcommList[rfcommList.size()-1] = channel;
143 } 143 }
144 } 144 }
145 } 145 }
146 return rfcommList; 146 return rfcommList;
147} 147}
148 148
149void OTPeer::save( QTextStream & TS ) { 149void OTPeer::save( QTextStream & TS ) {
150 TS << "bdaddr " << address().toString() << endl; 150 TS << "bdaddr " << address().toString() << endl;
151 TS << "name " << name() << endl; 151 TS << "name " << name() << endl;
152 TS << "class " << deviceClass() << endl; 152 TS << "class " << deviceClass() << endl;
153} 153}
154 154
155void OTPeer::load( QTextStream & TS ) { 155void OTPeer::load( QTextStream & TS ) {
156 QString S; 156 QString S;
157 S = TS.readLine(); 157 S = TS.readLine();
158 setAddress( OTDeviceAddress( S.mid( 7 ) ) ); 158 setAddress( OTDeviceAddress( S.mid( 7 ) ) );
159 159
160 S = TS.readLine(); 160 S = TS.readLine();
161 setName( S.mid( 5 ) ); 161 setName( S.mid( 5 ) );
162 162
163 S = TS.readLine(); 163 S = TS.readLine();
164 setDeviceClass( S.mid( 6 ).toLong() ); 164 setDeviceClass( S.mid( 6 ).toLong() );
165} 165}
166 166
167#define MAGICNR -99999 167#define MAGICNR -99999
168#define POLLDELAY 1000 168#define POLLDELAY 1000
169#define PREMAGICNR (MAGICNR+POLLDELAY) 169#define PREMAGICNR (MAGICNR+POLLDELAY)
170 170
171void OTPeer::findOutState( int timeoutInSec, bool Force ) { 171void OTPeer::findOutState( int timeoutInSec, bool Force ) {
172 ProbeFD = -1; 172 ProbeFD = -1;
173 if( Force && ConnectedTo == 0 ) { 173 if( Force && ConnectedTo == 0 ) {
174 State = OTPeer::Peer_Unknown; 174 State = OTPeer::Peer_Unknown;
175 } // else keep state or is connected to us 175 } // else keep state or is connected to us
176 176
177 if( State == OTPeer::Peer_Unknown ) { 177 if( State == OTPeer::Peer_Unknown ) {
178 ProbePhase = 0; 178 ProbePhase = 0;
179 ProbeTimeout = timeoutInSec*1000; 179 ProbeTimeout = timeoutInSec*1000;
180 owarn << "Ping " << address().toString() << oendl; 180 odebug << "Ping " << address().toString() << oendl;
181 startTimer( POLLDELAY ); 181 startTimer( POLLDELAY );
182 } else { 182 } else {
183 ProbeTimeout = 0; 183 ProbeTimeout = 0;
184 startTimer( 0 ); 184 startTimer( 0 );
185 } 185 }
186} 186}
187 187
188#define PINGSIZE 20 188#define PINGSIZE 20
189void OTPeer::timerEvent( QTimerEvent * ev ) { 189void OTPeer::timerEvent( QTimerEvent * ev ) {
190 190
191 ProbeTimeout -= POLLDELAY; 191 ProbeTimeout -= POLLDELAY;
192 192
193 if( State == OTPeer::Peer_Unknown ) { 193 if( State == OTPeer::Peer_Unknown ) {
194 switch( ProbePhase ) { 194 switch( ProbePhase ) {
195 case 0 : // connect nonblock 195 case 0 : // connect nonblock
196 { struct sockaddr_l2 addr; 196 { struct sockaddr_l2 addr;
197 197
198 if (( ProbeFD = ::socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_L2CAP)) < 0) { 198 if (( ProbeFD = ::socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_L2CAP)) < 0) {
199 ProbeTimeout = 0; 199 ProbeTimeout = 0;
200 break; 200 break;
201 } 201 }
202 202
203 memset(&addr, 0, sizeof(addr)); 203 memset(&addr, 0, sizeof(addr));
204 204
205 addr.l2_family = AF_BLUETOOTH; 205 addr.l2_family = AF_BLUETOOTH;
206 addr.l2_bdaddr = OTDeviceAddress::any.getBDAddr(); 206 addr.l2_bdaddr = OTDeviceAddress::any.getBDAddr();
207 207
208 if( ::bind( ProbeFD, (struct sockaddr *) &addr, sizeof(addr)) < 0) { 208 if( ::bind( ProbeFD, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
209 ProbeTimeout = 0; 209 ProbeTimeout = 0;
210 break; 210 break;
211 } 211 }
212 212
213 // non blocking 213 // non blocking
214 if( ::fcntl( ProbeFD, F_SETFL, O_NONBLOCK ) < 0 ) { 214 if( ::fcntl( ProbeFD, F_SETFL, O_NONBLOCK ) < 0 ) {
215 ProbeTimeout = 0; 215 ProbeTimeout = 0;
216 break; 216 break;
217 } 217 }
218 218
219 // to this peer 219 // to this peer
220 addr.l2_bdaddr = address().getBDAddr(); 220 addr.l2_bdaddr = address().getBDAddr();
221 if( ::connect( ProbeFD, (struct sockaddr *) &addr, sizeof(addr)) < 0) { 221 if( ::connect( ProbeFD, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
222 if( errno != EAGAIN && errno != EINPROGRESS ) { 222 if( errno != EAGAIN && errno != EINPROGRESS ) {
223 ProbeTimeout = 0; 223 ProbeTimeout = 0;
224 break; 224 break;
225 } // wait for connect to fail or succeed 225 } // wait for connect to fail or succeed
226 } 226 }
227 } 227 }
228 ProbePhase = 1; // wait for connect 228 ProbePhase = 1; // wait for connect
229 break; 229 break;
230 case 1 : 230 case 1 :
231 { struct pollfd pf[1]; 231 { struct pollfd pf[1];
232 char buf[L2CAP_CMD_HDR_SIZE + PINGSIZE + 20]; 232 char buf[L2CAP_CMD_HDR_SIZE + PINGSIZE + 20];
233 int n; 233 int n;
234 234
235 pf[0].fd = ProbeFD; 235 pf[0].fd = ProbeFD;
236 pf[0].events = POLLOUT; 236 pf[0].events = POLLOUT;
237 if( (n = ::poll(pf, 1, 0)) < 0 ) { 237 if( (n = ::poll(pf, 1, 0)) < 0 ) {
238 owarn << address().toString() 238 odebug << address().toString()
239 << " : errno " 239 << " : errno "
240 << errno 240 << errno
241 << " " 241 << " "
242 << strerror(errno)<<oendl; 242 << strerror(errno)<<oendl;
243 ProbeTimeout = 0; 243 ProbeTimeout = 0;
244 break; 244 break;
245 } 245 }
246 246
247 if( ! n ) { 247 if( ! n ) {
248 // not ready -> try again 248 // not ready -> try again
249 break; 249 break;
250 } 250 }
251 251
252 // send ping 252 // send ping
253 for( unsigned int i = L2CAP_CMD_HDR_SIZE; i < sizeof(buf); i++) 253 for( unsigned int i = L2CAP_CMD_HDR_SIZE; i < sizeof(buf); i++)
254 buf[i] = (i % 40) + 'A'; 254 buf[i] = (i % 40) + 'A';
255 255
256 l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf; 256 l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf;
257 257
258 /* Build command header */ 258 /* Build command header */
259 cmd->code = L2CAP_ECHO_REQ; 259 cmd->code = L2CAP_ECHO_REQ;
260 cmd->ident = *(char *)this; // get some byte 260 cmd->ident = *(char *)this; // get some byte
261 cmd->len = PINGSIZE; 261 cmd->len = PINGSIZE;
262 262
263 /* Send Echo Request */ 263 /* Send Echo Request */
264 if( ::send(ProbeFD, buf, PINGSIZE + L2CAP_CMD_HDR_SIZE, 0) <= 0) { 264 if( ::send(ProbeFD, buf, PINGSIZE + L2CAP_CMD_HDR_SIZE, 0) <= 0) {
265 if( errno == EACCES ) { 265 if( errno == EACCES ) {
266 // permission denied means that we could not 266 // permission denied means that we could not
267 // connect because the device does not allow us 267 // connect because the device does not allow us
268 // but it is UP 268 // but it is UP
269 owarn << address().toString() 269 odebug << address().toString()
270 << " good send error " 270 << " good send error "
271 << errno 271 << errno
272 << " " 272 << " "
273 << strerror( errno) 273 << strerror( errno)
274 << oendl; 274 << oendl;
275 State = OTPeer::Peer_Up; 275 State = OTPeer::Peer_Up;
276 ProbeTimeout = 0; 276 ProbeTimeout = 0;
277 break; 277 break;
278 } else if( errno != EBUSY ) { 278 } else if( errno != EBUSY ) {
279 owarn << address().toString() 279 odebug << address().toString()
280 << " : errno " 280 << " : errno "
281 << errno 281 << errno
282 << " " 282 << " "
283 << strerror(errno) 283 << strerror(errno)
284 << oendl; 284 << oendl;
285 ProbeTimeout = 0; 285 ProbeTimeout = 0;
286 break; 286 break;
287 } // else want some more 287 } // else want some more
288 } 288 }
289 289
290 ProbePhase = 2; // wait for ping reply 290 ProbePhase = 2; // wait for ping reply
291 } 291 }
292 break; 292 break;
293 case 2 : // wait for reply 293 case 2 : // wait for reply
294 { struct pollfd pf[1]; 294 { struct pollfd pf[1];
295 char buf[L2CAP_CMD_HDR_SIZE + PINGSIZE + 20]; 295 char buf[L2CAP_CMD_HDR_SIZE + PINGSIZE + 20];
296 l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf; 296 l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf;
297 int n; 297 int n;
298 298
299 pf[0].fd = ProbeFD; 299 pf[0].fd = ProbeFD;
300 pf[0].events = POLLIN; 300 pf[0].events = POLLIN;
301 if( (n = ::poll(pf, 1, 0)) < 0 ) { 301 if( (n = ::poll(pf, 1, 0)) < 0 ) {
302 owarn << address().toString() 302 odebug << address().toString()
303 << " : errno " 303 << " : errno "
304 << errno 304 << errno
305 << " " 305 << " "
306 << strerror(errno) 306 << strerror(errno)
307 <<oendl; 307 <<oendl;
308 ProbeTimeout = 0; 308 ProbeTimeout = 0;
309 break; 309 break;
310 } 310 }
311 311
312 if( ! n ) { 312 if( ! n ) {
313 // not ready -> try again 313 // not ready -> try again
314 break; 314 break;
315 } 315 }
316 316
317 if( (n = ::recv( ProbeFD, buf, sizeof(buf), 0)) < 0) { 317 if( (n = ::recv( ProbeFD, buf, sizeof(buf), 0)) < 0) {
318 owarn << address().toString() 318 odebug << address().toString()
319 << "errno " 319 << "errno "
320 << errno 320 << errno
321 << " " 321 << " "
322 << strerror(errno) 322 << strerror(errno)
323 << oendl; 323 << oendl;
324 ProbeTimeout = 0; 324 ProbeTimeout = 0;
325 break; 325 break;
326 } 326 }
327 327
328 /* Check for our id */ 328 /* Check for our id */
329 if( cmd->ident != *(char *)this ) 329 if( cmd->ident != *(char *)this )
330 // not our reply 330 // not our reply
331 break; 331 break;
332 332
333 owarn << "reply from " 333 odebug << "reply from "
334 << address().toString() 334 << address().toString()
335 << oendl; 335 << oendl;
336 // whatever reply we get is a valid reply 336 // whatever reply we get is a valid reply
337 State = OTPeer::Peer_Up; 337 State = OTPeer::Peer_Up;
338 ProbeTimeout = 0; 338 ProbeTimeout = 0;
339 } 339 }
340 break; 340 break;
341 } 341 }
342 342
343 if( State != OTPeer::Peer_Unknown ) { 343 if( State != OTPeer::Peer_Unknown ) {
344 ProbeTimeout = 0; 344 ProbeTimeout = 0;
345 } 345 }
346 } 346 }
347 347
348 if( ProbeTimeout <= 0 ) { 348 if( ProbeTimeout <= 0 ) {
349 // regular timeout 349 // regular timeout
350 emit peerStateReport( this ); 350 emit peerStateReport( this );
351 if( State == Peer_Unknown ) { 351 if( State == Peer_Unknown ) {
352 State = Peer_Down; 352 State = Peer_Down;
353 } 353 }
354 if( ProbeFD >= 0 ) { 354 if( ProbeFD >= 0 ) {
355 // requested to stop by caller -> stop probing 355 // requested to stop by caller -> stop probing
356 ::close( ProbeFD ); 356 ::close( ProbeFD );
357 } 357 }
358 // no more waiting 358 // no more waiting
359 killTimer( ev->timerId() ); 359 killTimer( ev->timerId() );
360 } // else sleep some more 360 } // else sleep some more
361} 361}
362 362
363void OTPeer::stopFindingOutState( void ) { 363void OTPeer::stopFindingOutState( void ) {
364 ProbeTimeout = PREMAGICNR; 364 ProbeTimeout = PREMAGICNR;
365} 365}
366 366
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
@@ -284,884 +284,884 @@ OTPairing::OTPairing( QWidget * parent, OTIcons * _IC ) :
284 i ++ ) { 284 i ++ ) {
285 285
286 it = new LinkKeyLVI( i, Pairs_LV ); 286 it = new LinkKeyLVI( i, Pairs_LV );
287 287
288 P = 0; 288 P = 0;
289 D = OT->findDriver( Keys[i].from() ); 289 D = OT->findDriver( Keys[i].from() );
290 290
291 if( D ) { 291 if( D ) {
292 it->setText( 0, D->devname() ); 292 it->setText( 0, D->devname() );
293 293
294 // we are source 294 // we are source
295 P = OT->findPeer( Keys[i].to() ); 295 P = OT->findPeer( Keys[i].to() );
296 296
297 if( P ) { 297 if( P ) {
298 // put name 298 // put name
299 it->setText( 1, P->name() ); 299 it->setText( 1, P->name() );
300 } else { 300 } else {
301 // unknown 301 // unknown
302 it->setText( 1, Keys[i].to().toString() ); 302 it->setText( 1, Keys[i].to().toString() );
303 } 303 }
304 304
305 // and put address as sub 305 // and put address as sub
306 QListViewItem * Sub = new QListViewItem( it ); 306 QListViewItem * Sub = new QListViewItem( it );
307 Sub->setText( 0, D->address().toString() ); 307 Sub->setText( 0, D->address().toString() );
308 Sub->setText( 1, Keys[i].to().toString() ); 308 Sub->setText( 1, Keys[i].to().toString() );
309 } else { 309 } else {
310 // perhaps we are destination 310 // perhaps we are destination
311 D = OT->findDriver( Keys[i].to() ); 311 D = OT->findDriver( Keys[i].to() );
312 312
313 if( D ) { 313 if( D ) {
314 it->setText( 1, D->devname() ); 314 it->setText( 1, D->devname() );
315 315
316 // we are source 316 // we are source
317 P = OT->findPeer( Keys[i].from() ); 317 P = OT->findPeer( Keys[i].from() );
318 318
319 if( P ) { 319 if( P ) {
320 // put name 320 // put name
321 it->setText( 0, P->name() ); 321 it->setText( 0, P->name() );
322 } else { 322 } else {
323 // unknown 323 // unknown
324 it->setText( 0, Keys[i].from().toString() ); 324 it->setText( 0, Keys[i].from().toString() );
325 } 325 }
326 326
327 // and put address as sub 327 // and put address as sub
328 QListViewItem * Sub = new QListViewItem( it ); 328 QListViewItem * Sub = new QListViewItem( it );
329 Sub->setText( 0, Keys[i].from().toString() ); 329 Sub->setText( 0, Keys[i].from().toString() );
330 Sub->setText( 1, D->address().toString() ); 330 Sub->setText( 1, D->address().toString() );
331 } else { 331 } else {
332 // nor source nor destination -> unknown 332 // nor source nor destination -> unknown
333 it->setText( 0, Keys[i].from().toString() ); 333 it->setText( 0, Keys[i].from().toString() );
334 it->setText( 1, Keys[i].to().toString() ); 334 it->setText( 1, Keys[i].to().toString() );
335 } 335 }
336 } 336 }
337 } 337 }
338} 338}
339 339
340 340
341OTPairing::~OTPairing() { 341OTPairing::~OTPairing() {
342 if( MyIcons ) 342 if( MyIcons )
343 delete Icons; 343 delete Icons;
344 OTGateway::releaseOTGateway(); 344 OTGateway::releaseOTGateway();
345} 345}
346 346
347void OTPairing::SLOT_Unpair( ) { 347void OTPairing::SLOT_Unpair( ) {
348 // find selected pair 348 // find selected pair
349 349
350 QListViewItem * it = Pairs_LV->firstChild(); 350 QListViewItem * it = Pairs_LV->firstChild();
351 while( it ) { 351 while( it ) {
352 if( it->isSelected() ) { 352 if( it->isSelected() ) {
353 // confirm ? 353 // confirm ?
354 if( QMessageBox::warning(0, 354 if( QMessageBox::warning(0,
355 tr("Break pairing"), 355 tr("Break pairing"),
356 tr("Sure ?"), 356 tr("Sure ?"),
357 tr("Yes, break"), 357 tr("Yes, break"),
358 tr("No, don't break") ) == 0 ) { 358 tr("No, don't break") ) == 0 ) {
359 LinkKeyLVI * KPIt = (LinkKeyLVI *)it; 359 LinkKeyLVI * KPIt = (LinkKeyLVI *)it;
360 // break 360 // break
361 OT->removeLinkKey( KPIt->index() ); 361 OT->removeLinkKey( KPIt->index() );
362 delete KPIt; 362 delete KPIt;
363 } 363 }
364 return; 364 return;
365 } 365 }
366 it= it->nextSibling(); 366 it= it->nextSibling();
367 } 367 }
368} 368}
369 369
370// 370//
371// 371//
372// 372//
373// 373//
374// 374//
375 375
376OTScan::OTScan( QWidget * parent, OTIcons * _IC ) : 376OTScan::OTScan( QWidget * parent, OTIcons * _IC ) :
377 OTScanGUI( parent ), Filter() { 377 OTScanGUI( parent ), Filter() {
378 378
379 OT = OTGateway::getOTGateway(); 379 OT = OTGateway::getOTGateway();
380 Icons = (_IC ) ? _IC : new OTIcons(); 380 Icons = (_IC ) ? _IC : new OTIcons();
381 MyIcons = (_IC == 0 ); 381 MyIcons = (_IC == 0 );
382 DetectedPeers_LV->header()->hide(); 382 DetectedPeers_LV->header()->hide();
383 Current = 0; 383 Current = 0;
384 SelectedPeer = 0; 384 SelectedPeer = 0;
385 SelectedChannel = 0; 385 SelectedChannel = 0;
386 386
387 StrengthTimer = new QTimer( this ); 387 StrengthTimer = new QTimer( this );
388 connect( StrengthTimer, 388 connect( StrengthTimer,
389 SIGNAL( timeout()), 389 SIGNAL( timeout()),
390 this, 390 this,
391 SLOT( SLOT_UpdateStrength()) 391 SLOT( SLOT_UpdateStrength())
392 ); 392 );
393 393
394 connect( OT, 394 connect( OT,
395 SIGNAL( detectedPeer( OTPeer *, bool )), 395 SIGNAL( detectedPeer( OTPeer *, bool )),
396 this, 396 this,
397 SLOT( SLOT_NewPeer( OTPeer *, bool )) 397 SLOT( SLOT_NewPeer( OTPeer *, bool ))
398 ); 398 );
399 connect( OT, 399 connect( OT,
400 SIGNAL( finishedDetecting()), 400 SIGNAL( finishedDetecting()),
401 this, 401 this,
402 SLOT( SLOT_FinishedDetecting()) 402 SLOT( SLOT_FinishedDetecting())
403 ); 403 );
404 404
405 // populate with peers we already know about 405 // populate with peers we already know about
406 const PeerVector & P = OT->peers(); 406 const PeerVector & P = OT->peers();
407 for( unsigned int i = 0; 407 for( unsigned int i = 0;
408 i < P.count(); 408 i < P.count();
409 i ++ ) { 409 i ++ ) {
410 SLOT_NewPeer( P[i], TRUE ); 410 SLOT_NewPeer( P[i], TRUE );
411 } 411 }
412 412
413 // populate State fram 413 // populate State fram
414 { QHBoxLayout * H =new QHBoxLayout( State_Frm ); 414 { QHBoxLayout * H =new QHBoxLayout( State_Frm );
415 415
416 Paired_Led = new OLedBox( green, State_Frm ); 416 Paired_Led = new OLedBox( green, State_Frm );
417 QLabel * L1 = new QLabel( tr( "Paired" ), State_Frm ); 417 QLabel * L1 = new QLabel( tr( "Paired" ), State_Frm );
418 418
419 H->addWidget( Paired_Led ); 419 H->addWidget( Paired_Led );
420 H->addWidget( L1 ); 420 H->addWidget( L1 );
421 H->addStretch( 1 ); 421 H->addStretch( 1 );
422 } 422 }
423} 423}
424 424
425OTScan::~OTScan() { 425OTScan::~OTScan() {
426 if( MyIcons ) 426 if( MyIcons )
427 delete Icons; 427 delete Icons;
428 OTGateway::releaseOTGateway(); 428 OTGateway::releaseOTGateway();
429 429
430 // send all peers that we do not care about states 430 // send all peers that we do not care about states
431 QListViewItem * Lit = DetectedPeers_LV->firstChild(); 431 QListViewItem * Lit = DetectedPeers_LV->firstChild();
432 while( Lit ) { 432 while( Lit ) {
433 ((PeerLVI *)Lit)->peer()->stopFindingOutState( ); 433 ((PeerLVI *)Lit)->peer()->stopFindingOutState( );
434 Lit = Lit->nextSibling(); 434 Lit = Lit->nextSibling();
435 } 435 }
436} 436}
437 437
438// static scan dialog function 438// static scan dialog function
439int OTScan::getDevice( OTPeer *& Peer, 439int OTScan::getDevice( OTPeer *& Peer,
440 int & Channel, 440 int & Channel,
441 OTGateway * OT, 441 OTGateway * OT,
442 const UUIDVector & Filter, 442 const UUIDVector & Filter,
443 QWidget* Parent ) { 443 QWidget* Parent ) {
444 bool IsUp = 0; 444 bool IsUp = 0;
445 unsigned int i; 445 unsigned int i;
446 446
447 // check if bluetooth is up 447 // check if bluetooth is up
448 OTDriverList & DL = OT->getDriverList(); 448 OTDriverList & DL = OT->getDriverList();
449 for( i = 0; 449 for( i = 0;
450 i < DL.count(); 450 i < DL.count();
451 i ++ ) { 451 i ++ ) {
452 if( DL[i]->isUp() ) { 452 if( DL[i]->isUp() ) {
453 // one device that is up found 453 // one device that is up found
454 IsUp = 1; 454 IsUp = 1;
455 break; 455 break;
456 } 456 }
457 } 457 }
458 458
459 // use this driver 459 // use this driver
460 OT->setScanWith( OT->driver(i) ); 460 OT->setScanWith( OT->driver(i) );
461 461
462 // create dialog 462 // create dialog
463 QDialog * Dlg = new QDialog( Parent, 0, TRUE ); 463 QDialog * Dlg = new QDialog( Parent, 0, TRUE );
464 QVBoxLayout * V = new QVBoxLayout( Dlg ); 464 QVBoxLayout * V = new QVBoxLayout( Dlg );
465 OTScan * Scn = new OTScan( Dlg ); 465 OTScan * Scn = new OTScan( Dlg );
466 466
467 connect( Scn, 467 connect( Scn,
468 SIGNAL( selected() ), 468 SIGNAL( selected() ),
469 Dlg, 469 Dlg,
470 SLOT( accept() ) 470 SLOT( accept() )
471 ); 471 );
472 472
473 if( Filter ) { 473 if( Filter ) {
474 Scn->setScanFilter( Filter ); 474 Scn->setScanFilter( Filter );
475 } 475 }
476 476
477 V->addWidget( Scn ); 477 V->addWidget( Scn );
478 Dlg->setCaption( tr("Scan Neighbourhood" ) ); 478 Dlg->setCaption( tr("Scan Neighbourhood" ) );
479 Dlg->showMaximized(); 479 Dlg->showMaximized();
480 int rv = Dlg->exec(); 480 int rv = Dlg->exec();
481 481
482 if( rv == QDialog::Accepted ) { 482 if( rv == QDialog::Accepted ) {
483 // get peer 483 // get peer
484 Peer = Scn->selectedPeer(); 484 Peer = Scn->selectedPeer();
485 if( Peer == 0 ) { 485 if( Peer == 0 ) {
486 // no peer selected 486 // no peer selected
487 rv = QDialog::Rejected; 487 rv = QDialog::Rejected;
488 } else { 488 } else {
489 Channel = Scn->selectedChannel(); 489 Channel = Scn->selectedChannel();
490 } 490 }
491 } 491 }
492 492
493 delete Dlg; 493 delete Dlg;
494 494
495 return rv; 495 return rv;
496} 496}
497 497
498void OTScan::setScanFilter( const UUIDVector & V ) { 498void OTScan::setScanFilter( const UUIDVector & V ) {
499 Filter = V; 499 Filter = V;
500} 500}
501 501
502void OTScan::resetScanFilter( void ) { 502void OTScan::resetScanFilter( void ) {
503 Filter.truncate(0); 503 Filter.truncate(0);
504} 504}
505 505
506void OTScan::SLOT_DoScan( bool DoIt ) { 506void OTScan::SLOT_DoScan( bool DoIt ) {
507 if( DoIt ) { 507 if( DoIt ) {
508 OT->scanNeighbourhood(); 508 OT->scanNeighbourhood();
509 } else { 509 } else {
510 OT->stopScanOfNeighbourhood(); 510 OT->stopScanOfNeighbourhood();
511 } 511 }
512 512
513 scanMode( DoIt ); 513 scanMode( DoIt );
514} 514}
515 515
516// double clicked on a device 516// double clicked on a device
517void OTScan::SLOT_Selected( QListViewItem * it ) { 517void OTScan::SLOT_Selected( QListViewItem * it ) {
518 if( ! it ) 518 if( ! it )
519 return; 519 return;
520 520
521 if( Filter.count() > 0 ) { 521 if( Filter.count() > 0 ) {
522 // filter on service 522 // filter on service
523 if( it->depth() == 0 ) { 523 if( it->depth() == 0 ) {
524 // select a service and not a device 524 // select a service and not a device
525 return; 525 return;
526 } 526 }
527 527
528 // store result 528 // store result
529 SelectedPeer = ((PeerLVI *)it->parent())->peer(); 529 SelectedPeer = ((PeerLVI *)it->parent())->peer();
530 SelectedChannel = ((ChannelLVI *)it)->channel(); 530 SelectedChannel = ((ChannelLVI *)it)->channel();
531 } else { 531 } else {
532 // click on device 532 // click on device
533 if( it->depth() != 0 ) { 533 if( it->depth() != 0 ) {
534 return; 534 return;
535 } 535 }
536 536
537 SelectedPeer = ((PeerLVI *)it)->peer(); 537 SelectedPeer = ((PeerLVI *)it)->peer();
538 SelectedChannel = 0; 538 SelectedChannel = 0;
539 } 539 }
540 owarn << "Selected " << SelectedPeer->address().toString() << 540 odebug << "Selected " << SelectedPeer->address().toString() <<
541 " Channel " << SelectedChannel << oendl; 541 " Channel " << SelectedChannel << oendl;
542 emit selected(); 542 emit selected();
543} 543}
544 544
545void OTScan::SLOT_FinishedDetecting( ) { 545void OTScan::SLOT_FinishedDetecting( ) {
546 scanMode( false ); 546 scanMode( false );
547} 547}
548 548
549void OTScan::SLOT_CleanupOld( ) { 549void OTScan::SLOT_CleanupOld( ) {
550 550
551 // iterate over all peers and find those that 551 // iterate over all peers and find those that
552 // are down and have no pairing info 552 // are down and have no pairing info
553 OTPeer * TheP; 553 OTPeer * TheP;
554 const LinkKeyArray & Keys = OT->getLinkKeys(); 554 const LinkKeyArray & Keys = OT->getLinkKeys();
555 555
556 QListViewItem * Lit = DetectedPeers_LV->firstChild(); 556 QListViewItem * Lit = DetectedPeers_LV->firstChild();
557 while( Lit ) { 557 while( Lit ) {
558 TheP = ((PeerLVI *)Lit)->peer(); 558 TheP = ((PeerLVI *)Lit)->peer();
559 if( TheP->state() == OTPeer::Peer_Down ) { 559 if( TheP->state() == OTPeer::Peer_Down ) {
560 unsigned int k; 560 unsigned int k;
561 561
562 // what about linkkeys ? 562 // what about linkkeys ?
563 for( k = 0; k < Keys.count(); k ++ ) { 563 for( k = 0; k < Keys.count(); k ++ ) {
564 if( TheP->address() == Keys[k].to() || 564 if( TheP->address() == Keys[k].to() ||
565 TheP->address() == Keys[k].from() 565 TheP->address() == Keys[k].from()
566 ) { 566 ) {
567 // part of linkkey 567 // part of linkkey
568 owarn << "LINKKEY " << TheP->address().toString() << oendl; 568 odebug << "LINKKEY " << TheP->address().toString() << oendl;
569 break; 569 break;
570 } 570 }
571 } 571 }
572 572
573 if( k == Keys.count() ) { 573 if( k == Keys.count() ) {
574 owarn << "RM LINKKEY " << TheP->address().toString() << oendl; 574 odebug << "RM LINKKEY " << TheP->address().toString() << oendl;
575 // not found -> remember to remove this peer 575 // not found -> remember to remove this peer
576 QListViewItem * Nit; 576 QListViewItem * Nit;
577 OT->removePeer( TheP ); 577 OT->removePeer( TheP );
578 Nit = Lit->nextSibling(); 578 Nit = Lit->nextSibling();
579 delete Lit; 579 delete Lit;
580 Lit = Nit; 580 Lit = Nit;
581 continue; 581 continue;
582 } 582 }
583 } else { 583 } else {
584 owarn << "NODOWN " << TheP->address().toString() << oendl; 584 odebug << "NODOWN " << TheP->address().toString() << oendl;
585 } 585 }
586 586
587 Lit = Lit->nextSibling(); 587 Lit = Lit->nextSibling();
588 } 588 }
589} 589}
590 590
591void OTScan::SLOT_NewPeer( OTPeer * P, bool IsNew ){ 591void OTScan::SLOT_NewPeer( OTPeer * P, bool IsNew ){
592 PeerLVI * it = 0; 592 PeerLVI * it = 0;
593 593
594 if( IsNew ) { 594 if( IsNew ) {
595 it = new PeerLVI( P, DetectedPeers_LV ); 595 it = new PeerLVI( P, DetectedPeers_LV );
596 } else { 596 } else {
597 // find peer in table 597 // find peer in table
598 QListViewItem * Lit = DetectedPeers_LV->firstChild(); 598 QListViewItem * Lit = DetectedPeers_LV->firstChild();
599 while( Lit ) { 599 while( Lit ) {
600 if( ((PeerLVI *)Lit)->peer() == P ) { 600 if( ((PeerLVI *)Lit)->peer() == P ) {
601 // this item 601 // this item
602 it = (PeerLVI *)Lit; 602 it = (PeerLVI *)Lit;
603 break; 603 break;
604 } 604 }
605 Lit = Lit->nextSibling(); 605 Lit = Lit->nextSibling();
606 } 606 }
607 607
608 if( ! it ) { 608 if( ! it ) {
609 owarn << "Should not occur" << oendl; 609 odebug << "Should not occur" << oendl;
610 return; 610 return;
611 } 611 }
612 } 612 }
613 613
614 // update/show info 614 // update/show info
615 it->setText( 0, P->name() ); 615 it->setText( 0, P->name() );
616 it->setPixmap(0, Icons->deviceIcon( 616 it->setPixmap(0, Icons->deviceIcon(
617 OT->deviceTypeToName( P->deviceClass() ) ) ); 617 OT->deviceTypeToName( P->deviceClass() ) ) );
618 618
619 // tell peer to report its state async 619 // tell peer to report its state async
620 connect( P, 620 connect( P,
621 SIGNAL( peerStateReport( OTPeer *)), 621 SIGNAL( peerStateReport( OTPeer *)),
622 this, 622 this,
623 SLOT( SLOT_PeerState( OTPeer *)) 623 SLOT( SLOT_PeerState( OTPeer *))
624 ); 624 );
625 625
626 if( IsNew ) { 626 if( IsNew ) {
627 // find state 627 // find state
628 refreshState( (PeerLVI *)it, 1 ); 628 refreshState( (PeerLVI *)it, 1 );
629 } else { 629 } else {
630 // update staet 630 // update staet
631 SLOT_PeerState( P ); 631 SLOT_PeerState( P );
632 } 632 }
633} 633}
634 634
635void OTScan::SLOT_PeerState( OTPeer * P ) { 635void OTScan::SLOT_PeerState( OTPeer * P ) {
636 PeerLVI * it = (PeerLVI *)DetectedPeers_LV->firstChild(); 636 PeerLVI * it = (PeerLVI *)DetectedPeers_LV->firstChild();
637 while( it ) { 637 while( it ) {
638 if( it->peer() == P ) { 638 if( it->peer() == P ) {
639 break; 639 break;
640 } 640 }
641 it = (PeerLVI * )it->nextSibling(); 641 it = (PeerLVI * )it->nextSibling();
642 } 642 }
643 643
644 if( ! it ) 644 if( ! it )
645 return; 645 return;
646 646
647 switch( P->state() ) { 647 switch( P->state() ) {
648 case OTPeer::Peer_Unknown : 648 case OTPeer::Peer_Unknown :
649 case OTPeer::Peer_Down : 649 case OTPeer::Peer_Down :
650 it->setPixmap( 1, 0 ); 650 it->setPixmap( 1, 0 );
651 break; 651 break;
652 case OTPeer::Peer_Up : 652 case OTPeer::Peer_Up :
653 it->setPixmap( 1, Icons->loadPixmap( 653 it->setPixmap( 1, Icons->loadPixmap(
654 ( P->connectedTo() ) ? "connected" : "notconnected" ) ); 654 ( P->connectedTo() ) ? "connected" : "notconnected" ) );
655 if( it == Current && ! StrengthTimer->isActive() ) { 655 if( it == Current && ! StrengthTimer->isActive() ) {
656 // start showing strength 656 // start showing strength
657 StrengthTimer->start( 1000, FALSE ); 657 StrengthTimer->start( 1000, FALSE );
658 SLOT_UpdateStrength(); 658 SLOT_UpdateStrength();
659 } 659 }
660 break; 660 break;
661 } 661 }
662} 662}
663 663
664void OTScan::SLOT_RefreshState( void ) { 664void OTScan::SLOT_RefreshState( void ) {
665 665
666 QListViewItem * it = DetectedPeers_LV->firstChild(); 666 QListViewItem * it = DetectedPeers_LV->firstChild();
667 while( it ) { 667 while( it ) {
668 if( it->isSelected() ) { 668 if( it->isSelected() ) {
669 break; 669 break;
670 } 670 }
671 it = it->nextSibling(); 671 it = it->nextSibling();
672 } 672 }
673 673
674 if( ! it ) 674 if( ! it )
675 return; 675 return;
676 676
677 refreshState( (PeerLVI *)it, 1 ); 677 refreshState( (PeerLVI *)it, 1 );
678} 678}
679 679
680void OTScan::refreshState( PeerLVI * it, bool Force ) { 680void OTScan::refreshState( PeerLVI * it, bool Force ) {
681 it->setPixmap( 1, Icons->loadPixmap( "find" ) ); 681 it->setPixmap( 1, Icons->loadPixmap( "find" ) );
682 it->peer()->findOutState( 30, Force ); 682 it->peer()->findOutState( 30, Force );
683} 683}
684 684
685void OTScan::SLOT_Show( QListViewItem * it ) { 685void OTScan::SLOT_Show( QListViewItem * it ) {
686 686
687 if( ! it || it->depth() > 0 ) 687 if( ! it || it->depth() > 0 )
688 return; 688 return;
689 689
690 QString S; 690 QString S;
691 691
692 Current = (PeerLVI *)it; 692 Current = (PeerLVI *)it;
693 693
694 Strength_PB->setProgress( 0 ); // reset 694 Strength_PB->setProgress( 0 ); // reset
695 Address_LBL->setText( Current->peer()->address().toString() ); 695 Address_LBL->setText( Current->peer()->address().toString() );
696 Peer_GB->setTitle( Current->peer()->name() ); 696 Peer_GB->setTitle( Current->peer()->name() );
697 697
698 const LinkKeyArray & Keys = OT->getLinkKeys(); 698 const LinkKeyArray & Keys = OT->getLinkKeys();
699 699
700 Paired_Led->setOn( FALSE ); 700 Paired_Led->setOn( FALSE );
701 for( unsigned int i = 0; 701 for( unsigned int i = 0;
702 i < Keys.count(); 702 i < Keys.count();
703 i ++ ) { 703 i ++ ) {
704 if( Current->peer()->address() == Keys[i].to() ) { 704 if( Current->peer()->address() == Keys[i].to() ) {
705 Paired_Led->setOn( TRUE ); 705 Paired_Led->setOn( TRUE );
706 break; 706 break;
707 } 707 }
708 } 708 }
709 709
710 if( Current->peer()->state() == OTPeer::Peer_Up ) { 710 if( Current->peer()->state() == OTPeer::Peer_Up ) {
711 RefreshServices_But->setEnabled( TRUE ); 711 RefreshServices_But->setEnabled( TRUE );
712 StrengthTimer->start( 1000, FALSE ); 712 StrengthTimer->start( 1000, FALSE );
713 SLOT_UpdateStrength(); 713 SLOT_UpdateStrength();
714 } else { 714 } else {
715 RefreshServices_But->setEnabled( FALSE ); 715 RefreshServices_But->setEnabled( FALSE );
716 } 716 }
717 717
718} 718}
719 719
720void OTScan::SLOT_UpdateStrength( void ) { 720void OTScan::SLOT_UpdateStrength( void ) {
721 OTDriver * D = Current->peer()->connectedTo(); 721 OTDriver * D = Current->peer()->connectedTo();
722 722
723 if( D ) { 723 if( D ) {
724 long Q = D->getLinkQuality( Current->peer()->address() ); 724 long Q = D->getLinkQuality( Current->peer()->address() );
725 Strength_PB->setProgress( Q ); 725 Strength_PB->setProgress( Q );
726 if( ! Q ) { 726 if( ! Q ) {
727 // no quality 727 // no quality
728 Strength_PB->setEnabled( TRUE ); 728 Strength_PB->setEnabled( TRUE );
729 StrengthTimer->stop(); 729 StrengthTimer->stop();
730 } 730 }
731 } else { 731 } else {
732 Strength_PB->setEnabled( FALSE ); 732 Strength_PB->setEnabled( FALSE );
733 Strength_PB->setProgress( 0 ); 733 Strength_PB->setProgress( 0 );
734 // no point in continuing 734 // no point in continuing
735 StrengthTimer->stop(); 735 StrengthTimer->stop();
736 } 736 }
737} 737}
738 738
739void OTScan::SLOT_RefreshServices( void ) { 739void OTScan::SLOT_RefreshServices( void ) {
740 740
741 QListViewItem * it = DetectedPeers_LV->firstChild(); 741 QListViewItem * it = DetectedPeers_LV->firstChild();
742 while( it ) { 742 while( it ) {
743 if( it->isSelected() ) { 743 if( it->isSelected() ) {
744 break; 744 break;
745 } 745 }
746 it = it->nextSibling(); 746 it = it->nextSibling();
747 } 747 }
748 748
749 if( ! it ) 749 if( ! it )
750 return; 750 return;
751 751
752 QString S; 752 QString S;
753 PeerLVI * PI = (PeerLVI *)it; 753 PeerLVI * PI = (PeerLVI *)it;
754 754
755 scanMode( true ); 755 scanMode( true );
756 qApp->processEvents(0); 756 qApp->processEvents(0);
757 757
758 ServiceVector & V = PI->peer()->services(); 758 ServiceVector & V = PI->peer()->services();
759 759
760 while( PI->firstChild() ) { 760 while( PI->firstChild() ) {
761 // remove children 761 // remove children
762 delete PI->firstChild(); 762 delete PI->firstChild();
763 } 763 }
764 764
765 for( unsigned int i = 0 ; 765 for( unsigned int i = 0 ;
766 i < V.count(); 766 i < V.count();
767 i ++ ) { 767 i ++ ) {
768 QString S; 768 QString S;
769 S = V[i]->name(); 769 S = V[i]->name();
770 770
771 if( S.isEmpty() ) { 771 if( S.isEmpty() ) {
772 continue; 772 continue;
773 } 773 }
774 774
775 { QListViewItem * SIt; 775 { QListViewItem * SIt;
776 UUIDVector UIDV; 776 UUIDVector UIDV;
777 QPixmap Pm; 777 QPixmap Pm;
778 bool Done = 0; 778 bool Done = 0;
779 bool R; 779 bool R;
780 short ID; 780 short ID;
781 781
782 SIt = 0; 782 SIt = 0;
783 783
784 UIDV = V[i]->classIDList(); 784 UIDV = V[i]->classIDList();
785 // first all UUID ! 1200 12ff (Genericprofiles) 785 // first all UUID ! 1200 12ff (Genericprofiles)
786 for( unsigned int j = 0; 786 for( unsigned int j = 0;
787 j < UIDV.count(); 787 j < UIDV.count();
788 j ++ ) { 788 j ++ ) {
789 789
790 if( Filter.count() ) { 790 if( Filter.count() ) {
791 bool FilterOut = 1; 791 bool FilterOut = 1;
792 // filter out if not in list 792 // filter out if not in list
793 for( unsigned int ff = 0; 793 for( unsigned int ff = 0;
794 ff < Filter.count(); 794 ff < Filter.count();
795 ff ++ ) { 795 ff ++ ) {
796 if( UIDV[j] == Filter[ff] ) { 796 if( UIDV[j] == Filter[ff] ) {
797 FilterOut = 0; 797 FilterOut = 0;
798 break; 798 break;
799 } 799 }
800 } 800 }
801 801
802 if( FilterOut ) { 802 if( FilterOut ) {
803 // not in filter list 803 // not in filter list
804 continue; 804 continue;
805 } 805 }
806 } // else show 806 } // else show
807 807
808 ID = UIDV[j].toShort(); 808 ID = UIDV[j].toShort();
809 if( ID < 0x1200 || ID > 0x12ff ) { 809 if( ID < 0x1200 || ID > 0x12ff ) {
810 // use this profile 810 // use this profile
811 if( R ) { 811 if( R ) {
812 unsigned int ch; 812 unsigned int ch;
813 bool has; 813 bool has;
814 has = V[i]->rfcommChannel( ch ); 814 has = V[i]->rfcommChannel( ch );
815 SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI ); 815 SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI );
816 SIt->setText(0, V[i]->name() ); 816 SIt->setText(0, V[i]->name() );
817 817
818 Pm = Icons->serviceIcon( ID, R ); 818 Pm = Icons->serviceIcon( ID, R );
819 SIt->setPixmap(0, Pm ); 819 SIt->setPixmap(0, Pm );
820 Done = 1; 820 Done = 1;
821 break; 821 break;
822 } 822 }
823 } 823 }
824 } 824 }
825 825
826 if( ! Done ) { 826 if( ! Done ) {
827 // check other range too 827 // check other range too
828 for( unsigned int j = 0; 828 for( unsigned int j = 0;
829 j < UIDV.count(); 829 j < UIDV.count();
830 j ++ ) { 830 j ++ ) {
831 831
832 if( Filter.count() ) { 832 if( Filter.count() ) {
833 bool FilterOut = 1; 833 bool FilterOut = 1;
834 // filter out if not in list 834 // filter out if not in list
835 for( unsigned int ff = 0; 835 for( unsigned int ff = 0;
836 ff < Filter.count(); 836 ff < Filter.count();
837 ff ++ ) { 837 ff ++ ) {
838 if( UIDV[j] == Filter[ff] ) { 838 if( UIDV[j] == Filter[ff] ) {
839 FilterOut = 0; 839 FilterOut = 0;
840 break; 840 break;
841 } 841 }
842 } 842 }
843 843
844 if( FilterOut ) { 844 if( FilterOut ) {
845 // not in filter list 845 // not in filter list
846 continue; 846 continue;
847 } 847 }
848 } // else show 848 } // else show
849 849
850 ID = UIDV[j].toShort(); 850 ID = UIDV[j].toShort();
851 if( ID >= 0x1200 && ID <= 0x12ff ) { 851 if( ID >= 0x1200 && ID <= 0x12ff ) {
852 // use this profile 852 // use this profile
853 unsigned int ch; 853 unsigned int ch;
854 bool has; 854 bool has;
855 has = V[i]->rfcommChannel( ch ); 855 has = V[i]->rfcommChannel( ch );
856 SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI ); 856 SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI );
857 SIt->setText(0, V[i]->name() ); 857 SIt->setText(0, V[i]->name() );
858 858
859 Pm = Icons->serviceIcon( ID, R ); 859 Pm = Icons->serviceIcon( ID, R );
860 SIt->setPixmap(0, Pm ); 860 SIt->setPixmap(0, Pm );
861 861
862 break; 862 break;
863 } 863 }
864 } 864 }
865 } 865 }
866 866
867 } 867 }
868 } 868 }
869 869
870 scanMode( false ); 870 scanMode( false );
871} 871}
872 872
873void OTScan::scanMode( bool M ) { 873void OTScan::scanMode( bool M ) {
874 // avoid infinite loop because it triggers DoScan 874 // avoid infinite loop because it triggers DoScan
875 Detect_But->blockSignals( TRUE ); 875 Detect_But->blockSignals( TRUE );
876 Detect_But->setOn( M ); 876 Detect_But->setOn( M );
877 Detect_But->setText( (M) ? tr("Scanning") : tr("Scan") ); 877 Detect_But->setText( (M) ? tr("Scanning") : tr("Scan") );
878 Detect_But->blockSignals( FALSE ); 878 Detect_But->blockSignals( FALSE );
879} 879}
880 880
881// 881//
882// 882//
883// 883//
884// 884//
885// 885//
886 886
887OTManage::OTManage( QWidget * parent, OTIcons * _IC ) : 887OTManage::OTManage( QWidget * parent, OTIcons * _IC ) :
888 OTManageGUI( parent ) { 888 OTManageGUI( parent ) {
889 889
890 OT = OTGateway::getOTGateway(); 890 OT = OTGateway::getOTGateway();
891 891
892 Icons = (_IC ) ? _IC : new OTIcons(); 892 Icons = (_IC ) ? _IC : new OTIcons();
893 MyIcons = (_IC == 0 ); 893 MyIcons = (_IC == 0 );
894 AllDrivers_LV->setSorting(-1); 894 AllDrivers_LV->setSorting(-1);
895 895
896 connect( OT, 896 connect( OT,
897 SIGNAL( driverListChanged() ), 897 SIGNAL( driverListChanged() ),
898 this, 898 this,
899 SLOT( SLOT_DriverListChanged() ) 899 SLOT( SLOT_DriverListChanged() )
900 ); 900 );
901 connect( OT, 901 connect( OT,
902 SIGNAL( stateChange( OTDriver *, bool ) ), 902 SIGNAL( stateChange( OTDriver *, bool ) ),
903 this, 903 this,
904 SLOT( SLOT_StateChange( OTDriver *, bool ) ) 904 SLOT( SLOT_StateChange( OTDriver *, bool ) )
905 ); 905 );
906 906
907 SLOT_DriverListChanged(); 907 SLOT_DriverListChanged();
908 908
909 AllDrivers_LV->header()->hide(); 909 AllDrivers_LV->header()->hide();
910} 910}
911 911
912OTManage::~OTManage() { 912OTManage::~OTManage() {
913 if( MyIcons ) 913 if( MyIcons )
914 delete Icons; 914 delete Icons;
915 OTGateway::releaseOTGateway(); 915 OTGateway::releaseOTGateway();
916} 916}
917 917
918void OTManage::SLOT_ShowDriver( QListViewItem * It ) { 918void OTManage::SLOT_ShowDriver( QListViewItem * It ) {
919 if( It == 0 || It->depth() > 0 ) 919 if( It == 0 || It->depth() > 0 )
920 // not toplevel 920 // not toplevel
921 return; 921 return;
922 922
923 DriverLVI * it = (DriverLVI *) It; 923 DriverLVI * it = (DriverLVI *) It;
924 DriverIsUp_CB->setChecked( it->driver()->isUp() ); 924 DriverIsUp_CB->setChecked( it->driver()->isUp() );
925} 925}
926 926
927void OTManage::SLOT_UpDriver( bool Up ) { 927void OTManage::SLOT_UpDriver( bool Up ) {
928 QListViewItem * it = AllDrivers_LV->firstChild(); 928 QListViewItem * it = AllDrivers_LV->firstChild();
929 while( it ) { 929 while( it ) {
930 if( it->isSelected() ) { 930 if( it->isSelected() ) {
931 OTDriver * D = ((DriverLVI *)it)->driver(); 931 OTDriver * D = ((DriverLVI *)it)->driver();
932 owarn << "UP driver " << D->devname() << oendl; 932 odebug << "UP driver " << D->devname() << oendl;
933 // this 933 // this
934 D->setUp( Up ); 934 D->setUp( Up );
935 return; 935 return;
936 } 936 }
937 it = it->nextSibling(); 937 it = it->nextSibling();
938 } 938 }
939} 939}
940 940
941void OTManage::SLOT_StateChange( OTDriver * D, bool Up ) { 941void OTManage::SLOT_StateChange( OTDriver * D, bool Up ) {
942 QListViewItem * it = AllDrivers_LV->firstChild(); 942 QListViewItem * it = AllDrivers_LV->firstChild();
943 while( it ) { 943 while( it ) {
944 if( ((DriverLVI *)it)->driver() == D ) { 944 if( ((DriverLVI *)it)->driver() == D ) {
945 it->setPixmap( 0, 945 it->setPixmap( 0,
946 Icons->loadPixmap( ( Up ) ? "bluezon" : "bluezoff" ) ); 946 Icons->loadPixmap( ( Up ) ? "bluezon" : "bluezoff" ) );
947 return; 947 return;
948 } 948 }
949 it = it->nextSibling(); 949 it = it->nextSibling();
950 } 950 }
951} 951}
952 952
953void OTManage::SLOT_DriverListChanged( ) { 953void OTManage::SLOT_DriverListChanged( ) {
954 DriverLVI * It; 954 DriverLVI * It;
955 QListViewItem * Sub; 955 QListViewItem * Sub;
956 QListViewItem * First = 0; 956 QListViewItem * First = 0;
957 OTDriver* D; 957 OTDriver* D;
958 OTDriverList & DL = OT->getDriverList(); 958 OTDriverList & DL = OT->getDriverList();
959 959
960 AllDrivers_LV->clear(); 960 AllDrivers_LV->clear();
961 for( unsigned int i = 0; 961 for( unsigned int i = 0;
962 i < DL.count(); 962 i < DL.count();
963 i ++ ) { 963 i ++ ) {
964 D = DL[i]; 964 D = DL[i];
965 It = new DriverLVI( D, AllDrivers_LV ); 965 It = new DriverLVI( D, AllDrivers_LV );
966 966
967 if( ! First ) 967 if( ! First )
968 First = It; 968 First = It;
969 969
970 It->setText( 0, D->devname() ); 970 It->setText( 0, D->devname() );
971 It->setPixmap( 0, 971 It->setPixmap( 0,
972 Icons->loadPixmap( (D->isUp()) ? 972 Icons->loadPixmap( (D->isUp()) ?
973 "bluezon" : "bluezoff" ) ); 973 "bluezon" : "bluezoff" ) );
974 974
975 Sub = new QListViewItem( It ); 975 Sub = new QListViewItem( It );
976 Sub->setText( 0, tr( "Name" ) ); 976 Sub->setText( 0, tr( "Name" ) );
977 Sub->setText( 1, D->name() ); 977 Sub->setText( 1, D->name() );
978 978
979 Sub = new QListViewItem( It ); 979 Sub = new QListViewItem( It );
980 Sub->setText( 0, tr( "Address" ) ); 980 Sub->setText( 0, tr( "Address" ) );
981 Sub->setText( 1, D->address().toString() ); 981 Sub->setText( 1, D->address().toString() );
982 982
983 Sub = new QListViewItem( It ); 983 Sub = new QListViewItem( It );
984 Sub->setText( 0, tr( "Revision" ) ); 984 Sub->setText( 0, tr( "Revision" ) );
985 Sub->setText( 1, D->revision() ); 985 Sub->setText( 1, D->revision() );
986 986
987 Sub = new QListViewItem( It ); 987 Sub = new QListViewItem( It );
988 Sub->setText( 0, tr( "Manufacturer" ) ); 988 Sub->setText( 0, tr( "Manufacturer" ) );
989 Sub->setText( 1, D->manufacturer() ); 989 Sub->setText( 1, D->manufacturer() );
990 990
991 QString Service, Device; 991 QString Service, Device;
992 D->getClass( Service, Device ); 992 D->getClass( Service, Device );
993 993
994 Sub = new QListViewItem( It ); 994 Sub = new QListViewItem( It );
995 Sub->setText( 0, tr( "Service classes" ) ); 995 Sub->setText( 0, tr( "Service classes" ) );
996 Sub->setText( 1, Service ); 996 Sub->setText( 1, Service );
997 Sub = new QListViewItem( It ); 997 Sub = new QListViewItem( It );
998 Sub->setText( 0, tr( "Device class" ) ); 998 Sub->setText( 0, tr( "Device class" ) );
999 Sub->setText( 1, Device ); 999 Sub->setText( 1, Device );
1000 } 1000 }
1001 1001
1002 if( DL.count() ) { 1002 if( DL.count() ) {
1003 AllDrivers_LV->setCurrentItem( First ); 1003 AllDrivers_LV->setCurrentItem( First );
1004 DriverIsUp_CB->setEnabled( TRUE ); 1004 DriverIsUp_CB->setEnabled( TRUE );
1005 } else { 1005 } else {
1006 DriverIsUp_CB->setChecked( FALSE ); 1006 DriverIsUp_CB->setChecked( FALSE );
1007 DriverIsUp_CB->setEnabled( FALSE ); 1007 DriverIsUp_CB->setEnabled( FALSE );
1008 } 1008 }
1009} 1009}
1010 1010
1011void OTManage::SLOT_SetRefreshTimer( int v ) { 1011void OTManage::SLOT_SetRefreshTimer( int v ) {
1012 OT->setRefreshTimer( v * 1000 ); 1012 OT->setRefreshTimer( v * 1000 );
1013} 1013}
1014 1014
1015// 1015//
1016// 1016//
1017// 1017//
1018// 1018//
1019// 1019//
1020 1020
1021OTMain::OTMain( QWidget * parent ) : OTMainGUI( parent ) { 1021OTMain::OTMain( QWidget * parent ) : OTMainGUI( parent ) {
1022 1022
1023 Icons = new OTIcons(); 1023 Icons = new OTIcons();
1024 SnifWindow = 0; 1024 SnifWindow = 0;
1025 OT = OTGateway::getOTGateway(); 1025 OT = OTGateway::getOTGateway();
1026 1026
1027 connect( OT, 1027 connect( OT,
1028 SIGNAL( deviceEnabled( bool ) ), 1028 SIGNAL( deviceEnabled( bool ) ),
1029 this, 1029 this,
1030 SLOT( SLOT_DeviceIsEnabled( bool ) ) 1030 SLOT( SLOT_DeviceIsEnabled( bool ) )
1031 ); 1031 );
1032 connect( OT, 1032 connect( OT,
1033 SIGNAL( driverListChanged() ), 1033 SIGNAL( driverListChanged() ),
1034 this, 1034 this,
1035 SLOT( SLOT_DriverListChanged() ) 1035 SLOT( SLOT_DriverListChanged() )
1036 ); 1036 );
1037 connect( OT, 1037 connect( OT,
1038 SIGNAL( stateChange( OTDriver *, bool ) ), 1038 SIGNAL( stateChange( OTDriver *, bool ) ),
1039 this, 1039 this,
1040 SLOT( SLOT_StateChange( OTDriver *, bool ) ) 1040 SLOT( SLOT_StateChange( OTDriver *, bool ) )
1041 ); 1041 );
1042 1042
1043 if( ! OT->needsEnabling() ) { 1043 if( ! OT->needsEnabling() ) {
1044 MustBeEnabled_CB->hide(); 1044 MustBeEnabled_CB->hide();
1045 } else { 1045 } else {
1046 // detect current state 1046 // detect current state
1047 MustBeEnabled_CB->setChecked( 1047 MustBeEnabled_CB->setChecked(
1048 OT->isEnabled() ); 1048 OT->isEnabled() );
1049 } 1049 }
1050 1050
1051 SLOT_DriverListChanged(); 1051 SLOT_DriverListChanged();
1052} 1052}
1053 1053
1054OTMain::~OTMain() { 1054OTMain::~OTMain() {
1055 OTGateway::releaseOTGateway(); 1055 OTGateway::releaseOTGateway();
1056 delete Icons; 1056 delete Icons;
1057} 1057}
1058 1058
1059void OTMain::SLOT_DriverListChanged() { 1059void OTMain::SLOT_DriverListChanged() {
1060 OTDriver * D; 1060 OTDriver * D;
1061 OTDriverList & DL = OT->getDriverList(); 1061 OTDriverList & DL = OT->getDriverList();
1062 1062
1063 DeviceList_CB->clear(); 1063 DeviceList_CB->clear();
1064 for( unsigned int i = 0; 1064 for( unsigned int i = 0;
1065 i < DL.count(); 1065 i < DL.count();
1066 i ++ ) { 1066 i ++ ) {
1067 D = DL[i]; 1067 D = DL[i];
1068 DeviceList_CB->insertItem( 1068 DeviceList_CB->insertItem(
1069 Icons->loadPixmap( (D->isUp()) ? 1069 Icons->loadPixmap( (D->isUp()) ?
1070 "bluezon" : "bluezoff" ), 1070 "bluezon" : "bluezoff" ),
1071 D->devname() ); 1071 D->devname() );
1072 if( D == OT->scanWith() ) { 1072 if( D == OT->scanWith() ) {
1073 DeviceList_CB->setCurrentItem( i ); 1073 DeviceList_CB->setCurrentItem( i );
1074 } 1074 }
1075 } 1075 }
1076 1076
1077 Scan_But->setEnabled( OT->getDriverList().count() > 0 ); 1077 Scan_But->setEnabled( OT->getDriverList().count() > 0 );
1078 DeviceList_CB->setEnabled( OT->getDriverList().count() > 0 ); 1078 DeviceList_CB->setEnabled( OT->getDriverList().count() > 0 );
1079} 1079}
1080 1080
1081void OTMain::SLOT_EnableBluetooth( bool Up ) { 1081void OTMain::SLOT_EnableBluetooth( bool Up ) {
1082 OT->SLOT_SetEnabled( Up ); 1082 OT->SLOT_SetEnabled( Up );
1083} 1083}
1084 1084
1085void OTMain::SLOT_DeviceIsEnabled( bool Up ) { 1085void OTMain::SLOT_DeviceIsEnabled( bool Up ) {
1086 MustBeEnabled_CB->blockSignals( TRUE ); 1086 MustBeEnabled_CB->blockSignals( TRUE );
1087 MustBeEnabled_CB->setChecked( Up ); 1087 MustBeEnabled_CB->setChecked( Up );
1088 MustBeEnabled_CB->blockSignals( FALSE ); 1088 MustBeEnabled_CB->blockSignals( FALSE );
1089} 1089}
1090 1090
1091void OTMain::SLOT_Manage( void ) { 1091void OTMain::SLOT_Manage( void ) {
1092 QDialog * Dlg = new QDialog( this, 0, TRUE ); 1092 QDialog * Dlg = new QDialog( this, 0, TRUE );
1093 QVBoxLayout * V = new QVBoxLayout( Dlg ); 1093 QVBoxLayout * V = new QVBoxLayout( Dlg );
1094 OTManage * Mng = new OTManage( Dlg, Icons ); 1094 OTManage * Mng = new OTManage( Dlg, Icons );
1095 1095
1096 V->addWidget( Mng ); 1096 V->addWidget( Mng );
1097 1097
1098 Dlg->setCaption( tr("Manage local devices" ) ); 1098 Dlg->setCaption( tr("Manage local devices" ) );
1099 Dlg->showMaximized(); 1099 Dlg->showMaximized();
1100 Dlg->exec(); 1100 Dlg->exec();
1101 delete Dlg; 1101 delete Dlg;
1102} 1102}
1103 1103
1104void OTMain::SLOT_Scan( void ) { 1104void OTMain::SLOT_Scan( void ) {
1105 OTDriverList & DL = OT->getDriverList(); 1105 OTDriverList & DL = OT->getDriverList();
1106 for( unsigned int i = 0; 1106 for( unsigned int i = 0;
1107 i < DL.count(); 1107 i < DL.count();
1108 i ++ ) { 1108 i ++ ) {
1109 if( DL[i]->isUp() && 1109 if( DL[i]->isUp() &&
1110 DL[i]->devname() == DeviceList_CB->currentText() 1110 DL[i]->devname() == DeviceList_CB->currentText()
1111 ) { 1111 ) {
1112 QDialog * Dlg = new QDialog( this, 0, TRUE ); 1112 QDialog * Dlg = new QDialog( this, 0, TRUE );
1113 QVBoxLayout * V = new QVBoxLayout( Dlg ); 1113 QVBoxLayout * V = new QVBoxLayout( Dlg );
1114 OTScan * Scn = new OTScan( Dlg, Icons ); 1114 OTScan * Scn = new OTScan( Dlg, Icons );
1115 1115
1116 OT->setScanWith( OT->driver(i) ); 1116 OT->setScanWith( OT->driver(i) );
1117 V->addWidget( Scn ); 1117 V->addWidget( Scn );
1118 Dlg->setCaption( tr("Scan Neighbourhood" ) ); 1118 Dlg->setCaption( tr("Scan Neighbourhood" ) );
1119 Dlg->showMaximized(); 1119 Dlg->showMaximized();
1120 Dlg->exec(); 1120 Dlg->exec();
1121 1121
1122 delete Dlg; 1122 delete Dlg;
1123 return; 1123 return;
1124 } 1124 }
1125 } 1125 }
1126 1126
1127} 1127}
1128 1128
1129void OTMain::SLOT_StateChange( OTDriver * D, bool Up ) { 1129void OTMain::SLOT_StateChange( OTDriver * D, bool Up ) {
1130 for( int i = 0; 1130 for( int i = 0;
1131 i < DeviceList_CB->count(); 1131 i < DeviceList_CB->count();
1132 i ++ ) { 1132 i ++ ) {
1133 if( DeviceList_CB->text(i) == D->devname() ) { 1133 if( DeviceList_CB->text(i) == D->devname() ) {
1134 DeviceList_CB->changeItem( 1134 DeviceList_CB->changeItem(
1135 Icons->loadPixmap( (Up) ? "bluezon" : "bluezoff" ), 1135 Icons->loadPixmap( (Up) ? "bluezon" : "bluezoff" ),
1136 D->devname(), 1136 D->devname(),
1137 i ); 1137 i );
1138 return; 1138 return;
1139 } 1139 }
1140 } 1140 }
1141} 1141}
1142 1142
1143void OTMain::SLOT_Pairing( void ) { 1143void OTMain::SLOT_Pairing( void ) {
1144 QDialog * Dlg = new QDialog( this, 0, TRUE ); 1144 QDialog * Dlg = new QDialog( this, 0, TRUE );
1145 QVBoxLayout * V = new QVBoxLayout( Dlg ); 1145 QVBoxLayout * V = new QVBoxLayout( Dlg );
1146 OTPairing * Pair = new OTPairing( Dlg, Icons ); 1146 OTPairing * Pair = new OTPairing( Dlg, Icons );
1147 1147
1148 V->addWidget( Pair ); 1148 V->addWidget( Pair );
1149 Dlg->showMaximized(); 1149 Dlg->showMaximized();
1150 Dlg->setCaption( tr("Manage pairing" ) ); 1150 Dlg->setCaption( tr("Manage pairing" ) );
1151 Dlg->exec(); 1151 Dlg->exec();
1152 1152
1153 delete Dlg; 1153 delete Dlg;
1154} 1154}
1155 1155
1156void OTMain::SLOT_Sniffing( void ) { 1156void OTMain::SLOT_Sniffing( void ) {
1157 1157
1158 if( SnifWindow == 0 ) { 1158 if( SnifWindow == 0 ) {
1159 SnifWindow = new QDialog( this, 0, FALSE ); 1159 SnifWindow = new QDialog( this, 0, FALSE );
1160 QVBoxLayout * V = new QVBoxLayout( SnifWindow ); 1160 QVBoxLayout * V = new QVBoxLayout( SnifWindow );
1161 OTSniffing * SN = new OTSniffing( SnifWindow ); 1161 OTSniffing * SN = new OTSniffing( SnifWindow );
1162 V->addWidget( SN ); 1162 V->addWidget( SN );
1163 } 1163 }
1164 1164
1165 SnifWindow->showMaximized(); 1165 SnifWindow->showMaximized();
1166 SnifWindow->show(); 1166 SnifWindow->show();
1167} 1167}
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 @@
1config NS2OPIETOOTH 1config NS2OPIETOOTH
2 boolean "opie-networksettings2 bluetooth library" 2 boolean "Opietooth2 bluetooth library"
3 default "y" 3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE 4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBBLUEZ_DEP && NS2CORE
5 5
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 @@
1#!/bin/sh 1#!/bin/sh
2 2
3QTPB=/opt/QtPalmtop/bin 3QTPB=/opt/QtPalmtop/bin
4 4
5[ ! -L ${QTPB}/networksettings2-opietooth ] && ln -sf ${QTPB}/networksettings2 ${QTPB}/networksettings2-opietooth 5[ ! -L ${QTPB}/networksettings2-opietooth ] && ln -sf ${QTPB}/networksettings2 ${QTPB}/networksettings2-opietooth
6 6
7# qcop QPE/Taskbar "linkChanged(opietooth)" 7# qcop QPE/Taskbar "linkChanged(opietooth)"
8qcop QPE/Taskbar "reloadApps()" 8${QTPB}/qcop QPE/Taskbar "reloadApps()"
9 9
10exit 0 10exit 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 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3 #CONFIG += qt warn_on debug 3 #CONFIG += qt warn_on debug
4 DESTDIR = $(OPIEDIR)/lib$(PROJMAK) 4 DESTDIR = $(OPIEDIR)/lib$(PROJMAK)
5 HEADERS = OTDevice.h \ 5 HEADERS = OTDevice.h \
6 OTDriver.h \ 6 OTDriver.h \
7 OTGateway.h \ 7 OTGateway.h \
8 OTHCISocket.h \ 8 OTHCISocket.h \
9 OTInquiry.h \ 9 OTInquiry.h \
10 OTDeviceAddress.h \ 10 OTDeviceAddress.h \
11 OTIcons.h \ 11 OTIcons.h \
12 OTUUID.h \ 12 OTUUID.h \
13 OTSDPAttribute.h \ 13 OTSDPAttribute.h \
14 OTSDPService.h \ 14 OTSDPService.h \
15 OTPeer.h \ 15 OTPeer.h \
16 Opietooth.h 16 Opietooth.h
17 SOURCES = OTDevice.cpp \ 17 SOURCES = OTDevice.cpp \
18 OTDriver.cpp \ 18 OTDriver.cpp \
19 OTDriverList.cpp \ 19 OTDriverList.cpp \
20 OTHCISocket.cpp \ 20 OTHCISocket.cpp \
21 OTInquiry.cpp \ 21 OTInquiry.cpp \
22 OTDeviceAddress.cpp \ 22 OTDeviceAddress.cpp \
23 OTUUID.cpp \ 23 OTUUID.cpp \
24 OTSDPAttribute.cpp \ 24 OTSDPAttribute.cpp \
25 OTSDPService.cpp \ 25 OTSDPService.cpp \
26 OTIcons.cpp \ 26 OTIcons.cpp \
27 OTPeer.cpp \ 27 OTPeer.cpp \
28 OTGateway.cpp \ 28 OTGateway.cpp \
29 Opietooth.cpp 29 Opietooth.cpp
30 INCLUDEPATH+= $(OPIEDIR)/include ../networksettings2 30 INCLUDEPATH+= $(OPIEDIR)/include ../networksettings2
31 DEPENDPATH+= $(OPIEDIR)/include 31 DEPENDPATH+= $(OPIEDIR)/include
32LIBS += -lqpe -lopiecore2 -lbluetooth -lnetworksettings2 32LIBS += -lqpe -lopiecore2 -lbluetooth -lnetworksettings2
33 INTERFACES= OTMainGUI.ui OTSniffGUI.ui OTScanGUI.ui OTManageGUI.ui OTPairingGUI.ui 33 INTERFACES= OTMainGUI.ui OTSniffGUI.ui OTScanGUI.ui OTManageGUI.ui OTPairingGUI.ui
34 TARGET = opietooth2 34 TARGET = opietooth2
35 VERSION = 1.0.0 35 VERSION = 1.0.0
36 36
37include ( $(OPIEDIR)/include.pro ) 37include ( $(OPIEDIR)/include.pro )
38
39!isEmpty( LIBBLUEZ_INC_DIR ) {
40 INCLUDEPATH += $$LIBBLUEZ_INC_DIR
41}
42!isEmpty( LIBBLUEZ_LIB_DIR ) {
43 LIBS += -L$$LIBBLUEZ_LIB_DIR
44}
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 @@
1#include <resources.h> 1#include <resources.h>
2 2
3#include "profilerun.h" 3#include "profilerun.h"
4 4
5State_t ProfileRun::detectState( void ) { 5State_t ProfileRun::detectState( void ) {
6 if( Data->Disabled ) { 6 if( Data->Disabled ) {
7 return Disabled; 7 return Disabled;
8 } 8 }
9 return Unknown; 9 return Unknown;
10} 10}
11 11
12QString ProfileRun::setMyState( NodeCollection * NC, Action_t A, bool ) { 12QString ProfileRun::setMyState( NodeCollection * NC, Action_t A, bool ) {
13 owarn << "Profile " << Data->Disabled << oendl; 13 odebug << "Profile " << Data->Disabled << oendl;
14 if( A == Disable ) { 14 if( A == Disable ) {
15 if( ! Data->Disabled ) { 15 if( ! Data->Disabled ) {
16 Data->Disabled = 1; 16 Data->Disabled = 1;
17 NC->setModified( 1 ); 17 NC->setModified( 1 );
18 } 18 }
19 } else if( A == Enable ) { 19 } else if( A == Enable ) {
20 if( Data->Disabled ) { 20 if( Data->Disabled ) {
21 Data->Disabled = 0; 21 Data->Disabled = 0;
22 NC->setModified( 1 ); 22 NC->setModified( 1 );
23 } 23 }
24 } 24 }
25 25
26 return QString(); 26 return QString();
27} 27}
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 @@
1#include <qfile.h> 1#include <qfile.h>
2#include <qfileinfo.h> 2#include <qfileinfo.h>
3#include <qtextstream.h> 3#include <qtextstream.h>
4#include <resources.h> 4#include <resources.h>
5#include "usbrun.h" 5#include "usbrun.h"
6 6
7State_t USBRun::detectState( void ) { 7State_t USBRun::detectState( void ) {
8 8
9 // unavailable : no card found 9 // unavailable : no card found
10 // available : card found and assigned to us or free 10 // available : card found and assigned to us or free
11 // up : card found and assigned to us and up 11 // up : card found and assigned to us and up
12 12
13 NodeCollection * NC = nodeCollection(); 13 NodeCollection * NC = nodeCollection();
14 QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); 14 QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number());
15 System & Sys = NSResources->system(); 15 System & Sys = NSResources->system();
16 InterfaceInfo * Run; 16 InterfaceInfo * Run;
17 QFile F( S ); 17 QFile F( S );
18 Log(("Detecting for %s\n", NC->name().latin1() )); 18 Log(("Detecting for %s\n", NC->name().latin1() ));
19 19
20 if( F.open( IO_ReadOnly ) ) { 20 if( F.open( IO_ReadOnly ) ) {
21 // could open file -> read interface and assign 21 // could open file -> read interface and assign
22 QString X; 22 QString X;
23 QTextStream TS(&F); 23 QTextStream TS(&F);
24 X = TS.readLine(); 24 X = TS.readLine();
25 Log(("%s exists\n", S.latin1() )); 25 Log(("%s exists\n", S.latin1() ));
26 // find interface 26 // find interface
27 if( handlesInterface( X ) ) { 27 if( handlesInterface( X ) ) {
28 for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); 28 for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
29 It.current(); 29 It.current();
30 ++It ) { 30 ++It ) {
31 Run = It.current(); 31 Run = It.current();
32 if( X == Run->Name ) { 32 if( X == Run->Name ) {
33 NC->assignInterface( Run ); 33 NC->assignInterface( Run );
34 return IsUp; 34 return IsUp;
35 } 35 }
36 } 36 }
37 } 37 }
38 } 38 }
39 39
40 Log(("Assigned %p\n", NC->assignedInterface() )); 40 Log(("Assigned %p\n", NC->assignedInterface() ));
41
41 if( ( Run = NC->assignedInterface() ) ) { 42 if( ( Run = NC->assignedInterface() ) ) {
42 // we already have an interface assigned -> still present ? 43 // we already have an interface assigned -> still present ?
43 if( ! Run->IsUp ) { 44 if( ! Run->IsUp ) {
44 // usb is still free -> keep assignment 45 // usb is still free -> keep assignment
45 return Available; 46 return Available;
46 } // else interface is up but NOT us -> some other profile 47 } // else interface is up but NOT us -> some other profile
47 } 48 }
48 49
49 // nothing (valid) assigned to us 50 // nothing (valid) assigned to us
50 NC->assignInterface( 0 ); 51 NC->assignInterface( 0 );
51 52
52 // find possible interface 53 // find possible interface
53 for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); 54 if( getInterface() ) {
54 It.current(); 55 // proper type, and Not UP -> free
55 ++It ) { 56 // usb cables are currently always available when requested
56 Run = It.current(); 57 // until we can detect if we are plugged in
57 58 return Available;
58 Log(("%s %d %d=%d %d\n",
59 Run->Name.latin1(),
60 handlesInterface( Run->Name ),
61 Run->CardType, ARPHRD_ETHER,
62 ! Run->IsUp ));
63
64 if( handlesInterface( Run->Name ) &&
65 Run->CardType == ARPHRD_ETHER &&
66 ! Run->IsUp
67 ) {
68 // proper type, and Not UP -> free
69 // usb cables are currently always available when requested
70 // until we can detect if we are plugged in
71 return Available;
72 }
73 } 59 }
74 60
75 return Unavailable; 61 return Unavailable;
76} 62}
77 63
78QString USBRun::setMyState( NodeCollection * NC, Action_t A, bool ) { 64QString USBRun::setMyState( NodeCollection * NC, Action_t A, bool ) {
79 65
80 // nothing needs to be done to 'activate' or 'deactivate' 66 InterfaceInfo * I = getInterface();
81 // a cable 67
68 if( ! I ) {
69 return QString("No usb device available");
70 }
71
72 Log(( "Grabbed USB interface %s\n", I->Name.latin1() ));
73 // grab this interface
74 NC->assignInterface( I );
75
82 return QString(); 76 return QString();
83} 77}
84 78
85// get interface that is free or assigned to us 79// get interface that is free or assigned to us
86InterfaceInfo * USBRun::getInterface( void ) { 80InterfaceInfo * USBRun::getInterface( void ) {
87 81
88 System & S = NSResources->system(); 82 System & S = NSResources->system();
89 InterfaceInfo * best = 0, * Run; 83 InterfaceInfo * best = 0, * Run;
90 QRegExp R( "usb[0-9abcdef]" );
91 84
92 for( QDictIterator<InterfaceInfo> It(S.interfaces()); 85 for( QDictIterator<InterfaceInfo> It(S.interfaces());
93 It.current(); 86 It.current();
94 ++It ) { 87 ++It ) {
95 Run = It.current(); 88 Run = It.current();
89
90 Log(("%s %d %d=%d %d\n",
91 Run->Name.latin1(),
92 handlesInterface( Run->Name ),
93 Run->CardType, ARPHRD_ETHER,
94 ! Run->IsUp ));
95
96 if( handlesInterface( Run->Name ) && 96 if( handlesInterface( Run->Name ) &&
97 Run->CardType == ARPHRD_ETHER 97 Run->CardType == ARPHRD_ETHER
98 ) { 98 ) {
99 // this is a USB card 99 // this is a USB card
100 if( Run->assignedConnection() == netNode()->connection() ) { 100 if( Run->assignedConnection() == netNode()->connection() ) {
101 // assigned to us 101 // assigned to us
102 return Run; 102 return Run;
103 } else if( Run->assignedConnection() == 0 ) { 103 } else if( ! Run->IsUp &&
104 Run->assignedConnection() == 0 ) {
104 // free 105 // free
105 best = Run; 106 best = Run;
106 } 107 } // UP or not assigned to us
107 } 108 }
108 } 109 }
109 return best; // can be 0 110 return best; // can be 0
110} 111}
111 112
112bool USBRun::handlesInterface( const QString & S ) { 113bool USBRun::handlesInterface( const QString & S ) {
113 return Pat.match( S ) >= 0; 114 return Pat.match( S ) >= 0;
114} 115}
115 116
116bool USBRun::handlesInterface( InterfaceInfo * I ) { 117bool USBRun::handlesInterface( InterfaceInfo * I ) {
117 return handlesInterface( I->Name ); 118 return handlesInterface( I->Name );
118} 119}
119 120