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