blob: c71cae5cd65e5d913591c4daada36468c51ebbac [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
Ben Chanc54afe52014-11-05 10:28:08 -08005#include "shill/cellular/modem.h"
David Rochbergfa1d31d2012-03-20 10:38:07 -04006
7#include <mm/mm-modem.h>
8
Ben Chanc54afe52014-11-05 10:28:08 -08009#include "shill/cellular/cellular.h"
David Rochbergfa1d31d2012-03-20 10:38:07 -040010
11using std::string;
12using std::vector;
13
14namespace shill {
15
Peter Qiu05d87e32015-08-14 23:46:21 -070016ModemClassic::ModemClassic(const string& service,
Paul Stewartf58b28e2015-06-16 13:13:10 -070017 const string& path,
Peter Qiu608ec292015-07-30 15:46:16 -070018 ModemInfo* modem_info,
19 ControlInterface* control_interface)
Peter Qiu05d87e32015-08-14 23:46:21 -070020 : Modem(service, path, modem_info, control_interface) {}
David Rochbergfa1d31d2012-03-20 10:38:07 -040021
22ModemClassic::~ModemClassic() {}
23
Peter Qiu05d87e32015-08-14 23:46:21 -070024bool ModemClassic::GetLinkName(const KeyValueStore& modem_properties,
Paul Stewartf58b28e2015-06-16 13:13:10 -070025 string* name) const {
Peter Qiu05d87e32015-08-14 23:46:21 -070026 if (!modem_properties.ContainsString(kPropertyLinkName)) {
27 return false;
28 }
29 *name = modem_properties.GetString(kPropertyLinkName);
30 return true;
David Rochbergfa1d31d2012-03-20 10:38:07 -040031}
32
33void ModemClassic::CreateDeviceClassic(
Peter Qiu05d87e32015-08-14 23:46:21 -070034 const KeyValueStore& modem_properties) {
Eric Shienbrood11567d02012-04-10 18:08:49 -040035 Init();
Ben Chan7fab8972014-08-10 17:14:46 -070036 uint32_t mm_type = kuint32max;
Peter Qiu05d87e32015-08-14 23:46:21 -070037 if (modem_properties.ContainsUint(kPropertyType)) {
38 mm_type = modem_properties.GetUint(kPropertyType);
39 }
David Rochbergfa1d31d2012-03-20 10:38:07 -040040 switch (mm_type) {
41 case MM_MODEM_TYPE_CDMA:
42 set_type(Cellular::kTypeCDMA);
43 break;
44 case MM_MODEM_TYPE_GSM:
45 set_type(Cellular::kTypeGSM);
46 break;
47 default:
48 LOG(ERROR) << "Unsupported cellular modem type: " << mm_type;
49 return;
50 }
Ben Chan7fab8972014-08-10 17:14:46 -070051 uint32_t ip_method = kuint32max;
Peter Qiu05d87e32015-08-14 23:46:21 -070052 if (!modem_properties.ContainsUint(kPropertyIPMethod) ||
53 (ip_method = modem_properties.GetUint(kPropertyIPMethod)) !=
54 MM_MODEM_IP_METHOD_DHCP) {
David Rochbergfa1d31d2012-03-20 10:38:07 -040055 LOG(ERROR) << "Unsupported IP method: " << ip_method;
56 return;
57 }
Ben Chan876efd32012-09-28 15:25:13 -070058
Peter Qiu05d87e32015-08-14 23:46:21 -070059 InterfaceToProperties properties;
Ben Chan876efd32012-09-28 15:25:13 -070060 properties[MM_MODEM_INTERFACE] = modem_properties;
61 CreateDeviceFromModemProperties(properties);
David Rochbergfa1d31d2012-03-20 10:38:07 -040062}
63
Jason Glasgow4c0724a2012-04-17 15:47:40 -040064string ModemClassic::GetModemInterface(void) const {
65 return string(MM_MODEM_INTERFACE);
66}
67
David Rochbergfa1d31d2012-03-20 10:38:07 -040068} // namespace shill