blob: f11c90b09c14301c7896a10bde211a6b31880f0a [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
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 Guthrie0d438532012-05-18 14:18:50 -070030 // TODO(wdg): break 'Attribute' into its own class to handle
31 // nested attributes better.
32
33 // A const iterator to the attribute names in the attributes_ map of a
34 // UserBoundNlMessage. The purpose, here, is to hide the way that the
35 // attribute is stored.
36 class AttributeNameIterator {
37 public:
38 explicit AttributeNameIterator(const std::map<nl80211_attrs,
39 nlattr *> &map_param)
40 : map_(map_param) {
41 iter_ = map_.begin();
42 }
43
44 // Causes the iterator to point to the next attribute in the list.
45 void Advance() { ++iter_; }
46
47 // Returns 'true' if the iterator points beyond the last attribute in the
48 // list; returns 'false' otherwise.
49 bool AtEnd() const { return iter_ == map_.end(); }
50
51 // Returns the attribute name (which is actually an 'enum' value).
52 nl80211_attrs GetName() const { return iter_->first; }
53
54 private:
55 const std::map<nl80211_attrs, nlattr *> &map_;
56 std::map<nl80211_attrs, nlattr *>::const_iterator iter_;
57
58 DISALLOW_COPY_AND_ASSIGN(AttributeNameIterator);
59 };
60
Wade Guthrie0d438532012-05-18 14:18:50 -070061 static const char kBogusMacAddress[];
62
Christopher Wiley764538d2012-11-09 10:58:23 -080063 UserBoundNlMessage(uint8 message_type, const char *message_type_string)
64 : message_(NULL),
65 message_type_(message_type),
66 message_type_string_(message_type_string) { }
Wade Guthrie0d438532012-05-18 14:18:50 -070067 virtual ~UserBoundNlMessage();
68
69 // Non-trivial initialization.
70 virtual bool Init(nlattr *tb[NL80211_ATTR_MAX + 1], nlmsghdr *msg);
71
72 // Provide a suite of methods to allow (const) iteration over the names of the
73 // attributes inside a message object.
74
75 AttributeNameIterator *GetAttributeNameIterator() const;
76 bool HasAttributes() const { return !attributes_.empty(); }
77 uint32_t GetAttributeCount() const { return attributes_.size(); }
78
Wade Guthrie0d438532012-05-18 14:18:50 -070079 // Other ways to see the internals of the object.
80
81 // Return true if the attribute is in our map, regardless of the value of
82 // the attribute, itself.
83 bool AttributeExists(nl80211_attrs name) const;
84
85 // Message ID is equivalent to the message's sequence number.
86 uint32_t GetId() const;
87
88 // Returns the data type of a given attribute.
Wade Guthrie16196242012-11-20 15:53:52 -080089 Nl80211Attribute::Type GetAttributeType(nl80211_attrs name) const;
Wade Guthrie0d438532012-05-18 14:18:50 -070090
91 // Returns a string describing the data type of a given attribute.
92 std::string GetAttributeTypeString(nl80211_attrs name) const;
93
94 // If successful, returns 'true' and sets *|value| to the raw attribute data
95 // (after the header) for this attribute and, if |length| is not
96 // null, *|length| to the number of bytes of data available. If no
97 // attribute by this name exists in this message, sets *|value| to NULL and
98 // returns 'false'. If otherwise unsuccessful, returns 'false' and leaves
99 // |value| and |length| unchanged.
100 bool GetRawAttributeData(nl80211_attrs name, void **value, int *length) const;
101
102 // Each of these methods set |value| with the value of the specified
103 // attribute (if the attribute is not found, |value| remains unchanged).
104
105 bool GetStringAttribute(nl80211_attrs name, std::string *value) const;
106 bool GetU8Attribute(nl80211_attrs name, uint8_t *value) const;
107 bool GetU16Attribute(nl80211_attrs name, uint16_t *value) const;
108 bool GetU32Attribute(nl80211_attrs name, uint32_t *value) const;
109 bool GetU64Attribute(nl80211_attrs name, uint64_t *value) const;
110
111 // Fill a string with characters that represents the value of the attribute.
112 // If no attribute is found or if the type isn't trivially stringizable,
113 // this method returns 'false' and |value| remains unchanged.
114 bool GetAttributeString(nl80211_attrs name, std::string *value) const;
115
116 // Helper function to provide a string for a MAC address. If no attribute
117 // is found, this method returns 'false'. On any error with a non-NULL
118 // |value|, this method sets |value| to a bogus MAC address.
119 bool GetMacAttributeString(nl80211_attrs name, std::string *value) const;
120
121 // Helper function to provide a vector of scan frequencies for attributes
122 // that contain them (such as NL80211_ATTR_SCAN_FREQUENCIES).
123 bool GetScanFrequenciesAttribute(enum nl80211_attrs name,
124 std::vector<uint32_t> *value) const;
125
126 // Helper function to provide a vector of SSIDs for attributes that contain
127 // them (such as NL80211_ATTR_SCAN_SSIDS).
128 bool GetScanSsidsAttribute(enum nl80211_attrs name,
129 std::vector<std::string> *value) const;
130
131 // Writes the raw attribute data to a string. For debug.
132 virtual std::string RawToString(nl80211_attrs name) const;
133
134 // Returns a string describing a given attribute name.
135 static std::string StringFromAttributeName(nl80211_attrs name);
136
137 // Stringizes the MAC address found in 'arg'. If there are problems (such
138 // as a NULL |arg|), |value| is set to a bogus MAC address.
139 static std::string StringFromMacAddress(const uint8_t *arg);
140
Wade Guthried4977f22012-08-22 12:37:54 -0700141 // Returns a string representing the passed-in |status| or |reason|, the
142 // value of which has been acquired from libnl (for example, from the
Wade Guthrie0d438532012-05-18 14:18:50 -0700143 // NL80211_ATTR_STATUS_CODE or NL80211_ATTR_REASON_CODE attribute).
Wade Guthried4977f22012-08-22 12:37:54 -0700144 static std::string StringFromReason(uint16_t reason);
Wade Guthrie0d438532012-05-18 14:18:50 -0700145 static std::string StringFromStatus(uint16_t status);
146
147 // Returns a string that describes this message.
148 virtual std::string ToString() const { return GetHeaderString(); }
149
Christopher Wiley764538d2012-11-09 10:58:23 -0800150 uint8 message_type() const { return message_type_; }
151 const char *message_type_string() const { return message_type_string_; }
152
Wade Guthrie0d438532012-05-18 14:18:50 -0700153 protected:
154 // Duplicate attribute data, store in map indexed on 'name'.
155 bool AddAttribute(nl80211_attrs name, nlattr *data);
156
157 // Returns the raw nlattr for a given attribute (NULL if attribute doesn't
158 // exist).
159 const nlattr *GetAttribute(nl80211_attrs name) const;
160
161 // Returns a string that should precede all user-bound message strings.
162 virtual std::string GetHeaderString() const;
163
164 // Returns a string that describes the contents of the frame pointed to by
165 // 'attr'.
166 std::string StringFromFrame(nl80211_attrs attr_name) const;
167
168 // Converts key_type to a string.
169 static std::string StringFromKeyType(nl80211_key_type key_type);
170
171 // Returns a string representation of the REG initiator described by the
172 // method's parameter.
173 static std::string StringFromRegInitiator(__u8 initiator);
174
175 // Returns a string based on the SSID found in 'data'. Non-printable
176 // characters are string-ized.
177 static std::string StringFromSsid(const uint8_t len, const uint8_t *data);
178
179 private:
180 friend class AttributeNameIterator;
181 friend class Config80211Test;
182 FRIEND_TEST(Config80211Test, NL80211_CMD_NOTIFY_CQM);
183
184 static const uint32_t kIllegalMessage;
185 static const int kEthernetAddressBytes;
186
187 nlmsghdr *message_;
Christopher Wiley764538d2012-11-09 10:58:23 -0800188 const uint8 message_type_;
189 const char *message_type_string_;
Wade Guthried4977f22012-08-22 12:37:54 -0700190 static std::map<uint16_t, std::string> *reason_code_string_;
191 static std::map<uint16_t, std::string> *status_code_string_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700192 std::map<nl80211_attrs, nlattr *> attributes_;
193
194 DISALLOW_COPY_AND_ASSIGN(UserBoundNlMessage);
195};
196
197class Nl80211Frame {
198 public:
199 enum Type {
200 kAssocResponseFrameType = 0x10,
201 kReassocResponseFrameType = 0x30,
202 kAssocRequestFrameType = 0x00,
203 kReassocRequestFrameType = 0x20,
204 kAuthFrameType = 0xb0,
205 kDisassocFrameType = 0xa0,
206 kDeauthFrameType = 0xc0,
207 kIllegalFrameType = 0xff
208 };
209
210 Nl80211Frame(const uint8_t *frame, int frame_byte_count);
211 ~Nl80211Frame();
Wade Guthried4977f22012-08-22 12:37:54 -0700212 bool ToString(std::string *output) const;
213 bool IsEqual(const Nl80211Frame &other) const;
214 uint16_t reason() const { return reason_; }
215 uint16_t status() const { return status_; }
Wade Guthrie0d438532012-05-18 14:18:50 -0700216
217 private:
218 static const uint8_t kMinimumFrameByteCount;
219 static const uint8_t kFrameTypeMask;
220
221 std::string mac_from_;
222 std::string mac_to_;
223 uint8_t frame_type_;
Wade Guthried4977f22012-08-22 12:37:54 -0700224 uint16_t reason_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700225 uint16_t status_;
226 uint8_t *frame_;
227 int byte_count_;
228
229 DISALLOW_COPY_AND_ASSIGN(Nl80211Frame);
230};
231
232//
233// Specific UserBoundNlMessage types.
234//
235
236class AssociateMessage : public UserBoundNlMessage {
237 public:
238 static const uint8_t kCommand;
239 static const char kCommandString[];
240
Christopher Wiley764538d2012-11-09 10:58:23 -0800241 AssociateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700242
Wade Guthrie0d438532012-05-18 14:18:50 -0700243 virtual std::string ToString() const;
244
245 private:
246 DISALLOW_COPY_AND_ASSIGN(AssociateMessage);
247};
248
249
250class AuthenticateMessage : public UserBoundNlMessage {
251 public:
252 static const uint8_t kCommand;
253 static const char kCommandString[];
254
Christopher Wiley764538d2012-11-09 10:58:23 -0800255 AuthenticateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700256
Wade Guthrie0d438532012-05-18 14:18:50 -0700257 virtual std::string ToString() const;
258
259 private:
260 DISALLOW_COPY_AND_ASSIGN(AuthenticateMessage);
261};
262
263
264class CancelRemainOnChannelMessage : public UserBoundNlMessage {
265 public:
266 static const uint8_t kCommand;
267 static const char kCommandString[];
268
Christopher Wiley764538d2012-11-09 10:58:23 -0800269 CancelRemainOnChannelMessage()
270 : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700271
Wade Guthrie0d438532012-05-18 14:18:50 -0700272 virtual std::string ToString() const;
273
274 private:
275 DISALLOW_COPY_AND_ASSIGN(CancelRemainOnChannelMessage);
276};
277
278
279class ConnectMessage : public UserBoundNlMessage {
280 public:
281 static const uint8_t kCommand;
282 static const char kCommandString[];
283
Christopher Wiley764538d2012-11-09 10:58:23 -0800284 ConnectMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700285
Wade Guthrie0d438532012-05-18 14:18:50 -0700286 virtual std::string ToString() const;
287
288 private:
289 DISALLOW_COPY_AND_ASSIGN(ConnectMessage);
290};
291
292
293class DeauthenticateMessage : public UserBoundNlMessage {
294 public:
295 static const uint8_t kCommand;
296 static const char kCommandString[];
297
Christopher Wiley764538d2012-11-09 10:58:23 -0800298 DeauthenticateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700299
Wade Guthrie0d438532012-05-18 14:18:50 -0700300 virtual std::string ToString() const;
301
302 private:
303 DISALLOW_COPY_AND_ASSIGN(DeauthenticateMessage);
304};
305
306
307class DeleteStationMessage : public UserBoundNlMessage {
308 public:
309 static const uint8_t kCommand;
310 static const char kCommandString[];
311
Christopher Wiley764538d2012-11-09 10:58:23 -0800312 DeleteStationMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700313
Wade Guthrie0d438532012-05-18 14:18:50 -0700314 virtual std::string ToString() const;
315
316 private:
317 DISALLOW_COPY_AND_ASSIGN(DeleteStationMessage);
318};
319
320
321class DisassociateMessage : public UserBoundNlMessage {
322 public:
323 static const uint8_t kCommand;
324 static const char kCommandString[];
325
Christopher Wiley764538d2012-11-09 10:58:23 -0800326 DisassociateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700327
Wade Guthrie0d438532012-05-18 14:18:50 -0700328 virtual std::string ToString() const;
329
330 private:
331 DISALLOW_COPY_AND_ASSIGN(DisassociateMessage);
332};
333
334
335class DisconnectMessage : public UserBoundNlMessage {
336 public:
337 static const uint8_t kCommand;
338 static const char kCommandString[];
339
Christopher Wiley764538d2012-11-09 10:58:23 -0800340 DisconnectMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700341
Wade Guthrie0d438532012-05-18 14:18:50 -0700342 virtual std::string ToString() const;
343
344 private:
345 DISALLOW_COPY_AND_ASSIGN(DisconnectMessage);
346};
347
348
349class FrameTxStatusMessage : public UserBoundNlMessage {
350 public:
351 static const uint8_t kCommand;
352 static const char kCommandString[];
353
Christopher Wiley764538d2012-11-09 10:58:23 -0800354 FrameTxStatusMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700355
Wade Guthrie0d438532012-05-18 14:18:50 -0700356 virtual std::string ToString() const;
357
358 private:
359 DISALLOW_COPY_AND_ASSIGN(FrameTxStatusMessage);
360};
361
362
363class JoinIbssMessage : public UserBoundNlMessage {
364 public:
365 static const uint8_t kCommand;
366 static const char kCommandString[];
367
Christopher Wiley764538d2012-11-09 10:58:23 -0800368 JoinIbssMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700369
Wade Guthrie0d438532012-05-18 14:18:50 -0700370 virtual std::string ToString() const;
371
372 private:
373 DISALLOW_COPY_AND_ASSIGN(JoinIbssMessage);
374};
375
376
377class MichaelMicFailureMessage : public UserBoundNlMessage {
378 public:
379 static const uint8_t kCommand;
380 static const char kCommandString[];
381
Christopher Wiley764538d2012-11-09 10:58:23 -0800382 MichaelMicFailureMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700383
Wade Guthrie0d438532012-05-18 14:18:50 -0700384 virtual std::string ToString() const;
385
386 private:
387 DISALLOW_COPY_AND_ASSIGN(MichaelMicFailureMessage);
388};
389
390
391class NewScanResultsMessage : public UserBoundNlMessage {
392 public:
393 static const uint8_t kCommand;
394 static const char kCommandString[];
395
Christopher Wiley764538d2012-11-09 10:58:23 -0800396 NewScanResultsMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700397
Wade Guthrie0d438532012-05-18 14:18:50 -0700398 virtual std::string ToString() const;
399
400 private:
401 DISALLOW_COPY_AND_ASSIGN(NewScanResultsMessage);
402};
403
404
405class NewStationMessage : public UserBoundNlMessage {
406 public:
407 static const uint8_t kCommand;
408 static const char kCommandString[];
409
Christopher Wiley764538d2012-11-09 10:58:23 -0800410 NewStationMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700411
Wade Guthrie0d438532012-05-18 14:18:50 -0700412 virtual std::string ToString() const;
413
414 private:
415 DISALLOW_COPY_AND_ASSIGN(NewStationMessage);
416};
417
418
419class NewWifiMessage : public UserBoundNlMessage {
420 public:
421 static const uint8_t kCommand;
422 static const char kCommandString[];
423
Christopher Wiley764538d2012-11-09 10:58:23 -0800424 NewWifiMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700425
Wade Guthrie0d438532012-05-18 14:18:50 -0700426 virtual std::string ToString() const;
427
428 private:
429 DISALLOW_COPY_AND_ASSIGN(NewWifiMessage);
430};
431
432
433class NotifyCqmMessage : public UserBoundNlMessage {
434 public:
435 static const uint8_t kCommand;
436 static const char kCommandString[];
437
Christopher Wiley764538d2012-11-09 10:58:23 -0800438 NotifyCqmMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700439
Wade Guthrie0d438532012-05-18 14:18:50 -0700440 virtual std::string ToString() const;
441
442 private:
443 DISALLOW_COPY_AND_ASSIGN(NotifyCqmMessage);
444};
445
446
447class PmksaCandidateMessage : public UserBoundNlMessage {
448 public:
449 static const uint8_t kCommand;
450 static const char kCommandString[];
451
Christopher Wiley764538d2012-11-09 10:58:23 -0800452 PmksaCandidateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700453
Wade Guthrie0d438532012-05-18 14:18:50 -0700454 virtual std::string ToString() const;
455
456 private:
457 DISALLOW_COPY_AND_ASSIGN(PmksaCandidateMessage);
458};
459
460
461class RegBeaconHintMessage : public UserBoundNlMessage {
462 public:
463 static const uint8_t kCommand;
464 static const char kCommandString[];
465
Christopher Wiley764538d2012-11-09 10:58:23 -0800466 RegBeaconHintMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700467
Wade Guthrie0d438532012-05-18 14:18:50 -0700468 virtual std::string ToString() const;
469
470 private:
471 struct ieee80211_beacon_channel {
472 __u16 center_freq;
473 bool passive_scan;
474 bool no_ibss;
475 };
476
477 // Returns the channel ID calculated from the 802.11 frequency.
478 static int ChannelFromIeee80211Frequency(int freq);
479
480 // Sets values in |chan| based on attributes in |tb|, the array of pointers
481 // to netlink attributes, indexed by attribute type.
482 int ParseBeaconHintChan(const nlattr *tb,
483 ieee80211_beacon_channel *chan) const;
484
485 DISALLOW_COPY_AND_ASSIGN(RegBeaconHintMessage);
486};
487
488
489class RegChangeMessage : public UserBoundNlMessage {
490 public:
491 static const uint8_t kCommand;
492 static const char kCommandString[];
493
Christopher Wiley764538d2012-11-09 10:58:23 -0800494 RegChangeMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700495
Wade Guthrie0d438532012-05-18 14:18:50 -0700496 virtual std::string ToString() const;
497
498 private:
499 DISALLOW_COPY_AND_ASSIGN(RegChangeMessage);
500};
501
502
503class RemainOnChannelMessage : public UserBoundNlMessage {
504 public:
505 static const uint8_t kCommand;
506 static const char kCommandString[];
507
Christopher Wiley764538d2012-11-09 10:58:23 -0800508 RemainOnChannelMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700509
Wade Guthrie0d438532012-05-18 14:18:50 -0700510 virtual std::string ToString() const;
511
512 private:
513 DISALLOW_COPY_AND_ASSIGN(RemainOnChannelMessage);
514};
515
516
517class RoamMessage : public UserBoundNlMessage {
518 public:
519 static const uint8_t kCommand;
520 static const char kCommandString[];
521
Christopher Wiley764538d2012-11-09 10:58:23 -0800522 RoamMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700523
Wade Guthrie0d438532012-05-18 14:18:50 -0700524 virtual std::string ToString() const;
525
526 private:
527 DISALLOW_COPY_AND_ASSIGN(RoamMessage);
528};
529
530
531class ScanAbortedMessage : public UserBoundNlMessage {
532 public:
533 static const uint8_t kCommand;
534 static const char kCommandString[];
535
Christopher Wiley764538d2012-11-09 10:58:23 -0800536 ScanAbortedMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700537
Wade Guthrie0d438532012-05-18 14:18:50 -0700538 virtual std::string ToString() const;
539
540 private:
541 DISALLOW_COPY_AND_ASSIGN(ScanAbortedMessage);
542};
543
544
545class TriggerScanMessage : public UserBoundNlMessage {
546 public:
547 static const uint8_t kCommand;
548 static const char kCommandString[];
549
Christopher Wiley764538d2012-11-09 10:58:23 -0800550 TriggerScanMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700551
Wade Guthrie0d438532012-05-18 14:18:50 -0700552 virtual std::string ToString() const;
553
554 private:
555 DISALLOW_COPY_AND_ASSIGN(TriggerScanMessage);
556};
557
558
559class UnknownMessage : public UserBoundNlMessage {
560 public:
Christopher Wiley764538d2012-11-09 10:58:23 -0800561 explicit UnknownMessage(uint8_t command)
562 : UserBoundNlMessage(command, kCommandString),
563 command_(command) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700564
565 static const uint8_t kCommand;
566 static const char kCommandString[];
567
Wade Guthrie0d438532012-05-18 14:18:50 -0700568 virtual std::string ToString() const;
569
570 private:
571 uint8_t command_;
572
573 DISALLOW_COPY_AND_ASSIGN(UnknownMessage);
574};
575
576
577class UnprotDeauthenticateMessage : public UserBoundNlMessage {
578 public:
579 static const uint8_t kCommand;
580 static const char kCommandString[];
581
Christopher Wiley764538d2012-11-09 10:58:23 -0800582 UnprotDeauthenticateMessage()
583 : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700584
Wade Guthrie0d438532012-05-18 14:18:50 -0700585 virtual std::string ToString() const;
586
587 private:
588 DISALLOW_COPY_AND_ASSIGN(UnprotDeauthenticateMessage);
589};
590
591
592class UnprotDisassociateMessage : public UserBoundNlMessage {
593 public:
594 static const uint8_t kCommand;
595 static const char kCommandString[];
596
Christopher Wiley764538d2012-11-09 10:58:23 -0800597 UnprotDisassociateMessage() : UserBoundNlMessage(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700598
Wade Guthrie0d438532012-05-18 14:18:50 -0700599 virtual std::string ToString() const;
600
601 private:
602 DISALLOW_COPY_AND_ASSIGN(UnprotDisassociateMessage);
603};
604
605
606//
607// Factory class.
608//
609
610class UserBoundNlMessageFactory {
611 public:
612 // Ownership of the message is passed to the caller and, as such, he should
613 // delete it.
614 static UserBoundNlMessage *CreateMessage(nlmsghdr *msg);
615
616 private:
617 DISALLOW_COPY_AND_ASSIGN(UserBoundNlMessageFactory);
618};
619
620
621// UserBoundNlMessageDataCollector - this class is used to collect data to be
622// used for unit tests. It is only invoked in this case.
623
624class UserBoundNlMessageDataCollector {
625 public:
626 // This is a singleton -- use Config80211::GetInstance()->Foo()
627 static UserBoundNlMessageDataCollector *GetInstance();
628
629 void CollectDebugData(const UserBoundNlMessage &message, nlmsghdr *msg);
630
631 protected:
632 friend struct
633 base::DefaultLazyInstanceTraits<UserBoundNlMessageDataCollector>;
634
635 explicit UserBoundNlMessageDataCollector();
636
637 private:
638 // In order to limit the output from this class, I keep track of types I
639 // haven't yet printed.
640 std::map<uint8_t, bool> need_to_print;
641};
642
643} // namespace shill
644
645#endif // SHILL_USER_BOUND_NLMESSAGE_H_