1 // 2 // Copyright (C) 2012 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #include "shill/cellular/modem.h" 18 19 #include <mm/mm-modem.h> 20 21 #include "shill/cellular/cellular.h" 22 23 using std::string; 24 using std::vector; 25 26 namespace shill { 27 28 ModemClassic::ModemClassic(const string& service, 29 const string& path, 30 ModemInfo* modem_info, 31 ControlInterface* control_interface) 32 : Modem(service, path, modem_info, control_interface) {} 33 34 ModemClassic::~ModemClassic() {} 35 36 bool ModemClassic::GetLinkName(const KeyValueStore& modem_properties, 37 string* name) const { 38 if (!modem_properties.ContainsString(kPropertyLinkName)) { 39 return false; 40 } 41 *name = modem_properties.GetString(kPropertyLinkName); 42 return true; 43 } 44 45 void ModemClassic::CreateDeviceClassic( 46 const KeyValueStore& modem_properties) { 47 Init(); 48 uint32_t mm_type = std::numeric_limits<uint32_t>::max(); 49 if (modem_properties.ContainsUint(kPropertyType)) { 50 mm_type = modem_properties.GetUint(kPropertyType); 51 } 52 switch (mm_type) { 53 case MM_MODEM_TYPE_CDMA: 54 set_type(Cellular::kTypeCDMA); 55 break; 56 case MM_MODEM_TYPE_GSM: 57 set_type(Cellular::kTypeGSM); 58 break; 59 default: 60 LOG(ERROR) << "Unsupported cellular modem type: " << mm_type; 61 return; 62 } 63 uint32_t ip_method = std::numeric_limits<uint32_t>::max(); 64 if (!modem_properties.ContainsUint(kPropertyIPMethod) || 65 (ip_method = modem_properties.GetUint(kPropertyIPMethod)) != 66 MM_MODEM_IP_METHOD_DHCP) { 67 LOG(ERROR) << "Unsupported IP method: " << ip_method; 68 return; 69 } 70 71 InterfaceToProperties properties; 72 properties[MM_MODEM_INTERFACE] = modem_properties; 73 CreateDeviceFromModemProperties(properties); 74 } 75 76 string ModemClassic::GetModemInterface(void) const { 77 return string(MM_MODEM_INTERFACE); 78 } 79 80 } // namespace shill 81