From 2a7afda8b7daf4a43e370dba09e43e7f5058ab49 Mon Sep 17 00:00:00 2001 From: wimpie Date: Tue, 04 Jan 2005 01:39:32 +0000 Subject: More NS2 files --- (limited to 'noncore') diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.cpp new file mode 100644 index 0000000..ee3e92b --- a/dev/null +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.cpp @@ -0,0 +1,78 @@ +#include "bluetoothBNEP_NN.h" +#include "bluetoothBNEP_NNI.h" +#include "bluetoothRFCOMM_NNI.h" + +// +// +// BLUETOOTH PAN/NAP node +// +// + +static const char * BluetoothBNEPNeeds[] = + { 0 + }; + +static const char * BluetoothBNEPProvides[] = + { "device", + 0 + }; + +/** + * Constructor, find all of the possible interfaces + */ +BluetoothBNEPNetNode::BluetoothBNEPNetNode() : + ANetNode(tr("Bluetooth PAN/NAP")) { + InstanceCount = 7; // default +} + +/** + * Delete any interfaces that we own. + */ +BluetoothBNEPNetNode::~BluetoothBNEPNetNode(){ +} + +const QString BluetoothBNEPNetNode::nodeDescription(){ + return tr("\ +

Sets up a bluetooth link using the bluetooth Network profile.

\ +

Use this to connect two computing devices.

\ +" +); +} + +ANetNodeInstance * BluetoothBNEPNetNode::createInstance( void ) { + return new ABluetoothBNEP( this ); +} + +const char ** BluetoothBNEPNetNode::needs( void ) { + return BluetoothBNEPNeeds; +} + +const char ** BluetoothBNEPNetNode::provides( void ) { + return BluetoothBNEPProvides; +} + +QString BluetoothBNEPNetNode::genNic( long nr ) { + QString S; + return S.sprintf( "bnep%ld", nr ); +} + + +void BluetoothBNEPNetNode::setSpecificAttribute( QString & A, QString & V ) { + if( A == "interfacecount" ) { + InstanceCount = V.toLong(); + } +} + +void BluetoothBNEPNetNode::saveSpecificAttribute( QTextStream & TS) { + TS << "interfacecount=" + << InstanceCount + << endl; +} + +extern "C" { +// create plugin registers both BT functions +void create_plugin( QList & PNN ) { + PNN.append( new BluetoothBNEPNetNode() ); + PNN.append( new BluetoothRFCOMMNetNode() ); +} +} diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.h b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.h new file mode 100644 index 0000000..5057e6d --- a/dev/null +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.h @@ -0,0 +1,44 @@ +#ifndef BLUETOOTHBNEP_NETNODE_H +#define BLUETOOTHBNEP_NETNODE_H + +#include "netnode.h" +#include "bluetoothRFCOMM_NN.h" + +class ABluetoothBNEP; + +class BluetoothBNEPNetNode : public ANetNode { + + Q_OBJECT + +public: + + BluetoothBNEPNetNode(); + virtual ~BluetoothBNEPNetNode(); + + virtual QString genNic( long ); + virtual long instanceCount( void ) + { return InstanceCount; } + virtual const QString pixmapName() + { return "Devices/bluetooth"; } + + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** provides( void ); + virtual const char ** needs( void ); + +private: + + virtual void setSpecificAttribute( QString & Attr, QString & Value ); + virtual void saveSpecificAttribute( QTextStream & TS ); + + // number of interfaces for this device + long InstanceCount; + +}; + +extern "C" +{ + void create_plugin( QList & PNN ); +}; + +#endif diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NN.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NN.cpp new file mode 100644 index 0000000..2b17ab5 --- a/dev/null +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NN.cpp @@ -0,0 +1,46 @@ +#include "bluetoothRFCOMM_NN.h" +#include "bluetoothRFCOMM_NNI.h" + +static const char * BluetoothRFCOMMNeeds[] = + { 0 + }; + +static const char * BluetoothRFCOMMProvides[] = + { "line", + "GPRS" + }; + +BluetoothRFCOMMNetNode::BluetoothRFCOMMNetNode() : + ANetNode( tr("Bluetooth serial link") ) { +} + +BluetoothRFCOMMNetNode::~BluetoothRFCOMMNetNode(){ +} + +const QString BluetoothRFCOMMNetNode::nodeDescription(){ + return tr("\ +

Sets up a bluetooth link using the bluetooth serial profile.

\ +

Use this to connect to a GSM.

