File: wifi_access_point_info_provider_chromeos.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (123 lines) | stat: -rw-r--r-- 4,722 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/metrics/net/wifi_access_point_info_provider_chromeos.h"

#include <stdint.h>

#include "base/bind.h"
#include "base/location.h"
#include "base/strings/string_number_conversions.h"
#include "chromeos/network/network_configuration_handler.h"
#include "chromeos/network/network_handler.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/shill_property_util.h"
#include "third_party/cros_system_api/dbus/service_constants.h"

using chromeos::NetworkHandler;

namespace metrics {

WifiAccessPointInfoProviderChromeos::WifiAccessPointInfoProviderChromeos() {
  NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE);

  // Update initial connection state.
  DefaultNetworkChanged(
      NetworkHandler::Get()->network_state_handler()->DefaultNetwork());
}

WifiAccessPointInfoProviderChromeos::~WifiAccessPointInfoProviderChromeos() {
  NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
                                                                 FROM_HERE);
}

bool WifiAccessPointInfoProviderChromeos::GetInfo(WifiAccessPointInfo* info) {
  // Wifi access point information is not provided if the BSSID is empty.
  // This assumes the BSSID is never empty when access point information exists.
  if (wifi_access_point_info_.bssid.empty())
    return false;

  *info = wifi_access_point_info_;
  return true;
}

void WifiAccessPointInfoProviderChromeos::DefaultNetworkChanged(
    const chromeos::NetworkState* default_network) {
  // Reset access point info to prevent reporting of out-dated data.
  wifi_access_point_info_ = WifiAccessPointInfo();

  // Skip non-wifi connections
  if (!default_network || default_network->type() != shill::kTypeWifi)
    return;

  // Retrieve access point info for wifi connection.
  NetworkHandler::Get()->network_configuration_handler()->GetShillProperties(
      default_network->path(),
      base::Bind(&WifiAccessPointInfoProviderChromeos::ParseInfo, AsWeakPtr()),
      chromeos::network_handler::ErrorCallback());
}

void WifiAccessPointInfoProviderChromeos::ParseInfo(
    const std::string &service_path,
    const base::DictionaryValue& properties) {
  // Skip services that contain "_nomap" in the SSID.
  std::string ssid = chromeos::shill_property_util::GetSSIDFromProperties(
      properties, false /* verbose_logging */, nullptr);
  if (ssid.find("_nomap", 0) != std::string::npos)
    return;

  std::string bssid;
  if (!properties.GetStringWithoutPathExpansion(shill::kWifiBSsid, &bssid) ||
      bssid.empty())
    return;

  // Filter out BSSID with local bit set in the first byte.
  uint32_t first_octet;
  if (!base::HexStringToUInt(bssid.substr(0, 2), &first_octet))
    NOTREACHED();
  if (first_octet & 0x2)
    return;
  wifi_access_point_info_.bssid = bssid;

  // Parse security info.
  std::string security;
  properties.GetStringWithoutPathExpansion(
      shill::kSecurityProperty, &security);
  wifi_access_point_info_.security = WIFI_SECURITY_UNKNOWN;
  if (security == shill::kSecurityWpa)
    wifi_access_point_info_.security = WIFI_SECURITY_WPA;
  else if (security == shill::kSecurityWep)
    wifi_access_point_info_.security = WIFI_SECURITY_WEP;
  else if (security == shill::kSecurityRsn)
    wifi_access_point_info_.security = WIFI_SECURITY_RSN;
  else if (security == shill::kSecurity8021x)
    wifi_access_point_info_.security = WIFI_SECURITY_802_1X;
  else if (security == shill::kSecurityPsk)
    wifi_access_point_info_.security = WIFI_SECURITY_PSK;
  else if (security == shill::kSecurityNone)
    wifi_access_point_info_.security = WIFI_SECURITY_NONE;

  properties.GetStringWithoutPathExpansion(
      shill::kWifiBSsid, &wifi_access_point_info_.bssid);
  const base::DictionaryValue* vendor_dict = NULL;
  if (!properties.GetDictionaryWithoutPathExpansion(
          shill::kWifiVendorInformationProperty,
          &vendor_dict))
    return;

  vendor_dict->GetStringWithoutPathExpansion(
      shill::kVendorWPSModelNumberProperty,
      &wifi_access_point_info_.model_number);
  vendor_dict->GetStringWithoutPathExpansion(
      shill::kVendorWPSModelNameProperty,
      &wifi_access_point_info_.model_name);
  vendor_dict->GetStringWithoutPathExpansion(
      shill::kVendorWPSDeviceNameProperty,
      &wifi_access_point_info_.device_name);
  vendor_dict->GetStringWithoutPathExpansion(shill::kVendorOUIListProperty,
                                             &wifi_access_point_info_.oui_list);
}

}  // namespace metrics