blob: 6edbdf0a5896b73f7e7f79172a33cd9a6945c577 [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
Wade Guthriebee87c22013-03-06 11:00:46 -080067// message_type along with the sting to Config80211::GetFamily:
Wade Guthrief48a1952013-03-04 17:33:47 -080068//
Wade Guthriebee87c22013-03-06 11:00:46 -080069// nl80211_type = config80211_->GetFamily(Nl80211Message::kMessageType);
Wade Guthrief48a1952013-03-04 17:33:47 -080070//
71// Do all of this before you start to create NetlinkMessages so that
72// NetlinkMessage can be instantiated with a valid |message_type_|.
73
74class NetlinkMessage {
Wade Guthrie0d438532012-05-18 14:18:50 -070075 public:
Wade Guthriebdcdaa72013-03-04 12:47:12 -080076 static const uint32_t kBroadcastSequenceNumber;
77 static const uint16_t kIllegalMessageType;
Wade Guthrie0d438532012-05-18 14:18:50 -070078
Wade Guthrief48a1952013-03-04 17:33:47 -080079 explicit NetlinkMessage(uint16_t message_type) :
80 flags_(0), message_type_(message_type),
81 sequence_number_(kBroadcastSequenceNumber) {}
82 virtual ~NetlinkMessage() {}
83
84 // Returns a string of bytes representing the message (with it headers) and
85 // any necessary padding. These bytes are appropriately formatted to be
86 // written to a netlink socket.
Wade Guthriebee87c22013-03-06 11:00:46 -080087 virtual ByteString Encode(uint32_t sequence_number) = 0;
Wade Guthrief48a1952013-03-04 17:33:47 -080088
89 // Initializes the |NetlinkMessage| from a complete and legal message
90 // (potentially received from the kernel via a netlink socket).
91 virtual bool InitFromNlmsg(const nlmsghdr *msg);
92
93 uint16_t message_type() const { return message_type_; }
94 void AddFlag(uint16_t new_flag) { flags_ |= new_flag; }
95 uint16_t flags() const { return flags_; }
96 uint32_t sequence_number() const { return sequence_number_; }
97 virtual void Print(int log_level) const = 0;
98
99 // Logs the message's raw bytes (with minimal interpretation).
100 static void PrintBytes(int log_level, const unsigned char *buf,
101 size_t num_bytes);
102
103 protected:
104 friend class Config80211Test;
105 FRIEND_TEST(Config80211Test, NL80211_CMD_NOTIFY_CQM);
106
107 // Returns a string of bytes representing an |nlmsghdr|, filled-in, and its
108 // padding.
Wade Guthriebee87c22013-03-06 11:00:46 -0800109 virtual ByteString EncodeHeader(uint32_t sequence_number);
Wade Guthrief48a1952013-03-04 17:33:47 -0800110 // Reads the |nlmsghdr| and removes it from |input|.
111 virtual bool InitAndStripHeader(ByteString *input);
112
113 uint16_t flags_;
114 uint16_t message_type_;
115 uint32_t sequence_number_;
116
117 private:
118 DISALLOW_COPY_AND_ASSIGN(NetlinkMessage);
119};
120
Wade Guthrie71872472013-03-05 10:33:38 -0800121
122// The Error and Ack messages are received from the kernel and are combined,
123// here, because they look so much alike (the only difference is that the
124// error code is 0 for the Ack messages). Error messages are received from
125// the kernel in response to a sent message when there's a problem (such as
126// a malformed message or a busy kernel module). Ack messages are received
127// from the kernel when a sent message has the NLM_F_ACK flag set, indicating
128// that an Ack is requested.
129class ErrorAckMessage : public NetlinkMessage {
130 public:
131 static const uint16_t kMessageType;
132
133 ErrorAckMessage() : NetlinkMessage(kMessageType), error_(0) {}
134 virtual bool InitFromNlmsg(const nlmsghdr *const_msg);
Wade Guthriebee87c22013-03-06 11:00:46 -0800135 virtual ByteString Encode(uint32_t sequence_number);
Wade Guthrie71872472013-03-05 10:33:38 -0800136 virtual void Print(int log_level) const;
137 std::string ToString() const;
138 uint32_t error() const { return -error_; }
139
140 private:
141 uint32_t error_;
142
143 DISALLOW_COPY_AND_ASSIGN(ErrorAckMessage);
144};
145
146
147class NoopMessage : public NetlinkMessage {
148 public:
149 static const uint16_t kMessageType;
150
151 NoopMessage() : NetlinkMessage(kMessageType) {}
Wade Guthriebee87c22013-03-06 11:00:46 -0800152 virtual ByteString Encode(uint32_t sequence_number);
Wade Guthrie71872472013-03-05 10:33:38 -0800153 virtual void Print(int log_level) const;
154 std::string ToString() const { return "<NOOP>"; }
155
156 private:
157 DISALLOW_COPY_AND_ASSIGN(NoopMessage);
158};
159
160
161class DoneMessage : public NetlinkMessage {
162 public:
163 static const uint16_t kMessageType;
164
165 DoneMessage() : NetlinkMessage(kMessageType) {}
Wade Guthriebee87c22013-03-06 11:00:46 -0800166 virtual ByteString Encode(uint32_t sequence_number);
Wade Guthrie71872472013-03-05 10:33:38 -0800167 virtual void Print(int log_level) const;
168 std::string ToString() const { return "<DONE with multipart message>"; }
169
170 private:
171 DISALLOW_COPY_AND_ASSIGN(DoneMessage);
172};
173
174
175class OverrunMessage : public NetlinkMessage {
176 public:
177 static const uint16_t kMessageType;
178
179 OverrunMessage() : NetlinkMessage(kMessageType) {}
Wade Guthriebee87c22013-03-06 11:00:46 -0800180 virtual ByteString Encode(uint32_t sequence_number);
Wade Guthrie71872472013-03-05 10:33:38 -0800181 virtual void Print(int log_level) const;
182 std::string ToString() const { return "<OVERRUN - data lost>"; }
183
184 private:
185 DISALLOW_COPY_AND_ASSIGN(OverrunMessage);
186};
187
Wade Guthrief48a1952013-03-04 17:33:47 -0800188// Objects of the |GenericNetlinkMessage| type represent messages that contain
189// a |genlmsghdr| after a |nlmsghdr|. These messages seem to all contain a
190// payload that consists of a list of structured attributes (it's possible that
191// some messages might have a genlmsghdr and a different kind of payload but I
192// haven't seen one, yet). The genlmsghdr contains a command id that, when
193// combined with the family_id (from the nlmsghdr), describes the ultimate use
194// for the netlink message.
195//
196// An attribute contains a header and a chunk of data. The header contains an
197// id which is an enumerated value that describes the use of the attribute's
198// data (the datatype of the attribute's data is implied by the attribute id)
199// and the length of the header+data in bytes. The attribute id is,
200// confusingly, called the type (or nla_type -- this is _not_ the data type of
201// the attribute). Each family defines the meaning of the nla_types in the
202// context of messages in that family (for example, the nla_type with the
203// value 3 will always mean the same thing for attributes in the same family).
204// EXCEPTION: Some attributes are nested (that is, they contain a list of other
205// attributes rather than a single value). Each nested attribute defines the
206// meaning of the nla_types in the context of attributes that are nested under
207// this attribute (for example, the nla_type with the value 3 will have a
208// different meaning when nested under another attribute -- that meaning is
209// defined by the attribute under which it is nested). Fun.
210//
211// The GenericNetlink messages look like this:
212//
213// -----+-----+-+-------------------------------------------------+-+--
214// ... | | | message payload | |
215// | | +------+-+----------------------------------------+ |
216// | nl | | | | attributes | |
217// | msg |p| genl |p+-----------+-+---------+-+--------+-----+p| ...
218// | hdr |a| msg |a| struct |p| attrib |p| struct | ... |a|
219// | |d| hdr |d| nlattr |a| payload |a| nlattr | |d|
220// | | | | | |d| |d| | | |
221// -----+-----+-+------+-+-----------+-+---------+-+--------+-----+-+--
222// | ^ | |
223// |<-NLA_HDRLEN->| | |
224// | +---nla_data()
225// |<----nla_attr_size---->| |
226// |<-----nla_total_size---->|
227
228class GenericNetlinkMessage : public NetlinkMessage {
229 public:
230 GenericNetlinkMessage(uint16_t my_message_type, uint8 command,
231 const char *command_string)
232 : NetlinkMessage(my_message_type),
233 attributes_(new AttributeList),
Wade Guthriebdcdaa72013-03-04 12:47:12 -0800234 command_(command),
Wade Guthrief48a1952013-03-04 17:33:47 -0800235 command_string_(command_string) {}
236 virtual ~GenericNetlinkMessage() {}
237
Wade Guthriebee87c22013-03-06 11:00:46 -0800238 virtual ByteString Encode(uint32_t sequence_number);
Wade Guthrie0d438532012-05-18 14:18:50 -0700239
Wade Guthriebdcdaa72013-03-04 12:47:12 -0800240 uint8 command() const { return command_; }
241 const char *command_string() const { return command_string_; }
Wade Guthrieefe1f0c2013-02-26 17:42:01 -0800242 AttributeListConstRefPtr const_attributes() const { return attributes_; }
243 AttributeListRefPtr attributes() { return attributes_; }
Wade Guthrie0d438532012-05-18 14:18:50 -0700244
Wade Guthrief48a1952013-03-04 17:33:47 -0800245 virtual void Print(int log_level) const;
246
247 protected:
248 // Returns a string of bytes representing _both_ an |nlmsghdr| and a
249 // |genlmsghdr|, filled-in, and its padding.
Wade Guthriebee87c22013-03-06 11:00:46 -0800250 virtual ByteString EncodeHeader(uint32_t sequence_number);
Wade Guthrief48a1952013-03-04 17:33:47 -0800251 // Reads the |nlmsghdr| and |genlmsghdr| headers and removes them from
252 // |input|.
253 virtual bool InitAndStripHeader(ByteString *input);
254
255 AttributeListRefPtr attributes_;
256 const uint8 command_;
257 const char *command_string_;
258
259 private:
260 DISALLOW_COPY_AND_ASSIGN(GenericNetlinkMessage);
261};
262
Wade Guthrie71872472013-03-05 10:33:38 -0800263// Control Messages
264
265class ControlNetlinkMessage : public GenericNetlinkMessage {
266 public:
267 static const uint16_t kMessageType;
268 ControlNetlinkMessage(uint8 command, const char *command_string)
269 : GenericNetlinkMessage(kMessageType, command, command_string) {}
270
271 virtual bool InitFromNlmsg(const nlmsghdr *msg);
272};
273
274class NewFamilyMessage : public ControlNetlinkMessage {
275 public:
276 static const uint8_t kCommand;
277 static const char kCommandString[];
278
279 NewFamilyMessage() : ControlNetlinkMessage(kCommand, kCommandString) {}
280
281 private:
282 DISALLOW_COPY_AND_ASSIGN(NewFamilyMessage);
283};
284
285class GetFamilyMessage : public ControlNetlinkMessage {
286 public:
287 static const uint8_t kCommand;
288 static const char kCommandString[];
289
290 GetFamilyMessage() : ControlNetlinkMessage(kCommand, kCommandString) {}
291
292 private:
293 DISALLOW_COPY_AND_ASSIGN(GetFamilyMessage);
294};
295
296
Wade Guthrief48a1952013-03-04 17:33:47 -0800297// Class for messages received from the mac80211 drivers by way of the
298// cfg80211 kernel module.
299class Nl80211Message : public GenericNetlinkMessage {
300 public:
301 static const char kMessageTypeString[];
302 static const unsigned int kEthernetAddressBytes;
303 static const char kBogusMacAddress[];
304
305 Nl80211Message(uint8 command, const char *command_string)
306 : GenericNetlinkMessage(nl80211_message_type_, command, command_string) {}
307 virtual ~Nl80211Message() {}
308
Wade Guthriebee87c22013-03-06 11:00:46 -0800309 // Sets the family_id / message_type for all Nl80211 messages.
310 static void SetMessageType(uint16_t message_type);
311
Wade Guthrief48a1952013-03-04 17:33:47 -0800312 virtual bool InitFromNlmsg(const nlmsghdr *msg);
313
314 uint8 command() const { return command_; }
315 const char *command_string() const { return command_string_; }
316 uint16_t message_type() const { return message_type_; }
317 uint32_t sequence_number() const { return sequence_number_; }
318 void set_sequence_number(uint32_t seq) { sequence_number_ = seq; }
319
repo sync90ee0fa2012-12-18 10:08:08 -0800320 // TODO(wdg): This needs to be moved to AttributeMac.
Wade Guthrie0d438532012-05-18 14:18:50 -0700321 // Helper function to provide a string for a MAC address. If no attribute
322 // is found, this method returns 'false'. On any error with a non-NULL
323 // |value|, this method sets |value| to a bogus MAC address.
Wade Guthrie68da97c2013-02-26 13:09:35 -0800324 bool GetMacAttributeString(int id, std::string *value) const;
Wade Guthrie0d438532012-05-18 14:18:50 -0700325
repo sync90ee0fa2012-12-18 10:08:08 -0800326 // TODO(wdg): This needs to be moved to AttributeScanFrequencies.
Wade Guthrie0d438532012-05-18 14:18:50 -0700327 // Helper function to provide a vector of scan frequencies for attributes
328 // that contain them (such as NL80211_ATTR_SCAN_FREQUENCIES).
Wade Guthrie68da97c2013-02-26 13:09:35 -0800329 bool GetScanFrequenciesAttribute(int id, std::vector<uint32_t> *value) const;
Wade Guthrie0d438532012-05-18 14:18:50 -0700330
repo sync90ee0fa2012-12-18 10:08:08 -0800331 // TODO(wdg): This needs to be moved to AttributeScanSSids.
Wade Guthrie0d438532012-05-18 14:18:50 -0700332 // Helper function to provide a vector of SSIDs for attributes that contain
333 // them (such as NL80211_ATTR_SCAN_SSIDS).
Wade Guthrie68da97c2013-02-26 13:09:35 -0800334 bool GetScanSsidsAttribute(int id, std::vector<std::string> *value) const;
Wade Guthrie0d438532012-05-18 14:18:50 -0700335
repo sync90ee0fa2012-12-18 10:08:08 -0800336 // TODO(wdg): This needs to be moved to AttributeMac.
Wade Guthrie0d438532012-05-18 14:18:50 -0700337 // Stringizes the MAC address found in 'arg'. If there are problems (such
338 // as a NULL |arg|), |value| is set to a bogus MAC address.
339 static std::string StringFromMacAddress(const uint8_t *arg);
340
Wade Guthried4977f22012-08-22 12:37:54 -0700341 // Returns a string representing the passed-in |status| or |reason|, the
342 // value of which has been acquired from libnl (for example, from the
Wade Guthrie0d438532012-05-18 14:18:50 -0700343 // NL80211_ATTR_STATUS_CODE or NL80211_ATTR_REASON_CODE attribute).
Wade Guthried4977f22012-08-22 12:37:54 -0700344 static std::string StringFromReason(uint16_t reason);
Wade Guthrie0d438532012-05-18 14:18:50 -0700345 static std::string StringFromStatus(uint16_t status);
346
Wade Guthrie0d438532012-05-18 14:18:50 -0700347 private:
Wade Guthried4977f22012-08-22 12:37:54 -0700348 static std::map<uint16_t, std::string> *reason_code_string_;
349 static std::map<uint16_t, std::string> *status_code_string_;
Wade Guthrief48a1952013-03-04 17:33:47 -0800350 static uint16_t nl80211_message_type_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700351
repo syncdc085c82012-12-28 08:54:41 -0800352 DISALLOW_COPY_AND_ASSIGN(Nl80211Message);
Wade Guthrie0d438532012-05-18 14:18:50 -0700353};
354
355class Nl80211Frame {
356 public:
357 enum Type {
358 kAssocResponseFrameType = 0x10,
359 kReassocResponseFrameType = 0x30,
360 kAssocRequestFrameType = 0x00,
361 kReassocRequestFrameType = 0x20,
362 kAuthFrameType = 0xb0,
363 kDisassocFrameType = 0xa0,
364 kDeauthFrameType = 0xc0,
365 kIllegalFrameType = 0xff
366 };
367
repo syncd316eb72012-12-10 15:48:47 -0800368 explicit Nl80211Frame(const ByteString &init);
Wade Guthried4977f22012-08-22 12:37:54 -0700369 bool ToString(std::string *output) const;
370 bool IsEqual(const Nl80211Frame &other) const;
371 uint16_t reason() const { return reason_; }
372 uint16_t status() const { return status_; }
Wade Guthrie0d438532012-05-18 14:18:50 -0700373
374 private:
375 static const uint8_t kMinimumFrameByteCount;
376 static const uint8_t kFrameTypeMask;
377
378 std::string mac_from_;
379 std::string mac_to_;
380 uint8_t frame_type_;
Wade Guthried4977f22012-08-22 12:37:54 -0700381 uint16_t reason_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700382 uint16_t status_;
Wade Guthrie8343f7f2012-12-04 13:52:32 -0800383 ByteString frame_;
Wade Guthrie0d438532012-05-18 14:18:50 -0700384
385 DISALLOW_COPY_AND_ASSIGN(Nl80211Frame);
386};
387
388//
repo syncdc085c82012-12-28 08:54:41 -0800389// Specific Nl80211Message types.
Wade Guthrie0d438532012-05-18 14:18:50 -0700390//
391
repo syncdc085c82012-12-28 08:54:41 -0800392class AssociateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700393 public:
394 static const uint8_t kCommand;
395 static const char kCommandString[];
396
repo syncdc085c82012-12-28 08:54:41 -0800397 AssociateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700398
Wade Guthrie0d438532012-05-18 14:18:50 -0700399 private:
400 DISALLOW_COPY_AND_ASSIGN(AssociateMessage);
401};
402
403
repo syncdc085c82012-12-28 08:54:41 -0800404class AuthenticateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700405 public:
406 static const uint8_t kCommand;
407 static const char kCommandString[];
408
repo syncdc085c82012-12-28 08:54:41 -0800409 AuthenticateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700410
Wade Guthrie0d438532012-05-18 14:18:50 -0700411 private:
412 DISALLOW_COPY_AND_ASSIGN(AuthenticateMessage);
413};
414
415
repo syncdc085c82012-12-28 08:54:41 -0800416class CancelRemainOnChannelMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700417 public:
418 static const uint8_t kCommand;
419 static const char kCommandString[];
420
Christopher Wiley764538d2012-11-09 10:58:23 -0800421 CancelRemainOnChannelMessage()
repo syncdc085c82012-12-28 08:54:41 -0800422 : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700423
Wade Guthrie0d438532012-05-18 14:18:50 -0700424 private:
425 DISALLOW_COPY_AND_ASSIGN(CancelRemainOnChannelMessage);
426};
427
428
repo syncdc085c82012-12-28 08:54:41 -0800429class ConnectMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700430 public:
431 static const uint8_t kCommand;
432 static const char kCommandString[];
433
repo syncdc085c82012-12-28 08:54:41 -0800434 ConnectMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700435
Wade Guthrie0d438532012-05-18 14:18:50 -0700436 private:
437 DISALLOW_COPY_AND_ASSIGN(ConnectMessage);
438};
439
440
repo syncdc085c82012-12-28 08:54:41 -0800441class DeauthenticateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700442 public:
443 static const uint8_t kCommand;
444 static const char kCommandString[];
445
repo syncdc085c82012-12-28 08:54:41 -0800446 DeauthenticateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700447
Wade Guthrie0d438532012-05-18 14:18:50 -0700448 private:
449 DISALLOW_COPY_AND_ASSIGN(DeauthenticateMessage);
450};
451
452
repo syncdc085c82012-12-28 08:54:41 -0800453class DeleteStationMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700454 public:
455 static const uint8_t kCommand;
456 static const char kCommandString[];
457
repo syncdc085c82012-12-28 08:54:41 -0800458 DeleteStationMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700459
Wade Guthrie0d438532012-05-18 14:18:50 -0700460 private:
461 DISALLOW_COPY_AND_ASSIGN(DeleteStationMessage);
462};
463
464
repo syncdc085c82012-12-28 08:54:41 -0800465class DisassociateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700466 public:
467 static const uint8_t kCommand;
468 static const char kCommandString[];
469
repo syncdc085c82012-12-28 08:54:41 -0800470 DisassociateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700471
Wade Guthrie0d438532012-05-18 14:18:50 -0700472 private:
473 DISALLOW_COPY_AND_ASSIGN(DisassociateMessage);
474};
475
476
repo syncdc085c82012-12-28 08:54:41 -0800477class DisconnectMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700478 public:
479 static const uint8_t kCommand;
480 static const char kCommandString[];
481
repo syncdc085c82012-12-28 08:54:41 -0800482 DisconnectMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700483
Wade Guthrie0d438532012-05-18 14:18:50 -0700484 private:
485 DISALLOW_COPY_AND_ASSIGN(DisconnectMessage);
486};
487
488
repo syncdc085c82012-12-28 08:54:41 -0800489class FrameTxStatusMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700490 public:
491 static const uint8_t kCommand;
492 static const char kCommandString[];
493
repo syncdc085c82012-12-28 08:54:41 -0800494 FrameTxStatusMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700495
Wade Guthrie0d438532012-05-18 14:18:50 -0700496 private:
497 DISALLOW_COPY_AND_ASSIGN(FrameTxStatusMessage);
498};
499
repo sync0efa9f02012-12-28 13:40:20 -0800500class GetRegMessage : public Nl80211Message {
501 public:
502 static const uint8_t kCommand;
503 static const char kCommandString[];
504
505 GetRegMessage() : Nl80211Message(kCommand, kCommandString) {}
506
507 private:
508 DISALLOW_COPY_AND_ASSIGN(GetRegMessage);
509};
510
Wade Guthrie0d438532012-05-18 14:18:50 -0700511
repo syncdc085c82012-12-28 08:54:41 -0800512class JoinIbssMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700513 public:
514 static const uint8_t kCommand;
515 static const char kCommandString[];
516
repo syncdc085c82012-12-28 08:54:41 -0800517 JoinIbssMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700518
Wade Guthrie0d438532012-05-18 14:18:50 -0700519 private:
520 DISALLOW_COPY_AND_ASSIGN(JoinIbssMessage);
521};
522
523
repo syncdc085c82012-12-28 08:54:41 -0800524class MichaelMicFailureMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700525 public:
526 static const uint8_t kCommand;
527 static const char kCommandString[];
528
repo syncdc085c82012-12-28 08:54:41 -0800529 MichaelMicFailureMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700530
Wade Guthrie0d438532012-05-18 14:18:50 -0700531 private:
532 DISALLOW_COPY_AND_ASSIGN(MichaelMicFailureMessage);
533};
534
535
repo syncdc085c82012-12-28 08:54:41 -0800536class NewScanResultsMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700537 public:
538 static const uint8_t kCommand;
539 static const char kCommandString[];
540
repo syncdc085c82012-12-28 08:54:41 -0800541 NewScanResultsMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700542
Wade Guthrie0d438532012-05-18 14:18:50 -0700543 private:
544 DISALLOW_COPY_AND_ASSIGN(NewScanResultsMessage);
545};
546
547
repo syncdc085c82012-12-28 08:54:41 -0800548class NewStationMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700549 public:
550 static const uint8_t kCommand;
551 static const char kCommandString[];
552
repo syncdc085c82012-12-28 08:54:41 -0800553 NewStationMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700554
Wade Guthrie0d438532012-05-18 14:18:50 -0700555 private:
556 DISALLOW_COPY_AND_ASSIGN(NewStationMessage);
557};
558
559
repo syncdc085c82012-12-28 08:54:41 -0800560class NewWifiMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700561 public:
562 static const uint8_t kCommand;
563 static const char kCommandString[];
564
repo syncdc085c82012-12-28 08:54:41 -0800565 NewWifiMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700566
Wade Guthrie0d438532012-05-18 14:18:50 -0700567 private:
568 DISALLOW_COPY_AND_ASSIGN(NewWifiMessage);
569};
570
571
repo syncdc085c82012-12-28 08:54:41 -0800572class NotifyCqmMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700573 public:
574 static const uint8_t kCommand;
575 static const char kCommandString[];
576
repo syncdc085c82012-12-28 08:54:41 -0800577 NotifyCqmMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700578
Wade Guthrie0d438532012-05-18 14:18:50 -0700579 private:
580 DISALLOW_COPY_AND_ASSIGN(NotifyCqmMessage);
581};
582
583
repo syncdc085c82012-12-28 08:54:41 -0800584class PmksaCandidateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700585 public:
586 static const uint8_t kCommand;
587 static const char kCommandString[];
588
repo syncdc085c82012-12-28 08:54:41 -0800589 PmksaCandidateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700590
Wade Guthrie0d438532012-05-18 14:18:50 -0700591 private:
592 DISALLOW_COPY_AND_ASSIGN(PmksaCandidateMessage);
593};
594
595
repo syncdc085c82012-12-28 08:54:41 -0800596class RegBeaconHintMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700597 public:
598 static const uint8_t kCommand;
599 static const char kCommandString[];
600
repo syncdc085c82012-12-28 08:54:41 -0800601 RegBeaconHintMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700602
Wade Guthrie0d438532012-05-18 14:18:50 -0700603 private:
Wade Guthrie0d438532012-05-18 14:18:50 -0700604 DISALLOW_COPY_AND_ASSIGN(RegBeaconHintMessage);
605};
606
607
repo syncdc085c82012-12-28 08:54:41 -0800608class RegChangeMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700609 public:
610 static const uint8_t kCommand;
611 static const char kCommandString[];
612
repo syncdc085c82012-12-28 08:54:41 -0800613 RegChangeMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700614
Wade Guthrie0d438532012-05-18 14:18:50 -0700615 private:
616 DISALLOW_COPY_AND_ASSIGN(RegChangeMessage);
617};
618
619
repo syncdc085c82012-12-28 08:54:41 -0800620class RemainOnChannelMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700621 public:
622 static const uint8_t kCommand;
623 static const char kCommandString[];
624
repo syncdc085c82012-12-28 08:54:41 -0800625 RemainOnChannelMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700626
Wade Guthrie0d438532012-05-18 14:18:50 -0700627 private:
628 DISALLOW_COPY_AND_ASSIGN(RemainOnChannelMessage);
629};
630
631
repo syncdc085c82012-12-28 08:54:41 -0800632class RoamMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700633 public:
634 static const uint8_t kCommand;
635 static const char kCommandString[];
636
repo syncdc085c82012-12-28 08:54:41 -0800637 RoamMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700638
Wade Guthrie0d438532012-05-18 14:18:50 -0700639 private:
640 DISALLOW_COPY_AND_ASSIGN(RoamMessage);
641};
642
643
repo syncdc085c82012-12-28 08:54:41 -0800644class ScanAbortedMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700645 public:
646 static const uint8_t kCommand;
647 static const char kCommandString[];
648
repo syncdc085c82012-12-28 08:54:41 -0800649 ScanAbortedMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700650
Wade Guthrie0d438532012-05-18 14:18:50 -0700651 private:
652 DISALLOW_COPY_AND_ASSIGN(ScanAbortedMessage);
653};
654
655
Wade Guthrie71872472013-03-05 10:33:38 -0800656class GetScanMessage : public Nl80211Message {
657 public:
658 static const uint8_t kCommand;
659 static const char kCommandString[];
660
661 GetScanMessage() : Nl80211Message(kCommand, kCommandString) {}
662
663 private:
664 DISALLOW_COPY_AND_ASSIGN(GetScanMessage);
665};
666
667
repo syncdc085c82012-12-28 08:54:41 -0800668class TriggerScanMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700669 public:
670 static const uint8_t kCommand;
671 static const char kCommandString[];
672
repo syncdc085c82012-12-28 08:54:41 -0800673 TriggerScanMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700674
Wade Guthrie0d438532012-05-18 14:18:50 -0700675 private:
676 DISALLOW_COPY_AND_ASSIGN(TriggerScanMessage);
677};
678
679
repo syncdc085c82012-12-28 08:54:41 -0800680class UnknownMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700681 public:
Christopher Wiley764538d2012-11-09 10:58:23 -0800682 explicit UnknownMessage(uint8_t command)
repo syncdc085c82012-12-28 08:54:41 -0800683 : Nl80211Message(command, kCommandString),
Christopher Wiley764538d2012-11-09 10:58:23 -0800684 command_(command) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700685
686 static const uint8_t kCommand;
687 static const char kCommandString[];
688
Wade Guthrie0d438532012-05-18 14:18:50 -0700689 private:
690 uint8_t command_;
691
692 DISALLOW_COPY_AND_ASSIGN(UnknownMessage);
693};
694
695
repo syncdc085c82012-12-28 08:54:41 -0800696class UnprotDeauthenticateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700697 public:
698 static const uint8_t kCommand;
699 static const char kCommandString[];
700
Christopher Wiley764538d2012-11-09 10:58:23 -0800701 UnprotDeauthenticateMessage()
repo syncdc085c82012-12-28 08:54:41 -0800702 : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700703
Wade Guthrie0d438532012-05-18 14:18:50 -0700704 private:
705 DISALLOW_COPY_AND_ASSIGN(UnprotDeauthenticateMessage);
706};
707
708
repo syncdc085c82012-12-28 08:54:41 -0800709class UnprotDisassociateMessage : public Nl80211Message {
Wade Guthrie0d438532012-05-18 14:18:50 -0700710 public:
711 static const uint8_t kCommand;
712 static const char kCommandString[];
713
repo syncdc085c82012-12-28 08:54:41 -0800714 UnprotDisassociateMessage() : Nl80211Message(kCommand, kCommandString) {}
Wade Guthrie0d438532012-05-18 14:18:50 -0700715
Wade Guthrie0d438532012-05-18 14:18:50 -0700716 private:
717 DISALLOW_COPY_AND_ASSIGN(UnprotDisassociateMessage);
718};
719
720
721//
722// Factory class.
723//
724
Wade Guthrief48a1952013-03-04 17:33:47 -0800725class NetlinkMessageFactory {
Wade Guthrie0d438532012-05-18 14:18:50 -0700726 public:
727 // Ownership of the message is passed to the caller and, as such, he should
728 // delete it.
Wade Guthrief48a1952013-03-04 17:33:47 -0800729 static NetlinkMessage *CreateMessage(nlmsghdr *msg);
730 // TODO(wdg): Need a way for a class to register a callback and a message
731 // type. That way, CreateMessage can call the appropriate factory based on
732 // the incoming message type.
Wade Guthrie0d438532012-05-18 14:18:50 -0700733
734 private:
Wade Guthrief48a1952013-03-04 17:33:47 -0800735 DISALLOW_COPY_AND_ASSIGN(NetlinkMessageFactory);
Wade Guthrie0d438532012-05-18 14:18:50 -0700736};
737
738
repo syncdc085c82012-12-28 08:54:41 -0800739// Nl80211MessageDataCollector - this class is used to collect data to be
Wade Guthrie0d438532012-05-18 14:18:50 -0700740// used for unit tests. It is only invoked in this case.
741
repo syncdc085c82012-12-28 08:54:41 -0800742class Nl80211MessageDataCollector {
Wade Guthrie0d438532012-05-18 14:18:50 -0700743 public:
repo syncdc085c82012-12-28 08:54:41 -0800744 static Nl80211MessageDataCollector *GetInstance();
Wade Guthrie0d438532012-05-18 14:18:50 -0700745
repo syncdc085c82012-12-28 08:54:41 -0800746 void CollectDebugData(const Nl80211Message &message, nlmsghdr *msg);
Wade Guthrie0d438532012-05-18 14:18:50 -0700747
748 protected:
749 friend struct
repo syncdc085c82012-12-28 08:54:41 -0800750 base::DefaultLazyInstanceTraits<Nl80211MessageDataCollector>;
Wade Guthrie0d438532012-05-18 14:18:50 -0700751
repo syncdc085c82012-12-28 08:54:41 -0800752 explicit Nl80211MessageDataCollector();
Wade Guthrie0d438532012-05-18 14:18:50 -0700753
754 private:
755 // In order to limit the output from this class, I keep track of types I
756 // haven't yet printed.
757 std::map<uint8_t, bool> need_to_print;
repo syncdc085c82012-12-28 08:54:41 -0800758
759 DISALLOW_COPY_AND_ASSIGN(Nl80211MessageDataCollector);
Wade Guthrie0d438532012-05-18 14:18:50 -0700760};
761
762} // namespace shill
763
764#endif // SHILL_USER_BOUND_NLMESSAGE_H_