blob: 2d8ccd43deb17d8a4d5c063917899e92c1597690 [file] [log] [blame]
David Rochbergfa1d31d2012-03-20 10:38:07 -04001// Copyright (c) 2012 The Chromium OS 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.
4
5#include "shill/modem.h"
6
7#include <mm/ModemManager-enums.h>
8#include <mm/ModemManager-names.h>
9
10#include "shill/cellular.h"
11
12using std::string;
13
14namespace shill {
15
16Modem1::Modem1(const string &owner,
17 const string &path,
18 ControlInterface *control_interface,
19 EventDispatcher *dispatcher,
20 Metrics *metrics,
21 Manager *manager,
22 mobile_provider_db *provider_db)
23 : Modem(owner, path, control_interface, dispatcher, metrics, manager,
24 provider_db) {
25}
26
27Modem1::~Modem1() {}
28
29Cellular::ModemState Modem1::ConvertMmToCellularModemState(uint32 input) const {
30 switch (input) {
31 case MM_MODEM_STATE_UNKNOWN: return Cellular::kModemStateUnknown;
32 case MM_MODEM_STATE_INITIALIZING: return Cellular::kModemStateInitializing;
33 case MM_MODEM_STATE_LOCKED: return Cellular::kModemStateLocked;
34 case MM_MODEM_STATE_DISABLED: return Cellular::kModemStateDisabled;
35 case MM_MODEM_STATE_DISABLING: return Cellular::kModemStateDisabling;
36 case MM_MODEM_STATE_ENABLING: return Cellular::kModemStateEnabling;
37 case MM_MODEM_STATE_ENABLED: return Cellular::kModemStateEnabled;
38 case MM_MODEM_STATE_SEARCHING: return Cellular::kModemStateSearching;
39 case MM_MODEM_STATE_REGISTERED: return Cellular::kModemStateRegistered;
40 case MM_MODEM_STATE_DISCONNECTING:
41 return Cellular::kModemStateDisconnecting;
42 case MM_MODEM_STATE_CONNECTING: return Cellular::kModemStateConnecting;
43 case MM_MODEM_STATE_CONNECTED: return Cellular::kModemStateConnected;
44 default:
45 DCHECK(false) << "Unknown cellular state: " << input;
46 return Cellular::kModemStateUnknown;
47 }
48}
49
50bool Modem1::GetLinkName(const DBusPropertiesMap & /* modem_props */,
51 string *name) const {
52 // TODO(rochberg): use the device path to find the link name in
53 // sysfs. crosbug.com/28498
54 *name = "usb0";
55 return true;
56}
57
58void Modem1::CreateDeviceMM1(const DBusInterfaceToProperties &i_to_p) {
Eric Shienbrood11567d02012-04-10 18:08:49 -040059 Init();
David Rochbergfa1d31d2012-03-20 10:38:07 -040060 DBusInterfaceToProperties::const_iterator modem_properties =
61 i_to_p.find(MM_DBUS_INTERFACE_MODEM);
62 if (modem_properties == i_to_p.end()) {
63 LOG(ERROR) << "Cellular device with no modem properties";
64 return;
65 }
66 set_type(Cellular::kTypeUniversal);
67
68 // We cannot check the IP method to make sure it's not PPP. The IP
69 // method will be checked later when the bearer object is fetched.
70 CreateDeviceFromModemProperties(modem_properties->second);
71}
72
73} // namespace shill