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 #ifndef SHILL_CELLULAR_CELLULAR_CAPABILITY_CLASSIC_H_ 18 #define SHILL_CELLULAR_CELLULAR_CAPABILITY_CLASSIC_H_ 19 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 #include <base/callback.h> 25 #include <base/macros.h> 26 #include <base/memory/weak_ptr.h> 27 #include <gtest/gtest_prod.h> // for FRIEND_TEST 28 29 #include "shill/cellular/cellular.h" 30 #include "shill/cellular/cellular_capability.h" 31 #include "shill/cellular/modem_proxy_interface.h" 32 #include "shill/cellular/modem_simple_proxy_interface.h" 33 34 namespace shill { 35 36 class Cellular; 37 class ControlInterface; 38 class Error; 39 class EventDispatcher; 40 class ModemGobiProxyInterface; 41 class ModemInfo; 42 43 enum ModemClassicState { 44 kModemClassicStateUnknown = 0, 45 kModemClassicStateDisabled = 10, 46 kModemClassicStateDisabling = 20, 47 kModemClassicStateEnabling = 30, 48 kModemClassicStateEnabled = 40, 49 kModemClassicStateSearching = 50, 50 kModemClassicStateRegistered = 60, 51 kModemClassicStateDisconnecting = 70, 52 kModemClassicStateConnecting = 80, 53 kModemClassicStateConnected = 90, 54 }; 55 56 // CellularCapabilityClassic handles modems using the 57 // org.chromium.ModemManager DBUS interface. 58 class CellularCapabilityClassic : public CellularCapability { 59 public: 60 static const char kConnectPropertyApn[]; 61 static const char kConnectPropertyApnUsername[]; 62 static const char kConnectPropertyApnPassword[]; 63 static const char kConnectPropertyHomeOnly[]; 64 static const char kConnectPropertyPhoneNumber[]; 65 static const char kModemPropertyEnabled[]; 66 static const int kTimeoutSetCarrierMilliseconds; 67 68 // |cellular| is the parent Cellular device. 69 CellularCapabilityClassic(Cellular* cellular, 70 ControlInterface* control_interface, 71 ModemInfo* modem_info); 72 ~CellularCapabilityClassic() override; 73 74 // Inherited from CellularCapability. 75 void OnPropertiesChanged( 76 const std::string& interface, 77 const KeyValueStore& changed_properties, 78 const std::vector<std::string>& invalidated_properties) override; 79 void StopModem(Error* error, const ResultCallback& callback) override; 80 bool AreProxiesInitialized() const override; 81 void SetCarrier(const std::string& carrier, 82 Error* error, 83 const ResultCallback& callback) override; 84 void Connect(const KeyValueStore& properties, 85 Error* error, 86 const ResultCallback& callback) override; 87 void Disconnect(Error* error, 88 const ResultCallback& callback) override; 89 90 protected: 91 typedef std::vector<base::Closure> CellularTaskList; 92 93 virtual void GetRegistrationState() = 0; 94 95 // The following five methods are only ever called as 96 // callbacks (from the main loop), which is why they 97 // don't take an Error* argument. 98 virtual void EnableModem(const ResultCallback& callback); 99 virtual void DisableModem(const ResultCallback& callback); 100 virtual void GetModemStatus(const ResultCallback& callback); 101 virtual void GetModemInfo(const ResultCallback& callback); 102 virtual void GetProperties(const ResultCallback& callback) = 0; 103 104 void FinishEnable(const ResultCallback& callback); 105 void FinishDisable(const ResultCallback& callback); 106 virtual void InitProxies(); 107 void ReleaseProxies() override; 108 109 // Default implementation is no-op. 110 virtual void UpdateStatus(const KeyValueStore& properties); 111 112 // Runs the next task in a list. 113 // Precondition: |tasks| is not empty. 114 void RunNextStep(CellularTaskList* tasks); 115 // StepCompletedCallback is called after a task completes. 116 // |callback| is the original callback that needs to be invoked when all of 117 // the tasks complete or if there is a failure. |ignore_error| will be set 118 // to true if the next task should be run regardless of the result of the 119 // just-completed task. |tasks| is the list of tasks remaining. |error| is 120 // the result of the just-completed task. 121 void StepCompletedCallback(const ResultCallback& callback, 122 bool ignore_error, 123 CellularTaskList* tasks, 124 const Error& error); 125 126 std::unique_ptr<ModemSimpleProxyInterface> simple_proxy_; 127 128 private: 129 friend class CellularTest; 130 friend class CellularCapabilityCDMATest; 131 friend class CellularCapabilityTest; 132 friend class CellularCapabilityGSMTest; 133 FRIEND_TEST(CellularCapabilityGSMTest, SetProxy); 134 FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier); 135 FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus); 136 FRIEND_TEST(CellularCapabilityTest, AllowRoaming); 137 FRIEND_TEST(CellularCapabilityTest, EnableModemFail); 138 FRIEND_TEST(CellularCapabilityTest, EnableModemSucceed); 139 FRIEND_TEST(CellularCapabilityTest, FinishEnable); 140 FRIEND_TEST(CellularCapabilityTest, GetModemInfo); 141 FRIEND_TEST(CellularCapabilityTest, GetModemStatus); 142 FRIEND_TEST(CellularCapabilityTest, TryApns); 143 FRIEND_TEST(CellularServiceTest, FriendlyName); 144 FRIEND_TEST(CellularTest, StartCDMARegister); 145 FRIEND_TEST(CellularTest, StartConnected); 146 FRIEND_TEST(CellularTest, StartGSMRegister); 147 FRIEND_TEST(CellularTest, StartLinked); 148 FRIEND_TEST(CellularTest, Connect); 149 FRIEND_TEST(CellularTest, ConnectFailure); 150 FRIEND_TEST(CellularTest, ConnectFailureNoService); 151 FRIEND_TEST(CellularTest, ConnectSuccessNoService); 152 FRIEND_TEST(CellularTest, Disconnect); 153 FRIEND_TEST(CellularTest, DisconnectFailure); 154 FRIEND_TEST(CellularTest, DisconnectWithCallback); 155 FRIEND_TEST(CellularTest, ModemStateChangeEnable); 156 FRIEND_TEST(CellularTest, ModemStateChangeDisable); 157 158 // Method reply and signal callbacks from Modem interface 159 void OnModemStateChangedSignal(uint32_t old_state, 160 uint32_t new_state, 161 uint32_t reason); 162 void OnGetModemInfoReply(const ResultCallback& callback, 163 const std::string& manufacturer, 164 const std::string& modem, 165 const std::string& version, 166 const Error& error); 167 168 // Method reply callbacks from Modem.Simple interface 169 void OnGetModemStatusReply(const ResultCallback& callback, 170 const KeyValueStore& props, 171 const Error& error); 172 173 Cellular* cellular_; 174 base::WeakPtrFactory<CellularCapabilityClassic> weak_ptr_factory_; 175 std::unique_ptr<ModemProxyInterface> proxy_; 176 std::unique_ptr<ModemGobiProxyInterface> gobi_proxy_; 177 178 DISALLOW_COPY_AND_ASSIGN(CellularCapabilityClassic); 179 }; 180 181 } // namespace shill 182 183 #endif // SHILL_CELLULAR_CELLULAR_CAPABILITY_CLASSIC_H_ 184