├── Makefile ├── Makefile.win32 ├── example_list_aps.cpp ├── library ├── debug.h ├── wlanapi.cpp ├── wlanapi.h ├── wlanapi_exception.cpp ├── wlanapi_exception.h ├── wlanapi_windows_ndisuio.h ├── wlanapi_windows_wlan.h └── wlanapi_windows_wzc.h └── license.txt /Makefile: -------------------------------------------------------------------------------- 1 | COMPILER := g++ 2 | EXECUTABLE := example_list_aps 3 | LIBS := dbus-glib-1 4 | INCLUDES := /usr/include/dbus-1.0 /usr/lib/dbus-1.0/include /usr/include/glib-2.0 /usr/lib/glib-2.0/include 5 | CFLAGS := -O3 -DDBUS 6 | 7 | SOURCE := example_list_aps.cpp library/wlanapi.cpp library/wlanapi_exception.cpp 8 | 9 | all : $(EXECUTABLE) 10 | 11 | build : $(EXECUTABLE) 12 | 13 | clean : 14 | rm -f $(EXECUTABLE) 15 | 16 | $(EXECUTABLE) : 17 | $(COMPILER) $(CFLAGS) $(SOURCE) -o $(EXECUTABLE) $(addprefix -l,$(LIBS)) $(addprefix -I,$(INCLUDES)) 18 | strip $(EXECUTABLE) 19 | -------------------------------------------------------------------------------- /Makefile.win32: -------------------------------------------------------------------------------- 1 | COMPILER := g++ 2 | EXECUTABLE := example_list_aps.exe 3 | LIBS := 4 | CFLAGS := -O3 5 | 6 | SOURCE := example_list_aps.cpp library/wlanapi.cpp library/wlanapi_exception.cpp 7 | 8 | all : $(EXECUTABLE) 9 | 10 | build : $(EXECUTABLE) 11 | 12 | clean : 13 | rm -f $(EXECUTABLE) 14 | 15 | $(EXECUTABLE) : 16 | $(COMPILER) $(CFLAGS) $(SOURCE) -o $(EXECUTABLE) $(addprefix -l,$(LIBS)) 17 | strip $(EXECUTABLE) 18 | -------------------------------------------------------------------------------- /example_list_aps.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * wlanapi library 0.4 3 | * 4 | * Copyright (C) 2008, 2009 Moritz Mertinkat 5 | * All rights reserved. 6 | * 7 | * wlanapi library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wlanapi library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details.* 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with wlanapi library. If not, see . 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "library/wlanapi.h" 26 | 27 | using namespace std; 28 | 29 | int main() { 30 | 31 | wlanapi *wi = new wlanapi(); 32 | 33 | try { 34 | 35 | const ADAPTER_LIST &adapter_list = wi->get_adapter_list(); 36 | const AP_LIST &ap_list = wi->get_ap_list(NULL); 37 | 38 | for (AP_LIST::const_iterator it = ap_list.begin(); it < ap_list.end(); ++it) { 39 | 40 | printf("ap name: %s\n", it->name); 41 | printf("ap mac address: %02x-%02x-%02x-%02x-%02x-%02x\n", it->mac_address.u[0], 42 | it->mac_address.u[1], 43 | it->mac_address.u[2], 44 | it->mac_address.u[3], 45 | it->mac_address.u[4], 46 | it->mac_address.u[5]); 47 | printf("ap rssi: %i\n", it->rssi); 48 | printf("\n"); 49 | 50 | } 51 | 52 | } catch (std::exception &e) { 53 | printf("[X] %s\n", e.what()); 54 | } 55 | 56 | printf("Press enter to exit."); 57 | scanf("..."); 58 | 59 | delete wi; 60 | 61 | } 62 | -------------------------------------------------------------------------------- /library/debug.h: -------------------------------------------------------------------------------- 1 | /** 2 | * wlanapi library 0.4 3 | * 4 | * Copyright (C) 2008, 2009 Moritz Mertinkat 5 | * All rights reserved. 6 | * 7 | * wlanapi library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wlanapi library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details.* 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with wlanapi library. If not, see . 19 | */ 20 | 21 | #ifndef __DEBUG_H_ 22 | #define __DEBUG_H_ 23 | 24 | #include 25 | 26 | #ifdef DEBUG 27 | #define DEBUG_PRINT(...) printf(__VA_ARGS__); 28 | #define DEBUG_WPRINT(...) wprintf(__VA_ARGS__); 29 | #define DEBUG_ENTER(class_name) if (strlen(#class_name) > 0) printf("[>] %s::%s()\n", #class_name, __FUNCTION__); else printf("[>] %s()\n", __FUNCTION__); 30 | #define DEBUG_LEAVE(class_name) if (strlen(#class_name) > 0) printf("[<] %s::%s()\n\n", #class_name, __FUNCTION__); else printf("[<] %s()\n\n", __FUNCTION__); 31 | #define DEBUG_ENTER_PRETTY() printf("[>] %s\n", __PRETTY_FUNCTION__); 32 | #define DEBUG_LEAVE_PRETTY() printf("[<] %s\n\n", __PRETTY_FUNCTION__); 33 | #else 34 | #define DEBUG_PRINT(...) 35 | #define DEBUG_WPRINT(...) 36 | #define DEBUG_ENTER(class_name) 37 | #define DEBUG_LEAVE(class_name) 38 | #define DEBUG_ENTER_PRETTY() 39 | #define DEBUG_LEAVE_PRETTY() 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /library/wlanapi.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * wlanapi library 0.4 3 | * 4 | * Copyright (C) 2008, 2009 Moritz Mertinkat 5 | * All rights reserved. 6 | * 7 | * wlanapi library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wlanapi library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details.* 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with wlanapi library. If not, see . 19 | */ 20 | 21 | #include "wlanapi.h" 22 | 23 | /** 24 | * Constructor 25 | */ 26 | wlanapi::wlanapi() { 27 | 28 | get_adapter_list_func = NULL; 29 | get_ap_list_func = NULL; 30 | 31 | #ifdef WIN32 32 | 33 | // Wireless Zero Configuration API (WZC API) 34 | wzc_library = NULL; 35 | WZCEnumInterfaces = NULL; 36 | WZCQueryInterface = NULL; 37 | WZCRefreshInterface = NULL; 38 | 39 | // Native Wifi API (WLAN API) 40 | wlan_library = NULL; 41 | wlan_handle = NULL; 42 | WlanOpenHandle = NULL; 43 | WlanEnumInterfaces = NULL; 44 | WlanGetNetworkBssList = NULL; 45 | WlanCloseHandle = NULL; 46 | WlanFreeMemory = NULL; 47 | 48 | WlanGetAvailableNetworkList = NULL; 49 | 50 | #else 51 | 52 | #ifdef DBUS 53 | dbus_connection = NULL; 54 | _dbus_nm_proxy = NULL; 55 | #endif 56 | 57 | #endif 58 | 59 | } 60 | 61 | /** 62 | * Destructor 63 | */ 64 | wlanapi::~wlanapi() { 65 | 66 | DEBUG_ENTER(wlanapi) 67 | 68 | #ifdef WIN32 69 | 70 | if (wlan_handle != NULL) { 71 | WlanCloseHandle(wlan_handle, NULL); 72 | wlan_handle = NULL; 73 | DEBUG_PRINT(" Closed WLAN API handle\n"); 74 | } 75 | 76 | #else 77 | 78 | #ifdef DBUS 79 | _dbus_shutdown(); 80 | #endif 81 | 82 | #endif 83 | 84 | DEBUG_LEAVE(wlanapi) 85 | 86 | } 87 | 88 | /** 89 | * Returns list of adapters 90 | * 91 | * @return ADAPTER_LIST& 92 | * @throws wlanapi_exception 93 | */ 94 | const ADAPTER_LIST& wlanapi::get_adapter_list() { 95 | 96 | DEBUG_ENTER(wlanapi) 97 | 98 | if (get_adapter_list_func == NULL) { 99 | 100 | #ifdef WIN32 101 | 102 | try { 103 | _wzc_get_adapter_list(); 104 | } catch (std::exception &e){ 105 | 106 | DEBUG_PRINT("WZC failed: %s\n", e.what()); 107 | 108 | try { 109 | _wlan_get_adapter_list(); 110 | } catch (std::exception &e){ 111 | 112 | DEBUG_PRINT("WLAN failed: %s\n", e.what()); 113 | 114 | try { 115 | _ndis_get_adapter_list(); 116 | } catch (std::exception &e){ 117 | DEBUG_PRINT("NDIS failed: %s\n", e.what()); 118 | throw wlanapi_exception("Unable to find a valid method for retrieving a list of network adapters"); 119 | } 120 | 121 | } 122 | 123 | } 124 | 125 | #else 126 | 127 | #ifdef DBUS 128 | 129 | try { 130 | _dbus_get_adapter_list(); 131 | } catch (std::exception &e) { 132 | DEBUG_PRINT("DBUS failed: %s\n", e.what()); 133 | throw wlanapi_exception("Unable to find a valid method for retrieving a list of network adapters"); 134 | } 135 | #endif // DBUS 136 | 137 | #endif 138 | 139 | } else { 140 | (this->*get_adapter_list_func)(); 141 | } 142 | 143 | DEBUG_LEAVE(wlanapi); 144 | 145 | return adapter_list; 146 | 147 | } 148 | 149 | /** 150 | * Returns list of access points for a given adapter. If no adapter is 151 | * given all adapters are queried for their access points. 152 | * 153 | * Please note that the list may contain multiple references to one 154 | * access point. 155 | * 156 | * @param ADAPTER_NAME *adapter_name [OPTIONAL] 157 | * @return AP_LIST& 158 | * @throws wlanapi_exception 159 | */ 160 | const AP_LIST& wlanapi::get_ap_list(ADAPTER_NAME *adapter_name) { 161 | 162 | DEBUG_ENTER(wlanapi); 163 | 164 | if (get_ap_list_func == NULL) { 165 | throw wlanapi_exception("You have to call get_adapter_list() first!"); 166 | } 167 | 168 | #ifdef WIN32 169 | if (adapter_name == NULL || (adapter_name != NULL && wcslen(adapter_name) == 0)) { 170 | #else 171 | if (adapter_name == NULL || (adapter_name != NULL && strlen(adapter_name) == 0)) { 172 | #endif 173 | 174 | for (ADAPTER_LIST::iterator it = adapter_list.begin(); it < adapter_list.end(); ++it) { 175 | DEBUG_PRINT(" Handling adapter %s...\n", (char *)it->name); 176 | (this->*get_ap_list_func)(it->name); 177 | } 178 | 179 | } else { 180 | (this->*get_ap_list_func)(adapter_name); 181 | } 182 | 183 | DEBUG_LEAVE(wlanapi); 184 | 185 | return ap_list; 186 | 187 | } 188 | 189 | #ifdef WIN32 190 | 191 | /** 192 | * Fetches list of adapters using NDIS User-Mode I/O driver (NDISUIO 5.1) 193 | * http://msdn.microsoft.com/en-us/library/ms892537.aspx 194 | * 195 | * Works with Windows XP >= SP1 196 | * 197 | * @return void 198 | * @throws wlanapi_exception 199 | */ 200 | void wlanapi::_ndis_get_adapter_list() { 201 | 202 | DWORD dwBytes; 203 | BOOL result; 204 | HANDLE ndisuio; 205 | ADAPTER_INFO adapter_info; 206 | 207 | DEBUG_ENTER(wlanapi) 208 | 209 | ndisuio = CreateFile( 210 | "\\\\.\\\\Ndisuio", 211 | GENERIC_READ | GENERIC_WRITE, 0, NULL, 212 | OPEN_EXISTING, 213 | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 214 | INVALID_HANDLE_VALUE 215 | ); 216 | 217 | if (ndisuio == INVALID_HANDLE_VALUE) { 218 | throw wlanapi_exception("NDIS: Failed to open connection to NDISUIO with error code: %d", (int)GetLastError()); 219 | } 220 | 221 | result = DeviceIoControl( 222 | ndisuio, 223 | IOCTL_NDISUIO_BIND_WAIT, 224 | NULL, 225 | 0, 226 | NULL, 227 | 0, 228 | &dwBytes, 229 | NULL 230 | ); 231 | 232 | if (!result) { 233 | throw wlanapi_exception("NDIS: IOCTL_NDISUIO_BIND_WAIT failed with error code: %d", (int)GetLastError()); 234 | } 235 | 236 | PNDISUIO_QUERY_BINDING pQueryBinding = (PNDISUIO_QUERY_BINDING)malloc(sizeof(NDISUIO_QUERY_BINDING) + 1024); 237 | //boost::scoped_array pQueryBinding((PNDISUIO_QUERY_BINDING)new char[sizeof(NDISUIO_QUERY_BINDING) + 1024]); 238 | 239 | adapter_list.clear(); 240 | 241 | int i = 0; 242 | while (1) { 243 | 244 | memset(pQueryBinding, 0, sizeof(NDISUIO_QUERY_BINDING)); 245 | pQueryBinding->BindingIndex = i; 246 | 247 | dwBytes = 0; 248 | 249 | result = DeviceIoControl( 250 | ndisuio, 251 | IOCTL_NDISUIO_QUERY_BINDING, 252 | pQueryBinding, 253 | sizeof(NDISUIO_QUERY_BINDING), 254 | pQueryBinding, 255 | sizeof(NDISUIO_QUERY_BINDING) + 1024, 256 | &dwBytes, 257 | NULL 258 | ); 259 | 260 | if (!result) { 261 | break; 262 | } 263 | 264 | WCHAR wtmp[ADAPTER_NAME_LENGTH + ADAPTER_DESCRIPTION_LENGTH]; 265 | 266 | if (pQueryBinding->DeviceNameLength < sizeof(wtmp)) { 267 | 268 | memset(wtmp, 0, sizeof(wtmp)); 269 | memcpy(wtmp, (PUCHAR)pQueryBinding + pQueryBinding->DeviceNameOffset, pQueryBinding->DeviceNameLength); 270 | 271 | DEBUG_WPRINT(L" pQueryBinding->DeviceNameLength: %u\n", pQueryBinding->DeviceNameLength); 272 | DEBUG_WPRINT(L" pQueryBinding->DeviceName: %s\n", wtmp); 273 | 274 | int length = wcslen(wtmp); 275 | if (length > 0 && length < ADAPTER_NAME_LENGTH) { 276 | 277 | memset(&adapter_info, 0, sizeof(adapter_info)); 278 | 279 | WCHAR *pos = wcsstr(wtmp, L"\\DEVICE\\"); 280 | if (pos != NULL) { 281 | wcscpy(adapter_info.name, pos + 8); 282 | } else { 283 | wcscpy(adapter_info.name, wtmp); 284 | } 285 | 286 | DEBUG_WPRINT(L" adapter_info.name: %s\n", adapter_info.name); 287 | 288 | if (pQueryBinding->DeviceDescrLength < sizeof(wtmp)) { 289 | 290 | memset(wtmp, 0, sizeof(wtmp)); 291 | memcpy(wtmp, (PUCHAR)pQueryBinding + pQueryBinding->DeviceDescrOffset, pQueryBinding->DeviceDescrLength); 292 | 293 | DEBUG_WPRINT(L" pQueryBinding->DeviceDescrLength: %u\n", pQueryBinding->DeviceDescrLength); 294 | DEBUG_WPRINT(L" pQueryBinding->DeviceDescr: %s\n", wtmp); 295 | 296 | length = wcslen(wtmp); 297 | if (length > 0 && length < ADAPTER_DESCRIPTION_LENGTH) { 298 | 299 | wcscpy(adapter_info.description, wtmp); 300 | DEBUG_WPRINT(L" adapter_info.description: %s\n", adapter_info.description); 301 | 302 | } 303 | 304 | } 305 | 306 | adapter_list.push_back(adapter_info); 307 | 308 | } 309 | 310 | } 311 | 312 | i++; 313 | 314 | DEBUG_PRINT("\n"); 315 | 316 | } 317 | 318 | free(pQueryBinding); 319 | get_ap_list_func = &wlanapi::_ndis_get_ap_list; 320 | get_adapter_list_func = &wlanapi::_ndis_get_adapter_list; 321 | 322 | DEBUG_LEAVE(wlanapi) 323 | 324 | } 325 | 326 | /** 327 | * Fetches list of access points using NDIS User-Mode I/O driver (NDISUIO 5.1) 328 | * http://msdn.microsoft.com/en-us/library/ms892537.aspx 329 | * 330 | * Works with Windows XP >= SP1 331 | * 332 | * @return void 333 | * @throws wlanapi_exception 334 | */ 335 | void wlanapi::_ndis_get_ap_list(ADAPTER_NAME *adapter_name) { 336 | 337 | BOOL result; 338 | HANDLE ndisuio; 339 | DWORD dwOIDCode; 340 | DWORD dwBytes; 341 | AP_INFO ap_info; 342 | 343 | DEBUG_ENTER(wlanapi); 344 | 345 | DEBUG_WPRINT(L" Querying adapter '%s'...\n", adapter_name); 346 | 347 | char device[ADAPTER_NAME_LENGTH + 4]; 348 | memset(device, 0, sizeof(device)); 349 | strcpy(device, "\\\\.\\"); 350 | wcstombs(device + 4, adapter_name, ADAPTER_NAME_LENGTH - 1); 351 | 352 | ndisuio = CreateFile( 353 | device, 354 | GENERIC_READ | GENERIC_WRITE, 0, NULL, 355 | OPEN_EXISTING, 356 | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 357 | INVALID_HANDLE_VALUE 358 | ); 359 | 360 | if (ndisuio == INVALID_HANDLE_VALUE) { 361 | throw wlanapi_exception("NDIS: Failed to open connection to NDISUIO with error code: %d", (int)GetLastError()); 362 | } 363 | 364 | DEBUG_PRINT(" Connection to NDISUIO has been opened.\n"); 365 | 366 | dwOIDCode = OID_802_11_BSSID_LIST_SCAN; 367 | dwBytes = 0; 368 | result = DeviceIoControl( 369 | ndisuio, 370 | IOCTL_NDIS_QUERY_GLOBAL_STATS, 371 | &dwOIDCode, 372 | sizeof(dwOIDCode), 373 | NULL, 374 | 0, 375 | &dwBytes, 376 | NULL 377 | ); 378 | 379 | //printf("result: %d\n", result); 380 | //printf("dwBytes: %d\n", dwBytes); 381 | 382 | PNDIS_802_11_BSSID_LIST_EX pList = (PNDIS_802_11_BSSID_LIST_EX)malloc(sizeof(NDIS_802_11_BSSID_LIST_EX) * 50); 383 | //boost::scoped_array pList((PNDIS_802_11_BSSID_LIST_EX)new char[sizeof(NDIS_802_11_BSSID_LIST_EX) * 50]); 384 | 385 | memset(pList, 0, sizeof(NDIS_802_11_BSSID_LIST_EX) * 50); 386 | 387 | dwOIDCode = OID_802_11_BSSID_LIST; 388 | dwBytes = 0; 389 | result = DeviceIoControl( 390 | ndisuio, 391 | IOCTL_NDIS_QUERY_GLOBAL_STATS, 392 | &dwOIDCode, 393 | sizeof(dwOIDCode), 394 | pList, 395 | sizeof(NDIS_802_11_BSSID_LIST_EX) * 50, 396 | &dwBytes, 397 | NULL 398 | ); 399 | 400 | //printf("result: %d\n", result); 401 | //printf("dwBytes: %d\n", dwBytes); 402 | 403 | DEBUG_PRINT(" pList->NumberOfItems: %ld\n\n", pList->NumberOfItems); 404 | 405 | PNDIS_WLAN_BSSID_EX pBssid = (PNDIS_WLAN_BSSID_EX)&pList->Bssid[0]; 406 | 407 | const unsigned char *buffer_end = reinterpret_cast(pBssid) + dwBytes; 408 | 409 | for (DWORD i = 0; i < pList->NumberOfItems; ++i) { 410 | 411 | memset(&ap_info, 0, sizeof(ap_info)); 412 | 413 | if (pBssid->Length < sizeof(NDIS_WLAN_BSSID) || (reinterpret_cast(pBssid) + pBssid->Length > buffer_end)) { 414 | DEBUG_PRINT(" Bssid structure looks odd. Break!\n"); 415 | break; 416 | } 417 | 418 | DEBUG_PRINT(" == [ %ld ] ==================================================\n", i + 1); 419 | DEBUG_PRINT(" pBssid->Length: %ld\n", pBssid->Length); 420 | DEBUG_PRINT(" pBssid->Ssid.Ssid: %s\n", pBssid->Ssid.Ssid); 421 | DEBUG_PRINT(" pBssid->MacAddress: %02X-%02X-%02X-%02X-%02X-%02X\n", pBssid->MacAddress[0], pBssid->MacAddress[1], pBssid->MacAddress[2], pBssid->MacAddress[3], pBssid->MacAddress[4], pBssid->MacAddress[5]); 422 | DEBUG_PRINT(" pBssid->Rssi: %ld\n", pBssid->Rssi); 423 | DEBUG_PRINT("\n"); 424 | 425 | memcpy(&ap_info.mac_address, pBssid->MacAddress, sizeof(ap_info.mac_address)); 426 | strncpy(ap_info.name, (AP_NAME *)pBssid->Ssid.Ssid, AP_NAME_LENGTH - 1); 427 | ap_info.rssi = pBssid->Rssi; 428 | 429 | ap_list.push_back(ap_info); 430 | 431 | pBssid = (PNDIS_WLAN_BSSID_EX)((PUCHAR)pBssid + pBssid->Length); 432 | 433 | } 434 | 435 | free(pList); 436 | CloseHandle(ndisuio); 437 | 438 | DEBUG_LEAVE(wlanapi); 439 | 440 | } 441 | 442 | /** 443 | * Fetches list of adapters using Wireless Zero Configuration service (WZCSVC) 444 | * http://msdn.microsoft.com/en-us/library/ms706593(VS.85).aspx 445 | * 446 | * Works with Windows XP >= SP2 447 | * 448 | * @return void 449 | * @throws wlanapi_exception 450 | */ 451 | void wlanapi::_wzc_get_adapter_list() { 452 | 453 | ADAPTER_INFO adapter_info; 454 | 455 | DEBUG_ENTER(wlanapi) 456 | 457 | if (wzc_library == NULL) { 458 | wzc_library = LoadLibrary("wzcsapi"); 459 | } 460 | 461 | if (wzc_library == NULL) { 462 | throw wlanapi_exception("WZC: Unable to load wzcsapi!\n"); 463 | } 464 | 465 | DEBUG_PRINT(" Successfully loaded library 'wzcsapi'\n"); 466 | 467 | if (WZCEnumInterfaces == NULL) { 468 | 469 | WZCEnumInterfaces = (WZCEnumInterfacesFunction)GetProcAddress(wzc_library, "WZCEnumInterfaces"); 470 | 471 | if (WZCEnumInterfaces == NULL) { 472 | throw wlanapi_exception("WZC: Unable to find process address of function 'WZCEnumInterfaces' (error code: %d)\n", (int)GetLastError()); 473 | } 474 | 475 | } 476 | 477 | // Get the list of interfaces. WZCEnumInterfaces allocates INTFS_KEY_TABLE::pIntfs. 478 | INTFS_KEY_TABLE interface_list; 479 | memset(&interface_list, 0, sizeof(INTFS_KEY_TABLE)); 480 | 481 | DWORD result = WZCEnumInterfaces(NULL, &interface_list); 482 | if (result != ERROR_SUCCESS) { 483 | throw wlanapi_exception("WZC: Interface enumeration failed; WCZ service is probably not running\n"); 484 | } 485 | 486 | DEBUG_PRINT(" Number of devices: %lu\n", interface_list.dwNumIntfs); 487 | 488 | if (WZCQueryInterface == NULL) { 489 | 490 | WZCQueryInterface = (WZCQueryInterfaceFunction)GetProcAddress(wzc_library, "WZCQueryInterface"); 491 | 492 | if (WZCQueryInterface == NULL) { 493 | 494 | // cleanup 495 | LocalFree(interface_list.pIntfs); 496 | 497 | throw wlanapi_exception("WZC: Unable to find process address of function 'WZCQueryInterface' (error code: %d)\n", (int)GetLastError()); 498 | 499 | } 500 | 501 | } 502 | 503 | if (WZCRefreshInterface == NULL) { 504 | 505 | WZCRefreshInterface = (WZCRefreshInterfaceFunction)GetProcAddress(wzc_library, "WZCRefreshInterface"); 506 | 507 | if (WZCRefreshInterface == NULL) { 508 | 509 | // cleanup 510 | LocalFree(interface_list.pIntfs); 511 | 512 | throw wlanapi_exception("WZC: Unable to find process address of function 'WZCRefreshInterface' (error code: %d)\n", (int)GetLastError()); 513 | 514 | } 515 | 516 | } 517 | 518 | adapter_list.clear(); 519 | 520 | for (int i = 0; i < static_cast(interface_list.dwNumIntfs); ++i) { 521 | 522 | INTF_ENTRY interface_data; 523 | memset(&interface_data, 0, sizeof(INTF_ENTRY)); 524 | 525 | interface_data.wszGuid = interface_list.pIntfs[i].wszGuid; 526 | DWORD dwOutFlags = 1; 527 | 528 | DWORD result = WZCQueryInterface(NULL, INTF_DESCR, &interface_data, &dwOutFlags); 529 | 530 | if (result != ERROR_SUCCESS) { 531 | 532 | // cleanup 533 | LocalFree(interface_list.pIntfs); 534 | 535 | throw wlanapi_exception("WZC: Interface query failed; WCZ service is probably not running\n"); 536 | 537 | } 538 | 539 | int length = wcslen(interface_list.pIntfs[i].wszGuid); 540 | if (length > 0 && length < ADAPTER_NAME_LENGTH) { 541 | 542 | memset(&adapter_info, 0, sizeof(adapter_info)); 543 | 544 | wcscpy(adapter_info.name, interface_list.pIntfs[i].wszGuid); 545 | DEBUG_WPRINT(L" interface_list.pIntfs[%i].wszGuid: %s\n", i, interface_list.pIntfs[i].wszGuid); 546 | DEBUG_WPRINT(L" adapter_info.name: %s\n", adapter_info.name); 547 | 548 | length = wcslen(interface_data.wszDescr); 549 | if (length > 0 && length < ADAPTER_DESCRIPTION_LENGTH) { 550 | wcscpy(adapter_info.description, interface_data.wszDescr); 551 | DEBUG_WPRINT(L" interface_data.wszDescr: %s\n", interface_data.wszDescr); 552 | DEBUG_WPRINT(L" adapter_info.description: %s\n", adapter_info.description); 553 | } 554 | 555 | adapter_list.push_back(adapter_info); 556 | 557 | } 558 | 559 | DEBUG_PRINT("\n"); 560 | 561 | } 562 | 563 | LocalFree(interface_list.pIntfs); 564 | 565 | get_ap_list_func = &wlanapi::_wzc_get_ap_list; 566 | get_adapter_list_func = &wlanapi::_wzc_get_adapter_list; 567 | 568 | DEBUG_LEAVE(wlanapi) 569 | 570 | } 571 | 572 | /** 573 | * Fetches list of access points using Wireless Zero Configuration service (WZCSVC) 574 | * http://msdn.microsoft.com/en-us/library/ms706593(VS.85).aspx 575 | * 576 | * Works with Windows XP >= SP2 577 | * 578 | * @return void 579 | * @throws wlanapi_exception 580 | */ 581 | void wlanapi::_wzc_get_ap_list(ADAPTER_NAME *adapter_name) { 582 | 583 | DWORD result; 584 | AP_INFO ap_info; 585 | 586 | DEBUG_ENTER(wlanapi); 587 | 588 | DEBUG_WPRINT(L" Querying adapter '%s'...\n", adapter_name); 589 | 590 | INTF_ENTRY interface_data; 591 | memset(&interface_data, 0, sizeof(INTF_ENTRY)); 592 | interface_data.wszGuid = adapter_name; 593 | DWORD dwOutFlags = 1; 594 | 595 | result = WZCQueryInterface(NULL, INTF_BSSIDLIST | INTF_LIST_SCAN, &interface_data, &dwOutFlags); 596 | 597 | if (result != ERROR_SUCCESS) { 598 | throw wlanapi_exception("WZC: Interface query failed; WCZ service is probably not running\n"); 599 | } 600 | 601 | if ((dwOutFlags & INTF_BSSIDLIST) != INTF_BSSIDLIST) { 602 | throw wlanapi_exception("WZC: Interface query consistency failure: incorrect flags\n"); 603 | } 604 | 605 | if (interface_data.rdBSSIDList.dwDataLen == 0 || interface_data.rdBSSIDList.dwDataLen < sizeof(NDIS_802_11_BSSID_LIST)) { 606 | 607 | int data_until_padding = (UCHAR*)&interface_data.padding1 - (UCHAR*)&interface_data; 608 | 609 | // this is a hack to support Windows XP SP2 with WLAN Hotfix and SP3 610 | memmove((UCHAR*)&interface_data + data_until_padding, (UCHAR*)&interface_data + data_until_padding + 8, sizeof(interface_data) - data_until_padding - 8); 611 | 612 | if (interface_data.rdBSSIDList.dwDataLen == 0 || interface_data.rdBSSIDList.dwDataLen < sizeof(NDIS_802_11_BSSID_LIST)) { 613 | // cleanup 614 | LocalFree(interface_data.rdBSSIDList.pData); 615 | throw wlanapi_exception("WZC: Interface query consistency failure: no data or incorrect data length (length: %ld)\n", interface_data.rdBSSIDList.dwDataLen); 616 | } 617 | 618 | } 619 | 620 | DEBUG_PRINT(" dwOutFlags & INTF_BSSIDLIST == INTF_BSSIDLIST: %d\n", (dwOutFlags & INTF_BSSIDLIST) == INTF_BSSIDLIST); 621 | DEBUG_PRINT(" interface_data.rdBSSIDList.dwDataLen: %ld\n", interface_data.rdBSSIDList.dwDataLen); 622 | 623 | const PNDIS_802_11_BSSID_LIST pList = reinterpret_cast(interface_data.rdBSSIDList.pData); 624 | DEBUG_PRINT(" pList->NumberOfItems: %ld\n\n", pList->NumberOfItems); 625 | 626 | PNDIS_WLAN_BSSID pBssid = reinterpret_cast(&pList->Bssid[0]); 627 | const unsigned char *buffer_end = reinterpret_cast(pBssid) + interface_data.rdBSSIDList.dwDataLen; 628 | 629 | for (DWORD i = 0; i < pList->NumberOfItems; ++i) { 630 | 631 | if (pBssid->Length < sizeof(NDIS_WLAN_BSSID) || (reinterpret_cast(pBssid) + pBssid->Length > buffer_end)) { 632 | // cleanup 633 | LocalFree(interface_data.rdBSSIDList.pData); 634 | throw wlanapi_exception("WZC: Bssid structure looks odd. Break!\n"); 635 | } 636 | 637 | memset(&ap_info, 0, sizeof(ap_info)); 638 | 639 | DEBUG_PRINT(" == [ %ld ] ==================================================\n", i + 1); 640 | DEBUG_PRINT(" pBssid->Length: %ld\n", pBssid->Length); 641 | DEBUG_PRINT(" pBssid->Ssid.Ssid: %s\n", pBssid->Ssid.Ssid); 642 | DEBUG_PRINT(" pBssid->MacAddress: %02X-%02X-%02X-%02X-%02X-%02X\n", pBssid->MacAddress[0], pBssid->MacAddress[1], pBssid->MacAddress[2], pBssid->MacAddress[3], pBssid->MacAddress[4], pBssid->MacAddress[5]); 643 | DEBUG_PRINT(" pBssid->Rssi: %ld\n", pBssid->Rssi); 644 | DEBUG_PRINT("\n"); 645 | 646 | memcpy(&ap_info.mac_address, pBssid->MacAddress, sizeof(ap_info.mac_address)); 647 | strncpy(ap_info.name, (AP_NAME *)pBssid->Ssid.Ssid, AP_NAME_LENGTH - 1); 648 | ap_info.rssi = pBssid->Rssi; 649 | 650 | ap_list.push_back(ap_info); 651 | 652 | pBssid = reinterpret_cast(reinterpret_cast(pBssid) + pBssid->Length); 653 | 654 | } 655 | 656 | LocalFree(interface_data.rdBSSIDList.pData); 657 | 658 | DEBUG_LEAVE(wlanapi); 659 | 660 | } 661 | 662 | /** 663 | * Fetches list of adapters using Native Wifi (WLAN) API 664 | * http://msdn.microsoft.com/en-us/library/ms706556(VS.85).aspx 665 | * 666 | * Works with Windows XP >= SP3 and Windows Vista 667 | * 668 | * @return void 669 | * @throws wlanapi_exception 670 | */ 671 | void wlanapi::_wlan_get_adapter_list() { 672 | 673 | ADAPTER_INFO adapter_info; 674 | DWORD result; 675 | 676 | DEBUG_ENTER(wlanapi) 677 | 678 | if (wlan_library == NULL) { 679 | wlan_library = LoadLibrary("wlanapi"); 680 | } 681 | 682 | if (wlan_library == NULL) { 683 | throw wlanapi_exception("WLAN: Unable to load wlanapi!\n"); 684 | } 685 | 686 | DEBUG_PRINT(" Successfully loaded library 'wlanapi'\n"); 687 | 688 | if (WlanOpenHandle == NULL) { 689 | 690 | WlanOpenHandle = (WlanOpenHandleFunction)GetProcAddress(wlan_library, "WlanOpenHandle"); 691 | 692 | if (WlanOpenHandle == NULL) { 693 | throw wlanapi_exception("WLAN: Unable to find process address of function 'WlanOpenHandle' (error code: %d)\n", (int)GetLastError()); 694 | } 695 | 696 | } 697 | 698 | if (WlanCloseHandle == NULL) { 699 | 700 | WlanCloseHandle = (WlanCloseHandleFunction)GetProcAddress(wlan_library, "WlanCloseHandle"); 701 | 702 | if (WlanCloseHandle == NULL) { 703 | throw wlanapi_exception("WLAN: Unable to find process address of function 'WlanCloseHandle' (error code: %d)\n", (int)GetLastError()); 704 | } 705 | 706 | } 707 | 708 | if (WlanEnumInterfaces == NULL) { 709 | 710 | WlanEnumInterfaces = (WlanEnumInterfacesFunction)GetProcAddress(wlan_library, "WlanEnumInterfaces"); 711 | 712 | if (WlanEnumInterfaces == NULL) { 713 | throw wlanapi_exception("WLAN: Unable to find process address of function 'WlanEnumInterfaces' (error code: %d)\n", (int)GetLastError()); 714 | } 715 | 716 | } 717 | 718 | if (WlanGetNetworkBssList == NULL) { 719 | 720 | WlanGetNetworkBssList = (WlanGetNetworkBssListFunction)GetProcAddress(wlan_library, "WlanGetNetworkBssList"); 721 | 722 | if (WlanGetNetworkBssList == NULL) { 723 | throw wlanapi_exception("WLAN: Unable to find process address of function 'WlanGetNetworkBssList' (error code: %d)\n", (int)GetLastError()); 724 | } 725 | 726 | } 727 | 728 | if (WlanFreeMemory == NULL) { 729 | 730 | WlanFreeMemory = (WlanFreeMemoryFunction)GetProcAddress(wlan_library, "WlanFreeMemory"); 731 | 732 | if (WlanFreeMemory == NULL) { 733 | throw wlanapi_exception("WLAN: Unable to find process address of function 'WlanFreeMemory' (error code: %d)\n", (int)GetLastError()); 734 | } 735 | 736 | } 737 | 738 | if (WlanGetAvailableNetworkList == NULL) { 739 | 740 | WlanGetAvailableNetworkList = (WlanGetAvailableNetworkListFunction)GetProcAddress(wlan_library, "WlanGetAvailableNetworkList"); 741 | 742 | if (WlanGetAvailableNetworkList == NULL) { 743 | throw wlanapi_exception("WLAN: Unable to find process address of function 'WlanGetAvailableNetworkList' (error code: %d)\n", (int)GetLastError()); 744 | } 745 | 746 | } 747 | 748 | 749 | DWORD negotiated_version = 0; 750 | 751 | if (wlan_handle == NULL) { 752 | 753 | result = WlanOpenHandle(1, NULL, &negotiated_version, &wlan_handle); 754 | 755 | if (result != ERROR_SUCCESS || wlan_handle == NULL) { 756 | throw wlanapi_exception("WLAN: Error creating WLAN API handle (error code: %d)\n", (int)GetLastError()); 757 | } 758 | 759 | } 760 | 761 | DEBUG_PRINT(" Negotiated WLAN API version: %ld\n", negotiated_version); 762 | 763 | // get list of adapters 764 | 765 | WLAN_INTERFACE_INFO_LIST *interface_list; 766 | 767 | result = WlanEnumInterfaces(wlan_handle, NULL, &interface_list); 768 | DEBUG_PRINT(" interface_list.dwNumberOfItems: %ld\n", interface_list->dwNumberOfItems); 769 | 770 | adapter_list.clear(); 771 | 772 | // iterate through list of adapters 773 | 774 | for (unsigned int i = 0; i < interface_list->dwNumberOfItems; ++i) { 775 | 776 | memset(&adapter_info, 0, sizeof(adapter_info)); 777 | 778 | DEBUG_PRINT(" interface_list->InterfaceInfo[%d].InterfaceGuid: {%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n", i, 779 | interface_list->InterfaceInfo[i].InterfaceGuid.Data1, 780 | interface_list->InterfaceInfo[i].InterfaceGuid.Data2, 781 | interface_list->InterfaceInfo[i].InterfaceGuid.Data3, 782 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[0], 783 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[1], 784 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[2], 785 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[3], 786 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[4], 787 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[5], 788 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[6], 789 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[7] 790 | ); 791 | 792 | swprintf(adapter_info.name, L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", 793 | interface_list->InterfaceInfo[i].InterfaceGuid.Data1, 794 | interface_list->InterfaceInfo[i].InterfaceGuid.Data2, 795 | interface_list->InterfaceInfo[i].InterfaceGuid.Data3, 796 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[0], 797 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[1], 798 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[2], 799 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[3], 800 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[4], 801 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[5], 802 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[6], 803 | interface_list->InterfaceInfo[i].InterfaceGuid.Data4[7] 804 | ); 805 | 806 | DEBUG_WPRINT(L" adapter_info.name: %s\n", adapter_info.name); 807 | 808 | DEBUG_WPRINT(L" interface_list->InterfaceInfo[%d].strInterfaceDescription: %s\n", i, interface_list->InterfaceInfo[i].strInterfaceDescription); 809 | 810 | wcsncpy(adapter_info.description, interface_list->InterfaceInfo[i].strInterfaceDescription, ADAPTER_DESCRIPTION_LENGTH - 1); 811 | DEBUG_WPRINT(L" adapter_info.description %s\n", adapter_info.description); 812 | 813 | adapter_list.push_back(adapter_info); 814 | 815 | } 816 | 817 | WlanFreeMemory(interface_list); 818 | 819 | get_ap_list_func = &wlanapi::_wlan_get_ap_list; 820 | get_adapter_list_func = &wlanapi::_wlan_get_adapter_list; 821 | 822 | DEBUG_LEAVE(wlanapi) 823 | 824 | } 825 | 826 | /** 827 | * Fetches list of acess points using Native Wifi (WLAN) API 828 | * http://msdn.microsoft.com/en-us/library/ms706556(VS.85).aspx 829 | * 830 | * Works with Windows XP >= SP3 and Windows Vista 831 | * 832 | * @return void 833 | * @throws wlanapi_exception 834 | */ 835 | void wlanapi::_wlan_get_ap_list(ADAPTER_NAME *adapter_name) { 836 | 837 | DWORD result; 838 | AP_INFO ap_info; 839 | 840 | DEBUG_ENTER(wlanapi); 841 | 842 | DEBUG_WPRINT(L" Querying adapter '%s'...\n", adapter_name); 843 | 844 | if (adapter_name == NULL || wcslen(adapter_name) != 38) { 845 | throw wlanapi_exception("WLAN: No adapter name given or length mismatch (should be 38 wchars long)"); 846 | } 847 | 848 | adapter_name[37] = L'\0'; 849 | adapter_name++; 850 | 851 | GUID guid; 852 | swscanf(adapter_name, L"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", 853 | &guid.Data1, 854 | &guid.Data2, 855 | &guid.Data3, 856 | &guid.Data4[0], 857 | &guid.Data4[1], 858 | &guid.Data4[2], 859 | &guid.Data4[3], 860 | &guid.Data4[4], 861 | &guid.Data4[5], 862 | &guid.Data4[6], 863 | &guid.Data4[7] 864 | ); 865 | 866 | WLAN_BSS_LIST *bss_list; 867 | 868 | result = WlanGetNetworkBssList( 869 | wlan_handle, 870 | &guid, 871 | NULL, // return all available BSSes 872 | dot11_BSS_type_any, 873 | false, 874 | NULL, 875 | &bss_list 876 | ); 877 | 878 | if (result != 0x32) { 879 | 880 | // Looks like we're running on Windows Vista... 881 | // 882 | // When called from Windows XP (SP3 or SP2 with WLAN Hotfix) this function always 883 | // returns 0x32, which means it is simply NOT implemented. 884 | // 885 | // For more information habe a look at: 886 | // http://www.wlanapi.info/wiki/windows_xp#WindowsXPServicePack2withWLANAPIHotfix 887 | 888 | if (result != ERROR_SUCCESS) { 889 | throw wlanapi_exception("WLAN: Unable to get BSS list using WlanGetNetworkBssList (return code: %ld)\n", result); 890 | } 891 | 892 | DEBUG_PRINT(" bss_list->dwNumberOfItems: %d\n", bss_list->dwNumberOfItems); 893 | 894 | for (DWORD i = 0; i < bss_list->dwNumberOfItems; ++i) { 895 | 896 | memset(&ap_info, 0, sizeof(ap_info)); 897 | 898 | DEBUG_PRINT(" == [ %d ] ==================================================\n", i + 1); 899 | DEBUG_PRINT(" bss_list->wlanBssEntries[%d].dot11Ssid.ucSSID: %s\n", i, bss_list->wlanBssEntries[i].dot11Ssid.ucSSID); 900 | DEBUG_PRINT(" bss_list->wlanBssEntries[%d].dot11Bssid: %02X-%02X-%02X-%02X-%02X-%02X\n", i, bss_list->wlanBssEntries[i].dot11Bssid[0], bss_list->wlanBssEntries[i].dot11Bssid[1], bss_list->wlanBssEntries[i].dot11Bssid[2], bss_list->wlanBssEntries[i].dot11Bssid[3], bss_list->wlanBssEntries[i].dot11Bssid[4], bss_list->wlanBssEntries[i].dot11Bssid[5]); 901 | DEBUG_PRINT(" bss_list->wlanBssEntries[%d].lRssi: %d\n", i, (signed)bss_list->wlanBssEntries[i].lRssi); 902 | 903 | DEBUG_PRINT("\n"); 904 | 905 | strncpy(ap_info.name, (AP_NAME *)bss_list->wlanBssEntries[i].dot11Ssid.ucSSID, AP_NAME_LENGTH - 1); 906 | memcpy(&ap_info.mac_address, bss_list->wlanBssEntries[i].dot11Bssid, sizeof(ap_info.mac_address)); 907 | ap_info.rssi = (signed)bss_list->wlanBssEntries[i].lRssi; 908 | 909 | ap_list.push_back(ap_info); 910 | 911 | } 912 | 913 | WlanFreeMemory(bss_list); 914 | 915 | } else { 916 | 917 | // It seems we're running on Windows XP (SP3 or SP2 with WLAN Hotfix), as the 918 | // function WlanGetNetworkBssList returned 0x32, which means it is NOT implemented. 919 | // 920 | // In this case we're using WlanGetAvailableNetworkList instead, which unfortunately 921 | // gives as a little bit less accurately signal strength values and no MAC address. 922 | // 923 | // For more information habe a look at: 924 | // http://www.wlanapi.info/wiki/windows_xp#WindowsXPServicePack2withWLANAPIHotfix 925 | 926 | PWLAN_AVAILABLE_NETWORK_LIST network_list; 927 | 928 | result = WlanGetAvailableNetworkList( 929 | wlan_handle, 930 | &guid, 931 | 0x00000001, 932 | NULL, 933 | &network_list 934 | ); 935 | 936 | if (result != ERROR_SUCCESS) { 937 | throw wlanapi_exception("WLAN: Unable to get BSS list using WlanGetAvailableNetworkList (return code: %ld)\n", result); 938 | } 939 | 940 | DEBUG_PRINT(" sizeof(WLAN_AVAILABLE_NETWORK): %d\n", sizeof(WLAN_AVAILABLE_NETWORK)); 941 | 942 | DEBUG_PRINT(" network_list->dwNumberOfItems: %ld\n", network_list->dwNumberOfItems); 943 | PWLAN_AVAILABLE_NETWORK network = &network_list->Network[0]; 944 | 945 | for (DWORD i = 0; i < network_list->dwNumberOfItems; ++i) { 946 | 947 | if (network->dwFlags != 0 || network->strProfileName[0] != 0) { 948 | 949 | // Only show adapter entries which do not have a profile and 950 | // which are currently not connected to avoid duplicates: 951 | // http://msdn.microsoft.com/en-us/library/ms707403(VS.85).aspx 952 | 953 | network++; 954 | continue; 955 | } 956 | 957 | memset(&ap_info, 0, sizeof(ap_info)); 958 | 959 | DEBUG_PRINT(" == [ %ld ] ==================================================\n", i + 1); 960 | DEBUG_PRINT(" network->dot11Ssid.ucSSID: %s\n", network->dot11Ssid.ucSSID); 961 | DEBUG_WPRINT(L" network->strProfileName: %s\n", network->strProfileName); 962 | DEBUG_PRINT(" network->wlanSignalQuality: %lu\n", network->wlanSignalQuality); 963 | DEBUG_PRINT(" network->uNumberOfBssids: %lu\n", network->uNumberOfBssids); 964 | DEBUG_PRINT(" network->dwFlags: %lu\n", network->dwFlags); 965 | 966 | strncpy(ap_info.name, (AP_NAME *)network->dot11Ssid.ucSSID, AP_NAME_LENGTH - 1); 967 | 968 | // We do only have wlanSignalQuality here, so we have to convert it 969 | // to an RSSI value using linear interpolation: 970 | // http://msdn.microsoft.com/en-us/library/ms707403(VS.85).aspx 971 | ap_info.rssi = -100 + network->wlanSignalQuality / 2; 972 | 973 | ap_list.push_back(ap_info); 974 | 975 | network++; 976 | 977 | } 978 | 979 | WlanFreeMemory(network_list); 980 | 981 | } 982 | 983 | DEBUG_LEAVE(wlanapi); 984 | 985 | } 986 | 987 | #else 988 | 989 | #ifdef DBUS 990 | /** 991 | * Opens D-BUS connection and creates proxy for NetworkManager 992 | * 993 | * @return void 994 | * @throws wlanapi_exception 995 | */ 996 | void wlanapi::_dbus_initiate() { 997 | 998 | DEBUG_ENTER(wlanapi); 999 | 1000 | GError *error = NULL; 1001 | char error_msg[256] = {0}; 1002 | 1003 | if (dbus_connection != NULL) { 1004 | return; 1005 | } 1006 | 1007 | g_type_init(); 1008 | DEBUG_PRINT(" Initialized type system\n"); 1009 | 1010 | // connect to the system bus 1011 | dbus_connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); 1012 | if (dbus_connection == NULL) { 1013 | strncpy(error_msg, error->message, 255); 1014 | error_msg[255] = '\0'; 1015 | g_error_free(error); 1016 | throw wlanapi_exception("D-BUS: Failed to open connection: %s", error_msg); 1017 | } 1018 | 1019 | DEBUG_PRINT(" Successfully opened SYSTEM D-BUS\n"); 1020 | 1021 | // create a proxy object for the remote interface "org.freedesktop.NetworkManager" on the system bus 1022 | _dbus_nm_proxy = dbus_g_proxy_new_for_name( 1023 | dbus_connection, 1024 | "org.freedesktop.NetworkManager", 1025 | "/org/freedesktop/NetworkManager", 1026 | "org.freedesktop.NetworkManager" 1027 | ); 1028 | 1029 | if (_dbus_nm_proxy != NULL) { 1030 | DEBUG_PRINT(" Created proxy for NetworkManager\n"); 1031 | } else { 1032 | throw wlanapi_exception("D-BUS: Failed to create proxy for NetworkManager"); 1033 | } 1034 | 1035 | DEBUG_LEAVE(wlanapi); 1036 | 1037 | } 1038 | 1039 | /** 1040 | * Closes D-BUS connection and releases proxy for NetworkManager 1041 | * 1042 | * @return void 1043 | */ 1044 | void wlanapi::_dbus_shutdown() { 1045 | 1046 | DEBUG_ENTER(wlanapi); 1047 | 1048 | if (dbus_connection != NULL) { 1049 | 1050 | dbus_g_connection_unref(dbus_connection); 1051 | g_object_unref(_dbus_nm_proxy); 1052 | 1053 | dbus_connection = NULL; 1054 | _dbus_nm_proxy = NULL; 1055 | 1056 | } 1057 | 1058 | DEBUG_LEAVE(wlanapi); 1059 | 1060 | } 1061 | 1062 | /** 1063 | * Fetches adapter list using (K)NetworkManager over D-BUS 1064 | * 1065 | * This should work for most recent (as of 2008) Gnome and KDE desktop 1066 | * systems. Tested under Ubuntu 7.x/8.x, Kubuntu 7.x/8.x and openSUSE 11.x 1067 | * 1068 | * @return void 1069 | * @throws wlanapi_exception 1070 | */ 1071 | void wlanapi::_dbus_get_adapter_list() { 1072 | 1073 | DEBUG_ENTER(wlanapi); 1074 | 1075 | GError *error = NULL; 1076 | char error_msg[256] = {0}; 1077 | DBusGProxy *proxy_props; 1078 | GPtrArray *g_device_list = NULL; 1079 | 1080 | GValue g_device_type = {0}; 1081 | guint device_type = 0; 1082 | 1083 | GValue g_interface = {0}; 1084 | 1085 | ADAPTER_INFO adapter_info; 1086 | 1087 | _dbus_initiate(); 1088 | 1089 | // get list of devices 1090 | 1091 | int res = dbus_g_proxy_call( 1092 | _dbus_nm_proxy, 1093 | "GetDevices", 1094 | &error, 1095 | G_TYPE_INVALID, 1096 | dbus_g_type_get_collection("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &g_device_list, 1097 | G_TYPE_INVALID 1098 | ); 1099 | 1100 | if (!res) { 1101 | strcpy(error_msg, error->message); 1102 | g_error_free(error); 1103 | error = NULL; 1104 | throw wlanapi_exception("D-BUS: Error calling org.freedesktop.NetworkManager.GetDevices method: %s", error_msg); 1105 | } 1106 | 1107 | DEBUG_PRINT(" Successfully called org.freedesktop.NetworkManager.GetDevices method\n"); 1108 | 1109 | // interate through list of devices and get some extra information 1110 | 1111 | for (uint i = 0; i < g_device_list->len; i++) { 1112 | 1113 | gchar *path = (gchar*)g_ptr_array_index(g_device_list, i); 1114 | 1115 | DEBUG_PRINT("\n Device UDI: %s\n", path); 1116 | 1117 | proxy_props = dbus_g_proxy_new_from_proxy( 1118 | _dbus_nm_proxy, 1119 | DBUS_INTERFACE_PROPERTIES, 1120 | path 1121 | ); 1122 | 1123 | int res = dbus_g_proxy_call( 1124 | proxy_props, 1125 | "Get", 1126 | &error, 1127 | G_TYPE_STRING, "org.freedesktop.NetworkManager.Device", 1128 | G_TYPE_STRING, "DeviceType", 1129 | G_TYPE_INVALID, 1130 | G_TYPE_VALUE, &g_device_type, 1131 | G_TYPE_INVALID 1132 | ); 1133 | 1134 | if (!res) { 1135 | 1136 | strcpy(error_msg, error->message); 1137 | g_error_free(error); 1138 | error = NULL; 1139 | 1140 | // cleanup 1141 | g_ptr_array_free(g_device_list, TRUE); 1142 | g_object_unref(proxy_props); 1143 | g_free(path); 1144 | 1145 | throw wlanapi_exception("D-BUS: Error calling org.freedesktop.DBus.Properties.Get method: %s", error_msg); 1146 | 1147 | } 1148 | 1149 | device_type = g_value_get_uint(&g_device_type); 1150 | g_value_unset(&g_device_type); 1151 | 1152 | DEBUG_PRINT(" Device Type: %d (%s)\n", device_type, (device_type == 1 ? "wired" : (device_type == 2 ? "wireless" : "unknown"))); 1153 | 1154 | if (device_type == 2) { 1155 | 1156 | // wireless device 1157 | 1158 | memset(&adapter_info, 0, sizeof(adapter_info)); 1159 | 1160 | int res = dbus_g_proxy_call( 1161 | proxy_props, 1162 | "Get", 1163 | &error, 1164 | G_TYPE_STRING, "org.freedesktop.NetworkManager.Device", 1165 | G_TYPE_STRING, "Interface", 1166 | G_TYPE_INVALID, 1167 | G_TYPE_VALUE, &g_interface, 1168 | G_TYPE_INVALID 1169 | ); 1170 | 1171 | if (!res) { 1172 | 1173 | strcpy(error_msg, error->message); 1174 | g_error_free(error); 1175 | error = NULL; 1176 | 1177 | // cleanup 1178 | g_ptr_array_free(g_device_list, TRUE); 1179 | g_object_unref(proxy_props); 1180 | g_free(path); 1181 | 1182 | throw wlanapi_exception("D-BUS: Error calling org.freedesktop.DBus.Properties.Get method: %s", error_msg); 1183 | 1184 | } 1185 | 1186 | int length = strlen(path); 1187 | if (length > 0 && length < ADAPTER_NAME_LENGTH) { 1188 | 1189 | strncpy(adapter_info.name, path, ADAPTER_NAME_LENGTH - 1); 1190 | strncpy(adapter_info.description, g_value_get_string(&g_interface), ADAPTER_DESCRIPTION_LENGTH - 1); 1191 | g_value_unset(&g_interface); 1192 | 1193 | DEBUG_PRINT(" adapter_info.name: %s\n", adapter_info.name); 1194 | DEBUG_PRINT(" adapter_info.description: %s\n", adapter_info.description); 1195 | 1196 | adapter_list.push_back(adapter_info); 1197 | 1198 | get_ap_list_func = &wlanapi::_dbus_get_ap_list; 1199 | get_adapter_list_func = &wlanapi::_dbus_get_adapter_list; 1200 | 1201 | } 1202 | 1203 | } 1204 | 1205 | g_object_unref(proxy_props); 1206 | g_free(path); 1207 | 1208 | } 1209 | 1210 | g_ptr_array_free(g_device_list, TRUE); 1211 | 1212 | DEBUG_LEAVE(wlanapi); 1213 | 1214 | } 1215 | 1216 | /** 1217 | * Fetches list of access points using (K)NetworkManager over D-BUS 1218 | * 1219 | * This should work for most recent (as of 2008) Gnome and KDE desktop 1220 | * systems. Tested under Ubuntu 7.x/8.x, Kubuntu 7.x/8.x and openSUSE 11.x 1221 | * 1222 | * @return void 1223 | * @throws wlanapi_exception 1224 | */ 1225 | void wlanapi::_dbus_get_ap_list(ADAPTER_NAME *adapter_name) { 1226 | 1227 | DEBUG_ENTER(wlanapi); 1228 | 1229 | GError *error = NULL; 1230 | char error_msg[256] = {0}; 1231 | DBusGProxy *proxy_props; 1232 | DBusGProxy *proxy_nm_dw; 1233 | GPtrArray *g_ap_list = NULL; 1234 | 1235 | GValue g_value = {0}; 1236 | guchar strength = 0; 1237 | GArray *ssid = NULL; 1238 | const gchar *hwaddress = NULL; 1239 | 1240 | AP_INFO ap_info; 1241 | 1242 | // create a proxy object for the remote interface "org.freedesktop.NetworkManager" on the system bus 1243 | 1244 | proxy_nm_dw = dbus_g_proxy_new_from_proxy( 1245 | _dbus_nm_proxy, 1246 | "org.freedesktop.NetworkManager.Device.Wireless", 1247 | adapter_name 1248 | ); 1249 | 1250 | if (proxy_nm_dw != NULL) { 1251 | DEBUG_PRINT(" Created proxy for NetworkManager.Device.Wireless\n"); 1252 | } else { 1253 | throw wlanapi_exception("D-BUS: Failed to create proxy for NetworkManager"); 1254 | } 1255 | 1256 | // get list of access points 1257 | 1258 | int res = dbus_g_proxy_call( 1259 | proxy_nm_dw, 1260 | "GetAccessPoints", 1261 | &error, 1262 | G_TYPE_INVALID, 1263 | dbus_g_type_get_collection("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &g_ap_list, 1264 | G_TYPE_INVALID 1265 | ); 1266 | 1267 | if (!res) { 1268 | 1269 | strcpy(error_msg, error->message); 1270 | g_error_free(error); 1271 | error = NULL; 1272 | 1273 | // cleanup 1274 | g_object_unref(proxy_nm_dw); 1275 | 1276 | throw wlanapi_exception("D-BUS: Error calling org.freedesktop.NetworkManager.GetAccessPoints method: %s", error_msg); 1277 | 1278 | } 1279 | 1280 | DEBUG_PRINT(" Successfully called org.freedesktop.NetworkManager.GetAccessPoints method\n"); 1281 | 1282 | // interate through list of access points 1283 | 1284 | for (uint i = 0; i < g_ap_list->len; i++) { 1285 | 1286 | gchar *path = (gchar*)g_ptr_array_index(g_ap_list, i); 1287 | 1288 | DEBUG_PRINT("\n Access point UDI: %s\n", path); 1289 | 1290 | proxy_props = dbus_g_proxy_new_from_proxy( 1291 | _dbus_nm_proxy, 1292 | DBUS_INTERFACE_PROPERTIES, 1293 | path 1294 | ); 1295 | 1296 | memset(&ap_info, 0, sizeof(ap_info)); 1297 | 1298 | // retrieve signal strength 1299 | 1300 | error = NULL; 1301 | int res = dbus_g_proxy_call( 1302 | proxy_props, 1303 | "Get", 1304 | &error, 1305 | G_TYPE_STRING, "org.freedesktop.NetworkManager.AccessPoint", 1306 | G_TYPE_STRING, "Strength", 1307 | G_TYPE_INVALID, 1308 | G_TYPE_VALUE, &g_value, 1309 | G_TYPE_INVALID 1310 | ); 1311 | 1312 | if (!res) { 1313 | 1314 | strncpy(error_msg, error->message, 255); 1315 | error_msg[255] = '\0'; 1316 | g_error_free(error); 1317 | 1318 | // cleanup 1319 | g_ptr_array_free(g_ap_list, TRUE); 1320 | g_object_unref(proxy_props); 1321 | g_free(path); 1322 | 1323 | throw wlanapi_exception("D-BUS: Error calling org.freedesktop.DBus.Properties.Get method: %s", error_msg); 1324 | 1325 | } 1326 | 1327 | strength = g_value_get_uchar(&g_value); 1328 | g_value_unset(&g_value); 1329 | 1330 | // Strength is expressed as a percentage and thus we have to convert 1331 | // it to a RSSI value using linear interpolation. 1332 | ap_info.rssi = -100 + strength / 2; 1333 | 1334 | DEBUG_PRINT(" Strength: %i\n", strength); 1335 | 1336 | // retrieve SSID 1337 | 1338 | error = NULL; 1339 | res = dbus_g_proxy_call( 1340 | proxy_props, 1341 | "Get", 1342 | &error, 1343 | G_TYPE_STRING, "org.freedesktop.NetworkManager.AccessPoint", 1344 | G_TYPE_STRING, "Ssid", 1345 | G_TYPE_INVALID, 1346 | G_TYPE_VALUE, &g_value, 1347 | G_TYPE_INVALID 1348 | ); 1349 | 1350 | if (!res) { 1351 | 1352 | strncpy(error_msg, error->message, 255); 1353 | error_msg[255] = '\0'; 1354 | g_error_free(error); 1355 | 1356 | // cleanup 1357 | g_ptr_array_free(g_ap_list, TRUE); 1358 | g_object_unref(proxy_props); 1359 | g_free(path); 1360 | 1361 | throw wlanapi_exception("D-BUS: Error calling org.freedesktop.DBus.Properties.Get method: %s", error_msg); 1362 | 1363 | } 1364 | 1365 | ssid = (GArray *)g_value_get_boxed(&g_value); 1366 | 1367 | int length = MAX(0, MIN(ssid->len, AP_NAME_LENGTH - 1)); 1368 | 1369 | strncpy(ap_info.name, (AP_NAME *)ssid->data, length); 1370 | ap_info.name[length] = '\0'; 1371 | g_value_unset(&g_value); 1372 | 1373 | DEBUG_PRINT(" Ssid: %s\n", ap_info.name); 1374 | 1375 | // retrieve mac address 1376 | 1377 | error = NULL; 1378 | res = dbus_g_proxy_call( 1379 | proxy_props, 1380 | "Get", 1381 | &error, 1382 | G_TYPE_STRING, "org.freedesktop.NetworkManager.AccessPoint", 1383 | G_TYPE_STRING, "HwAddress", 1384 | G_TYPE_INVALID, 1385 | G_TYPE_VALUE, &g_value, 1386 | G_TYPE_INVALID 1387 | ); 1388 | 1389 | if (!res) { 1390 | 1391 | strncpy(error_msg, error->message, 255); 1392 | error_msg[255] = '\0'; 1393 | g_error_free(error); 1394 | 1395 | // cleanup 1396 | g_ptr_array_free(g_ap_list, TRUE); 1397 | g_object_unref(proxy_props); 1398 | g_free(path); 1399 | 1400 | throw wlanapi_exception("D-BUS: Error calling org.freedesktop.DBus.Properties.Get method: %s", error_msg); 1401 | 1402 | } 1403 | 1404 | hwaddress = g_value_get_string(&g_value); 1405 | DEBUG_PRINT(" Mac address1: %s\n", (char *)hwaddress); 1406 | 1407 | int int_list[6]; 1408 | 1409 | sscanf(hwaddress, "%x:%x:%x:%x:%x:%x", 1410 | &int_list[0], 1411 | &int_list[1], 1412 | &int_list[2], 1413 | &int_list[3], 1414 | &int_list[4], 1415 | &int_list[5] 1416 | ); 1417 | 1418 | for (int i = 0; i < 6; ++i) { 1419 | ap_info.mac_address.u[i] = int_list[i]; 1420 | } 1421 | 1422 | g_value_unset(&g_value); 1423 | 1424 | // push ap item to list 1425 | 1426 | ap_list.push_back(ap_info); 1427 | 1428 | g_object_unref(proxy_props); 1429 | g_free(path); 1430 | 1431 | } 1432 | 1433 | g_ptr_array_free(g_ap_list, TRUE); 1434 | 1435 | DEBUG_LEAVE(wlanapi); 1436 | 1437 | } 1438 | 1439 | #endif // DBUS 1440 | 1441 | #endif 1442 | 1443 | -------------------------------------------------------------------------------- /library/wlanapi.h: -------------------------------------------------------------------------------- 1 | /** 2 | * wlanapi library 0.4 3 | * 4 | * Copyright (C) 2008, 2009 Moritz Mertinkat 5 | * All rights reserved. 6 | * 7 | * wlanapi library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wlanapi library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details.* 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with wlanapi library. If not, see . 19 | */ 20 | 21 | #ifndef __WLANAPI_H_ 22 | #define __WLANAPI_H_ 23 | 24 | #include 25 | 26 | #include "debug.h" 27 | #include "wlanapi_exception.h" 28 | 29 | #ifdef WIN32 30 | 31 | #include 32 | #include 33 | 34 | #define UNDER_CE 35 | 36 | #include "wlanapi_windows_ndisuio.h" 37 | #include "wlanapi_windows_wzc.h" 38 | #include "wlanapi_windows_wlan.h" 39 | 40 | #else 41 | 42 | #include 43 | #include 44 | #include 45 | 46 | #ifdef DBUS 47 | #include 48 | #include 49 | #endif 50 | 51 | #endif 52 | 53 | #define ADAPTER_NAME_LENGTH 256 54 | #define ADAPTER_DESCRIPTION_LENGTH 256 55 | 56 | #define AP_NAME_LENGTH 256 57 | 58 | #ifdef WIN32 59 | typedef wchar_t ADAPTER_NAME; 60 | typedef wchar_t ADAPTER_DESCRIPTION; 61 | typedef char AP_NAME; 62 | #else 63 | typedef char ADAPTER_NAME; 64 | typedef char ADAPTER_DESCRIPTION; 65 | typedef char AP_NAME; 66 | #endif 67 | 68 | typedef struct _ADAPTER_INFO { 69 | ADAPTER_NAME name[ADAPTER_NAME_LENGTH]; 70 | ADAPTER_DESCRIPTION description[ADAPTER_DESCRIPTION_LENGTH]; 71 | } ADAPTER_INFO; 72 | 73 | typedef std::vector ADAPTER_LIST; 74 | 75 | typedef struct _MAC_ADDRESS { 76 | unsigned char u[6]; 77 | } MAC_ADDRESS; 78 | 79 | typedef struct _AP_INFO { 80 | AP_NAME name[AP_NAME_LENGTH]; 81 | signed int rssi; 82 | MAC_ADDRESS mac_address; 83 | } AP_INFO; 84 | 85 | typedef std::vector AP_LIST; 86 | 87 | class wlanapi { 88 | public: 89 | const ADAPTER_LIST& get_adapter_list(); 90 | const AP_LIST& get_ap_list(ADAPTER_NAME *adapter_name); 91 | wlanapi(); 92 | virtual ~wlanapi(); 93 | protected: 94 | private: 95 | 96 | #ifdef WIN32 97 | 98 | void _ndis_get_adapter_list(); 99 | void _ndis_get_ap_list(ADAPTER_NAME *adapter_name); 100 | void _ndis_initiate(); 101 | void _ndis_shutdown(); 102 | 103 | void _wzc_get_adapter_list(); 104 | void _wlan_get_adapter_list(); 105 | 106 | void _wzc_get_ap_list(ADAPTER_NAME *adapter_name); 107 | void _wlan_get_ap_list(ADAPTER_NAME *adapter_name); 108 | 109 | HINSTANCE wzc_library; 110 | WZCEnumInterfacesFunction WZCEnumInterfaces; 111 | WZCQueryInterfaceFunction WZCQueryInterface; 112 | WZCRefreshInterfaceFunction WZCRefreshInterface; 113 | 114 | HINSTANCE wlan_library; 115 | HANDLE wlan_handle; 116 | WlanOpenHandleFunction WlanOpenHandle; 117 | WlanEnumInterfacesFunction WlanEnumInterfaces; 118 | WlanGetNetworkBssListFunction WlanGetNetworkBssList; 119 | WlanCloseHandleFunction WlanCloseHandle; 120 | WlanFreeMemoryFunction WlanFreeMemory; 121 | WlanGetAvailableNetworkListFunction WlanGetAvailableNetworkList; 122 | 123 | #else 124 | 125 | #ifdef DBUS 126 | void _dbus_get_adapter_list(); 127 | void _dbus_get_ap_list(ADAPTER_NAME *adapter_name); 128 | void _dbus_initiate(); 129 | void _dbus_shutdown(); 130 | DBusGConnection *dbus_connection; 131 | DBusGProxy *_dbus_nm_proxy; 132 | #endif 133 | 134 | #endif 135 | 136 | ADAPTER_LIST adapter_list; 137 | AP_LIST ap_list; 138 | 139 | typedef void (wlanapi::*GET_ADAPTER_LIST_FUNC)(); 140 | GET_ADAPTER_LIST_FUNC get_adapter_list_func; 141 | 142 | typedef void (wlanapi::*GET_AP_LIST_FUNC)(ADAPTER_NAME *adapter_name); 143 | GET_AP_LIST_FUNC get_ap_list_func; 144 | 145 | }; 146 | 147 | #endif // __WLANAPI_H_ 148 | -------------------------------------------------------------------------------- /library/wlanapi_exception.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * wlanapi library 0.4 3 | * 4 | * Copyright (C) 2008, 2009 Moritz Mertinkat 5 | * All rights reserved. 6 | * 7 | * wlanapi library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wlanapi library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details.* 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with wlanapi library. If not, see . 19 | */ 20 | 21 | #include "wlanapi_exception.h" 22 | 23 | wlanapi_exception::wlanapi_exception(const char* message, ...) : std::runtime_error::runtime_error(message) { 24 | 25 | va_list arguments; 26 | 27 | va_start(arguments, message); 28 | vsnprintf(msg, sizeof(msg), message, arguments); 29 | va_end(arguments); 30 | 31 | } 32 | 33 | const char *wlanapi_exception::what() const throw() { 34 | return msg; 35 | } 36 | -------------------------------------------------------------------------------- /library/wlanapi_exception.h: -------------------------------------------------------------------------------- 1 | /** 2 | * wlanapi library 0.4 3 | * 4 | * Copyright (C) 2008, 2009 Moritz Mertinkat 5 | * All rights reserved. 6 | * 7 | * wlanapi library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wlanapi library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details.* 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with wlanapi library. If not, see . 19 | */ 20 | 21 | #ifndef __WLANAPI_EXCEPTION_H_ 22 | #define __WLANAPI_EXCEPTION_H_ 23 | 24 | #include 25 | #include 26 | 27 | 28 | class wlanapi_exception : public std::runtime_error { 29 | public: 30 | wlanapi_exception(const char* message, ...); 31 | virtual const char * what() const throw(); 32 | protected: 33 | char msg[512]; 34 | private: 35 | }; 36 | 37 | #endif // __WLANAPI_EXCEPTION_H_ 38 | -------------------------------------------------------------------------------- /library/wlanapi_windows_ndisuio.h: -------------------------------------------------------------------------------- 1 | /** 2 | * wlanapi library 0.4 3 | * 4 | * Copyright (C) 2008, 2009 Moritz Mertinkat 5 | * All rights reserved. 6 | * 7 | * wlanapi library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wlanapi library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details.* 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with wlanapi library. If not, see . 19 | * 20 | * 21 | * The following information has been taken from MSDN. 22 | */ 23 | 24 | #ifndef __WLANAPI_WINDOWS_NDISUIO_H_ 25 | #define __WLANAPI_WINDOWS_NDISUIO_H_ 26 | 27 | #define OID_802_11_BSSID 0x0D010101 28 | #define OID_802_11_SSID 0x0D010102 29 | #define OID_802_11_NETWORK_TYPES_SUPPORTED 0x0D010203 30 | #define OID_802_11_NETWORK_TYPE_IN_USE 0x0D010204 31 | #define OID_802_11_TX_POWER_LEVEL 0x0D010205 32 | #define OID_802_11_RSSI 0x0D010206 33 | #define OID_802_11_RSSI_TRIGGER 0x0D010207 34 | #define OID_802_11_INFRASTRUCTURE_MODE 0x0D010108 35 | #define OID_802_11_FRAGMENTATION_THRESHOLD 0x0D010209 36 | #define OID_802_11_RTS_THRESHOLD 0x0D01020A 37 | #define OID_802_11_NUMBER_OF_ANTENNAS 0x0D01020B 38 | #define OID_802_11_RX_ANTENNA_SELECTED 0x0D01020C 39 | #define OID_802_11_TX_ANTENNA_SELECTED 0x0D01020D 40 | #define OID_802_11_SUPPORTED_RATES 0x0D01020E 41 | #define OID_802_11_DESIRED_RATES 0x0D010210 42 | #define OID_802_11_CONFIGURATION 0x0D010211 43 | #define OID_802_11_STATISTICS 0x0D020212 44 | #define OID_802_11_ADD_WEP 0x0D010113 45 | #define OID_802_11_REMOVE_WEP 0x0D010114 46 | #define OID_802_11_DISASSOCIATE 0x0D010115 47 | #define OID_802_11_POWER_MODE 0x0D010216 48 | #define OID_802_11_BSSID_LIST 0x0D010217 49 | #define OID_802_11_AUTHENTICATION_MODE 0x0D010118 50 | #define OID_802_11_PRIVACY_FILTER 0x0D010119 51 | #define OID_802_11_BSSID_LIST_SCAN 0x0D01011A 52 | #define OID_802_11_WEP_STATUS 0x0D01011B 53 | #define OID_802_11_RELOAD_DEFAULTS 0x0D01011C 54 | 55 | //#define IOCTL_NDISUIO_QUERY_OID_VALUE 0x120804 56 | 57 | #define _NDIS_CONTROL_CODE(request, method) \ 58 | CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, request, method, FILE_ANY_ACCESS) 59 | 60 | #define IOCTL_NDIS_QUERY_GLOBAL_STATS \ 61 | _NDIS_CONTROL_CODE(0, METHOD_OUT_DIRECT) 62 | 63 | 64 | #define FSCTL_NDISUIO_BASE FILE_DEVICE_NETWORK 65 | 66 | #define _NDISUIO_CTL_CODE(_Function, _Method, _Access) \ 67 | CTL_CODE(FSCTL_NDISUIO_BASE, _Function, _Method, _Access) 68 | 69 | // FILE_READ_ACCESS | FILE_WRITE_ACCESS vs. FILE_ANY_ACCESS 70 | 71 | #define IOCTL_NDISUIO_QUERY_OID_VALUE \ 72 | _NDISUIO_CTL_CODE(0x201, METHOD_BUFFERED, \ 73 | FILE_READ_ACCESS | FILE_WRITE_ACCESS) 74 | 75 | #define IOCTL_NDISUIO_SET_OID_VALUE \ 76 | _NDISUIO_CTL_CODE(0x205, METHOD_BUFFERED, \ 77 | FILE_READ_ACCESS | FILE_WRITE_ACCESS) 78 | 79 | #define IOCTL_NDISUIO_QUERY_BINDING \ 80 | _NDISUIO_CTL_CODE(0x203, METHOD_BUFFERED, \ 81 | FILE_READ_ACCESS | FILE_WRITE_ACCESS) 82 | 83 | #define IOCTL_NDISUIO_BIND_WAIT \ 84 | _NDISUIO_CTL_CODE(0x204, METHOD_BUFFERED, \ 85 | FILE_READ_ACCESS | FILE_WRITE_ACCESS) 86 | 87 | 88 | // http://msdn.microsoft.com/en-us/library/aa910075.aspx (NDIS_802_11_MAC_ADDRESS, Windows CE) 89 | typedef UCHAR NDIS_802_11_MAC_ADDRESS[6]; 90 | 91 | // http://msdn.microsoft.com/en-us/library/aa931485.aspx (NDIS_802_11_SSID, Windows CE) 92 | typedef struct _NDIS_802_11_SSID { 93 | ULONG SsidLength; 94 | UCHAR Ssid [32]; 95 | } NDIS_802_11_SSID, *PNDIS_802_11_SSID; 96 | 97 | // http://msdn.microsoft.com/en-us/library/aa929300.aspx (NDIS_802_11_RSSI, Windows CE) 98 | typedef LONG NDIS_802_11_RSSI; 99 | 100 | // http://msdn.microsoft.com/en-us/library/aa932076.aspx (NDIS_802_11_NETWORK_TYPE, Windows CE) 101 | typedef enum _NDIS_802_11_NETWORK_TYPE { 102 | Ndis802_11FH, 103 | Ndis802_11DS, 104 | Ndis802_11NetworkTypeMax, 105 | } NDIS_802_11_NETWORK_TYPE, *PNDIS_802_11_NETWORK_TYPE; 106 | 107 | // http://msdn.microsoft.com/en-us/library/aa447880.aspx (NDIS_802_11_CONFIGURATION_FH, Windows CE) 108 | typedef struct _NDIS_802_11_CONFIGURATION_FH { 109 | ULONG Length; 110 | ULONG HopPattern; 111 | ULONG HopSet; 112 | ULONG DwellTime; 113 | } NDIS_802_11_CONFIGURATION_FH, *PNDIS_802_11_CONFIGURATION_FH; 114 | 115 | // http://msdn.microsoft.com/en-us/library/aa930570.aspx (NDIS_802_11_CONFIGURATION, Windows CE) 116 | typedef struct _NDIS_802_11_CONFIGURATION 117 | { 118 | ULONG Length; 119 | ULONG BeaconPeriod; 120 | ULONG ATIMWindow; 121 | ULONG DSConfig; 122 | NDIS_802_11_CONFIGURATION_FH FHConfig; 123 | } NDIS_802_11_CONFIGURATION, *PNDIS_802_11_CONFIGURATION; 124 | 125 | // http://msdn.microsoft.com/en-us/library/aa931142.aspx (NDIS_802_11_NETWORK_INFRASTRUCTURE, Windows CE) 126 | typedef enum _NDIS_802_11_NETWORK_INFRASTRUCTURE { 127 | Ndis802_11IBSS, 128 | Ndis802_11Infrastructure, 129 | Ndis802_11AutoUnknown, 130 | Ndis802_11InfrastructureMax, 131 | } NDIS_802_11_NETWORK_INFRASTRUCTURE, *PNDIS_802_11_NETWORK_INFRASTRUCTURE; 132 | 133 | // http://msdn.microsoft.com/en-us/library/ms799391.aspx (only described here -- no struct, Windows XP) 134 | typedef UCHAR NDIS_802_11_RATES_EX[16]; 135 | 136 | // http://msdn.microsoft.com/en-us/library/ms799391.aspx (OID_802_11_BSSID_LIST, Windows XP) 137 | typedef struct _NDIS_WLAN_BSSID_EX 138 | { 139 | ULONG Length; 140 | NDIS_802_11_MAC_ADDRESS MacAddress; 141 | UCHAR Reserved[2]; 142 | NDIS_802_11_SSID Ssid; 143 | ULONG Privacy; 144 | NDIS_802_11_RSSI Rssi; 145 | NDIS_802_11_NETWORK_TYPE NetworkTypeInUse; 146 | NDIS_802_11_CONFIGURATION Configuration; 147 | NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode; 148 | NDIS_802_11_RATES_EX SupportedRates; 149 | ULONG IELength; 150 | UCHAR IEs[1]; 151 | } NDIS_WLAN_BSSID_EX, *PNDIS_WLAN_BSSID_EX; 152 | 153 | // http://msdn.microsoft.com/en-us/library/ms799391.aspx (OID_802_11_BSSID_LIST, Windows XP) 154 | typedef struct _NDIS_802_11_BSSID_LIST_EX 155 | { 156 | ULONG NumberOfItems; 157 | NDIS_WLAN_BSSID_EX Bssid[1]; 158 | } NDIS_802_11_BSSID_LIST_EX, *PNDIS_802_11_BSSID_LIST_EX; 159 | 160 | 161 | typedef ULONG NDIS_OID, *PNDIS_OID; 162 | 163 | typedef struct _NDISUIO_QUERY_BINDING { 164 | ULONG BindingIndex; 165 | ULONG DeviceNameOffset; 166 | ULONG DeviceNameLength; 167 | ULONG DeviceDescrOffset; 168 | ULONG DeviceDescrLength; 169 | } NDISUIO_QUERY_BINDING, *PNDISUIO_QUERY_BINDING; 170 | 171 | typedef struct _NDISUIO_SET_OID { 172 | NDIS_OID Oid; 173 | #ifdef UNDER_CE 174 | PTCHAR ptcDeviceName; 175 | #endif 176 | UCHAR Data[sizeof(ULONG)]; 177 | } NDISUIO_SET_OID, *PNDISUIO_SET_OID; 178 | 179 | #endif 180 | -------------------------------------------------------------------------------- /library/wlanapi_windows_wlan.h: -------------------------------------------------------------------------------- 1 | /** 2 | * wlanapi library 0.4 3 | * 4 | * Copyright (C) 2008, 2009 Moritz Mertinkat 5 | * All rights reserved. 6 | * 7 | * wlanapi library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wlanapi library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details.* 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with wlanapi library. If not, see . 19 | * 20 | * 21 | * The following information has been taken from MSDN. 22 | */ 23 | 24 | #ifndef __WLANAPI_WINDOWS_WLAN_H_ 25 | #define __WLANAPI_WINDOWS_WLAN_H_ 26 | 27 | typedef enum _WLAN_INTERFACE_STATE { 28 | wlan_interface_state_not_ready = 0, 29 | wlan_interface_state_connected = 1, 30 | wlan_interface_state_ad_hoc_network_formed = 2, 31 | wlan_interface_state_disconnecting = 3, 32 | wlan_interface_state_disconnected = 4, 33 | wlan_interface_state_associating = 5, 34 | wlan_interface_state_discovering = 6, 35 | wlan_interface_state_authenticating = 7 36 | } WLAN_INTERFACE_STATE, *PWLAN_INTERFACE_STATE; 37 | 38 | typedef struct _WLAN_INTERFACE_INFO { 39 | GUID InterfaceGuid; 40 | WCHAR strInterfaceDescription[256]; 41 | WLAN_INTERFACE_STATE isState; 42 | } WLAN_INTERFACE_INFO, *PWLAN_INTERFACE_INFO; 43 | 44 | typedef struct _WLAN_INTERFACE_INFO_LIST { 45 | DWORD dwNumberOfItems; 46 | DWORD dwIndex; 47 | WLAN_INTERFACE_INFO InterfaceInfo[]; 48 | } WLAN_INTERFACE_INFO_LIST, *PWLAN_INTERFACE_INFO_LIST; 49 | 50 | typedef UCHAR DOT11_MAC_ADDRESS[6]; 51 | 52 | typedef DOT11_MAC_ADDRESS* PDOT11_MAC_ADDRESS; 53 | 54 | typedef enum _DOT11_BSS_TYPE { 55 | dot11_BSS_type_infrastructure = 1, 56 | dot11_BSS_type_independent = 2, 57 | dot11_BSS_type_any = 3 58 | } DOT11_BSS_TYPE, *PDOT11_BSS_TYPE; 59 | 60 | 61 | #define DOT11_SSID_MAX_LENGTH 32 62 | 63 | typedef struct _DOT11_SSID { 64 | ULONG uSSIDLength; 65 | UCHAR ucSSID[DOT11_SSID_MAX_LENGTH]; 66 | } DOT11_SSID, *PDOT11_SSID; 67 | 68 | typedef enum _DOT11_PHY_TYPE { 69 | dot11_phy_type_unknown, 70 | dot11_phy_type_any, 71 | dot11_phy_type_fhss, 72 | dot11_phy_type_dsss, 73 | dot11_phy_type_irbaseband, 74 | dot11_phy_type_ofdm, 75 | dot11_phy_type_hrdsss, 76 | dot11_phy_type_erp, 77 | dot11_phy_type_ht, 78 | dot11_phy_type_IHV_start, 79 | dot11_phy_type_IHV_end 80 | } DOT11_PHY_TYPE, *PDOT11_PHY_TYPE; 81 | 82 | #define DOT11_RATE_SET_MAX_LENGTH 126 83 | 84 | typedef struct _WLAN_RATE_SET { 85 | ULONG uRateSetLength; 86 | USHORT usRateSet[DOT11_RATE_SET_MAX_LENGTH]; 87 | } WLAN_RATE_SET, *PWLAN_RATE_SET; 88 | 89 | typedef struct _WLAN_BSS_ENTRY { 90 | DOT11_SSID dot11Ssid; 91 | ULONG uPhyId; 92 | DOT11_MAC_ADDRESS dot11Bssid; 93 | DOT11_BSS_TYPE dot11BssType; 94 | DOT11_PHY_TYPE dot11BssPhyType; 95 | LONG lRssi; 96 | ULONG uLinkQuality; 97 | BOOLEAN bInRegDomain; 98 | USHORT usBeaconPeriod; 99 | ULONGLONG ullTimestamp; 100 | ULONGLONG ullHostTimestamp; 101 | USHORT usCapabilityInformation; 102 | ULONG ulChCenterFrequency; 103 | WLAN_RATE_SET wlanRateSet; 104 | ULONG ulIeOffset; 105 | ULONG ulIeSize; 106 | } WLAN_BSS_ENTRY, *PWLAN_BSS_ENTRY; 107 | 108 | typedef struct _WLAN_BSS_LIST { 109 | DWORD dwTotalSize; 110 | DWORD dwNumberOfItems; 111 | WLAN_BSS_ENTRY wlanBssEntries[1]; 112 | } WLAN_BSS_LIST, *PWLAN_BSS_LIST; 113 | 114 | 115 | /******************/ 116 | 117 | typedef DWORD WLAN_REASON_CODE, *PWLAN_REASON_CODE; 118 | 119 | #define WLAN_MAX_PHY_TYPE_NUMBER 8 120 | 121 | typedef ULONG WLAN_SIGNAL_QUALITY; 122 | 123 | typedef enum DOT11_AUTH_ALGORITHM { 124 | DOT11_AUTH_ALGO_80211_OPEN, 125 | DOT11_AUTH_ALGO_80211_SHARED_KEY, 126 | DOT11_AUTH_ALGO_WPA, 127 | DOT11_AUTH_ALGO_WPA_PSK, 128 | DOT11_AUTH_ALGO_RSNA, 129 | DOT11_AUTH_ALGO_RSNA_PSK, 130 | DOT11_AUTH_ALGO_IHV_START, 131 | DOT11_AUTH_ALGO_IHV_END 132 | } DOT11_AUTH_ALGORITHM, *PDOT11_AUTH_ALGORITHM; 133 | 134 | typedef enum DOT11_CIPHER_ALGORITHM { 135 | DOT11_CIPHER_ALGO_NONE, 136 | DOT11_CIPHER_ALGO_WEP40, 137 | DOT11_CIPHER_ALGO_TKIP, 138 | DOT11_CIPHER_ALGO_CCMP, 139 | DOT11_CIPHER_ALGO_WEP104, 140 | DOT11_CIPHER_ALGO_WEP, 141 | DOT11_CIPHER_ALGO_IHV_START, 142 | DOT11_CIPHER_ALGO_IHV_END 143 | } DOT11_CIPHER_ALGORITHM, *PDOT11_CIPHER_ALGORITHM; 144 | 145 | typedef struct _WLAN_AVAILABLE_NETWORK { 146 | WCHAR strProfileName[256]; 147 | DOT11_SSID dot11Ssid; 148 | DOT11_BSS_TYPE dot11BssType; 149 | ULONG uNumberOfBssids; 150 | BOOL bNetworkConnectable; 151 | WLAN_REASON_CODE wlanNotConnectableReason; 152 | ULONG uNumberOfPhyTypes; 153 | DOT11_PHY_TYPE dot11PhyTypes[WLAN_MAX_PHY_TYPE_NUMBER]; 154 | BOOL bMorePhyTypes; 155 | WLAN_SIGNAL_QUALITY wlanSignalQuality; 156 | BOOL bSecurityEnabled; 157 | DOT11_AUTH_ALGORITHM dot11DefaultAuthAlgorithm; 158 | DOT11_CIPHER_ALGORITHM dot11DefaultCipherAlgorithm; 159 | DWORD dwFlags; 160 | DWORD dwReserved; 161 | } WLAN_AVAILABLE_NETWORK, *PWLAN_AVAILABLE_NETWORK; 162 | 163 | typedef struct _WLAN_AVAILABLE_NETWORK_LIST { 164 | DWORD dwNumberOfItems; 165 | DWORD dwIndex; 166 | WLAN_AVAILABLE_NETWORK Network[1]; 167 | } WLAN_AVAILABLE_NETWORK_LIST, *PWLAN_AVAILABLE_NETWORK_LIST; 168 | 169 | typedef DWORD (WINAPI *WlanGetAvailableNetworkListFunction)( 170 | HANDLE hClientHandle, 171 | const GUID *pInterfaceGuid, 172 | DWORD dwFlags, 173 | PVOID pReserved, 174 | PWLAN_AVAILABLE_NETWORK_LIST *ppAvailableNetworkList 175 | ); 176 | 177 | 178 | /******************/ 179 | 180 | // Native Wifi Functions 181 | 182 | typedef DWORD (WINAPI *WlanOpenHandleFunction)( 183 | DWORD dwClientVersion, 184 | PVOID pReserved, 185 | PDWORD pdwNegotiatedVersion, 186 | PHANDLE phClientHandle 187 | ); 188 | 189 | typedef DWORD (WINAPI *WlanEnumInterfacesFunction)( 190 | HANDLE hClientHandle, 191 | PVOID pReserved, 192 | PWLAN_INTERFACE_INFO_LIST *ppInterfaceList 193 | ); 194 | 195 | typedef DWORD (WINAPI *WlanGetNetworkBssListFunction)( 196 | HANDLE hClientHandle, 197 | const GUID *pInterfaceGuid, 198 | const PDOT11_SSID pDot11Ssid, 199 | DOT11_BSS_TYPE dot11BssType, 200 | BOOL bSecurityEnabled, 201 | PVOID pReserved, 202 | PWLAN_BSS_LIST *ppWlanBssList 203 | ); 204 | 205 | typedef DWORD (WINAPI *WlanCloseHandleFunction)( 206 | HANDLE hClientHandle, 207 | PVOID pReserved 208 | ); 209 | 210 | typedef VOID (WINAPI *WlanFreeMemoryFunction)( 211 | PVOID pMemory 212 | ); 213 | 214 | #endif 215 | -------------------------------------------------------------------------------- /library/wlanapi_windows_wzc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * wlanapi library 0.4 3 | * 4 | * Copyright (C) 2008, 2009 Moritz Mertinkat 5 | * All rights reserved. 6 | * 7 | * wlanapi library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wlanapi library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details.* 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with wlanapi library. If not, see . 19 | * 20 | * 21 | * The following information has been taken from MSDN. 22 | */ 23 | 24 | #ifndef __WLANAPI_WINDOWS_WZC_H_ 25 | #define __WLANAPI_WINDOWS_WZC_H_ 26 | 27 | #define INTF_DESCR (0x00010000) 28 | #define INTF_BSSIDLIST (0x04000000) 29 | #define INTF_LIST_SCAN (0x08000000) 30 | //#define INTF_BSSIDLIST 0xFFFFFFFF 31 | 32 | // WZCEnumInterfaces 33 | 34 | typedef struct { 35 | LPWSTR wszGuid; 36 | } INTF_KEY_ENTRY, *PINTF_KEY_ENTRY; 37 | 38 | typedef struct { 39 | DWORD dwNumIntfs; 40 | PINTF_KEY_ENTRY pIntfs; 41 | } INTFS_KEY_TABLE, *PINTFS_KEY_TABLE; 42 | 43 | typedef DWORD (WINAPI *WZCEnumInterfacesFunction)(LPWSTR pSrvAddr, PINTFS_KEY_TABLE pIntfs); 44 | 45 | // WZCQueryInterface 46 | 47 | typedef struct { 48 | DWORD dwDataLen; 49 | LPBYTE pData; 50 | } RAW_DATA, *PRAW_DATA; 51 | 52 | typedef struct { 53 | LPWSTR wszGuid; 54 | LPWSTR wszDescr; 55 | ULONG ulMediaState; 56 | ULONG ulMediaType; 57 | ULONG ulPhysicalMediaType; 58 | INT nInfraMode; 59 | INT nAuthMode; 60 | INT nWepStatus; 61 | ULONG padding1[2]; // 16 chars on Windows XP SP3 or SP2 with WLAN Hotfix installed, 8 chars otherwise 62 | DWORD dwCtlFlags; 63 | DWORD dwCapabilities; 64 | RAW_DATA rdSSID; 65 | RAW_DATA rdBSSID; 66 | RAW_DATA rdBSSIDList; 67 | RAW_DATA rdStSSIDList; 68 | RAW_DATA rdCtrlData; 69 | BOOL bInitialized; 70 | ULONG padding2[64]; // for security reason ... 71 | } INTF_ENTRY, *PINTF_ENTRY; 72 | 73 | typedef DWORD (WINAPI *WZCQueryInterfaceFunction)(LPWSTR pSrvAddr, DWORD dwInFlags, PINTF_ENTRY pIntf, LPDWORD pdwOutFlags); 74 | 75 | 76 | // This structure is not quite the same as the WinCE equivalent. 77 | typedef struct _NDIS_WLAN_BSSID { 78 | UCHAR padding1[4]; 79 | ULONG Length; 80 | UCHAR padding2[4]; 81 | NDIS_802_11_MAC_ADDRESS MacAddress; 82 | UCHAR Reserved[2]; 83 | NDIS_802_11_SSID Ssid; 84 | ULONG Privacy; 85 | NDIS_802_11_RSSI Rssi; 86 | } NDIS_WLAN_BSSID, *PNDIS_WLAN_BSSID; 87 | 88 | typedef struct _NDIS_802_11_BSSID_LIST { 89 | ULONG NumberOfItems; 90 | NDIS_WLAN_BSSID Bssid[1]; 91 | } NDIS_802_11_BSSID_LIST, *PNDIS_802_11_BSSID_LIST; 92 | 93 | 94 | 95 | typedef DWORD (WINAPI *WZCRefreshInterfaceFunction)( 96 | LPWSTR pSrvAddr, 97 | DWORD dwInFlags, 98 | PINTF_ENTRY pIntf, 99 | LPDWORD pdwOutFlags 100 | ); 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------