Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1 | // 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 | // This code is derived from the 'iw' source code. The copyright and license |
| 6 | // of that code is as follows: |
| 7 | // |
| 8 | // Copyright (c) 2007, 2008 Johannes Berg |
| 9 | // Copyright (c) 2007 Andy Lutomirski |
| 10 | // Copyright (c) 2007 Mike Kershaw |
| 11 | // Copyright (c) 2008-2009 Luis R. Rodriguez |
| 12 | // |
| 13 | // Permission to use, copy, modify, and/or distribute this software for any |
| 14 | // purpose with or without fee is hereby granted, provided that the above |
| 15 | // copyright notice and this permission notice appear in all copies. |
| 16 | // |
| 17 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 18 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 19 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 20 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 21 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 22 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 23 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 24 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 25 | #include "shill/nl80211_message.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 26 | |
| 27 | #include <ctype.h> |
| 28 | #include <endian.h> |
| 29 | #include <errno.h> |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 30 | #include <limits.h> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 31 | #include <linux/nl80211.h> |
| 32 | #include <net/if.h> |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 33 | #include <netinet/in.h> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 34 | #include <netlink/attr.h> |
| 35 | #include <netlink/genl/ctrl.h> |
| 36 | #include <netlink/genl/family.h> |
| 37 | #include <netlink/genl/genl.h> |
| 38 | #include <netlink/msg.h> |
| 39 | #include <netlink/netlink.h> |
| 40 | |
Wade Guthrie | 8e27861 | 2013-02-26 10:32:34 -0800 | [diff] [blame] | 41 | #include <algorithm> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 42 | #include <iomanip> |
| 43 | #include <string> |
| 44 | |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 45 | #include <base/bind.h> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 46 | #include <base/format_macros.h> |
| 47 | #include <base/stl_util.h> |
| 48 | #include <base/stringprintf.h> |
| 49 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 50 | #include "shill/attribute_list.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 51 | #include "shill/ieee80211.h" |
| 52 | #include "shill/logging.h" |
Wade Guthrie | f162f8b | 2013-02-27 14:13:55 -0800 | [diff] [blame] | 53 | #include "shill/netlink_attribute.h" |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 54 | #include "shill/netlink_socket.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 55 | #include "shill/scope_logger.h" |
| 56 | |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 57 | using base::Bind; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 58 | using base::LazyInstance; |
| 59 | using base::StringAppendF; |
| 60 | using base::StringPrintf; |
| 61 | using std::map; |
Wade Guthrie | 8e27861 | 2013-02-26 10:32:34 -0800 | [diff] [blame] | 62 | using std::min; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 63 | using std::string; |
| 64 | using std::vector; |
| 65 | |
| 66 | namespace shill { |
| 67 | |
| 68 | namespace { |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 69 | LazyInstance<Nl80211MessageDataCollector> g_datacollector = |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 70 | LAZY_INSTANCE_INITIALIZER; |
| 71 | } // namespace |
| 72 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 73 | const uint8_t Nl80211Frame::kMinimumFrameByteCount = 26; |
| 74 | const uint8_t Nl80211Frame::kFrameTypeMask = 0xfc; |
| 75 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame^] | 76 | const uint32_t NetlinkMessage::kBroadcastSequenceNumber = 0; |
| 77 | const uint16_t NetlinkMessage::kIllegalMessageType = UINT16_MAX; |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 78 | |
| 79 | const char Nl80211Message::kBogusMacAddress[] = "XX:XX:XX:XX:XX:XX"; |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 80 | const unsigned int Nl80211Message::kEthernetAddressBytes = 6; |
| 81 | map<uint16_t, string> *Nl80211Message::reason_code_string_ = NULL; |
| 82 | map<uint16_t, string> *Nl80211Message::status_code_string_ = NULL; |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 83 | uint16_t Nl80211Message::nl80211_message_type_ = kIllegalMessageType; |
| 84 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame^] | 85 | // NetlinkMessage |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 86 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame^] | 87 | ByteString NetlinkMessage::EncodeHeader(uint32_t sequence_number, |
| 88 | uint16_t nlmsg_type) { |
| 89 | ByteString result; |
| 90 | sequence_number_ = sequence_number; |
| 91 | if (sequence_number_ == kBroadcastSequenceNumber) { |
| 92 | LOG(ERROR) << "Couldn't get a legal sequence number"; |
| 93 | return result; |
| 94 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 95 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame^] | 96 | // Build netlink header. |
| 97 | nlmsghdr header; |
| 98 | size_t nlmsghdr_with_pad = NLMSG_ALIGN(sizeof(header)); |
| 99 | header.nlmsg_len = nlmsghdr_with_pad; |
| 100 | header.nlmsg_type = nlmsg_type; |
| 101 | header.nlmsg_flags = NLM_F_REQUEST | flags_; |
| 102 | header.nlmsg_seq = sequence_number_; |
| 103 | header.nlmsg_pid = getpid(); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 104 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame^] | 105 | // Netlink header + pad. |
| 106 | result.Append(ByteString(reinterpret_cast<unsigned char *>(&header), |
| 107 | sizeof(header))); |
| 108 | result.Resize(nlmsghdr_with_pad); // Zero-fill pad space (if any). |
| 109 | return result; |
| 110 | } |
| 111 | |
| 112 | bool NetlinkMessage::InitAndStripHeader(ByteString *input) { |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 113 | if (!input) { |
| 114 | LOG(ERROR) << "NULL input"; |
| 115 | return false; |
| 116 | } |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame^] | 117 | if (input->GetLength() < sizeof(nlmsghdr)) { |
| 118 | LOG(ERROR) << "Insufficient input to extract nlmsghdr"; |
| 119 | return false; |
| 120 | } |
| 121 | |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 122 | // Read the nlmsghdr. |
| 123 | nlmsghdr *header = reinterpret_cast<nlmsghdr *>(input->GetData()); |
| 124 | message_type_ = header->nlmsg_type; |
| 125 | flags_ = header->nlmsg_flags; |
| 126 | sequence_number_ = header->nlmsg_seq; |
| 127 | |
| 128 | // Strip the nlmsghdr. |
| 129 | input->RemovePrefix(NLMSG_ALIGN(sizeof(struct nlmsghdr))); |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame^] | 130 | return true; |
| 131 | } |
| 132 | |
| 133 | bool NetlinkMessage::InitFromNlmsg(const nlmsghdr *const_msg) { |
| 134 | if (!const_msg) { |
| 135 | LOG(ERROR) << "Null |const_msg| parameter"; |
| 136 | return false; |
| 137 | } |
| 138 | ByteString message(reinterpret_cast<const unsigned char *>(const_msg), |
| 139 | const_msg->nlmsg_len); |
| 140 | if (!InitAndStripHeader(&message)) { |
| 141 | return false; |
| 142 | } |
| 143 | return true; |
| 144 | } |
| 145 | |
| 146 | // static |
| 147 | void NetlinkMessage::PrintBytes(int log_level, const unsigned char *buf, |
| 148 | size_t num_bytes) { |
| 149 | SLOG(WiFi, log_level) << "Netlink Message -- Examining Bytes"; |
| 150 | if (!buf) { |
| 151 | SLOG(WiFi, log_level) << "<NULL Buffer>"; |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | if (num_bytes >= sizeof(nlmsghdr)) { |
| 156 | const nlmsghdr *header = reinterpret_cast<const nlmsghdr *>(buf); |
| 157 | SLOG(WiFi, log_level) << StringPrintf( |
| 158 | "len: %02x %02x %02x %02x = %u bytes", |
| 159 | buf[0], buf[1], buf[2], buf[3], header->nlmsg_len); |
| 160 | |
| 161 | SLOG(WiFi, log_level) << StringPrintf( |
| 162 | "type | flags: %02x %02x %02x %02x - type:%u flags:%s%s%s%s%s", |
| 163 | buf[4], buf[5], buf[6], buf[7], header->nlmsg_type, |
| 164 | ((header->nlmsg_flags & NLM_F_REQUEST) ? " REQUEST" : ""), |
| 165 | ((header->nlmsg_flags & NLM_F_MULTI) ? " MULTI" : ""), |
| 166 | ((header->nlmsg_flags & NLM_F_ACK) ? " ACK" : ""), |
| 167 | ((header->nlmsg_flags & NLM_F_ECHO) ? " ECHO" : ""), |
| 168 | ((header->nlmsg_flags & NLM_F_DUMP_INTR) ? " BAD-SEQ" : "")); |
| 169 | |
| 170 | SLOG(WiFi, log_level) << StringPrintf( |
| 171 | "sequence: %02x %02x %02x %02x = %u", |
| 172 | buf[8], buf[9], buf[10], buf[11], header->nlmsg_seq); |
| 173 | SLOG(WiFi, log_level) << StringPrintf( |
| 174 | "pid: %02x %02x %02x %02x = %u", |
| 175 | buf[12], buf[13], buf[14], buf[15], header->nlmsg_pid); |
| 176 | buf += sizeof(nlmsghdr); |
| 177 | num_bytes -= sizeof(nlmsghdr); |
| 178 | } else { |
| 179 | SLOG(WiFi, log_level) << "Not enough bytes (" << num_bytes |
| 180 | << ") for a complete nlmsghdr (requires " |
| 181 | << sizeof(nlmsghdr) << ")."; |
| 182 | } |
| 183 | |
| 184 | while (num_bytes) { |
| 185 | string output; |
| 186 | size_t bytes_this_row = min(num_bytes, static_cast<size_t>(32)); |
| 187 | for (size_t i = 0; i < bytes_this_row; ++i) { |
| 188 | StringAppendF(&output, " %02x", *buf++); |
| 189 | } |
| 190 | SLOG(WiFi, log_level) << output; |
| 191 | num_bytes -= bytes_this_row; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | // GenericNetlinkMessage |
| 196 | |
| 197 | ByteString GenericNetlinkMessage::EncodeHeader(uint32_t sequence_number, |
| 198 | uint16_t nlmsg_type) { |
| 199 | // Build nlmsghdr. |
| 200 | ByteString result(NetlinkMessage::EncodeHeader(sequence_number, nlmsg_type)); |
| 201 | if (result.GetLength() == 0) { |
| 202 | LOG(ERROR) << "Couldn't encode message header."; |
| 203 | return result; |
| 204 | } |
| 205 | |
| 206 | // Build and append the genl message header. |
| 207 | genlmsghdr genl_header; |
| 208 | genl_header.cmd = command(); |
| 209 | genl_header.version = 1; |
| 210 | genl_header.reserved = 0; |
| 211 | |
| 212 | ByteString genl_header_string( |
| 213 | reinterpret_cast<unsigned char *>(&genl_header), sizeof(genl_header)); |
| 214 | size_t genlmsghdr_with_pad = NLMSG_ALIGN(sizeof(genl_header)); |
| 215 | genl_header_string.Resize(genlmsghdr_with_pad); // Zero-fill. |
| 216 | |
| 217 | nlmsghdr *pheader = reinterpret_cast<nlmsghdr *>(result.GetData()); |
| 218 | pheader->nlmsg_len += genlmsghdr_with_pad; |
| 219 | result.Append(genl_header_string); |
| 220 | return result; |
| 221 | } |
| 222 | |
| 223 | ByteString GenericNetlinkMessage::Encode(uint32_t sequence_number, |
| 224 | uint16_t nlmsg_type) { |
| 225 | ByteString result(EncodeHeader(sequence_number, nlmsg_type)); |
| 226 | if (result.GetLength() == 0) { |
| 227 | LOG(ERROR) << "Couldn't encode message header."; |
| 228 | return result; |
| 229 | } |
| 230 | |
| 231 | // Build and append attributes (padding is included by |
| 232 | // AttributeList::Encode). |
| 233 | ByteString attribute_string = attributes_->Encode(); |
| 234 | |
| 235 | // Need to re-calculate |header| since |Append|, above, moves the data. |
| 236 | nlmsghdr *pheader = reinterpret_cast<nlmsghdr *>(result.GetData()); |
| 237 | pheader->nlmsg_len += attribute_string.GetLength(); |
| 238 | result.Append(attribute_string); |
| 239 | |
| 240 | return result; |
| 241 | } |
| 242 | |
| 243 | bool GenericNetlinkMessage::InitAndStripHeader(ByteString *input) { |
| 244 | if (!input) { |
| 245 | LOG(ERROR) << "NULL input"; |
| 246 | return false; |
| 247 | } |
| 248 | if (!NetlinkMessage::InitAndStripHeader(input)) { |
| 249 | return false; |
| 250 | } |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 251 | |
| 252 | // Read the genlmsghdr. |
| 253 | genlmsghdr *gnlh = reinterpret_cast<genlmsghdr *>(input->GetData()); |
| 254 | if (command_ != gnlh->cmd) { |
| 255 | LOG(WARNING) << "This object thinks it's a " << command_ |
| 256 | << " but the message thinks it's a " << gnlh->cmd; |
| 257 | } |
| 258 | |
| 259 | // Strip the genlmsghdr. |
| 260 | input->RemovePrefix(NLMSG_ALIGN(sizeof(struct genlmsghdr))); |
| 261 | return true; |
Wade Guthrie | 8e27861 | 2013-02-26 10:32:34 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame^] | 264 | void GenericNetlinkMessage::Print(int log_level) const { |
| 265 | SLOG(WiFi, log_level) << StringPrintf("Message %s (%d)", |
| 266 | command_string(), |
| 267 | command()); |
| 268 | attributes_->Print(log_level, 1); |
| 269 | } |
| 270 | |
| 271 | // Nl80211Message |
| 272 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 273 | bool Nl80211Message::InitFromNlmsg(const nlmsghdr *const_msg) { |
| 274 | if (!const_msg) { |
| 275 | LOG(ERROR) << "Null |msg| parameter"; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 276 | return false; |
| 277 | } |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 278 | ByteString message(reinterpret_cast<const unsigned char *>(const_msg), |
| 279 | const_msg->nlmsg_len); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 280 | |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 281 | if (!InitAndStripHeader(&message)) { |
| 282 | return false; |
| 283 | } |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 284 | |
| 285 | // Attributes. |
| 286 | // Parse the attributes from the nl message payload into the 'tb' array. |
| 287 | nlattr *tb[NL80211_ATTR_MAX + 1]; |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 288 | nla_parse(tb, NL80211_ATTR_MAX, |
| 289 | reinterpret_cast<nlattr *>(message.GetData()), message.GetLength(), |
| 290 | NULL); |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 291 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 292 | for (int i = 0; i < NL80211_ATTR_MAX + 1; ++i) { |
| 293 | if (tb[i]) { |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 294 | // TODO(wdg): When Nl80211Messages instantiate their own attributes, |
| 295 | // this call should, instead, call |SetAttributeFromNlAttr|. |
Wade Guthrie | efe1f0c | 2013-02-26 17:42:01 -0800 | [diff] [blame] | 296 | attributes_->CreateAndInitAttribute( |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 297 | i, tb[i], Bind(&NetlinkAttribute::NewNl80211AttributeFromId)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
| 301 | // Convert integer values provided by libnl (for example, from the |
| 302 | // NL80211_ATTR_STATUS_CODE or NL80211_ATTR_REASON_CODE attribute) into |
| 303 | // strings describing the status. |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 304 | if (!reason_code_string_) { |
| 305 | reason_code_string_ = new map<uint16_t, string>; |
| 306 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnspecified] = |
| 307 | "Unspecified reason"; |
| 308 | (*reason_code_string_)[ |
| 309 | IEEE_80211::kReasonCodePreviousAuthenticationInvalid] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 310 | "Previous authentication no longer valid"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 311 | (*reason_code_string_)[IEEE_80211::kReasonCodeSenderHasLeft] = |
| 312 | "Deauthentcated because sending STA is leaving (or has left) IBSS or " |
| 313 | "ESS"; |
| 314 | (*reason_code_string_)[IEEE_80211::kReasonCodeInactivity] = |
| 315 | "Disassociated due to inactivity"; |
| 316 | (*reason_code_string_)[IEEE_80211::kReasonCodeTooManySTAs] = |
| 317 | "Disassociated because AP is unable to handle all currently associated " |
| 318 | "STAs"; |
| 319 | (*reason_code_string_)[IEEE_80211::kReasonCodeNonAuthenticated] = |
| 320 | "Class 2 frame received from nonauthenticated STA"; |
| 321 | (*reason_code_string_)[IEEE_80211::kReasonCodeNonAssociated] = |
| 322 | "Class 3 frame received from nonassociated STA"; |
| 323 | (*reason_code_string_)[IEEE_80211::kReasonCodeDisassociatedHasLeft] = |
| 324 | "Disassociated because sending STA is leaving (or has left) BSS"; |
| 325 | (*reason_code_string_)[ |
| 326 | IEEE_80211::kReasonCodeReassociationNotAuthenticated] = |
| 327 | "STA requesting (re)association is not authenticated with responding " |
| 328 | "STA"; |
| 329 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnacceptablePowerCapability] = |
| 330 | "Disassociated because the information in the Power Capability " |
| 331 | "element is unacceptable"; |
| 332 | (*reason_code_string_)[ |
| 333 | IEEE_80211::kReasonCodeUnacceptableSupportedChannelInfo] = |
| 334 | "Disassociated because the information in the Supported Channels " |
| 335 | "element is unacceptable"; |
| 336 | (*reason_code_string_)[IEEE_80211::kReasonCodeInvalidInfoElement] = |
| 337 | "Invalid information element, i.e., an information element defined in " |
| 338 | "this standard for which the content does not meet the specifications " |
| 339 | "in Clause 7"; |
| 340 | (*reason_code_string_)[IEEE_80211::kReasonCodeMICFailure] = |
| 341 | "Message integrity code (MIC) failure"; |
| 342 | (*reason_code_string_)[IEEE_80211::kReasonCode4WayTimeout] = |
| 343 | "4-Way Handshake timeout"; |
| 344 | (*reason_code_string_)[IEEE_80211::kReasonCodeGroupKeyHandshakeTimeout] = |
| 345 | "Group Key Handshake timeout"; |
| 346 | (*reason_code_string_)[IEEE_80211::kReasonCodeDifferenIE] = |
| 347 | "Information element in 4-Way Handshake different from " |
| 348 | "(Re)Association Request/Probe Response/Beacon frame"; |
| 349 | (*reason_code_string_)[IEEE_80211::kReasonCodeGroupCipherInvalid] = |
| 350 | "Invalid group cipher"; |
| 351 | (*reason_code_string_)[IEEE_80211::kReasonCodePairwiseCipherInvalid] = |
| 352 | "Invalid pairwise cipher"; |
| 353 | (*reason_code_string_)[IEEE_80211::kReasonCodeAkmpInvalid] = |
| 354 | "Invalid AKMP"; |
| 355 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnsupportedRsnIeVersion] = |
| 356 | "Unsupported RSN information element version"; |
| 357 | (*reason_code_string_)[IEEE_80211::kReasonCodeInvalidRsnIeCaps] = |
| 358 | "Invalid RSN information element capabilities"; |
| 359 | (*reason_code_string_)[IEEE_80211::kReasonCode8021XAuth] = |
| 360 | "IEEE 802.1X authentication failed"; |
| 361 | (*reason_code_string_)[IEEE_80211::kReasonCodeCipherSuiteRejected] = |
| 362 | "Cipher suite rejected because of the security policy"; |
| 363 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnspecifiedQoS] = |
| 364 | "Disassociated for unspecified, QoS-related reason"; |
| 365 | (*reason_code_string_)[IEEE_80211::kReasonCodeQoSBandwidth] = |
| 366 | "Disassociated because QoS AP lacks sufficient bandwidth for this " |
| 367 | "QoS STA"; |
| 368 | (*reason_code_string_)[IEEE_80211::kReasonCodeiPoorConditions] = |
| 369 | "Disassociated because excessive number of frames need to be " |
| 370 | "acknowledged, but are not acknowledged due to AP transmissions " |
| 371 | "and/or poor channel conditions"; |
| 372 | (*reason_code_string_)[IEEE_80211::kReasonCodeOutsideTxop] = |
| 373 | "Disassociated because STA is transmitting outside the limits of its " |
| 374 | "TXOPs"; |
| 375 | (*reason_code_string_)[IEEE_80211::kReasonCodeStaLeaving] = |
| 376 | "Requested from peer STA as the STA is leaving the BSS (or resetting)"; |
| 377 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnacceptableMechanism] = |
| 378 | "Requested from peer STA as it does not want to use the mechanism"; |
| 379 | (*reason_code_string_)[IEEE_80211::kReasonCodeSetupRequired] = |
| 380 | "Requested from peer STA as the STA received frames using the " |
| 381 | "mechanism for which a setup is required"; |
| 382 | (*reason_code_string_)[IEEE_80211::kReasonCodeTimeout] = |
| 383 | "Requested from peer STA due to timeout"; |
| 384 | (*reason_code_string_)[IEEE_80211::kReasonCodeCipherSuiteNotSupported] = |
| 385 | "Peer STA does not support the requested cipher suite"; |
| 386 | (*reason_code_string_)[IEEE_80211::kReasonCodeInvalid] = "<INVALID REASON>"; |
| 387 | } |
| 388 | |
| 389 | if (!status_code_string_) { |
| 390 | status_code_string_ = new map<uint16_t, string>; |
| 391 | (*status_code_string_)[IEEE_80211::kStatusCodeSuccessful] = "Successful"; |
| 392 | (*status_code_string_)[IEEE_80211::kStatusCodeFailure] = |
| 393 | "Unspecified failure"; |
| 394 | (*status_code_string_)[IEEE_80211::kStatusCodeAllCapabilitiesNotSupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 395 | "Cannot support all requested capabilities in the capability " |
| 396 | "information field"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 397 | (*status_code_string_)[IEEE_80211::kStatusCodeCantConfirmAssociation] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 398 | "Reassociation denied due to inability to confirm that association " |
| 399 | "exists"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 400 | (*status_code_string_)[IEEE_80211::kStatusCodeAssociationDenied] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 401 | "Association denied due to reason outside the scope of this standard"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 402 | (*status_code_string_)[ |
| 403 | IEEE_80211::kStatusCodeAuthenticationUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 404 | "Responding station does not support the specified authentication " |
| 405 | "algorithm"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 406 | (*status_code_string_)[IEEE_80211::kStatusCodeOutOfSequence] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 407 | "Received an authentication frame with authentication transaction " |
| 408 | "sequence number out of expected sequence"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 409 | (*status_code_string_)[IEEE_80211::kStatusCodeChallengeFailure] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 410 | "Authentication rejected because of challenge failure"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 411 | (*status_code_string_)[IEEE_80211::kStatusCodeFrameTimeout] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 412 | "Authentication rejected due to timeout waiting for next frame in " |
| 413 | "sequence"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 414 | (*status_code_string_)[IEEE_80211::kStatusCodeMaxSta] = |
| 415 | "Association denied because AP is unable to handle additional " |
| 416 | "associated STA"; |
| 417 | (*status_code_string_)[IEEE_80211::kStatusCodeDataRateUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 418 | "Association denied due to requesting station not supporting all of " |
| 419 | "the data rates in the BSSBasicRateSet parameter"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 420 | (*status_code_string_)[IEEE_80211::kStatusCodeShortPreambleUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 421 | "Association denied due to requesting station not supporting the " |
| 422 | "short preamble option"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 423 | (*status_code_string_)[IEEE_80211::kStatusCodePbccUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 424 | "Association denied due to requesting station not supporting the PBCC " |
| 425 | "modulation option"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 426 | (*status_code_string_)[ |
| 427 | IEEE_80211::kStatusCodeChannelAgilityUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 428 | "Association denied due to requesting station not supporting the " |
| 429 | "channel agility option"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 430 | (*status_code_string_)[IEEE_80211::kStatusCodeNeedSpectrumManagement] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 431 | "Association request rejected because Spectrum Management capability " |
| 432 | "is required"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 433 | (*status_code_string_)[ |
| 434 | IEEE_80211::kStatusCodeUnacceptablePowerCapability] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 435 | "Association request rejected because the information in the Power " |
| 436 | "Capability element is unacceptable"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 437 | (*status_code_string_)[ |
| 438 | IEEE_80211::kStatusCodeUnacceptableSupportedChannelInfo] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 439 | "Association request rejected because the information in the " |
| 440 | "Supported Channels element is unacceptable"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 441 | (*status_code_string_)[IEEE_80211::kStatusCodeShortTimeSlotRequired] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 442 | "Association request rejected due to requesting station not " |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 443 | "supporting the Short Slot Time option"; |
| 444 | (*status_code_string_)[IEEE_80211::kStatusCodeDssOfdmRequired] = |
| 445 | "Association request rejected due to requesting station not " |
| 446 | "supporting the DSSS-OFDM option"; |
| 447 | (*status_code_string_)[IEEE_80211::kStatusCodeQosFailure] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 448 | "Unspecified, QoS related failure"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 449 | (*status_code_string_)[ |
| 450 | IEEE_80211::kStatusCodeInsufficientBandwithForQsta] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 451 | "Association denied due to QAP having insufficient bandwidth to handle " |
| 452 | "another QSTA"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 453 | (*status_code_string_)[IEEE_80211::kStatusCodePoorConditions] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 454 | "Association denied due to poor channel conditions"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 455 | (*status_code_string_)[IEEE_80211::kStatusCodeQosNotSupported] = |
| 456 | "Association (with QoS BSS) denied due to requesting station not " |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 457 | "supporting the QoS facility"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 458 | (*status_code_string_)[IEEE_80211::kStatusCodeDeclined] = |
| 459 | "The request has been declined"; |
| 460 | (*status_code_string_)[IEEE_80211::kStatusCodeInvalidParameterValues] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 461 | "The request has not been successful as one or more parameters have " |
| 462 | "invalid values"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 463 | (*status_code_string_)[IEEE_80211::kStatusCodeCannotBeHonored] = |
| 464 | "The TS has not been created because the request cannot be honored. " |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 465 | "However, a suggested Tspec is provided so that the initiating QSTA " |
| 466 | "may attempt to send another TS with the suggested changes to the " |
| 467 | "TSpec"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 468 | (*status_code_string_)[IEEE_80211::kStatusCodeInvalidInfoElement] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 469 | "Invalid Information Element"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 470 | (*status_code_string_)[IEEE_80211::kStatusCodeGroupCipherInvalid] = |
| 471 | "Invalid Group Cipher"; |
| 472 | (*status_code_string_)[IEEE_80211::kStatusCodePairwiseCipherInvalid] = |
| 473 | "Invalid Pairwise Cipher"; |
| 474 | (*status_code_string_)[IEEE_80211::kStatusCodeAkmpInvalid] = "Invalid AKMP"; |
| 475 | (*status_code_string_)[IEEE_80211::kStatusCodeUnsupportedRsnIeVersion] = |
| 476 | "Unsupported RSN Information Element version"; |
| 477 | (*status_code_string_)[IEEE_80211::kStatusCodeInvalidRsnIeCaps] = |
| 478 | "Invalid RSN Information Element Capabilities"; |
| 479 | (*status_code_string_)[IEEE_80211::kStatusCodeCipherSuiteRejected] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 480 | "Cipher suite is rejected per security policy"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 481 | (*status_code_string_)[IEEE_80211::kStatusCodeTsDelayNotMet] = |
| 482 | "The TS has not been created. However, the HC may be capable of " |
| 483 | "creating a TS, in response to a request, after the time indicated in " |
| 484 | "the TS Delay element"; |
| 485 | (*status_code_string_)[IEEE_80211::kStatusCodeDirectLinkIllegal] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 486 | "Direct link is not allowed in the BSS by policy"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 487 | (*status_code_string_)[IEEE_80211::kStatusCodeStaNotInBss] = |
| 488 | "Destination STA is not present within this BSS"; |
| 489 | (*status_code_string_)[IEEE_80211::kStatusCodeStaNotInQsta] = |
| 490 | "The destination STA is not a QoS STA"; |
| 491 | (*status_code_string_)[IEEE_80211::kStatusCodeExcessiveListenInterval] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 492 | "Association denied because Listen Interval is too large"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 493 | (*status_code_string_)[IEEE_80211::kStatusCodeInvalid] = "<INVALID STATUS>"; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | return true; |
| 497 | } |
| 498 | |
Wade Guthrie | 8e27861 | 2013-02-26 10:32:34 -0800 | [diff] [blame] | 499 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 500 | // Helper function to provide a string for a MAC address. |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 501 | bool Nl80211Message::GetMacAttributeString(int id, string *value) const { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 502 | if (!value) { |
| 503 | LOG(ERROR) << "Null |value| parameter"; |
| 504 | return false; |
| 505 | } |
| 506 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 507 | ByteString data; |
Wade Guthrie | efe1f0c | 2013-02-26 17:42:01 -0800 | [diff] [blame] | 508 | if (!const_attributes()->GetRawAttributeValue(id, &data)) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 509 | value->assign(kBogusMacAddress); |
| 510 | return false; |
| 511 | } |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 512 | value->assign(StringFromMacAddress(data.GetConstData())); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 513 | |
| 514 | return true; |
| 515 | } |
| 516 | |
| 517 | // Helper function to provide a string for NL80211_ATTR_SCAN_FREQUENCIES. |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 518 | bool Nl80211Message::GetScanFrequenciesAttribute( |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 519 | int id, vector<uint32_t> *value) const { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 520 | if (!value) { |
| 521 | LOG(ERROR) << "Null |value| parameter"; |
| 522 | return false; |
| 523 | } |
| 524 | |
| 525 | value->clear(); |
Wade Guthrie | d3dfd6c | 2013-02-28 17:40:36 -0800 | [diff] [blame] | 526 | |
| 527 | AttributeListConstRefPtr frequency_list; |
| 528 | if (!const_attributes()->ConstGetNestedAttributeList( |
| 529 | NL80211_ATTR_SCAN_FREQUENCIES, &frequency_list) || !frequency_list) { |
| 530 | LOG(ERROR) << "Couldn't get NL80211_ATTR_SCAN_FREQUENCIES attribute"; |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 531 | return false; |
Wade Guthrie | d3dfd6c | 2013-02-28 17:40:36 -0800 | [diff] [blame] | 532 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 533 | |
Wade Guthrie | d3dfd6c | 2013-02-28 17:40:36 -0800 | [diff] [blame] | 534 | // Assume IDs for the nested attribute array are linear starting from 1. |
| 535 | // Currently, that is enforced in the input to the nested attribute. |
| 536 | uint32_t freq; |
| 537 | int i = 1; |
| 538 | while (frequency_list->GetU32AttributeValue(i, &freq)) { |
| 539 | value->push_back(freq); |
| 540 | ++i; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 541 | } |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 542 | return true; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | // Helper function to provide a string for NL80211_ATTR_SCAN_SSIDS. |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 546 | bool Nl80211Message::GetScanSsidsAttribute( |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 547 | int id, vector<string> *value) const { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 548 | if (!value) { |
| 549 | LOG(ERROR) << "Null |value| parameter"; |
| 550 | return false; |
| 551 | } |
| 552 | |
Wade Guthrie | d3dfd6c | 2013-02-28 17:40:36 -0800 | [diff] [blame] | 553 | AttributeListConstRefPtr ssid_list; |
| 554 | if (!const_attributes()->ConstGetNestedAttributeList( |
| 555 | NL80211_ATTR_SCAN_SSIDS, &ssid_list) || !ssid_list) { |
| 556 | LOG(ERROR) << "Couldn't get NL80211_ATTR_SCAN_SSIDS attribute"; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 557 | return false; |
Wade Guthrie | d3dfd6c | 2013-02-28 17:40:36 -0800 | [diff] [blame] | 558 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 559 | |
Wade Guthrie | d3dfd6c | 2013-02-28 17:40:36 -0800 | [diff] [blame] | 560 | // Assume IDs for the nested attribute array are linear starting from 1. |
| 561 | // Currently, that is enforced in the input to the nested attribute. |
| 562 | string ssid; |
| 563 | int i = 1; |
| 564 | while (ssid_list->GetStringAttributeValue(i, &ssid)) { |
| 565 | value->push_back(ssid); |
| 566 | ++i; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 567 | } |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 568 | return true; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 571 | // static |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 572 | string Nl80211Message::StringFromMacAddress(const uint8_t *arg) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 573 | string output; |
| 574 | |
| 575 | if (!arg) { |
| 576 | output = kBogusMacAddress; |
| 577 | LOG(ERROR) << "|arg| parameter is NULL."; |
| 578 | } else { |
| 579 | StringAppendF(&output, "%02x", arg[0]); |
| 580 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 581 | for (unsigned int i = 1; i < kEthernetAddressBytes ; ++i) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 582 | StringAppendF(&output, ":%02x", arg[i]); |
| 583 | } |
| 584 | } |
| 585 | return output; |
| 586 | } |
| 587 | |
| 588 | // static |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 589 | string Nl80211Message::StringFromReason(uint16_t status) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 590 | map<uint16_t, string>::const_iterator match; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 591 | match = reason_code_string_->find(status); |
| 592 | if (match == reason_code_string_->end()) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 593 | string output; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 594 | if (status < IEEE_80211::kReasonCodeMax) { |
| 595 | StringAppendF(&output, "<Reserved Reason:%u>", status); |
| 596 | } else { |
| 597 | StringAppendF(&output, "<Unknown Reason:%u>", status); |
| 598 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 599 | return output; |
| 600 | } |
| 601 | return match->second; |
| 602 | } |
| 603 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 604 | // static |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 605 | string Nl80211Message::StringFromStatus(uint16_t status) { |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 606 | map<uint16_t, string>::const_iterator match; |
| 607 | match = status_code_string_->find(status); |
| 608 | if (match == status_code_string_->end()) { |
| 609 | string output; |
| 610 | if (status < IEEE_80211::kStatusCodeMax) { |
| 611 | StringAppendF(&output, "<Reserved Status:%u>", status); |
| 612 | } else { |
| 613 | StringAppendF(&output, "<Unknown Status:%u>", status); |
| 614 | } |
| 615 | return output; |
| 616 | } |
| 617 | return match->second; |
| 618 | } |
| 619 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 620 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 621 | Nl80211Frame::Nl80211Frame(const ByteString &raw_frame) |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 622 | : frame_type_(kIllegalFrameType), reason_(UINT16_MAX), status_(UINT16_MAX), |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 623 | frame_(raw_frame) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 624 | const IEEE_80211::ieee80211_frame *frame = |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 625 | reinterpret_cast<const IEEE_80211::ieee80211_frame *>( |
| 626 | frame_.GetConstData()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 627 | |
| 628 | // Now, let's populate the other stuff. |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 629 | if (frame_.GetLength() >= kMinimumFrameByteCount) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 630 | mac_from_ = |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 631 | Nl80211Message::StringFromMacAddress(&frame->destination_mac[0]); |
| 632 | mac_to_ = Nl80211Message::StringFromMacAddress(&frame->source_mac[0]); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 633 | frame_type_ = frame->frame_control & kFrameTypeMask; |
| 634 | |
| 635 | switch (frame_type_) { |
| 636 | case kAssocResponseFrameType: |
| 637 | case kReassocResponseFrameType: |
| 638 | status_ = le16toh(frame->u.associate_response.status_code); |
| 639 | break; |
| 640 | |
| 641 | case kAuthFrameType: |
| 642 | status_ = le16toh(frame->u.authentiate_message.status_code); |
| 643 | break; |
| 644 | |
| 645 | case kDisassocFrameType: |
| 646 | case kDeauthFrameType: |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 647 | reason_ = le16toh(frame->u.deauthentiate_message.reason_code); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 648 | break; |
| 649 | |
| 650 | default: |
| 651 | break; |
| 652 | } |
| 653 | } |
| 654 | } |
| 655 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 656 | bool Nl80211Frame::ToString(string *output) const { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 657 | if (!output) { |
| 658 | LOG(ERROR) << "NULL |output|"; |
| 659 | return false; |
| 660 | } |
| 661 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 662 | if (frame_.IsEmpty()) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 663 | output->append(" [no frame]"); |
| 664 | return true; |
| 665 | } |
| 666 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 667 | if (frame_.GetLength() < kMinimumFrameByteCount) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 668 | output->append(" [invalid frame: "); |
| 669 | } else { |
| 670 | StringAppendF(output, " %s -> %s", mac_from_.c_str(), mac_to_.c_str()); |
| 671 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 672 | switch (frame_.GetConstData()[0] & kFrameTypeMask) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 673 | case kAssocResponseFrameType: |
| 674 | StringAppendF(output, "; AssocResponse status: %u: %s", |
| 675 | status_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 676 | Nl80211Message::StringFromStatus(status_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 677 | break; |
| 678 | case kReassocResponseFrameType: |
| 679 | StringAppendF(output, "; ReassocResponse status: %u: %s", |
| 680 | status_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 681 | Nl80211Message::StringFromStatus(status_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 682 | break; |
| 683 | case kAuthFrameType: |
| 684 | StringAppendF(output, "; Auth status: %u: %s", |
| 685 | status_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 686 | Nl80211Message::StringFromStatus(status_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 687 | break; |
| 688 | |
| 689 | case kDisassocFrameType: |
| 690 | StringAppendF(output, "; Disassoc reason %u: %s", |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 691 | reason_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 692 | Nl80211Message::StringFromReason(reason_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 693 | break; |
| 694 | case kDeauthFrameType: |
| 695 | StringAppendF(output, "; Deauth reason %u: %s", |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 696 | reason_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 697 | Nl80211Message::StringFromReason(reason_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 698 | break; |
| 699 | |
| 700 | default: |
| 701 | break; |
| 702 | } |
| 703 | output->append(" [frame: "); |
| 704 | } |
| 705 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 706 | const unsigned char *frame = frame_.GetConstData(); |
| 707 | for (size_t i = 0; i < frame_.GetLength(); ++i) { |
| 708 | StringAppendF(output, "%02x, ", frame[i]); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 709 | } |
| 710 | output->append("]"); |
| 711 | |
| 712 | return true; |
| 713 | } |
| 714 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 715 | bool Nl80211Frame::IsEqual(const Nl80211Frame &other) const { |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 716 | return frame_.Equals(other.frame_); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 719 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 720 | // |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 721 | // Specific Nl80211Message types. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 722 | // |
| 723 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 724 | // An Ack is not a GENL message and, as such, has no command. |
| 725 | const uint8_t AckMessage::kCommand = NL80211_CMD_UNSPEC; |
| 726 | const char AckMessage::kCommandString[] = "NL80211_ACK"; |
| 727 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 728 | const uint8_t AssociateMessage::kCommand = NL80211_CMD_ASSOCIATE; |
| 729 | const char AssociateMessage::kCommandString[] = "NL80211_CMD_ASSOCIATE"; |
| 730 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 731 | const uint8_t AuthenticateMessage::kCommand = NL80211_CMD_AUTHENTICATE; |
| 732 | const char AuthenticateMessage::kCommandString[] = "NL80211_CMD_AUTHENTICATE"; |
| 733 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 734 | const uint8_t CancelRemainOnChannelMessage::kCommand = |
| 735 | NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL; |
| 736 | const char CancelRemainOnChannelMessage::kCommandString[] = |
| 737 | "NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL"; |
| 738 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 739 | const uint8_t ConnectMessage::kCommand = NL80211_CMD_CONNECT; |
| 740 | const char ConnectMessage::kCommandString[] = "NL80211_CMD_CONNECT"; |
| 741 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 742 | const uint8_t DeauthenticateMessage::kCommand = NL80211_CMD_DEAUTHENTICATE; |
| 743 | const char DeauthenticateMessage::kCommandString[] = |
| 744 | "NL80211_CMD_DEAUTHENTICATE"; |
| 745 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 746 | const uint8_t DeleteStationMessage::kCommand = NL80211_CMD_DEL_STATION; |
| 747 | const char DeleteStationMessage::kCommandString[] = "NL80211_CMD_DEL_STATION"; |
| 748 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 749 | const uint8_t DisassociateMessage::kCommand = NL80211_CMD_DISASSOCIATE; |
| 750 | const char DisassociateMessage::kCommandString[] = "NL80211_CMD_DISASSOCIATE"; |
| 751 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 752 | const uint8_t DisconnectMessage::kCommand = NL80211_CMD_DISCONNECT; |
| 753 | const char DisconnectMessage::kCommandString[] = "NL80211_CMD_DISCONNECT"; |
| 754 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 755 | // An Error is not a GENL message and, as such, has no command. |
| 756 | const uint8_t ErrorMessage::kCommand = NL80211_CMD_UNSPEC; |
| 757 | const char ErrorMessage::kCommandString[] = "NL80211_ERROR"; |
| 758 | |
| 759 | ErrorMessage::ErrorMessage(uint32_t error) |
| 760 | : Nl80211Message(kCommand, kCommandString), error_(error) {} |
| 761 | |
| 762 | string ErrorMessage::ToString() const { |
| 763 | string output; |
| 764 | StringAppendF(&output, "NL80211_ERROR %" PRIx32 ": %s", |
| 765 | error_, strerror(error_)); |
| 766 | return output; |
| 767 | } |
| 768 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 769 | const uint8_t FrameTxStatusMessage::kCommand = NL80211_CMD_FRAME_TX_STATUS; |
| 770 | const char FrameTxStatusMessage::kCommandString[] = |
| 771 | "NL80211_CMD_FRAME_TX_STATUS"; |
| 772 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 773 | const uint8_t GetRegMessage::kCommand = NL80211_CMD_GET_REG; |
| 774 | const char GetRegMessage::kCommandString[] = "NL80211_CMD_GET_REG"; |
| 775 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 776 | const uint8_t JoinIbssMessage::kCommand = NL80211_CMD_JOIN_IBSS; |
| 777 | const char JoinIbssMessage::kCommandString[] = "NL80211_CMD_JOIN_IBSS"; |
| 778 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 779 | const uint8_t MichaelMicFailureMessage::kCommand = |
| 780 | NL80211_CMD_MICHAEL_MIC_FAILURE; |
| 781 | const char MichaelMicFailureMessage::kCommandString[] = |
| 782 | "NL80211_CMD_MICHAEL_MIC_FAILURE"; |
| 783 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 784 | const uint8_t NewScanResultsMessage::kCommand = NL80211_CMD_NEW_SCAN_RESULTS; |
| 785 | const char NewScanResultsMessage::kCommandString[] = |
| 786 | "NL80211_CMD_NEW_SCAN_RESULTS"; |
| 787 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 788 | const uint8_t NewStationMessage::kCommand = NL80211_CMD_NEW_STATION; |
| 789 | const char NewStationMessage::kCommandString[] = "NL80211_CMD_NEW_STATION"; |
| 790 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 791 | const uint8_t NewWifiMessage::kCommand = NL80211_CMD_NEW_WIPHY; |
| 792 | const char NewWifiMessage::kCommandString[] = "NL80211_CMD_NEW_WIPHY"; |
| 793 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 794 | // A NOOP is not a GENL message and, as such, has no command. |
| 795 | const uint8_t NoopMessage::kCommand = NL80211_CMD_UNSPEC; |
| 796 | const char NoopMessage::kCommandString[] = "NL80211_NOOP"; |
| 797 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 798 | const uint8_t NotifyCqmMessage::kCommand = NL80211_CMD_NOTIFY_CQM; |
| 799 | const char NotifyCqmMessage::kCommandString[] = "NL80211_CMD_NOTIFY_CQM"; |
| 800 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 801 | const uint8_t PmksaCandidateMessage::kCommand = NL80211_ATTR_PMKSA_CANDIDATE; |
| 802 | const char PmksaCandidateMessage::kCommandString[] = |
| 803 | "NL80211_ATTR_PMKSA_CANDIDATE"; |
| 804 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 805 | const uint8_t RegBeaconHintMessage::kCommand = NL80211_CMD_REG_BEACON_HINT; |
| 806 | const char RegBeaconHintMessage::kCommandString[] = |
| 807 | "NL80211_CMD_REG_BEACON_HINT"; |
| 808 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 809 | const uint8_t RegChangeMessage::kCommand = NL80211_CMD_REG_CHANGE; |
| 810 | const char RegChangeMessage::kCommandString[] = "NL80211_CMD_REG_CHANGE"; |
| 811 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 812 | const uint8_t RemainOnChannelMessage::kCommand = NL80211_CMD_REMAIN_ON_CHANNEL; |
| 813 | const char RemainOnChannelMessage::kCommandString[] = |
| 814 | "NL80211_CMD_REMAIN_ON_CHANNEL"; |
| 815 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 816 | const uint8_t RoamMessage::kCommand = NL80211_CMD_ROAM; |
| 817 | const char RoamMessage::kCommandString[] = "NL80211_CMD_ROAM"; |
| 818 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 819 | const uint8_t ScanAbortedMessage::kCommand = NL80211_CMD_SCAN_ABORTED; |
| 820 | const char ScanAbortedMessage::kCommandString[] = "NL80211_CMD_SCAN_ABORTED"; |
| 821 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 822 | const uint8_t TriggerScanMessage::kCommand = NL80211_CMD_TRIGGER_SCAN; |
| 823 | const char TriggerScanMessage::kCommandString[] = "NL80211_CMD_TRIGGER_SCAN"; |
| 824 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 825 | const uint8_t UnknownMessage::kCommand = 0xff; |
| 826 | const char UnknownMessage::kCommandString[] = "<Unknown Message Type>"; |
| 827 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 828 | const uint8_t UnprotDeauthenticateMessage::kCommand = |
| 829 | NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 830 | const char UnprotDeauthenticateMessage::kCommandString[] = |
| 831 | "NL80211_CMD_UNPROT_DEAUTHENTICATE"; |
| 832 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 833 | const uint8_t UnprotDisassociateMessage::kCommand = |
| 834 | NL80211_CMD_UNPROT_DISASSOCIATE; |
| 835 | const char UnprotDisassociateMessage::kCommandString[] = |
| 836 | "NL80211_CMD_UNPROT_DISASSOCIATE"; |
| 837 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 838 | // |
| 839 | // Factory class. |
| 840 | // |
| 841 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame^] | 842 | NetlinkMessage *NetlinkMessageFactory::CreateMessage(nlmsghdr *msg) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 843 | if (!msg) { |
| 844 | LOG(ERROR) << "NULL |msg| parameter"; |
| 845 | return NULL; |
| 846 | } |
| 847 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame^] | 848 | scoped_ptr<NetlinkMessage> message; |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 849 | void *payload = nlmsg_data(msg); |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 850 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 851 | if (msg->nlmsg_type == NLMSG_NOOP) { |
| 852 | SLOG(WiFi, 6) << "Creating a NOP message"; |
| 853 | message.reset(new NoopMessage()); |
| 854 | } else if (msg->nlmsg_type == NLMSG_ERROR) { |
| 855 | uint32_t error_code = *(reinterpret_cast<uint32_t *>(payload)); |
| 856 | if (error_code) { |
| 857 | SLOG(WiFi, 6) << "Creating an ERROR message:" << error_code; |
| 858 | message.reset(new ErrorMessage(error_code)); |
| 859 | } else { |
| 860 | SLOG(WiFi, 6) << "Creating an ACK message"; |
| 861 | message.reset(new AckMessage()); |
| 862 | } |
| 863 | } else { |
| 864 | SLOG(WiFi, 6) << "Creating a Regular message"; |
| 865 | genlmsghdr *gnlh = reinterpret_cast<genlmsghdr *>(payload); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 866 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 867 | switch (gnlh->cmd) { |
| 868 | case AssociateMessage::kCommand: |
| 869 | message.reset(new AssociateMessage()); break; |
| 870 | case AuthenticateMessage::kCommand: |
| 871 | message.reset(new AuthenticateMessage()); break; |
| 872 | case CancelRemainOnChannelMessage::kCommand: |
| 873 | message.reset(new CancelRemainOnChannelMessage()); break; |
| 874 | case ConnectMessage::kCommand: |
| 875 | message.reset(new ConnectMessage()); break; |
| 876 | case DeauthenticateMessage::kCommand: |
| 877 | message.reset(new DeauthenticateMessage()); break; |
| 878 | case DeleteStationMessage::kCommand: |
| 879 | message.reset(new DeleteStationMessage()); break; |
| 880 | case DisassociateMessage::kCommand: |
| 881 | message.reset(new DisassociateMessage()); break; |
| 882 | case DisconnectMessage::kCommand: |
| 883 | message.reset(new DisconnectMessage()); break; |
| 884 | case FrameTxStatusMessage::kCommand: |
| 885 | message.reset(new FrameTxStatusMessage()); break; |
| 886 | case GetRegMessage::kCommand: |
| 887 | message.reset(new GetRegMessage()); break; |
| 888 | case JoinIbssMessage::kCommand: |
| 889 | message.reset(new JoinIbssMessage()); break; |
| 890 | case MichaelMicFailureMessage::kCommand: |
| 891 | message.reset(new MichaelMicFailureMessage()); break; |
| 892 | case NewScanResultsMessage::kCommand: |
| 893 | message.reset(new NewScanResultsMessage()); break; |
| 894 | case NewStationMessage::kCommand: |
| 895 | message.reset(new NewStationMessage()); break; |
| 896 | case NewWifiMessage::kCommand: |
| 897 | message.reset(new NewWifiMessage()); break; |
| 898 | case NotifyCqmMessage::kCommand: |
| 899 | message.reset(new NotifyCqmMessage()); break; |
| 900 | case PmksaCandidateMessage::kCommand: |
| 901 | message.reset(new PmksaCandidateMessage()); break; |
| 902 | case RegBeaconHintMessage::kCommand: |
| 903 | message.reset(new RegBeaconHintMessage()); break; |
| 904 | case RegChangeMessage::kCommand: |
| 905 | message.reset(new RegChangeMessage()); break; |
| 906 | case RemainOnChannelMessage::kCommand: |
| 907 | message.reset(new RemainOnChannelMessage()); break; |
| 908 | case RoamMessage::kCommand: |
| 909 | message.reset(new RoamMessage()); break; |
| 910 | case ScanAbortedMessage::kCommand: |
| 911 | message.reset(new ScanAbortedMessage()); break; |
| 912 | case TriggerScanMessage::kCommand: |
| 913 | message.reset(new TriggerScanMessage()); break; |
| 914 | case UnprotDeauthenticateMessage::kCommand: |
| 915 | message.reset(new UnprotDeauthenticateMessage()); break; |
| 916 | case UnprotDisassociateMessage::kCommand: |
| 917 | message.reset(new UnprotDisassociateMessage()); break; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 918 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 919 | default: |
| 920 | message.reset(new UnknownMessage(gnlh->cmd)); break; |
| 921 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 922 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 923 | if (!message->InitFromNlmsg(msg)) { |
| 924 | LOG(ERROR) << "Message did not initialize properly"; |
| 925 | return NULL; |
| 926 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 929 | return message.release(); |
| 930 | } |
| 931 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 932 | Nl80211MessageDataCollector * |
| 933 | Nl80211MessageDataCollector::GetInstance() { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 934 | return g_datacollector.Pointer(); |
| 935 | } |
| 936 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 937 | Nl80211MessageDataCollector::Nl80211MessageDataCollector() { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 938 | need_to_print[NL80211_ATTR_PMKSA_CANDIDATE] = true; |
| 939 | need_to_print[NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL] = true; |
| 940 | need_to_print[NL80211_CMD_DEL_STATION] = true; |
| 941 | need_to_print[NL80211_CMD_FRAME_TX_STATUS] = true; |
| 942 | need_to_print[NL80211_CMD_JOIN_IBSS] = true; |
| 943 | need_to_print[NL80211_CMD_MICHAEL_MIC_FAILURE] = true; |
| 944 | need_to_print[NL80211_CMD_NEW_WIPHY] = true; |
| 945 | need_to_print[NL80211_CMD_REG_BEACON_HINT] = true; |
| 946 | need_to_print[NL80211_CMD_REG_CHANGE] = true; |
| 947 | need_to_print[NL80211_CMD_REMAIN_ON_CHANNEL] = true; |
| 948 | need_to_print[NL80211_CMD_ROAM] = true; |
| 949 | need_to_print[NL80211_CMD_SCAN_ABORTED] = true; |
| 950 | need_to_print[NL80211_CMD_UNPROT_DEAUTHENTICATE] = true; |
| 951 | need_to_print[NL80211_CMD_UNPROT_DISASSOCIATE] = true; |
| 952 | } |
| 953 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 954 | void Nl80211MessageDataCollector::CollectDebugData( |
| 955 | const Nl80211Message &message, nlmsghdr *msg) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 956 | if (!msg) { |
| 957 | LOG(ERROR) << "NULL |msg| parameter"; |
| 958 | return; |
| 959 | } |
| 960 | |
| 961 | bool doit = false; |
| 962 | |
| 963 | map<uint8_t, bool>::const_iterator node; |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 964 | node = need_to_print.find(message.command()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 965 | if (node != need_to_print.end()) |
| 966 | doit = node->second; |
| 967 | |
| 968 | if (doit) { |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 969 | LOG(INFO) << "@@const unsigned char " |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 970 | << "k" << message.command_string() |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 971 | << "[] = {"; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 972 | |
Christopher Wiley | efd521f | 2012-11-07 17:32:46 -0800 | [diff] [blame] | 973 | int payload_bytes = nlmsg_datalen(msg); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 974 | |
| 975 | size_t bytes = nlmsg_total_size(payload_bytes); |
| 976 | unsigned char *rawdata = reinterpret_cast<unsigned char *>(msg); |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 977 | for (size_t i = 0; i < bytes; ++i) { |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 978 | LOG(INFO) << " 0x" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 979 | << std::hex << std::setfill('0') << std::setw(2) |
| 980 | << + rawdata[i] << ","; |
| 981 | } |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 982 | LOG(INFO) << "};"; |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 983 | need_to_print[message.command()] = false; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 984 | } |
| 985 | } |
| 986 | |
| 987 | } // namespace shill. |