blob: 9c8b4ade62c3edc3662332a38b568128aaa0dcb5 [file] [log] [blame]
Darin Petkov5c97ac52011-07-19 16:30:49 -07001// Copyright (c) 2011 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
Darin Petkove0a312e2011-07-20 13:45:28 -07007#include <base/logging.h>
8#include <mm/mm-modem.h>
9
10#include "shill/cellular.h"
11#include "shill/manager.h"
Darin Petkov5c97ac52011-07-19 16:30:49 -070012#include "shill/proxy_factory.h"
Darin Petkove0a312e2011-07-20 13:45:28 -070013#include "shill/rtnl_handler.h"
14
15using std::string;
Darin Petkov5c97ac52011-07-19 16:30:49 -070016
17namespace shill {
18
Darin Petkove0a312e2011-07-20 13:45:28 -070019// TODO(petkov): Consider generating these in mm/mm-modem.h.
20const char Modem::kPropertyLinkName[] = "Device";
21const char Modem::kPropertyIPMethod[] = "IpMethod";
22const char Modem::kPropertyType[] = "Type";
23const char Modem::kPropertyUnlockRequired[] = "UnlockRequired";
24const char Modem::kPropertyUnlockRetries[] = "UnlockRetries";
25
Darin Petkov5c97ac52011-07-19 16:30:49 -070026Modem::Modem(const std::string &owner,
27 const std::string &path,
28 ControlInterface *control_interface,
29 EventDispatcher *dispatcher,
30 Manager *manager)
Darin Petkove0a312e2011-07-20 13:45:28 -070031 : owner_(owner),
32 path_(path),
Darin Petkov5c97ac52011-07-19 16:30:49 -070033 control_interface_(control_interface),
34 dispatcher_(dispatcher),
Darin Petkove0a312e2011-07-20 13:45:28 -070035 manager_(manager) {
36 LOG(INFO) << "Modem created: " << owner << " at " << path;
37}
Darin Petkov5c97ac52011-07-19 16:30:49 -070038
39Modem::~Modem() {}
40
Darin Petkove0a312e2011-07-20 13:45:28 -070041void Modem::Init() {
42 CHECK(!device_.get());
43 dbus_properties_proxy_.reset(
44 ProxyFactory::factory()->CreateDBusPropertiesProxy(this, path_, owner_));
45 // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583).
46 DBusPropertiesMap properties =
47 dbus_properties_proxy_->GetAll(MM_MODEM_INTERFACE);
48 CreateCellularDevice(properties);
49}
50
51void Modem::CreateCellularDevice(const DBusPropertiesMap &properties) {
52 uint32 ip_method = kuint32max;
53 if (!DBusProperties::GetUint32(properties, kPropertyIPMethod, &ip_method) ||
54 ip_method != MM_MODEM_IP_METHOD_DHCP) {
55 LOG(ERROR) << "Unsupported IP method: " << ip_method;
56 return;
57 }
58
59 string link_name;
60 if (!DBusProperties::GetString(properties, kPropertyLinkName, &link_name)) {
61 LOG(ERROR) << "Unable to create cellular device without a link name.";
62 return;
63 }
64 int interface_index =
65 RTNLHandler::GetInstance()->GetInterfaceIndex(link_name);
66 if (interface_index < 0) {
67 LOG(ERROR) << "Unable to create cellular device -- no interface index.";
68 return;
69 }
70
71 uint32 type = 0;
72 DBusProperties::GetUint32(properties, kPropertyType, &type);
73 // TODO(petkov): Use type.
74
75 LOG(INFO) << "Creating a cellular device on link " << link_name
76 << " interface index " << interface_index << ".";
77 device_ = new Cellular(control_interface_,
78 dispatcher_,
79 manager_,
80 link_name,
81 interface_index);
82 manager_->RegisterDevice(device_);
83
84 string unlock_required;
85 if (DBusProperties::GetString(
86 properties, kPropertyUnlockRequired, &unlock_required)) {
87 uint32 unlock_retries = 0;
88 DBusProperties::GetUint32(properties,
89 kPropertyUnlockRetries,
90 &unlock_retries);
91 // TODO(petkov): Set these properties on the device instance.
92 }
93}
94
Darin Petkov5c97ac52011-07-19 16:30:49 -070095} // namespace shill