summaryrefslogtreecommitdiff
path: root/examples
authormickeyl <mickeyl>2005-05-17 16:57:08 (UTC)
committer mickeyl <mickeyl>2005-05-17 16:57:08 (UTC)
commitd2ae68c413873e234b34f733818427902e738948 (patch) (unidiff)
treef5748014d7b1785302c167c6f43fbd0622bf1019 /examples
parentcce15d6b9a27880df72ea2638f9295900ea6c21e (diff)
downloadopie-d2ae68c413873e234b34f733818427902e738948.zip
opie-d2ae68c413873e234b34f733818427902e738948.tar.gz
opie-d2ae68c413873e234b34f733818427902e738948.tar.bz2
libopienet API cleanups
Diffstat (limited to 'examples') (more/less context) (ignore whitespace changes)
-rw-r--r--examples/opienet/miniwellenreiter/miniwellenreiter.cpp2
-rw-r--r--examples/opienet/onetworkdemo/onetworkdemo.cpp2
2 files changed, 2 insertions, 2 deletions
diff --git a/examples/opienet/miniwellenreiter/miniwellenreiter.cpp b/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
index ebd3b5f..ba9d2ca 100644
--- a/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
+++ b/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
@@ -1,118 +1,118 @@
1#include <qdict.h> 1#include <qdict.h>
2#include <qsocketnotifier.h> 2#include <qsocketnotifier.h>
3#include <qstring.h> 3#include <qstring.h>
4#include <opie2/onetwork.h> 4#include <opie2/onetwork.h>
5#include <qapplication.h> 5#include <qapplication.h>
6#include <opie2/opcap.h> 6#include <opie2/opcap.h>
7#include <cerrno> 7#include <cerrno>
8#include <cstdio> 8#include <cstdio>
9#include <cstdlib> 9#include <cstdlib>
10#include <cstring> 10#include <cstring>
11 11
12 12
13using namespace Opie::Net; 13using namespace Opie::Net;
14//======================== Station help class =============================== 14//======================== Station help class ===============================
15 15
16class Station 16class Station
17{ 17{
18 public: 18 public:
19 Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {}; 19 Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {};
20 ~Station() {}; 20 ~Station() {};
21 21
22 QString type; 22 QString type;
23 int channel; 23 int channel;
24 bool wep; 24 bool wep;
25 int beacons; 25 int beacons;
26}; 26};
27 27
28QDict<Station> stations; 28QDict<Station> stations;
29 29
30//======================== Application class =============================== 30//======================== Application class ===============================
31 31
32class Wellenreiter : public QApplication 32class Wellenreiter : public QApplication
33{ 33{
34Q_OBJECT 34Q_OBJECT
35public: 35public:
36 Wellenreiter( int argc, char** argv ) : QApplication( argc, argv ), channel( 1 ) 36 Wellenreiter( int argc, char** argv ) : QApplication( argc, argv ), channel( 1 )
37 { 37 {
38 38
39 ONetwork* net = ONetwork::instance(); 39 ONetwork* net = ONetwork::instance();
40 40
41 if ( argc < 3 ) 41 if ( argc < 3 )
42 { 42 {
43 printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] ); 43 printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] );
44 printf( "\n" ); 44 printf( "\n" );
45 printf( "Valid wireless interfaces (detected) are:\n" ); 45 printf( "Valid wireless interfaces (detected) are:\n" );
46 46
47 ONetwork::InterfaceIterator it = net->iterator(); 47 ONetwork::InterfaceIterator it = net->iterator();
48 while ( it.current() ) 48 while ( it.current() )
49 { 49 {
50 if ( it.current()->isWireless() ) 50 if ( it.current()->isWireless() )
51 { 51 {
52 printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(), 52 printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(),
53 (const char*) it.current()->macAddress().toString(), 53 (const char*) it.current()->macAddress().toString(),
54 (const char*) it.current()->ipV4Address() ); 54 (const char*) it.current()->ipV4Address().toString() );
55 } 55 }
56 ++it; 56 ++it;
57 } 57 }
58 exit( -1 ); 58 exit( -1 );
59 } 59 }
60 60
61 printf( "*******************************************************************\n" ); 61 printf( "*******************************************************************\n" );
62 printf( "* Wellenreiter mini edition 1.0.0 (C) 2003 Michael 'Mickey' Lauer *\n" ); 62 printf( "* Wellenreiter mini edition 1.0.0 (C) 2003 Michael 'Mickey' Lauer *\n" );
63 printf( "*******************************************************************\n" ); 63 printf( "*******************************************************************\n" );
64 printf( "\n\n" ); 64 printf( "\n\n" );
65 65
66 QString interface( argv[1] ); 66 QString interface( argv[1] );
67 QString driver( argv[2] ); 67 QString driver( argv[2] );
68 68
69 printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver ); 69 printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver );
70 70
71 // sanity checks before downcasting 71 // sanity checks before downcasting
72 ONetworkInterface* iface = net->interface( interface ); 72 ONetworkInterface* iface = net->interface( interface );
73 if ( !iface ) 73 if ( !iface )
74 { 74 {
75 printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface ); 75 printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface );
76 exit( -1 ); 76 exit( -1 );
77 } 77 }
78 if ( !iface->isWireless() ) 78 if ( !iface->isWireless() )
79 { 79 {
80 printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface ); 80 printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface );
81 exit( -1 ); 81 exit( -1 );
82 } 82 }
83 83
84 // downcast should be safe now 84 // downcast should be safe now
85 wiface = (OWirelessNetworkInterface*) iface; 85 wiface = (OWirelessNetworkInterface*) iface;
86 printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() ); 86 printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() );
87 87
88 // ifconfig +promisc the interface to receive all packets 88 // ifconfig +promisc the interface to receive all packets
89 if ( !wiface->promiscuousMode() ) 89 if ( !wiface->promiscuousMode() )
90 { 90 {
91 printf( "Interface status is not promisc... switching to promisc... " ); 91 printf( "Interface status is not promisc... switching to promisc... " );
92 wiface->setPromiscuousMode( true ); 92 wiface->setPromiscuousMode( true );
93 if ( !wiface->promiscuousMode() ) 93 if ( !wiface->promiscuousMode() )
94 { 94 {
95 printf( "failed (%s). Exiting.\n", strerror( errno ) ); 95 printf( "failed (%s). Exiting.\n", strerror( errno ) );
96 exit( -1 ); 96 exit( -1 );
97 } 97 }
98 else 98 else
99 { 99 {
100 printf( "ok.\n" ); 100 printf( "ok.\n" );
101 } 101 }
102 } 102 }
103 else 103 else
104 printf( "Interface status is already promisc - good.\n" ); 104 printf( "Interface status is already promisc - good.\n" );
105 105
106 // connect a monitoring strategy to the interface 106 // connect a monitoring strategy to the interface
107 if ( driver == "orinoco" ) 107 if ( driver == "orinoco" )
108 new OOrinocoMonitoringInterface( wiface, false ); 108 new OOrinocoMonitoringInterface( wiface, false );
109 else 109 else
110 if ( driver == "hostap" ) 110 if ( driver == "hostap" )
111 new OHostAPMonitoringInterface( wiface, false ); 111 new OHostAPMonitoringInterface( wiface, false );
112 else 112 else
113 if ( driver == "wlan-ng" ) 113 if ( driver == "wlan-ng" )
114 new OWlanNGMonitoringInterface( wiface, false ); 114 new OWlanNGMonitoringInterface( wiface, false );
115 else 115 else
116 { 116 {
117 printf( "Unknown driver. Exiting\n" ); 117 printf( "Unknown driver. Exiting\n" );
118 exit( -1 ); 118 exit( -1 );
diff --git a/examples/opienet/onetworkdemo/onetworkdemo.cpp b/examples/opienet/onetworkdemo/onetworkdemo.cpp
index b3a1115..e8958dc 100644
--- a/examples/opienet/onetworkdemo/onetworkdemo.cpp
+++ b/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -1,126 +1,126 @@
1/* 1/*
2 =. This file is part of the Opie Project 2 =. This file is part of the Opie Project
3 .=l. Copyright (C) 2004 Opie Team <opie-devel@handhelds.org> 3 .=l. Copyright (C) 2004 Opie Team <opie-devel@handhelds.org>
4 .>+-= 4 .>+-=
5 _;:, .> :=|. This library is free software; you can 5 _;:, .> :=|. This library is free software; you can
6.> <`_, > . <= redistribute it and/or modify it under 6.> <`_, > . <= redistribute it and/or modify it under
7:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 7:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
8.="- .-=="i, .._ License as published by the Free Software 8.="- .-=="i, .._ License as published by the Free Software
9 - . .-<_> .<> Foundation; either version 2 of the License, 9 - . .-<_> .<> Foundation; either version 2 of the License,
10 ._= =} : or (at your option) any later version. 10 ._= =} : or (at your option) any later version.
11 .%`+i> _;_. 11 .%`+i> _;_.
12 .i_,=:_. -<s. This library is distributed in the hope that 12 .i_,=:_. -<s. This library is distributed in the hope that
13 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 13 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
14 : .. .:, . . . without even the implied warranty of 14 : .. .:, . . . without even the implied warranty of
15 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 15 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
16 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 16 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.= = ; Library General Public License for more 17..}^=.= = ; Library General Public License for more
18++= -. .` .: details. 18++= -. .` .: details.
19 : = ...= . :.=- 19 : = ...= . :.=-
20 -. .:....=;==+<; You should have received a copy of the GNU 20 -. .:....=;==+<; You should have received a copy of the GNU
21 -_. . . )=. = Library General Public License along with 21 -_. . . )=. = Library General Public License along with
22 -- :-=` this library; see the file COPYING.LIB. 22 -- :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29/* OPIE */ 29/* OPIE */
30#include <opie2/onetwork.h> 30#include <opie2/onetwork.h>
31#include <opie2/ostation.h> 31#include <opie2/ostation.h>
32#include <opie2/omanufacturerdb.h> 32#include <opie2/omanufacturerdb.h>
33#include <opie2/odebug.h> 33#include <opie2/odebug.h>
34 34
35/* STD */ 35/* STD */
36#include <unistd.h> 36#include <unistd.h>
37 37
38using namespace Opie::Net; 38using namespace Opie::Net;
39 39
40int main( int argc, char** argv ) 40int main( int argc, char** argv )
41{ 41{
42 odebug << "OPIE Network Demo" << oendl; 42 odebug << "OPIE Network Demo" << oendl;
43 43
44 ONetwork* net = ONetwork::instance(); 44 ONetwork* net = ONetwork::instance();
45 45
46 ONetwork::InterfaceIterator it = net->iterator(); 46 ONetwork::InterfaceIterator it = net->iterator();
47 47
48 while ( it.current() ) 48 while ( it.current() )
49 { 49 {
50 odebug << "DEMO: ONetwork contains Interface '" << it.current()->name() << "'" << oendl; 50 odebug << "DEMO: ONetwork contains Interface '" << it.current()->name() << "'" << oendl;
51 ONetworkInterfaceDriverInfo info = it.current()->driverInfo(); 51 ONetworkInterfaceDriverInfo info = it.current()->driverInfo();
52 odebug << "DEMO: DriverName reported as '" << info.name() << "'" << oendl; 52 odebug << "DEMO: DriverName reported as '" << info.name() << "'" << oendl;
53 odebug << "DEMO: DriverVersion reported as '" << info.version() << "'" << oendl; 53 odebug << "DEMO: DriverVersion reported as '" << info.version() << "'" << oendl;
54 odebug << "DEMO: DriverFirmware reported as '" << info.firmware() << "'" << oendl; 54 odebug << "DEMO: DriverFirmware reported as '" << info.firmware() << "'" << oendl;
55 odebug << "DEMO: DriverBus reported as '" << info.bus() << "'" << oendl; 55 odebug << "DEMO: DriverBus reported as '" << info.bus() << "'" << oendl;
56 odebug << "DEMO: Datalink code is '" << it.current()->dataLinkType() << "'" << oendl; 56 odebug << "DEMO: Datalink code is '" << it.current()->dataLinkType() << "'" << oendl;
57 odebug << "DEMO: MAC Address is '" << it.current()->macAddress().toString() << "'" << oendl; 57 odebug << "DEMO: MAC Address is '" << it.current()->macAddress().toString() << "'" << oendl;
58 odebug << "DEMO: MAC Address is '" << it.current()->macAddress().toString(true) << "'" << oendl; 58 odebug << "DEMO: MAC Address is '" << it.current()->macAddress().toString(true) << "'" << oendl;
59 odebug << "DEMO: MAC Manufacturer seems to be '" << it.current()->macAddress().manufacturer() << "'" << oendl; 59 odebug << "DEMO: MAC Manufacturer seems to be '" << it.current()->macAddress().manufacturer() << "'" << oendl;
60 odebug << "DEMO: Manufacturertest1 = '" << OManufacturerDB::instance()->lookupExt( "08:00:87" ) << "'" << oendl; 60 odebug << "DEMO: Manufacturertest1 = '" << OManufacturerDB::instance()->lookupExt( "08:00:87" ) << "'" << oendl;
61 odebug << "DEMO: Manufacturertest2 = '" << OManufacturerDB::instance()->lookupExt( "E2:0C:0F" ) << "'" << oendl; 61 odebug << "DEMO: Manufacturertest2 = '" << OManufacturerDB::instance()->lookupExt( "E2:0C:0F" ) << "'" << oendl;
62 odebug << "Demo: IPv4 Address is '" << it.current()->ipV4Address() << "'" << oendl; 62 odebug << "Demo: IPv4 Address is '" << it.current()->ipV4Address().toString() << "'" << oendl;
63 if ( it.current()->isWireless() ) 63 if ( it.current()->isWireless() )
64 { 64 {
65 OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() ); 65 OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() );
66 odebug << "DEMO: '" << iface->name() << "' seems to feature the wireless extensions." << oendl; 66 odebug << "DEMO: '" << iface->name() << "' seems to feature the wireless extensions." << oendl;
67 odebug << "DEMO: Current SSID is '" << iface->SSID() << "'" << oendl; 67 odebug << "DEMO: Current SSID is '" << iface->SSID() << "'" << oendl;
68 odebug << "DEMO: Antenna is tuned to '" << iface->frequency() << "', that is channel " << iface->channel() << "" << oendl; 68 odebug << "DEMO: Antenna is tuned to '" << iface->frequency() << "', that is channel " << iface->channel() << "" << oendl;
69 69
70 //if ( iface->mode() == OWirelessNetworkInterface::adhoc ) 70 //if ( iface->mode() == OWirelessNetworkInterface::adhoc )
71 //{ 71 //{
72 //odebug << "DEMO: Associated AP has MAC Address '" << iface->associatedAP().toString() << "'" << oendl; 72 //odebug << "DEMO: Associated AP has MAC Address '" << iface->associatedAP().toString() << "'" << oendl;
73 //} 73 //}
74 74
75 /* 75 /*
76 76
77 // nickname 77 // nickname
78 odebug << "DEMO: Current NickName is '" << iface->nickName() << "'" << oendl; 78 odebug << "DEMO: Current NickName is '" << iface->nickName() << "'" << oendl;
79 iface->setNickName( "MyNickName" ); 79 iface->setNickName( "MyNickName" );
80 if ( iface->nickName() != "MyNickName" ) 80 if ( iface->nickName() != "MyNickName" )
81 odebug << "DEMO: Warning! Can't change nickname" << oendl; 81 odebug << "DEMO: Warning! Can't change nickname" << oendl;
82 else 82 else
83 odebug << "DEMO: Nickname change successful." << oendl; 83 odebug << "DEMO: Nickname change successful." << oendl;
84 84
85 /* 85 /*
86 86
87 // operation mode 87 // operation mode
88 odebug << "DEMO: Current OperationMode is '" << iface->mode() << "'" << oendl; 88 odebug << "DEMO: Current OperationMode is '" << iface->mode() << "'" << oendl;
89 iface->setMode( "adhoc" ); 89 iface->setMode( "adhoc" );
90 if ( iface->mode() != "adhoc" ) 90 if ( iface->mode() != "adhoc" )
91 odebug << "DEMO: Warning! Can't change operation mode" << oendl; 91 odebug << "DEMO: Warning! Can't change operation mode" << oendl;
92 else 92 else
93 odebug << "DEMO: Operation Mode change successful." << oendl; 93 odebug << "DEMO: Operation Mode change successful." << oendl;
94 94
95 // RF channel 95 // RF channel
96 odebug << "DEMO: Current Channel is '" << iface->channel() << "'" << oendl; 96 odebug << "DEMO: Current Channel is '" << iface->channel() << "'" << oendl;
97 iface->setChannel( 1 ); 97 iface->setChannel( 1 );
98 if ( iface->channel() != 1 ) 98 if ( iface->channel() != 1 )
99 odebug << "DEMO: Warning! Can't change RF channel" << oendl; 99 odebug << "DEMO: Warning! Can't change RF channel" << oendl;
100 else 100 else
101 odebug << "DEMO: RF channel change successful." << oendl; 101 odebug << "DEMO: RF channel change successful." << oendl;
102 102
103 iface->setMode( "managed" ); 103 iface->setMode( "managed" );
104 104
105 */ 105 */
106 106
107 /* 107 /*
108 108
109 // network scan 109 // network scan
110 110
111 OStationList* stations = iface->scanNetwork(); 111 OStationList* stations = iface->scanNetwork();
112 if ( stations ) 112 if ( stations )
113 { 113 {
114 odebug << "DEMO: # of stations around = " << stations->count() << "" << oendl; 114 odebug << "DEMO: # of stations around = " << stations->count() << "" << oendl;
115 OStation* station; 115 OStation* station;
116 for ( station = stations->first(); station != 0; station = stations->next() ) 116 for ( station = stations->first(); station != 0; station = stations->next() )
117 { 117 {
118 odebug << "DEMO: station dump following..." << oendl; 118 odebug << "DEMO: station dump following..." << oendl;
119 station->dump(); 119 station->dump();
120 } 120 }
121 } 121 }
122 122
123 else 123 else
124 { 124 {
125 odebug << "DEMO: Warning! Scan didn't work!" << oendl; 125 odebug << "DEMO: Warning! Scan didn't work!" << oendl;
126 } 126 }