Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SHILL_USER_BOUND_NLMESSAGE_H_ |
| 6 | #define SHILL_USER_BOUND_NLMESSAGE_H_ |
| 7 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 8 | #include <linux/nl80211.h> |
| 9 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 10 | #include <iomanip> |
| 11 | #include <map> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 12 | #include <string> |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 13 | #include <vector> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 14 | |
| 15 | #include <base/basictypes.h> |
| 16 | #include <base/bind.h> |
| 17 | #include <base/lazy_instance.h> |
| 18 | #include <gtest/gtest.h> |
| 19 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 20 | #include "shill/attribute_list.h" |
repo sync | 1538d44 | 2012-12-20 15:24:35 -0800 | [diff] [blame] | 21 | #include "shill/byte_string.h" |
Wade Guthrie | efe1f0c | 2013-02-26 17:42:01 -0800 | [diff] [blame^] | 22 | #include "shill/refptr_types.h" |
Wade Guthrie | 1619624 | 2012-11-20 15:53:52 -0800 | [diff] [blame] | 23 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 24 | struct nlattr; |
| 25 | struct nlmsghdr; |
| 26 | |
| 27 | namespace shill { |
| 28 | |
| 29 | // Class for messages received from libnl. |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 30 | class Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 31 | public: |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 32 | static const unsigned int kEthernetAddressBytes; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 33 | static const char kBogusMacAddress[]; |
| 34 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 35 | Nl80211Message(uint8 message_type, const char *message_type_string) |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 36 | : message_type_(message_type), |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 37 | message_type_string_(message_type_string), |
Wade Guthrie | efe1f0c | 2013-02-26 17:42:01 -0800 | [diff] [blame^] | 38 | sequence_number_(kIllegalMessage), |
| 39 | attributes_(new AttributeList) {} |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 40 | virtual ~Nl80211Message() {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 41 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 42 | // Initializes the message with bytes from the kernel. |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 43 | virtual bool InitFromNlmsg(const nlmsghdr *msg); |
Wade Guthrie | 8e27861 | 2013-02-26 10:32:34 -0800 | [diff] [blame] | 44 | static void PrintBytes(int log_level, const unsigned char *buf, |
| 45 | size_t num_bytes); |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 46 | uint32_t sequence_number() const { return sequence_number_; } |
Wade Guthrie | 8e27861 | 2013-02-26 10:32:34 -0800 | [diff] [blame] | 47 | virtual void Print(int log_level) const; |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 48 | |
| 49 | void set_sequence_number(uint32_t seq) { sequence_number_ = seq; } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 50 | |
Wade Guthrie | efe1f0c | 2013-02-26 17:42:01 -0800 | [diff] [blame^] | 51 | AttributeListConstRefPtr const_attributes() const { return attributes_; } |
| 52 | AttributeListRefPtr attributes() { return attributes_; } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 53 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 54 | // TODO(wdg): This needs to be moved to AttributeMac. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 55 | // Helper function to provide a string for a MAC address. If no attribute |
| 56 | // is found, this method returns 'false'. On any error with a non-NULL |
| 57 | // |value|, this method sets |value| to a bogus MAC address. |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 58 | bool GetMacAttributeString(int id, std::string *value) const; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 59 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 60 | // TODO(wdg): This needs to be moved to AttributeScanFrequencies. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 61 | // Helper function to provide a vector of scan frequencies for attributes |
| 62 | // that contain them (such as NL80211_ATTR_SCAN_FREQUENCIES). |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 63 | bool GetScanFrequenciesAttribute(int id, std::vector<uint32_t> *value) const; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 64 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 65 | // TODO(wdg): This needs to be moved to AttributeScanSSids. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 66 | // Helper function to provide a vector of SSIDs for attributes that contain |
| 67 | // them (such as NL80211_ATTR_SCAN_SSIDS). |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 68 | bool GetScanSsidsAttribute(int id, std::vector<std::string> *value) const; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 69 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 70 | // TODO(wdg): This needs to be moved to AttributeMac. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 71 | // Stringizes the MAC address found in 'arg'. If there are problems (such |
| 72 | // as a NULL |arg|), |value| is set to a bogus MAC address. |
| 73 | static std::string StringFromMacAddress(const uint8_t *arg); |
| 74 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 75 | // Returns a string representing the passed-in |status| or |reason|, the |
| 76 | // value of which has been acquired from libnl (for example, from the |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 77 | // NL80211_ATTR_STATUS_CODE or NL80211_ATTR_REASON_CODE attribute). |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 78 | static std::string StringFromReason(uint16_t reason); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 79 | static std::string StringFromStatus(uint16_t status); |
| 80 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 81 | uint8 message_type() const { return message_type_; } |
| 82 | const char *message_type_string() const { return message_type_string_; } |
| 83 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 84 | // Returns a netlink message suitable for Sockets::Send. Return value is |
| 85 | // empty on failure. |nlmsg_type| needs to be the family id returned by |
| 86 | // |genl_ctrl_resolve|. |
| 87 | ByteString Encode(uint16_t nlmsg_type) const; |
| 88 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 89 | protected: |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 90 | // Returns a string that should precede all user-bound message strings. |
| 91 | virtual std::string GetHeaderString() const; |
| 92 | |
| 93 | // Returns a string that describes the contents of the frame pointed to by |
| 94 | // 'attr'. |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 95 | std::string StringFromFrame(int attr_name) const; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 96 | |
| 97 | // Converts key_type to a string. |
| 98 | static std::string StringFromKeyType(nl80211_key_type key_type); |
| 99 | |
| 100 | // Returns a string representation of the REG initiator described by the |
| 101 | // method's parameter. |
| 102 | static std::string StringFromRegInitiator(__u8 initiator); |
| 103 | |
| 104 | // Returns a string based on the SSID found in 'data'. Non-printable |
| 105 | // characters are string-ized. |
| 106 | static std::string StringFromSsid(const uint8_t len, const uint8_t *data); |
| 107 | |
| 108 | private: |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 109 | friend class Config80211Test; |
| 110 | FRIEND_TEST(Config80211Test, NL80211_CMD_NOTIFY_CQM); |
| 111 | |
| 112 | static const uint32_t kIllegalMessage; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 113 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 114 | const uint8 message_type_; |
| 115 | const char *message_type_string_; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 116 | static std::map<uint16_t, std::string> *reason_code_string_; |
| 117 | static std::map<uint16_t, std::string> *status_code_string_; |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 118 | uint32_t sequence_number_; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 119 | |
Wade Guthrie | efe1f0c | 2013-02-26 17:42:01 -0800 | [diff] [blame^] | 120 | AttributeListRefPtr attributes_; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 121 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 122 | DISALLOW_COPY_AND_ASSIGN(Nl80211Message); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | class Nl80211Frame { |
| 126 | public: |
| 127 | enum Type { |
| 128 | kAssocResponseFrameType = 0x10, |
| 129 | kReassocResponseFrameType = 0x30, |
| 130 | kAssocRequestFrameType = 0x00, |
| 131 | kReassocRequestFrameType = 0x20, |
| 132 | kAuthFrameType = 0xb0, |
| 133 | kDisassocFrameType = 0xa0, |
| 134 | kDeauthFrameType = 0xc0, |
| 135 | kIllegalFrameType = 0xff |
| 136 | }; |
| 137 | |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 138 | explicit Nl80211Frame(const ByteString &init); |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 139 | bool ToString(std::string *output) const; |
| 140 | bool IsEqual(const Nl80211Frame &other) const; |
| 141 | uint16_t reason() const { return reason_; } |
| 142 | uint16_t status() const { return status_; } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 143 | |
| 144 | private: |
| 145 | static const uint8_t kMinimumFrameByteCount; |
| 146 | static const uint8_t kFrameTypeMask; |
| 147 | |
| 148 | std::string mac_from_; |
| 149 | std::string mac_to_; |
| 150 | uint8_t frame_type_; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 151 | uint16_t reason_; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 152 | uint16_t status_; |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 153 | ByteString frame_; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 154 | |
| 155 | DISALLOW_COPY_AND_ASSIGN(Nl80211Frame); |
| 156 | }; |
| 157 | |
| 158 | // |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 159 | // Specific Nl80211Message types. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 160 | // |
| 161 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 162 | class AckMessage : public Nl80211Message { |
| 163 | public: |
| 164 | static const uint8_t kCommand; |
| 165 | static const char kCommandString[]; |
| 166 | |
| 167 | AckMessage() : Nl80211Message(kCommand, kCommandString) {} |
| 168 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 169 | private: |
| 170 | DISALLOW_COPY_AND_ASSIGN(AckMessage); |
| 171 | }; |
| 172 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 173 | class AssociateMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 174 | public: |
| 175 | static const uint8_t kCommand; |
| 176 | static const char kCommandString[]; |
| 177 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 178 | AssociateMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 179 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 180 | private: |
| 181 | DISALLOW_COPY_AND_ASSIGN(AssociateMessage); |
| 182 | }; |
| 183 | |
| 184 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 185 | class AuthenticateMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 186 | public: |
| 187 | static const uint8_t kCommand; |
| 188 | static const char kCommandString[]; |
| 189 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 190 | AuthenticateMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 191 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 192 | private: |
| 193 | DISALLOW_COPY_AND_ASSIGN(AuthenticateMessage); |
| 194 | }; |
| 195 | |
| 196 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 197 | class CancelRemainOnChannelMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 198 | public: |
| 199 | static const uint8_t kCommand; |
| 200 | static const char kCommandString[]; |
| 201 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 202 | CancelRemainOnChannelMessage() |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 203 | : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 204 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 205 | private: |
| 206 | DISALLOW_COPY_AND_ASSIGN(CancelRemainOnChannelMessage); |
| 207 | }; |
| 208 | |
| 209 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 210 | class ConnectMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 211 | public: |
| 212 | static const uint8_t kCommand; |
| 213 | static const char kCommandString[]; |
| 214 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 215 | ConnectMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 216 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 217 | private: |
| 218 | DISALLOW_COPY_AND_ASSIGN(ConnectMessage); |
| 219 | }; |
| 220 | |
| 221 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 222 | class DeauthenticateMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 223 | public: |
| 224 | static const uint8_t kCommand; |
| 225 | static const char kCommandString[]; |
| 226 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 227 | DeauthenticateMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 228 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 229 | private: |
| 230 | DISALLOW_COPY_AND_ASSIGN(DeauthenticateMessage); |
| 231 | }; |
| 232 | |
| 233 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 234 | class DeleteStationMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 235 | public: |
| 236 | static const uint8_t kCommand; |
| 237 | static const char kCommandString[]; |
| 238 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 239 | DeleteStationMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 240 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 241 | private: |
| 242 | DISALLOW_COPY_AND_ASSIGN(DeleteStationMessage); |
| 243 | }; |
| 244 | |
| 245 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 246 | class DisassociateMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 247 | public: |
| 248 | static const uint8_t kCommand; |
| 249 | static const char kCommandString[]; |
| 250 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 251 | DisassociateMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 252 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 253 | private: |
| 254 | DISALLOW_COPY_AND_ASSIGN(DisassociateMessage); |
| 255 | }; |
| 256 | |
| 257 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 258 | class DisconnectMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 259 | public: |
| 260 | static const uint8_t kCommand; |
| 261 | static const char kCommandString[]; |
| 262 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 263 | DisconnectMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 264 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 265 | private: |
| 266 | DISALLOW_COPY_AND_ASSIGN(DisconnectMessage); |
| 267 | }; |
| 268 | |
| 269 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 270 | class ErrorMessage : public Nl80211Message { |
| 271 | public: |
| 272 | static const uint8_t kCommand; |
| 273 | static const char kCommandString[]; |
| 274 | |
Wade Guthrie | 3af8b4d | 2013-01-10 08:39:30 -0800 | [diff] [blame] | 275 | explicit ErrorMessage(uint32_t error); |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 276 | virtual std::string ToString() const; |
| 277 | |
| 278 | private: |
| 279 | uint32_t error_; |
| 280 | |
| 281 | DISALLOW_COPY_AND_ASSIGN(ErrorMessage); |
| 282 | }; |
| 283 | |
| 284 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 285 | class FrameTxStatusMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 286 | public: |
| 287 | static const uint8_t kCommand; |
| 288 | static const char kCommandString[]; |
| 289 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 290 | FrameTxStatusMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 291 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 292 | private: |
| 293 | DISALLOW_COPY_AND_ASSIGN(FrameTxStatusMessage); |
| 294 | }; |
| 295 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 296 | class GetRegMessage : public Nl80211Message { |
| 297 | public: |
| 298 | static const uint8_t kCommand; |
| 299 | static const char kCommandString[]; |
| 300 | |
| 301 | GetRegMessage() : Nl80211Message(kCommand, kCommandString) {} |
| 302 | |
| 303 | private: |
| 304 | DISALLOW_COPY_AND_ASSIGN(GetRegMessage); |
| 305 | }; |
| 306 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 307 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 308 | class JoinIbssMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 309 | public: |
| 310 | static const uint8_t kCommand; |
| 311 | static const char kCommandString[]; |
| 312 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 313 | JoinIbssMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 314 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 315 | private: |
| 316 | DISALLOW_COPY_AND_ASSIGN(JoinIbssMessage); |
| 317 | }; |
| 318 | |
| 319 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 320 | class MichaelMicFailureMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 321 | public: |
| 322 | static const uint8_t kCommand; |
| 323 | static const char kCommandString[]; |
| 324 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 325 | MichaelMicFailureMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 326 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 327 | private: |
| 328 | DISALLOW_COPY_AND_ASSIGN(MichaelMicFailureMessage); |
| 329 | }; |
| 330 | |
| 331 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 332 | class NewScanResultsMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 333 | public: |
| 334 | static const uint8_t kCommand; |
| 335 | static const char kCommandString[]; |
| 336 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 337 | NewScanResultsMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 338 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 339 | private: |
| 340 | DISALLOW_COPY_AND_ASSIGN(NewScanResultsMessage); |
| 341 | }; |
| 342 | |
| 343 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 344 | class NewStationMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 345 | public: |
| 346 | static const uint8_t kCommand; |
| 347 | static const char kCommandString[]; |
| 348 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 349 | NewStationMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 350 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 351 | private: |
| 352 | DISALLOW_COPY_AND_ASSIGN(NewStationMessage); |
| 353 | }; |
| 354 | |
| 355 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 356 | class NewWifiMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 357 | public: |
| 358 | static const uint8_t kCommand; |
| 359 | static const char kCommandString[]; |
| 360 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 361 | NewWifiMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 362 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 363 | private: |
| 364 | DISALLOW_COPY_AND_ASSIGN(NewWifiMessage); |
| 365 | }; |
| 366 | |
| 367 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 368 | class NoopMessage : public Nl80211Message { |
| 369 | public: |
| 370 | static const uint8_t kCommand; |
| 371 | static const char kCommandString[]; |
| 372 | |
| 373 | NoopMessage() : Nl80211Message(kCommand, kCommandString) {} |
| 374 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 375 | private: |
| 376 | DISALLOW_COPY_AND_ASSIGN(NoopMessage); |
| 377 | }; |
| 378 | |
| 379 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 380 | class NotifyCqmMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 381 | public: |
| 382 | static const uint8_t kCommand; |
| 383 | static const char kCommandString[]; |
| 384 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 385 | NotifyCqmMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 386 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 387 | private: |
| 388 | DISALLOW_COPY_AND_ASSIGN(NotifyCqmMessage); |
| 389 | }; |
| 390 | |
| 391 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 392 | class PmksaCandidateMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 393 | public: |
| 394 | static const uint8_t kCommand; |
| 395 | static const char kCommandString[]; |
| 396 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 397 | PmksaCandidateMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 398 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 399 | private: |
| 400 | DISALLOW_COPY_AND_ASSIGN(PmksaCandidateMessage); |
| 401 | }; |
| 402 | |
| 403 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 404 | class RegBeaconHintMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 405 | public: |
| 406 | static const uint8_t kCommand; |
| 407 | static const char kCommandString[]; |
| 408 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 409 | RegBeaconHintMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 410 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 411 | private: |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 412 | DISALLOW_COPY_AND_ASSIGN(RegBeaconHintMessage); |
| 413 | }; |
| 414 | |
| 415 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 416 | class RegChangeMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 417 | public: |
| 418 | static const uint8_t kCommand; |
| 419 | static const char kCommandString[]; |
| 420 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 421 | RegChangeMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 422 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 423 | private: |
| 424 | DISALLOW_COPY_AND_ASSIGN(RegChangeMessage); |
| 425 | }; |
| 426 | |
| 427 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 428 | class RemainOnChannelMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 429 | public: |
| 430 | static const uint8_t kCommand; |
| 431 | static const char kCommandString[]; |
| 432 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 433 | RemainOnChannelMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 434 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 435 | private: |
| 436 | DISALLOW_COPY_AND_ASSIGN(RemainOnChannelMessage); |
| 437 | }; |
| 438 | |
| 439 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 440 | class RoamMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 441 | public: |
| 442 | static const uint8_t kCommand; |
| 443 | static const char kCommandString[]; |
| 444 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 445 | RoamMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 446 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 447 | private: |
| 448 | DISALLOW_COPY_AND_ASSIGN(RoamMessage); |
| 449 | }; |
| 450 | |
| 451 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 452 | class ScanAbortedMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 453 | public: |
| 454 | static const uint8_t kCommand; |
| 455 | static const char kCommandString[]; |
| 456 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 457 | ScanAbortedMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 458 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 459 | private: |
| 460 | DISALLOW_COPY_AND_ASSIGN(ScanAbortedMessage); |
| 461 | }; |
| 462 | |
| 463 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 464 | class TriggerScanMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 465 | public: |
| 466 | static const uint8_t kCommand; |
| 467 | static const char kCommandString[]; |
| 468 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 469 | TriggerScanMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 470 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 471 | private: |
| 472 | DISALLOW_COPY_AND_ASSIGN(TriggerScanMessage); |
| 473 | }; |
| 474 | |
| 475 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 476 | class UnknownMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 477 | public: |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 478 | explicit UnknownMessage(uint8_t command) |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 479 | : Nl80211Message(command, kCommandString), |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 480 | command_(command) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 481 | |
| 482 | static const uint8_t kCommand; |
| 483 | static const char kCommandString[]; |
| 484 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 485 | private: |
| 486 | uint8_t command_; |
| 487 | |
| 488 | DISALLOW_COPY_AND_ASSIGN(UnknownMessage); |
| 489 | }; |
| 490 | |
| 491 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 492 | class UnprotDeauthenticateMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 493 | public: |
| 494 | static const uint8_t kCommand; |
| 495 | static const char kCommandString[]; |
| 496 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 497 | UnprotDeauthenticateMessage() |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 498 | : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 499 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 500 | private: |
| 501 | DISALLOW_COPY_AND_ASSIGN(UnprotDeauthenticateMessage); |
| 502 | }; |
| 503 | |
| 504 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 505 | class UnprotDisassociateMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 506 | public: |
| 507 | static const uint8_t kCommand; |
| 508 | static const char kCommandString[]; |
| 509 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 510 | UnprotDisassociateMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 511 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 512 | private: |
| 513 | DISALLOW_COPY_AND_ASSIGN(UnprotDisassociateMessage); |
| 514 | }; |
| 515 | |
| 516 | |
| 517 | // |
| 518 | // Factory class. |
| 519 | // |
| 520 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 521 | class Nl80211MessageFactory { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 522 | public: |
| 523 | // Ownership of the message is passed to the caller and, as such, he should |
| 524 | // delete it. |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 525 | static Nl80211Message *CreateMessage(nlmsghdr *msg); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 526 | |
| 527 | private: |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 528 | DISALLOW_COPY_AND_ASSIGN(Nl80211MessageFactory); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 532 | // Nl80211MessageDataCollector - this class is used to collect data to be |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 533 | // used for unit tests. It is only invoked in this case. |
| 534 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 535 | class Nl80211MessageDataCollector { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 536 | public: |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 537 | static Nl80211MessageDataCollector *GetInstance(); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 538 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 539 | void CollectDebugData(const Nl80211Message &message, nlmsghdr *msg); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 540 | |
| 541 | protected: |
| 542 | friend struct |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 543 | base::DefaultLazyInstanceTraits<Nl80211MessageDataCollector>; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 544 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 545 | explicit Nl80211MessageDataCollector(); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 546 | |
| 547 | private: |
| 548 | // In order to limit the output from this class, I keep track of types I |
| 549 | // haven't yet printed. |
| 550 | std::map<uint8_t, bool> need_to_print; |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 551 | |
| 552 | DISALLOW_COPY_AND_ASSIGN(Nl80211MessageDataCollector); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 553 | }; |
| 554 | |
| 555 | } // namespace shill |
| 556 | |
| 557 | #endif // SHILL_USER_BOUND_NLMESSAGE_H_ |