Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 1 | // 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 Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame^] | 7 | #include <base/logging.h> |
| 8 | #include <mm/mm-modem.h> |
| 9 | |
| 10 | #include "shill/cellular.h" |
| 11 | #include "shill/manager.h" |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 12 | #include "shill/proxy_factory.h" |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame^] | 13 | #include "shill/rtnl_handler.h" |
| 14 | |
| 15 | using std::string; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 16 | |
| 17 | namespace shill { |
| 18 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame^] | 19 | // TODO(petkov): Consider generating these in mm/mm-modem.h. |
| 20 | const char Modem::kPropertyLinkName[] = "Device"; |
| 21 | const char Modem::kPropertyIPMethod[] = "IpMethod"; |
| 22 | const char Modem::kPropertyType[] = "Type"; |
| 23 | const char Modem::kPropertyUnlockRequired[] = "UnlockRequired"; |
| 24 | const char Modem::kPropertyUnlockRetries[] = "UnlockRetries"; |
| 25 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 26 | Modem::Modem(const std::string &owner, |
| 27 | const std::string &path, |
| 28 | ControlInterface *control_interface, |
| 29 | EventDispatcher *dispatcher, |
| 30 | Manager *manager) |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame^] | 31 | : owner_(owner), |
| 32 | path_(path), |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 33 | control_interface_(control_interface), |
| 34 | dispatcher_(dispatcher), |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame^] | 35 | manager_(manager) { |
| 36 | LOG(INFO) << "Modem created: " << owner << " at " << path; |
| 37 | } |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 38 | |
| 39 | Modem::~Modem() {} |
| 40 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame^] | 41 | void 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 | |
| 51 | void 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 Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 95 | } // namespace shill |