shill: wimax: Load WiMAX services from profiles, support Manager::GetService.

This change basically allows shill to create, register, load, save and configure
multiple WiMAX serices for each WiMAX network (identified by the network
id). The overall set of changes:

- Introduce the concept of a WiMaxNetworkId. This corresponds to Network's
  Identifier property but may group several different identifiers if necessary
  (e.g., through a WiMAX network database).

- Each WiMAX service is uniquely identified by its storage ID which is based on
  the WiMaxNetworkId and the friendly service name. For example,
  "wimax_mynetwork_01234567".

- When a WiMax device is registered with the manager or when a new profile is
  pushed, the WiMax device loads and registers all WiMax services from the
  profile (WiMax::Load). It start only the services that are associated with
  live WiMaxNetworkIds. For example, if the only live network is "01234567" and
  the device loads "wimax_mynetwork_01234567" and "wimax_yournetwork_76543210",
  only "wimax_mynetwork_01234567" will be started. A started service will
  usually have a positive signal strength, while a stopped service will always
  have a zero signal strength.

- When a new WiMAX network becomes available (identified by its WiMaxNetworkId),
  a new default WiMAX service may get created that's associated with that
  WiMaxNetworkId and network name as supplied by the network. Also, all services
  that are associated with that WiMaxNetworkId are started. For example, if
  network "76543210" with a network-supplied name of "defaultname" becomes live,
  shill creates, registers and starts "wimax_defaultname_76543210" and start the
  already created and registered "wimax_yournetwork_76543210".

- When a WiMAX network disappears, the associated services are stopped. The
  services are deregistered when the WiMAX device is stopped.

- RPC methods Manager::GetService and Manager::ConfigureService now support
  configuring of WiMAX services. The required arguments include the
  WiMaxNetworkId and the service name.

BUG=chrome-os-partner:9907
TEST=unit tests

Change-Id: Ieedbb62b5ca82e36d862ed86e817d584ae5c7d08
Reviewed-on: https://gerrit.chromium.org/gerrit/23211
Tested-by: Darin Petkov <petkov@chromium.org>
Commit-Ready: Darin Petkov <petkov@chromium.org>
Reviewed-by: Darin Petkov <petkov@chromium.org>
diff --git a/wimax_service.h b/wimax_service.h
index d2fd33a..582f2dd 100644
--- a/wimax_service.h
+++ b/wimax_service.h
@@ -9,14 +9,19 @@
 
 #include "shill/refptr_types.h"
 #include "shill/service.h"
+#include "shill/wimax_network_proxy_interface.h"
 
 namespace shill {
 
 class KeyValueStore;
-class WiMaxNetworkProxyInterface;
 
 class WiMaxService : public Service {
  public:
+  static const char kStorageNetworkId[];
+
+  // TODO(petkov): Declare this in chromeos/dbus/service_constants.h.
+  static const char kNetworkIdProperty[];
+
   WiMaxService(ControlInterface *control,
                EventDispatcher *dispatcher,
                Metrics *metrics,
@@ -30,14 +35,31 @@
 
   // Returns the RPC object path for the WiMaxManager.Network object associated
   // with this service. Must only be called after |proxy_| is set by Start().
-  RpcIdentifier GetNetworkObjectPath() const;
+  virtual RpcIdentifier GetNetworkObjectPath() const;
 
-  // Returns true on success, false otherwise. Takes ownership of proxy,
-  // regardless of the result of the operation.
-  bool Start(WiMaxNetworkProxyInterface *proxy);
+  // Starts the service by associating it with the RPC network object |proxy|
+  // and listening for its signal strength. Returns true on success, false
+  // otherwise. Takes ownership of proxy, regardless of the result of the
+  // operation. The proxy will be destroyed on failure.
+  virtual bool Start(WiMaxNetworkProxyInterface *proxy);
+
+  // Stops the service by disassociating it from |proxy_| and resetting its
+  // signal strength to 0.
+  virtual void Stop();
+
+  virtual bool IsStarted() const;
 
   const std::string &network_name() const { return network_name_; }
-  uint32 network_identifier() const { return network_identifier_; }
+  const WiMaxNetworkId &network_id() const { return network_id_; }
+  void set_network_id(const WiMaxNetworkId &id) { network_id_ = id; }
+
+  static WiMaxNetworkId ConvertIdentifierToNetworkId(uint32 identifier);
+
+  // Initializes the storage identifier. Note that the friendly service name and
+  // the |network_id_| must already be initialized.
+  void InitStorageIdentifier();
+  static std::string CreateStorageIdentifier(const WiMaxNetworkId &id,
+                                             const std::string &name);
 
   // Inherited from Service.
   virtual bool TechnologyIs(const Technology::Identifier type) const;
@@ -46,11 +68,13 @@
   virtual std::string GetStorageIdentifier() const;
   virtual bool Is8021x() const;
   virtual void set_eap(const EapCredentials &eap);
+  virtual bool Save(StoreInterface *storage);
 
  private:
   FRIEND_TEST(WiMaxServiceTest, GetDeviceRpcId);
   FRIEND_TEST(WiMaxServiceTest, OnSignalStrengthChanged);
   FRIEND_TEST(WiMaxServiceTest, SetEAP);
+  FRIEND_TEST(WiMaxServiceTest, StartStop);
 
   virtual std::string GetDeviceRpcId(Error *error);
 
@@ -62,7 +86,7 @@
   scoped_ptr<WiMaxNetworkProxyInterface> proxy_;
   std::string storage_id_;
 
-  uint32 network_identifier_;
+  WiMaxNetworkId network_id_;
   std::string network_name_;
   bool need_passphrase_;