blob: 3cec60aa4100c8a7d68a0cc5b718b739b4bcb649 [file] [log] [blame]
Wade Guthrie0d438532012-05-18 14:18:50 -07001// 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 Guthrie8343f7f2012-12-04 13:52:32 -08008#include <linux/nl80211.h>
9
Wade Guthrie0d438532012-05-18 14:18:50 -070010#include <iomanip>
11#include <map>
Wade Guthrie0d438532012-05-18 14:18:50 -070012#include <string>
Wade Guthrie8343f7f2012-12-04 13:52:32 -080013#include <vector>
Wade Guthrie0d438532012-05-18 14:18:50 -070014
15#include <base/basictypes.h>
16#include <base/bind.h>
17#include <base/lazy_instance.h>
18#include <gtest/gtest.h>
19
repo sync90ee0fa2012-12-18 10:08:08 -080020#include "shill/attribute_list.h"
repo sync1538d442012-12-20 15:24:35 -080021#include "shill/byte_string.h"
Wade Guthrie16196242012-11-20 15:53:52 -080022
Wade Guthrie0d438532012-05-18 14:18:50 -070023struct nlattr;
24struct nlmsghdr;
25
26namespace shill {
27
28// Class for messages received from libnl.
repo syncdc085c82012-12-28 08:54:41 -080029class Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -070030 public:
Wade Guthrie8343f7f2012-12-04 13:52:32 -080031 static const unsigned int kEthernetAddressBytes;
Wade Guthrie0d438532012-05-18 14:18:50 -070032 static const char kBogusMacAddress[];
33
repo syncdc085c82012-12-28 08:54:41 -080034 Nl80211Message(uint8 message_type, const char *message_type_string)
repo sync0efa9f02012-12-28 13:40:20 -080035 : message_type_(message_type),
repo syncdc085c82012-12-28 08:54:41 -080036 message_type_string_(message_type_string),
37 sequence_number_(kIllegalMessage) {}
38 virtual ~Nl80211Message() {}
Wade Guthrie0d438532012-05-18 14:18:50 -070039
repo syncdc085c82012-12-28 08:54:41 -080040 // Initializes the message with bytes from the kernel.
repo sync0efa9f02012-12-28 13:40:20 -080041 virtual bool InitFromNlmsg(const nlmsghdr *msg);
Wade Guthrie0d438532012-05-18 14:18:50 -070042
repo syncdc085c82012-12-28 08:54:41 -080043 uint32_t sequence_number() const { return sequence_number_; }
44
45 void set_sequence_number(uint32_t seq) { sequence_number_ = seq; }
Wade Guthrie0d438532012-05-18 14:18:50 -070046
repo sync90ee0fa2012-12-18 10:08:08 -080047 const AttributeList &attributes() const { return attributes_; }
Wade Guthrie0d438532012-05-18 14:18:50 -070048
repo sync90ee0fa2012-12-18 10:08:08 -080049 // TODO(wdg): This needs to be moved to AttributeMac.
Wade Guthrie0d438532012-05-18 14:18:50 -070050 // Helper function to provide a string for a MAC address. If no attribute
51 // is found, this method returns 'false'. On any error with a non-NULL
52 // |value|, this method sets |value| to a bogus MAC address.
repo sync12cca802012-12-19 17:34:22 -080053 bool GetMacAttributeString(nl80211_attrs id, std::string *value) const;
Wade Guthrie0d438532012-05-18 14:18:50 -070054
repo sync90ee0fa2012-12-18 10:08:08 -080055 // TODO(wdg): This needs to be moved to AttributeScanFrequencies.
Wade Guthrie0d438532012-05-18 14:18:50 -070056 // Helper function to provide a vector of scan frequencies for attributes
57 // that contain them (such as NL80211_ATTR_SCAN_FREQUENCIES).
repo sync12cca802012-12-19 17:34:22 -080058 bool GetScanFrequenciesAttribute(nl80211_attrs id,
Wade Guthrie0d438532012-05-18 14:18:50 -070059 std::vector<uint32_t> *value) const;
60
repo sync90ee0fa2012-12-18 10:08:08 -080061 // TODO(wdg): This needs to be moved to AttributeScanSSids.
Wade Guthrie0d438532012-05-18 14:18:50 -070062 // Helper function to provide a vector of SSIDs for attributes that contain
63 // them (such as NL80211_ATTR_SCAN_SSIDS).
repo sync12cca802012-12-19 17:34:22 -080064 bool GetScanSsidsAttribute(nl80211_attrs id,
Wade Guthrie0d438532012-05-18 14:18:50 -070065 std::vector<std::string> *value) const;
66
repo sync90ee0fa2012-12-18 10:08:08 -080067 // TODO(wdg): This needs to be moved to AttributeMac.
Wade Guthrie0d438532012-05-18 14:18:50 -070068 // Stringizes the MAC address found in 'arg'. If there are problems (such
69 // as a NULL |arg|), |value| is set to a bogus MAC address.
70 static std::string StringFromMacAddress(const uint8_t *arg);
71
Wade Guthried4977f22012-08-22 12:37:54 -070072 // Returns a string representing the passed-in |status| or |reason|, the
73 // value of which has been acquired from libnl (for example, from the
Wade Guthrie0d438532012-05-18 14:18:50 -070074 // NL80211_ATTR_STATUS_CODE or NL80211_ATTR_REASON_CODE attribute).
Wade Guthried4977f22012-08-22 12:37:54 -070075 static std::string StringFromReason(uint16_t reason);
Wade Guthrie0d438532012-05-18 14:18:50 -070076 static std::string StringFromStatus(uint16_t status);
77
repo syncdc085c82012-12-28 08:54:41 -080078 // Returns a string that describes the message in terms of its attributes.
79 // For example, a trigger scan message might look like:
80 // Received _NL80211_CMD_TRIGGER_SCAN (33)
81 // Attr:NL80211_ATTR_WIPHY=0 Type:uint32_t
82 // Attr:NL80211_ATTR_IFINDEX=2 Type:uint32_t
83 // Attr:NL80211_ATTR_SCAN_FREQUENCIES=296 bytes: 0x2c [...]
repo sync1538d442012-12-20 15:24:35 -080084 std::string GenericToString() const;
85
repo syncdc085c82012-12-28 08:54:41 -080086 // Returns a string that describes this message in a message-type-specific
87 // way. For example, a trigger scan message might look like:
88 // @wlan0 (phy #0): scan started; frequencies: 2412, [...] 5825, ; SSIDs: "",
Wade Guthrie0d438532012-05-18 14:18:50 -070089 virtual std::string ToString() const { return GetHeaderString(); }
90
Christopher Wiley764538d2012-11-09 10:58:23 -080091 uint8 message_type() const { return message_type_; }
92 const char *message_type_string() const { return message_type_string_; }
93
repo syncdc085c82012-12-28 08:54:41 -080094 // Returns a netlink message suitable for Sockets::Send. Return value is
95 // empty on failure. |nlmsg_type| needs to be the family id returned by
96 // |genl_ctrl_resolve|.
97 ByteString Encode(uint16_t nlmsg_type) const;
98
Wade Guthrie0d438532012-05-18 14:18:50 -070099 protected:
Wade Guthrie0d438532012-05-18 14:18:50 -0700100 // Returns a string that should precede all user-bound message strings.
101 virtual std::string GetHeaderString() const;
102
103 // Returns a string that describes the contents of the frame pointed to by
104 // 'attr'.
105 std::string StringFromFrame(nl80211_attrs attr_name) const;
106
107 // Converts key_type to a string.
108 static std::string StringFromKeyType(nl80211_key_type key_type);
109
110 // Returns a string representation of the REG initiator described by the
111 // method's parameter.
112 static std::string StringFromRegInitiator(__u8 initiator);
113
114 // Returns a string based on the SSID found in 'data'. Non-printable
115 // characters are string-ized.
116 static std::string StringFromSsid(const uint8_t len, const uint8_t *data);
117
118 private:
Wade Guthrie0d438532012-05-18 14:18:50 -0700119 friend class Config80211Test;
120 FRIEND_TEST(Config80211Test, NL80211_CMD_NOTIFY_CQM);
121
122 static const uint32_t kIllegalMessage;
Wade Guthrie0d438532012-05-18 14:18:50 -0700123
Christopher Wiley764538d2012-11-09 10:58:23 -0800124 const uint8 message_type_;
125 const char *message_type_string_;
Wade Guthried4977f22012-08-22 12:37:54 -0700126 static std::map<uint16_t, std::string> *reason_code_string_;
127 static std::map<uint16_t, std::string> *status_code_string_;
repo syncdc085c82012-12-28 08:54:41 -0800128 uint32_t sequence_number_;
repo sync90ee0fa2012-12-18 10:08:08 -0800129
130 AttributeList attributes_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700131
repo syncdc085c82012-12-28 08:54:41 -0800132 DISALLOW_COPY_AND_ASSIGN(Nl80211Message);
Wade Guthrie0d438532012-05-18 14:18:50 -0700133};
134
135class Nl80211Frame {
136 public:
137 enum Type {
138 kAssocResponseFrameType = 0x10,
139 kReassocResponseFrameType = 0x30,
140 kAssocRequestFrameType = 0x00,
141 kReassocRequestFrameType = 0x20,
142 kAuthFrameType = 0xb0,
143 kDisassocFrameType = 0xa0,
144 kDeauthFrameType = 0xc0,
145 kIllegalFrameType = 0xff
146 };
147
repo syncd316eb72012-12-10 15:48:47 -0800148 explicit Nl80211Frame(const ByteString &init);
Wade Guthried4977f22012-08-22 12:37:54 -0700149 bool ToString(std::string *output) const;
150 bool IsEqual(const Nl80211Frame &other) const;
151 uint16_t reason() const { return reason_; }
152 uint16_t status() const { return status_; }
Wade Guthrie0d438532012-05-18 14:18:50 -0700153
154 private:
155 static const uint8_t kMinimumFrameByteCount;
156 static const uint8_t kFrameTypeMask;
157
158 std::string mac_from_;
159 std::string mac_to_;
160 uint8_t frame_type_;
Wade Guthried4977f22012-08-22 12:37:54 -0700161 uint16_t reason_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700162 uint16_t status_;
Wade Guthrie8343f7f2012-12-04 13:52:32 -0800163 ByteString frame_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700164
165 DISALLOW_COPY_AND_ASSIGN(Nl80211Frame);
166};
167
168//
repo syncdc085c82012-12-28 08:54:41 -0800169// Specific Nl80211Message types.
Wade Guthrie0d438532012-05-18 14:18:50 -0700170//
171
repo sync0efa9f02012-12-28 13:40:20 -0800172class AckMessage : public Nl80211Message {
173 public:
174 static const uint8_t kCommand;
175 static const char kCommandString[];
176
177 AckMessage() : Nl80211Message(kCommand, kCommandString) {}
178
179 virtual std::string ToString() const;
180
181 private:
182 DISALLOW_COPY_AND_ASSIGN(AckMessage);
183};
184
repo syncdc085c82012-12-28 08:54:41 -0800185class AssociateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700186 public:
187 static const uint8_t kCommand;
188 static const char kCommandString[];
189
repo syncdc085c82012-12-28 08:54:41 -0800190 AssociateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700191
Wade Guthrie0d438532012-05-18 14:18:50 -0700192 virtual std::string ToString() const;
193
194 private:
195 DISALLOW_COPY_AND_ASSIGN(AssociateMessage);
196};
197
198
repo syncdc085c82012-12-28 08:54:41 -0800199class AuthenticateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700200 public:
201 static const uint8_t kCommand;
202 static const char kCommandString[];
203
repo syncdc085c82012-12-28 08:54:41 -0800204 AuthenticateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700205
Wade Guthrie0d438532012-05-18 14:18:50 -0700206 virtual std::string ToString() const;
207
208 private:
209 DISALLOW_COPY_AND_ASSIGN(AuthenticateMessage);
210};
211
212
repo syncdc085c82012-12-28 08:54:41 -0800213class CancelRemainOnChannelMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700214 public:
215 static const uint8_t kCommand;
216 static const char kCommandString[];
217
Christopher Wiley764538d2012-11-09 10:58:23 -0800218 CancelRemainOnChannelMessage()
repo syncdc085c82012-12-28 08:54:41 -0800219 : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700220
Wade Guthrie0d438532012-05-18 14:18:50 -0700221 virtual std::string ToString() const;
222
223 private:
224 DISALLOW_COPY_AND_ASSIGN(CancelRemainOnChannelMessage);
225};
226
227
repo syncdc085c82012-12-28 08:54:41 -0800228class ConnectMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700229 public:
230 static const uint8_t kCommand;
231 static const char kCommandString[];
232
repo syncdc085c82012-12-28 08:54:41 -0800233 ConnectMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700234
Wade Guthrie0d438532012-05-18 14:18:50 -0700235 virtual std::string ToString() const;
236
237 private:
238 DISALLOW_COPY_AND_ASSIGN(ConnectMessage);
239};
240
241
repo syncdc085c82012-12-28 08:54:41 -0800242class DeauthenticateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700243 public:
244 static const uint8_t kCommand;
245 static const char kCommandString[];
246
repo syncdc085c82012-12-28 08:54:41 -0800247 DeauthenticateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700248
Wade Guthrie0d438532012-05-18 14:18:50 -0700249 virtual std::string ToString() const;
250
251 private:
252 DISALLOW_COPY_AND_ASSIGN(DeauthenticateMessage);
253};
254
255
repo syncdc085c82012-12-28 08:54:41 -0800256class DeleteStationMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700257 public:
258 static const uint8_t kCommand;
259 static const char kCommandString[];
260
repo syncdc085c82012-12-28 08:54:41 -0800261 DeleteStationMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700262
Wade Guthrie0d438532012-05-18 14:18:50 -0700263 virtual std::string ToString() const;
264
265 private:
266 DISALLOW_COPY_AND_ASSIGN(DeleteStationMessage);
267};
268
269
repo syncdc085c82012-12-28 08:54:41 -0800270class DisassociateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700271 public:
272 static const uint8_t kCommand;
273 static const char kCommandString[];
274
repo syncdc085c82012-12-28 08:54:41 -0800275 DisassociateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700276
Wade Guthrie0d438532012-05-18 14:18:50 -0700277 virtual std::string ToString() const;
278
279 private:
280 DISALLOW_COPY_AND_ASSIGN(DisassociateMessage);
281};
282
283
repo syncdc085c82012-12-28 08:54:41 -0800284class DisconnectMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700285 public:
286 static const uint8_t kCommand;
287 static const char kCommandString[];
288
repo syncdc085c82012-12-28 08:54:41 -0800289 DisconnectMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700290
Wade Guthrie0d438532012-05-18 14:18:50 -0700291 virtual std::string ToString() const;
292
293 private:
294 DISALLOW_COPY_AND_ASSIGN(DisconnectMessage);
295};
296
297
repo sync0efa9f02012-12-28 13:40:20 -0800298class ErrorMessage : public Nl80211Message {
299 public:
300 static const uint8_t kCommand;
301 static const char kCommandString[];
302
Wade Guthrie3af8b4d2013-01-10 08:39:30 -0800303 explicit ErrorMessage(uint32_t error);
repo sync0efa9f02012-12-28 13:40:20 -0800304
305 virtual std::string ToString() const;
306
307 private:
308 uint32_t error_;
309
310 DISALLOW_COPY_AND_ASSIGN(ErrorMessage);
311};
312
313
repo syncdc085c82012-12-28 08:54:41 -0800314class FrameTxStatusMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700315 public:
316 static const uint8_t kCommand;
317 static const char kCommandString[];
318
repo syncdc085c82012-12-28 08:54:41 -0800319 FrameTxStatusMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700320
Wade Guthrie0d438532012-05-18 14:18:50 -0700321 virtual std::string ToString() const;
322
323 private:
324 DISALLOW_COPY_AND_ASSIGN(FrameTxStatusMessage);
325};
326
repo sync0efa9f02012-12-28 13:40:20 -0800327class GetRegMessage : public Nl80211Message {
328 public:
329 static const uint8_t kCommand;
330 static const char kCommandString[];
331
332 GetRegMessage() : Nl80211Message(kCommand, kCommandString) {}
333
334 private:
335 DISALLOW_COPY_AND_ASSIGN(GetRegMessage);
336};
337
Wade Guthrie0d438532012-05-18 14:18:50 -0700338
repo syncdc085c82012-12-28 08:54:41 -0800339class JoinIbssMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700340 public:
341 static const uint8_t kCommand;
342 static const char kCommandString[];
343
repo syncdc085c82012-12-28 08:54:41 -0800344 JoinIbssMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700345
Wade Guthrie0d438532012-05-18 14:18:50 -0700346 virtual std::string ToString() const;
347
348 private:
349 DISALLOW_COPY_AND_ASSIGN(JoinIbssMessage);
350};
351
352
repo syncdc085c82012-12-28 08:54:41 -0800353class MichaelMicFailureMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700354 public:
355 static const uint8_t kCommand;
356 static const char kCommandString[];
357
repo syncdc085c82012-12-28 08:54:41 -0800358 MichaelMicFailureMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700359
Wade Guthrie0d438532012-05-18 14:18:50 -0700360 virtual std::string ToString() const;
361
362 private:
363 DISALLOW_COPY_AND_ASSIGN(MichaelMicFailureMessage);
364};
365
366
repo syncdc085c82012-12-28 08:54:41 -0800367class NewScanResultsMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700368 public:
369 static const uint8_t kCommand;
370 static const char kCommandString[];
371
repo syncdc085c82012-12-28 08:54:41 -0800372 NewScanResultsMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700373
Wade Guthrie0d438532012-05-18 14:18:50 -0700374 virtual std::string ToString() const;
375
376 private:
377 DISALLOW_COPY_AND_ASSIGN(NewScanResultsMessage);
378};
379
380
repo syncdc085c82012-12-28 08:54:41 -0800381class NewStationMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700382 public:
383 static const uint8_t kCommand;
384 static const char kCommandString[];
385
repo syncdc085c82012-12-28 08:54:41 -0800386 NewStationMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700387
Wade Guthrie0d438532012-05-18 14:18:50 -0700388 virtual std::string ToString() const;
389
390 private:
391 DISALLOW_COPY_AND_ASSIGN(NewStationMessage);
392};
393
394
repo syncdc085c82012-12-28 08:54:41 -0800395class NewWifiMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700396 public:
397 static const uint8_t kCommand;
398 static const char kCommandString[];
399
repo syncdc085c82012-12-28 08:54:41 -0800400 NewWifiMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700401
Wade Guthrie0d438532012-05-18 14:18:50 -0700402 virtual std::string ToString() const;
403
404 private:
405 DISALLOW_COPY_AND_ASSIGN(NewWifiMessage);
406};
407
408
repo sync0efa9f02012-12-28 13:40:20 -0800409class NoopMessage : public Nl80211Message {
410 public:
411 static const uint8_t kCommand;
412 static const char kCommandString[];
413
414 NoopMessage() : Nl80211Message(kCommand, kCommandString) {}
415
416 virtual std::string ToString() const;
417
418 private:
419 DISALLOW_COPY_AND_ASSIGN(NoopMessage);
420};
421
422
repo syncdc085c82012-12-28 08:54:41 -0800423class NotifyCqmMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700424 public:
425 static const uint8_t kCommand;
426 static const char kCommandString[];
427
repo syncdc085c82012-12-28 08:54:41 -0800428 NotifyCqmMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700429
Wade Guthrie0d438532012-05-18 14:18:50 -0700430 virtual std::string ToString() const;
431
432 private:
433 DISALLOW_COPY_AND_ASSIGN(NotifyCqmMessage);
434};
435
436
repo syncdc085c82012-12-28 08:54:41 -0800437class PmksaCandidateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700438 public:
439 static const uint8_t kCommand;
440 static const char kCommandString[];
441
repo syncdc085c82012-12-28 08:54:41 -0800442 PmksaCandidateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700443
Wade Guthrie0d438532012-05-18 14:18:50 -0700444 virtual std::string ToString() const;
445
446 private:
447 DISALLOW_COPY_AND_ASSIGN(PmksaCandidateMessage);
448};
449
450
repo syncdc085c82012-12-28 08:54:41 -0800451class RegBeaconHintMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700452 public:
453 static const uint8_t kCommand;
454 static const char kCommandString[];
455
repo syncdc085c82012-12-28 08:54:41 -0800456 RegBeaconHintMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700457
Wade Guthrie0d438532012-05-18 14:18:50 -0700458 virtual std::string ToString() const;
459
460 private:
461 struct ieee80211_beacon_channel {
462 __u16 center_freq;
463 bool passive_scan;
464 bool no_ibss;
465 };
466
467 // Returns the channel ID calculated from the 802.11 frequency.
468 static int ChannelFromIeee80211Frequency(int freq);
469
470 // Sets values in |chan| based on attributes in |tb|, the array of pointers
471 // to netlink attributes, indexed by attribute type.
472 int ParseBeaconHintChan(const nlattr *tb,
473 ieee80211_beacon_channel *chan) const;
474
475 DISALLOW_COPY_AND_ASSIGN(RegBeaconHintMessage);
476};
477
478
repo syncdc085c82012-12-28 08:54:41 -0800479class RegChangeMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700480 public:
481 static const uint8_t kCommand;
482 static const char kCommandString[];
483
repo syncdc085c82012-12-28 08:54:41 -0800484 RegChangeMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700485
Wade Guthrie0d438532012-05-18 14:18:50 -0700486 virtual std::string ToString() const;
487
488 private:
489 DISALLOW_COPY_AND_ASSIGN(RegChangeMessage);
490};
491
492
repo syncdc085c82012-12-28 08:54:41 -0800493class RemainOnChannelMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700494 public:
495 static const uint8_t kCommand;
496 static const char kCommandString[];
497
repo syncdc085c82012-12-28 08:54:41 -0800498 RemainOnChannelMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700499
Wade Guthrie0d438532012-05-18 14:18:50 -0700500 virtual std::string ToString() const;
501
502 private:
503 DISALLOW_COPY_AND_ASSIGN(RemainOnChannelMessage);
504};
505
506
repo syncdc085c82012-12-28 08:54:41 -0800507class RoamMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700508 public:
509 static const uint8_t kCommand;
510 static const char kCommandString[];
511
repo syncdc085c82012-12-28 08:54:41 -0800512 RoamMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700513
Wade Guthrie0d438532012-05-18 14:18:50 -0700514 virtual std::string ToString() const;
515
516 private:
517 DISALLOW_COPY_AND_ASSIGN(RoamMessage);
518};
519
520
repo syncdc085c82012-12-28 08:54:41 -0800521class ScanAbortedMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700522 public:
523 static const uint8_t kCommand;
524 static const char kCommandString[];
525
repo syncdc085c82012-12-28 08:54:41 -0800526 ScanAbortedMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700527
Wade Guthrie0d438532012-05-18 14:18:50 -0700528 virtual std::string ToString() const;
529
530 private:
531 DISALLOW_COPY_AND_ASSIGN(ScanAbortedMessage);
532};
533
534
repo syncdc085c82012-12-28 08:54:41 -0800535class TriggerScanMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700536 public:
537 static const uint8_t kCommand;
538 static const char kCommandString[];
539
repo syncdc085c82012-12-28 08:54:41 -0800540 TriggerScanMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700541
Wade Guthrie0d438532012-05-18 14:18:50 -0700542 virtual std::string ToString() const;
543
544 private:
545 DISALLOW_COPY_AND_ASSIGN(TriggerScanMessage);
546};
547
548
repo syncdc085c82012-12-28 08:54:41 -0800549class UnknownMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700550 public:
Christopher Wiley764538d2012-11-09 10:58:23 -0800551 explicit UnknownMessage(uint8_t command)
repo syncdc085c82012-12-28 08:54:41 -0800552 : Nl80211Message(command, kCommandString),
Christopher Wiley764538d2012-11-09 10:58:23 -0800553 command_(command) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700554
555 static const uint8_t kCommand;
556 static const char kCommandString[];
557
Wade Guthrie0d438532012-05-18 14:18:50 -0700558 virtual std::string ToString() const;
559
560 private:
561 uint8_t command_;
562
563 DISALLOW_COPY_AND_ASSIGN(UnknownMessage);
564};
565
566
repo syncdc085c82012-12-28 08:54:41 -0800567class UnprotDeauthenticateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700568 public:
569 static const uint8_t kCommand;
570 static const char kCommandString[];
571
Christopher Wiley764538d2012-11-09 10:58:23 -0800572 UnprotDeauthenticateMessage()
repo syncdc085c82012-12-28 08:54:41 -0800573 : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700574
Wade Guthrie0d438532012-05-18 14:18:50 -0700575 virtual std::string ToString() const;
576
577 private:
578 DISALLOW_COPY_AND_ASSIGN(UnprotDeauthenticateMessage);
579};
580
581
repo syncdc085c82012-12-28 08:54:41 -0800582class UnprotDisassociateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700583 public:
584 static const uint8_t kCommand;
585 static const char kCommandString[];
586
repo syncdc085c82012-12-28 08:54:41 -0800587 UnprotDisassociateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700588
Wade Guthrie0d438532012-05-18 14:18:50 -0700589 virtual std::string ToString() const;
590
591 private:
592 DISALLOW_COPY_AND_ASSIGN(UnprotDisassociateMessage);
593};
594
595
596//
597// Factory class.
598//
599
repo syncdc085c82012-12-28 08:54:41 -0800600class Nl80211MessageFactory {
Wade Guthrie0d438532012-05-18 14:18:50 -0700601 public:
602 // Ownership of the message is passed to the caller and, as such, he should
603 // delete it.
repo syncdc085c82012-12-28 08:54:41 -0800604 static Nl80211Message *CreateMessage(nlmsghdr *msg);
Wade Guthrie0d438532012-05-18 14:18:50 -0700605
606 private:
repo syncdc085c82012-12-28 08:54:41 -0800607 DISALLOW_COPY_AND_ASSIGN(Nl80211MessageFactory);
Wade Guthrie0d438532012-05-18 14:18:50 -0700608};
609
610
repo syncdc085c82012-12-28 08:54:41 -0800611// Nl80211MessageDataCollector - this class is used to collect data to be
Wade Guthrie0d438532012-05-18 14:18:50 -0700612// used for unit tests. It is only invoked in this case.
613
repo syncdc085c82012-12-28 08:54:41 -0800614class Nl80211MessageDataCollector {
Wade Guthrie0d438532012-05-18 14:18:50 -0700615 public:
repo syncdc085c82012-12-28 08:54:41 -0800616 static Nl80211MessageDataCollector *GetInstance();
Wade Guthrie0d438532012-05-18 14:18:50 -0700617
repo syncdc085c82012-12-28 08:54:41 -0800618 void CollectDebugData(const Nl80211Message &message, nlmsghdr *msg);
Wade Guthrie0d438532012-05-18 14:18:50 -0700619
620 protected:
621 friend struct
repo syncdc085c82012-12-28 08:54:41 -0800622 base::DefaultLazyInstanceTraits<Nl80211MessageDataCollector>;
Wade Guthrie0d438532012-05-18 14:18:50 -0700623
repo syncdc085c82012-12-28 08:54:41 -0800624 explicit Nl80211MessageDataCollector();
Wade Guthrie0d438532012-05-18 14:18:50 -0700625
626 private:
627 // In order to limit the output from this class, I keep track of types I
628 // haven't yet printed.
629 std::map<uint8_t, bool> need_to_print;
repo syncdc085c82012-12-28 08:54:41 -0800630
631 DISALLOW_COPY_AND_ASSIGN(Nl80211MessageDataCollector);
Wade Guthrie0d438532012-05-18 14:18:50 -0700632};
633
634} // namespace shill
635
636#endif // SHILL_USER_BOUND_NLMESSAGE_H_