blob: 6d2f7407fc0f78d6e409dced1fd8692c0b28d425 [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
Wade Guthriebdcdaa72013-03-04 12:47:12 -080029class Config80211;
30
Wade Guthrief48a1952013-03-04 17:33:47 -080031// Netlink messages are sent over netlink sockets to talk between user-space
32// programs (like shill) and kernel modules (like the cfg80211 module). Each
33// kernel module that talks netlink potentially adds its own family header to
34// the nlmsghdr (the top-level netlink message header) and, potentially, uses a
35// different payload format. The NetlinkMessage class represents that which
36// is common between the different types of netlink message.
37//
38// The common portions of Netlink Messages start with a |nlmsghdr|. Those
39// messages look something like the following (the functions, macros, and
40// datatypes described are provided by libnl -- see also
41// http://www.infradead.org/~tgr/libnl/doc/core.html):
42//
43// |<--------------nlmsg_total_size()----------->|
44// | |<------nlmsg_datalen()-------------->|
45// | | |
46// -----+-----+-+-----------------------------------+-+----
47// ... | | | netlink payload | |
48// | | +------------+-+--------------------+ |
49// | nl | | | | | | nl
50// | msg |p| (optional) |p| |p| msg ...
51// | hdr |a| family |a| family payload |a| hdr
52// | |d| header |d| |d|
53// | | | | | | |
54// -----+-----+-+------------+-+--------------------+-+----
55// ^
56// |
57// +-- nlmsg_data()
58//
59// All NetlinkMessages sent to the kernel need a valid message type (which is
60// found in the nlmsghdr structure) and all NetlinkMessages received from the
61// kernel have a valid message type. Some message types (NLMSG_NOOP,
62// NLMSG_ERROR, and GENL_ID_CTRL, for example) are allocated statically; for
63// those, the |message_type_| is assigned directly.
64//
65// Other message types ("nl80211", for example), are assigned by the kernel
66// dynamically. To get the message type, pass a closure to assign the
67// message_type along with the sting to Config80211::AddFamilyByString:
68//
69// config80211_->AddFamilyByString(Nl80211Message::kMessageType,
70// Bind(&Nl80211Message::SetFamilyId));
71//
72// Do all of this before you start to create NetlinkMessages so that
73// NetlinkMessage can be instantiated with a valid |message_type_|.
74
75class NetlinkMessage {
Wade Guthrie0d438532012-05-18 14:18:50 -070076 public:
Wade Guthriebdcdaa72013-03-04 12:47:12 -080077 static const uint32_t kBroadcastSequenceNumber;
78 static const uint16_t kIllegalMessageType;
Wade Guthrie0d438532012-05-18 14:18:50 -070079
Wade Guthrief48a1952013-03-04 17:33:47 -080080 explicit NetlinkMessage(uint16_t message_type) :
81 flags_(0), message_type_(message_type),
82 sequence_number_(kBroadcastSequenceNumber) {}
83 virtual ~NetlinkMessage() {}
84
85 // Returns a string of bytes representing the message (with it headers) and
86 // any necessary padding. These bytes are appropriately formatted to be
87 // written to a netlink socket.
88 virtual ByteString Encode(uint32_t sequence_number, uint16_t nlmsg_type) = 0;
89
90 // Initializes the |NetlinkMessage| from a complete and legal message
91 // (potentially received from the kernel via a netlink socket).
92 virtual bool InitFromNlmsg(const nlmsghdr *msg);
93
94 uint16_t message_type() const { return message_type_; }
95 void AddFlag(uint16_t new_flag) { flags_ |= new_flag; }
96 uint16_t flags() const { return flags_; }
97 uint32_t sequence_number() const { return sequence_number_; }
98 virtual void Print(int log_level) const = 0;
99
100 // Logs the message's raw bytes (with minimal interpretation).
101 static void PrintBytes(int log_level, const unsigned char *buf,
102 size_t num_bytes);
103
104 protected:
105 friend class Config80211Test;
106 FRIEND_TEST(Config80211Test, NL80211_CMD_NOTIFY_CQM);
107
108 // Returns a string of bytes representing an |nlmsghdr|, filled-in, and its
109 // padding.
110 virtual ByteString EncodeHeader(uint32_t sequence_number,
111 uint16_t nlmsg_type);
112 // Reads the |nlmsghdr| and removes it from |input|.
113 virtual bool InitAndStripHeader(ByteString *input);
114
115 uint16_t flags_;
116 uint16_t message_type_;
117 uint32_t sequence_number_;
118
119 private:
120 DISALLOW_COPY_AND_ASSIGN(NetlinkMessage);
121};
122
Wade Guthrie71872472013-03-05 10:33:38 -0800123
124// The Error and Ack messages are received from the kernel and are combined,
125// here, because they look so much alike (the only difference is that the
126// error code is 0 for the Ack messages). Error messages are received from
127// the kernel in response to a sent message when there's a problem (such as
128// a malformed message or a busy kernel module). Ack messages are received
129// from the kernel when a sent message has the NLM_F_ACK flag set, indicating
130// that an Ack is requested.
131class ErrorAckMessage : public NetlinkMessage {
132 public:
133 static const uint16_t kMessageType;
134
135 ErrorAckMessage() : NetlinkMessage(kMessageType), error_(0) {}
136 virtual bool InitFromNlmsg(const nlmsghdr *const_msg);
137 virtual ByteString Encode(uint32_t sequence_number, uint16_t nlmsg_type);
138 virtual void Print(int log_level) const;
139 std::string ToString() const;
140 uint32_t error() const { return -error_; }
141
142 private:
143 uint32_t error_;
144
145 DISALLOW_COPY_AND_ASSIGN(ErrorAckMessage);
146};
147
148
149class NoopMessage : public NetlinkMessage {
150 public:
151 static const uint16_t kMessageType;
152
153 NoopMessage() : NetlinkMessage(kMessageType) {}
154 virtual ByteString Encode(uint32_t sequence_number, uint16_t nlmsg_type);
155 virtual void Print(int log_level) const;
156 std::string ToString() const { return "<NOOP>"; }
157
158 private:
159 DISALLOW_COPY_AND_ASSIGN(NoopMessage);
160};
161
162
163class DoneMessage : public NetlinkMessage {
164 public:
165 static const uint16_t kMessageType;
166
167 DoneMessage() : NetlinkMessage(kMessageType) {}
168 virtual ByteString Encode(uint32_t sequence_number, uint16_t nlmsg_type);
169 virtual void Print(int log_level) const;
170 std::string ToString() const { return "<DONE with multipart message>"; }
171
172 private:
173 DISALLOW_COPY_AND_ASSIGN(DoneMessage);
174};
175
176
177class OverrunMessage : public NetlinkMessage {
178 public:
179 static const uint16_t kMessageType;
180
181 OverrunMessage() : NetlinkMessage(kMessageType) {}
182 virtual ByteString Encode(uint32_t sequence_number, uint16_t nlmsg_type);
183 virtual void Print(int log_level) const;
184 std::string ToString() const { return "<OVERRUN - data lost>"; }
185
186 private:
187 DISALLOW_COPY_AND_ASSIGN(OverrunMessage);
188};
189
Wade Guthrief48a1952013-03-04 17:33:47 -0800190// Objects of the |GenericNetlinkMessage| type represent messages that contain
191// a |genlmsghdr| after a |nlmsghdr|. These messages seem to all contain a
192// payload that consists of a list of structured attributes (it's possible that
193// some messages might have a genlmsghdr and a different kind of payload but I
194// haven't seen one, yet). The genlmsghdr contains a command id that, when
195// combined with the family_id (from the nlmsghdr), describes the ultimate use
196// for the netlink message.
197//
198// An attribute contains a header and a chunk of data. The header contains an
199// id which is an enumerated value that describes the use of the attribute's
200// data (the datatype of the attribute's data is implied by the attribute id)
201// and the length of the header+data in bytes. The attribute id is,
202// confusingly, called the type (or nla_type -- this is _not_ the data type of
203// the attribute). Each family defines the meaning of the nla_types in the
204// context of messages in that family (for example, the nla_type with the
205// value 3 will always mean the same thing for attributes in the same family).
206// EXCEPTION: Some attributes are nested (that is, they contain a list of other
207// attributes rather than a single value). Each nested attribute defines the
208// meaning of the nla_types in the context of attributes that are nested under
209// this attribute (for example, the nla_type with the value 3 will have a
210// different meaning when nested under another attribute -- that meaning is
211// defined by the attribute under which it is nested). Fun.
212//
213// The GenericNetlink messages look like this:
214//
215// -----+-----+-+-------------------------------------------------+-+--
216// ... | | | message payload | |
217// | | +------+-+----------------------------------------+ |
218// | nl | | | | attributes | |
219// | msg |p| genl |p+-----------+-+---------+-+--------+-----+p| ...
220// | hdr |a| msg |a| struct |p| attrib |p| struct | ... |a|
221// | |d| hdr |d| nlattr |a| payload |a| nlattr | |d|
222// | | | | | |d| |d| | | |
223// -----+-----+-+------+-+-----------+-+---------+-+--------+-----+-+--
224// | ^ | |
225// |<-NLA_HDRLEN->| | |
226// | +---nla_data()
227// |<----nla_attr_size---->| |
228// |<-----nla_total_size---->|
229
230class GenericNetlinkMessage : public NetlinkMessage {
231 public:
232 GenericNetlinkMessage(uint16_t my_message_type, uint8 command,
233 const char *command_string)
234 : NetlinkMessage(my_message_type),
235 attributes_(new AttributeList),
Wade Guthriebdcdaa72013-03-04 12:47:12 -0800236 command_(command),
Wade Guthrief48a1952013-03-04 17:33:47 -0800237 command_string_(command_string) {}
238 virtual ~GenericNetlinkMessage() {}
239
240 virtual ByteString Encode(uint32_t sequence_number, uint16_t nlmsg_type);
Wade Guthrie0d438532012-05-18 14:18:50 -0700241
Wade Guthriebdcdaa72013-03-04 12:47:12 -0800242 uint8 command() const { return command_; }
243 const char *command_string() const { return command_string_; }
244
Wade Guthrieefe1f0c2013-02-26 17:42:01 -0800245 AttributeListConstRefPtr const_attributes() const { return attributes_; }
246 AttributeListRefPtr attributes() { return attributes_; }
Wade Guthrie0d438532012-05-18 14:18:50 -0700247
Wade Guthrief48a1952013-03-04 17:33:47 -0800248 virtual void Print(int log_level) const;
249
250 protected:
251 // Returns a string of bytes representing _both_ an |nlmsghdr| and a
252 // |genlmsghdr|, filled-in, and its padding.
253 virtual ByteString EncodeHeader(uint32_t sequence_number,
254 uint16_t nlmsg_type);
255 // Reads the |nlmsghdr| and |genlmsghdr| headers and removes them from
256 // |input|.
257 virtual bool InitAndStripHeader(ByteString *input);
258
259 AttributeListRefPtr attributes_;
260 const uint8 command_;
261 const char *command_string_;
262
263 private:
264 DISALLOW_COPY_AND_ASSIGN(GenericNetlinkMessage);
265};
266
Wade Guthrie71872472013-03-05 10:33:38 -0800267// Control Messages
268
269class ControlNetlinkMessage : public GenericNetlinkMessage {
270 public:
271 static const uint16_t kMessageType;
272 ControlNetlinkMessage(uint8 command, const char *command_string)
273 : GenericNetlinkMessage(kMessageType, command, command_string) {}
274
275 virtual bool InitFromNlmsg(const nlmsghdr *msg);
276};
277
278class NewFamilyMessage : public ControlNetlinkMessage {
279 public:
280 static const uint8_t kCommand;
281 static const char kCommandString[];
282
283 NewFamilyMessage() : ControlNetlinkMessage(kCommand, kCommandString) {}
284
285 private:
286 DISALLOW_COPY_AND_ASSIGN(NewFamilyMessage);
287};
288
289class GetFamilyMessage : public ControlNetlinkMessage {
290 public:
291 static const uint8_t kCommand;
292 static const char kCommandString[];
293
294 GetFamilyMessage() : ControlNetlinkMessage(kCommand, kCommandString) {}
295
296 private:
297 DISALLOW_COPY_AND_ASSIGN(GetFamilyMessage);
298};
299
300
Wade Guthrief48a1952013-03-04 17:33:47 -0800301// Class for messages received from the mac80211 drivers by way of the
302// cfg80211 kernel module.
303class Nl80211Message : public GenericNetlinkMessage {
304 public:
305 static const char kMessageTypeString[];
306 static const unsigned int kEthernetAddressBytes;
307 static const char kBogusMacAddress[];
308
309 Nl80211Message(uint8 command, const char *command_string)
310 : GenericNetlinkMessage(nl80211_message_type_, command, command_string) {}
311 virtual ~Nl80211Message() {}
312
313 virtual bool InitFromNlmsg(const nlmsghdr *msg);
314
315 uint8 command() const { return command_; }
316 const char *command_string() const { return command_string_; }
317 uint16_t message_type() const { return message_type_; }
318 uint32_t sequence_number() const { return sequence_number_; }
319 void set_sequence_number(uint32_t seq) { sequence_number_ = seq; }
320
repo sync90ee0fa2012-12-18 10:08:08 -0800321 // TODO(wdg): This needs to be moved to AttributeMac.
Wade Guthrie0d438532012-05-18 14:18:50 -0700322 // Helper function to provide a string for a MAC address. If no attribute
323 // is found, this method returns 'false'. On any error with a non-NULL
324 // |value|, this method sets |value| to a bogus MAC address.
Wade Guthrie68da97c2013-02-26 13:09:35 -0800325 bool GetMacAttributeString(int id, std::string *value) const;
Wade Guthrie0d438532012-05-18 14:18:50 -0700326
repo sync90ee0fa2012-12-18 10:08:08 -0800327 // TODO(wdg): This needs to be moved to AttributeScanFrequencies.
Wade Guthrie0d438532012-05-18 14:18:50 -0700328 // Helper function to provide a vector of scan frequencies for attributes
329 // that contain them (such as NL80211_ATTR_SCAN_FREQUENCIES).
Wade Guthrie68da97c2013-02-26 13:09:35 -0800330 bool GetScanFrequenciesAttribute(int id, std::vector<uint32_t> *value) const;
Wade Guthrie0d438532012-05-18 14:18:50 -0700331
repo sync90ee0fa2012-12-18 10:08:08 -0800332 // TODO(wdg): This needs to be moved to AttributeScanSSids.
Wade Guthrie0d438532012-05-18 14:18:50 -0700333 // Helper function to provide a vector of SSIDs for attributes that contain
334 // them (such as NL80211_ATTR_SCAN_SSIDS).
Wade Guthrie68da97c2013-02-26 13:09:35 -0800335 bool GetScanSsidsAttribute(int id, std::vector<std::string> *value) const;
Wade Guthrie0d438532012-05-18 14:18:50 -0700336
repo sync90ee0fa2012-12-18 10:08:08 -0800337 // TODO(wdg): This needs to be moved to AttributeMac.
Wade Guthrie0d438532012-05-18 14:18:50 -0700338 // Stringizes the MAC address found in 'arg'. If there are problems (such
339 // as a NULL |arg|), |value| is set to a bogus MAC address.
340 static std::string StringFromMacAddress(const uint8_t *arg);
341
Wade Guthried4977f22012-08-22 12:37:54 -0700342 // Returns a string representing the passed-in |status| or |reason|, the
343 // value of which has been acquired from libnl (for example, from the
Wade Guthrie0d438532012-05-18 14:18:50 -0700344 // NL80211_ATTR_STATUS_CODE or NL80211_ATTR_REASON_CODE attribute).
Wade Guthried4977f22012-08-22 12:37:54 -0700345 static std::string StringFromReason(uint16_t reason);
Wade Guthrie0d438532012-05-18 14:18:50 -0700346 static std::string StringFromStatus(uint16_t status);
347
Wade Guthrie0d438532012-05-18 14:18:50 -0700348 private:
Wade Guthried4977f22012-08-22 12:37:54 -0700349 static std::map<uint16_t, std::string> *reason_code_string_;
350 static std::map<uint16_t, std::string> *status_code_string_;
Wade Guthrief48a1952013-03-04 17:33:47 -0800351 static uint16_t nl80211_message_type_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700352
repo syncdc085c82012-12-28 08:54:41 -0800353 DISALLOW_COPY_AND_ASSIGN(Nl80211Message);
Wade Guthrie0d438532012-05-18 14:18:50 -0700354};
355
356class Nl80211Frame {
357 public:
358 enum Type {
359 kAssocResponseFrameType = 0x10,
360 kReassocResponseFrameType = 0x30,
361 kAssocRequestFrameType = 0x00,
362 kReassocRequestFrameType = 0x20,
363 kAuthFrameType = 0xb0,
364 kDisassocFrameType = 0xa0,
365 kDeauthFrameType = 0xc0,
366 kIllegalFrameType = 0xff
367 };
368
repo syncd316eb72012-12-10 15:48:47 -0800369 explicit Nl80211Frame(const ByteString &init);
Wade Guthried4977f22012-08-22 12:37:54 -0700370 bool ToString(std::string *output) const;
371 bool IsEqual(const Nl80211Frame &other) const;
372 uint16_t reason() const { return reason_; }
373 uint16_t status() const { return status_; }
Wade Guthrie0d438532012-05-18 14:18:50 -0700374
375 private:
376 static const uint8_t kMinimumFrameByteCount;
377 static const uint8_t kFrameTypeMask;
378
379 std::string mac_from_;
380 std::string mac_to_;
381 uint8_t frame_type_;
Wade Guthried4977f22012-08-22 12:37:54 -0700382 uint16_t reason_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700383 uint16_t status_;
Wade Guthrie8343f7f2012-12-04 13:52:32 -0800384 ByteString frame_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700385
386 DISALLOW_COPY_AND_ASSIGN(Nl80211Frame);
387};
388
389//
repo syncdc085c82012-12-28 08:54:41 -0800390// Specific Nl80211Message types.
Wade Guthrie0d438532012-05-18 14:18:50 -0700391//
392
repo syncdc085c82012-12-28 08:54:41 -0800393class AssociateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700394 public:
395 static const uint8_t kCommand;
396 static const char kCommandString[];
397
repo syncdc085c82012-12-28 08:54:41 -0800398 AssociateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700399
Wade Guthrie0d438532012-05-18 14:18:50 -0700400 private:
401 DISALLOW_COPY_AND_ASSIGN(AssociateMessage);
402};
403
404
repo syncdc085c82012-12-28 08:54:41 -0800405class AuthenticateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700406 public:
407 static const uint8_t kCommand;
408 static const char kCommandString[];
409
repo syncdc085c82012-12-28 08:54:41 -0800410 AuthenticateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700411
Wade Guthrie0d438532012-05-18 14:18:50 -0700412 private:
413 DISALLOW_COPY_AND_ASSIGN(AuthenticateMessage);
414};
415
416
repo syncdc085c82012-12-28 08:54:41 -0800417class CancelRemainOnChannelMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700418 public:
419 static const uint8_t kCommand;
420 static const char kCommandString[];
421
Christopher Wiley764538d2012-11-09 10:58:23 -0800422 CancelRemainOnChannelMessage()
repo syncdc085c82012-12-28 08:54:41 -0800423 : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700424
Wade Guthrie0d438532012-05-18 14:18:50 -0700425 private:
426 DISALLOW_COPY_AND_ASSIGN(CancelRemainOnChannelMessage);
427};
428
429
repo syncdc085c82012-12-28 08:54:41 -0800430class ConnectMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700431 public:
432 static const uint8_t kCommand;
433 static const char kCommandString[];
434
repo syncdc085c82012-12-28 08:54:41 -0800435 ConnectMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700436
Wade Guthrie0d438532012-05-18 14:18:50 -0700437 private:
438 DISALLOW_COPY_AND_ASSIGN(ConnectMessage);
439};
440
441
repo syncdc085c82012-12-28 08:54:41 -0800442class DeauthenticateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700443 public:
444 static const uint8_t kCommand;
445 static const char kCommandString[];
446
repo syncdc085c82012-12-28 08:54:41 -0800447 DeauthenticateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700448
Wade Guthrie0d438532012-05-18 14:18:50 -0700449 private:
450 DISALLOW_COPY_AND_ASSIGN(DeauthenticateMessage);
451};
452
453
repo syncdc085c82012-12-28 08:54:41 -0800454class DeleteStationMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700455 public:
456 static const uint8_t kCommand;
457 static const char kCommandString[];
458
repo syncdc085c82012-12-28 08:54:41 -0800459 DeleteStationMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700460
Wade Guthrie0d438532012-05-18 14:18:50 -0700461 private:
462 DISALLOW_COPY_AND_ASSIGN(DeleteStationMessage);
463};
464
465
repo syncdc085c82012-12-28 08:54:41 -0800466class DisassociateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700467 public:
468 static const uint8_t kCommand;
469 static const char kCommandString[];
470
repo syncdc085c82012-12-28 08:54:41 -0800471 DisassociateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700472
Wade Guthrie0d438532012-05-18 14:18:50 -0700473 private:
474 DISALLOW_COPY_AND_ASSIGN(DisassociateMessage);
475};
476
477
repo syncdc085c82012-12-28 08:54:41 -0800478class DisconnectMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700479 public:
480 static const uint8_t kCommand;
481 static const char kCommandString[];
482
repo syncdc085c82012-12-28 08:54:41 -0800483 DisconnectMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700484
Wade Guthrie0d438532012-05-18 14:18:50 -0700485 private:
486 DISALLOW_COPY_AND_ASSIGN(DisconnectMessage);
487};
488
489
repo syncdc085c82012-12-28 08:54:41 -0800490class FrameTxStatusMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700491 public:
492 static const uint8_t kCommand;
493 static const char kCommandString[];
494
repo syncdc085c82012-12-28 08:54:41 -0800495 FrameTxStatusMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700496
Wade Guthrie0d438532012-05-18 14:18:50 -0700497 private:
498 DISALLOW_COPY_AND_ASSIGN(FrameTxStatusMessage);
499};
500
repo sync0efa9f02012-12-28 13:40:20 -0800501class GetRegMessage : public Nl80211Message {
502 public:
503 static const uint8_t kCommand;
504 static const char kCommandString[];
505
506 GetRegMessage() : Nl80211Message(kCommand, kCommandString) {}
507
508 private:
509 DISALLOW_COPY_AND_ASSIGN(GetRegMessage);
510};
511
Wade Guthrie0d438532012-05-18 14:18:50 -0700512
repo syncdc085c82012-12-28 08:54:41 -0800513class JoinIbssMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700514 public:
515 static const uint8_t kCommand;
516 static const char kCommandString[];
517
repo syncdc085c82012-12-28 08:54:41 -0800518 JoinIbssMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700519
Wade Guthrie0d438532012-05-18 14:18:50 -0700520 private:
521 DISALLOW_COPY_AND_ASSIGN(JoinIbssMessage);
522};
523
524
repo syncdc085c82012-12-28 08:54:41 -0800525class MichaelMicFailureMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700526 public:
527 static const uint8_t kCommand;
528 static const char kCommandString[];
529
repo syncdc085c82012-12-28 08:54:41 -0800530 MichaelMicFailureMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700531
Wade Guthrie0d438532012-05-18 14:18:50 -0700532 private:
533 DISALLOW_COPY_AND_ASSIGN(MichaelMicFailureMessage);
534};
535
536
repo syncdc085c82012-12-28 08:54:41 -0800537class NewScanResultsMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700538 public:
539 static const uint8_t kCommand;
540 static const char kCommandString[];
541
repo syncdc085c82012-12-28 08:54:41 -0800542 NewScanResultsMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700543
Wade Guthrie0d438532012-05-18 14:18:50 -0700544 private:
545 DISALLOW_COPY_AND_ASSIGN(NewScanResultsMessage);
546};
547
548
repo syncdc085c82012-12-28 08:54:41 -0800549class NewStationMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700550 public:
551 static const uint8_t kCommand;
552 static const char kCommandString[];
553
repo syncdc085c82012-12-28 08:54:41 -0800554 NewStationMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700555
Wade Guthrie0d438532012-05-18 14:18:50 -0700556 private:
557 DISALLOW_COPY_AND_ASSIGN(NewStationMessage);
558};
559
560
repo syncdc085c82012-12-28 08:54:41 -0800561class NewWifiMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700562 public:
563 static const uint8_t kCommand;
564 static const char kCommandString[];
565
repo syncdc085c82012-12-28 08:54:41 -0800566 NewWifiMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700567
Wade Guthrie0d438532012-05-18 14:18:50 -0700568 private:
569 DISALLOW_COPY_AND_ASSIGN(NewWifiMessage);
570};
571
572
repo syncdc085c82012-12-28 08:54:41 -0800573class NotifyCqmMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700574 public:
575 static const uint8_t kCommand;
576 static const char kCommandString[];
577
repo syncdc085c82012-12-28 08:54:41 -0800578 NotifyCqmMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700579
Wade Guthrie0d438532012-05-18 14:18:50 -0700580 private:
581 DISALLOW_COPY_AND_ASSIGN(NotifyCqmMessage);
582};
583
584
repo syncdc085c82012-12-28 08:54:41 -0800585class PmksaCandidateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700586 public:
587 static const uint8_t kCommand;
588 static const char kCommandString[];
589
repo syncdc085c82012-12-28 08:54:41 -0800590 PmksaCandidateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700591
Wade Guthrie0d438532012-05-18 14:18:50 -0700592 private:
593 DISALLOW_COPY_AND_ASSIGN(PmksaCandidateMessage);
594};
595
596
repo syncdc085c82012-12-28 08:54:41 -0800597class RegBeaconHintMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700598 public:
599 static const uint8_t kCommand;
600 static const char kCommandString[];
601
repo syncdc085c82012-12-28 08:54:41 -0800602 RegBeaconHintMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700603
Wade Guthrie0d438532012-05-18 14:18:50 -0700604 private:
Wade Guthrie0d438532012-05-18 14:18:50 -0700605 DISALLOW_COPY_AND_ASSIGN(RegBeaconHintMessage);
606};
607
608
repo syncdc085c82012-12-28 08:54:41 -0800609class RegChangeMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700610 public:
611 static const uint8_t kCommand;
612 static const char kCommandString[];
613
repo syncdc085c82012-12-28 08:54:41 -0800614 RegChangeMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700615
Wade Guthrie0d438532012-05-18 14:18:50 -0700616 private:
617 DISALLOW_COPY_AND_ASSIGN(RegChangeMessage);
618};
619
620
repo syncdc085c82012-12-28 08:54:41 -0800621class RemainOnChannelMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700622 public:
623 static const uint8_t kCommand;
624 static const char kCommandString[];
625
repo syncdc085c82012-12-28 08:54:41 -0800626 RemainOnChannelMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700627
Wade Guthrie0d438532012-05-18 14:18:50 -0700628 private:
629 DISALLOW_COPY_AND_ASSIGN(RemainOnChannelMessage);
630};
631
632
repo syncdc085c82012-12-28 08:54:41 -0800633class RoamMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700634 public:
635 static const uint8_t kCommand;
636 static const char kCommandString[];
637
repo syncdc085c82012-12-28 08:54:41 -0800638 RoamMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700639
Wade Guthrie0d438532012-05-18 14:18:50 -0700640 private:
641 DISALLOW_COPY_AND_ASSIGN(RoamMessage);
642};
643
644
repo syncdc085c82012-12-28 08:54:41 -0800645class ScanAbortedMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700646 public:
647 static const uint8_t kCommand;
648 static const char kCommandString[];
649
repo syncdc085c82012-12-28 08:54:41 -0800650 ScanAbortedMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700651
Wade Guthrie0d438532012-05-18 14:18:50 -0700652 private:
653 DISALLOW_COPY_AND_ASSIGN(ScanAbortedMessage);
654};
655
656
Wade Guthrie71872472013-03-05 10:33:38 -0800657class GetScanMessage : public Nl80211Message {
658 public:
659 static const uint8_t kCommand;
660 static const char kCommandString[];
661
662 GetScanMessage() : Nl80211Message(kCommand, kCommandString) {}
663
664 private:
665 DISALLOW_COPY_AND_ASSIGN(GetScanMessage);
666};
667
668
repo syncdc085c82012-12-28 08:54:41 -0800669class TriggerScanMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700670 public:
671 static const uint8_t kCommand;
672 static const char kCommandString[];
673
repo syncdc085c82012-12-28 08:54:41 -0800674 TriggerScanMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700675
Wade Guthrie0d438532012-05-18 14:18:50 -0700676 private:
677 DISALLOW_COPY_AND_ASSIGN(TriggerScanMessage);
678};
679
680
repo syncdc085c82012-12-28 08:54:41 -0800681class UnknownMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700682 public:
Christopher Wiley764538d2012-11-09 10:58:23 -0800683 explicit UnknownMessage(uint8_t command)
repo syncdc085c82012-12-28 08:54:41 -0800684 : Nl80211Message(command, kCommandString),
Christopher Wiley764538d2012-11-09 10:58:23 -0800685 command_(command) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700686
687 static const uint8_t kCommand;
688 static const char kCommandString[];
689
Wade Guthrie0d438532012-05-18 14:18:50 -0700690 private:
691 uint8_t command_;
692
693 DISALLOW_COPY_AND_ASSIGN(UnknownMessage);
694};
695
696
repo syncdc085c82012-12-28 08:54:41 -0800697class UnprotDeauthenticateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700698 public:
699 static const uint8_t kCommand;
700 static const char kCommandString[];
701
Christopher Wiley764538d2012-11-09 10:58:23 -0800702 UnprotDeauthenticateMessage()
repo syncdc085c82012-12-28 08:54:41 -0800703 : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700704
Wade Guthrie0d438532012-05-18 14:18:50 -0700705 private:
706 DISALLOW_COPY_AND_ASSIGN(UnprotDeauthenticateMessage);
707};
708
709
repo syncdc085c82012-12-28 08:54:41 -0800710class UnprotDisassociateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700711 public:
712 static const uint8_t kCommand;
713 static const char kCommandString[];
714
repo syncdc085c82012-12-28 08:54:41 -0800715 UnprotDisassociateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700716
Wade Guthrie0d438532012-05-18 14:18:50 -0700717 private:
718 DISALLOW_COPY_AND_ASSIGN(UnprotDisassociateMessage);
719};
720
721
722//
723// Factory class.
724//
725
Wade Guthrief48a1952013-03-04 17:33:47 -0800726class NetlinkMessageFactory {
Wade Guthrie0d438532012-05-18 14:18:50 -0700727 public:
728 // Ownership of the message is passed to the caller and, as such, he should
729 // delete it.
Wade Guthrief48a1952013-03-04 17:33:47 -0800730 static NetlinkMessage *CreateMessage(nlmsghdr *msg);
731 // TODO(wdg): Need a way for a class to register a callback and a message
732 // type. That way, CreateMessage can call the appropriate factory based on
733 // the incoming message type.
Wade Guthrie0d438532012-05-18 14:18:50 -0700734
735 private:
Wade Guthrief48a1952013-03-04 17:33:47 -0800736 DISALLOW_COPY_AND_ASSIGN(NetlinkMessageFactory);
Wade Guthrie0d438532012-05-18 14:18:50 -0700737};
738
739
repo syncdc085c82012-12-28 08:54:41 -0800740// Nl80211MessageDataCollector - this class is used to collect data to be
Wade Guthrie0d438532012-05-18 14:18:50 -0700741// used for unit tests. It is only invoked in this case.
742
repo syncdc085c82012-12-28 08:54:41 -0800743class Nl80211MessageDataCollector {
Wade Guthrie0d438532012-05-18 14:18:50 -0700744 public:
repo syncdc085c82012-12-28 08:54:41 -0800745 static Nl80211MessageDataCollector *GetInstance();
Wade Guthrie0d438532012-05-18 14:18:50 -0700746
repo syncdc085c82012-12-28 08:54:41 -0800747 void CollectDebugData(const Nl80211Message &message, nlmsghdr *msg);
Wade Guthrie0d438532012-05-18 14:18:50 -0700748
749 protected:
750 friend struct
repo syncdc085c82012-12-28 08:54:41 -0800751 base::DefaultLazyInstanceTraits<Nl80211MessageDataCollector>;
Wade Guthrie0d438532012-05-18 14:18:50 -0700752
repo syncdc085c82012-12-28 08:54:41 -0800753 explicit Nl80211MessageDataCollector();
Wade Guthrie0d438532012-05-18 14:18:50 -0700754
755 private:
756 // In order to limit the output from this class, I keep track of types I
757 // haven't yet printed.
758 std::map<uint8_t, bool> need_to_print;
repo syncdc085c82012-12-28 08:54:41 -0800759
760 DISALLOW_COPY_AND_ASSIGN(Nl80211MessageDataCollector);
Wade Guthrie0d438532012-05-18 14:18:50 -0700761};
762
763} // namespace shill
764
765#endif // SHILL_USER_BOUND_NLMESSAGE_H_