-rw-r--r-- | libopie2/opienet/onetwork.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index ab3e77f..26a6c81 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -1,168 +1,168 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer | 3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer |
4 | =. <mickey@Vanille.de> | 4 | =. <mickey@Vanille.de> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | /* OPIE */ | 31 | /* OPIE */ |
32 | 32 | ||
33 | #include <opie2/onetwork.h> | 33 | #include <opie2/onetwork.h> |
34 | #include <opie2/ostation.h> | 34 | #include <opie2/ostation.h> |
35 | #include <opie2/odebug.h> | 35 | #include <opie2/odebug.h> |
36 | 36 | ||
37 | /* QT */ | 37 | /* QT */ |
38 | 38 | ||
39 | #include <qfile.h> | 39 | #include <qfile.h> |
40 | #include <qtextstream.h> | 40 | #include <qtextstream.h> |
41 | 41 | ||
42 | /* UNIX */ | 42 | /* UNIX */ |
43 | 43 | ||
44 | #include <assert.h> | 44 | #include <assert.h> |
45 | #include <arpa/inet.h> | 45 | #include <arpa/inet.h> |
46 | #include <errno.h> | 46 | #include <errno.h> |
47 | #include <string.h> | 47 | #include <string.h> |
48 | #include <stdlib.h> | 48 | #include <stdlib.h> |
49 | #include <math.h> | 49 | #include <math.h> |
50 | #include <sys/ioctl.h> | 50 | #include <sys/ioctl.h> |
51 | #include <sys/socket.h> | 51 | #include <sys/socket.h> |
52 | #include <sys/types.h> | 52 | #include <sys/types.h> |
53 | #include <unistd.h> | 53 | #include <unistd.h> |
54 | #include <linux/sockios.h> | 54 | #include <linux/sockios.h> |
55 | #include <net/if_arp.h> | 55 | #include <net/if_arp.h> |
56 | #include <stdarg.h> | 56 | #include <stdarg.h> |
57 | 57 | ||
58 | #ifndef NODEBUG | 58 | #ifndef NODEBUG |
59 | #include <opie2/odebugmapper.h> | 59 | #include <opie2/odebugmapper.h> |
60 | 60 | ||
61 | 61 | ||
62 | using namespace Opie::Core; | 62 | using namespace Opie::Core; |
63 | using namespace Opie::Net::Private; | 63 | using namespace Opie::Net::Private; |
64 | DebugMapper* debugmapper = new DebugMapper(); | 64 | DebugMapper* debugmapper = new DebugMapper(); |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | /*====================================================================================== | 67 | /*====================================================================================== |
68 | * ONetwork | 68 | * ONetwork |
69 | *======================================================================================*/ | 69 | *======================================================================================*/ |
70 | 70 | ||
71 | namespace Opie { | 71 | namespace Opie { |
72 | namespace Net { | 72 | namespace Net { |
73 | ONetwork* ONetwork::_instance = 0; | 73 | ONetwork* ONetwork::_instance = 0; |
74 | 74 | ||
75 | ONetwork::ONetwork() | 75 | ONetwork::ONetwork() |
76 | { | 76 | { |
77 | odebug << "ONetwork::ONetwork()" << oendl; | 77 | odebug << "ONetwork::ONetwork()" << oendl; |
78 | odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; | 78 | odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; |
79 | synchronize(); | 79 | synchronize(); |
80 | } | 80 | } |
81 | 81 | ||
82 | void ONetwork::synchronize() | 82 | void ONetwork::synchronize() |
83 | { | 83 | { |
84 | // gather available interfaces by inspecting /proc/net/dev | 84 | // gather available interfaces by inspecting /proc/net/dev |
85 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 85 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
86 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | 86 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices |
87 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev | 87 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev |
88 | 88 | ||
89 | _interfaces.clear(); | 89 | _interfaces.clear(); |
90 | QString str; | 90 | QString str; |
91 | QFile f( "/proc/net/dev" ); | 91 | QFile f( "/proc/net/dev" ); |
92 | bool hasFile = f.open( IO_ReadOnly ); | 92 | bool hasFile = f.open( IO_ReadOnly ); |
93 | if ( !hasFile ) | 93 | if ( !hasFile ) |
94 | { | 94 | { |
95 | odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; | 95 | odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; |
96 | return; | 96 | return; |
97 | } | 97 | } |
98 | QTextStream s( &f ); | 98 | QTextStream s( &f ); |
99 | s.readLine(); | 99 | s.readLine(); |
100 | s.readLine(); | 100 | s.readLine(); |
101 | while ( !s.atEnd() ) | 101 | while ( !s.atEnd() ) |
102 | { | 102 | { |
103 | s >> str; | 103 | s >> str; |
104 | str.truncate( str.find( ':' ) ); | 104 | str.truncate( str.find( ':' ) ); |
105 | odebug << "ONetwork: found interface '" << str << "'" << oendl; | 105 | odebug << "ONetwork: found interface '" << str << "'" << oendl; |
106 | ONetworkInterface* iface; | 106 | ONetworkInterface* iface; |
107 | if ( isWirelessInterface( str ) ) | 107 | if ( isWirelessInterface( str ) ) |
108 | { | 108 | { |
109 | iface = new OWirelessNetworkInterface( this, (const char*) str ); | 109 | iface = new OWirelessNetworkInterface( this, (const char*) str ); |
110 | odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; | 110 | odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; |
111 | } | 111 | } |
112 | else | 112 | else |
113 | { | 113 | { |
114 | iface = new ONetworkInterface( this, (const char*) str ); | 114 | iface = new ONetworkInterface( this, (const char*) str ); |
115 | } | 115 | } |
116 | _interfaces.insert( str, iface ); | 116 | _interfaces.insert( str, iface ); |
117 | s.readLine(); | 117 | s.readLine(); |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | short ONetwork::wirelessExtensionVersion() | 122 | short ONetwork::wirelessExtensionVersion() |
123 | { | 123 | { |
124 | return WIRELESS_EXT; | 124 | return WIRELESS_EXT; |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | int ONetwork::count() const | 128 | int ONetwork::count() const |
129 | { | 129 | { |
130 | return _interfaces.count(); | 130 | return _interfaces.count(); |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | ONetworkInterface* ONetwork::interface( const QString& iface ) const | 134 | ONetworkInterface* ONetwork::interface( const QString& iface ) const |
135 | { | 135 | { |
136 | return _interfaces[iface]; | 136 | return _interfaces[iface]; |
137 | } | 137 | } |
138 | 138 | ||
139 | 139 | ||
140 | ONetwork* ONetwork::instance() | 140 | ONetwork* ONetwork::instance() |
141 | { | 141 | { |
142 | if ( !_instance ) _instance = new ONetwork(); | 142 | if ( !_instance ) _instance = new ONetwork(); |
143 | return _instance; | 143 | return _instance; |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | ONetwork::InterfaceIterator ONetwork::iterator() const | 147 | ONetwork::InterfaceIterator ONetwork::iterator() const |
148 | { | 148 | { |
149 | return ONetwork::InterfaceIterator( _interfaces ); | 149 | return ONetwork::InterfaceIterator( _interfaces ); |
150 | } | 150 | } |
151 | 151 | ||
152 | 152 | ||
153 | bool ONetwork::isPresent( const char* name ) const | 153 | bool ONetwork::isPresent( const char* name ) const |
154 | { | 154 | { |
155 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 155 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
156 | struct ifreq ifr; | 156 | struct ifreq ifr; |
157 | memset( &ifr, 0, sizeof( struct ifreq ) ); | 157 | memset( &ifr, 0, sizeof( struct ifreq ) ); |
158 | strcpy( (char*) &ifr.ifr_name, name ); | 158 | strcpy( (char*) &ifr.ifr_name, name ); |
159 | int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr ); | 159 | int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr ); |
160 | return result != -1; | 160 | return result != -1; |
161 | } | 161 | } |
162 | 162 | ||
163 | 163 | ||
164 | bool ONetwork::isWirelessInterface( const char* name ) const | 164 | bool ONetwork::isWirelessInterface( const char* name ) const |
165 | { | 165 | { |
166 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 166 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
167 | struct iwreq iwr; | 167 | struct iwreq iwr; |
168 | memset( &iwr, 0, sizeof( struct iwreq ) ); | 168 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
@@ -913,193 +913,194 @@ OStationList* OWirelessNetworkInterface::scanNetwork() | |||
913 | 913 | ||
914 | odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl; | 914 | odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl; |
915 | 915 | ||
916 | if ( results ) | 916 | if ( results ) |
917 | { | 917 | { |
918 | odebug << " - result length = " << _iwr.u.data.length << oendl; | 918 | odebug << " - result length = " << _iwr.u.data.length << oendl; |
919 | if ( !_iwr.u.data.length ) | 919 | if ( !_iwr.u.data.length ) |
920 | { | 920 | { |
921 | odebug << " - no results (empty neighbourhood)" << oendl; | 921 | odebug << " - no results (empty neighbourhood)" << oendl; |
922 | return stations; | 922 | return stations; |
923 | } | 923 | } |
924 | 924 | ||
925 | odebug << " - results are in!" << oendl; | 925 | odebug << " - results are in!" << oendl; |
926 | dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); | 926 | dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); |
927 | 927 | ||
928 | // parse results | 928 | // parse results |
929 | 929 | ||
930 | int offset = 0; | 930 | int offset = 0; |
931 | struct iw_event* we = (struct iw_event*) &buffer[0]; | 931 | struct iw_event* we = (struct iw_event*) &buffer[0]; |
932 | 932 | ||
933 | while ( offset < _iwr.u.data.length ) | 933 | while ( offset < _iwr.u.data.length ) |
934 | { | 934 | { |
935 | //const char* cmd = *(*_ioctlmap)[we->cmd]; | 935 | //const char* cmd = *(*_ioctlmap)[we->cmd]; |
936 | //if ( !cmd ) cmd = "<unknown>"; | 936 | //if ( !cmd ) cmd = "<unknown>"; |
937 | odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl; | 937 | odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl; |
938 | switch (we->cmd) | 938 | switch (we->cmd) |
939 | { | 939 | { |
940 | case SIOCGIWAP: | 940 | case SIOCGIWAP: |
941 | { | 941 | { |
942 | odebug << "SIOCGIWAP" << oendl; | 942 | odebug << "SIOCGIWAP" << oendl; |
943 | stations->append( new OStation() ); | 943 | stations->append( new OStation() ); |
944 | stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; | 944 | stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; |
945 | break; | 945 | break; |
946 | } | 946 | } |
947 | case SIOCGIWMODE: | 947 | case SIOCGIWMODE: |
948 | { | 948 | { |
949 | odebug << "SIOCGIWMODE" << oendl; | 949 | odebug << "SIOCGIWMODE" << oendl; |
950 | stations->last()->type = modeToString( we->u.mode ); | 950 | stations->last()->type = modeToString( we->u.mode ); |
951 | break; | 951 | break; |
952 | } | 952 | } |
953 | case SIOCGIWFREQ: | 953 | case SIOCGIWFREQ: |
954 | { | 954 | { |
955 | odebug << "SIOCGIWFREQ" << oendl; | 955 | odebug << "SIOCGIWFREQ" << oendl; |
956 | stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; | 956 | stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; |
957 | break; | 957 | break; |
958 | } | 958 | } |
959 | case SIOCGIWESSID: | 959 | case SIOCGIWESSID: |
960 | { | 960 | { |
961 | odebug << "SIOCGIWESSID" << oendl; | 961 | odebug << "SIOCGIWESSID" << oendl; |
962 | stations->last()->ssid = we->u.essid.pointer; | 962 | stations->last()->ssid = we->u.essid.pointer; |
963 | break; | 963 | break; |
964 | } | 964 | } |
965 | case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break; | 965 | case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break; |
966 | case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break; | 966 | case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break; |
967 | case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */ | 967 | case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */ |
968 | case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */ | 968 | case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */ |
969 | case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */ | 969 | case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */ |
970 | case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */ | 970 | case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */ |
971 | case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */ | 971 | case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */ |
972 | default: odebug << "unhandled event" << oendl; | 972 | default: odebug << "unhandled event" << oendl; |
973 | } | 973 | } |
974 | 974 | ||
975 | offset += we->len; | 975 | offset += we->len; |
976 | we = (struct iw_event*) &buffer[offset]; | 976 | we = (struct iw_event*) &buffer[offset]; |
977 | } | 977 | } |
978 | return stations; | 978 | return stations; |
979 | 979 | ||
980 | return stations; | 980 | return stations; |
981 | 981 | ||
982 | } | 982 | } |
983 | else | 983 | else |
984 | { | 984 | { |
985 | odebug << " - no results (timeout) :(" << oendl; | 985 | odebug << " - no results (timeout) :(" << oendl; |
986 | return stations; | 986 | return stations; |
987 | } | 987 | } |
988 | } | 988 | } |
989 | 989 | ||
990 | 990 | ||
991 | int OWirelessNetworkInterface::signalStrength() const | 991 | int OWirelessNetworkInterface::signalStrength() const |
992 | { | 992 | { |
993 | iw_statistics stat; | 993 | iw_statistics stat; |
994 | ::memset( &stat, 0, sizeof stat ); | 994 | ::memset( &stat, 0, sizeof stat ); |
995 | _iwr.u.data.pointer = (char*) &stat; | 995 | _iwr.u.data.pointer = (char*) &stat; |
996 | _iwr.u.data.flags = 0; | 996 | _iwr.u.data.flags = 0; |
997 | _iwr.u.data.length = sizeof stat; | 997 | _iwr.u.data.length = sizeof stat; |
998 | 998 | ||
999 | if ( !wioctl( SIOCGIWSTATS ) ) | 999 | if ( !wioctl( SIOCGIWSTATS ) ) |
1000 | { | 1000 | { |
1001 | return -1; | 1001 | return -1; |
1002 | } | 1002 | } |
1003 | 1003 | ||
1004 | int max = _range.max_qual.qual; | 1004 | int max = _range.max_qual.qual; |
1005 | int cur = stat.qual.qual; | 1005 | int cur = stat.qual.qual; |
1006 | int lev = stat.qual.level; //FIXME: Do something with them? | 1006 | int lev = stat.qual.level; //FIXME: Do something with them? |
1007 | int noi = stat.qual.noise; //FIXME: Do something with them? | 1007 | int noi = stat.qual.noise; //FIXME: Do something with them? |
1008 | 1008 | ||
1009 | return cur*100/max; | 1009 | |
1010 | return max != 0 ? cur*100/max: -1; | ||
1010 | } | 1011 | } |
1011 | 1012 | ||
1012 | 1013 | ||
1013 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 1014 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
1014 | { | 1015 | { |
1015 | #ifndef NODEBUG | 1016 | #ifndef NODEBUG |
1016 | int result = ::ioctl( _sfd, call, &iwreq ); | 1017 | int result = ::ioctl( _sfd, call, &iwreq ); |
1017 | 1018 | ||
1018 | if ( result == -1 ) | 1019 | if ( result == -1 ) |
1019 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" | 1020 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
1020 | << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; | 1021 | << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; |
1021 | else | 1022 | else |
1022 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" | 1023 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
1023 | << debugmapper->map( call ) << "' - Status: Ok." << oendl; | 1024 | << debugmapper->map( call ) << "' - Status: Ok." << oendl; |
1024 | 1025 | ||
1025 | return ( result != -1 ); | 1026 | return ( result != -1 ); |
1026 | #else | 1027 | #else |
1027 | return ::ioctl( _sfd, call, &iwreq ) != -1; | 1028 | return ::ioctl( _sfd, call, &iwreq ) != -1; |
1028 | #endif | 1029 | #endif |
1029 | } | 1030 | } |
1030 | 1031 | ||
1031 | 1032 | ||
1032 | bool OWirelessNetworkInterface::wioctl( int call ) const | 1033 | bool OWirelessNetworkInterface::wioctl( int call ) const |
1033 | { | 1034 | { |
1034 | strcpy( _iwr.ifr_name, name() ); | 1035 | strcpy( _iwr.ifr_name, name() ); |
1035 | return wioctl( call, _iwr ); | 1036 | return wioctl( call, _iwr ); |
1036 | } | 1037 | } |
1037 | 1038 | ||
1038 | 1039 | ||
1039 | /*====================================================================================== | 1040 | /*====================================================================================== |
1040 | * OMonitoringInterface | 1041 | * OMonitoringInterface |
1041 | *======================================================================================*/ | 1042 | *======================================================================================*/ |
1042 | 1043 | ||
1043 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1044 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1044 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) | 1045 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) |
1045 | { | 1046 | { |
1046 | } | 1047 | } |
1047 | 1048 | ||
1048 | 1049 | ||
1049 | OMonitoringInterface::~OMonitoringInterface() | 1050 | OMonitoringInterface::~OMonitoringInterface() |
1050 | { | 1051 | { |
1051 | } | 1052 | } |
1052 | 1053 | ||
1053 | 1054 | ||
1054 | void OMonitoringInterface::setChannel( int c ) | 1055 | void OMonitoringInterface::setChannel( int c ) |
1055 | { | 1056 | { |
1056 | // use standard WE channel switching protocol | 1057 | // use standard WE channel switching protocol |
1057 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); | 1058 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
1058 | _if->_iwr.u.freq.m = c; | 1059 | _if->_iwr.u.freq.m = c; |
1059 | _if->_iwr.u.freq.e = 0; | 1060 | _if->_iwr.u.freq.e = 0; |
1060 | _if->wioctl( SIOCSIWFREQ ); | 1061 | _if->wioctl( SIOCSIWFREQ ); |
1061 | } | 1062 | } |
1062 | 1063 | ||
1063 | 1064 | ||
1064 | void OMonitoringInterface::setEnabled( bool b ) | 1065 | void OMonitoringInterface::setEnabled( bool b ) |
1065 | { | 1066 | { |
1066 | } | 1067 | } |
1067 | 1068 | ||
1068 | 1069 | ||
1069 | /*====================================================================================== | 1070 | /*====================================================================================== |
1070 | * OCiscoMonitoringInterface | 1071 | * OCiscoMonitoringInterface |
1071 | *======================================================================================*/ | 1072 | *======================================================================================*/ |
1072 | 1073 | ||
1073 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1074 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1074 | :OMonitoringInterface( iface, prismHeader ) | 1075 | :OMonitoringInterface( iface, prismHeader ) |
1075 | { | 1076 | { |
1076 | iface->setMonitoring( this ); | 1077 | iface->setMonitoring( this ); |
1077 | } | 1078 | } |
1078 | 1079 | ||
1079 | 1080 | ||
1080 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | 1081 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() |
1081 | { | 1082 | { |
1082 | } | 1083 | } |
1083 | 1084 | ||
1084 | 1085 | ||
1085 | void OCiscoMonitoringInterface::setEnabled( bool b ) | 1086 | void OCiscoMonitoringInterface::setEnabled( bool b ) |
1086 | { | 1087 | { |
1087 | QString fname; | 1088 | QString fname; |
1088 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); | 1089 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); |
1089 | QFile f( fname ); | 1090 | QFile f( fname ); |
1090 | if ( !f.exists() ) return; | 1091 | if ( !f.exists() ) return; |
1091 | 1092 | ||
1092 | if ( f.open( IO_WriteOnly ) ) | 1093 | if ( f.open( IO_WriteOnly ) ) |
1093 | { | 1094 | { |
1094 | QTextStream s( &f ); | 1095 | QTextStream s( &f ); |
1095 | s << "Mode: r"; | 1096 | s << "Mode: r"; |
1096 | s << "Mode: y"; | 1097 | s << "Mode: y"; |
1097 | s << "XmitPower: 1"; | 1098 | s << "XmitPower: 1"; |
1098 | } | 1099 | } |
1099 | 1100 | ||
1100 | // flushing and closing will be done automatically when f goes out of scope | 1101 | // flushing and closing will be done automatically when f goes out of scope |
1101 | } | 1102 | } |
1102 | 1103 | ||
1103 | 1104 | ||
1104 | QString OCiscoMonitoringInterface::name() const | 1105 | QString OCiscoMonitoringInterface::name() const |
1105 | { | 1106 | { |
@@ -1150,99 +1151,99 @@ QString OWlanNGMonitoringInterface::name() const | |||
1150 | 1151 | ||
1151 | 1152 | ||
1152 | void OWlanNGMonitoringInterface::setChannel( int c ) | 1153 | void OWlanNGMonitoringInterface::setChannel( int c ) |
1153 | { | 1154 | { |
1154 | //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. | 1155 | //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. |
1155 | 1156 | ||
1156 | QString enable = "true"; //_if->monitorMode() ? "true" : "false"; | 1157 | QString enable = "true"; //_if->monitorMode() ? "true" : "false"; |
1157 | QString prism = _prismHeader ? "true" : "false"; | 1158 | QString prism = _prismHeader ? "true" : "false"; |
1158 | QString cmd; | 1159 | QString cmd; |
1159 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 1160 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
1160 | (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); | 1161 | (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); |
1161 | system( cmd ); | 1162 | system( cmd ); |
1162 | } | 1163 | } |
1163 | 1164 | ||
1164 | 1165 | ||
1165 | /*====================================================================================== | 1166 | /*====================================================================================== |
1166 | * OHostAPMonitoringInterface | 1167 | * OHostAPMonitoringInterface |
1167 | *======================================================================================*/ | 1168 | *======================================================================================*/ |
1168 | 1169 | ||
1169 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1170 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1170 | :OMonitoringInterface( iface, prismHeader ) | 1171 | :OMonitoringInterface( iface, prismHeader ) |
1171 | { | 1172 | { |
1172 | iface->setMonitoring( this ); | 1173 | iface->setMonitoring( this ); |
1173 | } | 1174 | } |
1174 | 1175 | ||
1175 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() | 1176 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() |
1176 | { | 1177 | { |
1177 | } | 1178 | } |
1178 | 1179 | ||
1179 | void OHostAPMonitoringInterface::setEnabled( bool b ) | 1180 | void OHostAPMonitoringInterface::setEnabled( bool b ) |
1180 | { | 1181 | { |
1181 | int monitorCode = _prismHeader ? 1 : 2; | 1182 | int monitorCode = _prismHeader ? 1 : 2; |
1182 | if ( b ) | 1183 | if ( b ) |
1183 | { | 1184 | { |
1184 | _if->setPrivate( "monitor", 1, monitorCode ); | 1185 | _if->setPrivate( "monitor", 1, monitorCode ); |
1185 | } | 1186 | } |
1186 | else | 1187 | else |
1187 | { | 1188 | { |
1188 | _if->setPrivate( "monitor", 1, 0 ); | 1189 | _if->setPrivate( "monitor", 1, 0 ); |
1189 | } | 1190 | } |
1190 | } | 1191 | } |
1191 | 1192 | ||
1192 | 1193 | ||
1193 | QString OHostAPMonitoringInterface::name() const | 1194 | QString OHostAPMonitoringInterface::name() const |
1194 | { | 1195 | { |
1195 | return "hostap"; | 1196 | return "hostap"; |
1196 | } | 1197 | } |
1197 | 1198 | ||
1198 | 1199 | ||
1199 | /*====================================================================================== | 1200 | /*====================================================================================== |
1200 | * OOrinocoNetworkInterface | 1201 | * OOrinocoNetworkInterface |
1201 | *======================================================================================*/ | 1202 | *======================================================================================*/ |
1202 | 1203 | ||
1203 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1204 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1204 | :OMonitoringInterface( iface, prismHeader ) | 1205 | :OMonitoringInterface( iface, prismHeader ) |
1205 | { | 1206 | { |
1206 | iface->setMonitoring( this ); | 1207 | iface->setMonitoring( this ); |
1207 | } | 1208 | } |
1208 | 1209 | ||
1209 | 1210 | ||
1210 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() | 1211 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() |
1211 | { | 1212 | { |
1212 | } | 1213 | } |
1213 | 1214 | ||
1214 | 1215 | ||
1215 | void OOrinocoMonitoringInterface::setChannel( int c ) | 1216 | void OOrinocoMonitoringInterface::setChannel( int c ) |
1216 | { | 1217 | { |
1217 | if ( !_if->hasPrivate( "monitor" ) ) | 1218 | if ( !_if->hasPrivate( "monitor" ) ) |
1218 | { | 1219 | { |
1219 | this->OMonitoringInterface::setChannel( c ); | 1220 | this->OMonitoringInterface::setChannel( c ); |
1220 | } | 1221 | } |
1221 | else | 1222 | else |
1222 | { | 1223 | { |
1223 | int monitorCode = _prismHeader ? 1 : 2; | 1224 | int monitorCode = _prismHeader ? 1 : 2; |
1224 | _if->setPrivate( "monitor", 2, monitorCode, c ); | 1225 | _if->setPrivate( "monitor", 2, monitorCode, c ); |
1225 | } | 1226 | } |
1226 | } | 1227 | } |
1227 | 1228 | ||
1228 | 1229 | ||
1229 | void OOrinocoMonitoringInterface::setEnabled( bool b ) | 1230 | void OOrinocoMonitoringInterface::setEnabled( bool b ) |
1230 | { | 1231 | { |
1231 | if ( b ) | 1232 | if ( b ) |
1232 | { | 1233 | { |
1233 | setChannel( 1 ); | 1234 | setChannel( 1 ); |
1234 | } | 1235 | } |
1235 | else | 1236 | else |
1236 | { | 1237 | { |
1237 | _if->setPrivate( "monitor", 2, 0, 0 ); | 1238 | _if->setPrivate( "monitor", 2, 0, 0 ); |
1238 | } | 1239 | } |
1239 | } | 1240 | } |
1240 | 1241 | ||
1241 | 1242 | ||
1242 | QString OOrinocoMonitoringInterface::name() const | 1243 | QString OOrinocoMonitoringInterface::name() const |
1243 | { | 1244 | { |
1244 | return "orinoco"; | 1245 | return "orinoco"; |
1245 | } | 1246 | } |
1246 | 1247 | ||
1247 | } | 1248 | } |
1248 | } | 1249 | } |