shill: Hide netlink sequence numbers and headers from users

Hide details of the netlink protocol from creators of nl80211 messages
to simplify the process of sending messages to the kernel.  This changes
the process to send a message and set a callback from:

KernelBoundNlMessage message;
// ... populate message with fields
message.AddNetlinkHeader(&socket_, 0, NL_AUTO_SEQ, 0, 0, 0,
                         CTRL_CMD_GETFAMILY, 0));
Config80211::GetInstance()->SendMessage(&message, callback);

to:

KernelBoundNlMessage message(CTRL_CMD_GETFAMILY);
// ... populate message with fields
Config80211::GetInstance()->SendMessage(&message, callback);

BUG=chromium-os:36122
TEST=Unit tests

Change-Id: Id0bc931b6952fc0eafdf73499c1b48d550575fce
Reviewed-on: https://gerrit.chromium.org/gerrit/37724
Reviewed-by: Wade Guthrie <wdg@chromium.org>
Commit-Ready: Christopher Wiley <wiley@chromium.org>
Tested-by: Christopher Wiley <wiley@chromium.org>
diff --git a/kernel_bound_nlmessage.h b/kernel_bound_nlmessage.h
index b51d465..e4595c4 100644
--- a/kernel_bound_nlmessage.h
+++ b/kernel_bound_nlmessage.h
@@ -26,12 +26,10 @@
 #define SHILL_KERNEL_BOUND_NLMESSAGE_H_
 
 #include <base/basictypes.h>
-#include <base/bind.h>
 
 struct nl_msg;
 
 namespace shill {
-struct NetlinkSocket;
 
 // TODO(wdg): eventually, KernelBoundNlMessage and UserBoundNlMessage should
 // be combined into a monolithic NlMessage.
@@ -39,29 +37,29 @@
 // Provides a wrapper around a netlink message destined for kernel-space.
 class KernelBoundNlMessage {
  public:
-  KernelBoundNlMessage() : message_(NULL) {}
+  // |command| is a type of command understood by the kernel, for instance:
+  // CTRL_CMD_GETFAMILY.
+  explicit KernelBoundNlMessage(uint8 command)
+      : command_(command),
+        message_(NULL) {};
   virtual ~KernelBoundNlMessage();
 
   // Non-trivial initialization.
   bool Init();
 
-  // Message ID is equivalent to the message's sequence number.
-  uint32_t GetId() const;
-
-  // Add a netlink header to the message.
-  bool AddNetlinkHeader(NetlinkSocket *socket, uint32_t port, uint32_t seq,
-                        int family_id, int hdrlen, int flags, uint8_t cmd,
-                        uint8_t version);
-
   // Add a netlink attribute to the message.
   int AddAttribute(int attrtype, int attrlen, const void *data);
 
-  // Sends |this| over the netlink socket.
-  virtual bool Send(NetlinkSocket *socket);
+  uint8 command() const { return command_; }
+  // TODO(wiley) It would be better if messages were bags of attributes which
+  //             the socket collapses into binary blobs at send time.
+  struct nl_msg *message() const { return message_; }
+  // Returns 0 when unsent, > 0 otherwise.
+  uint32 sequence_number() const;
 
  private:
-  static const uint32_t kIllegalMessage;
-
+  uint8 command_;
+  // TODO(wiley) Rename to |raw_message_| (message.message() looks silly).
   struct nl_msg *message_;
 
   DISALLOW_COPY_AND_ASSIGN(KernelBoundNlMessage);