shill: Connect the device on start when the modem is already connected.

BUG=chromium-os:18727
TEST=unit tests, tested on device

Change-Id: I9657cfd4423fa17c2f34973df5880db520a8662c
Reviewed-on: http://gerrit.chromium.org/gerrit/5584
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
diff --git a/cellular.h b/cellular.h
index d88a69c..1419b0e 100644
--- a/cellular.h
+++ b/cellular.h
@@ -38,6 +38,20 @@
     kStateConnected,
   };
 
+  // These should be kept in sync with ModemManager's mm-modem.h:MMModemState.
+  enum ModemState {
+    kModemStateUnknown = 0,
+    kModemStateDisabled = 10,
+    kModemStateDisabling = 20,
+    kModemStateEnabling = 30,
+    kModemStateEnabled = 40,
+    kModemStateSearching = 50,
+    kModemStateRegistered = 60,
+    kModemStateDisconnecting = 70,
+    kModemStateConnecting = 80,
+    kModemStateConnected = 90,
+  };
+
   class Network {
    public:
     Network();
@@ -100,15 +114,15 @@
   // Asynchronously connects the modem to the network.
   void Connect();
 
+  void set_modem_state(ModemState state) { modem_state_ = state; }
+  ModemState modem_state() const { return modem_state_; }
+
   // Inherited from Device.
   virtual void Start();
   virtual void Stop();
   virtual bool TechnologyIs(Technology type) const;
 
  private:
-  static const char kPhoneNumberCDMA[];
-  static const char kPhoneNumberGSM[];
-
   FRIEND_TEST(CellularTest, Connect);
   FRIEND_TEST(CellularTest, GetCDMARegistrationState);
   FRIEND_TEST(CellularTest, GetCDMASignalQuality);
@@ -119,9 +133,18 @@
   FRIEND_TEST(CellularTest, InitProxiesCDMA);
   FRIEND_TEST(CellularTest, InitProxiesGSM);
   FRIEND_TEST(CellularTest, Start);
+  FRIEND_TEST(CellularTest, StartConnected);
+  FRIEND_TEST(CellularTest, StartRegister);
+
+  static const char kPhoneNumberCDMA[];
+  static const char kPhoneNumberGSM[];
 
   void ConnectTask(const DBusPropertiesMap &properties);
 
+  // Invoked when the modem is connected to the cellular network to transition
+  // to the network-connected state and bring the network interface up.
+  void EstablishLink();
+
   Stringmaps EnumerateNetworks();
   StrIntPair SimLockStatusToProperty();
   void HelpRegisterDerivedStringmaps(const std::string &name,
@@ -181,6 +204,7 @@
 
   Type type_;
   State state_;
+  ModemState modem_state_;
 
   const std::string dbus_owner_;  // ModemManager.Modem
   const std::string dbus_path_;  // ModemManager.Modem