| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // We use the OSX system API function WirelessScanSplit. This function is not |
| 6 // documented or included in the SDK, so we use a reverse-engineered header, |
| 7 // osx_wifi_.h. This file is taken from the iStumbler project |
| 8 // (http://www.istumbler.net). |
| 9 |
| 10 // TODO(joth): port to chromium |
| 11 #if 0 |
| 12 |
| 13 #include "gears/geolocation/wifi_data_provider_osx.h" |
| 14 |
| 15 #include <dlfcn.h> |
| 16 #include <stdio.h> |
| 17 #include "gears/base/common/string_utils.h" |
| 18 #include "gears/geolocation/wifi_data_provider_common.h" |
| 19 |
| 20 // The time periods, in milliseconds, between successive polls of the wifi data. |
| 21 extern const int kDefaultPollingInterval = 120000; // 2 mins |
| 22 extern const int kNoChangePollingInterval = 300000; // 5 mins |
| 23 extern const int kTwoNoChangePollingInterval = 600000; // 10 mins |
| 24 |
| 25 // static |
| 26 template<> |
| 27 WifiDataProviderImplBase *WifiDataProvider::DefaultFactoryFunction() { |
| 28 return new OsxWifiDataProvider(); |
| 29 } |
| 30 |
| 31 |
| 32 OsxWifiDataProvider::OsxWifiDataProvider() : is_first_scan_complete_(false) { |
| 33 Start(); |
| 34 } |
| 35 |
| 36 OsxWifiDataProvider::~OsxWifiDataProvider() { |
| 37 stop_event_.Signal(); |
| 38 Join(); |
| 39 } |
| 40 |
| 41 bool OsxWifiDataProvider::GetData(WifiData *data) { |
| 42 assert(data); |
| 43 MutexLock lock(&data_mutex_); |
| 44 *data = wifi_data_; |
| 45 // If we've successfully completed a scan, indicate that we have all of the |
| 46 // data we can get. |
| 47 return is_first_scan_complete_; |
| 48 } |
| 49 |
| 50 // Thread implementation |
| 51 void OsxWifiDataProvider::Run() { |
| 52 void *apple_80211_library = dlopen( |
| 53 "/System/Library/PrivateFrameworks/Apple80211.framework/Apple80211", |
| 54 RTLD_LAZY); |
| 55 if (!apple_80211_library) { |
| 56 is_first_scan_complete_ = true; |
| 57 return; |
| 58 } |
| 59 |
| 60 WirelessAttach_function_ = reinterpret_cast<WirelessAttachFunction>( |
| 61 dlsym(apple_80211_library, "WirelessAttach")); |
| 62 WirelessScanSplit_function_ = reinterpret_cast<WirelessScanSplitFunction>( |
| 63 dlsym(apple_80211_library, "WirelessScanSplit")); |
| 64 WirelessDetach_function_ = reinterpret_cast<WirelessDetachFunction>( |
| 65 dlsym(apple_80211_library, "WirelessDetach")); |
| 66 assert(WirelessAttach_function_ && |
| 67 WirelessScanSplit_function_ && |
| 68 WirelessDetach_function_); |
| 69 |
| 70 if ((*WirelessAttach_function_)(&wifi_context_, 0) != noErr) { |
| 71 is_first_scan_complete_ = true; |
| 72 return; |
| 73 } |
| 74 |
| 75 // Regularly get the access point data. |
| 76 int polling_interval = kDefaultPollingInterval; |
| 77 do { |
| 78 WifiData new_data; |
| 79 GetAccessPointData(&new_data.access_point_data); |
| 80 bool update_available; |
| 81 data_mutex_.Lock(); |
| 82 update_available = wifi_data_.DiffersSignificantly(new_data); |
| 83 wifi_data_ = new_data; |
| 84 data_mutex_.Unlock(); |
| 85 polling_interval = |
| 86 UpdatePollingInterval(polling_interval, update_available); |
| 87 if (update_available) { |
| 88 is_first_scan_complete_ = true; |
| 89 NotifyListeners(); |
| 90 } |
| 91 } while (!stop_event_.WaitWithTimeout(polling_interval)); |
| 92 |
| 93 (*WirelessDetach_function_)(wifi_context_); |
| 94 |
| 95 dlclose(apple_80211_library); |
| 96 } |
| 97 |
| 98 void OsxWifiDataProvider::GetAccessPointData( |
| 99 WifiData::AccessPointDataSet *access_points) { |
| 100 assert(access_points); |
| 101 assert(WirelessScanSplit_function_); |
| 102 CFArrayRef managed_access_points = NULL; |
| 103 CFArrayRef adhoc_access_points = NULL; |
| 104 if ((*WirelessScanSplit_function_)(wifi_context_, |
| 105 &managed_access_points, |
| 106 &adhoc_access_points, |
| 107 0) != noErr) { |
| 108 return; |
| 109 } |
| 110 |
| 111 if (managed_access_points == NULL) { |
| 112 return; |
| 113 } |
| 114 |
| 115 int num_access_points = CFArrayGetCount(managed_access_points); |
| 116 for (int i = 0; i < num_access_points; ++i) { |
| 117 const WirelessNetworkInfo *access_point_info = |
| 118 reinterpret_cast<const WirelessNetworkInfo*>( |
| 119 CFDataGetBytePtr( |
| 120 reinterpret_cast<const CFDataRef>( |
| 121 CFArrayGetValueAtIndex(managed_access_points, i)))); |
| 122 |
| 123 // Currently we get only MAC address, signal strength, channel |
| 124 // signal-to-noise and SSID |
| 125 // TODO(steveblock): Work out how to get age. |
| 126 AccessPointData access_point_data; |
| 127 access_point_data.mac_address = |
| 128 MacAddressAsString16(access_point_info->macAddress); |
| 129 // WirelessNetworkInfo::signal appears to be signal strength in dBm. |
| 130 access_point_data.radio_signal_strength = access_point_info->signal; |
| 131 access_point_data.channel = access_point_info->channel; |
| 132 // WirelessNetworkInfo::noise appears to be noise floor in dBm. |
| 133 access_point_data.signal_to_noise = access_point_info->signal - |
| 134 access_point_info->noise; |
| 135 string16 ssid; |
| 136 if (UTF8ToString16(reinterpret_cast<const char*>(access_point_info->name), |
| 137 access_point_info->nameLen, |
| 138 &ssid)) { |
| 139 access_point_data.ssid = ssid; |
| 140 } |
| 141 |
| 142 access_points->insert(access_point_data); |
| 143 } |
| 144 } |
| 145 |
| 146 #endif // 0 |
| OLD | NEW |