-rw-r--r-- | libopie2/opienet/onetwork.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 36f409b..915814d 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -944,282 +944,285 @@ OStationList* OWirelessNetworkInterface::scanNetwork() | |||
944 | odebug << "SIOCGIWESSID" << oendl; | 944 | odebug << "SIOCGIWESSID" << oendl; |
945 | stations->last()->ssid = we->u.essid.pointer; | 945 | stations->last()->ssid = we->u.essid.pointer; |
946 | break; | 946 | break; |
947 | } | 947 | } |
948 | case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break; | 948 | case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break; |
949 | case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break; | 949 | case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break; |
950 | case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */ | 950 | case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */ |
951 | case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */ | 951 | case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */ |
952 | case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */ | 952 | case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */ |
953 | case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */ | 953 | case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */ |
954 | case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */ | 954 | case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */ |
955 | default: odebug << "unhandled event" << oendl; | 955 | default: odebug << "unhandled event" << oendl; |
956 | } | 956 | } |
957 | 957 | ||
958 | offset += we->len; | 958 | offset += we->len; |
959 | we = (struct iw_event*) &buffer[offset]; | 959 | we = (struct iw_event*) &buffer[offset]; |
960 | } | 960 | } |
961 | return stations; | 961 | return stations; |
962 | 962 | ||
963 | return stations; | 963 | return stations; |
964 | 964 | ||
965 | } | 965 | } |
966 | else | 966 | else |
967 | { | 967 | { |
968 | odebug << " - no results (timeout) :(" << oendl; | 968 | odebug << " - no results (timeout) :(" << oendl; |
969 | return stations; | 969 | return stations; |
970 | } | 970 | } |
971 | } | 971 | } |
972 | 972 | ||
973 | 973 | ||
974 | int OWirelessNetworkInterface::signalStrength() const | 974 | int OWirelessNetworkInterface::signalStrength() const |
975 | { | 975 | { |
976 | iw_statistics stat; | 976 | iw_statistics stat; |
977 | ::memset( &stat, 0, sizeof stat ); | 977 | ::memset( &stat, 0, sizeof stat ); |
978 | _iwr.u.data.pointer = (char*) &stat; | 978 | _iwr.u.data.pointer = (char*) &stat; |
979 | _iwr.u.data.flags = 0; | 979 | _iwr.u.data.flags = 0; |
980 | _iwr.u.data.length = sizeof stat; | 980 | _iwr.u.data.length = sizeof stat; |
981 | 981 | ||
982 | if ( !wioctl( SIOCGIWSTATS ) ) | 982 | if ( !wioctl( SIOCGIWSTATS ) ) |
983 | { | 983 | { |
984 | return -1; | 984 | return -1; |
985 | } | 985 | } |
986 | 986 | ||
987 | int max = _range.max_qual.qual; | 987 | int max = _range.max_qual.qual; |
988 | int cur = stat.qual.qual; | 988 | int cur = stat.qual.qual; |
989 | int lev = stat.qual.level; //FIXME: Do something with them? | 989 | int lev = stat.qual.level; //FIXME: Do something with them? |
990 | int noi = stat.qual.noise; //FIXME: Do something with them? | 990 | int noi = stat.qual.noise; //FIXME: Do something with them? |
991 | 991 | ||
992 | return cur*100/max; | 992 | return cur*100/max; |
993 | } | 993 | } |
994 | 994 | ||
995 | 995 | ||
996 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 996 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
997 | { | 997 | { |
998 | #ifndef NODEBUG | 998 | #ifndef NODEBUG |
999 | int result = ::ioctl( _sfd, call, &iwreq ); | 999 | int result = ::ioctl( _sfd, call, &iwreq ); |
1000 | 1000 | ||
1001 | if ( result == -1 ) | 1001 | if ( result == -1 ) |
1002 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" | 1002 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
1003 | << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; | 1003 | << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; |
1004 | else | 1004 | else |
1005 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" | 1005 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
1006 | << debugmapper->map( call ) << "' - Status: Ok." << oendl; | 1006 | << debugmapper->map( call ) << "' - Status: Ok." << oendl; |
1007 | 1007 | ||
1008 | return ( result != -1 ); | 1008 | return ( result != -1 ); |
1009 | #else | 1009 | #else |
1010 | return ::ioctl( _sfd, call, &iwreq ) != -1; | 1010 | return ::ioctl( _sfd, call, &iwreq ) != -1; |
1011 | #endif | 1011 | #endif |
1012 | } | 1012 | } |
1013 | 1013 | ||
1014 | 1014 | ||
1015 | bool OWirelessNetworkInterface::wioctl( int call ) const | 1015 | bool OWirelessNetworkInterface::wioctl( int call ) const |
1016 | { | 1016 | { |
1017 | strcpy( _iwr.ifr_name, name() ); | 1017 | strcpy( _iwr.ifr_name, name() ); |
1018 | return wioctl( call, _iwr ); | 1018 | return wioctl( call, _iwr ); |
1019 | } | 1019 | } |
1020 | 1020 | ||
1021 | 1021 | ||
1022 | /*====================================================================================== | 1022 | /*====================================================================================== |
1023 | * OMonitoringInterface | 1023 | * OMonitoringInterface |
1024 | *======================================================================================*/ | 1024 | *======================================================================================*/ |
1025 | 1025 | ||
1026 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1026 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1027 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) | 1027 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) |
1028 | { | 1028 | { |
1029 | } | 1029 | } |
1030 | 1030 | ||
1031 | 1031 | ||
1032 | OMonitoringInterface::~OMonitoringInterface() | 1032 | OMonitoringInterface::~OMonitoringInterface() |
1033 | { | 1033 | { |
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | 1036 | ||
1037 | void OMonitoringInterface::setChannel( int c ) | 1037 | void OMonitoringInterface::setChannel( int c ) |
1038 | { | 1038 | { |
1039 | // use standard WE channel switching protocol | 1039 | // use standard WE channel switching protocol |
1040 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); | 1040 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
1041 | _if->_iwr.u.freq.m = c; | 1041 | _if->_iwr.u.freq.m = c; |
1042 | _if->_iwr.u.freq.e = 0; | 1042 | _if->_iwr.u.freq.e = 0; |
1043 | _if->wioctl( SIOCSIWFREQ ); | 1043 | _if->wioctl( SIOCSIWFREQ ); |
1044 | } | 1044 | } |
1045 | 1045 | ||
1046 | 1046 | ||
1047 | void OMonitoringInterface::setEnabled( bool b ) | 1047 | void OMonitoringInterface::setEnabled( bool b ) |
1048 | { | 1048 | { |
1049 | } | 1049 | } |
1050 | 1050 | ||
1051 | 1051 | ||
1052 | /*====================================================================================== | 1052 | /*====================================================================================== |
1053 | * OCiscoMonitoringInterface | 1053 | * OCiscoMonitoringInterface |
1054 | *======================================================================================*/ | 1054 | *======================================================================================*/ |
1055 | 1055 | ||
1056 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1056 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1057 | :OMonitoringInterface( iface, prismHeader ) | 1057 | :OMonitoringInterface( iface, prismHeader ) |
1058 | { | 1058 | { |
1059 | iface->setMonitoring( this ); | 1059 | iface->setMonitoring( this ); |
1060 | } | 1060 | } |
1061 | 1061 | ||
1062 | 1062 | ||
1063 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | 1063 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() |
1064 | { | 1064 | { |
1065 | } | 1065 | } |
1066 | 1066 | ||
1067 | 1067 | ||
1068 | void OCiscoMonitoringInterface::setEnabled( bool b ) | 1068 | void OCiscoMonitoringInterface::setEnabled( bool b ) |
1069 | { | 1069 | { |
1070 | QString fname; | 1070 | QString fname; |
1071 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); | 1071 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); |
1072 | QFile f( fname ); | 1072 | QFile f( fname ); |
1073 | if ( !f.exists() ) return; | 1073 | if ( !f.exists() ) return; |
1074 | 1074 | ||
1075 | if ( f.open( IO_WriteOnly ) ) | 1075 | if ( f.open( IO_WriteOnly ) ) |
1076 | { | 1076 | { |
1077 | QTextStream s( &f ); | 1077 | QTextStream s( &f ); |
1078 | s << "Mode: r"; | 1078 | s << "Mode: r"; |
1079 | s << "Mode: y"; | 1079 | s << "Mode: y"; |
1080 | s << "XmitPower: 1"; | 1080 | s << "XmitPower: 1"; |
1081 | } | 1081 | } |
1082 | 1082 | ||
1083 | // flushing and closing will be done automatically when f goes out of scope | 1083 | // flushing and closing will be done automatically when f goes out of scope |
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | 1086 | ||
1087 | QString OCiscoMonitoringInterface::name() const | 1087 | QString OCiscoMonitoringInterface::name() const |
1088 | { | 1088 | { |
1089 | return "cisco"; | 1089 | return "cisco"; |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | 1092 | ||
1093 | void OCiscoMonitoringInterface::setChannel( int ) | 1093 | void OCiscoMonitoringInterface::setChannel( int ) |
1094 | { | 1094 | { |
1095 | // cisco devices automatically switch channels when in monitor mode | 1095 | // cisco devices automatically switch channels when in monitor mode |
1096 | } | 1096 | } |
1097 | 1097 | ||
1098 | 1098 | ||
1099 | /*====================================================================================== | 1099 | /*====================================================================================== |
1100 | * OWlanNGMonitoringInterface | 1100 | * OWlanNGMonitoringInterface |
1101 | *======================================================================================*/ | 1101 | *======================================================================================*/ |
1102 | 1102 | ||
1103 | 1103 | ||
1104 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1104 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1105 | :OMonitoringInterface( iface, prismHeader ) | 1105 | :OMonitoringInterface( iface, prismHeader ) |
1106 | { | 1106 | { |
1107 | iface->setMonitoring( this ); | 1107 | iface->setMonitoring( this ); |
1108 | } | 1108 | } |
1109 | 1109 | ||
1110 | 1110 | ||
1111 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() | 1111 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() |
1112 | { | 1112 | { |
1113 | } | 1113 | } |
1114 | 1114 | ||
1115 | 1115 | ||
1116 | void OWlanNGMonitoringInterface::setEnabled( bool b ) | 1116 | void OWlanNGMonitoringInterface::setEnabled( bool b ) |
1117 | { | 1117 | { |
1118 | //FIXME: do nothing if its already in the same mode | 1118 | //FIXME: do nothing if its already in the same mode |
1119 | 1119 | ||
1120 | QString enable = b ? "true" : "false"; | 1120 | QString enable = b ? "true" : "false"; |
1121 | QString prism = _prismHeader ? "true" : "false"; | 1121 | QString prism = _prismHeader ? "true" : "false"; |
1122 | QString cmd; | 1122 | QString cmd; |
1123 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 1123 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
1124 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); | 1124 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); |
1125 | system( cmd ); | 1125 | system( cmd ); |
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | 1128 | ||
1129 | QString OWlanNGMonitoringInterface::name() const | 1129 | QString OWlanNGMonitoringInterface::name() const |
1130 | { | 1130 | { |
1131 | return "wlan-ng"; | 1131 | return "wlan-ng"; |
1132 | } | 1132 | } |
1133 | 1133 | ||
1134 | 1134 | ||
1135 | void OWlanNGMonitoringInterface::setChannel( int c ) | 1135 | void OWlanNGMonitoringInterface::setChannel( int c ) |
1136 | { | 1136 | { |
1137 | //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. | 1137 | //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. |
1138 | 1138 | ||
1139 | QString enable = "true"; //_if->monitorMode() ? "true" : "false"; | 1139 | QString enable = "true"; //_if->monitorMode() ? "true" : "false"; |
1140 | QString prism = _prismHeader ? "true" : "false"; | 1140 | QString prism = _prismHeader ? "true" : "false"; |
1141 | QString cmd; | 1141 | QString cmd; |
1142 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 1142 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
1143 | (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); | 1143 | (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); |
1144 | system( cmd ); | 1144 | system( cmd ); |
1145 | } | 1145 | } |
1146 | 1146 | ||
1147 | 1147 | ||
1148 | /*====================================================================================== | 1148 | /*====================================================================================== |
1149 | * OHostAPMonitoringInterface | 1149 | * OHostAPMonitoringInterface |
1150 | *======================================================================================*/ | 1150 | *======================================================================================*/ |
1151 | 1151 | ||
1152 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1152 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1153 | :OMonitoringInterface( iface, prismHeader ) | 1153 | :OMonitoringInterface( iface, prismHeader ) |
1154 | { | 1154 | { |
1155 | iface->setMonitoring( this ); | 1155 | iface->setMonitoring( this ); |
1156 | } | 1156 | } |
1157 | 1157 | ||
1158 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() | 1158 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() |
1159 | { | 1159 | { |
1160 | } | 1160 | } |
1161 | 1161 | ||
1162 | void OHostAPMonitoringInterface::setEnabled( bool b ) | 1162 | void OHostAPMonitoringInterface::setEnabled( bool b ) |
1163 | { | 1163 | { |
1164 | int monitorCode = _prismHeader ? 1 : 2; | 1164 | int monitorCode = _prismHeader ? 1 : 2; |
1165 | if ( b ) | 1165 | if ( b ) |
1166 | { | 1166 | { |
1167 | _if->setPrivate( "monitor", 1, monitorCode ); | 1167 | _if->setPrivate( "monitor", 1, monitorCode ); |
1168 | } | 1168 | } |
1169 | else | 1169 | else |
1170 | { | 1170 | { |
1171 | _if->setPrivate( "monitor", 1, 0 ); | 1171 | _if->setPrivate( "monitor", 1, 0 ); |
1172 | } | 1172 | } |
1173 | } | 1173 | } |
1174 | 1174 | ||
1175 | 1175 | ||
1176 | QString OHostAPMonitoringInterface::name() const | 1176 | QString OHostAPMonitoringInterface::name() const |
1177 | { | 1177 | { |
1178 | return "hostap"; | 1178 | return "hostap"; |
1179 | } | 1179 | } |
1180 | 1180 | ||
1181 | 1181 | ||
1182 | /*====================================================================================== | 1182 | /*====================================================================================== |
1183 | * OOrinocoNetworkInterface | 1183 | * OOrinocoNetworkInterface |
1184 | *======================================================================================*/ | 1184 | *======================================================================================*/ |
1185 | 1185 | ||
1186 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1186 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1187 | :OMonitoringInterface( iface, prismHeader ) | 1187 | :OMonitoringInterface( iface, prismHeader ) |
1188 | { | 1188 | { |
1189 | iface->setMonitoring( this ); | 1189 | iface->setMonitoring( this ); |
1190 | } | 1190 | } |
1191 | 1191 | ||
1192 | 1192 | ||
1193 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() | 1193 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() |
1194 | { | 1194 | { |
1195 | } | 1195 | } |
1196 | 1196 | ||
1197 | 1197 | ||
1198 | void OOrinocoMonitoringInterface::setChannel( int c ) | 1198 | void OOrinocoMonitoringInterface::setChannel( int c ) |
1199 | { | 1199 | { |
1200 | int monitorCode = _prismHeader ? 1 : 2; | 1200 | if ( !_if->hasPrivate( "monitor" ) ) |
1201 | _if->setPrivate( "monitor", 2, monitorCode, c ); | 1201 | { |
1202 | this->OMonitoringInterface::setChannel( c ); | ||
1203 | } | ||
1204 | else | ||
1205 | { | ||
1206 | int monitorCode = _prismHeader ? 1 : 2; | ||
1207 | _if->setPrivate( "monitor", 2, monitorCode, c ); | ||
1208 | } | ||
1202 | } | 1209 | } |
1203 | 1210 | ||
1204 | 1211 | ||
1205 | void OOrinocoMonitoringInterface::setEnabled( bool b ) | 1212 | void OOrinocoMonitoringInterface::setEnabled( bool b ) |
1206 | { | 1213 | { |
1207 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | ||
1208 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | ||
1209 | // However, as of recent orinoco drivers, IW_MODE_MONITOR is still not supported | ||
1210 | |||
1211 | if ( b ) | 1214 | if ( b ) |
1212 | { | 1215 | { |
1213 | setChannel( 1 ); | 1216 | setChannel( 1 ); |
1214 | } | 1217 | } |
1215 | else | 1218 | else |
1216 | { | 1219 | { |
1217 | _if->setPrivate( "monitor", 2, 0, 0 ); | 1220 | _if->setPrivate( "monitor", 2, 0, 0 ); |
1218 | } | 1221 | } |
1219 | } | 1222 | } |
1220 | 1223 | ||
1221 | 1224 | ||
1222 | QString OOrinocoMonitoringInterface::name() const | 1225 | QString OOrinocoMonitoringInterface::name() const |
1223 | { | 1226 | { |
1224 | return "orinoco"; | 1227 | return "orinoco"; |
1225 | } | 1228 | } |