1 // Copyright 2013 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.
5 #ifndef CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_
6 #define CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "chromeos/chromeos_export.h"
14 class DictionaryValue;
22 namespace shill_property_util {
24 // Sets the |ssid| in |properties|.
25 CHROMEOS_EXPORT void SetSSID(const std::string ssid,
26 base::DictionaryValue* properties);
28 // Returns the SSID from |properties| in UTF-8 encoding. If |unknown_encoding|
29 // is not NULL, it is set to whether the SSID is of unknown encoding.
30 CHROMEOS_EXPORT std::string GetSSIDFromProperties(
31 const base::DictionaryValue& properties,
32 bool* unknown_encoding);
34 // Returns the GUID (if available), SSID, or Name from |properties|. Only used
35 // for logging and debugging.
36 CHROMEOS_EXPORT std::string GetNetworkIdFromProperties(
37 const base::DictionaryValue& properties);
39 // Returns the name for the network represented by the Shill |properties|. For
40 // WiFi it refers to the HexSSID.
41 CHROMEOS_EXPORT std::string GetNameFromProperties(
42 const std::string& service_path,
43 const base::DictionaryValue& properties);
45 // Returns the UIData specified by |value|. Returns NULL if the value cannot be
47 scoped_ptr<NetworkUIData> GetUIDataFromValue(const base::Value& value);
49 // Returns the NetworkUIData parsed from the UIData property of
50 // |shill_dictionary|. If parsing fails or the field doesn't exist, returns
52 scoped_ptr<NetworkUIData> GetUIDataFromProperties(
53 const base::DictionaryValue& shill_dictionary);
55 // Sets the UIData property in |shill_dictionary| to the serialization of
57 void SetUIData(const NetworkUIData& ui_data,
58 base::DictionaryValue* shill_dictionary);
60 // Copy configuration properties required by Shill to identify a network.
61 // Only WiFi, VPN, Ethernet and EthernetEAP are supported. WiMax and Cellular
62 // are not supported. Returns true only if all required properties could be
64 bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties,
65 base::DictionaryValue* dest);
67 // Compares the identifying configuration properties of |properties_a| and
68 // |properties_b|, returns true if they are identical. See also
69 // CopyIdentifyingProperties. Only WiFi, VPN, Ethernet and EthernetEAP are
70 // supported. WiMax and Cellular are not supported.
71 bool DoIdentifyingPropertiesMatch(const base::DictionaryValue& properties_a,
72 const base::DictionaryValue& properties_b);
74 // Returns true if |key| corresponds to a passphrase property.
75 bool IsPassphraseKey(const std::string& key);
77 } // namespace shill_property_util
79 class CHROMEOS_EXPORT NetworkTypePattern {
81 // Matches any network.
82 static NetworkTypePattern Default();
84 // Matches wireless (WiFi, cellular, etc.) networks
85 static NetworkTypePattern Wireless();
87 // Matches cellular or wimax networks.
88 static NetworkTypePattern Mobile();
90 // Matches non virtual networks.
91 static NetworkTypePattern NonVirtual();
93 // Matches ethernet networks (with or without EAP).
94 static NetworkTypePattern Ethernet();
96 static NetworkTypePattern WiFi();
97 static NetworkTypePattern Cellular();
98 static NetworkTypePattern VPN();
99 static NetworkTypePattern Wimax();
101 // Matches only networks of exactly the type |shill_network_type|, which must
102 // be one of the types defined in service_constants.h (e.g.
103 // shill::kTypeWifi).
104 // Note: Shill distinguishes Ethernet without EAP from Ethernet with EAP. If
105 // unsure, better use one of the matchers above.
106 static NetworkTypePattern Primitive(const std::string& shill_network_type);
108 bool Equals(const NetworkTypePattern& other) const;
109 bool MatchesType(const std::string& shill_network_type) const;
111 // Returns true if this pattern matches at least one network type that
112 // |other_pattern| matches (according to MatchesType). Thus MatchesPattern is
113 // symmetric and reflexive but not transitive.
114 // See the unit test for examples.
115 bool MatchesPattern(const NetworkTypePattern& other_pattern) const;
117 std::string ToDebugString() const;
120 explicit NetworkTypePattern(int pattern);
122 // The bit array of the matching network types.
125 DISALLOW_ASSIGN(NetworkTypePattern);
128 } // namespace chromeos
130 #endif // CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_