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