| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2018 The Qt Company Ltd and/or its subsidiary(-ies). |
| 4 | ** Contact: http://www.qt-project.org/legal |
| 5 | ** |
| 6 | ** This file is part of the QtSystems module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qnetworkinfo_win_p.h" |
| 41 | |
| 42 | #include <QMutex> |
| 43 | #include <QLibraryInfo> |
| 44 | #include <QtCore/qlibrary.h> |
| 45 | #include <QtCore/QTimer> |
| 46 | #include <QtCore/QTimerEvent> |
| 47 | #include <QtCore/QSettings> |
| 48 | #include <QtCore/QStringList> |
| 49 | #include <QtCore/qt_windows.h> |
| 50 | |
| 51 | #include <QtCore/qmetaobject.h> |
| 52 | |
| 53 | #if !defined( Q_CC_MINGW) |
| 54 | #ifndef Q_OS_WINCE |
| 55 | #include "qwmihelper_win_p.h" |
| 56 | |
| 57 | enum NDIS_MEDIUM { |
| 58 | NdisMedium802_3 = 0, |
| 59 | NdisMediumWirelessWan = 9, |
| 60 | }; |
| 61 | |
| 62 | enum NDIS_PHYSICAL_MEDIUM { |
| 63 | NdisPhysicalMediumUnspecified = 0, |
| 64 | NdisPhysicalMediumWirelessLan = 1, |
| 65 | NdisPhysicalMediumBluetooth = 10, |
| 66 | NdisPhysicalMediumWiMax = 12, |
| 67 | }; |
| 68 | |
| 69 | #define OID_GEN_MEDIA_SUPPORTED 0x00010103 |
| 70 | #define OID_GEN_PHYSICAL_MEDIUM 0x00010202 |
| 71 | |
| 72 | #define IOCTL_NDIS_QUERY_GLOBAL_STATS \ |
| 73 | CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, 0, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) |
| 74 | |
| 75 | #endif |
| 76 | #endif |
| 77 | |
| 78 | |
| 79 | #define WLAN_MAX_NAME_LENGTH 256 |
| 80 | #define DOT11_SSID_MAX_LENGTH 32 |
| 81 | #define WLAN_NOTIFICATION_SOURCE_ALL 0x0000ffff |
| 82 | |
| 83 | enum WLAN_INTF_OPCODE { |
| 84 | wlan_intf_opcode_autoconf_start = 0x000000000, |
| 85 | wlan_intf_opcode_autoconf_enabled, |
| 86 | wlan_intf_opcode_background_scan_enabled, |
| 87 | wlan_intf_opcode_media_streaming_mode, |
| 88 | wlan_intf_opcode_radio_state, |
| 89 | wlan_intf_opcode_batteryStatuss_type, |
| 90 | wlan_intf_opcode_interface_state, |
| 91 | wlan_intf_opcode_current_connection, |
| 92 | wlan_intf_opcode_channel_number, |
| 93 | wlan_intf_opcode_supported_infrastructure_auth_cipher_pairs, |
| 94 | wlan_intf_opcode_supported_adhoc_auth_cipher_pairs, |
| 95 | wlan_intf_opcode_supported_country_or_region_string_list, |
| 96 | wlan_intf_opcode_current_operation_mode, |
| 97 | wlan_intf_opcode_supported_safe_mode, |
| 98 | wlan_intf_opcode_certified_safe_mode, |
| 99 | wlan_intf_opcode_autoconf_end = 0x0fffffff, |
| 100 | wlan_intf_opcode_msm_start = 0x10000100, |
| 101 | wlan_intf_opcode_statistics, |
| 102 | wlan_intf_opcode_rssi, |
| 103 | wlan_intf_opcode_msm_end = 0x1fffffff, |
| 104 | wlan_intf_opcode_security_start = 0x20010000, |
| 105 | wlan_intf_opcode_security_end = 0x2fffffff, |
| 106 | wlan_intf_opcode_ihv_start = 0x30000000, |
| 107 | wlan_intf_opcode_ihv_end = 0x3fffffff |
| 108 | }; |
| 109 | |
| 110 | enum WLAN_OPCODE_VALUE_TYPE { |
| 111 | wlan_opcode_value_type_query_only = 0, |
| 112 | wlan_opcode_value_type_set_by_group_policy, |
| 113 | wlan_opcode_value_type_set_by_user, |
| 114 | wlan_opcode_value_type_invalid |
| 115 | }; |
| 116 | |
| 117 | enum WLAN_INTERFACE_STATE { |
| 118 | wlan_interface_state_not_ready = 0, |
| 119 | wlan_interface_state_connected, |
| 120 | wlan_interface_state_ad_hoc_network_formed, |
| 121 | wlan_interface_state_disconnecting, |
| 122 | wlan_interface_state_disconnected, |
| 123 | wlan_interface_state_associating, |
| 124 | wlan_interface_state_discovering, |
| 125 | wlan_interface_state_authenticating |
| 126 | }; |
| 127 | |
| 128 | struct WLAN_INTERFACE_INFO { |
| 129 | GUID InterfaceGuid; |
| 130 | WCHAR strInterfaceDescription[WLAN_MAX_NAME_LENGTH]; |
| 131 | WLAN_INTERFACE_STATE isState; |
| 132 | }; |
| 133 | |
| 134 | struct WLAN_INTERFACE_INFO_LIST { |
| 135 | DWORD dwNumberOfItems; |
| 136 | DWORD dwIndex; |
| 137 | WLAN_INTERFACE_INFO InterfaceInfo[1]; |
| 138 | }; |
| 139 | |
| 140 | struct WLAN_NOTIFICATION_DATA { |
| 141 | DWORD NotificationSource; |
| 142 | DWORD NotificationCode; |
| 143 | GUID InterfaceGuid; |
| 144 | DWORD dwDataSize; |
| 145 | PVOID pData; |
| 146 | }; |
| 147 | |
| 148 | enum WLAN_CONNECTION_MODE { |
| 149 | wlan_connection_mode_profile = 0, |
| 150 | wlan_connection_mode_temporary_profile, |
| 151 | wlan_connection_mode_discovery_secure, |
| 152 | wlan_connection_mode_discovery_unsecure, |
| 153 | wlan_connection_mode_auto, |
| 154 | wlan_connection_mode_invalid |
| 155 | }; |
| 156 | |
| 157 | enum DOT11_PHY_TYPE { |
| 158 | dot11_phy_type_unknown = 0, |
| 159 | dot11_phy_type_any = dot11_phy_type_unknown, |
| 160 | dot11_phy_type_fhss = 1, |
| 161 | dot11_phy_type_dsss = 2, |
| 162 | dot11_phy_type_irbaseband = 3, |
| 163 | dot11_phy_type_ofdm = 4, |
| 164 | dot11_phy_type_hrdsss = 5, |
| 165 | dot11_phy_type_erp = 6, |
| 166 | dot11_phy_type_ht = 7, |
| 167 | dot11_phy_type_IHV_start = 0x80000000, |
| 168 | dot11_phy_type_IHV_end = 0xffffffff |
| 169 | }; |
| 170 | |
| 171 | |
| 172 | enum DOT11_AUTH_ALGORITHM { |
| 173 | DOT11_AUTH_ALGO_80211_OPEN = 1, |
| 174 | DOT11_AUTH_ALGO_80211_SHARED_KEY = 2, |
| 175 | DOT11_AUTH_ALGO_WPA = 3, |
| 176 | DOT11_AUTH_ALGO_WPA_PSK = 4, |
| 177 | DOT11_AUTH_ALGO_WPA_NONE = 5, |
| 178 | DOT11_AUTH_ALGO_RSNA = 6, |
| 179 | DOT11_AUTH_ALGO_RSNA_PSK = 7, |
| 180 | DOT11_AUTH_ALGO_IHV_START = 0x80000000, |
| 181 | DOT11_AUTH_ALGO_IHV_END = 0xffffffff |
| 182 | }; |
| 183 | |
| 184 | |
| 185 | enum DOT11_CIPHER_ALGORITHM { |
| 186 | DOT11_CIPHER_ALGO_NONE = 0x00, |
| 187 | DOT11_CIPHER_ALGO_WEP40 = 0x01, |
| 188 | DOT11_CIPHER_ALGO_TKIP = 0x02, |
| 189 | DOT11_CIPHER_ALGO_CCMP = 0x04, |
| 190 | DOT11_CIPHER_ALGO_WEP104 = 0x05, |
| 191 | DOT11_CIPHER_ALGO_WPA_USE_GROUP = 0x100, |
| 192 | DOT11_CIPHER_ALGO_RSN_USE_GROUP = 0x100, |
| 193 | DOT11_CIPHER_ALGO_WEP = 0x101, |
| 194 | DOT11_CIPHER_ALGO_IHV_START = 0x80000000, |
| 195 | DOT11_CIPHER_ALGO_IHV_END = 0xffffffff |
| 196 | }; |
| 197 | |
| 198 | |
| 199 | enum DOT11_batteryStatusS_TYPE { |
| 200 | dot11_batteryStatusS_type_infrastructure = 1, |
| 201 | dot11_batteryStatusS_type_independent = 2, |
| 202 | dot11_batteryStatusS_type_any = 3 |
| 203 | }; |
| 204 | |
| 205 | |
| 206 | struct DOT11_SSID { |
| 207 | ULONG uSSIDLength; |
| 208 | UCHAR ucSSID[DOT11_SSID_MAX_LENGTH]; |
| 209 | }; |
| 210 | |
| 211 | typedef UCHAR DOT11_MAC_ADDRESS[6]; |
| 212 | |
| 213 | struct WLAN_ASSOCIATION_ATTRIBUTES { |
| 214 | DOT11_SSID dot11Ssid; |
| 215 | DOT11_batteryStatusS_TYPE dot11batteryStatussType; |
| 216 | DOT11_MAC_ADDRESS dot11batteryStatussid; |
| 217 | DOT11_PHY_TYPE dot11PhyType; |
| 218 | ULONG uDot11PhyIndex; |
| 219 | ULONG wlanSignalQuality; |
| 220 | ULONG ulRxRate; |
| 221 | ULONG ulTxRate; |
| 222 | }; |
| 223 | |
| 224 | struct WLAN_SECURITY_ATTRIBUTES { |
| 225 | BOOL batteryStatusecurityEnabled; |
| 226 | BOOL bOneXEnabled; |
| 227 | DOT11_AUTH_ALGORITHM dot11AuthAlgorithm; |
| 228 | DOT11_CIPHER_ALGORITHM dot11CipherAlgorithm; |
| 229 | }; |
| 230 | |
| 231 | struct WLAN_CONNECTION_ATTRIBUTES { |
| 232 | WLAN_INTERFACE_STATE isState; |
| 233 | WLAN_CONNECTION_MODE wlanConnectionMode; |
| 234 | WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]; |
| 235 | WLAN_ASSOCIATION_ATTRIBUTES wlanAssociationAttributes; |
| 236 | WLAN_SECURITY_ATTRIBUTES wlanSecurityAttributes; |
| 237 | }; |
| 238 | |
| 239 | enum WLAN_NOTIFICATION_ACM { |
| 240 | wlan_notification_acm_start = 0, |
| 241 | wlan_notification_acm_autoconf_enabled, |
| 242 | wlan_notification_acm_autoconf_disabled, |
| 243 | wlan_notification_acm_background_scan_enabled, |
| 244 | wlan_notification_acm_background_scan_disabled, |
| 245 | wlan_notification_acm_batteryStatuss_type_change, |
| 246 | wlan_notification_acm_power_setting_change, |
| 247 | wlan_notification_acm_scan_complete, |
| 248 | wlan_notification_acm_scan_fail, |
| 249 | wlan_notification_acm_connection_start, |
| 250 | wlan_notification_acm_connection_complete, |
| 251 | wlan_notification_acm_connection_attempt_fail, |
| 252 | wlan_notification_acm_filter_list_change, |
| 253 | wlan_notification_acm_interface_arrival, |
| 254 | wlan_notification_acm_interface_removal, |
| 255 | wlan_notification_acm_profile_change, |
| 256 | wlan_notification_acm_profile_name_change, |
| 257 | wlan_notification_acm_profiles_exhausted, |
| 258 | wlan_notification_acm_network_not_available, |
| 259 | wlan_notification_acm_network_available, |
| 260 | wlan_notification_acm_disconnecting, |
| 261 | wlan_notification_acm_disconnected, |
| 262 | wlan_notification_acm_adhoc_network_state_change, |
| 263 | wlan_notification_acm_end |
| 264 | }; |
| 265 | |
| 266 | enum _WLAN_NOTIFICATION_MSM { |
| 267 | wlan_notification_msm_start = 0, |
| 268 | wlan_notification_msm_associating, |
| 269 | wlan_notification_msm_associated, |
| 270 | wlan_notification_msm_authenticating, |
| 271 | wlan_notification_msm_connected, |
| 272 | wlan_notification_msm_roaming_start, |
| 273 | wlan_notification_msm_roaming_end, |
| 274 | wlan_notification_msm_radio_state_change, |
| 275 | wlan_notification_msm_signal_quality_change, |
| 276 | wlan_notification_msm_disassociating, |
| 277 | wlan_notification_msm_disconnected, |
| 278 | wlan_notification_msm_peer_join, |
| 279 | wlan_notification_msm_peer_leave, |
| 280 | wlan_notification_msm_adapter_removal, |
| 281 | wlan_notification_msm_adapter_operation_mode_change, |
| 282 | wlan_notification_msm_end |
| 283 | }; |
| 284 | |
| 285 | typedef void (WINAPI *WLAN_NOTIFICATION_CALLBACK) (WLAN_NOTIFICATION_DATA *, PVOID); |
| 286 | |
| 287 | //#define _WCHAR_T_DEFINED |
| 288 | //#define _TIME64_T_DEFINED |
| 289 | |
| 290 | typedef struct _BLUETOOTH_FIND_RADIO_PARAMS { |
| 291 | DWORD dwSize; // IN sizeof this structure |
| 292 | } BLUETOOTH_FIND_RADIO_PARAMS; |
| 293 | |
| 294 | |
| 295 | typedef DWORD (WINAPI *WlanOpenHandleProto) |
| 296 | (DWORD dwClientVersion, PVOID pReserved, PDWORD pdwNegotiatedVersion, PHANDLE phClientHandle); |
| 297 | static WlanOpenHandleProto local_WlanOpenHandle = 0; |
| 298 | |
| 299 | typedef DWORD (WINAPI *WlanCloseHandleProto)(HANDLE hClientHandle, PVOID pReserved); |
| 300 | static WlanCloseHandleProto local_WlanCloseHandle = 0; |
| 301 | |
| 302 | #if !defined(Q_OS_WINCE) |
| 303 | typedef DWORD (WINAPI *WlanEnumInterfacesProto) |
| 304 | (HANDLE hClientHandle, PVOID pReserved, WLAN_INTERFACE_INFO_LIST **ppInterfaceList); |
| 305 | static WlanEnumInterfacesProto local_WlanEnumInterfaces = 0; |
| 306 | |
| 307 | typedef DWORD (WINAPI *WlanQueryInterfaceProto) |
| 308 | (HANDLE hClientHandle, const GUID *pInterfaceGuid, WLAN_INTF_OPCODE OpCode, PVOID pReserved, |
| 309 | PDWORD pdwDataSize, PVOID *ppData, WLAN_OPCODE_VALUE_TYPE *pWlanOpcodeValueType); |
| 310 | static WlanQueryInterfaceProto local_WlanQueryInterface = 0; |
| 311 | |
| 312 | typedef DWORD (WINAPI *WlanRegisterNotificationProto) |
| 313 | (HANDLE hClientHandle, DWORD dwNotifSource, BOOL bIgnoreDuplicate, |
| 314 | WLAN_NOTIFICATION_CALLBACK funcCallback, PVOID pCallbackContext, |
| 315 | PVOID pReserved, PDWORD pdwPrevNotifSource); |
| 316 | static WlanRegisterNotificationProto local_WlanRegisterNotification = 0; |
| 317 | #endif |
| 318 | |
| 319 | typedef VOID (WINAPI *WlanFreeMemoryProto)(PVOID pMemory); |
| 320 | static WlanFreeMemoryProto local_WlanFreeMemory = 0; |
| 321 | |
| 322 | typedef BOOL (WINAPI *BluetoothFindRadioClose)(HANDLE hFind); |
| 323 | static BluetoothFindRadioClose local_BluetoothFindRadioClose=0; |
| 324 | |
| 325 | typedef HANDLE (WINAPI *BluetoothFindFirstRadio)(const BLUETOOTH_FIND_RADIO_PARAMS * pbtfrp,HANDLE * phRadio); |
| 326 | static BluetoothFindFirstRadio local_BluetoothFindFirstRadio=0; |
| 327 | |
| 328 | |
| 329 | #if !defined( Q_CC_MINGW) && !defined( Q_OS_WINCE) |
| 330 | static WLAN_CONNECTION_ATTRIBUTES *getWifiConnectionAttributes() |
| 331 | { |
| 332 | if (!local_WlanOpenHandle) |
| 333 | return NULL; |
| 334 | DWORD version = 0; |
| 335 | HANDLE clientHandle = NULL; |
| 336 | DWORD result; |
| 337 | WLAN_CONNECTION_ATTRIBUTES *connAtts = NULL; |
| 338 | |
| 339 | WLAN_INTERFACE_INFO_LIST *interfacesInfoList = NULL; |
| 340 | result = local_WlanOpenHandle( 2, NULL, &version, &clientHandle ); |
| 341 | if ( result != ERROR_SUCCESS) { |
| 342 | local_WlanFreeMemory(connAtts); |
| 343 | local_WlanCloseHandle(clientHandle, 0); |
| 344 | return NULL; |
| 345 | } |
| 346 | result = local_WlanEnumInterfaces(clientHandle, NULL, &interfacesInfoList); |
| 347 | |
| 348 | if ( result != ERROR_SUCCESS) { |
| 349 | local_WlanCloseHandle(clientHandle, NULL); |
| 350 | local_WlanFreeMemory(connAtts); |
| 351 | return NULL; |
| 352 | } |
| 353 | |
| 354 | for ( uint i = 0; i < interfacesInfoList->dwNumberOfItems; i++ ) { |
| 355 | WLAN_INTERFACE_INFO *interfaceInfo = &interfacesInfoList->InterfaceInfo[i]; |
| 356 | GUID& guid = interfaceInfo->InterfaceGuid; |
| 357 | WLAN_INTERFACE_STATE wlanInterfaceState = interfaceInfo->isState; |
| 358 | |
| 359 | if ( wlanInterfaceState == wlan_interface_state_not_ready ) { |
| 360 | continue; |
| 361 | } |
| 362 | |
| 363 | ULONG size = 0; |
| 364 | result = local_WlanQueryInterface( clientHandle, &guid, wlan_intf_opcode_current_connection, NULL, &size, (PVOID*) &connAtts, NULL ); |
| 365 | if ( result != ERROR_SUCCESS ) { |
| 366 | continue; |
| 367 | } |
| 368 | } |
| 369 | local_WlanCloseHandle(clientHandle, NULL); |
| 370 | return connAtts; |
| 371 | } |
| 372 | #endif |
| 373 | |
| 374 | #if !defined( Q_CC_MINGW) && !defined( Q_OS_WINCE) |
| 375 | |
| 376 | void wlanNotificationCallback(WLAN_NOTIFICATION_DATA *pNotifyData, QNetworkInfoPrivate *netInfo) |
| 377 | { |
| 378 | // xp only supports disconnected and complete |
| 379 | switch (pNotifyData->NotificationCode) { |
| 380 | case wlan_notification_acm_scan_complete: |
| 381 | break; |
| 382 | case wlan_notification_acm_disconnecting: |
| 383 | break; |
| 384 | case wlan_notification_acm_disconnected: |
| 385 | case wlan_notification_acm_connection_attempt_fail: |
| 386 | case wlan_notification_acm_network_not_available: |
| 387 | netInfo->emitNetworkStatusChanged(QNetworkInfo::WlanMode, |
| 388 | QNetworkInfo::NoNetworkAvailable); |
| 389 | break; |
| 390 | case wlan_notification_acm_profile_name_change: |
| 391 | break; |
| 392 | case wlan_notification_msm_connected: |
| 393 | netInfo->emitNetworkStatusChanged(QNetworkInfo::WlanMode, |
| 394 | QNetworkInfo::HomeNetwork); |
| 395 | break; |
| 396 | case wlan_notification_acm_connection_start: |
| 397 | netInfo->emitNetworkStatusChanged(QNetworkInfo::WlanMode, |
| 398 | QNetworkInfo::Searching); |
| 399 | break; |
| 400 | case wlan_notification_msm_signal_quality_change: |
| 401 | netInfo->emitNetworkSignalStrengthChanged(QNetworkInfo::WlanMode, |
| 402 | reinterpret_cast<qint32>(pNotifyData->pData)); |
| 403 | break; |
| 404 | default: |
| 405 | break; |
| 406 | }; |
| 407 | } |
| 408 | #endif |
| 409 | |
| 410 | QT_BEGIN_NAMESPACE |
| 411 | |
| 412 | Q_GLOBAL_STATIC_WITH_ARGS(QMutex, dynamicLoadMutex, (QMutex::Recursive)); |
| 413 | |
| 414 | static void resolveLibrary() |
| 415 | { |
| 416 | #if !defined( Q_OS_WINCE) |
| 417 | static volatile bool triedResolve = false; |
| 418 | |
| 419 | if (!triedResolve) { |
| 420 | #ifndef QT_NO_THREAD |
| 421 | QMutexLocker locker(dynamicLoadMutex()); |
| 422 | #endif |
| 423 | |
| 424 | if (!triedResolve) { |
| 425 | local_WlanOpenHandle = (WlanOpenHandleProto) |
| 426 | QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanOpenHandle"); |
| 427 | local_WlanRegisterNotification = (WlanRegisterNotificationProto) |
| 428 | QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanRegisterNotification"); |
| 429 | local_WlanEnumInterfaces = (WlanEnumInterfacesProto) |
| 430 | QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanEnumInterfaces"); |
| 431 | local_WlanQueryInterface = (WlanQueryInterfaceProto) |
| 432 | QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanQueryInterface"); |
| 433 | local_WlanFreeMemory = (WlanFreeMemoryProto) |
| 434 | QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanFreeMemory"); |
| 435 | local_WlanCloseHandle = (WlanCloseHandleProto) |
| 436 | QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanCloseHandle"); |
| 437 | |
| 438 | |
| 439 | local_BluetoothFindFirstRadio = (BluetoothFindFirstRadio) |
| 440 | QLibrary::resolve(QLatin1String("Bthprops.cpl"), "BluetoothFindFirstRadio"); |
| 441 | local_BluetoothFindRadioClose = (BluetoothFindRadioClose) |
| 442 | QLibrary::resolve(QLatin1String("Bthprops.cpl"), "BluetoothFindRadioClose"); |
| 443 | |
| 444 | triedResolve = true; |
| 445 | } |
| 446 | } |
| 447 | #endif |
| 448 | } |
| 449 | |
| 450 | QNetworkInfoPrivate::QNetworkInfoPrivate(QNetworkInfo *parent) |
| 451 | : QObject(parent) |
| 452 | , q_ptr(parent) |
| 453 | { |
| 454 | wlanCallbackInitialized = false; |
| 455 | |
| 456 | resolveLibrary(); |
| 457 | |
| 458 | startWifiCallback(); |
| 459 | |
| 460 | timerMs = 5000; |
| 461 | switch (QSysInfo::WindowsVersion) { |
| 462 | case QSysInfo::WV_VISTA: |
| 463 | case QSysInfo::WV_WINDOWS7: |
| 464 | break; |
| 465 | default: |
| 466 | { |
| 467 | if (local_WlanOpenHandle) |
| 468 | QTimer::singleShot(timerMs, this, SLOT(networkStrengthTimeout())); |
| 469 | } |
| 470 | break; |
| 471 | }; |
| 472 | } |
| 473 | QNetworkInfoPrivate::~QNetworkInfoPrivate() |
| 474 | { |
| 475 | #if !defined( Q_OS_WINCE) |
| 476 | if (hWlan != 0) |
| 477 | local_WlanCloseHandle(hWlan, 0); |
| 478 | #endif |
| 479 | } |
| 480 | |
| 481 | QNetworkInfoPrivate *QNetworkInfoPrivate::instance() |
| 482 | { |
| 483 | resolveLibrary(); |
| 484 | static QNetworkInfoPrivate *self = 0; |
| 485 | if (!self) { |
| 486 | self = new QNetworkInfoPrivate; |
| 487 | } |
| 488 | return self; |
| 489 | } |
| 490 | |
| 491 | // Called by the feature detection code. |
| 492 | unsigned QNetworkInfoPrivate::wifiInterfaceCount() |
| 493 | { |
| 494 | #if !defined( Q_CC_MINGW) && !defined( Q_OS_WINCE) |
| 495 | resolveLibrary(); |
| 496 | if (!local_WlanOpenHandle) |
| 497 | return 0; |
| 498 | DWORD negotiatedVersion; |
| 499 | HANDLE handle; |
| 500 | if (ERROR_SUCCESS != local_WlanOpenHandle(1, NULL, &negotiatedVersion, &handle)) |
| 501 | return 0; |
| 502 | WLAN_INTERFACE_INFO_LIST *list; |
| 503 | unsigned result = 0; |
| 504 | if (ERROR_SUCCESS == local_WlanEnumInterfaces(handle, NULL, &list)) { |
| 505 | result = list->dwNumberOfItems; |
| 506 | local_WlanFreeMemory(list); |
| 507 | } |
| 508 | local_WlanCloseHandle(handle, NULL); |
| 509 | return result; |
| 510 | #else // !defined( Q_CC_MINGW) && !defined( Q_OS_WINCE) |
| 511 | return 0; |
| 512 | #endif |
| 513 | } |
| 514 | |
| 515 | void QNetworkInfoPrivate::startWifiCallback() |
| 516 | { |
| 517 | #if !defined( Q_CC_MINGW) && !defined( Q_OS_WINCE) |
| 518 | if (networkStatus(QNetworkInfo::WlanMode, 1) != QNetworkInfo::HomeNetwork |
| 519 | && wlanCallbackInitialized){ |
| 520 | return; |
| 521 | } |
| 522 | DWORD version = 0; |
| 523 | hWlan = NULL; |
| 524 | DWORD result; |
| 525 | if (local_WlanOpenHandle) |
| 526 | result = local_WlanOpenHandle(2, NULL, &version, &hWlan ); |
| 527 | if ( result != ERROR_SUCCESS ) { |
| 528 | qDebug() << "Error opening Wlanapi 2" << result ; |
| 529 | return ; |
| 530 | } |
| 531 | if ( result != ERROR_SUCCESS) { |
| 532 | qDebug() << "Error in enumerating wireless interfaces" << result; |
| 533 | return ; |
| 534 | } |
| 535 | if (ERROR_SUCCESS != local_WlanRegisterNotification(hWlan, |
| 536 | WLAN_NOTIFICATION_SOURCE_ALL, |
| 537 | true, |
| 538 | WLAN_NOTIFICATION_CALLBACK(wlanNotificationCallback), |
| 539 | this, 0, 0)) { |
| 540 | qDebug() << "failed"; |
| 541 | } else { |
| 542 | wlanCallbackInitialized = true; |
| 543 | } |
| 544 | #endif |
| 545 | } |
| 546 | |
| 547 | |
| 548 | void QNetworkInfoPrivate::emitNetworkStatusChanged(QNetworkInfo::NetworkMode mode, |
| 549 | QNetworkInfo::NetworkStatus status) |
| 550 | { |
| 551 | emit networkStatusChanged(mode, 1, status); |
| 552 | if (status == QNetworkInfo::NoNetworkAvailable |
| 553 | || status == QNetworkInfo::HomeNetwork) { |
| 554 | startWifiCallback(); |
| 555 | emit networkNameChanged(mode, 1, networkName(mode, 1)); |
| 556 | if (isDefaultMode(mode)) { |
| 557 | emit currentNetworkModeChanged(mode); |
| 558 | } |
| 559 | } else { |
| 560 | networkSignalStrengthChanged(mode, 1, 0); |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | void QNetworkInfoPrivate::emitNetworkSignalStrengthChanged(QNetworkInfo::NetworkMode mode,int /*strength*/) |
| 565 | { |
| 566 | switch (QSysInfo::WindowsVersion) { |
| 567 | case QSysInfo::WV_VISTA: |
| 568 | case QSysInfo::WV_WINDOWS7: |
| 569 | break; |
| 570 | default: |
| 571 | QTimer::singleShot(timerMs, this, SLOT(networkStrengthTimeout())); |
| 572 | break; |
| 573 | }; |
| 574 | networkSignalStrength(mode, 1); |
| 575 | } |
| 576 | |
| 577 | void QNetworkInfoPrivate::timerEvent(QTimerEvent *event) |
| 578 | { |
| 579 | if (event->timerId() == netStrengthTimer.timerId()) { |
| 580 | networkStrengthTimeout(); |
| 581 | } else { |
| 582 | QObject::timerEvent(event); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | |
| 587 | void QNetworkInfoPrivate::networkStrengthTimeout() |
| 588 | { |
| 589 | QList<QNetworkInfo::NetworkMode> modeList; |
| 590 | modeList << QNetworkInfo::GsmMode; |
| 591 | modeList << QNetworkInfo::CdmaMode; |
| 592 | modeList << QNetworkInfo::WcdmaMode; |
| 593 | modeList << QNetworkInfo::WlanMode; |
| 594 | modeList << QNetworkInfo::EthernetMode; |
| 595 | modeList << QNetworkInfo::BluetoothMode; |
| 596 | modeList << QNetworkInfo::WimaxMode; |
| 597 | |
| 598 | foreach (const QNetworkInfo::NetworkMode mode, modeList) { |
| 599 | networkSignalStrength(mode, 1); |
| 600 | } |
| 601 | switch (QSysInfo::WindowsVersion) { |
| 602 | case QSysInfo::WV_VISTA: |
| 603 | case QSysInfo::WV_WINDOWS7: |
| 604 | break; |
| 605 | default: |
| 606 | if (local_WlanOpenHandle) |
| 607 | QTimer::singleShot(timerMs, this, SLOT(networkStrengthTimeout())); |
| 608 | break; |
| 609 | }; |
| 610 | } |
| 611 | |
| 612 | void QNetworkInfoPrivate::networkStatusTimeout() |
| 613 | { |
| 614 | QList<QNetworkInfo::NetworkMode> modeList; |
| 615 | modeList << QNetworkInfo::GsmMode; |
| 616 | modeList << QNetworkInfo::CdmaMode; |
| 617 | modeList << QNetworkInfo::WcdmaMode; |
| 618 | modeList << QNetworkInfo::WlanMode; |
| 619 | modeList << QNetworkInfo::EthernetMode; |
| 620 | modeList << QNetworkInfo::BluetoothMode; |
| 621 | modeList << QNetworkInfo::WimaxMode; |
| 622 | |
| 623 | foreach (const QNetworkInfo::NetworkMode mode, modeList) { |
| 624 | networkStatus(mode,1); |
| 625 | } |
| 626 | |
| 627 | } |
| 628 | |
| 629 | int QNetworkInfoPrivate::networkInterfaceCount(QNetworkInfo::NetworkMode mode) |
| 630 | { |
| 631 | switch (mode) { |
| 632 | case QNetworkInfo::WlanMode: |
| 633 | case QNetworkInfo::EthernetMode: |
| 634 | case QNetworkInfo::BluetoothMode: |
| 635 | |
| 636 | // case QNetworkInfo::GsmMode: |
| 637 | // case QNetworkInfo::CdmaMode: |
| 638 | // case QNetworkInfo::WcdmaMode: |
| 639 | // case QNetworkInfo::WimaxMode: |
| 640 | // case QNetworkInfo::LteMode: |
| 641 | // case QNetworkInfo::TdscdmaMode: |
| 642 | default: |
| 643 | break; |
| 644 | }; |
| 645 | |
| 646 | return -1; |
| 647 | } |
| 648 | |
| 649 | int QNetworkInfoPrivate::networkSignalStrength(QNetworkInfo::NetworkMode mode, int netInterface) |
| 650 | { |
| 651 | Q_UNUSED(netInterface) |
| 652 | |
| 653 | switch (mode) { |
| 654 | case QNetworkInfo::WlanMode: |
| 655 | { |
| 656 | |
| 657 | #if !defined( Q_CC_MINGW) && !defined( Q_OS_WINCE) |
| 658 | if (local_WlanOpenHandle) { |
| 659 | |
| 660 | DWORD version = 0; |
| 661 | DWORD result; |
| 662 | |
| 663 | WLAN_INTERFACE_INFO_LIST *interfacesInfoList = NULL; |
| 664 | if (hWlan ==0) { |
| 665 | result = local_WlanOpenHandle( 2, NULL, &version, &hWlan ); |
| 666 | if ( result != ERROR_SUCCESS ) { |
| 667 | qDebug() << "Error opening Wlanapi 3" << result ; |
| 668 | local_WlanCloseHandle(hWlan, 0); |
| 669 | return 0; |
| 670 | } |
| 671 | } |
| 672 | result = local_WlanEnumInterfaces(hWlan, NULL, &interfacesInfoList); |
| 673 | |
| 674 | if ( result != ERROR_SUCCESS) { |
| 675 | qDebug() << "Error in enumerating wireless interfaces" << result; |
| 676 | local_WlanCloseHandle(hWlan, 0); |
| 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | for ( uint i = 0; i < interfacesInfoList->dwNumberOfItems; i++ ) { |
| 681 | WLAN_INTERFACE_INFO *interfaceInfo = &interfacesInfoList->InterfaceInfo[i]; |
| 682 | GUID& guid = interfaceInfo->InterfaceGuid; |
| 683 | WLAN_INTERFACE_STATE wlanInterfaceState = interfaceInfo->isState; |
| 684 | |
| 685 | if ( wlanInterfaceState == wlan_interface_state_not_ready ) { |
| 686 | qDebug() << "Interface not ready"; |
| 687 | continue; |
| 688 | } |
| 689 | |
| 690 | ULONG size = 0; |
| 691 | WLAN_CONNECTION_ATTRIBUTES *connAtts = NULL; |
| 692 | result = local_WlanQueryInterface( hWlan, &guid, |
| 693 | wlan_intf_opcode_current_connection, NULL, &size, (PVOID*) &connAtts, NULL ); |
| 694 | |
| 695 | if ( result != ERROR_SUCCESS ) { |
| 696 | continue; |
| 697 | } |
| 698 | ulong sig = connAtts->wlanAssociationAttributes.wlanSignalQuality; |
| 699 | local_WlanFreeMemory(connAtts); |
| 700 | local_WlanFreeMemory(interfacesInfoList); |
| 701 | |
| 702 | if (sig != wifiStrength) { |
| 703 | emit networkSignalStrengthChanged(mode,1, sig); |
| 704 | wifiStrength = sig; |
| 705 | } |
| 706 | return sig; |
| 707 | } |
| 708 | } |
| 709 | #endif |
| 710 | } |
| 711 | break; |
| 712 | case QNetworkInfo::EthernetMode: |
| 713 | { |
| 714 | #if !defined( Q_CC_MINGW) && !defined( Q_OS_WINCE) |
| 715 | WMIHelper *wHelper; |
| 716 | wHelper = new WMIHelper(this); |
| 717 | wHelper->setWmiNamespace(QLatin1String("root/cimv2")); |
| 718 | wHelper->setClassName(QLatin1String("Win32_NetworkAdapter")); |
| 719 | wHelper->setClassProperty(QStringList() << QLatin1String("NetConnectionStatus")); |
| 720 | QString cond = QLatin1String("WHERE MACAddress = '%1'"); |
| 721 | cond = cond.arg( interfaceForMode(mode, 1).hardwareAddress()); |
| 722 | wHelper->setConditional(cond); |
| 723 | QVariant v = wHelper->getWMIData(); |
| 724 | quint32 strength = v.toUInt(); |
| 725 | quint32 tmpStrength; |
| 726 | |
| 727 | if ( strength == 2 |
| 728 | || strength == 9) { |
| 729 | tmpStrength = 100; |
| 730 | } else { |
| 731 | tmpStrength = 0; |
| 732 | } |
| 733 | |
| 734 | if (tmpStrength != ethStrength) { |
| 735 | ethStrength = tmpStrength; |
| 736 | emit networkSignalStrengthChanged(mode, 1, ethStrength); |
| 737 | } |
| 738 | |
| 739 | return ethStrength; |
| 740 | #endif |
| 741 | } |
| 742 | break; |
| 743 | case QNetworkInfo::BluetoothMode: |
| 744 | |
| 745 | // case QNetworkInfo::GsmMode: |
| 746 | // case QNetworkInfo::CdmaMode: |
| 747 | // case QNetworkInfo::WcdmaMode: |
| 748 | // case QNetworkInfo::WimaxMode: |
| 749 | // case QNetworkInfo::LteMode: |
| 750 | // case QNetworkInfo::TdscdmaMode: |
| 751 | default: |
| 752 | break; |
| 753 | }; |
| 754 | |
| 755 | return -1; |
| 756 | } |
| 757 | |
| 758 | QNetworkInfo::CellDataTechnology QNetworkInfoPrivate::currentCellDataTechnology(int netInterface) |
| 759 | { |
| 760 | Q_UNUSED(netInterface) |
| 761 | return QNetworkInfo::UnknownDataTechnology; |
| 762 | } |
| 763 | |
| 764 | bool QNetworkInfoPrivate::isDefaultMode(QNetworkInfo::NetworkMode mode) |
| 765 | { |
| 766 | bool isDefaultGateway = false; |
| 767 | QNetworkInterface netInterface = interfaceForMode(mode,1); |
| 768 | QString deviceNameReg; |
| 769 | |
| 770 | switch (QSysInfo::WindowsVersion) { |
| 771 | case QSysInfo::WV_VISTA: |
| 772 | case QSysInfo::WV_WINDOWS7: |
| 773 | deviceNameReg = QLatin1String("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%1\\"); |
| 774 | deviceNameReg = deviceNameReg.arg(netInterface.name()); |
| 775 | break; |
| 776 | default: |
| 777 | deviceNameReg = QLatin1String("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\%1\\Parameters\\Tcpip"); |
| 778 | deviceNameReg = deviceNameReg.arg(netInterface.name()); |
| 779 | break; |
| 780 | }; |
| 781 | |
| 782 | QSettings deviceSettings(deviceNameReg, QSettings::NativeFormat); |
| 783 | QString dhcpGw = QLatin1String("DhcpDefaultGateway"); |
| 784 | QString gw = QLatin1String("DefaultGateway"); |
| 785 | if (!deviceSettings.value(dhcpGw).toStringList().isEmpty() |
| 786 | || !deviceSettings.value(gw).toStringList().isEmpty()) { |
| 787 | isDefaultGateway = true; |
| 788 | } |
| 789 | return isDefaultGateway; |
| 790 | } |
| 791 | QNetworkInfo::NetworkMode QNetworkInfoPrivate::currentNetworkMode() |
| 792 | { |
| 793 | QList <QNetworkInfo::NetworkMode> modeList; |
| 794 | modeList << QNetworkInfo::EthernetMode |
| 795 | << QNetworkInfo::WlanMode |
| 796 | << QNetworkInfo::BluetoothMode |
| 797 | << QNetworkInfo::WcdmaMode |
| 798 | << QNetworkInfo::CdmaMode |
| 799 | << QNetworkInfo::GsmMode |
| 800 | << QNetworkInfo::WimaxMode; |
| 801 | |
| 802 | for (int i = 0; i < modeList.size(); ++i) { |
| 803 | if ( isDefaultMode(modeList.at(i))) |
| 804 | return modeList.at(i); |
| 805 | } |
| 806 | return QNetworkInfo::UnknownMode; |
| 807 | } |
| 808 | |
| 809 | QNetworkInfo::NetworkStatus QNetworkInfoPrivate::networkStatus(QNetworkInfo::NetworkMode mode, int netInterface) |
| 810 | { |
| 811 | Q_UNUSED(netInterface) |
| 812 | |
| 813 | switch (mode) { |
| 814 | case QNetworkInfo::WlanMode: |
| 815 | { |
| 816 | #if !defined( Q_CC_MINGW) && !defined( Q_OS_WINCE) |
| 817 | if (local_WlanOpenHandle) { |
| 818 | WLAN_CONNECTION_ATTRIBUTES *connAtts = getWifiConnectionAttributes(); |
| 819 | if (connAtts != NULL) { |
| 820 | if (connAtts->isState == wlan_interface_state_authenticating) { |
| 821 | local_WlanFreeMemory(connAtts); |
| 822 | return QNetworkInfo::Searching; |
| 823 | } |
| 824 | if (connAtts->isState == wlan_interface_state_connected) { |
| 825 | local_WlanFreeMemory(connAtts); |
| 826 | return QNetworkInfo::HomeNetwork; |
| 827 | } |
| 828 | } |
| 829 | local_WlanFreeMemory(connAtts); |
| 830 | } |
| 831 | #endif |
| 832 | } |
| 833 | break; |
| 834 | case QNetworkInfo::EthernetMode: |
| 835 | { |
| 836 | #if !defined( Q_CC_MINGW) && !defined( Q_OS_WINCE) |
| 837 | WMIHelper *wHelper; |
| 838 | wHelper = new WMIHelper(this); |
| 839 | wHelper->setWmiNamespace(QLatin1String("root/cimv2")); |
| 840 | wHelper->setClassName(QLatin1String("Win32_NetworkAdapter")); |
| 841 | wHelper->setClassProperty(QStringList() << QLatin1String("NetConnectionStatus")); |
| 842 | QString cond = QLatin1String("WHERE MACAddress = '%1'"); |
| 843 | cond = cond.arg(interfaceForMode(mode,1).hardwareAddress()); |
| 844 | wHelper->setConditional(cond); |
| 845 | QVariant v = wHelper->getWMIData(); |
| 846 | if (v.toUInt() == 2) { |
| 847 | return QNetworkInfo::HomeNetwork; |
| 848 | } |
| 849 | #endif |
| 850 | } |
| 851 | break; |
| 852 | case QNetworkInfo::BluetoothMode: |
| 853 | { |
| 854 | #if !defined( Q_CC_MINGW) && !defined( Q_OS_WINCE) |
| 855 | WMIHelper *wHelper; |
| 856 | wHelper = new WMIHelper(this); |
| 857 | wHelper->setWmiNamespace(QLatin1String("root/cimv2")); |
| 858 | wHelper->setClassName(QLatin1String("Win32_NetworkAdapter")); |
| 859 | wHelper->setClassProperty(QStringList() << QLatin1String("NetConnectionStatus")); |
| 860 | QString cond = QLatin1String("WHERE MACAddress = '%1'"); |
| 861 | cond = cond.arg(interfaceForMode(mode, 1).hardwareAddress()); |
| 862 | wHelper->setConditional(cond); |
| 863 | QVariant v = wHelper->getWMIData(); |
| 864 | if (v.toUInt() == 2) { |
| 865 | return QNetworkInfo::HomeNetwork; |
| 866 | } |
| 867 | #endif |
| 868 | } |
| 869 | break; |
| 870 | // case QNetworkInfo::GsmMode: |
| 871 | // case QNetworkInfo::CdmaMode: |
| 872 | // case QNetworkInfo::WcdmaMode: |
| 873 | // case QNetworkInfo::WimaxMode: |
| 874 | // case QNetworkInfo::LteMode: |
| 875 | // case QNetworkInfo::TdscdmaMode: |
| 876 | break; |
| 877 | |
| 878 | default: |
| 879 | break; |
| 880 | }; |
| 881 | |
| 882 | return QNetworkInfo::UnknownStatus; |
| 883 | } |
| 884 | |
| 885 | #ifndef QT_NO_NETWORKINTERFACE |
| 886 | QNetworkInterface QNetworkInfoPrivate::interfaceForMode(QNetworkInfo::NetworkMode mode, int netInterface) |
| 887 | { |
| 888 | Q_UNUSED(netInterface) |
| 889 | QList<QNetworkInterface> interfaceList; |
| 890 | interfaceList = QNetworkInterface::allInterfaces(); |
| 891 | QListIterator<QNetworkInterface> i(interfaceList); |
| 892 | while (i.hasNext()) { |
| 893 | QNetworkInterface netInterface = i.next(); |
| 894 | if (!netInterface.isValid() |
| 895 | || (netInterface.flags() & QNetworkInterface::IsLoopBack) |
| 896 | || !(netInterface.flags() & QNetworkInterface::IsUp) |
| 897 | || !(netInterface.flags() & QNetworkInterface::IsRunning) |
| 898 | || netInterface.addressEntries().isEmpty()) { |
| 899 | continue; |
| 900 | } |
| 901 | |
| 902 | #if !defined( Q_CC_MINGW) && !defined( Q_OS_WINCE) |
| 903 | |
| 904 | if (local_WlanOpenHandle) { |
| 905 | unsigned long oid; |
| 906 | DWORD bytesWritten; |
| 907 | |
| 908 | NDIS_MEDIUM medium ; |
| 909 | NDIS_PHYSICAL_MEDIUM physicalMedium = NdisPhysicalMediumUnspecified; |
| 910 | QString filestr = QLatin1String("\\\\.\\%1"); |
| 911 | HANDLE handle = CreateFile((TCHAR *)filestr.arg(netInterface.name()).utf16(), 0, |
| 912 | FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); |
| 913 | |
| 914 | if (handle == INVALID_HANDLE_VALUE) { |
| 915 | continue; |
| 916 | } |
| 917 | |
| 918 | oid = OID_GEN_MEDIA_SUPPORTED; |
| 919 | bytesWritten; |
| 920 | bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), |
| 921 | &medium, sizeof(medium), &bytesWritten, 0); |
| 922 | if (!result) { |
| 923 | CloseHandle(handle); |
| 924 | qDebug() << "DeviceIo result is false"; |
| 925 | return QNetworkInterface(); |
| 926 | continue; |
| 927 | } |
| 928 | |
| 929 | oid = OID_GEN_PHYSICAL_MEDIUM; |
| 930 | bytesWritten = 0; |
| 931 | result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), |
| 932 | &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); |
| 933 | |
| 934 | if (!result) { |
| 935 | CloseHandle(handle); |
| 936 | if (medium == NdisMedium802_3 && mode == QNetworkInfo::EthernetMode) { |
| 937 | return netInterface; |
| 938 | } else { |
| 939 | continue; |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | CloseHandle(handle); |
| 944 | if (physicalMedium == NdisMediumWirelessWan && mode == QNetworkInfo::WlanMode) { |
| 945 | //some wifi devices show up here |
| 946 | return netInterface; |
| 947 | } |
| 948 | |
| 949 | if (medium == NdisMedium802_3) { |
| 950 | switch (physicalMedium) { |
| 951 | case NdisPhysicalMediumUnspecified: |
| 952 | { |
| 953 | if (mode == QNetworkInfo::EthernetMode) { |
| 954 | return netInterface; |
| 955 | } |
| 956 | } |
| 957 | break; |
| 958 | case NdisPhysicalMediumWirelessLan: |
| 959 | { |
| 960 | if (mode == QNetworkInfo::WlanMode) { |
| 961 | return netInterface; |
| 962 | } |
| 963 | } |
| 964 | break; |
| 965 | case NdisPhysicalMediumBluetooth: |
| 966 | { |
| 967 | if (mode == QNetworkInfo::BluetoothMode) { |
| 968 | return netInterface; |
| 969 | } |
| 970 | } |
| 971 | break; |
| 972 | #ifdef NDIS_SUPPORT_NDIS6 |
| 973 | case NdisPhysicalMediumWiMax: |
| 974 | { |
| 975 | if (mode == QNetworkInfo::WimaxMode) { |
| 976 | return netInterface; |
| 977 | } |
| 978 | } |
| 979 | break; |
| 980 | #endif |
| 981 | }; |
| 982 | } |
| 983 | } |
| 984 | #endif |
| 985 | } |
| 986 | // Q_UNUSED(interface) |
| 987 | |
| 988 | // switch (mode) { |
| 989 | // case QNetworkInfo::WlanMode: |
| 990 | // case QNetworkInfo::EthernetMode: |
| 991 | |
| 992 | //// case QNetworkInfo::BluetoothMode: |
| 993 | //// case QNetworkInfo::GsmMode: |
| 994 | //// case QNetworkInfo::CdmaMode: |
| 995 | //// case QNetworkInfo::WcdmaMode: |
| 996 | //// case QNetworkInfo::WimaxMode: |
| 997 | //// case QNetworkInfo::LteMode: |
| 998 | //// case QNetworkInfo::TdscdmaMode: |
| 999 | // default: |
| 1000 | // break; |
| 1001 | // }; |
| 1002 | |
| 1003 | return QNetworkInterface(); |
| 1004 | } |
| 1005 | #endif // QT_NO_NETWORKINTERFACE |
| 1006 | |
| 1007 | QString QNetworkInfoPrivate::cellId(int netInterface) |
| 1008 | { |
| 1009 | Q_UNUSED(netInterface) |
| 1010 | return QString(); |
| 1011 | } |
| 1012 | |
| 1013 | QString QNetworkInfoPrivate::currentMobileCountryCode(int netInterface) |
| 1014 | { |
| 1015 | Q_UNUSED(netInterface) |
| 1016 | return QString(); |
| 1017 | } |
| 1018 | |
| 1019 | QString QNetworkInfoPrivate::currentMobileNetworkCode(int netInterface) |
| 1020 | { |
| 1021 | Q_UNUSED(netInterface) |
| 1022 | return QString(); |
| 1023 | } |
| 1024 | |
| 1025 | QString QNetworkInfoPrivate::homeMobileCountryCode(int netInterface) |
| 1026 | { |
| 1027 | Q_UNUSED(netInterface) |
| 1028 | return QString(); |
| 1029 | } |
| 1030 | |
| 1031 | QString QNetworkInfoPrivate::homeMobileNetworkCode(int netInterface) |
| 1032 | { |
| 1033 | Q_UNUSED(netInterface) |
| 1034 | return QString(); |
| 1035 | } |
| 1036 | |
| 1037 | QString QNetworkInfoPrivate::imsi(int netInterface) |
| 1038 | { |
| 1039 | Q_UNUSED(netInterface) |
| 1040 | return QString(); |
| 1041 | } |
| 1042 | |
| 1043 | QString QNetworkInfoPrivate::locationAreaCode(int netInterface) |
| 1044 | { |
| 1045 | Q_UNUSED(netInterface) |
| 1046 | return QString(); |
| 1047 | } |
| 1048 | |
| 1049 | QString QNetworkInfoPrivate::macAddress(QNetworkInfo::NetworkMode mode, int netInterface) |
| 1050 | { |
| 1051 | Q_UNUSED(netInterface) |
| 1052 | QString mac = interfaceForMode(mode,1).hardwareAddress(); |
| 1053 | return mac; |
| 1054 | |
| 1055 | // switch (mode) { |
| 1056 | // case QNetworkInfo::WlanMode: |
| 1057 | // case QNetworkInfo::EthernetMode: |
| 1058 | // case QNetworkInfo::BluetoothMode: |
| 1059 | |
| 1060 | //// case QNetworkInfo::GsmMode: |
| 1061 | //// case QNetworkInfo::CdmaMode: |
| 1062 | //// case QNetworkInfo::WcdmaMode: |
| 1063 | //// case QNetworkInfo::WimaxMode: |
| 1064 | //// case QNetworkInfo::LteMode: |
| 1065 | //// case QNetworkInfo::TdscdmaMode: |
| 1066 | // default: |
| 1067 | // break; |
| 1068 | // }; |
| 1069 | |
| 1070 | return QString(); |
| 1071 | } |
| 1072 | |
| 1073 | QString QNetworkInfoPrivate::networkName(QNetworkInfo::NetworkMode mode, int netInterface) |
| 1074 | { |
| 1075 | Q_UNUSED(netInterface) |
| 1076 | QString netname; |
| 1077 | |
| 1078 | switch (mode) { |
| 1079 | case QNetworkInfo::WlanMode: |
| 1080 | { |
| 1081 | #if !defined( Q_CC_MINGW) && !defined( Q_OS_WINCE) |
| 1082 | if (local_WlanOpenHandle) { |
| 1083 | WLAN_CONNECTION_ATTRIBUTES *connAtts = getWifiConnectionAttributes(); |
| 1084 | if (connAtts != NULL) { |
| 1085 | DOT11_SSID ssid; |
| 1086 | ssid = connAtts->wlanAssociationAttributes.dot11Ssid; |
| 1087 | for (uint i = 0; i < ssid.uSSIDLength; i++) { |
| 1088 | QLatin1Char temp(ssid.ucSSID[i]); |
| 1089 | netname += temp; |
| 1090 | } |
| 1091 | } |
| 1092 | local_WlanFreeMemory(connAtts); |
| 1093 | } |
| 1094 | #endif |
| 1095 | } |
| 1096 | break; |
| 1097 | case QNetworkInfo::EthernetMode: |
| 1098 | { |
| 1099 | #if !defined( Q_CC_MINGW) && !defined( Q_OS_WINCE) |
| 1100 | WMIHelper *wHelper; |
| 1101 | wHelper = new WMIHelper(this); |
| 1102 | wHelper->setWmiNamespace(QLatin1String("root/cimv2")); |
| 1103 | wHelper->setClassName(QLatin1String("Win32_ComputerSystem")); |
| 1104 | wHelper->setClassProperty(QStringList() << QLatin1String("Domain")); |
| 1105 | |
| 1106 | QVariant v = wHelper->getWMIData(); |
| 1107 | netname = v.toString(); |
| 1108 | #endif |
| 1109 | } |
| 1110 | break; |
| 1111 | case QNetworkInfo::BluetoothMode: |
| 1112 | |
| 1113 | // case QNetworkInfo::GsmMode: |
| 1114 | // case QNetworkInfo::CdmaMode: |
| 1115 | // case QNetworkInfo::WcdmaMode: |
| 1116 | // case QNetworkInfo::WimaxMode: |
| 1117 | // case QNetworkInfo::LteMode: |
| 1118 | // case QNetworkInfo::TdscdmaMode: |
| 1119 | default: |
| 1120 | break; |
| 1121 | }; |
| 1122 | |
| 1123 | return netname; |
| 1124 | } |
| 1125 | |
| 1126 | void QNetworkInfoPrivate::connectNotify(const QMetaMethod &signal) |
| 1127 | { |
| 1128 | Q_UNUSED(signal) |
| 1129 | } |
| 1130 | |
| 1131 | void QNetworkInfoPrivate::disconnectNotify(const QMetaMethod &signal) |
| 1132 | { |
| 1133 | Q_UNUSED(signal) |
| 1134 | } |
| 1135 | |
| 1136 | QT_END_NAMESPACE |