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 | |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 29 | class Config80211; |
| 30 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 31 | // Netlink messages are sent over netlink sockets to talk between user-space |
| 32 | // programs (like shill) and kernel modules (like the cfg80211 module). Each |
| 33 | // kernel module that talks netlink potentially adds its own family header to |
| 34 | // the nlmsghdr (the top-level netlink message header) and, potentially, uses a |
| 35 | // different payload format. The NetlinkMessage class represents that which |
| 36 | // is common between the different types of netlink message. |
| 37 | // |
| 38 | // The common portions of Netlink Messages start with a |nlmsghdr|. Those |
| 39 | // messages look something like the following (the functions, macros, and |
| 40 | // datatypes described are provided by libnl -- see also |
| 41 | // http://www.infradead.org/~tgr/libnl/doc/core.html): |
| 42 | // |
| 43 | // |<--------------nlmsg_total_size()----------->| |
| 44 | // | |<------nlmsg_datalen()-------------->| |
| 45 | // | | | |
| 46 | // -----+-----+-+-----------------------------------+-+---- |
| 47 | // ... | | | netlink payload | | |
| 48 | // | | +------------+-+--------------------+ | |
| 49 | // | nl | | | | | | nl |
| 50 | // | msg |p| (optional) |p| |p| msg ... |
| 51 | // | hdr |a| family |a| family payload |a| hdr |
| 52 | // | |d| header |d| |d| |
| 53 | // | | | | | | | |
| 54 | // -----+-----+-+------------+-+--------------------+-+---- |
| 55 | // ^ |
| 56 | // | |
| 57 | // +-- nlmsg_data() |
| 58 | // |
| 59 | // All NetlinkMessages sent to the kernel need a valid message type (which is |
| 60 | // found in the nlmsghdr structure) and all NetlinkMessages received from the |
| 61 | // kernel have a valid message type. Some message types (NLMSG_NOOP, |
| 62 | // NLMSG_ERROR, and GENL_ID_CTRL, for example) are allocated statically; for |
| 63 | // those, the |message_type_| is assigned directly. |
| 64 | // |
| 65 | // Other message types ("nl80211", for example), are assigned by the kernel |
| 66 | // dynamically. To get the message type, pass a closure to assign the |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame^] | 67 | // message_type along with the sting to Config80211::GetFamily: |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 68 | // |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame^] | 69 | // nl80211_type = config80211_->GetFamily(Nl80211Message::kMessageType); |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 70 | // |
| 71 | // Do all of this before you start to create NetlinkMessages so that |
| 72 | // NetlinkMessage can be instantiated with a valid |message_type_|. |
| 73 | |
| 74 | class NetlinkMessage { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 75 | public: |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 76 | static const uint32_t kBroadcastSequenceNumber; |
| 77 | static const uint16_t kIllegalMessageType; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 78 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 79 | explicit NetlinkMessage(uint16_t message_type) : |
| 80 | flags_(0), message_type_(message_type), |
| 81 | sequence_number_(kBroadcastSequenceNumber) {} |
| 82 | virtual ~NetlinkMessage() {} |
| 83 | |
| 84 | // Returns a string of bytes representing the message (with it headers) and |
| 85 | // any necessary padding. These bytes are appropriately formatted to be |
| 86 | // written to a netlink socket. |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame^] | 87 | virtual ByteString Encode(uint32_t sequence_number) = 0; |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 88 | |
| 89 | // Initializes the |NetlinkMessage| from a complete and legal message |
| 90 | // (potentially received from the kernel via a netlink socket). |
| 91 | virtual bool InitFromNlmsg(const nlmsghdr *msg); |
| 92 | |
| 93 | uint16_t message_type() const { return message_type_; } |
| 94 | void AddFlag(uint16_t new_flag) { flags_ |= new_flag; } |
| 95 | uint16_t flags() const { return flags_; } |
| 96 | uint32_t sequence_number() const { return sequence_number_; } |
| 97 | virtual void Print(int log_level) const = 0; |
| 98 | |
| 99 | // Logs the message's raw bytes (with minimal interpretation). |
| 100 | static void PrintBytes(int log_level, const unsigned char *buf, |
| 101 | size_t num_bytes); |
| 102 | |
| 103 | protected: |
| 104 | friend class Config80211Test; |
| 105 | FRIEND_TEST(Config80211Test, NL80211_CMD_NOTIFY_CQM); |
| 106 | |
| 107 | // Returns a string of bytes representing an |nlmsghdr|, filled-in, and its |
| 108 | // padding. |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame^] | 109 | virtual ByteString EncodeHeader(uint32_t sequence_number); |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 110 | // Reads the |nlmsghdr| and removes it from |input|. |
| 111 | virtual bool InitAndStripHeader(ByteString *input); |
| 112 | |
| 113 | uint16_t flags_; |
| 114 | uint16_t message_type_; |
| 115 | uint32_t sequence_number_; |
| 116 | |
| 117 | private: |
| 118 | DISALLOW_COPY_AND_ASSIGN(NetlinkMessage); |
| 119 | }; |
| 120 | |
Wade Guthrie | 7187247 | 2013-03-05 10:33:38 -0800 | [diff] [blame] | 121 | |
| 122 | // The Error and Ack messages are received from the kernel and are combined, |
| 123 | // here, because they look so much alike (the only difference is that the |
| 124 | // error code is 0 for the Ack messages). Error messages are received from |
| 125 | // the kernel in response to a sent message when there's a problem (such as |
| 126 | // a malformed message or a busy kernel module). Ack messages are received |
| 127 | // from the kernel when a sent message has the NLM_F_ACK flag set, indicating |
| 128 | // that an Ack is requested. |
| 129 | class ErrorAckMessage : public NetlinkMessage { |
| 130 | public: |
| 131 | static const uint16_t kMessageType; |
| 132 | |
| 133 | ErrorAckMessage() : NetlinkMessage(kMessageType), error_(0) {} |
| 134 | virtual bool InitFromNlmsg(const nlmsghdr *const_msg); |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame^] | 135 | virtual ByteString Encode(uint32_t sequence_number); |
Wade Guthrie | 7187247 | 2013-03-05 10:33:38 -0800 | [diff] [blame] | 136 | virtual void Print(int log_level) const; |
| 137 | std::string ToString() const; |
| 138 | uint32_t error() const { return -error_; } |
| 139 | |
| 140 | private: |
| 141 | uint32_t error_; |
| 142 | |
| 143 | DISALLOW_COPY_AND_ASSIGN(ErrorAckMessage); |
| 144 | }; |
| 145 | |
| 146 | |
| 147 | class NoopMessage : public NetlinkMessage { |
| 148 | public: |
| 149 | static const uint16_t kMessageType; |
| 150 | |
| 151 | NoopMessage() : NetlinkMessage(kMessageType) {} |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame^] | 152 | virtual ByteString Encode(uint32_t sequence_number); |
Wade Guthrie | 7187247 | 2013-03-05 10:33:38 -0800 | [diff] [blame] | 153 | virtual void Print(int log_level) const; |
| 154 | std::string ToString() const { return "<NOOP>"; } |
| 155 | |
| 156 | private: |
| 157 | DISALLOW_COPY_AND_ASSIGN(NoopMessage); |
| 158 | }; |
| 159 | |
| 160 | |
| 161 | class DoneMessage : public NetlinkMessage { |
| 162 | public: |
| 163 | static const uint16_t kMessageType; |
| 164 | |
| 165 | DoneMessage() : NetlinkMessage(kMessageType) {} |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame^] | 166 | virtual ByteString Encode(uint32_t sequence_number); |
Wade Guthrie | 7187247 | 2013-03-05 10:33:38 -0800 | [diff] [blame] | 167 | virtual void Print(int log_level) const; |
| 168 | std::string ToString() const { return "<DONE with multipart message>"; } |
| 169 | |
| 170 | private: |
| 171 | DISALLOW_COPY_AND_ASSIGN(DoneMessage); |
| 172 | }; |
| 173 | |
| 174 | |
| 175 | class OverrunMessage : public NetlinkMessage { |
| 176 | public: |
| 177 | static const uint16_t kMessageType; |
| 178 | |
| 179 | OverrunMessage() : NetlinkMessage(kMessageType) {} |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame^] | 180 | virtual ByteString Encode(uint32_t sequence_number); |
Wade Guthrie | 7187247 | 2013-03-05 10:33:38 -0800 | [diff] [blame] | 181 | virtual void Print(int log_level) const; |
| 182 | std::string ToString() const { return "<OVERRUN - data lost>"; } |
| 183 | |
| 184 | private: |
| 185 | DISALLOW_COPY_AND_ASSIGN(OverrunMessage); |
| 186 | }; |
| 187 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 188 | // Objects of the |GenericNetlinkMessage| type represent messages that contain |
| 189 | // a |genlmsghdr| after a |nlmsghdr|. These messages seem to all contain a |
| 190 | // payload that consists of a list of structured attributes (it's possible that |
| 191 | // some messages might have a genlmsghdr and a different kind of payload but I |
| 192 | // haven't seen one, yet). The genlmsghdr contains a command id that, when |
| 193 | // combined with the family_id (from the nlmsghdr), describes the ultimate use |
| 194 | // for the netlink message. |
| 195 | // |
| 196 | // An attribute contains a header and a chunk of data. The header contains an |
| 197 | // id which is an enumerated value that describes the use of the attribute's |
| 198 | // data (the datatype of the attribute's data is implied by the attribute id) |
| 199 | // and the length of the header+data in bytes. The attribute id is, |
| 200 | // confusingly, called the type (or nla_type -- this is _not_ the data type of |
| 201 | // the attribute). Each family defines the meaning of the nla_types in the |
| 202 | // context of messages in that family (for example, the nla_type with the |
| 203 | // value 3 will always mean the same thing for attributes in the same family). |
| 204 | // EXCEPTION: Some attributes are nested (that is, they contain a list of other |
| 205 | // attributes rather than a single value). Each nested attribute defines the |
| 206 | // meaning of the nla_types in the context of attributes that are nested under |
| 207 | // this attribute (for example, the nla_type with the value 3 will have a |
| 208 | // different meaning when nested under another attribute -- that meaning is |
| 209 | // defined by the attribute under which it is nested). Fun. |
| 210 | // |
| 211 | // The GenericNetlink messages look like this: |
| 212 | // |
| 213 | // -----+-----+-+-------------------------------------------------+-+-- |
| 214 | // ... | | | message payload | | |
| 215 | // | | +------+-+----------------------------------------+ | |
| 216 | // | nl | | | | attributes | | |
| 217 | // | msg |p| genl |p+-----------+-+---------+-+--------+-----+p| ... |
| 218 | // | hdr |a| msg |a| struct |p| attrib |p| struct | ... |a| |
| 219 | // | |d| hdr |d| nlattr |a| payload |a| nlattr | |d| |
| 220 | // | | | | | |d| |d| | | | |
| 221 | // -----+-----+-+------+-+-----------+-+---------+-+--------+-----+-+-- |
| 222 | // | ^ | | |
| 223 | // |<-NLA_HDRLEN->| | | |
| 224 | // | +---nla_data() |
| 225 | // |<----nla_attr_size---->| | |
| 226 | // |<-----nla_total_size---->| |
| 227 | |
| 228 | class GenericNetlinkMessage : public NetlinkMessage { |
| 229 | public: |
| 230 | GenericNetlinkMessage(uint16_t my_message_type, uint8 command, |
| 231 | const char *command_string) |
| 232 | : NetlinkMessage(my_message_type), |
| 233 | attributes_(new AttributeList), |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 234 | command_(command), |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 235 | command_string_(command_string) {} |
| 236 | virtual ~GenericNetlinkMessage() {} |
| 237 | |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame^] | 238 | virtual ByteString Encode(uint32_t sequence_number); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 239 | |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 240 | uint8 command() const { return command_; } |
| 241 | const char *command_string() const { return command_string_; } |
Wade Guthrie | efe1f0c | 2013-02-26 17:42:01 -0800 | [diff] [blame] | 242 | AttributeListConstRefPtr const_attributes() const { return attributes_; } |
| 243 | AttributeListRefPtr attributes() { return attributes_; } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 244 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 245 | virtual void Print(int log_level) const; |
| 246 | |
| 247 | protected: |
| 248 | // Returns a string of bytes representing _both_ an |nlmsghdr| and a |
| 249 | // |genlmsghdr|, filled-in, and its padding. |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame^] | 250 | virtual ByteString EncodeHeader(uint32_t sequence_number); |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 251 | // Reads the |nlmsghdr| and |genlmsghdr| headers and removes them from |
| 252 | // |input|. |
| 253 | virtual bool InitAndStripHeader(ByteString *input); |
| 254 | |
| 255 | AttributeListRefPtr attributes_; |
| 256 | const uint8 command_; |
| 257 | const char *command_string_; |
| 258 | |
| 259 | private: |
| 260 | DISALLOW_COPY_AND_ASSIGN(GenericNetlinkMessage); |
| 261 | }; |
| 262 | |
Wade Guthrie | 7187247 | 2013-03-05 10:33:38 -0800 | [diff] [blame] | 263 | // Control Messages |
| 264 | |
| 265 | class ControlNetlinkMessage : public GenericNetlinkMessage { |
| 266 | public: |
| 267 | static const uint16_t kMessageType; |
| 268 | ControlNetlinkMessage(uint8 command, const char *command_string) |
| 269 | : GenericNetlinkMessage(kMessageType, command, command_string) {} |
| 270 | |
| 271 | virtual bool InitFromNlmsg(const nlmsghdr *msg); |
| 272 | }; |
| 273 | |
| 274 | class NewFamilyMessage : public ControlNetlinkMessage { |
| 275 | public: |
| 276 | static const uint8_t kCommand; |
| 277 | static const char kCommandString[]; |
| 278 | |
| 279 | NewFamilyMessage() : ControlNetlinkMessage(kCommand, kCommandString) {} |
| 280 | |
| 281 | private: |
| 282 | DISALLOW_COPY_AND_ASSIGN(NewFamilyMessage); |
| 283 | }; |
| 284 | |
| 285 | class GetFamilyMessage : public ControlNetlinkMessage { |
| 286 | public: |
| 287 | static const uint8_t kCommand; |
| 288 | static const char kCommandString[]; |
| 289 | |
| 290 | GetFamilyMessage() : ControlNetlinkMessage(kCommand, kCommandString) {} |
| 291 | |
| 292 | private: |
| 293 | DISALLOW_COPY_AND_ASSIGN(GetFamilyMessage); |
| 294 | }; |
| 295 | |
| 296 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 297 | // Class for messages received from the mac80211 drivers by way of the |
| 298 | // cfg80211 kernel module. |
| 299 | class Nl80211Message : public GenericNetlinkMessage { |
| 300 | public: |
| 301 | static const char kMessageTypeString[]; |
| 302 | static const unsigned int kEthernetAddressBytes; |
| 303 | static const char kBogusMacAddress[]; |
| 304 | |
| 305 | Nl80211Message(uint8 command, const char *command_string) |
| 306 | : GenericNetlinkMessage(nl80211_message_type_, command, command_string) {} |
| 307 | virtual ~Nl80211Message() {} |
| 308 | |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame^] | 309 | // Sets the family_id / message_type for all Nl80211 messages. |
| 310 | static void SetMessageType(uint16_t message_type); |
| 311 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 312 | virtual bool InitFromNlmsg(const nlmsghdr *msg); |
| 313 | |
| 314 | uint8 command() const { return command_; } |
| 315 | const char *command_string() const { return command_string_; } |
| 316 | uint16_t message_type() const { return message_type_; } |
| 317 | uint32_t sequence_number() const { return sequence_number_; } |
| 318 | void set_sequence_number(uint32_t seq) { sequence_number_ = seq; } |
| 319 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 320 | // TODO(wdg): This needs to be moved to AttributeMac. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 321 | // Helper function to provide a string for a MAC address. If no attribute |
| 322 | // is found, this method returns 'false'. On any error with a non-NULL |
| 323 | // |value|, this method sets |value| to a bogus MAC address. |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 324 | bool GetMacAttributeString(int id, std::string *value) const; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 325 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 326 | // TODO(wdg): This needs to be moved to AttributeScanFrequencies. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 327 | // Helper function to provide a vector of scan frequencies for attributes |
| 328 | // that contain them (such as NL80211_ATTR_SCAN_FREQUENCIES). |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 329 | bool GetScanFrequenciesAttribute(int id, std::vector<uint32_t> *value) const; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 330 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 331 | // TODO(wdg): This needs to be moved to AttributeScanSSids. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 332 | // Helper function to provide a vector of SSIDs for attributes that contain |
| 333 | // them (such as NL80211_ATTR_SCAN_SSIDS). |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 334 | bool GetScanSsidsAttribute(int id, std::vector<std::string> *value) const; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 335 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 336 | // TODO(wdg): This needs to be moved to AttributeMac. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 337 | // Stringizes the MAC address found in 'arg'. If there are problems (such |
| 338 | // as a NULL |arg|), |value| is set to a bogus MAC address. |
| 339 | static std::string StringFromMacAddress(const uint8_t *arg); |
| 340 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 341 | // Returns a string representing the passed-in |status| or |reason|, the |
| 342 | // value of which has been acquired from libnl (for example, from the |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 343 | // NL80211_ATTR_STATUS_CODE or NL80211_ATTR_REASON_CODE attribute). |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 344 | static std::string StringFromReason(uint16_t reason); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 345 | static std::string StringFromStatus(uint16_t status); |
| 346 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 347 | private: |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 348 | static std::map<uint16_t, std::string> *reason_code_string_; |
| 349 | static std::map<uint16_t, std::string> *status_code_string_; |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 350 | static uint16_t nl80211_message_type_; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 351 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 352 | DISALLOW_COPY_AND_ASSIGN(Nl80211Message); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 353 | }; |
| 354 | |
| 355 | class Nl80211Frame { |
| 356 | public: |
| 357 | enum Type { |
| 358 | kAssocResponseFrameType = 0x10, |
| 359 | kReassocResponseFrameType = 0x30, |
| 360 | kAssocRequestFrameType = 0x00, |
| 361 | kReassocRequestFrameType = 0x20, |
| 362 | kAuthFrameType = 0xb0, |
| 363 | kDisassocFrameType = 0xa0, |
| 364 | kDeauthFrameType = 0xc0, |
| 365 | kIllegalFrameType = 0xff |
| 366 | }; |
| 367 | |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 368 | explicit Nl80211Frame(const ByteString &init); |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 369 | bool ToString(std::string *output) const; |
| 370 | bool IsEqual(const Nl80211Frame &other) const; |
| 371 | uint16_t reason() const { return reason_; } |
| 372 | uint16_t status() const { return status_; } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 373 | |
| 374 | private: |
| 375 | static const uint8_t kMinimumFrameByteCount; |
| 376 | static const uint8_t kFrameTypeMask; |
| 377 | |
| 378 | std::string mac_from_; |
| 379 | std::string mac_to_; |
| 380 | uint8_t frame_type_; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 381 | uint16_t reason_; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 382 | uint16_t status_; |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 383 | ByteString frame_; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 384 | |
| 385 | DISALLOW_COPY_AND_ASSIGN(Nl80211Frame); |
| 386 | }; |
| 387 | |
| 388 | // |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 389 | // Specific Nl80211Message types. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 390 | // |
| 391 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 392 | class AssociateMessage : 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 | AssociateMessage() : 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(AssociateMessage); |
| 401 | }; |
| 402 | |
| 403 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 404 | class AuthenticateMessage : 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 | AuthenticateMessage() : 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: |
| 412 | DISALLOW_COPY_AND_ASSIGN(AuthenticateMessage); |
| 413 | }; |
| 414 | |
| 415 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 416 | class CancelRemainOnChannelMessage : 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 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 421 | CancelRemainOnChannelMessage() |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 422 | : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 423 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 424 | private: |
| 425 | DISALLOW_COPY_AND_ASSIGN(CancelRemainOnChannelMessage); |
| 426 | }; |
| 427 | |
| 428 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 429 | class ConnectMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 430 | public: |
| 431 | static const uint8_t kCommand; |
| 432 | static const char kCommandString[]; |
| 433 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 434 | ConnectMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 435 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 436 | private: |
| 437 | DISALLOW_COPY_AND_ASSIGN(ConnectMessage); |
| 438 | }; |
| 439 | |
| 440 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 441 | class DeauthenticateMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 442 | public: |
| 443 | static const uint8_t kCommand; |
| 444 | static const char kCommandString[]; |
| 445 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 446 | DeauthenticateMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 447 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 448 | private: |
| 449 | DISALLOW_COPY_AND_ASSIGN(DeauthenticateMessage); |
| 450 | }; |
| 451 | |
| 452 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 453 | class DeleteStationMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 454 | public: |
| 455 | static const uint8_t kCommand; |
| 456 | static const char kCommandString[]; |
| 457 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 458 | DeleteStationMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 459 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 460 | private: |
| 461 | DISALLOW_COPY_AND_ASSIGN(DeleteStationMessage); |
| 462 | }; |
| 463 | |
| 464 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 465 | class DisassociateMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 466 | public: |
| 467 | static const uint8_t kCommand; |
| 468 | static const char kCommandString[]; |
| 469 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 470 | DisassociateMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 471 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 472 | private: |
| 473 | DISALLOW_COPY_AND_ASSIGN(DisassociateMessage); |
| 474 | }; |
| 475 | |
| 476 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 477 | class DisconnectMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 478 | public: |
| 479 | static const uint8_t kCommand; |
| 480 | static const char kCommandString[]; |
| 481 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 482 | DisconnectMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 483 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 484 | private: |
| 485 | DISALLOW_COPY_AND_ASSIGN(DisconnectMessage); |
| 486 | }; |
| 487 | |
| 488 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 489 | class FrameTxStatusMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 490 | public: |
| 491 | static const uint8_t kCommand; |
| 492 | static const char kCommandString[]; |
| 493 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 494 | FrameTxStatusMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 495 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 496 | private: |
| 497 | DISALLOW_COPY_AND_ASSIGN(FrameTxStatusMessage); |
| 498 | }; |
| 499 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 500 | class GetRegMessage : public Nl80211Message { |
| 501 | public: |
| 502 | static const uint8_t kCommand; |
| 503 | static const char kCommandString[]; |
| 504 | |
| 505 | GetRegMessage() : Nl80211Message(kCommand, kCommandString) {} |
| 506 | |
| 507 | private: |
| 508 | DISALLOW_COPY_AND_ASSIGN(GetRegMessage); |
| 509 | }; |
| 510 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 511 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 512 | class JoinIbssMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 513 | public: |
| 514 | static const uint8_t kCommand; |
| 515 | static const char kCommandString[]; |
| 516 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 517 | JoinIbssMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 518 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 519 | private: |
| 520 | DISALLOW_COPY_AND_ASSIGN(JoinIbssMessage); |
| 521 | }; |
| 522 | |
| 523 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 524 | class MichaelMicFailureMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 525 | public: |
| 526 | static const uint8_t kCommand; |
| 527 | static const char kCommandString[]; |
| 528 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 529 | MichaelMicFailureMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 530 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 531 | private: |
| 532 | DISALLOW_COPY_AND_ASSIGN(MichaelMicFailureMessage); |
| 533 | }; |
| 534 | |
| 535 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 536 | class NewScanResultsMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 537 | public: |
| 538 | static const uint8_t kCommand; |
| 539 | static const char kCommandString[]; |
| 540 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 541 | NewScanResultsMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 542 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 543 | private: |
| 544 | DISALLOW_COPY_AND_ASSIGN(NewScanResultsMessage); |
| 545 | }; |
| 546 | |
| 547 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 548 | class NewStationMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 549 | public: |
| 550 | static const uint8_t kCommand; |
| 551 | static const char kCommandString[]; |
| 552 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 553 | NewStationMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 554 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 555 | private: |
| 556 | DISALLOW_COPY_AND_ASSIGN(NewStationMessage); |
| 557 | }; |
| 558 | |
| 559 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 560 | class NewWifiMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 561 | public: |
| 562 | static const uint8_t kCommand; |
| 563 | static const char kCommandString[]; |
| 564 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 565 | NewWifiMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 566 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 567 | private: |
| 568 | DISALLOW_COPY_AND_ASSIGN(NewWifiMessage); |
| 569 | }; |
| 570 | |
| 571 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 572 | class NotifyCqmMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 573 | public: |
| 574 | static const uint8_t kCommand; |
| 575 | static const char kCommandString[]; |
| 576 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 577 | NotifyCqmMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 578 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 579 | private: |
| 580 | DISALLOW_COPY_AND_ASSIGN(NotifyCqmMessage); |
| 581 | }; |
| 582 | |
| 583 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 584 | class PmksaCandidateMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 585 | public: |
| 586 | static const uint8_t kCommand; |
| 587 | static const char kCommandString[]; |
| 588 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 589 | PmksaCandidateMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 590 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 591 | private: |
| 592 | DISALLOW_COPY_AND_ASSIGN(PmksaCandidateMessage); |
| 593 | }; |
| 594 | |
| 595 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 596 | class RegBeaconHintMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 597 | public: |
| 598 | static const uint8_t kCommand; |
| 599 | static const char kCommandString[]; |
| 600 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 601 | RegBeaconHintMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 602 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 603 | private: |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 604 | DISALLOW_COPY_AND_ASSIGN(RegBeaconHintMessage); |
| 605 | }; |
| 606 | |
| 607 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 608 | class RegChangeMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 609 | public: |
| 610 | static const uint8_t kCommand; |
| 611 | static const char kCommandString[]; |
| 612 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 613 | RegChangeMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 614 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 615 | private: |
| 616 | DISALLOW_COPY_AND_ASSIGN(RegChangeMessage); |
| 617 | }; |
| 618 | |
| 619 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 620 | class RemainOnChannelMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 621 | public: |
| 622 | static const uint8_t kCommand; |
| 623 | static const char kCommandString[]; |
| 624 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 625 | RemainOnChannelMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 626 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 627 | private: |
| 628 | DISALLOW_COPY_AND_ASSIGN(RemainOnChannelMessage); |
| 629 | }; |
| 630 | |
| 631 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 632 | class RoamMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 633 | public: |
| 634 | static const uint8_t kCommand; |
| 635 | static const char kCommandString[]; |
| 636 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 637 | RoamMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 638 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 639 | private: |
| 640 | DISALLOW_COPY_AND_ASSIGN(RoamMessage); |
| 641 | }; |
| 642 | |
| 643 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 644 | class ScanAbortedMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 645 | public: |
| 646 | static const uint8_t kCommand; |
| 647 | static const char kCommandString[]; |
| 648 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 649 | ScanAbortedMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 650 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 651 | private: |
| 652 | DISALLOW_COPY_AND_ASSIGN(ScanAbortedMessage); |
| 653 | }; |
| 654 | |
| 655 | |
Wade Guthrie | 7187247 | 2013-03-05 10:33:38 -0800 | [diff] [blame] | 656 | class GetScanMessage : public Nl80211Message { |
| 657 | public: |
| 658 | static const uint8_t kCommand; |
| 659 | static const char kCommandString[]; |
| 660 | |
| 661 | GetScanMessage() : Nl80211Message(kCommand, kCommandString) {} |
| 662 | |
| 663 | private: |
| 664 | DISALLOW_COPY_AND_ASSIGN(GetScanMessage); |
| 665 | }; |
| 666 | |
| 667 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 668 | class TriggerScanMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 669 | public: |
| 670 | static const uint8_t kCommand; |
| 671 | static const char kCommandString[]; |
| 672 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 673 | TriggerScanMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 674 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 675 | private: |
| 676 | DISALLOW_COPY_AND_ASSIGN(TriggerScanMessage); |
| 677 | }; |
| 678 | |
| 679 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 680 | class UnknownMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 681 | public: |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 682 | explicit UnknownMessage(uint8_t command) |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 683 | : Nl80211Message(command, kCommandString), |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 684 | command_(command) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 685 | |
| 686 | static const uint8_t kCommand; |
| 687 | static const char kCommandString[]; |
| 688 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 689 | private: |
| 690 | uint8_t command_; |
| 691 | |
| 692 | DISALLOW_COPY_AND_ASSIGN(UnknownMessage); |
| 693 | }; |
| 694 | |
| 695 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 696 | class UnprotDeauthenticateMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 697 | public: |
| 698 | static const uint8_t kCommand; |
| 699 | static const char kCommandString[]; |
| 700 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 701 | UnprotDeauthenticateMessage() |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 702 | : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 703 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 704 | private: |
| 705 | DISALLOW_COPY_AND_ASSIGN(UnprotDeauthenticateMessage); |
| 706 | }; |
| 707 | |
| 708 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 709 | class UnprotDisassociateMessage : public Nl80211Message { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 710 | public: |
| 711 | static const uint8_t kCommand; |
| 712 | static const char kCommandString[]; |
| 713 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 714 | UnprotDisassociateMessage() : Nl80211Message(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 715 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 716 | private: |
| 717 | DISALLOW_COPY_AND_ASSIGN(UnprotDisassociateMessage); |
| 718 | }; |
| 719 | |
| 720 | |
| 721 | // |
| 722 | // Factory class. |
| 723 | // |
| 724 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 725 | class NetlinkMessageFactory { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 726 | public: |
| 727 | // Ownership of the message is passed to the caller and, as such, he should |
| 728 | // delete it. |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 729 | static NetlinkMessage *CreateMessage(nlmsghdr *msg); |
| 730 | // TODO(wdg): Need a way for a class to register a callback and a message |
| 731 | // type. That way, CreateMessage can call the appropriate factory based on |
| 732 | // the incoming message type. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 733 | |
| 734 | private: |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 735 | DISALLOW_COPY_AND_ASSIGN(NetlinkMessageFactory); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 736 | }; |
| 737 | |
| 738 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 739 | // Nl80211MessageDataCollector - this class is used to collect data to be |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 740 | // used for unit tests. It is only invoked in this case. |
| 741 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 742 | class Nl80211MessageDataCollector { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 743 | public: |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 744 | static Nl80211MessageDataCollector *GetInstance(); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 745 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 746 | void CollectDebugData(const Nl80211Message &message, nlmsghdr *msg); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 747 | |
| 748 | protected: |
| 749 | friend struct |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 750 | base::DefaultLazyInstanceTraits<Nl80211MessageDataCollector>; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 751 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 752 | explicit Nl80211MessageDataCollector(); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 753 | |
| 754 | private: |
| 755 | // In order to limit the output from this class, I keep track of types I |
| 756 | // haven't yet printed. |
| 757 | std::map<uint8_t, bool> need_to_print; |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 758 | |
| 759 | DISALLOW_COPY_AND_ASSIGN(Nl80211MessageDataCollector); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 760 | }; |
| 761 | |
| 762 | } // namespace shill |
| 763 | |
| 764 | #endif // SHILL_USER_BOUND_NLMESSAGE_H_ |