1//
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
21namespace chromeos_update_engine {
22namespace connection_utils {
23
24ConnectionType ParseConnectionType(const std::string& type_str) {
25  if (type_str == shill::kTypeEthernet) {
26    return ConnectionType::kEthernet;
27  } else if (type_str == shill::kTypeWifi) {
28    return ConnectionType::kWifi;
29  } else if (type_str == shill::kTypeWimax) {
30    return ConnectionType::kWimax;
31  } else if (type_str == shill::kTypeBluetooth) {
32    return ConnectionType::kBluetooth;
33  } else if (type_str == shill::kTypeCellular) {
34    return ConnectionType::kCellular;
35  }
36  return ConnectionType::kUnknown;
37}
38
39ConnectionTethering ParseConnectionTethering(const std::string& tethering_str) {
40  if (tethering_str == shill::kTetheringNotDetectedState) {
41    return ConnectionTethering::kNotDetected;
42  } else if (tethering_str == shill::kTetheringSuspectedState) {
43    return ConnectionTethering::kSuspected;
44  } else if (tethering_str == shill::kTetheringConfirmedState) {
45    return ConnectionTethering::kConfirmed;
46  }
47  return ConnectionTethering::kUnknown;
48}
49
50const char* StringForConnectionType(ConnectionType type) {
51  switch (type) {
52    case ConnectionType::kEthernet:
53      return shill::kTypeEthernet;
54    case ConnectionType::kWifi:
55      return shill::kTypeWifi;
56    case ConnectionType::kWimax:
57      return shill::kTypeWimax;
58    case ConnectionType::kBluetooth:
59      return shill::kTypeBluetooth;
60    case ConnectionType::kCellular:
61      return shill::kTypeCellular;
62    case ConnectionType::kUnknown:
63      return "Unknown";
64  }
65  return "Unknown";
66}
67
68}  // namespace connection_utils
69
70}  // namespace chromeos_update_engine
71