summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/usb
Unidiff
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 @@
1 config NS2USB
2 boolean "opie-networksettings2plugin-usb (set up USB)"
3 default "n" if NS2
4 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 @@
1TEMPLATE = lib
2CONFIG += qt warn_on release
3DESTDIR = $(OPIEDIR)/plugins/networksettings2
4 HEADERS = usb_NN.h \
5 usb_NNI.h \
6 usbedit.h
7 SOURCES = usb_NN.cpp \
8 usb_NNI.cpp \
9 usbedit.cpp \
10 usbrun.cpp
11 INCLUDEPATH+= $(OPIEDIR)/include ../ ../networksettings2
12 DEPENDPATH+= $(OPIEDIR)/include ../ ../networksettings2
13LIBS += -lqpe
14 INTERFACES= usbGUI.ui
15 TARGET = usb
16 VERSION = 1.0.0
17
18include ( $(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 @@
1<!DOCTYPE UI><UI>
2<class>USBGUI</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>USB_FRM</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>279</width>
15 <height>199</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>USB</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <vbox>
29 <property stdset="1">
30 <name>margin</name>
31 <number>0</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>0</number>
36 </property>
37 <widget>
38 <class>QLabel</class>
39 <property stdset="1">
40 <name>name</name>
41 <cstring>TextLabel3</cstring>
42 </property>
43 <property stdset="1">
44 <name>text</name>
45 <string>Nothing to configure</string>
46 </property>
47 <property stdset="1">
48 <name>alignment</name>
49 <set>AlignCenter</set>
50 </property>
51 <property>
52 <name>hAlign</name>
53 </property>
54 </widget>
55 </vbox>
56</widget>
57</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 @@
1#include "usb_NN.h"
2#include "usb_NNI.h"
3
4static const char * USBNeeds[] =
5 { 0
6 };
7
8/**
9 * Constructor, find all of the possible interfaces
10 */
11USBNetNode::USBNetNode() : ANetNode() {
12}
13
14/**
15 * Delete any interfaces that we own.
16 */
17USBNetNode::~USBNetNode(){
18}
19
20const QString USBNetNode::nodeDescription(){
21 return tr("\
22<p>Configure Ethernet over USB.</p>\
23<p>Use this for a computer to computer USB cable connection</p>\
24"
25);
26}
27
28ANetNodeInstance * USBNetNode::createInstance( void ) {
29 return new AUSB( this );
30}
31
32const char ** USBNetNode::needs( void ) {
33 return USBNeeds;
34}
35
36const char * USBNetNode::provides( void ) {
37 return "device";
38}
39
40bool USBNetNode::generateProperFilesFor(
41 ANetNodeInstance * ) {
42 return 1;
43}
44
45bool USBNetNode::hasDataFor( const QString & S ) {
46 return (S== "interfaces");
47}
48
49bool USBNetNode::generateDataForCommonFile(
50 SystemFile & S ,
51 long DevNr,
52 ANetNodeInstance * NNI) {
53 return ((AUSB *)NNI)->generateDataForCommonFile(S, DevNr);
54}
55
56extern "C" {
57void create_plugin( QList<ANetNode> & PNN ) {
58 PNN.append( new USBNetNode() );
59}
60}
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 @@
1#ifndef USB_NETNODE_H
2#define USB_NETNODE_H
3
4#include "netnode.h"
5
6class AUSB;
7
8class USBNetNode : public ANetNode{
9
10 Q_OBJECT
11
12public:
13
14 USBNetNode();
15 virtual ~USBNetNode();
16
17 virtual const QString pixmapName()
18 { return "usb"; }
19
20 virtual const QString nodeName()
21 { return tr("USB Cable Connect"); }
22
23 virtual const QString nodeDescription() ;
24
25 virtual ANetNodeInstance * createInstance( void );
26
27 virtual const char ** needs( void );
28 virtual const char * provides( void );
29
30 virtual bool generateProperFilesFor( ANetNodeInstance * NNI );
31 virtual bool hasDataFor( const QString & S );
32 virtual bool generateDataForCommonFile(
33 SystemFile & SF, long DevNr, ANetNodeInstance * NNI );
34
35private:
36
37};
38
39extern "C"
40{
41 void create_plugin( QList<ANetNode> & PNN );
42};
43
44#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 @@
1#include <qpe/qpeapplication.h>
2#include "usbedit.h"
3#include "usb_NNI.h"
4#include "usb_NN.h"
5
6AUSB::AUSB( USBNetNode * PNN ) : ANetNodeInstance( PNN ) {
7
8 GUI = 0;
9 RT = 0;
10}
11
12void AUSB::setSpecificAttribute( QString & , QString & ) {
13}
14
15void AUSB::saveSpecificAttribute( QTextStream & ) {
16}
17
18
19QWidget * AUSB::edit( QWidget * parent ) {
20 GUI = new USBEdit( parent );
21 GUI->showData( Data );
22 return GUI;
23}
24
25QString AUSB::acceptable( void ) {
26 return ( GUI ) ? GUI->acceptable( ) : QString();
27}
28
29void AUSB::commit( void ) {
30 if( GUI && GUI->commit( Data ) ) {
31 setModified( 1 );
32 }
33}
34
35bool AUSB::generateDataForCommonFile( SystemFile & S, long DevNr ) {
36 AsDevice * Dev = runtime()->device();
37 QString NIC = Dev->genNic( DevNr );
38
39 if( S.name() == "interfaces" ) {
40 // generate mapping stanza for this interface
41 S << " pre-up " << QPEApplication::qpeDir() << "bin/setmacaddress.sh " << NIC << " || true" << endl;
42 }
43 return 0;
44}
45
46
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 @@
1#ifndef USB_H
2#define USB_H
3
4#include <netnode.h>
5#include "usbdata.h"
6#include "usbrun.h"
7
8class USBNetNode;
9class USBEdit;
10
11class AUSB : public ANetNodeInstance {
12
13public :
14
15 AUSB( USBNetNode * PNN );
16
17 QWidget * edit( QWidget * parent );
18 QString acceptable( void );
19 void commit( void );
20
21 RuntimeInfo * runtime( void )
22 { if( RT == 0 )
23 RT = new USBRun( this, Data );
24 return RT;
25 }
26
27 virtual void * data( void )
28 { return (void *)&Data; }
29
30 bool generateDataForCommonFile( SystemFile & S, long DevNr );
31
32protected :
33
34 virtual void setSpecificAttribute( QString & Attr, QString & Value );
35 virtual void saveSpecificAttribute( QTextStream & TS );
36
37private :
38
39 USBEdit * GUI;
40 USBData Data;
41 USBRun * RT;
42};
43
44#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 @@
1#ifndef USB_DATA_H
2#define USB_DATA_H
3
4typedef struct USBData {
5 bool Fake;
6} USBData_t;
7
8#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 @@
1#include <GUIUtils.h>
2#include "usbedit.h"
3
4USBEdit::USBEdit( QWidget * Parent ) : USBGUI( Parent ){
5
6}
7
8QString USBEdit::acceptable( void ) {
9 return QString();
10}
11
12void USBEdit::showData( USBData_t & Data ) {
13}
14
15bool USBEdit::commit( USBData_t & Data ) {
16 return 1;
17}
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 @@
1#include "usbdata.h"
2#include "usbGUI.h"
3
4class USBEdit : public USBGUI {
5
6public :
7
8 USBEdit( QWidget * parent );
9 QString acceptable( void );
10 bool commit( USBData_t & Data );
11 void showData( USBData_t & Data );
12};
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 @@
1#include <qfile.h>
2#include <qfileinfo.h>
3#include <qtextstream.h>
4#include <resources.h>
5#include "usbrun.h"
6
7void USBRun::detectState( NodeCollection * NC ) {
8 // unavailable : no card found
9 // available : card found and assigned to us or free
10 // up : card found and assigned to us and up
11 QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number());
12 System & Sys = NSResources->system();
13 InterfaceInfo * Run;
14 QFile F( S );
15
16 if( F.open( IO_ReadOnly ) ) {
17 // could open file -> read interface and assign
18 QString X;
19 QTextStream TS(&F);
20 X = TS.readLine();
21 // find interface
22 if( handlesInterface( X ) ) {
23 for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
24 It.current();
25 ++It ) {
26 Run = It.current();
27 if( X == Run->Name ) {
28 Run->assignNode( netNode() );
29 assignInterface( Run );
30 NC->setCurrentState( IsUp );
31 return;
32 }
33 }
34 }
35 }
36
37 fprintf( stderr, "NUP\n" );
38 // definitively not up
39 assignInterface( 0 );
40
41 // find possible interface
42 for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
43 It.current();
44 ++It ) {
45 Run = It.current();
46 fprintf( stderr, "%s %d %d=%d %d\n",
47 Run->Name.latin1(),
48 handlesInterface( Run->Name ),
49 Run->CardType, ARPHRD_ETHER,
50 ! Run->IsUp );
51 if( handlesInterface( Run->Name ) &&
52 Run->CardType == ARPHRD_ETHER &&
53 ! Run->IsUp
54 ) {
55 fprintf( stderr, "OFF\n" );
56 // proper type, and Not UP -> free
57 NC->setCurrentState( Off );
58 return;
59 }
60 }
61 // no free found
62 fprintf( stderr, "UNA\n" );
63
64 NC->setCurrentState( Unavailable );
65}
66
67bool USBRun::setState( NodeCollection * NC, Action_t A ) {
68
69 // we only handle activate and deactivate
70 switch( A ) {
71 case Activate :
72 {
73 if( NC->currentState() != Off ) {
74 return 0;
75 }
76 InterfaceInfo * N = getInterface();
77 if( ! N ) {
78 // no interface available
79 NC->setCurrentState( Unavailable );
80 return 0;
81 }
82 // because we were OFF the interface
83 // we get back is NOT assigned
84 N->assignNode( netNode() );
85 assignInterface( N );
86 NC->setCurrentState( Available );
87 return 1;
88 }
89 case Deactivate :
90 if( NC->currentState() == IsUp ) {
91 // bring down first
92 if( ! connection()->setState( Down ) )
93 // could not ...
94 return 0;
95 }
96 if( NC->currentState() != Available ) {
97 return 1;
98 }
99 assignedInterface()->assignNode( 0 ); // release
100 assignInterface( 0 );
101 NC->setCurrentState( Off );
102 return 1;
103 default :
104 // FT
105 break;
106 }
107 return 0;
108}
109
110bool USBRun::canSetState( State_t Curr, Action_t A ) {
111 // we only handle up down activate and deactivate
112 switch( A ) {
113 case Activate :
114 { // at least available
115 if( Curr == Available ) {
116 return 1;
117 }
118 // or we can make one available
119 InterfaceInfo * N = getInterface();
120 if( ! N || N->assignedNode() != 0 ) {
121 // non available or assigned
122 return 0;
123 }
124 return 1;
125 }
126 case Deactivate :
127 return ( Curr >= Available );
128 default :
129 // FT
130 break;
131 }
132 return 0;
133}
134
135// get interface that is free or assigned to us
136InterfaceInfo * USBRun::getInterface( void ) {
137
138 System & S = NSResources->system();
139 InterfaceInfo * best = 0, * Run;
140 QRegExp R( "usb[0-9abcdef]" );
141
142 for( QDictIterator<InterfaceInfo> It(S.interfaces());
143 It.current();
144 ++It ) {
145 Run = It.current();
146 if( handlesInterface( Run->Name ) &&
147 Run->CardType == ARPHRD_ETHER
148 ) {
149 // this is a USB card
150 if( Run->assignedNode() == netNode() ) {
151 // assigned to us
152 return Run;
153 } else if( Run->assignedNode() == 0 ) {
154 // free
155 best = Run;
156 }
157 }
158 }
159 return best; // can be 0
160}
161
162bool USBRun::handlesInterface( const QString & S ) {
163 return Pat.match( S ) >= 0;
164}
165
166QString USBRun::genNic( long nr ) {
167 QString S;
168 S.sprintf( "usbf" );
169 return S;
170}
171
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 @@
1#ifndef USBRUN_H
2#define USBRUN_H
3
4#include <asdevice.h>
5#include <qregexp.h>
6#include "usbdata.h"
7
8class USBRun : public AsDevice {
9
10public :
11
12 USBRun( ANetNodeInstance * NNI,
13 USBData & Data ) :
14 AsDevice( NNI ),
15 Pat( "usb[0-9abcdef]" )
16 { }
17
18 virtual long count( void )
19 { return 1; }
20 virtual QString genNic( long nr );
21 virtual AsDevice * device( void )
22 { return asDevice(); }
23
24protected :
25
26 void detectState( NodeCollection * );
27 bool setState( NodeCollection * , Action_t A );
28 bool canSetState( State_t , Action_t A );
29
30 bool handlesInterface( const QString & I );
31
32private :
33
34 InterfaceInfo * getInterface( void );
35 QRegExp Pat;
36
37};
38#endif