blob: aeb01634df12e88f523f18962a002143ca9845ab [file] [log] [blame]
Sen Jiang255e22b2016-05-20 16:15:29 -07001//
2// Copyright (C) 2016 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#include "update_engine/connection_utils.h"
18
19#include <shill/dbus-constants.h>
20
Colin Howesc9e98d62018-09-18 10:35:20 -070021namespace {
22// Not defined by shill since we don't use this outside of UE.
23constexpr char kTypeDisconnected[] = "Disconnected";
24constexpr char kTypeUnknown[] = "Unknown";
25} // namespace
26
Sen Jiang255e22b2016-05-20 16:15:29 -070027namespace chromeos_update_engine {
28namespace connection_utils {
29
30ConnectionType ParseConnectionType(const std::string& type_str) {
31 if (type_str == shill::kTypeEthernet) {
32 return ConnectionType::kEthernet;
33 } else if (type_str == shill::kTypeWifi) {
34 return ConnectionType::kWifi;
35 } else if (type_str == shill::kTypeWimax) {
36 return ConnectionType::kWimax;
37 } else if (type_str == shill::kTypeBluetooth) {
38 return ConnectionType::kBluetooth;
39 } else if (type_str == shill::kTypeCellular) {
40 return ConnectionType::kCellular;
Colin Howesc9e98d62018-09-18 10:35:20 -070041 } else if (type_str == kTypeDisconnected) {
42 return ConnectionType::kDisconnected;
Sen Jiang255e22b2016-05-20 16:15:29 -070043 }
44 return ConnectionType::kUnknown;
45}
46
47ConnectionTethering ParseConnectionTethering(const std::string& tethering_str) {
48 if (tethering_str == shill::kTetheringNotDetectedState) {
49 return ConnectionTethering::kNotDetected;
50 } else if (tethering_str == shill::kTetheringSuspectedState) {
51 return ConnectionTethering::kSuspected;
52 } else if (tethering_str == shill::kTetheringConfirmedState) {
53 return ConnectionTethering::kConfirmed;
54 }
55 return ConnectionTethering::kUnknown;
56}
57
58const char* StringForConnectionType(ConnectionType type) {
59 switch (type) {
60 case ConnectionType::kEthernet:
61 return shill::kTypeEthernet;
62 case ConnectionType::kWifi:
63 return shill::kTypeWifi;
64 case ConnectionType::kWimax:
65 return shill::kTypeWimax;
66 case ConnectionType::kBluetooth:
67 return shill::kTypeBluetooth;
68 case ConnectionType::kCellular:
69 return shill::kTypeCellular;
Colin Howesc9e98d62018-09-18 10:35:20 -070070 case ConnectionType::kDisconnected:
71 return kTypeDisconnected;
Sen Jiang255e22b2016-05-20 16:15:29 -070072 case ConnectionType::kUnknown:
Colin Howesc9e98d62018-09-18 10:35:20 -070073 return kTypeUnknown;
Sen Jiang255e22b2016-05-20 16:15:29 -070074 }
Colin Howesc9e98d62018-09-18 10:35:20 -070075 return kTypeUnknown;
Sen Jiang255e22b2016-05-20 16:15:29 -070076}
77
78} // namespace connection_utils
79
80} // namespace chromeos_update_engine