summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/usb
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings2/usb') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/usb/config.in4
-rw-r--r--noncore/settings/networksettings2/usb/usb.pro18
-rw-r--r--noncore/settings/networksettings2/usb/usbGUI.ui57
-rw-r--r--noncore/settings/networksettings2/usb/usb_NN.cpp60
-rw-r--r--noncore/settings/networksettings2/usb/usb_NN.h44
-rw-r--r--noncore/settings/networksettings2/usb/usb_NNI.cpp46
-rw-r--r--noncore/settings/networksettings2/usb/usb_NNI.h44
-rw-r--r--noncore/settings/networksettings2/usb/usbdata.h8
-rw-r--r--noncore/settings/networksettings2/usb/usbedit.cpp17
-rw-r--r--noncore/settings/networksettings2/usb/usbedit.h12
-rw-r--r--noncore/settings/networksettings2/usb/usbrun.cpp171
-rw-r--r--noncore/settings/networksettings2/usb/usbrun.h38
12 files changed, 519 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/usb/config.in b/noncore/settings/networksettings2/usb/config.in
new file mode 100644
index 0000000..988601a
--- a/dev/null
+++ b/noncore/settings/networksettings2/usb/config.in
@@ -0,0 +1,4 @@
+ config NS2USB
+ boolean "opie-networksettings2plugin-usb (set up USB)"
+ default "n" if NS2
+ depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE && NS2 && NS2CORE
diff --git a/noncore/settings/networksettings2/usb/usb.pro b/noncore/settings/networksettings2/usb/usb.pro
new file mode 100644
index 0000000..cc2f9db
--- a/dev/null
+++ b/noncore/settings/networksettings2/usb/usb.pro
@@ -0,0 +1,18 @@
+TEMPLATE = lib
+CONFIG += qt warn_on release
+DESTDIR = $(OPIEDIR)/plugins/networksettings2
+HEADERS = usb_NN.h \
+ usb_NNI.h \
+ usbedit.h
+SOURCES = usb_NN.cpp \
+ usb_NNI.cpp \
+ usbedit.cpp \
+ usbrun.cpp
+INCLUDEPATH += $(OPIEDIR)/include ../ ../networksettings2
+DEPENDPATH += $(OPIEDIR)/include ../ ../networksettings2
+LIBS += -lqpe
+INTERFACES = usbGUI.ui
+TARGET = usb
+VERSION = 1.0.0
+
+include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/settings/networksettings2/usb/usbGUI.ui b/noncore/settings/networksettings2/usb/usbGUI.ui
new file mode 100644
index 0000000..bd78ab4
--- a/dev/null
+++ b/noncore/settings/networksettings2/usb/usbGUI.ui
@@ -0,0 +1,57 @@
+<!DOCTYPE UI><UI>
+<class>USBGUI</class>
+<widget>
+ <class>QWidget</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>USB_FRM</cstring>
+ </property>
+ <property stdset="1">
+ <name>geometry</name>
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>279</width>
+ <height>199</height>
+ </rect>
+ </property>
+ <property stdset="1">
+ <name>caption</name>
+ <string>USB</string>
+ </property>
+ <property>
+ <name>layoutMargin</name>
+ </property>
+ <property>
+ <name>layoutSpacing</name>
+ </property>
+ <vbox>
+ <property stdset="1">
+ <name>margin</name>
+ <number>0</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>0</number>
+ </property>
+ <widget>
+ <class>QLabel</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>TextLabel3</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Nothing to configure</string>
+ </property>
+ <property stdset="1">
+ <name>alignment</name>
+ <set>AlignCenter</set>
+ </property>
+ <property>
+ <name>hAlign</name>
+ </property>
+ </widget>
+ </vbox>
+</widget>
+</UI>
diff --git a/noncore/settings/networksettings2/usb/usb_NN.cpp b/noncore/settings/networksettings2/usb/usb_NN.cpp
new file mode 100644
index 0000000..c65771d
--- a/dev/null
+++ b/noncore/settings/networksettings2/usb/usb_NN.cpp
@@ -0,0 +1,60 @@
+#include "usb_NN.h"
+#include "usb_NNI.h"
+
+static const char * USBNeeds[] =
+ { 0
+ };
+
+/**
+ * Constructor, find all of the possible interfaces
+ */
+USBNetNode::USBNetNode() : ANetNode() {
+}
+
+/**
+ * Delete any interfaces that we own.
+ */
+USBNetNode::~USBNetNode(){
+}
+
+const QString USBNetNode::nodeDescription(){
+ return tr("\
+<p>Configure Ethernet over USB.</p>\
+<p>Use this for a computer to computer USB cable connection</p>\
+"
+);
+}
+
+ANetNodeInstance * USBNetNode::createInstance( void ) {
+ return new AUSB( this );
+}
+
+const char ** USBNetNode::needs( void ) {
+ return USBNeeds;
+}
+
+const char * USBNetNode::provides( void ) {
+ return "device";
+}
+
+bool USBNetNode::generateProperFilesFor(
+ ANetNodeInstance * ) {
+ return 1;
+}
+
+bool USBNetNode::hasDataFor( const QString & S ) {
+ return (S== "interfaces");
+}
+
+bool USBNetNode::generateDataForCommonFile(
+ SystemFile & S ,
+ long DevNr,
+ ANetNodeInstance * NNI) {
+ return ((AUSB *)NNI)->generateDataForCommonFile(S, DevNr);
+}
+
+extern "C" {
+void create_plugin( QList<ANetNode> & PNN ) {
+ PNN.append( new USBNetNode() );
+}
+}
diff --git a/noncore/settings/networksettings2/usb/usb_NN.h b/noncore/settings/networksettings2/usb/usb_NN.h
new file mode 100644
index 0000000..3871afc
--- a/dev/null
+++ b/noncore/settings/networksettings2/usb/usb_NN.h
@@ -0,0 +1,44 @@
+#ifndef USB_NETNODE_H
+#define USB_NETNODE_H
+
+#include "netnode.h"
+
+class AUSB;
+
+class USBNetNode : public ANetNode{
+
+ Q_OBJECT
+
+public:
+
+ USBNetNode();
+ virtual ~USBNetNode();
+
+ virtual const QString pixmapName()
+ { return "usb"; }
+
+ virtual const QString nodeName()
+ { return tr("USB Cable Connect"); }
+
+ virtual const QString nodeDescription() ;
+
+ virtual ANetNodeInstance * createInstance( void );
+
+ virtual const char ** needs( void );
+ virtual const char * provides( void );
+
+ virtual bool generateProperFilesFor( ANetNodeInstance * NNI );
+ virtual bool hasDataFor( const QString & S );
+ virtual bool generateDataForCommonFile(
+ SystemFile & SF, long DevNr, ANetNodeInstance * NNI );
+
+private:
+
+};
+
+extern "C"
+{
+ void create_plugin( QList<ANetNode> & PNN );
+};
+
+#endif
diff --git a/noncore/settings/networksettings2/usb/usb_NNI.cpp b/noncore/settings/networksettings2/usb/usb_NNI.cpp
new file mode 100644
index 0000000..4729416
--- a/dev/null
+++ b/noncore/settings/networksettings2/usb/usb_NNI.cpp
@@ -0,0 +1,46 @@
+#include <qpe/qpeapplication.h>
+#include "usbedit.h"
+#include "usb_NNI.h"
+#include "usb_NN.h"
+
+AUSB::AUSB( USBNetNode * PNN ) : ANetNodeInstance( PNN ) {
+
+ GUI = 0;
+ RT = 0;
+}
+
+void AUSB::setSpecificAttribute( QString & , QString & ) {
+}
+
+void AUSB::saveSpecificAttribute( QTextStream & ) {
+}
+
+
+QWidget * AUSB::edit( QWidget * parent ) {
+ GUI = new USBEdit( parent );
+ GUI->showData( Data );
+ return GUI;
+}
+
+QString AUSB::acceptable( void ) {
+ return ( GUI ) ? GUI->acceptable( ) : QString();
+}
+
+void AUSB::commit( void ) {
+ if( GUI && GUI->commit( Data ) ) {
+ setModified( 1 );
+ }
+}
+
+bool AUSB::generateDataForCommonFile( SystemFile & S, long DevNr ) {
+ AsDevice * Dev = runtime()->device();
+ QString NIC = Dev->genNic( DevNr );
+
+ if( S.name() == "interfaces" ) {
+ // generate mapping stanza for this interface
+ S << " pre-up " << QPEApplication::qpeDir() << "bin/setmacaddress.sh " << NIC << " || true" << endl;
+ }
+ return 0;
+}
+
+
diff --git a/noncore/settings/networksettings2/usb/usb_NNI.h b/noncore/settings/networksettings2/usb/usb_NNI.h
new file mode 100644
index 0000000..b09f17a
--- a/dev/null
+++ b/noncore/settings/networksettings2/usb/usb_NNI.h
@@ -0,0 +1,44 @@
+#ifndef USB_H
+#define USB_H
+
+#include <netnode.h>
+#include "usbdata.h"
+#include "usbrun.h"
+
+class USBNetNode;
+class USBEdit;
+
+class AUSB : public ANetNodeInstance {
+
+public :
+
+ AUSB( USBNetNode * PNN );
+
+ QWidget * edit( QWidget * parent );
+ QString acceptable( void );
+ void commit( void );
+
+ RuntimeInfo * runtime( void )
+ { if( RT == 0 )
+ RT = new USBRun( this, Data );
+ return RT;
+ }
+
+ virtual void * data( void )
+ { return (void *)&Data; }
+
+ bool generateDataForCommonFile( SystemFile & S, long DevNr );
+
+protected :
+
+ virtual void setSpecificAttribute( QString & Attr, QString & Value );
+ virtual void saveSpecificAttribute( QTextStream & TS );
+
+private :
+
+ USBEdit * GUI;
+ USBData Data;
+ USBRun * RT;
+};
+
+#endif
diff --git a/noncore/settings/networksettings2/usb/usbdata.h b/noncore/settings/networksettings2/usb/usbdata.h
new file mode 100644
index 0000000..c59f508
--- a/dev/null
+++ b/noncore/settings/networksettings2/usb/usbdata.h
@@ -0,0 +1,8 @@
+#ifndef USB_DATA_H
+#define USB_DATA_H
+
+typedef struct USBData {
+ bool Fake;
+} USBData_t;
+
+#endif
diff --git a/noncore/settings/networksettings2/usb/usbedit.cpp b/noncore/settings/networksettings2/usb/usbedit.cpp
new file mode 100644
index 0000000..153c497
--- a/dev/null
+++ b/noncore/settings/networksettings2/usb/usbedit.cpp
@@ -0,0 +1,17 @@
+#include <GUIUtils.h>
+#include "usbedit.h"
+
+USBEdit::USBEdit( QWidget * Parent ) : USBGUI( Parent ){
+
+}
+
+QString USBEdit::acceptable( void ) {
+ return QString();
+}
+
+void USBEdit::showData( USBData_t & Data ) {
+}
+
+bool USBEdit::commit( USBData_t & Data ) {
+ return 1;
+}
diff --git a/noncore/settings/networksettings2/usb/usbedit.h b/noncore/settings/networksettings2/usb/usbedit.h
new file mode 100644
index 0000000..441f2f0
--- a/dev/null
+++ b/noncore/settings/networksettings2/usb/usbedit.h
@@ -0,0 +1,12 @@
+#include "usbdata.h"
+#include "usbGUI.h"
+
+class USBEdit : public USBGUI {
+
+public :
+
+ USBEdit( QWidget * parent );
+ QString acceptable( void );
+ bool commit( USBData_t & Data );
+ void showData( USBData_t & Data );
+};
diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp
new file mode 100644
index 0000000..49b5a77
--- a/dev/null
+++ b/noncore/settings/networksettings2/usb/usbrun.cpp
@@ -0,0 +1,171 @@
+#include <qfile.h>
+#include <qfileinfo.h>
+#include <qtextstream.h>
+#include <resources.h>
+#include "usbrun.h"
+
+void USBRun::detectState( NodeCollection * NC ) {
+ // unavailable : no card found
+ // available : card found and assigned to us or free
+ // up : card found and assigned to us and up
+ QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number());
+ System & Sys = NSResources->system();
+ InterfaceInfo * Run;
+ QFile F( S );
+
+ if( F.open( IO_ReadOnly ) ) {
+ // could open file -> read interface and assign
+ QString X;
+ QTextStream TS(&F);
+ X = TS.readLine();
+ // find interface
+ if( handlesInterface( X ) ) {
+ for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
+ It.current();
+ ++It ) {
+ Run = It.current();
+ if( X == Run->Name ) {
+ Run->assignNode( netNode() );
+ assignInterface( Run );
+ NC->setCurrentState( IsUp );
+ return;
+ }
+ }
+ }
+ }
+
+ fprintf( stderr, "NUP\n" );
+ // definitively not up
+ assignInterface( 0 );
+
+ // find possible interface
+ for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
+ It.current();
+ ++It ) {
+ Run = It.current();
+ fprintf( stderr, "%s %d %d=%d %d\n",
+ Run->Name.latin1(),
+ handlesInterface( Run->Name ),
+ Run->CardType, ARPHRD_ETHER,
+ ! Run->IsUp );
+ if( handlesInterface( Run->Name ) &&
+ Run->CardType == ARPHRD_ETHER &&
+ ! Run->IsUp
+ ) {
+ fprintf( stderr, "OFF\n" );
+ // proper type, and Not UP -> free
+ NC->setCurrentState( Off );
+ return;
+ }
+ }
+ // no free found
+ fprintf( stderr, "UNA\n" );
+
+ NC->setCurrentState( Unavailable );
+}
+
+bool USBRun::setState( NodeCollection * NC, Action_t A ) {
+
+ // we only handle activate and deactivate
+ switch( A ) {
+ case Activate :
+ {
+ if( NC->currentState() != Off ) {
+ return 0;
+ }
+ InterfaceInfo * N = getInterface();
+ if( ! N ) {
+ // no interface available
+ NC->setCurrentState( Unavailable );
+ return 0;
+ }
+ // because we were OFF the interface
+ // we get back is NOT assigned
+ N->assignNode( netNode() );
+ assignInterface( N );
+ NC->setCurrentState( Available );
+ return 1;
+ }
+ case Deactivate :
+ if( NC->currentState() == IsUp ) {
+ // bring down first
+ if( ! connection()->setState( Down ) )
+ // could not ...
+ return 0;
+ }
+ if( NC->currentState() != Available ) {
+ return 1;
+ }
+ assignedInterface()->assignNode( 0 ); // release
+ assignInterface( 0 );
+ NC->setCurrentState( Off );
+ return 1;
+ default :
+ // FT
+ break;
+ }
+ return 0;
+}
+
+bool USBRun::canSetState( State_t Curr, Action_t A ) {
+ // we only handle up down activate and deactivate
+ switch( A ) {
+ case Activate :
+ { // at least available
+ if( Curr == Available ) {
+ return 1;
+ }
+ // or we can make one available
+ InterfaceInfo * N = getInterface();
+ if( ! N || N->assignedNode() != 0 ) {
+ // non available or assigned
+ return 0;
+ }
+ return 1;
+ }
+ case Deactivate :
+ return ( Curr >= Available );
+ default :
+ // FT
+ break;
+ }
+ return 0;
+}
+
+// get interface that is free or assigned to us
+InterfaceInfo * USBRun::getInterface( void ) {
+
+ System & S = NSResources->system();
+ InterfaceInfo * best = 0, * Run;
+ QRegExp R( "usb[0-9abcdef]" );
+
+ for( QDictIterator<InterfaceInfo> It(S.interfaces());
+ It.current();
+ ++It ) {
+ Run = It.current();
+ if( handlesInterface( Run->Name ) &&
+ Run->CardType == ARPHRD_ETHER
+ ) {
+ // this is a USB card
+ if( Run->assignedNode() == netNode() ) {
+ // assigned to us
+ return Run;
+ } else if( Run->assignedNode() == 0 ) {
+ // free
+ best = Run;
+ }
+ }
+ }
+ return best; // can be 0
+}
+
+bool USBRun::handlesInterface( const QString & S ) {
+ return Pat.match( S ) >= 0;
+}
+
+QString USBRun::genNic( long nr ) {
+ QString S;
+ S.sprintf( "usbf" );
+ return S;
+}
+
diff --git a/noncore/settings/networksettings2/usb/usbrun.h b/noncore/settings/networksettings2/usb/usbrun.h
new file mode 100644
index 0000000..c9c9121
--- a/dev/null
+++ b/noncore/settings/networksettings2/usb/usbrun.h
@@ -0,0 +1,38 @@
+#ifndef USBRUN_H
+#define USBRUN_H
+
+#include <asdevice.h>
+#include <qregexp.h>
+#include "usbdata.h"
+
+class USBRun : public AsDevice {
+
+public :
+
+ USBRun( ANetNodeInstance * NNI,
+ USBData & Data ) :
+ AsDevice( NNI ),
+ Pat( "usb[0-9abcdef]" )
+ { }
+
+ virtual long count( void )
+ { return 1; }
+ virtual QString genNic( long nr );
+ virtual AsDevice * device( void )
+ { return asDevice(); }
+
+protected :
+
+ void detectState( NodeCollection * );
+ bool setState( NodeCollection * , Action_t A );
+ bool canSetState( State_t , Action_t A );
+
+ bool handlesInterface( const QString & I );
+
+private :
+
+ InterfaceInfo * getInterface( void );
+ QRegExp Pat;
+
+};
+#endif