David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 1 | // 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 Chan | c54afe5 | 2014-11-05 10:28:08 -0800 | [diff] [blame] | 5 | #include "shill/cellular/modem.h" |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 6 | |
| 7 | #include <mm/mm-modem.h> |
| 8 | |
Ben Chan | c54afe5 | 2014-11-05 10:28:08 -0800 | [diff] [blame] | 9 | #include "shill/cellular/cellular.h" |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 10 | |
| 11 | using std::string; |
| 12 | using std::vector; |
| 13 | |
| 14 | namespace shill { |
| 15 | |
Peter Qiu | 05d87e3 | 2015-08-14 23:46:21 -0700 | [diff] [blame^] | 16 | ModemClassic::ModemClassic(const string& service, |
Paul Stewart | f58b28e | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 17 | const string& path, |
Peter Qiu | 608ec29 | 2015-07-30 15:46:16 -0700 | [diff] [blame] | 18 | ModemInfo* modem_info, |
| 19 | ControlInterface* control_interface) |
Peter Qiu | 05d87e3 | 2015-08-14 23:46:21 -0700 | [diff] [blame^] | 20 | : Modem(service, path, modem_info, control_interface) {} |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 21 | |
| 22 | ModemClassic::~ModemClassic() {} |
| 23 | |
Peter Qiu | 05d87e3 | 2015-08-14 23:46:21 -0700 | [diff] [blame^] | 24 | bool ModemClassic::GetLinkName(const KeyValueStore& modem_properties, |
Paul Stewart | f58b28e | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 25 | string* name) const { |
Peter Qiu | 05d87e3 | 2015-08-14 23:46:21 -0700 | [diff] [blame^] | 26 | if (!modem_properties.ContainsString(kPropertyLinkName)) { |
| 27 | return false; |
| 28 | } |
| 29 | *name = modem_properties.GetString(kPropertyLinkName); |
| 30 | return true; |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | void ModemClassic::CreateDeviceClassic( |
Peter Qiu | 05d87e3 | 2015-08-14 23:46:21 -0700 | [diff] [blame^] | 34 | const KeyValueStore& modem_properties) { |
Eric Shienbrood | 11567d0 | 2012-04-10 18:08:49 -0400 | [diff] [blame] | 35 | Init(); |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 36 | uint32_t mm_type = kuint32max; |
Peter Qiu | 05d87e3 | 2015-08-14 23:46:21 -0700 | [diff] [blame^] | 37 | if (modem_properties.ContainsUint(kPropertyType)) { |
| 38 | mm_type = modem_properties.GetUint(kPropertyType); |
| 39 | } |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 40 | 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 Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 51 | uint32_t ip_method = kuint32max; |
Peter Qiu | 05d87e3 | 2015-08-14 23:46:21 -0700 | [diff] [blame^] | 52 | if (!modem_properties.ContainsUint(kPropertyIPMethod) || |
| 53 | (ip_method = modem_properties.GetUint(kPropertyIPMethod)) != |
| 54 | MM_MODEM_IP_METHOD_DHCP) { |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 55 | LOG(ERROR) << "Unsupported IP method: " << ip_method; |
| 56 | return; |
| 57 | } |
Ben Chan | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 58 | |
Peter Qiu | 05d87e3 | 2015-08-14 23:46:21 -0700 | [diff] [blame^] | 59 | InterfaceToProperties properties; |
Ben Chan | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 60 | properties[MM_MODEM_INTERFACE] = modem_properties; |
| 61 | CreateDeviceFromModemProperties(properties); |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 62 | } |
| 63 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 64 | string ModemClassic::GetModemInterface(void) const { |
| 65 | return string(MM_MODEM_INTERFACE); |
| 66 | } |
| 67 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 68 | } // namespace shill |