blob: 43d608923bd5ecc7180ab181b7d98df02fb6294e [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
Wade Guthrie16196242012-11-20 15:53:52 -080020#include "shill/nl80211_attribute.h"
21
Wade Guthrie0d438532012-05-18 14:18:50 -070022struct nlattr;
23struct nlmsghdr;
24
25namespace shill {
26
27// Class for messages received from libnl.
28class UserBoundNlMessage {
29 public:
Wade Guthrie8343f7f2012-12-04 13:52:32 -080030 static const unsigned int kEthernetAddressBytes;
Wade Guthrie0d438532012-05-18 14:18:50 -070031
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 Guthrie0d438532012-05-18 14:18:50 -070060 static const char kBogusMacAddress[];
61
Christopher Wiley764538d2012-11-09 10:58:23 -080062 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 Guthrie0d438532012-05-18 14:18:50 -070066 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 Guthrie0d438532012-05-18 14:18:50 -070075
Wade Guthrie0d438532012-05-18 14:18:50 -070076 // 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 Guthrie16196242012-11-20 15:53:52 -080086 Nl80211Attribute::Type GetAttributeType(nl80211_attrs name) const;
Wade Guthrie0d438532012-05-18 14:18:50 -070087
88 // Returns a string describing the data type of a given attribute.
89 std::string GetAttributeTypeString(nl80211_attrs name) const;
90
Wade Guthrie8343f7f2012-12-04 13:52:32 -080091 // 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 Guthrie0d438532012-05-18 14:18:50 -070096
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 Guthried4977f22012-08-22 12:37:54 -0700136 // 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 Guthrie0d438532012-05-18 14:18:50 -0700138 // NL80211_ATTR_STATUS_CODE or NL80211_ATTR_REASON_CODE attribute).
Wade Guthried4977f22012-08-22 12:37:54 -0700139 static std::string StringFromReason(uint16_t reason);
Wade Guthrie0d438532012-05-18 14:18:50 -0700140 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 Wiley764538d2012-11-09 10:58:23 -0800145 uint8 message_type() const { return message_type_; }
146 const char *message_type_string() const { return message_type_string_; }
147
Wade Guthrie0d438532012-05-18 14:18:50 -0700148 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 Guthrie0d438532012-05-18 14:18:50 -0700180
181 nlmsghdr *message_;
Christopher Wiley764538d2012-11-09 10:58:23 -0800182 const uint8 message_type_;
183 const char *message_type_string_;
Wade Guthried4977f22012-08-22 12:37:54 -0700184 static std::map<uint16_t, std::string> *reason_code_string_;
185 static std::map<uint16_t, std::string> *status_code_string_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700186 std::map<nl80211_attrs, nlattr *> attributes_;
187
188 DISALLOW_COPY_AND_ASSIGN(UserBoundNlMessage);
189};
190
191class 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 Guthrie8343f7f2012-12-04 13:52:32 -0800204 Nl80211Frame(const ByteString &init);
Wade Guthried4977f22012-08-22 12:37:54 -0700205 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 Guthrie0d438532012-05-18 14:18:50 -0700209
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 Guthried4977f22012-08-22 12:37:54 -0700217 uint16_t reason_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700218 uint16_t status_;
Wade Guthrie8343f7f2012-12-04 13:52:32 -0800219 ByteString frame_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700220
221 DISALLOW_COPY_AND_ASSIGN(Nl80211Frame);
222};
223
224//
225// Specific UserBoundNlMessage types.
226//
227
228class AssociateMessage : public UserBoundNlMessage {
229 public:
230 static const uint8_t kCommand;
231 static const char kCommandString[];
232
Christopher Wiley764538d2012-11-09 10:58:23 -0800233 AssociateMessage() : UserBoundNlMessage(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(AssociateMessage);
239};
240
241
242class AuthenticateMessage : public UserBoundNlMessage {
243 public:
244 static const uint8_t kCommand;
245 static const char kCommandString[];
246
Christopher Wiley764538d2012-11-09 10:58:23 -0800247 AuthenticateMessage() : UserBoundNlMessage(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(AuthenticateMessage);
253};
254
255
256class CancelRemainOnChannelMessage : public UserBoundNlMessage {
257 public:
258 static const uint8_t kCommand;
259 static const char kCommandString[];
260
Christopher Wiley764538d2012-11-09 10:58:23 -0800261 CancelRemainOnChannelMessage()
262 : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700263
Wade Guthrie0d438532012-05-18 14:18:50 -0700264 virtual std::string ToString() const;
265
266 private:
267 DISALLOW_COPY_AND_ASSIGN(CancelRemainOnChannelMessage);
268};
269
270
271class ConnectMessage : public UserBoundNlMessage {
272 public:
273 static const uint8_t kCommand;
274 static const char kCommandString[];
275
Christopher Wiley764538d2012-11-09 10:58:23 -0800276 ConnectMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700277
Wade Guthrie0d438532012-05-18 14:18:50 -0700278 virtual std::string ToString() const;
279
280 private:
281 DISALLOW_COPY_AND_ASSIGN(ConnectMessage);
282};
283
284
285class DeauthenticateMessage : public UserBoundNlMessage {
286 public:
287 static const uint8_t kCommand;
288 static const char kCommandString[];
289
Christopher Wiley764538d2012-11-09 10:58:23 -0800290 DeauthenticateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700291
Wade Guthrie0d438532012-05-18 14:18:50 -0700292 virtual std::string ToString() const;
293
294 private:
295 DISALLOW_COPY_AND_ASSIGN(DeauthenticateMessage);
296};
297
298
299class DeleteStationMessage : public UserBoundNlMessage {
300 public:
301 static const uint8_t kCommand;
302 static const char kCommandString[];
303
Christopher Wiley764538d2012-11-09 10:58:23 -0800304 DeleteStationMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700305
Wade Guthrie0d438532012-05-18 14:18:50 -0700306 virtual std::string ToString() const;
307
308 private:
309 DISALLOW_COPY_AND_ASSIGN(DeleteStationMessage);
310};
311
312
313class DisassociateMessage : public UserBoundNlMessage {
314 public:
315 static const uint8_t kCommand;
316 static const char kCommandString[];
317
Christopher Wiley764538d2012-11-09 10:58:23 -0800318 DisassociateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700319
Wade Guthrie0d438532012-05-18 14:18:50 -0700320 virtual std::string ToString() const;
321
322 private:
323 DISALLOW_COPY_AND_ASSIGN(DisassociateMessage);
324};
325
326
327class DisconnectMessage : public UserBoundNlMessage {
328 public:
329 static const uint8_t kCommand;
330 static const char kCommandString[];
331
Christopher Wiley764538d2012-11-09 10:58:23 -0800332 DisconnectMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700333
Wade Guthrie0d438532012-05-18 14:18:50 -0700334 virtual std::string ToString() const;
335
336 private:
337 DISALLOW_COPY_AND_ASSIGN(DisconnectMessage);
338};
339
340
341class FrameTxStatusMessage : public UserBoundNlMessage {
342 public:
343 static const uint8_t kCommand;
344 static const char kCommandString[];
345
Christopher Wiley764538d2012-11-09 10:58:23 -0800346 FrameTxStatusMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700347
Wade Guthrie0d438532012-05-18 14:18:50 -0700348 virtual std::string ToString() const;
349
350 private:
351 DISALLOW_COPY_AND_ASSIGN(FrameTxStatusMessage);
352};
353
354
355class JoinIbssMessage : public UserBoundNlMessage {
356 public:
357 static const uint8_t kCommand;
358 static const char kCommandString[];
359
Christopher Wiley764538d2012-11-09 10:58:23 -0800360 JoinIbssMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700361
Wade Guthrie0d438532012-05-18 14:18:50 -0700362 virtual std::string ToString() const;
363
364 private:
365 DISALLOW_COPY_AND_ASSIGN(JoinIbssMessage);
366};
367
368
369class MichaelMicFailureMessage : public UserBoundNlMessage {
370 public:
371 static const uint8_t kCommand;
372 static const char kCommandString[];
373
Christopher Wiley764538d2012-11-09 10:58:23 -0800374 MichaelMicFailureMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700375
Wade Guthrie0d438532012-05-18 14:18:50 -0700376 virtual std::string ToString() const;
377
378 private:
379 DISALLOW_COPY_AND_ASSIGN(MichaelMicFailureMessage);
380};
381
382
383class NewScanResultsMessage : public UserBoundNlMessage {
384 public:
385 static const uint8_t kCommand;
386 static const char kCommandString[];
387
Christopher Wiley764538d2012-11-09 10:58:23 -0800388 NewScanResultsMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700389
Wade Guthrie0d438532012-05-18 14:18:50 -0700390 virtual std::string ToString() const;
391
392 private:
393 DISALLOW_COPY_AND_ASSIGN(NewScanResultsMessage);
394};
395
396
397class NewStationMessage : public UserBoundNlMessage {
398 public:
399 static const uint8_t kCommand;
400 static const char kCommandString[];
401
Christopher Wiley764538d2012-11-09 10:58:23 -0800402 NewStationMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700403
Wade Guthrie0d438532012-05-18 14:18:50 -0700404 virtual std::string ToString() const;
405
406 private:
407 DISALLOW_COPY_AND_ASSIGN(NewStationMessage);
408};
409
410
411class NewWifiMessage : public UserBoundNlMessage {
412 public:
413 static const uint8_t kCommand;
414 static const char kCommandString[];
415
Christopher Wiley764538d2012-11-09 10:58:23 -0800416 NewWifiMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700417
Wade Guthrie0d438532012-05-18 14:18:50 -0700418 virtual std::string ToString() const;
419
420 private:
421 DISALLOW_COPY_AND_ASSIGN(NewWifiMessage);
422};
423
424
425class NotifyCqmMessage : public UserBoundNlMessage {
426 public:
427 static const uint8_t kCommand;
428 static const char kCommandString[];
429
Christopher Wiley764538d2012-11-09 10:58:23 -0800430 NotifyCqmMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700431
Wade Guthrie0d438532012-05-18 14:18:50 -0700432 virtual std::string ToString() const;
433
434 private:
435 DISALLOW_COPY_AND_ASSIGN(NotifyCqmMessage);
436};
437
438
439class PmksaCandidateMessage : public UserBoundNlMessage {
440 public:
441 static const uint8_t kCommand;
442 static const char kCommandString[];
443
Christopher Wiley764538d2012-11-09 10:58:23 -0800444 PmksaCandidateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700445
Wade Guthrie0d438532012-05-18 14:18:50 -0700446 virtual std::string ToString() const;
447
448 private:
449 DISALLOW_COPY_AND_ASSIGN(PmksaCandidateMessage);
450};
451
452
453class RegBeaconHintMessage : public UserBoundNlMessage {
454 public:
455 static const uint8_t kCommand;
456 static const char kCommandString[];
457
Christopher Wiley764538d2012-11-09 10:58:23 -0800458 RegBeaconHintMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700459
Wade Guthrie0d438532012-05-18 14:18:50 -0700460 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
481class RegChangeMessage : public UserBoundNlMessage {
482 public:
483 static const uint8_t kCommand;
484 static const char kCommandString[];
485
Christopher Wiley764538d2012-11-09 10:58:23 -0800486 RegChangeMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700487
Wade Guthrie0d438532012-05-18 14:18:50 -0700488 virtual std::string ToString() const;
489
490 private:
491 DISALLOW_COPY_AND_ASSIGN(RegChangeMessage);
492};
493
494
495class RemainOnChannelMessage : public UserBoundNlMessage {
496 public:
497 static const uint8_t kCommand;
498 static const char kCommandString[];
499
Christopher Wiley764538d2012-11-09 10:58:23 -0800500 RemainOnChannelMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700501
Wade Guthrie0d438532012-05-18 14:18:50 -0700502 virtual std::string ToString() const;
503
504 private:
505 DISALLOW_COPY_AND_ASSIGN(RemainOnChannelMessage);
506};
507
508
509class RoamMessage : public UserBoundNlMessage {
510 public:
511 static const uint8_t kCommand;
512 static const char kCommandString[];
513
Christopher Wiley764538d2012-11-09 10:58:23 -0800514 RoamMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700515
Wade Guthrie0d438532012-05-18 14:18:50 -0700516 virtual std::string ToString() const;
517
518 private:
519 DISALLOW_COPY_AND_ASSIGN(RoamMessage);
520};
521
522
523class ScanAbortedMessage : public UserBoundNlMessage {
524 public:
525 static const uint8_t kCommand;
526 static const char kCommandString[];
527
Christopher Wiley764538d2012-11-09 10:58:23 -0800528 ScanAbortedMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700529
Wade Guthrie0d438532012-05-18 14:18:50 -0700530 virtual std::string ToString() const;
531
532 private:
533 DISALLOW_COPY_AND_ASSIGN(ScanAbortedMessage);
534};
535
536
537class TriggerScanMessage : public UserBoundNlMessage {
538 public:
539 static const uint8_t kCommand;
540 static const char kCommandString[];
541
Christopher Wiley764538d2012-11-09 10:58:23 -0800542 TriggerScanMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700543
Wade Guthrie0d438532012-05-18 14:18:50 -0700544 virtual std::string ToString() const;
545
546 private:
547 DISALLOW_COPY_AND_ASSIGN(TriggerScanMessage);
548};
549
550
551class UnknownMessage : public UserBoundNlMessage {
552 public:
Christopher Wiley764538d2012-11-09 10:58:23 -0800553 explicit UnknownMessage(uint8_t command)
554 : UserBoundNlMessage(command, kCommandString),
555 command_(command) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700556
557 static const uint8_t kCommand;
558 static const char kCommandString[];
559
Wade Guthrie0d438532012-05-18 14:18:50 -0700560 virtual std::string ToString() const;
561
562 private:
563 uint8_t command_;
564
565 DISALLOW_COPY_AND_ASSIGN(UnknownMessage);
566};
567
568
569class UnprotDeauthenticateMessage : public UserBoundNlMessage {
570 public:
571 static const uint8_t kCommand;
572 static const char kCommandString[];
573
Christopher Wiley764538d2012-11-09 10:58:23 -0800574 UnprotDeauthenticateMessage()
575 : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700576
Wade Guthrie0d438532012-05-18 14:18:50 -0700577 virtual std::string ToString() const;
578
579 private:
580 DISALLOW_COPY_AND_ASSIGN(UnprotDeauthenticateMessage);
581};
582
583
584class UnprotDisassociateMessage : public UserBoundNlMessage {
585 public:
586 static const uint8_t kCommand;
587 static const char kCommandString[];
588
Christopher Wiley764538d2012-11-09 10:58:23 -0800589 UnprotDisassociateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700590
Wade Guthrie0d438532012-05-18 14:18:50 -0700591 virtual std::string ToString() const;
592
593 private:
594 DISALLOW_COPY_AND_ASSIGN(UnprotDisassociateMessage);
595};
596
597
598//
599// Factory class.
600//
601
602class 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
616class 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_