blob: a15e61a660e7dd0e171a64c17bac5d001a5e2ecb [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
8#include <iomanip>
9#include <map>
10#include <vector>
11#include <string>
12
13#include <base/basictypes.h>
14#include <base/bind.h>
15#include <base/lazy_instance.h>
16#include <gtest/gtest.h>
17
18#include <linux/nl80211.h>
19
20struct nlattr;
21struct nlmsghdr;
22
23namespace shill {
24
25// Class for messages received from libnl.
26class UserBoundNlMessage {
27 public:
28 enum Type {
29 kTypeUnspecified,
30 kTypeU8,
31 kTypeU16,
32 kTypeU32,
33 kTypeU64,
34 kTypeString,
35 kTypeFlag,
36 kTypeMsecs,
37 kTypeNested,
38 kTypeOther, // Specified in the message but not listed, here.
39 kTypeError
40 };
Wade Guthrie64b4c142012-08-20 15:21:01 -070041
Wade Guthrie0d438532012-05-18 14:18:50 -070042 // TODO(wdg): break 'Attribute' into its own class to handle
43 // nested attributes better.
44
45 // A const iterator to the attribute names in the attributes_ map of a
46 // UserBoundNlMessage. The purpose, here, is to hide the way that the
47 // attribute is stored.
48 class AttributeNameIterator {
49 public:
50 explicit AttributeNameIterator(const std::map<nl80211_attrs,
51 nlattr *> &map_param)
52 : map_(map_param) {
53 iter_ = map_.begin();
54 }
55
56 // Causes the iterator to point to the next attribute in the list.
57 void Advance() { ++iter_; }
58
59 // Returns 'true' if the iterator points beyond the last attribute in the
60 // list; returns 'false' otherwise.
61 bool AtEnd() const { return iter_ == map_.end(); }
62
63 // Returns the attribute name (which is actually an 'enum' value).
64 nl80211_attrs GetName() const { return iter_->first; }
65
66 private:
67 const std::map<nl80211_attrs, nlattr *> &map_;
68 std::map<nl80211_attrs, nlattr *>::const_iterator iter_;
69
70 DISALLOW_COPY_AND_ASSIGN(AttributeNameIterator);
71 };
72
Wade Guthrie0d438532012-05-18 14:18:50 -070073 static const char kBogusMacAddress[];
74
Christopher Wiley764538d2012-11-09 10:58:23 -080075 UserBoundNlMessage(uint8 message_type, const char *message_type_string)
76 : message_(NULL),
77 message_type_(message_type),
78 message_type_string_(message_type_string) { }
Wade Guthrie0d438532012-05-18 14:18:50 -070079 virtual ~UserBoundNlMessage();
80
81 // Non-trivial initialization.
82 virtual bool Init(nlattr *tb[NL80211_ATTR_MAX + 1], nlmsghdr *msg);
83
84 // Provide a suite of methods to allow (const) iteration over the names of the
85 // attributes inside a message object.
86
87 AttributeNameIterator *GetAttributeNameIterator() const;
88 bool HasAttributes() const { return !attributes_.empty(); }
89 uint32_t GetAttributeCount() const { return attributes_.size(); }
90
Wade Guthrie0d438532012-05-18 14:18:50 -070091 // Other ways to see the internals of the object.
92
93 // Return true if the attribute is in our map, regardless of the value of
94 // the attribute, itself.
95 bool AttributeExists(nl80211_attrs name) const;
96
97 // Message ID is equivalent to the message's sequence number.
98 uint32_t GetId() const;
99
100 // Returns the data type of a given attribute.
101 Type GetAttributeType(nl80211_attrs name) const;
102
103 // Returns a string describing the data type of a given attribute.
104 std::string GetAttributeTypeString(nl80211_attrs name) const;
105
106 // If successful, returns 'true' and sets *|value| to the raw attribute data
107 // (after the header) for this attribute and, if |length| is not
108 // null, *|length| to the number of bytes of data available. If no
109 // attribute by this name exists in this message, sets *|value| to NULL and
110 // returns 'false'. If otherwise unsuccessful, returns 'false' and leaves
111 // |value| and |length| unchanged.
112 bool GetRawAttributeData(nl80211_attrs name, void **value, int *length) const;
113
114 // Each of these methods set |value| with the value of the specified
115 // attribute (if the attribute is not found, |value| remains unchanged).
116
117 bool GetStringAttribute(nl80211_attrs name, std::string *value) const;
118 bool GetU8Attribute(nl80211_attrs name, uint8_t *value) const;
119 bool GetU16Attribute(nl80211_attrs name, uint16_t *value) const;
120 bool GetU32Attribute(nl80211_attrs name, uint32_t *value) const;
121 bool GetU64Attribute(nl80211_attrs name, uint64_t *value) const;
122
123 // Fill a string with characters that represents the value of the attribute.
124 // If no attribute is found or if the type isn't trivially stringizable,
125 // this method returns 'false' and |value| remains unchanged.
126 bool GetAttributeString(nl80211_attrs name, std::string *value) const;
127
128 // Helper function to provide a string for a MAC address. If no attribute
129 // is found, this method returns 'false'. On any error with a non-NULL
130 // |value|, this method sets |value| to a bogus MAC address.
131 bool GetMacAttributeString(nl80211_attrs name, std::string *value) const;
132
133 // Helper function to provide a vector of scan frequencies for attributes
134 // that contain them (such as NL80211_ATTR_SCAN_FREQUENCIES).
135 bool GetScanFrequenciesAttribute(enum nl80211_attrs name,
136 std::vector<uint32_t> *value) const;
137
138 // Helper function to provide a vector of SSIDs for attributes that contain
139 // them (such as NL80211_ATTR_SCAN_SSIDS).
140 bool GetScanSsidsAttribute(enum nl80211_attrs name,
141 std::vector<std::string> *value) const;
142
143 // Writes the raw attribute data to a string. For debug.
144 virtual std::string RawToString(nl80211_attrs name) const;
145
146 // Returns a string describing a given attribute name.
147 static std::string StringFromAttributeName(nl80211_attrs name);
148
149 // Stringizes the MAC address found in 'arg'. If there are problems (such
150 // as a NULL |arg|), |value| is set to a bogus MAC address.
151 static std::string StringFromMacAddress(const uint8_t *arg);
152
Wade Guthried4977f22012-08-22 12:37:54 -0700153 // Returns a string representing the passed-in |status| or |reason|, the
154 // value of which has been acquired from libnl (for example, from the
Wade Guthrie0d438532012-05-18 14:18:50 -0700155 // NL80211_ATTR_STATUS_CODE or NL80211_ATTR_REASON_CODE attribute).
Wade Guthried4977f22012-08-22 12:37:54 -0700156 static std::string StringFromReason(uint16_t reason);
Wade Guthrie0d438532012-05-18 14:18:50 -0700157 static std::string StringFromStatus(uint16_t status);
158
159 // Returns a string that describes this message.
160 virtual std::string ToString() const { return GetHeaderString(); }
161
Christopher Wiley764538d2012-11-09 10:58:23 -0800162 uint8 message_type() const { return message_type_; }
163 const char *message_type_string() const { return message_type_string_; }
164
Wade Guthrie0d438532012-05-18 14:18:50 -0700165 protected:
166 // Duplicate attribute data, store in map indexed on 'name'.
167 bool AddAttribute(nl80211_attrs name, nlattr *data);
168
169 // Returns the raw nlattr for a given attribute (NULL if attribute doesn't
170 // exist).
171 const nlattr *GetAttribute(nl80211_attrs name) const;
172
173 // Returns a string that should precede all user-bound message strings.
174 virtual std::string GetHeaderString() const;
175
176 // Returns a string that describes the contents of the frame pointed to by
177 // 'attr'.
178 std::string StringFromFrame(nl80211_attrs attr_name) const;
179
180 // Converts key_type to a string.
181 static std::string StringFromKeyType(nl80211_key_type key_type);
182
183 // Returns a string representation of the REG initiator described by the
184 // method's parameter.
185 static std::string StringFromRegInitiator(__u8 initiator);
186
187 // Returns a string based on the SSID found in 'data'. Non-printable
188 // characters are string-ized.
189 static std::string StringFromSsid(const uint8_t len, const uint8_t *data);
190
191 private:
192 friend class AttributeNameIterator;
193 friend class Config80211Test;
194 FRIEND_TEST(Config80211Test, NL80211_CMD_NOTIFY_CQM);
195
196 static const uint32_t kIllegalMessage;
197 static const int kEthernetAddressBytes;
198
199 nlmsghdr *message_;
Christopher Wiley764538d2012-11-09 10:58:23 -0800200 const uint8 message_type_;
201 const char *message_type_string_;
Wade Guthried4977f22012-08-22 12:37:54 -0700202 static std::map<uint16_t, std::string> *reason_code_string_;
203 static std::map<uint16_t, std::string> *status_code_string_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700204 std::map<nl80211_attrs, nlattr *> attributes_;
205
206 DISALLOW_COPY_AND_ASSIGN(UserBoundNlMessage);
207};
208
209class Nl80211Frame {
210 public:
211 enum Type {
212 kAssocResponseFrameType = 0x10,
213 kReassocResponseFrameType = 0x30,
214 kAssocRequestFrameType = 0x00,
215 kReassocRequestFrameType = 0x20,
216 kAuthFrameType = 0xb0,
217 kDisassocFrameType = 0xa0,
218 kDeauthFrameType = 0xc0,
219 kIllegalFrameType = 0xff
220 };
221
222 Nl80211Frame(const uint8_t *frame, int frame_byte_count);
223 ~Nl80211Frame();
Wade Guthried4977f22012-08-22 12:37:54 -0700224 bool ToString(std::string *output) const;
225 bool IsEqual(const Nl80211Frame &other) const;
226 uint16_t reason() const { return reason_; }
227 uint16_t status() const { return status_; }
Wade Guthrie0d438532012-05-18 14:18:50 -0700228
229 private:
230 static const uint8_t kMinimumFrameByteCount;
231 static const uint8_t kFrameTypeMask;
232
233 std::string mac_from_;
234 std::string mac_to_;
235 uint8_t frame_type_;
Wade Guthried4977f22012-08-22 12:37:54 -0700236 uint16_t reason_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700237 uint16_t status_;
238 uint8_t *frame_;
239 int byte_count_;
240
241 DISALLOW_COPY_AND_ASSIGN(Nl80211Frame);
242};
243
244//
245// Specific UserBoundNlMessage types.
246//
247
248class AssociateMessage : public UserBoundNlMessage {
249 public:
250 static const uint8_t kCommand;
251 static const char kCommandString[];
252
Christopher Wiley764538d2012-11-09 10:58:23 -0800253 AssociateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700254
Wade Guthrie0d438532012-05-18 14:18:50 -0700255 virtual std::string ToString() const;
256
257 private:
258 DISALLOW_COPY_AND_ASSIGN(AssociateMessage);
259};
260
261
262class AuthenticateMessage : public UserBoundNlMessage {
263 public:
264 static const uint8_t kCommand;
265 static const char kCommandString[];
266
Christopher Wiley764538d2012-11-09 10:58:23 -0800267 AuthenticateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700268
Wade Guthrie0d438532012-05-18 14:18:50 -0700269 virtual std::string ToString() const;
270
271 private:
272 DISALLOW_COPY_AND_ASSIGN(AuthenticateMessage);
273};
274
275
276class CancelRemainOnChannelMessage : public UserBoundNlMessage {
277 public:
278 static const uint8_t kCommand;
279 static const char kCommandString[];
280
Christopher Wiley764538d2012-11-09 10:58:23 -0800281 CancelRemainOnChannelMessage()
282 : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700283
Wade Guthrie0d438532012-05-18 14:18:50 -0700284 virtual std::string ToString() const;
285
286 private:
287 DISALLOW_COPY_AND_ASSIGN(CancelRemainOnChannelMessage);
288};
289
290
291class ConnectMessage : public UserBoundNlMessage {
292 public:
293 static const uint8_t kCommand;
294 static const char kCommandString[];
295
Christopher Wiley764538d2012-11-09 10:58:23 -0800296 ConnectMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700297
Wade Guthrie0d438532012-05-18 14:18:50 -0700298 virtual std::string ToString() const;
299
300 private:
301 DISALLOW_COPY_AND_ASSIGN(ConnectMessage);
302};
303
304
305class DeauthenticateMessage : public UserBoundNlMessage {
306 public:
307 static const uint8_t kCommand;
308 static const char kCommandString[];
309
Christopher Wiley764538d2012-11-09 10:58:23 -0800310 DeauthenticateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700311
Wade Guthrie0d438532012-05-18 14:18:50 -0700312 virtual std::string ToString() const;
313
314 private:
315 DISALLOW_COPY_AND_ASSIGN(DeauthenticateMessage);
316};
317
318
319class DeleteStationMessage : public UserBoundNlMessage {
320 public:
321 static const uint8_t kCommand;
322 static const char kCommandString[];
323
Christopher Wiley764538d2012-11-09 10:58:23 -0800324 DeleteStationMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700325
Wade Guthrie0d438532012-05-18 14:18:50 -0700326 virtual std::string ToString() const;
327
328 private:
329 DISALLOW_COPY_AND_ASSIGN(DeleteStationMessage);
330};
331
332
333class DisassociateMessage : public UserBoundNlMessage {
334 public:
335 static const uint8_t kCommand;
336 static const char kCommandString[];
337
Christopher Wiley764538d2012-11-09 10:58:23 -0800338 DisassociateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700339
Wade Guthrie0d438532012-05-18 14:18:50 -0700340 virtual std::string ToString() const;
341
342 private:
343 DISALLOW_COPY_AND_ASSIGN(DisassociateMessage);
344};
345
346
347class DisconnectMessage : public UserBoundNlMessage {
348 public:
349 static const uint8_t kCommand;
350 static const char kCommandString[];
351
Christopher Wiley764538d2012-11-09 10:58:23 -0800352 DisconnectMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700353
Wade Guthrie0d438532012-05-18 14:18:50 -0700354 virtual std::string ToString() const;
355
356 private:
357 DISALLOW_COPY_AND_ASSIGN(DisconnectMessage);
358};
359
360
361class FrameTxStatusMessage : public UserBoundNlMessage {
362 public:
363 static const uint8_t kCommand;
364 static const char kCommandString[];
365
Christopher Wiley764538d2012-11-09 10:58:23 -0800366 FrameTxStatusMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700367
Wade Guthrie0d438532012-05-18 14:18:50 -0700368 virtual std::string ToString() const;
369
370 private:
371 DISALLOW_COPY_AND_ASSIGN(FrameTxStatusMessage);
372};
373
374
375class JoinIbssMessage : public UserBoundNlMessage {
376 public:
377 static const uint8_t kCommand;
378 static const char kCommandString[];
379
Christopher Wiley764538d2012-11-09 10:58:23 -0800380 JoinIbssMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700381
Wade Guthrie0d438532012-05-18 14:18:50 -0700382 virtual std::string ToString() const;
383
384 private:
385 DISALLOW_COPY_AND_ASSIGN(JoinIbssMessage);
386};
387
388
389class MichaelMicFailureMessage : public UserBoundNlMessage {
390 public:
391 static const uint8_t kCommand;
392 static const char kCommandString[];
393
Christopher Wiley764538d2012-11-09 10:58:23 -0800394 MichaelMicFailureMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700395
Wade Guthrie0d438532012-05-18 14:18:50 -0700396 virtual std::string ToString() const;
397
398 private:
399 DISALLOW_COPY_AND_ASSIGN(MichaelMicFailureMessage);
400};
401
402
403class NewScanResultsMessage : public UserBoundNlMessage {
404 public:
405 static const uint8_t kCommand;
406 static const char kCommandString[];
407
Christopher Wiley764538d2012-11-09 10:58:23 -0800408 NewScanResultsMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700409
Wade Guthrie0d438532012-05-18 14:18:50 -0700410 virtual std::string ToString() const;
411
412 private:
413 DISALLOW_COPY_AND_ASSIGN(NewScanResultsMessage);
414};
415
416
417class NewStationMessage : public UserBoundNlMessage {
418 public:
419 static const uint8_t kCommand;
420 static const char kCommandString[];
421
Christopher Wiley764538d2012-11-09 10:58:23 -0800422 NewStationMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700423
Wade Guthrie0d438532012-05-18 14:18:50 -0700424 virtual std::string ToString() const;
425
426 private:
427 DISALLOW_COPY_AND_ASSIGN(NewStationMessage);
428};
429
430
431class NewWifiMessage : public UserBoundNlMessage {
432 public:
433 static const uint8_t kCommand;
434 static const char kCommandString[];
435
Christopher Wiley764538d2012-11-09 10:58:23 -0800436 NewWifiMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700437
Wade Guthrie0d438532012-05-18 14:18:50 -0700438 virtual std::string ToString() const;
439
440 private:
441 DISALLOW_COPY_AND_ASSIGN(NewWifiMessage);
442};
443
444
445class NotifyCqmMessage : public UserBoundNlMessage {
446 public:
447 static const uint8_t kCommand;
448 static const char kCommandString[];
449
Christopher Wiley764538d2012-11-09 10:58:23 -0800450 NotifyCqmMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700451
Wade Guthrie0d438532012-05-18 14:18:50 -0700452 virtual std::string ToString() const;
453
454 private:
455 DISALLOW_COPY_AND_ASSIGN(NotifyCqmMessage);
456};
457
458
459class PmksaCandidateMessage : public UserBoundNlMessage {
460 public:
461 static const uint8_t kCommand;
462 static const char kCommandString[];
463
Christopher Wiley764538d2012-11-09 10:58:23 -0800464 PmksaCandidateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700465
Wade Guthrie0d438532012-05-18 14:18:50 -0700466 virtual std::string ToString() const;
467
468 private:
469 DISALLOW_COPY_AND_ASSIGN(PmksaCandidateMessage);
470};
471
472
473class RegBeaconHintMessage : public UserBoundNlMessage {
474 public:
475 static const uint8_t kCommand;
476 static const char kCommandString[];
477
Christopher Wiley764538d2012-11-09 10:58:23 -0800478 RegBeaconHintMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700479
Wade Guthrie0d438532012-05-18 14:18:50 -0700480 virtual std::string ToString() const;
481
482 private:
483 struct ieee80211_beacon_channel {
484 __u16 center_freq;
485 bool passive_scan;
486 bool no_ibss;
487 };
488
489 // Returns the channel ID calculated from the 802.11 frequency.
490 static int ChannelFromIeee80211Frequency(int freq);
491
492 // Sets values in |chan| based on attributes in |tb|, the array of pointers
493 // to netlink attributes, indexed by attribute type.
494 int ParseBeaconHintChan(const nlattr *tb,
495 ieee80211_beacon_channel *chan) const;
496
497 DISALLOW_COPY_AND_ASSIGN(RegBeaconHintMessage);
498};
499
500
501class RegChangeMessage : public UserBoundNlMessage {
502 public:
503 static const uint8_t kCommand;
504 static const char kCommandString[];
505
Christopher Wiley764538d2012-11-09 10:58:23 -0800506 RegChangeMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700507
Wade Guthrie0d438532012-05-18 14:18:50 -0700508 virtual std::string ToString() const;
509
510 private:
511 DISALLOW_COPY_AND_ASSIGN(RegChangeMessage);
512};
513
514
515class RemainOnChannelMessage : public UserBoundNlMessage {
516 public:
517 static const uint8_t kCommand;
518 static const char kCommandString[];
519
Christopher Wiley764538d2012-11-09 10:58:23 -0800520 RemainOnChannelMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700521
Wade Guthrie0d438532012-05-18 14:18:50 -0700522 virtual std::string ToString() const;
523
524 private:
525 DISALLOW_COPY_AND_ASSIGN(RemainOnChannelMessage);
526};
527
528
529class RoamMessage : public UserBoundNlMessage {
530 public:
531 static const uint8_t kCommand;
532 static const char kCommandString[];
533
Christopher Wiley764538d2012-11-09 10:58:23 -0800534 RoamMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700535
Wade Guthrie0d438532012-05-18 14:18:50 -0700536 virtual std::string ToString() const;
537
538 private:
539 DISALLOW_COPY_AND_ASSIGN(RoamMessage);
540};
541
542
543class ScanAbortedMessage : public UserBoundNlMessage {
544 public:
545 static const uint8_t kCommand;
546 static const char kCommandString[];
547
Christopher Wiley764538d2012-11-09 10:58:23 -0800548 ScanAbortedMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700549
Wade Guthrie0d438532012-05-18 14:18:50 -0700550 virtual std::string ToString() const;
551
552 private:
553 DISALLOW_COPY_AND_ASSIGN(ScanAbortedMessage);
554};
555
556
557class TriggerScanMessage : public UserBoundNlMessage {
558 public:
559 static const uint8_t kCommand;
560 static const char kCommandString[];
561
Christopher Wiley764538d2012-11-09 10:58:23 -0800562 TriggerScanMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700563
Wade Guthrie0d438532012-05-18 14:18:50 -0700564 virtual std::string ToString() const;
565
566 private:
567 DISALLOW_COPY_AND_ASSIGN(TriggerScanMessage);
568};
569
570
571class UnknownMessage : public UserBoundNlMessage {
572 public:
Christopher Wiley764538d2012-11-09 10:58:23 -0800573 explicit UnknownMessage(uint8_t command)
574 : UserBoundNlMessage(command, kCommandString),
575 command_(command) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700576
577 static const uint8_t kCommand;
578 static const char kCommandString[];
579
Wade Guthrie0d438532012-05-18 14:18:50 -0700580 virtual std::string ToString() const;
581
582 private:
583 uint8_t command_;
584
585 DISALLOW_COPY_AND_ASSIGN(UnknownMessage);
586};
587
588
589class UnprotDeauthenticateMessage : public UserBoundNlMessage {
590 public:
591 static const uint8_t kCommand;
592 static const char kCommandString[];
593
Christopher Wiley764538d2012-11-09 10:58:23 -0800594 UnprotDeauthenticateMessage()
595 : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700596
Wade Guthrie0d438532012-05-18 14:18:50 -0700597 virtual std::string ToString() const;
598
599 private:
600 DISALLOW_COPY_AND_ASSIGN(UnprotDeauthenticateMessage);
601};
602
603
604class UnprotDisassociateMessage : public UserBoundNlMessage {
605 public:
606 static const uint8_t kCommand;
607 static const char kCommandString[];
608
Christopher Wiley764538d2012-11-09 10:58:23 -0800609 UnprotDisassociateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700610
Wade Guthrie0d438532012-05-18 14:18:50 -0700611 virtual std::string ToString() const;
612
613 private:
614 DISALLOW_COPY_AND_ASSIGN(UnprotDisassociateMessage);
615};
616
617
618//
619// Factory class.
620//
621
622class UserBoundNlMessageFactory {
623 public:
624 // Ownership of the message is passed to the caller and, as such, he should
625 // delete it.
626 static UserBoundNlMessage *CreateMessage(nlmsghdr *msg);
627
628 private:
629 DISALLOW_COPY_AND_ASSIGN(UserBoundNlMessageFactory);
630};
631
632
633// UserBoundNlMessageDataCollector - this class is used to collect data to be
634// used for unit tests. It is only invoked in this case.
635
636class UserBoundNlMessageDataCollector {
637 public:
638 // This is a singleton -- use Config80211::GetInstance()->Foo()
639 static UserBoundNlMessageDataCollector *GetInstance();
640
641 void CollectDebugData(const UserBoundNlMessage &message, nlmsghdr *msg);
642
643 protected:
644 friend struct
645 base::DefaultLazyInstanceTraits<UserBoundNlMessageDataCollector>;
646
647 explicit UserBoundNlMessageDataCollector();
648
649 private:
650 // In order to limit the output from this class, I keep track of types I
651 // haven't yet printed.
652 std::map<uint8_t, bool> need_to_print;
653};
654
655} // namespace shill
656
657#endif // SHILL_USER_BOUND_NLMESSAGE_H_