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. |
| 29 | class UserBoundNlMessage { |
| 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 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 34 | UserBoundNlMessage(uint8 message_type, const char *message_type_string) |
| 35 | : message_(NULL), |
| 36 | message_type_(message_type), |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 37 | message_type_string_(message_type_string) {} |
| 38 | virtual ~UserBoundNlMessage() {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 39 | |
| 40 | // Non-trivial initialization. |
| 41 | virtual bool Init(nlattr *tb[NL80211_ATTR_MAX + 1], nlmsghdr *msg); |
| 42 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 43 | // Message ID is equivalent to the message's sequence number. |
| 44 | uint32_t GetId() const; |
| 45 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 46 | const AttributeList &attributes() const { return attributes_; } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 47 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 48 | // TODO(wdg): This needs to be moved to AttributeMac. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 49 | // Helper function to provide a string for a MAC address. If no attribute |
| 50 | // is found, this method returns 'false'. On any error with a non-NULL |
| 51 | // |value|, this method sets |value| to a bogus MAC address. |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 52 | bool GetMacAttributeString(nl80211_attrs id, std::string *value) const; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 53 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 54 | // TODO(wdg): This needs to be moved to AttributeScanFrequencies. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 55 | // Helper function to provide a vector of scan frequencies for attributes |
| 56 | // that contain them (such as NL80211_ATTR_SCAN_FREQUENCIES). |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 57 | bool GetScanFrequenciesAttribute(nl80211_attrs id, |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 58 | std::vector<uint32_t> *value) const; |
| 59 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 60 | // TODO(wdg): This needs to be moved to AttributeScanSSids. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 61 | // Helper function to provide a vector of SSIDs for attributes that contain |
| 62 | // them (such as NL80211_ATTR_SCAN_SSIDS). |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 63 | bool GetScanSsidsAttribute(nl80211_attrs id, |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 64 | std::vector<std::string> *value) const; |
| 65 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 66 | // TODO(wdg): This needs to be moved to AttributeMac. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 67 | // Stringizes the MAC address found in 'arg'. If there are problems (such |
| 68 | // as a NULL |arg|), |value| is set to a bogus MAC address. |
| 69 | static std::string StringFromMacAddress(const uint8_t *arg); |
| 70 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 71 | // Returns a string representing the passed-in |status| or |reason|, the |
| 72 | // value of which has been acquired from libnl (for example, from the |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 73 | // NL80211_ATTR_STATUS_CODE or NL80211_ATTR_REASON_CODE attribute). |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 74 | static std::string StringFromReason(uint16_t reason); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 75 | static std::string StringFromStatus(uint16_t status); |
| 76 | |
repo sync | 1538d44 | 2012-12-20 15:24:35 -0800 | [diff] [blame^] | 77 | std::string GenericToString() const; |
| 78 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 79 | // Returns a string that describes this message. |
| 80 | virtual std::string ToString() const { return GetHeaderString(); } |
| 81 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 82 | uint8 message_type() const { return message_type_; } |
| 83 | const char *message_type_string() const { return message_type_string_; } |
| 84 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 85 | protected: |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 86 | // Returns a string that should precede all user-bound message strings. |
| 87 | virtual std::string GetHeaderString() const; |
| 88 | |
| 89 | // Returns a string that describes the contents of the frame pointed to by |
| 90 | // 'attr'. |
| 91 | std::string StringFromFrame(nl80211_attrs attr_name) const; |
| 92 | |
| 93 | // Converts key_type to a string. |
| 94 | static std::string StringFromKeyType(nl80211_key_type key_type); |
| 95 | |
| 96 | // Returns a string representation of the REG initiator described by the |
| 97 | // method's parameter. |
| 98 | static std::string StringFromRegInitiator(__u8 initiator); |
| 99 | |
| 100 | // Returns a string based on the SSID found in 'data'. Non-printable |
| 101 | // characters are string-ized. |
| 102 | static std::string StringFromSsid(const uint8_t len, const uint8_t *data); |
| 103 | |
| 104 | private: |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 105 | friend class Config80211Test; |
| 106 | FRIEND_TEST(Config80211Test, NL80211_CMD_NOTIFY_CQM); |
| 107 | |
| 108 | static const uint32_t kIllegalMessage; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 109 | |
| 110 | nlmsghdr *message_; |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 111 | const uint8 message_type_; |
| 112 | const char *message_type_string_; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 113 | static std::map<uint16_t, std::string> *reason_code_string_; |
| 114 | static std::map<uint16_t, std::string> *status_code_string_; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 115 | |
| 116 | AttributeList attributes_; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 117 | |
| 118 | DISALLOW_COPY_AND_ASSIGN(UserBoundNlMessage); |
| 119 | }; |
| 120 | |
| 121 | class Nl80211Frame { |
| 122 | public: |
| 123 | enum Type { |
| 124 | kAssocResponseFrameType = 0x10, |
| 125 | kReassocResponseFrameType = 0x30, |
| 126 | kAssocRequestFrameType = 0x00, |
| 127 | kReassocRequestFrameType = 0x20, |
| 128 | kAuthFrameType = 0xb0, |
| 129 | kDisassocFrameType = 0xa0, |
| 130 | kDeauthFrameType = 0xc0, |
| 131 | kIllegalFrameType = 0xff |
| 132 | }; |
| 133 | |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 134 | explicit Nl80211Frame(const ByteString &init); |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 135 | bool ToString(std::string *output) const; |
| 136 | bool IsEqual(const Nl80211Frame &other) const; |
| 137 | uint16_t reason() const { return reason_; } |
| 138 | uint16_t status() const { return status_; } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 139 | |
| 140 | private: |
| 141 | static const uint8_t kMinimumFrameByteCount; |
| 142 | static const uint8_t kFrameTypeMask; |
| 143 | |
| 144 | std::string mac_from_; |
| 145 | std::string mac_to_; |
| 146 | uint8_t frame_type_; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 147 | uint16_t reason_; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 148 | uint16_t status_; |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 149 | ByteString frame_; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 150 | |
| 151 | DISALLOW_COPY_AND_ASSIGN(Nl80211Frame); |
| 152 | }; |
| 153 | |
| 154 | // |
| 155 | // Specific UserBoundNlMessage types. |
| 156 | // |
| 157 | |
| 158 | class AssociateMessage : public UserBoundNlMessage { |
| 159 | public: |
| 160 | static const uint8_t kCommand; |
| 161 | static const char kCommandString[]; |
| 162 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 163 | AssociateMessage() : UserBoundNlMessage(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 164 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 165 | virtual std::string ToString() const; |
| 166 | |
| 167 | private: |
| 168 | DISALLOW_COPY_AND_ASSIGN(AssociateMessage); |
| 169 | }; |
| 170 | |
| 171 | |
| 172 | class AuthenticateMessage : public UserBoundNlMessage { |
| 173 | public: |
| 174 | static const uint8_t kCommand; |
| 175 | static const char kCommandString[]; |
| 176 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 177 | AuthenticateMessage() : UserBoundNlMessage(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 178 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 179 | virtual std::string ToString() const; |
| 180 | |
| 181 | private: |
| 182 | DISALLOW_COPY_AND_ASSIGN(AuthenticateMessage); |
| 183 | }; |
| 184 | |
| 185 | |
| 186 | class CancelRemainOnChannelMessage : public UserBoundNlMessage { |
| 187 | public: |
| 188 | static const uint8_t kCommand; |
| 189 | static const char kCommandString[]; |
| 190 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 191 | CancelRemainOnChannelMessage() |
| 192 | : UserBoundNlMessage(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 193 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 194 | virtual std::string ToString() const; |
| 195 | |
| 196 | private: |
| 197 | DISALLOW_COPY_AND_ASSIGN(CancelRemainOnChannelMessage); |
| 198 | }; |
| 199 | |
| 200 | |
| 201 | class ConnectMessage : public UserBoundNlMessage { |
| 202 | public: |
| 203 | static const uint8_t kCommand; |
| 204 | static const char kCommandString[]; |
| 205 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 206 | ConnectMessage() : UserBoundNlMessage(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 207 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 208 | virtual std::string ToString() const; |
| 209 | |
| 210 | private: |
| 211 | DISALLOW_COPY_AND_ASSIGN(ConnectMessage); |
| 212 | }; |
| 213 | |
| 214 | |
| 215 | class DeauthenticateMessage : public UserBoundNlMessage { |
| 216 | public: |
| 217 | static const uint8_t kCommand; |
| 218 | static const char kCommandString[]; |
| 219 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 220 | DeauthenticateMessage() : UserBoundNlMessage(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 221 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 222 | virtual std::string ToString() const; |
| 223 | |
| 224 | private: |
| 225 | DISALLOW_COPY_AND_ASSIGN(DeauthenticateMessage); |
| 226 | }; |
| 227 | |
| 228 | |
| 229 | class DeleteStationMessage : public UserBoundNlMessage { |
| 230 | public: |
| 231 | static const uint8_t kCommand; |
| 232 | static const char kCommandString[]; |
| 233 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 234 | DeleteStationMessage() : UserBoundNlMessage(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 235 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 236 | virtual std::string ToString() const; |
| 237 | |
| 238 | private: |
| 239 | DISALLOW_COPY_AND_ASSIGN(DeleteStationMessage); |
| 240 | }; |
| 241 | |
| 242 | |
| 243 | class DisassociateMessage : public UserBoundNlMessage { |
| 244 | public: |
| 245 | static const uint8_t kCommand; |
| 246 | static const char kCommandString[]; |
| 247 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 248 | DisassociateMessage() : UserBoundNlMessage(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 249 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 250 | virtual std::string ToString() const; |
| 251 | |
| 252 | private: |
| 253 | DISALLOW_COPY_AND_ASSIGN(DisassociateMessage); |
| 254 | }; |
| 255 | |
| 256 | |
| 257 | class DisconnectMessage : public UserBoundNlMessage { |
| 258 | public: |
| 259 | static const uint8_t kCommand; |
| 260 | static const char kCommandString[]; |
| 261 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 262 | DisconnectMessage() : 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(DisconnectMessage); |
| 268 | }; |
| 269 | |
| 270 | |
| 271 | class FrameTxStatusMessage : 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 | FrameTxStatusMessage() : 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(FrameTxStatusMessage); |
| 282 | }; |
| 283 | |
| 284 | |
| 285 | class JoinIbssMessage : 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 | JoinIbssMessage() : 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(JoinIbssMessage); |
| 296 | }; |
| 297 | |
| 298 | |
| 299 | class MichaelMicFailureMessage : 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 | MichaelMicFailureMessage() : 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(MichaelMicFailureMessage); |
| 310 | }; |
| 311 | |
| 312 | |
| 313 | class NewScanResultsMessage : 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 | NewScanResultsMessage() : 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(NewScanResultsMessage); |
| 324 | }; |
| 325 | |
| 326 | |
| 327 | class NewStationMessage : 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 | NewStationMessage() : 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(NewStationMessage); |
| 338 | }; |
| 339 | |
| 340 | |
| 341 | class NewWifiMessage : 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 | NewWifiMessage() : 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(NewWifiMessage); |
| 352 | }; |
| 353 | |
| 354 | |
| 355 | class NotifyCqmMessage : 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 | NotifyCqmMessage() : 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(NotifyCqmMessage); |
| 366 | }; |
| 367 | |
| 368 | |
| 369 | class PmksaCandidateMessage : 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 | PmksaCandidateMessage() : 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(PmksaCandidateMessage); |
| 380 | }; |
| 381 | |
| 382 | |
| 383 | class RegBeaconHintMessage : 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 | RegBeaconHintMessage() : 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 | struct ieee80211_beacon_channel { |
| 394 | __u16 center_freq; |
| 395 | bool passive_scan; |
| 396 | bool no_ibss; |
| 397 | }; |
| 398 | |
| 399 | // Returns the channel ID calculated from the 802.11 frequency. |
| 400 | static int ChannelFromIeee80211Frequency(int freq); |
| 401 | |
| 402 | // Sets values in |chan| based on attributes in |tb|, the array of pointers |
| 403 | // to netlink attributes, indexed by attribute type. |
| 404 | int ParseBeaconHintChan(const nlattr *tb, |
| 405 | ieee80211_beacon_channel *chan) const; |
| 406 | |
| 407 | DISALLOW_COPY_AND_ASSIGN(RegBeaconHintMessage); |
| 408 | }; |
| 409 | |
| 410 | |
| 411 | class RegChangeMessage : 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 | RegChangeMessage() : 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(RegChangeMessage); |
| 422 | }; |
| 423 | |
| 424 | |
| 425 | class RemainOnChannelMessage : 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 | RemainOnChannelMessage() : 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(RemainOnChannelMessage); |
| 436 | }; |
| 437 | |
| 438 | |
| 439 | class RoamMessage : 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 | RoamMessage() : 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(RoamMessage); |
| 450 | }; |
| 451 | |
| 452 | |
| 453 | class ScanAbortedMessage : 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 | ScanAbortedMessage() : 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 | DISALLOW_COPY_AND_ASSIGN(ScanAbortedMessage); |
| 464 | }; |
| 465 | |
| 466 | |
| 467 | class TriggerScanMessage : public UserBoundNlMessage { |
| 468 | public: |
| 469 | static const uint8_t kCommand; |
| 470 | static const char kCommandString[]; |
| 471 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 472 | TriggerScanMessage() : UserBoundNlMessage(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 473 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 474 | virtual std::string ToString() const; |
| 475 | |
| 476 | private: |
| 477 | DISALLOW_COPY_AND_ASSIGN(TriggerScanMessage); |
| 478 | }; |
| 479 | |
| 480 | |
| 481 | class UnknownMessage : public UserBoundNlMessage { |
| 482 | public: |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 483 | explicit UnknownMessage(uint8_t command) |
| 484 | : UserBoundNlMessage(command, kCommandString), |
| 485 | command_(command) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 486 | |
| 487 | static const uint8_t kCommand; |
| 488 | static const char kCommandString[]; |
| 489 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 490 | virtual std::string ToString() const; |
| 491 | |
| 492 | private: |
| 493 | uint8_t command_; |
| 494 | |
| 495 | DISALLOW_COPY_AND_ASSIGN(UnknownMessage); |
| 496 | }; |
| 497 | |
| 498 | |
| 499 | class UnprotDeauthenticateMessage : public UserBoundNlMessage { |
| 500 | public: |
| 501 | static const uint8_t kCommand; |
| 502 | static const char kCommandString[]; |
| 503 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 504 | UnprotDeauthenticateMessage() |
| 505 | : UserBoundNlMessage(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 506 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 507 | virtual std::string ToString() const; |
| 508 | |
| 509 | private: |
| 510 | DISALLOW_COPY_AND_ASSIGN(UnprotDeauthenticateMessage); |
| 511 | }; |
| 512 | |
| 513 | |
| 514 | class UnprotDisassociateMessage : public UserBoundNlMessage { |
| 515 | public: |
| 516 | static const uint8_t kCommand; |
| 517 | static const char kCommandString[]; |
| 518 | |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 519 | UnprotDisassociateMessage() : UserBoundNlMessage(kCommand, kCommandString) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 520 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 521 | virtual std::string ToString() const; |
| 522 | |
| 523 | private: |
| 524 | DISALLOW_COPY_AND_ASSIGN(UnprotDisassociateMessage); |
| 525 | }; |
| 526 | |
| 527 | |
| 528 | // |
| 529 | // Factory class. |
| 530 | // |
| 531 | |
| 532 | class UserBoundNlMessageFactory { |
| 533 | public: |
| 534 | // Ownership of the message is passed to the caller and, as such, he should |
| 535 | // delete it. |
| 536 | static UserBoundNlMessage *CreateMessage(nlmsghdr *msg); |
| 537 | |
| 538 | private: |
| 539 | DISALLOW_COPY_AND_ASSIGN(UserBoundNlMessageFactory); |
| 540 | }; |
| 541 | |
| 542 | |
| 543 | // UserBoundNlMessageDataCollector - this class is used to collect data to be |
| 544 | // used for unit tests. It is only invoked in this case. |
| 545 | |
| 546 | class UserBoundNlMessageDataCollector { |
| 547 | public: |
| 548 | // This is a singleton -- use Config80211::GetInstance()->Foo() |
| 549 | static UserBoundNlMessageDataCollector *GetInstance(); |
| 550 | |
| 551 | void CollectDebugData(const UserBoundNlMessage &message, nlmsghdr *msg); |
| 552 | |
| 553 | protected: |
| 554 | friend struct |
| 555 | base::DefaultLazyInstanceTraits<UserBoundNlMessageDataCollector>; |
| 556 | |
| 557 | explicit UserBoundNlMessageDataCollector(); |
| 558 | |
| 559 | private: |
| 560 | // In order to limit the output from this class, I keep track of types I |
| 561 | // haven't yet printed. |
| 562 | std::map<uint8_t, bool> need_to_print; |
| 563 | }; |
| 564 | |
| 565 | } // namespace shill |
| 566 | |
| 567 | #endif // SHILL_USER_BOUND_NLMESSAGE_H_ |