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 name for the network represented by the Shill |properties|. For
35 // WiFi it refers to the HexSSID.
36 CHROMEOS_EXPORT std::string GetNameFromProperties(
37 const std::string& service_path,
38 const base::DictionaryValue& properties);
40 // Returns the UIData specified by |value|. Returns NULL if the value cannot be
42 scoped_ptr<NetworkUIData> GetUIDataFromValue(const base::Value& value);
44 // Returns the NetworkUIData parsed from the UIData property of
45 // |shill_dictionary|. If parsing fails or the field doesn't exist, returns
47 scoped_ptr<NetworkUIData> GetUIDataFromProperties(
48 const base::DictionaryValue& shill_dictionary);
50 // Sets the UIData property in |shill_dictionary| to the serialization of
52 void SetUIData(const NetworkUIData& ui_data,
53 base::DictionaryValue* shill_dictionary);
55 // Copy configuration properties required by Shill to identify a network.
56 // Only WiFi, VPN, Ethernet and EthernetEAP are supported. WiMax and Cellular
57 // are not supported. Returns true only if all required properties could be
59 bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties,
60 base::DictionaryValue* dest);
62 } // namespace shill_property_util
64 class CHROMEOS_EXPORT NetworkTypePattern {
66 // Matches any network.
67 static NetworkTypePattern Default();
69 // Matches wireless networks
70 static NetworkTypePattern Wireless();
72 // Matches cellular or wimax networks.
73 static NetworkTypePattern Mobile();
75 // Matches non virtual networks.
76 static NetworkTypePattern NonVirtual();
78 // Matches ethernet networks (with or without EAP).
79 static NetworkTypePattern Ethernet();
81 static NetworkTypePattern WiFi();
82 static NetworkTypePattern Cellular();
83 static NetworkTypePattern VPN();
84 static NetworkTypePattern Wimax();
86 // Matches only networks of exactly the type |shill_network_type|, which must
87 // be one of the types defined in service_constants.h (e.g.
89 // Note: Shill distinguishes Ethernet without EAP from Ethernet with EAP. If
90 // unsure, better use one of the matchers above.
91 static NetworkTypePattern Primitive(const std::string& shill_network_type);
93 bool Equals(const NetworkTypePattern& other) const;
94 bool MatchesType(const std::string& shill_network_type) const;
96 // Returns true if this pattern matches at least one network type that
97 // |other_pattern| matches (according to MatchesType). Thus MatchesPattern is
98 // symmetric and reflexive but not transitive.
99 // See the unit test for examples.
100 bool MatchesPattern(const NetworkTypePattern& other_pattern) const;
102 std::string ToDebugString() const;
105 explicit NetworkTypePattern(int pattern);
107 // The bit array of the matching network types.
110 DISALLOW_ASSIGN(NetworkTypePattern);
113 } // namespace chromeos
115 #endif // CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_