\ +" +); +} + +ANetNodeInstance * BluetoothRFCOMMNetNode::createInstance( void ) { + return new ABluetoothRFCOMM( this ); +} + +const char ** BluetoothRFCOMMNetNode::needs( void ) { + return BluetoothRFCOMMNeeds; +} + +const char ** BluetoothRFCOMMNetNode::provides( void ) { + return BluetoothRFCOMMProvides; +} + +void BluetoothRFCOMMNetNode::setSpecificAttribute( QString &, QString & ) { +} + +void BluetoothRFCOMMNetNode::saveSpecificAttribute( QTextStream & ) { +} + +// create plugin -> see BNEP diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NN.h b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NN.h new file mode 100644 index 0000000..cc7037a --- a/dev/null +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NN.h @@ -0,0 +1,29 @@ +#ifndef BLUETOOTHRFCOMM_NETNODE_H +#define BLUETOOTHRFCOMM_NETNODE_H + +#include "netnode.h" + +class BluetoothRFCOMMNetNode : public ANetNode { + + Q_OBJECT + +public: + + BluetoothRFCOMMNetNode(); + virtual ~BluetoothRFCOMMNetNode(); + + virtual const QString pixmapName() + { return "Devices/bluetooth"; } + + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** needs( void ); + virtual const char ** provides( void ); + +private: + + virtual void setSpecificAttribute( QString & Attr, QString & Value ); + virtual void saveSpecificAttribute( QTextStream & TS ); +}; + +#endif diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp new file mode 100644 index 0000000..1e91ed1 --- a/dev/null +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp @@ -0,0 +1,162 @@ +#include +#include +#include +#include +#include "bluetoothRFCOMMrun.h" + +using namespace Opietooth2; + +BluetoothRFCOMMRun::~BluetoothRFCOMMRun( void ) { + if( OT ) { + OTGateway::releaseOTGateway(); + } +} + +State_t BluetoothRFCOMMRun::detectState( void ) { + + if( ! OT ) { + OT = OTGateway::getOTGateway(); + } + + if( deviceNrOfConnection() >= 0 ) { + return Available; + } + + owarn << "Bluetooth " + << OT->isEnabled() + << oendl; + + return ( OT->isEnabled() ) ? Off : Unavailable; +} + +QString BluetoothRFCOMMRun::setMyState( NodeCollection *, + Action_t A, + bool ) { + + if( OT ) { + OTGateway::getOTGateway(); + } + + if( A == Activate ) { + // from OFF to Available + RFCOMMChannel * Ch = getChannel( ); + System & Sys = NSResources->system(); + + if( Ch ) { + // connect to this peer + DeviceNr = OT->getFreeRFCommDevice(); + QStringList S; + + S << "rfcomm" + << "bind" + << QString().setNum( DeviceNr ) + << Ch->BDAddress + << QString().setNum( Ch->Channel ); + + if( Sys.runAsRoot( S ) ) { + return QString( "Error starting %1").arg(S.join(" ")); + } + + // here rfcomm should be running -> we will detect state later + return QString(); + } else { + Log(( "No channel selected -> cancel\n" )); + return QString( "No channel selected. Operation cancelled" ); + } + } + + if( A == Deactivate ) { + if( DeviceNr >= 0 ) { + if( OT->releaseRFCommDevice( DeviceNr ) ) { + return QString( "Cannot release RFCOMM connection" ); + } + DeviceNr = -1; + } + } + return QString(); +} + +#include +#include +#include +#include +#include + +RFCOMMChannel * BluetoothRFCOMMRun::getChannel( void ) { + + if( Data->Devices.count() == 1 ) { + // only one device -> return channel + return Data->Devices[0]; + } + + RFCOMMChannel * Ch = 0; + QDialog * Dlg = new QDialog( qApp->mainWidget(), 0, TRUE ); + QVBoxLayout * V = new QVBoxLayout( Dlg ); + + QLabel * L = new QLabel( + qApp->translate( "BluetoothRFCOMMRun", + "Select device to connect to"), + Dlg ); + QListBox * LB = new QListBox( Dlg ); + + for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) { + LB->insertItem( QString( "%1 (%2 Chnl %3)" ). + arg( Data->Devices[i]->Name ). + arg( Data->Devices[i]->BDAddress ). + arg( Data->Devices[i]->Channel ) ); + } + + V->addWidget( L ); + V->addWidget( LB ); + + Dlg->resize( 100, 100 ); + Dlg->move( 20, + (qApp->desktop()->height()-100)/2 ); + + if( Dlg->exec() == QDialog::Accepted ) { + unsigned int i = 0; + for( i = 0; i < Data->Devices.count(); i ++ ) { + if( LB->isSelected(i) ) { + owarn << "Selected " << Data->Devices[i]->Name << oendl; + Ch = Data->Devices[i]; + break; + } + } + } + + delete Dlg; + return Ch; +} + +QString BluetoothRFCOMMRun::deviceFile( void ) { + if( deviceNrOfConnection() >= 0 ) { + OTDevice * OTD = OT->getOTDevice(); + // there is a connection + return OTD->getRFCommDevicePattern().arg(DeviceNr); + } + return QString(); +} + +int BluetoothRFCOMMRun::deviceNrOfConnection( void ) { + + if( ! OT ) { + OT = OTGateway::getOTGateway(); + } + + DeviceNr = -1; + for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) { + owarn << "Check for rfcomm on " + << Data->Devices[i]->BDAddress + << " " + << Data->Devices[i]->Channel + << oendl; + if( ( DeviceNr = OT->connectedToRFCommChannel( + OTDeviceAddress( Data->Devices[i]->BDAddress ), + Data->Devices[i]->Channel ) ) >= 0 ) { + owarn << "Up " + << oendl; + break; + } + } + return DeviceNr; +} diff --git a/noncore/settings/networksettings2/gprs/GPRS.pro b/noncore/settings/networksettings2/gprs/GPRS.pro new file mode 100644 index 0000000..7818415 --- a/dev/null +++ b/noncore/settings/networksettings2/gprs/GPRS.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +CONFIG += qt warn_on release +DESTDIR = $(OPIEDIR)/plugins/networksettings2 +HEADERS = GPRS_NN.h \ + GPRS_NNI.h \ + GPRSedit.h +SOURCES = GPRS_NN.cpp \ + GPRS_NNI.cpp \ + GPRSedit.cpp \ + GPRSrun.cpp +INCLUDEPATH += $(OPIEDIR)/include ../ ../networksettings2 +DEPENDPATH += $(OPIEDIR)/include ../ ../networksettings2 +LIBS += -lqpe +INTERFACES = GPRSGUI.ui +TARGET = GPRS +VERSION = 1.0.0 + +include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings2/gprs/GPRSGUI.ui b/noncore/settings/networksettings2/gprs/GPRSGUI.ui new file mode 100644 index 0000000..1ba5971 --- a/dev/null +++ b/noncore/settings/networksettings2/gprs/GPRSGUI.ui @@ -0,0 +1,910 @@ + +GPRSGUI + + QWidget + + name + GPRSGUI + + + geometry + + 0 + 0 + 326 + 418 + + + + caption + GPRS Configuration + + + layoutMargin + + + layoutSpacing + + + + margin + 0 + + + spacing + 0 + + + QTabWidget + + name + TabWidget2 + + + layoutMargin + + + layoutSpacing + + + QWidget + + name + tab + + + title + Login + + + + margin + 3 + + + spacing + 3 + + + QLayoutWidget + + name + Layout10 + + + + margin + 0 + + + spacing + 6 + + + QLineEdit + + name + User_LE + + + + QLabel + + name + TextLabel1_3_2 + + + text + User + + + + QLineEdit + + name + Password_LE + + + + QLabel + + name + TextLabel1_3 + + + text + APN + + + + QLabel + + name + TextLabel1_3_3 + + + text + Password + + + alignment + AlignVCenter|AlignLeft + + + wordwrap + + + + QLineEdit + + name + APN_LE + + + + + + + name + Spacer9 + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + + QWidget + + name + tab + + + title + DNS + + + + margin + 3 + + + spacing + 3 + + + QCheckBox + + name + AssignedByServer_CB + + + text + As assigned by server + + + checked + true + + + + QLayoutWidget + + name + Layout10 + + + layoutSpacing + + + + margin + 0 + + + spacing + 0 + + + + name + Spacer14 + + + orientation + Horizontal + + + sizeType + Fixed + + + sizeHint + + 20 + 20 + + + + + QFrame + + name + Frame5 + + + enabled + false + + + frameShape + NoFrame + + + frameShadow + Raised + + + layoutMargin + + + layoutSpacing + + + + margin + 0 + + + spacing + 2 + + + QLineEdit + + name + DNS2_LE + + + sizePolicy + + 1 + 0 + + + + + QLabel + + name + TextLabel1_2 + + + text + DNS2 + + + + QLabel + + name + TextLabel1 + + + text + DNS1 + + + + QLineEdit + + name + DNS1_LE + + + sizePolicy + + 1 + 0 + + + + + + + + name + Spacer13 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + + + name + Spacer15 + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + + QWidget + + name + tab + + + title + Routing + + + + margin + 3 + + + spacing + 0 + + + QButtonGroup + + name + ButtonGroup1 + + + frameShape + NoFrame + + + title + + + + layoutMargin + + + layoutSpacing + + + + margin + 0 + + + spacing + -3 + + + QRadioButton + + name + DefaultGateway_RB + + + text + Set as default gateway + + + checked + true + + + + QLayoutWidget + + name + Layout13 + + + layoutSpacing + + + + margin + 0 + + + spacing + 0 + + + + name + Spacer8 + + + orientation + Horizontal + + + sizeType + Fixed + + + sizeHint + + 20 + 20 + + + + + QCheckBox + + name + SetIfSet_CB + + + enabled + true + + + text + Set even if Set + + + + + name + Spacer17 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + + QRadioButton + + name + FixedGateway_RB + + + text + Fixed Routing + + + + QLayoutWidget + + name + Layout11 + + + + margin + 0 + + + spacing + 6 + + + + name + Spacer8_2 + + + orientation + Horizontal + + + sizeType + Fixed + + + sizeHint + + 20 + 20 + + + + + QFrame + + name + Frame3 + + + enabled + false + + + sizePolicy + + 7 + 5 + + + + frameShape + NoFrame + + + frameShadow + Raised + + + layoutMargin + + + layoutSpacing + + + + margin + 3 + + + spacing + 3 + + + QLayoutWidget + + name + Layout10 + + + layoutSpacing + + + + margin + 0 + + + spacing + 3 + + + QLineEdit + + name + Net_LE + + + + QSpinBox + + name + Mask_SB + + + sizePolicy + + 7 + 0 + + + + maximumSize + + 32767 + 32767 + + + + maxValue + 32 + + + minValue + 1 + + + value + 24 + + + + QLabel + + name + TextLabel1_6 + + + text + Mask + + + + QToolButton + + name + Delete_TB + + + text + ... + + + + QLabel + + name + TextLabel1_5_2 + + + text + Net + + + + QToolButton + + name + Add_TB + + + text + ... + + + + + + QListView + + + text + Network + + + clickable + true + + + resizeable + true + + + + + text + Mask + + + clickable + true + + + resizeable + true + + + + name + Routing_LV + + + selectionMode + Extended + + + allColumnsShowFocus + true + + + + + + + + + + + + QWidget + + name + tab + + + title + Misc + + + + margin + 3 + + + spacing + 3 + + + QLayoutWidget + + name + Layout4 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + TextLabel1_4 + + + sizePolicy + + 0 + 1 + + + + text + Debug + + + + QSpinBox + + name + Debug_SB + + + maxValue + 3 + + + + + name + Spacer2 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + + + name + Spacer3 + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + + + + + + AssignedByServer_CB + toggled(bool) + Frame5 + setDisabled(bool) + + + FixedGateway_RB + toggled(bool) + Frame3 + setEnabled(bool) + + + DefaultGateway_RB + toggled(bool) + SetIfSet_CB + setEnabled(bool) + + + Add_TB + clicked() + GPRSGUI + SLOT_AddRoute() + + + Delete_TB + clicked() + GPRSGUI + SLOT_DeleteRoute() + + SLOT_AddRoute() + SLOT_AddServer() + SLOT_RemoveServer() + SLOT_DeleteRoute() + + + APN_LE + User_LE + Password_LE + DNS1_LE + DNS2_LE + + diff --git a/noncore/settings/networksettings2/gprs/GPRS_NN.cpp b/noncore/settings/networksettings2/gprs/GPRS_NN.cpp new file mode 100644 index 0000000..5393324 --- a/dev/null +++ b/noncore/settings/networksettings2/gprs/GPRS_NN.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include "GPRS_NN.h" +#include "GPRS_NNI.h" + +static const char * GPRSNeeds[] = + { "GPRS", + 0 + }; + +static const char * GPRSProvides[] = + { "connection", + 0 + }; + +/** + * Constructor, find all of the possible interfaces + */ +GPRSNetNode::GPRSNetNode() : ANetNode(tr("GPRS capable device")) { + NSResources->addSystemFile( + "pap-secrets", "/etc/ppp/pap-secrets", 0 ); +} + +/** + * Delete any interfaces that we own. + */ +GPRSNetNode::~GPRSNetNode(){ +} + +const QString GPRSNetNode::nodeDescription(){ + return tr("\ +

