blob: dddc46d99a720ea09cf18f3050581562329cfd5a [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 Guthrieefe1f0c2013-02-26 17:42:01 -080022#include "shill/refptr_types.h"
Wade Guthrie16196242012-11-20 15:53:52 -080023
Wade Guthrie0d438532012-05-18 14:18:50 -070024struct nlattr;
25struct nlmsghdr;
26
27namespace shill {
28
29// Class for messages received from libnl.
repo syncdc085c82012-12-28 08:54:41 -080030class Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -070031 public:
Wade Guthrie8343f7f2012-12-04 13:52:32 -080032 static const unsigned int kEthernetAddressBytes;
Wade Guthrie0d438532012-05-18 14:18:50 -070033 static const char kBogusMacAddress[];
34
repo syncdc085c82012-12-28 08:54:41 -080035 Nl80211Message(uint8 message_type, const char *message_type_string)
repo sync0efa9f02012-12-28 13:40:20 -080036 : message_type_(message_type),
repo syncdc085c82012-12-28 08:54:41 -080037 message_type_string_(message_type_string),
Wade Guthrieefe1f0c2013-02-26 17:42:01 -080038 sequence_number_(kIllegalMessage),
39 attributes_(new AttributeList) {}
repo syncdc085c82012-12-28 08:54:41 -080040 virtual ~Nl80211Message() {}
Wade Guthrie0d438532012-05-18 14:18:50 -070041
repo syncdc085c82012-12-28 08:54:41 -080042 // Initializes the message with bytes from the kernel.
repo sync0efa9f02012-12-28 13:40:20 -080043 virtual bool InitFromNlmsg(const nlmsghdr *msg);
Wade Guthrie8e278612013-02-26 10:32:34 -080044 static void PrintBytes(int log_level, const unsigned char *buf,
45 size_t num_bytes);
repo syncdc085c82012-12-28 08:54:41 -080046 uint32_t sequence_number() const { return sequence_number_; }
Wade Guthrie8e278612013-02-26 10:32:34 -080047 virtual void Print(int log_level) const;
repo syncdc085c82012-12-28 08:54:41 -080048
49 void set_sequence_number(uint32_t seq) { sequence_number_ = seq; }
Wade Guthrie0d438532012-05-18 14:18:50 -070050
Wade Guthrieefe1f0c2013-02-26 17:42:01 -080051 AttributeListConstRefPtr const_attributes() const { return attributes_; }
52 AttributeListRefPtr attributes() { return attributes_; }
Wade Guthrie0d438532012-05-18 14:18:50 -070053
repo sync90ee0fa2012-12-18 10:08:08 -080054 // TODO(wdg): This needs to be moved to AttributeMac.
Wade Guthrie0d438532012-05-18 14:18:50 -070055 // Helper function to provide a string for a MAC address. If no attribute
56 // is found, this method returns 'false'. On any error with a non-NULL
57 // |value|, this method sets |value| to a bogus MAC address.
Wade Guthrie68da97c2013-02-26 13:09:35 -080058 bool GetMacAttributeString(int id, std::string *value) const;
Wade Guthrie0d438532012-05-18 14:18:50 -070059
repo sync90ee0fa2012-12-18 10:08:08 -080060 // TODO(wdg): This needs to be moved to AttributeScanFrequencies.
Wade Guthrie0d438532012-05-18 14:18:50 -070061 // Helper function to provide a vector of scan frequencies for attributes
62 // that contain them (such as NL80211_ATTR_SCAN_FREQUENCIES).
Wade Guthrie68da97c2013-02-26 13:09:35 -080063 bool GetScanFrequenciesAttribute(int id, std::vector<uint32_t> *value) const;
Wade Guthrie0d438532012-05-18 14:18:50 -070064
repo sync90ee0fa2012-12-18 10:08:08 -080065 // TODO(wdg): This needs to be moved to AttributeScanSSids.
Wade Guthrie0d438532012-05-18 14:18:50 -070066 // Helper function to provide a vector of SSIDs for attributes that contain
67 // them (such as NL80211_ATTR_SCAN_SSIDS).
Wade Guthrie68da97c2013-02-26 13:09:35 -080068 bool GetScanSsidsAttribute(int id, std::vector<std::string> *value) const;
Wade Guthrie0d438532012-05-18 14:18:50 -070069
repo sync90ee0fa2012-12-18 10:08:08 -080070 // TODO(wdg): This needs to be moved to AttributeMac.
Wade Guthrie0d438532012-05-18 14:18:50 -070071 // Stringizes the MAC address found in 'arg'. If there are problems (such
72 // as a NULL |arg|), |value| is set to a bogus MAC address.
73 static std::string StringFromMacAddress(const uint8_t *arg);
74
Wade Guthried4977f22012-08-22 12:37:54 -070075 // Returns a string representing the passed-in |status| or |reason|, the
76 // value of which has been acquired from libnl (for example, from the
Wade Guthrie0d438532012-05-18 14:18:50 -070077 // NL80211_ATTR_STATUS_CODE or NL80211_ATTR_REASON_CODE attribute).
Wade Guthried4977f22012-08-22 12:37:54 -070078 static std::string StringFromReason(uint16_t reason);
Wade Guthrie0d438532012-05-18 14:18:50 -070079 static std::string StringFromStatus(uint16_t status);
80
Christopher Wiley764538d2012-11-09 10:58:23 -080081 uint8 message_type() const { return message_type_; }
82 const char *message_type_string() const { return message_type_string_; }
83
repo syncdc085c82012-12-28 08:54:41 -080084 // Returns a netlink message suitable for Sockets::Send. Return value is
85 // empty on failure. |nlmsg_type| needs to be the family id returned by
86 // |genl_ctrl_resolve|.
87 ByteString Encode(uint16_t nlmsg_type) const;
88
Wade Guthrie0d438532012-05-18 14:18:50 -070089 protected:
Wade Guthrie0d438532012-05-18 14:18:50 -070090 // Returns a string that should precede all user-bound message strings.
91 virtual std::string GetHeaderString() const;
92
93 // Returns a string that describes the contents of the frame pointed to by
94 // 'attr'.
Wade Guthrie68da97c2013-02-26 13:09:35 -080095 std::string StringFromFrame(int attr_name) const;
Wade Guthrie0d438532012-05-18 14:18:50 -070096
97 // Converts key_type to a string.
98 static std::string StringFromKeyType(nl80211_key_type key_type);
99
100 // Returns a string representation of the REG initiator described by the
101 // method's parameter.
102 static std::string StringFromRegInitiator(__u8 initiator);
103
104 // Returns a string based on the SSID found in 'data'. Non-printable
105 // characters are string-ized.
106 static std::string StringFromSsid(const uint8_t len, const uint8_t *data);
107
108 private:
Wade Guthrie0d438532012-05-18 14:18:50 -0700109 friend class Config80211Test;
110 FRIEND_TEST(Config80211Test, NL80211_CMD_NOTIFY_CQM);
111
112 static const uint32_t kIllegalMessage;
Wade Guthrie0d438532012-05-18 14:18:50 -0700113
Christopher Wiley764538d2012-11-09 10:58:23 -0800114 const uint8 message_type_;
115 const char *message_type_string_;
Wade Guthried4977f22012-08-22 12:37:54 -0700116 static std::map<uint16_t, std::string> *reason_code_string_;
117 static std::map<uint16_t, std::string> *status_code_string_;
repo syncdc085c82012-12-28 08:54:41 -0800118 uint32_t sequence_number_;
repo sync90ee0fa2012-12-18 10:08:08 -0800119
Wade Guthrieefe1f0c2013-02-26 17:42:01 -0800120 AttributeListRefPtr attributes_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700121
repo syncdc085c82012-12-28 08:54:41 -0800122 DISALLOW_COPY_AND_ASSIGN(Nl80211Message);
Wade Guthrie0d438532012-05-18 14:18:50 -0700123};
124
125class Nl80211Frame {
126 public:
127 enum Type {
128 kAssocResponseFrameType = 0x10,
129 kReassocResponseFrameType = 0x30,
130 kAssocRequestFrameType = 0x00,
131 kReassocRequestFrameType = 0x20,
132 kAuthFrameType = 0xb0,
133 kDisassocFrameType = 0xa0,
134 kDeauthFrameType = 0xc0,
135 kIllegalFrameType = 0xff
136 };
137
repo syncd316eb72012-12-10 15:48:47 -0800138 explicit Nl80211Frame(const ByteString &init);
Wade Guthried4977f22012-08-22 12:37:54 -0700139 bool ToString(std::string *output) const;
140 bool IsEqual(const Nl80211Frame &other) const;
141 uint16_t reason() const { return reason_; }
142 uint16_t status() const { return status_; }
Wade Guthrie0d438532012-05-18 14:18:50 -0700143
144 private:
145 static const uint8_t kMinimumFrameByteCount;
146 static const uint8_t kFrameTypeMask;
147
148 std::string mac_from_;
149 std::string mac_to_;
150 uint8_t frame_type_;
Wade Guthried4977f22012-08-22 12:37:54 -0700151 uint16_t reason_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700152 uint16_t status_;
Wade Guthrie8343f7f2012-12-04 13:52:32 -0800153 ByteString frame_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700154
155 DISALLOW_COPY_AND_ASSIGN(Nl80211Frame);
156};
157
158//
repo syncdc085c82012-12-28 08:54:41 -0800159// Specific Nl80211Message types.
Wade Guthrie0d438532012-05-18 14:18:50 -0700160//
161
repo sync0efa9f02012-12-28 13:40:20 -0800162class AckMessage : public Nl80211Message {
163 public:
164 static const uint8_t kCommand;
165 static const char kCommandString[];
166
167 AckMessage() : Nl80211Message(kCommand, kCommandString) {}
168
repo sync0efa9f02012-12-28 13:40:20 -0800169 private:
170 DISALLOW_COPY_AND_ASSIGN(AckMessage);
171};
172
repo syncdc085c82012-12-28 08:54:41 -0800173class AssociateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700174 public:
175 static const uint8_t kCommand;
176 static const char kCommandString[];
177
repo syncdc085c82012-12-28 08:54:41 -0800178 AssociateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700179
Wade Guthrie0d438532012-05-18 14:18:50 -0700180 private:
181 DISALLOW_COPY_AND_ASSIGN(AssociateMessage);
182};
183
184
repo syncdc085c82012-12-28 08:54:41 -0800185class AuthenticateMessage : 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 AuthenticateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700191
Wade Guthrie0d438532012-05-18 14:18:50 -0700192 private:
193 DISALLOW_COPY_AND_ASSIGN(AuthenticateMessage);
194};
195
196
repo syncdc085c82012-12-28 08:54:41 -0800197class CancelRemainOnChannelMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700198 public:
199 static const uint8_t kCommand;
200 static const char kCommandString[];
201
Christopher Wiley764538d2012-11-09 10:58:23 -0800202 CancelRemainOnChannelMessage()
repo syncdc085c82012-12-28 08:54:41 -0800203 : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700204
Wade Guthrie0d438532012-05-18 14:18:50 -0700205 private:
206 DISALLOW_COPY_AND_ASSIGN(CancelRemainOnChannelMessage);
207};
208
209
repo syncdc085c82012-12-28 08:54:41 -0800210class ConnectMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700211 public:
212 static const uint8_t kCommand;
213 static const char kCommandString[];
214
repo syncdc085c82012-12-28 08:54:41 -0800215 ConnectMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700216
Wade Guthrie0d438532012-05-18 14:18:50 -0700217 private:
218 DISALLOW_COPY_AND_ASSIGN(ConnectMessage);
219};
220
221
repo syncdc085c82012-12-28 08:54:41 -0800222class DeauthenticateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700223 public:
224 static const uint8_t kCommand;
225 static const char kCommandString[];
226
repo syncdc085c82012-12-28 08:54:41 -0800227 DeauthenticateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700228
Wade Guthrie0d438532012-05-18 14:18:50 -0700229 private:
230 DISALLOW_COPY_AND_ASSIGN(DeauthenticateMessage);
231};
232
233
repo syncdc085c82012-12-28 08:54:41 -0800234class DeleteStationMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700235 public:
236 static const uint8_t kCommand;
237 static const char kCommandString[];
238
repo syncdc085c82012-12-28 08:54:41 -0800239 DeleteStationMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700240
Wade Guthrie0d438532012-05-18 14:18:50 -0700241 private:
242 DISALLOW_COPY_AND_ASSIGN(DeleteStationMessage);
243};
244
245
repo syncdc085c82012-12-28 08:54:41 -0800246class DisassociateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700247 public:
248 static const uint8_t kCommand;
249 static const char kCommandString[];
250
repo syncdc085c82012-12-28 08:54:41 -0800251 DisassociateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700252
Wade Guthrie0d438532012-05-18 14:18:50 -0700253 private:
254 DISALLOW_COPY_AND_ASSIGN(DisassociateMessage);
255};
256
257
repo syncdc085c82012-12-28 08:54:41 -0800258class DisconnectMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700259 public:
260 static const uint8_t kCommand;
261 static const char kCommandString[];
262
repo syncdc085c82012-12-28 08:54:41 -0800263 DisconnectMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700264
Wade Guthrie0d438532012-05-18 14:18:50 -0700265 private:
266 DISALLOW_COPY_AND_ASSIGN(DisconnectMessage);
267};
268
269
repo sync0efa9f02012-12-28 13:40:20 -0800270class ErrorMessage : public Nl80211Message {
271 public:
272 static const uint8_t kCommand;
273 static const char kCommandString[];
274
Wade Guthrie3af8b4d2013-01-10 08:39:30 -0800275 explicit ErrorMessage(uint32_t error);
repo sync0efa9f02012-12-28 13:40:20 -0800276 virtual std::string ToString() const;
277
278 private:
279 uint32_t error_;
280
281 DISALLOW_COPY_AND_ASSIGN(ErrorMessage);
282};
283
284
repo syncdc085c82012-12-28 08:54:41 -0800285class FrameTxStatusMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700286 public:
287 static const uint8_t kCommand;
288 static const char kCommandString[];
289
repo syncdc085c82012-12-28 08:54:41 -0800290 FrameTxStatusMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700291
Wade Guthrie0d438532012-05-18 14:18:50 -0700292 private:
293 DISALLOW_COPY_AND_ASSIGN(FrameTxStatusMessage);
294};
295
repo sync0efa9f02012-12-28 13:40:20 -0800296class GetRegMessage : public Nl80211Message {
297 public:
298 static const uint8_t kCommand;
299 static const char kCommandString[];
300
301 GetRegMessage() : Nl80211Message(kCommand, kCommandString) {}
302
303 private:
304 DISALLOW_COPY_AND_ASSIGN(GetRegMessage);
305};
306
Wade Guthrie0d438532012-05-18 14:18:50 -0700307
repo syncdc085c82012-12-28 08:54:41 -0800308class JoinIbssMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700309 public:
310 static const uint8_t kCommand;
311 static const char kCommandString[];
312
repo syncdc085c82012-12-28 08:54:41 -0800313 JoinIbssMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700314
Wade Guthrie0d438532012-05-18 14:18:50 -0700315 private:
316 DISALLOW_COPY_AND_ASSIGN(JoinIbssMessage);
317};
318
319
repo syncdc085c82012-12-28 08:54:41 -0800320class MichaelMicFailureMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700321 public:
322 static const uint8_t kCommand;
323 static const char kCommandString[];
324
repo syncdc085c82012-12-28 08:54:41 -0800325 MichaelMicFailureMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700326
Wade Guthrie0d438532012-05-18 14:18:50 -0700327 private:
328 DISALLOW_COPY_AND_ASSIGN(MichaelMicFailureMessage);
329};
330
331
repo syncdc085c82012-12-28 08:54:41 -0800332class NewScanResultsMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700333 public:
334 static const uint8_t kCommand;
335 static const char kCommandString[];
336
repo syncdc085c82012-12-28 08:54:41 -0800337 NewScanResultsMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700338
Wade Guthrie0d438532012-05-18 14:18:50 -0700339 private:
340 DISALLOW_COPY_AND_ASSIGN(NewScanResultsMessage);
341};
342
343
repo syncdc085c82012-12-28 08:54:41 -0800344class NewStationMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700345 public:
346 static const uint8_t kCommand;
347 static const char kCommandString[];
348
repo syncdc085c82012-12-28 08:54:41 -0800349 NewStationMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700350
Wade Guthrie0d438532012-05-18 14:18:50 -0700351 private:
352 DISALLOW_COPY_AND_ASSIGN(NewStationMessage);
353};
354
355
repo syncdc085c82012-12-28 08:54:41 -0800356class NewWifiMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700357 public:
358 static const uint8_t kCommand;
359 static const char kCommandString[];
360
repo syncdc085c82012-12-28 08:54:41 -0800361 NewWifiMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700362
Wade Guthrie0d438532012-05-18 14:18:50 -0700363 private:
364 DISALLOW_COPY_AND_ASSIGN(NewWifiMessage);
365};
366
367
repo sync0efa9f02012-12-28 13:40:20 -0800368class NoopMessage : public Nl80211Message {
369 public:
370 static const uint8_t kCommand;
371 static const char kCommandString[];
372
373 NoopMessage() : Nl80211Message(kCommand, kCommandString) {}
374
repo sync0efa9f02012-12-28 13:40:20 -0800375 private:
376 DISALLOW_COPY_AND_ASSIGN(NoopMessage);
377};
378
379
repo syncdc085c82012-12-28 08:54:41 -0800380class NotifyCqmMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700381 public:
382 static const uint8_t kCommand;
383 static const char kCommandString[];
384
repo syncdc085c82012-12-28 08:54:41 -0800385 NotifyCqmMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700386
Wade Guthrie0d438532012-05-18 14:18:50 -0700387 private:
388 DISALLOW_COPY_AND_ASSIGN(NotifyCqmMessage);
389};
390
391
repo syncdc085c82012-12-28 08:54:41 -0800392class PmksaCandidateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700393 public:
394 static const uint8_t kCommand;
395 static const char kCommandString[];
396
repo syncdc085c82012-12-28 08:54:41 -0800397 PmksaCandidateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700398
Wade Guthrie0d438532012-05-18 14:18:50 -0700399 private:
400 DISALLOW_COPY_AND_ASSIGN(PmksaCandidateMessage);
401};
402
403
repo syncdc085c82012-12-28 08:54:41 -0800404class RegBeaconHintMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700405 public:
406 static const uint8_t kCommand;
407 static const char kCommandString[];
408
repo syncdc085c82012-12-28 08:54:41 -0800409 RegBeaconHintMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700410
Wade Guthrie0d438532012-05-18 14:18:50 -0700411 private:
Wade Guthrie0d438532012-05-18 14:18:50 -0700412 DISALLOW_COPY_AND_ASSIGN(RegBeaconHintMessage);
413};
414
415
repo syncdc085c82012-12-28 08:54:41 -0800416class RegChangeMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700417 public:
418 static const uint8_t kCommand;
419 static const char kCommandString[];
420
repo syncdc085c82012-12-28 08:54:41 -0800421 RegChangeMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700422
Wade Guthrie0d438532012-05-18 14:18:50 -0700423 private:
424 DISALLOW_COPY_AND_ASSIGN(RegChangeMessage);
425};
426
427
repo syncdc085c82012-12-28 08:54:41 -0800428class RemainOnChannelMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700429 public:
430 static const uint8_t kCommand;
431 static const char kCommandString[];
432
repo syncdc085c82012-12-28 08:54:41 -0800433 RemainOnChannelMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700434
Wade Guthrie0d438532012-05-18 14:18:50 -0700435 private:
436 DISALLOW_COPY_AND_ASSIGN(RemainOnChannelMessage);
437};
438
439
repo syncdc085c82012-12-28 08:54:41 -0800440class RoamMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700441 public:
442 static const uint8_t kCommand;
443 static const char kCommandString[];
444
repo syncdc085c82012-12-28 08:54:41 -0800445 RoamMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700446
Wade Guthrie0d438532012-05-18 14:18:50 -0700447 private:
448 DISALLOW_COPY_AND_ASSIGN(RoamMessage);
449};
450
451
repo syncdc085c82012-12-28 08:54:41 -0800452class ScanAbortedMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700453 public:
454 static const uint8_t kCommand;
455 static const char kCommandString[];
456
repo syncdc085c82012-12-28 08:54:41 -0800457 ScanAbortedMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700458
Wade Guthrie0d438532012-05-18 14:18:50 -0700459 private:
460 DISALLOW_COPY_AND_ASSIGN(ScanAbortedMessage);
461};
462
463
repo syncdc085c82012-12-28 08:54:41 -0800464class TriggerScanMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700465 public:
466 static const uint8_t kCommand;
467 static const char kCommandString[];
468
repo syncdc085c82012-12-28 08:54:41 -0800469 TriggerScanMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700470
Wade Guthrie0d438532012-05-18 14:18:50 -0700471 private:
472 DISALLOW_COPY_AND_ASSIGN(TriggerScanMessage);
473};
474
475
repo syncdc085c82012-12-28 08:54:41 -0800476class UnknownMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700477 public:
Christopher Wiley764538d2012-11-09 10:58:23 -0800478 explicit UnknownMessage(uint8_t command)
repo syncdc085c82012-12-28 08:54:41 -0800479 : Nl80211Message(command, kCommandString),
Christopher Wiley764538d2012-11-09 10:58:23 -0800480 command_(command) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700481
482 static const uint8_t kCommand;
483 static const char kCommandString[];
484
Wade Guthrie0d438532012-05-18 14:18:50 -0700485 private:
486 uint8_t command_;
487
488 DISALLOW_COPY_AND_ASSIGN(UnknownMessage);
489};
490
491
repo syncdc085c82012-12-28 08:54:41 -0800492class UnprotDeauthenticateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700493 public:
494 static const uint8_t kCommand;
495 static const char kCommandString[];
496
Christopher Wiley764538d2012-11-09 10:58:23 -0800497 UnprotDeauthenticateMessage()
repo syncdc085c82012-12-28 08:54:41 -0800498 : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700499
Wade Guthrie0d438532012-05-18 14:18:50 -0700500 private:
501 DISALLOW_COPY_AND_ASSIGN(UnprotDeauthenticateMessage);
502};
503
504
repo syncdc085c82012-12-28 08:54:41 -0800505class UnprotDisassociateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700506 public:
507 static const uint8_t kCommand;
508 static const char kCommandString[];
509
repo syncdc085c82012-12-28 08:54:41 -0800510 UnprotDisassociateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700511
Wade Guthrie0d438532012-05-18 14:18:50 -0700512 private:
513 DISALLOW_COPY_AND_ASSIGN(UnprotDisassociateMessage);
514};
515
516
517//
518// Factory class.
519//
520
repo syncdc085c82012-12-28 08:54:41 -0800521class Nl80211MessageFactory {
Wade Guthrie0d438532012-05-18 14:18:50 -0700522 public:
523 // Ownership of the message is passed to the caller and, as such, he should
524 // delete it.
repo syncdc085c82012-12-28 08:54:41 -0800525 static Nl80211Message *CreateMessage(nlmsghdr *msg);
Wade Guthrie0d438532012-05-18 14:18:50 -0700526
527 private:
repo syncdc085c82012-12-28 08:54:41 -0800528 DISALLOW_COPY_AND_ASSIGN(Nl80211MessageFactory);
Wade Guthrie0d438532012-05-18 14:18:50 -0700529};
530
531
repo syncdc085c82012-12-28 08:54:41 -0800532// Nl80211MessageDataCollector - this class is used to collect data to be
Wade Guthrie0d438532012-05-18 14:18:50 -0700533// used for unit tests. It is only invoked in this case.
534
repo syncdc085c82012-12-28 08:54:41 -0800535class Nl80211MessageDataCollector {
Wade Guthrie0d438532012-05-18 14:18:50 -0700536 public:
repo syncdc085c82012-12-28 08:54:41 -0800537 static Nl80211MessageDataCollector *GetInstance();
Wade Guthrie0d438532012-05-18 14:18:50 -0700538
repo syncdc085c82012-12-28 08:54:41 -0800539 void CollectDebugData(const Nl80211Message &message, nlmsghdr *msg);
Wade Guthrie0d438532012-05-18 14:18:50 -0700540
541 protected:
542 friend struct
repo syncdc085c82012-12-28 08:54:41 -0800543 base::DefaultLazyInstanceTraits<Nl80211MessageDataCollector>;
Wade Guthrie0d438532012-05-18 14:18:50 -0700544
repo syncdc085c82012-12-28 08:54:41 -0800545 explicit Nl80211MessageDataCollector();
Wade Guthrie0d438532012-05-18 14:18:50 -0700546
547 private:
548 // In order to limit the output from this class, I keep track of types I
549 // haven't yet printed.
550 std::map<uint8_t, bool> need_to_print;
repo syncdc085c82012-12-28 08:54:41 -0800551
552 DISALLOW_COPY_AND_ASSIGN(Nl80211MessageDataCollector);
Wade Guthrie0d438532012-05-18 14:18:50 -0700553};
554
555} // namespace shill
556
557#endif // SHILL_USER_BOUND_NLMESSAGE_H_