provides access to a GPRS capable device.

\ +" +); +} + +ANetNodeInstance * GPRSNetNode::createInstance( void ) { + return new AGPRSDevice( this ); +} + +bool GPRSNetNode::hasDataForFile( SystemFile & S ) { + return S.name() == "pap-secrets"; +} + +short GPRSNetNode::generateFile( SystemFile & , + ANetNodeInstance * , + long ) { + + return 0; +} + +const char ** GPRSNetNode::needs( void ) { + return GPRSNeeds; +} + +const char ** GPRSNetNode::provides( void ) { + return GPRSProvides; +} + +void GPRSNetNode::setSpecificAttribute( QString & , QString & ) { +} + +void GPRSNetNode::saveSpecificAttribute( QTextStream & ) { +} + +QStringList GPRSNetNode::properFiles( void ) { + QStringList SL; + + SL << "peers"; + SL << "chatscripts"; + SL << "extra"; + return SL; +} + +extern "C" { +void create_plugin( QList & PNN ) { + PNN.append( new GPRSNetNode() ); +} +} diff --git a/noncore/settings/networksettings2/gprs/GPRS_NN.h b/noncore/settings/networksettings2/gprs/GPRS_NN.h new file mode 100644 index 0000000..6a036e1 --- a/dev/null +++ b/noncore/settings/networksettings2/gprs/GPRS_NN.h @@ -0,0 +1,43 @@ +#ifndef GPRS_NETNODE_H +#define GPRS_NETNODE_H + +#include "netnode.h" + +class ANetwork; + +class GPRSNetNode : public ANetNode{ + + Q_OBJECT + +public: + + GPRSNetNode(); + virtual ~GPRSNetNode(); + + virtual bool hasDataForFile( SystemFile & S ); + + virtual short generateFile( SystemFile & Sf, + ANetNodeInstance * NNI, + long DevNr ); + virtual const QString pixmapName() + { return "Devices/gprs"; } + + virtual QStringList properFiles( void ); + + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** needs( void ); + virtual const char ** provides( void ); + +private: + + virtual void setSpecificAttribute( QString & Attr, QString & Value ); + virtual void saveSpecificAttribute( QTextStream & TS ); +}; + +extern "C" +{ + void create_plugin( QList & PNN ); +}; + +#endif diff --git a/noncore/settings/networksettings2/gprs/GPRS_NNI.cpp b/noncore/settings/networksettings2/gprs/GPRS_NNI.cpp new file mode 100644 index 0000000..2f61cba --- a/dev/null +++ b/noncore/settings/networksettings2/gprs/GPRS_NNI.cpp @@ -0,0 +1,231 @@ +#include +#include +#include "GPRSedit.h" +#include "GPRS_NNI.h" +#include "GPRS_NN.h" + +AGPRSDevice::AGPRSDevice( GPRSNetNode * PNN ) : ANetNodeInstance( PNN ) { + Data.APN = ""; + Data.User = ""; + Data.Password = ""; + Data.DefaultGateway = 1; + Data.SetIfSet = 0; + Data.Debug = 0; + Data.Routing.setAutoDelete( TRUE ); + GUI = 0; + RT = 0; +} + +void AGPRSDevice::setSpecificAttribute( QString & A, QString & V ) { + if( A == "apn" ) { + Data.APN = V; + } else if( A == "user" ) { + Data.User = V; + } else if( A == "password" ) { + Data.Password = V; + } else if( A == "dns2" ) { + Data.DNS2 = V; + } else if( A == "dns1" ) { + Data.DNS1 = V; + } else if( A == "defaultgateway" ) { + Data.DefaultGateway = (V=="yes"); + } else if( A == "setifset" ) { + Data.SetIfSet = (V == "yes"); + } else if( A == "routes" ) { + Data.Routing.resize( V.toULong() ); + } else if( A.startsWith( "route" ) ) { + QStringList SL = QStringList::split( "/", V ); + GPRSRoutingEntry * E = new GPRSRoutingEntry; + + E->Address = SL[0]; + E->Mask = SL[1].toULong(); + + Data.Routing.insert( A.mid(5).toULong(), E ); + } else if( A == "debug" ) { + Data.Debug = V.toShort(); + } +} + +void AGPRSDevice::saveSpecificAttribute( QTextStream & TS ) { + TS << "apn=" << Data.APN << endl; + TS << "user=" << Data.User << endl; + TS << "password=" << Data.Password << endl; + TS << "dns1=" << Data.DNS1 << endl; + TS << "dns2=" << Data.DNS2 << endl; + TS << "defaultgateway=" << ( (Data.DefaultGateway) ? "yes" : "no" ) << endl; + TS << "setifset=" << ((Data.SetIfSet) ? "yes" : "no") << endl; + TS << "debug=" << Data.Debug << endl; + + TS << "routes=" << Data.Routing.count() << oendl; + for( unsigned int i = 0; i < Data.Routing.count(); i ++ ) { + TS << "route" << i << "=" + << Data.Routing[i]->Address + << "/" + << Data.Routing[i]->Mask + << oendl; + } +} + +QWidget * AGPRSDevice::edit( QWidget * parent ) { + GUI = new GPRSEdit( parent ); + GUI->showData( Data ); + return GUI; +} + +QString AGPRSDevice::acceptable( void ) { + return ( GUI ) ? GUI->acceptable( ) : QString(); +} + +void AGPRSDevice::commit( void ) { + if( GUI && GUI->commit( Data ) ) + setModified( 1 ); +} + +bool AGPRSDevice::hasDataForFile( SystemFile & S ) { + return S.name() == "pap-secrets" || + S.name() == "peers" || + S.name() == "extra" || + S.name() == "chatscripts" ; +} + +short AGPRSDevice::generateFile( SystemFile & SF, + long + ) { + + if( SF.name() == "pap-secrets" ) { + SF << Data.User + << " * " + << Data.Password + << " *" + << endl; + return 0; + } else if( SF.name() == "chatscripts" ) { + SF << "SAY \"Starting\\n\"" << oendl; + SF << "ECHO OFF" << oendl; + SF << "ABORT BUSY" << oendl; + SF << "ABORT ERROR" << oendl; + SF << "ABORT VOICE" << oendl; + SF << "ABORT \"NO CARRIER\"" << oendl; + SF << "ABORT \"NO DIALTONE\"" << oendl; + SF << "\"\" AT" << oendl; + SF << "OK AT+CGATT=1" << oendl; + SF << "OK AT+CGDCONT=1,\"IP\",\"" + << Data.APN + << "\"" + << oendl; + SF << "OK ATD*99***1#\\n" << oendl; + SF << "TIMEOUT 10" << oendl; + SF << "CONNECT \"\"" << oendl; + SF << "SAY \"READY\\n\"" << oendl; + return 0; + } else if( SF.name() == "peers" ) { + SF << "noauth" << oendl; + SF << "user " << Data.User << oendl; + SF << "connect \"/usr/sbin/chat -s -v -f /etc/chatscripts/" + << removeSpaces( connection()->name() ) + << "\"" + << oendl; + SF << "ipcp-accept-local" << oendl; + SF << "ipcp-accept-remote" << oendl; + if( Data.DefaultGateway ) { + SF << "defaultroute" << oendl; + if( Data.SetIfSet ) { + SF << "replacedefaultroute" << oendl; + } + } + if( Data.Debug ) { + SF << "logfile /tmp/" + << removeSpaces( connection()->name() ) + << oendl; + for( int i = 0; i < Data.Debug; i ++ ) { + SF << "debug" << oendl; + } + } + SF << "nocrtscts" << oendl; + SF << "local" << oendl; + SF << "lcp-echo-interval 0" << oendl; + SF << "lcp-echo-failure 0" << oendl; + SF << "usepeerdns" << oendl; + SF << "linkname " << removeSpaces( connection()->name() ) << oendl; + SF << "nopersist" << oendl; + SF << "ipparam " << removeSpaces( connection()->name() ) <Mask == 32 ) { + Bits = 0xffffffff; + } else { + Bits = ~ ((1 << ((32-Data.Routing[i]->Mask))) - 1); + } + SF << "route add -net " + << Data.Routing[i]->Address + << " netmask " + << ((Bits&0xff000000)>>24) + << "." + << ((Bits&0x00ff0000)>>16) + << "." + << ((Bits&0x0000ff00)>>8) + << "." + << ((Bits&0x000000ff)) + << " gw $PPP_REMOTE" + << oendl; + SF << "route del -net " + << Data.Routing[i]->Address + << " netmask " + << ((Bits&0xff000000)>>24) + << "." + << ((Bits&0x00ff0000)>>16) + << "." + << ((Bits&0x0000ff00)>>8) + << "." + << ((Bits&0x000000ff)) + << " gw $PPP_REMOTE" + << oendl; + } + + if( ! Data.DNS1.isEmpty() ) { + SF << "nameserver " + << Data.DNS1 + << " # profile " + << removeSpaces( connection()->name() ) + <name() ) + <name() ) + ); + return 1; + } else if ( SF.name() == "chatscripts" ) { + SF.setPath( + QString( "/etc/chatscripts/" ) + + removeSpaces( connection()->name() ) + ); + return 1; + } else if ( SF.name() == "extra" ) { + SF.setPath( + QString( "/etc/ppp/" ) + + removeSpaces( connection()->name() ) + ".fixed" + ); + return 1; + } + return 0; +} diff --git a/noncore/settings/networksettings2/gprs/GPRS_NNI.h b/noncore/settings/networksettings2/gprs/GPRS_NNI.h new file mode 100644 index 0000000..1060a6e --- a/dev/null +++ b/noncore/settings/networksettings2/gprs/GPRS_NNI.h @@ -0,0 +1,48 @@ +#ifndef GPRS_H +#define GPRS_H + +#include +#include "GPRSdata.h" +#include "GPRSrun.h" + +class GPRSNetNode; +class GPRSEdit; +class SystemFile; + +class AGPRSDevice : public ANetNodeInstance{ + +public : + + AGPRSDevice( GPRSNetNode * PNN ); + + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new GPRSRun( this, Data ) ); + } + + QWidget * edit( QWidget * parent ); + QString acceptable( void ); + void commit( void ); + + virtual bool openFile( SystemFile & SF ); + + virtual void * data( void ) + { return (void *)&Data; } + + virtual bool hasDataForFile( SystemFile & S ); + virtual short generateFile( SystemFile & SF, + long DevNr ); + +protected : + + virtual void setSpecificAttribute( QString & Attr, QString & Value ); + virtual void saveSpecificAttribute( QTextStream & TS ); + +private : + + GPRSEdit * GUI; + GPRSData Data; + GPRSRun * RT; +}; + +#endif diff --git a/noncore/settings/networksettings2/gprs/GPRSdata.h b/noncore/settings/networksettings2/gprs/GPRSdata.h new file mode 100644 index 0000000..d68c3f2 --- a/dev/null +++ b/noncore/settings/networksettings2/gprs/GPRSdata.h @@ -0,0 +1,24 @@ +#ifndef GPRS_DATA_H +#define GPRS_DATA_H + +#include +class GPRSRoutingEntry { +public : + QString Address; + short Mask; +}; + +class GPRSData { +public : + QString APN; + QString User; + QString Password; + QString DNS1; + QString DNS2; + bool SetIfSet; + bool DefaultGateway; + short Debug; + QVector Routing; +} ; + +#endif diff --git a/noncore/settings/networksettings2/gprs/GPRSedit.cpp b/noncore/settings/networksettings2/gprs/GPRSedit.cpp new file mode 100644 index 0000000..d72b9a2 --- a/dev/null +++ b/noncore/settings/networksettings2/gprs/GPRSedit.cpp @@ -0,0 +1,164 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "GPRSedit.h" + +GPRSEdit::GPRSEdit( QWidget * Parent ) : GPRSGUI( Parent ){ + Routing_LV->header()->hide(); + Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); + Delete_TB->setPixmap( NSResources->getPixmap( "delete" ) ); + Routing_LV->setColumnAlignment( 1, Qt::AlignRight ); +} + +QString GPRSEdit::acceptable( void ) { + if( APN_LE->text().isEmpty() ) { + return tr("APN is required"); + } + + return QString(); +} + +bool GPRSEdit::commit( GPRSData & Data ) { + bool SM = 0; + bool RM; + + TXTM( Data.APN, APN_LE, SM ); + TXTM( Data.User, User_LE, SM ); + TXTM( Data.Password, Password_LE, SM ); + + if( AssignedByServer_CB->isChecked() ) { + if( ! Data.DNS1.isEmpty() ) { + SM = 1; + Data.DNS1 = ""; + } + if( ! Data.DNS2.isEmpty() ) { + SM = 1; + Data.DNS2 = ""; + } + } else { + TXTM( Data.DNS1, DNS1_LE, SM ); + TXTM( Data.DNS2, DNS2_LE, SM ); + } + + CBM( Data.DefaultGateway, DefaultGateway_RB, SM ); + CBM( Data.SetIfSet, SetIfSet_CB, SM ); + + // find new routes + unsigned int i; + + RM = 0; // routing modified + QListViewItem * it = Routing_LV->firstChild(); + while( ! RM && it ) { + for( i = 0; i < Data.Routing.count(); i ++ ) { + if( it->text(0) == Data.Routing[i]->Address ) { + // still exists + break; + } + } + if( i == Data.Routing.count() ) { + // modified + RM = 1; + } + it = it->nextSibling(); + } + + // find obsoleted + for( i = 0; ! RM && i < Data.Routing.count(); i ++ ) { + it = Routing_LV->firstChild(); + while( it ) { + if( it->text(0) == Data.Routing[i]->Address ) { + // still exists + break; + } + it = it->nextSibling(); + } + + if( it == 0 ) { + RM = 1; + } + } + + if( RM ) { + unsigned int i = 0; + GPRSRoutingEntry * E; + // update routing table + Data.Routing.resize(0); + Data.Routing.resize( Routing_LV->childCount() ); + + it = Routing_LV->firstChild(); + while( it ) { + E = new GPRSRoutingEntry; + E->Address = it->text(0); + E->Mask = it->text(1).toShort(); + Data.Routing.insert( i, E ); + i ++; + it = it->nextSibling(); + } + } + + SBM( Data.Debug, Debug_SB, SM ); + return SM; +} + +void GPRSEdit::showData( GPRSData & Data ) { + STXT( Data.APN, APN_LE ); + STXT( Data.User, User_LE ); + STXT( Data.Password, Password_LE ); + + SCB( ( Data.DNS1.isEmpty() && Data.DNS2.isEmpty() ), + AssignedByServer_CB ); + STXT( Data.DNS1, DNS1_LE ); + STXT( Data.DNS2, DNS2_LE ); + + SCB( Data.DefaultGateway, DefaultGateway_RB ); + SCB( (! Data.DefaultGateway), FixedGateway_RB ); + SCB( Data.SetIfSet, SetIfSet_CB ); + + for( unsigned int i = 0; i < Data.Routing.count(); i ++ ) { + QListViewItem * it; + it = new QListViewItem( Routing_LV ); + + it->setText( 0, Data.Routing[i]->Address ); + it->setText( 1, QString().setNum( Data.Routing[i]->Mask ) ); + } + + SSB( Data.Debug, Debug_SB ); +} + +void GPRSEdit::SLOT_AddRoute( void ) { + QListViewItem * it, *last; + QListViewItem * after = Routing_LV->firstChild(); + last = 0; + while( after ) { + if( after->isSelected() ) { + break; + } + last = after; + after = after->nextSibling(); + } + + it = new QListViewItem( Routing_LV, (after) ? after : last ); + + it->setText( 0, Net_LE->text() ); + it->setText( 1, QString().setNum( Mask_SB->value() ) ); +} + +void GPRSEdit::SLOT_DeleteRoute( void ) { + QListViewItem * nit; + QListViewItem * it = Routing_LV->firstChild(); + while( it ) { + nit = it->nextSibling(); + if( it->isSelected() ) { + delete it; + } + it = nit; + } +} diff --git a/noncore/settings/networksettings2/gprs/GPRSedit.h b/noncore/settings/networksettings2/gprs/GPRSedit.h new file mode 100644 index 0000000..35e8ee6 --- a/dev/null +++ b/noncore/settings/networksettings2/gprs/GPRSedit.h @@ -0,0 +1,20 @@ +#include "GPRSdata.h" +#include "GPRSGUI.h" + +class GPRSEdit : public GPRSGUI { + +public : + + GPRSEdit( QWidget * parent ); + QString acceptable( void ); + bool commit( GPRSData & Data ); + void showData( GPRSData & Data ); + +public slots : + + void SLOT_AddRoute(); + void SLOT_DeleteRoute(); + +private : + +}; diff --git a/noncore/settings/networksettings2/gprs/GPRSrun.cpp b/noncore/settings/networksettings2/gprs/GPRSrun.cpp new file mode 100644 index 0000000..e842b99 --- a/dev/null +++ b/noncore/settings/networksettings2/gprs/GPRSrun.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include +#include +#include +#include +#include "GPRSrun.h" + +State_t GPRSRun::detectState( void ) { + + // is pppd still running ? + // is rfcomm still active + NodeCollection * NC = nodeCollection(); + InterfaceInfo * I = NC->assignedInterface(); + + QDir D("/var/run"); + + if( I ) { + // has some pppx attached + return ( I->IsUp ) ? IsUp : Available; + } + + // check ppp itself and figure out interface + + owarn << "Check for ppp " << NC->name() << oendl; + if( D.exists( QString("ppp-")+removeSpaces(NC->name())+".pid") ) { + // get pid and check if pppd is still running + QFile F( D.path()+"/ppp-"+removeSpaces(NC->name())+".pid"); + + owarn << "PPP PID " << F.name() << oendl; + if( F.open( IO_ReadOnly ) ) { + QTextStream TS(&F); + QString X = TS.readLine(); + PPPPid = X.toULong(); + int rv; + + rv = ::kill( PPPPid, 0 ); + if( rv == 0 || + ( rv < 0 && errno == EPERM ) + ) { + // pppd is still up + X = TS.readLine(); + I = NSResources->system().findInterface(X); + + owarn << "ppp running : IFace " << X << " = " << (long)I << oendl; + + if( I ) { + NC->assignInterface( I ); + return (I->IsUp) ? IsUp : Available; + } + + return Available; + + } else { + // pppd is down + PPPPid = 0; + } + } // else pppd is down + } + NC->assignInterface( 0 ); + return Unknown; +} + +QString GPRSRun::setMyState( NodeCollection * NC, Action_t A , bool ) { + + if( A == Up ) { + // start ppp on deviceFile + QStringList SL; + SL << "pon" + << removeSpaces( NC->name() ) + << NC->device()->deviceFile(); + + if( ! NSResources->system().execAsUser( SL ) ) { + return QString("Cannot start pppd for %1").arg(NC->name()); + } + } else if ( A == Down ) { + if( PPPPid == 0 ) { + detectState(); + } + if( PPPPid ) { + QStringList SL; + + SL << "poff" + << removeSpaces( NC->name() ); + + if( ! NSResources->system().execAsUser( SL ) ) { + return QString("Cannot terminate pppd for %1").arg(NC->name()); + } + NC->assignInterface( 0 ); + owarn << "ppp stopped " << oendl; + PPPPid = 0; + } + } + + return QString(); +} + +bool GPRSRun::handlesInterface( const QString & S ) { + return Pat.match( S ) >= 0; +} + +bool GPRSRun::handlesInterface( InterfaceInfo * I ) { + return handlesInterface( I->Name ); +} diff --git a/noncore/settings/networksettings2/gprs/GPRSrun.h b/noncore/settings/networksettings2/gprs/GPRSrun.h new file mode 100644 index 0000000..817f8a9 --- a/dev/null +++ b/noncore/settings/networksettings2/gprs/GPRSrun.h @@ -0,0 +1,34 @@ +#include +#include +#include "GPRSdata.h" + +class GPRSRun : public RuntimeInfo { + +public : + + GPRSRun( ANetNodeInstance * NNI, + GPRSData & D ) : RuntimeInfo( NNI ), + Pat( "ppp[0-9]" ) { + PPPPid = 0; + } + + bool handlesInterface( const QString & I ); + bool handlesInterface( InterfaceInfo * ); + + virtual RuntimeInfo * device( void ) + { return this; } + virtual RuntimeInfo * connection( void ) + { return this; } + + State_t detectState( void ); + +protected : + + QString setMyState( NodeCollection * , Action_t, bool ); + +private : + + QRegExp Pat; + size_t PPPPid; + +}; diff --git a/noncore/settings/networksettings2/gprs/config.in b/noncore/settings/networksettings2/gprs/config.in new file mode 100644 index 0000000..ec29264 --- a/dev/null +++ b/noncore/settings/networksettings2/gprs/config.in @@ -0,0 +1,4 @@ + config NS2GPRS + boolean "opie-networksettings2plugin-gprs (set up GPRS)" + default "n" if NS2 + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && NS2CORE diff --git a/noncore/settings/networksettings2/gprs/opie-networksettings2plugin-network.control b/noncore/settings/networksettings2/gprs/opie-networksettings2plugin-network.control new file mode 100644 index 0000000..902ebff --- a/dev/null +++ b/noncore/settings/networksettings2/gprs/opie-networksettings2plugin-network.control @@ -0,0 +1,9 @@ +Package: opie-networksettings2plugin-GPRS +Files: plugins/networksettings2/libGPRS.so* +Priority: optional +Section: opie/settings +Maintainer: Wim Delvaux +Architecture: arm +Depends: opie-networksettings2, libopiecore2, libopienet2 +Description: Setup GPRS network +Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/opie-networksettings2.control b/noncore/settings/networksettings2/opie-networksettings2.control new file mode 100644 index 0000000..e4bd29c --- a/dev/null +++ b/noncore/settings/networksettings2/opie-networksettings2.control @@ -0,0 +1,10 @@ +Package: opie-networksettings2 +Files: bin/networksettings2 apps/Settings/networksettings2.desktop pics/networksettings2/*.png lib/libnetworksettings2.so* pics/networksettings2/Devices/*.png +Priority: optional +Section: opie/settings +Maintainer: wim delvaux +Architecture: arm +Depends: task-opie-minimal, libopietooth2 +Description: Network settings. +Replaces: opie-networksetup +Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/opie-networksettings2.postinst b/noncore/settings/networksettings2/opie-networksettings2.postinst new file mode 100755 index 0000000..ce43274 --- a/dev/null +++ b/noncore/settings/networksettings2/opie-networksettings2.postinst @@ -0,0 +1,9 @@ +#!/bin/sh + +QTPB=/opt/QtPalmtop/bin + +[ ! -L ${QTPB}/networksettings2-request ] && ln -sf ${QTPB}/networksettings2 ${QTPB}/networksettings2-request + +qcop QPE/TaskBar "reloadApps()" + +exit 0 diff --git a/noncore/settings/networksettings2/ppp/PPPDialingedit.cpp b/noncore/settings/networksettings2/ppp/PPPDialingedit.cpp new file mode 100644 index 0000000..9264ceb --- a/dev/null +++ b/noncore/settings/networksettings2/ppp/PPPDialingedit.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include +#include +#include "PPPDialingedit.h" + +PPPDialingEdit::PPPDialingEdit( QWidget * Parent ) : + PPPDialingGUI( Parent ){ + + // populate widget stack +} + +QString PPPDialingEdit::acceptable( void ) { + return QString(); +} + +bool PPPDialingEdit::commit( PPPData & D ) { + bool SM; + return SM; +} + +void PPPDialingEdit::showData( PPPData & D ) { +} diff --git a/noncore/settings/networksettings2/ppp/PPPDialingedit.h b/noncore/settings/networksettings2/ppp/PPPDialingedit.h new file mode 100644 index 0000000..016bb3b --- a/dev/null +++ b/noncore/settings/networksettings2/ppp/PPPDialingedit.h @@ -0,0 +1,16 @@ +#include "pppdata.h" +#include "PPPDialingGUI.h" + +class PPPDialingEdit : public PPPDialingGUI { + +public : + + PPPDialingEdit( QWidget * parent ); + + QString acceptable( void ); + bool commit( PPPData & Data ); + void showData( PPPData & Data ); + +private : + +}; diff --git a/noncore/settings/networksettings2/ppp/PPPRunGUI.ui b/noncore/settings/networksettings2/ppp/PPPRunGUI.ui new file mode 100644 index 0000000..4532065 --- a/dev/null +++ b/noncore/settings/networksettings2/ppp/PPPRunGUI.ui @@ -0,0 +1,207 @@ + +PPPRunGUI + + QWidget + + name + PPPRunGUI + + + geometry + + 0 + 0 + 210 + 272 + + + + caption + PPPRun + + + layoutMargin + + + layoutSpacing + + + + margin + 3 + + + spacing + 3 + + + QGroupBox + + name + GroupBox1 + + + title + Upon connect + + + layoutMargin + + + layoutSpacing + + + + margin + 3 + + + spacing + 3 + + + QLineEdit + + name + PreConnect_LE + + + + QLabel + + name + TextLabel2 + + + text + Before + + + + QLineEdit + + name + PostConnect_LE + + + + QLabel + + name + TextLabel2_2 + + + text + After + + + + + + QGroupBox + + name + GroupBox1_2 + + + title + Upon disconnect + + + layoutMargin + + + layoutSpacing + + + + margin + 3 + + + spacing + 3 + + + QLineEdit + + name + PreDisconnect_LE + + + + QLabel + + name + TextLabel2_3 + + + text + Before + + + + QLineEdit + + name + PostDisconnect_LE + + + + QLabel + + name + TextLabel2_2_2 + + + text + After + + + + + + QLabel + + name + TextLabel1 + + + text + <UL> +<LI>Commands run under your <b>real</b> user id (<b>not</b> as root)</LI> +<LI>Supply the whole path</LI> +</UL> + + + alignment + WordBreak|AlignVCenter|AlignLeft + + + wordwrap + + + + + name + Spacer1 + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + diff --git a/noncore/settings/networksettings2/ppp/PPPRunedit.cpp b/noncore/settings/networksettings2/ppp/PPPRunedit.cpp new file mode 100644 index 0000000..23fcd3c --- a/dev/null +++ b/noncore/settings/networksettings2/ppp/PPPRunedit.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#include +#include +#include "PPPRunedit.h" + +PPPRunEdit::PPPRunEdit( QWidget * Parent ) : PPPRunGUI( Parent ){ +} + +QString PPPRunEdit::acceptable( void ) { + return QString(); +} + +bool PPPRunEdit::commit( PPPData & D ) { + bool SM = 0; + + TXTM( D.Run.PreConnect, PreConnect_LE, SM ); + TXTM( D.Run.PostConnect, PostConnect_LE, SM ); + TXTM( D.Run.PreDisconnect, PreDisconnect_LE, SM ); + TXTM( D.Run.PostDisconnect, PostDisconnect_LE, SM ); + return SM; +} + +void PPPRunEdit::showData( PPPData & D ) { + STXT( D.Run.PreConnect, PreConnect_LE); + STXT( D.Run.PostConnect, PostConnect_LE); + STXT( D.Run.PreDisconnect, PreDisconnect_LE ); + STXT( D.Run.PostDisconnect, PostDisconnect_LE); +} diff --git a/noncore/settings/networksettings2/ppp/PPPRunedit.h b/noncore/settings/networksettings2/ppp/PPPRunedit.h new file mode 100644 index 0000000..4205512 --- a/dev/null +++ b/noncore/settings/networksettings2/ppp/PPPRunedit.h @@ -0,0 +1,16 @@ +#include "pppdata.h" +#include "PPPRunGUI.h" + +class PPPRunEdit : public PPPRunGUI { + +public : + + PPPRunEdit( QWidget * parent ); + + QString acceptable( void ); + bool commit( PPPData & Data ); + void showData( PPPData & Data ); + +private : + +}; -- cgit v0.9.0.2