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 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 27 | #include <netlink/msg.h> |
| 28 | #include <netlink/netlink.h> |
| 29 | |
Wade Guthrie | 92d0636 | 2013-04-25 15:41:30 -0700 | [diff] [blame] | 30 | #include <limits> |
Wade Guthrie | 89e6cb3 | 2013-03-07 08:03:45 -0800 | [diff] [blame] | 31 | #include <map> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 32 | #include <string> |
Wade Guthrie | 89e6cb3 | 2013-03-07 08:03:45 -0800 | [diff] [blame] | 33 | #include <vector> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 34 | |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 35 | #include <base/bind.h> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 36 | #include <base/stringprintf.h> |
| 37 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 38 | #include "shill/attribute_list.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 39 | #include "shill/ieee80211.h" |
| 40 | #include "shill/logging.h" |
Wade Guthrie | f162f8b | 2013-02-27 14:13:55 -0800 | [diff] [blame] | 41 | #include "shill/netlink_attribute.h" |
Wade Guthrie | 2193b23 | 2013-06-05 17:09:07 -0700 | [diff] [blame] | 42 | #include "shill/nl80211_attribute.h" // For Nl80211AttributeMac |
Wade Guthrie | 89e6cb3 | 2013-03-07 08:03:45 -0800 | [diff] [blame] | 43 | #include "shill/refptr_types.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 44 | |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 45 | using base::Bind; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 46 | using base::LazyInstance; |
| 47 | using base::StringAppendF; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 48 | using std::map; |
| 49 | using std::string; |
| 50 | using std::vector; |
| 51 | |
| 52 | namespace shill { |
| 53 | |
| 54 | namespace { |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 55 | LazyInstance<Nl80211MessageDataCollector> g_datacollector = |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 56 | LAZY_INSTANCE_INITIALIZER; |
| 57 | } // namespace |
| 58 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 59 | const uint8_t Nl80211Frame::kMinimumFrameByteCount = 26; |
| 60 | const uint8_t Nl80211Frame::kFrameTypeMask = 0xfc; |
| 61 | |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 62 | const char Nl80211Message::kMessageTypeString[] = "nl80211"; |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 63 | map<uint16_t, string> *Nl80211Message::reason_code_string_ = NULL; |
| 64 | map<uint16_t, string> *Nl80211Message::status_code_string_ = NULL; |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 65 | uint16_t Nl80211Message::nl80211_message_type_ = kIllegalMessageType; |
| 66 | |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 67 | // static |
Paul Stewart | 2ddf2c6 | 2013-04-16 09:47:34 -0700 | [diff] [blame] | 68 | uint16_t Nl80211Message::GetMessageType() { |
| 69 | return nl80211_message_type_; |
| 70 | } |
| 71 | |
| 72 | // static |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 73 | void Nl80211Message::SetMessageType(uint16_t message_type) { |
| 74 | if (message_type == NetlinkMessage::kIllegalMessageType) { |
| 75 | LOG(FATAL) << "Absolutely need a legal message type for Nl80211 messages."; |
| 76 | } |
| 77 | nl80211_message_type_ = message_type; |
| 78 | } |
| 79 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 80 | bool Nl80211Message::InitFromNlmsg(const nlmsghdr *const_msg) { |
| 81 | if (!const_msg) { |
| 82 | LOG(ERROR) << "Null |msg| parameter"; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 83 | return false; |
| 84 | } |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 85 | ByteString message(reinterpret_cast<const unsigned char *>(const_msg), |
| 86 | const_msg->nlmsg_len); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 87 | |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 88 | if (!InitAndStripHeader(&message)) { |
| 89 | return false; |
| 90 | } |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 91 | |
| 92 | // Attributes. |
| 93 | // Parse the attributes from the nl message payload into the 'tb' array. |
| 94 | nlattr *tb[NL80211_ATTR_MAX + 1]; |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 95 | nla_parse(tb, NL80211_ATTR_MAX, |
| 96 | reinterpret_cast<nlattr *>(message.GetData()), message.GetLength(), |
| 97 | NULL); |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 98 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 99 | for (int i = 0; i < NL80211_ATTR_MAX + 1; ++i) { |
| 100 | if (tb[i]) { |
Wade Guthrie | efe1f0c | 2013-02-26 17:42:01 -0800 | [diff] [blame] | 101 | attributes_->CreateAndInitAttribute( |
Wade Guthrie | 68da97c | 2013-02-26 13:09:35 -0800 | [diff] [blame] | 102 | i, tb[i], Bind(&NetlinkAttribute::NewNl80211AttributeFromId)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
| 106 | // Convert integer values provided by libnl (for example, from the |
| 107 | // NL80211_ATTR_STATUS_CODE or NL80211_ATTR_REASON_CODE attribute) into |
| 108 | // strings describing the status. |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 109 | if (!reason_code_string_) { |
| 110 | reason_code_string_ = new map<uint16_t, string>; |
| 111 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnspecified] = |
| 112 | "Unspecified reason"; |
| 113 | (*reason_code_string_)[ |
| 114 | IEEE_80211::kReasonCodePreviousAuthenticationInvalid] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 115 | "Previous authentication no longer valid"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 116 | (*reason_code_string_)[IEEE_80211::kReasonCodeSenderHasLeft] = |
| 117 | "Deauthentcated because sending STA is leaving (or has left) IBSS or " |
| 118 | "ESS"; |
| 119 | (*reason_code_string_)[IEEE_80211::kReasonCodeInactivity] = |
| 120 | "Disassociated due to inactivity"; |
| 121 | (*reason_code_string_)[IEEE_80211::kReasonCodeTooManySTAs] = |
| 122 | "Disassociated because AP is unable to handle all currently associated " |
| 123 | "STAs"; |
| 124 | (*reason_code_string_)[IEEE_80211::kReasonCodeNonAuthenticated] = |
| 125 | "Class 2 frame received from nonauthenticated STA"; |
| 126 | (*reason_code_string_)[IEEE_80211::kReasonCodeNonAssociated] = |
| 127 | "Class 3 frame received from nonassociated STA"; |
| 128 | (*reason_code_string_)[IEEE_80211::kReasonCodeDisassociatedHasLeft] = |
| 129 | "Disassociated because sending STA is leaving (or has left) BSS"; |
| 130 | (*reason_code_string_)[ |
| 131 | IEEE_80211::kReasonCodeReassociationNotAuthenticated] = |
| 132 | "STA requesting (re)association is not authenticated with responding " |
| 133 | "STA"; |
| 134 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnacceptablePowerCapability] = |
| 135 | "Disassociated because the information in the Power Capability " |
| 136 | "element is unacceptable"; |
| 137 | (*reason_code_string_)[ |
| 138 | IEEE_80211::kReasonCodeUnacceptableSupportedChannelInfo] = |
| 139 | "Disassociated because the information in the Supported Channels " |
| 140 | "element is unacceptable"; |
| 141 | (*reason_code_string_)[IEEE_80211::kReasonCodeInvalidInfoElement] = |
| 142 | "Invalid information element, i.e., an information element defined in " |
| 143 | "this standard for which the content does not meet the specifications " |
| 144 | "in Clause 7"; |
| 145 | (*reason_code_string_)[IEEE_80211::kReasonCodeMICFailure] = |
| 146 | "Message integrity code (MIC) failure"; |
| 147 | (*reason_code_string_)[IEEE_80211::kReasonCode4WayTimeout] = |
| 148 | "4-Way Handshake timeout"; |
| 149 | (*reason_code_string_)[IEEE_80211::kReasonCodeGroupKeyHandshakeTimeout] = |
| 150 | "Group Key Handshake timeout"; |
| 151 | (*reason_code_string_)[IEEE_80211::kReasonCodeDifferenIE] = |
| 152 | "Information element in 4-Way Handshake different from " |
| 153 | "(Re)Association Request/Probe Response/Beacon frame"; |
| 154 | (*reason_code_string_)[IEEE_80211::kReasonCodeGroupCipherInvalid] = |
| 155 | "Invalid group cipher"; |
| 156 | (*reason_code_string_)[IEEE_80211::kReasonCodePairwiseCipherInvalid] = |
| 157 | "Invalid pairwise cipher"; |
| 158 | (*reason_code_string_)[IEEE_80211::kReasonCodeAkmpInvalid] = |
| 159 | "Invalid AKMP"; |
| 160 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnsupportedRsnIeVersion] = |
| 161 | "Unsupported RSN information element version"; |
| 162 | (*reason_code_string_)[IEEE_80211::kReasonCodeInvalidRsnIeCaps] = |
| 163 | "Invalid RSN information element capabilities"; |
| 164 | (*reason_code_string_)[IEEE_80211::kReasonCode8021XAuth] = |
| 165 | "IEEE 802.1X authentication failed"; |
| 166 | (*reason_code_string_)[IEEE_80211::kReasonCodeCipherSuiteRejected] = |
| 167 | "Cipher suite rejected because of the security policy"; |
| 168 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnspecifiedQoS] = |
| 169 | "Disassociated for unspecified, QoS-related reason"; |
| 170 | (*reason_code_string_)[IEEE_80211::kReasonCodeQoSBandwidth] = |
| 171 | "Disassociated because QoS AP lacks sufficient bandwidth for this " |
| 172 | "QoS STA"; |
| 173 | (*reason_code_string_)[IEEE_80211::kReasonCodeiPoorConditions] = |
| 174 | "Disassociated because excessive number of frames need to be " |
| 175 | "acknowledged, but are not acknowledged due to AP transmissions " |
| 176 | "and/or poor channel conditions"; |
| 177 | (*reason_code_string_)[IEEE_80211::kReasonCodeOutsideTxop] = |
| 178 | "Disassociated because STA is transmitting outside the limits of its " |
| 179 | "TXOPs"; |
| 180 | (*reason_code_string_)[IEEE_80211::kReasonCodeStaLeaving] = |
| 181 | "Requested from peer STA as the STA is leaving the BSS (or resetting)"; |
| 182 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnacceptableMechanism] = |
| 183 | "Requested from peer STA as it does not want to use the mechanism"; |
| 184 | (*reason_code_string_)[IEEE_80211::kReasonCodeSetupRequired] = |
| 185 | "Requested from peer STA as the STA received frames using the " |
| 186 | "mechanism for which a setup is required"; |
| 187 | (*reason_code_string_)[IEEE_80211::kReasonCodeTimeout] = |
| 188 | "Requested from peer STA due to timeout"; |
| 189 | (*reason_code_string_)[IEEE_80211::kReasonCodeCipherSuiteNotSupported] = |
| 190 | "Peer STA does not support the requested cipher suite"; |
| 191 | (*reason_code_string_)[IEEE_80211::kReasonCodeInvalid] = "<INVALID REASON>"; |
| 192 | } |
| 193 | |
| 194 | if (!status_code_string_) { |
| 195 | status_code_string_ = new map<uint16_t, string>; |
| 196 | (*status_code_string_)[IEEE_80211::kStatusCodeSuccessful] = "Successful"; |
| 197 | (*status_code_string_)[IEEE_80211::kStatusCodeFailure] = |
| 198 | "Unspecified failure"; |
| 199 | (*status_code_string_)[IEEE_80211::kStatusCodeAllCapabilitiesNotSupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 200 | "Cannot support all requested capabilities in the capability " |
| 201 | "information field"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 202 | (*status_code_string_)[IEEE_80211::kStatusCodeCantConfirmAssociation] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 203 | "Reassociation denied due to inability to confirm that association " |
| 204 | "exists"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 205 | (*status_code_string_)[IEEE_80211::kStatusCodeAssociationDenied] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 206 | "Association denied due to reason outside the scope of this standard"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 207 | (*status_code_string_)[ |
| 208 | IEEE_80211::kStatusCodeAuthenticationUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 209 | "Responding station does not support the specified authentication " |
| 210 | "algorithm"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 211 | (*status_code_string_)[IEEE_80211::kStatusCodeOutOfSequence] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 212 | "Received an authentication frame with authentication transaction " |
| 213 | "sequence number out of expected sequence"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 214 | (*status_code_string_)[IEEE_80211::kStatusCodeChallengeFailure] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 215 | "Authentication rejected because of challenge failure"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 216 | (*status_code_string_)[IEEE_80211::kStatusCodeFrameTimeout] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 217 | "Authentication rejected due to timeout waiting for next frame in " |
| 218 | "sequence"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 219 | (*status_code_string_)[IEEE_80211::kStatusCodeMaxSta] = |
| 220 | "Association denied because AP is unable to handle additional " |
| 221 | "associated STA"; |
| 222 | (*status_code_string_)[IEEE_80211::kStatusCodeDataRateUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 223 | "Association denied due to requesting station not supporting all of " |
| 224 | "the data rates in the BSSBasicRateSet parameter"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 225 | (*status_code_string_)[IEEE_80211::kStatusCodeShortPreambleUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 226 | "Association denied due to requesting station not supporting the " |
| 227 | "short preamble option"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 228 | (*status_code_string_)[IEEE_80211::kStatusCodePbccUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 229 | "Association denied due to requesting station not supporting the PBCC " |
| 230 | "modulation option"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 231 | (*status_code_string_)[ |
| 232 | IEEE_80211::kStatusCodeChannelAgilityUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 233 | "Association denied due to requesting station not supporting the " |
| 234 | "channel agility option"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 235 | (*status_code_string_)[IEEE_80211::kStatusCodeNeedSpectrumManagement] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 236 | "Association request rejected because Spectrum Management capability " |
| 237 | "is required"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 238 | (*status_code_string_)[ |
| 239 | IEEE_80211::kStatusCodeUnacceptablePowerCapability] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 240 | "Association request rejected because the information in the Power " |
| 241 | "Capability element is unacceptable"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 242 | (*status_code_string_)[ |
| 243 | IEEE_80211::kStatusCodeUnacceptableSupportedChannelInfo] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 244 | "Association request rejected because the information in the " |
| 245 | "Supported Channels element is unacceptable"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 246 | (*status_code_string_)[IEEE_80211::kStatusCodeShortTimeSlotRequired] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 247 | "Association request rejected due to requesting station not " |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 248 | "supporting the Short Slot Time option"; |
| 249 | (*status_code_string_)[IEEE_80211::kStatusCodeDssOfdmRequired] = |
| 250 | "Association request rejected due to requesting station not " |
| 251 | "supporting the DSSS-OFDM option"; |
| 252 | (*status_code_string_)[IEEE_80211::kStatusCodeQosFailure] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 253 | "Unspecified, QoS related failure"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 254 | (*status_code_string_)[ |
| 255 | IEEE_80211::kStatusCodeInsufficientBandwithForQsta] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 256 | "Association denied due to QAP having insufficient bandwidth to handle " |
| 257 | "another QSTA"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 258 | (*status_code_string_)[IEEE_80211::kStatusCodePoorConditions] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 259 | "Association denied due to poor channel conditions"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 260 | (*status_code_string_)[IEEE_80211::kStatusCodeQosNotSupported] = |
| 261 | "Association (with QoS BSS) denied due to requesting station not " |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 262 | "supporting the QoS facility"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 263 | (*status_code_string_)[IEEE_80211::kStatusCodeDeclined] = |
| 264 | "The request has been declined"; |
| 265 | (*status_code_string_)[IEEE_80211::kStatusCodeInvalidParameterValues] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 266 | "The request has not been successful as one or more parameters have " |
| 267 | "invalid values"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 268 | (*status_code_string_)[IEEE_80211::kStatusCodeCannotBeHonored] = |
| 269 | "The TS has not been created because the request cannot be honored. " |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 270 | "However, a suggested Tspec is provided so that the initiating QSTA " |
| 271 | "may attempt to send another TS with the suggested changes to the " |
| 272 | "TSpec"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 273 | (*status_code_string_)[IEEE_80211::kStatusCodeInvalidInfoElement] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 274 | "Invalid Information Element"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 275 | (*status_code_string_)[IEEE_80211::kStatusCodeGroupCipherInvalid] = |
| 276 | "Invalid Group Cipher"; |
| 277 | (*status_code_string_)[IEEE_80211::kStatusCodePairwiseCipherInvalid] = |
| 278 | "Invalid Pairwise Cipher"; |
| 279 | (*status_code_string_)[IEEE_80211::kStatusCodeAkmpInvalid] = "Invalid AKMP"; |
| 280 | (*status_code_string_)[IEEE_80211::kStatusCodeUnsupportedRsnIeVersion] = |
| 281 | "Unsupported RSN Information Element version"; |
| 282 | (*status_code_string_)[IEEE_80211::kStatusCodeInvalidRsnIeCaps] = |
| 283 | "Invalid RSN Information Element Capabilities"; |
| 284 | (*status_code_string_)[IEEE_80211::kStatusCodeCipherSuiteRejected] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 285 | "Cipher suite is rejected per security policy"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 286 | (*status_code_string_)[IEEE_80211::kStatusCodeTsDelayNotMet] = |
| 287 | "The TS has not been created. However, the HC may be capable of " |
| 288 | "creating a TS, in response to a request, after the time indicated in " |
| 289 | "the TS Delay element"; |
| 290 | (*status_code_string_)[IEEE_80211::kStatusCodeDirectLinkIllegal] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 291 | "Direct link is not allowed in the BSS by policy"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 292 | (*status_code_string_)[IEEE_80211::kStatusCodeStaNotInBss] = |
| 293 | "Destination STA is not present within this BSS"; |
| 294 | (*status_code_string_)[IEEE_80211::kStatusCodeStaNotInQsta] = |
| 295 | "The destination STA is not a QoS STA"; |
| 296 | (*status_code_string_)[IEEE_80211::kStatusCodeExcessiveListenInterval] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 297 | "Association denied because Listen Interval is too large"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 298 | (*status_code_string_)[IEEE_80211::kStatusCodeInvalid] = "<INVALID STATUS>"; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | return true; |
| 302 | } |
| 303 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 304 | // static |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 305 | string Nl80211Message::StringFromReason(uint16_t status) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 306 | map<uint16_t, string>::const_iterator match; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 307 | match = reason_code_string_->find(status); |
| 308 | if (match == reason_code_string_->end()) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 309 | string output; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 310 | if (status < IEEE_80211::kReasonCodeMax) { |
| 311 | StringAppendF(&output, "<Reserved Reason:%u>", status); |
| 312 | } else { |
| 313 | StringAppendF(&output, "<Unknown Reason:%u>", status); |
| 314 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 315 | return output; |
| 316 | } |
| 317 | return match->second; |
| 318 | } |
| 319 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 320 | // static |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 321 | string Nl80211Message::StringFromStatus(uint16_t status) { |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 322 | map<uint16_t, string>::const_iterator match; |
| 323 | match = status_code_string_->find(status); |
| 324 | if (match == status_code_string_->end()) { |
| 325 | string output; |
| 326 | if (status < IEEE_80211::kStatusCodeMax) { |
| 327 | StringAppendF(&output, "<Reserved Status:%u>", status); |
| 328 | } else { |
| 329 | StringAppendF(&output, "<Unknown Status:%u>", status); |
| 330 | } |
| 331 | return output; |
| 332 | } |
| 333 | return match->second; |
| 334 | } |
| 335 | |
Wade Guthrie | 7187247 | 2013-03-05 10:33:38 -0800 | [diff] [blame] | 336 | // Nl80211Frame |
| 337 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 338 | Nl80211Frame::Nl80211Frame(const ByteString &raw_frame) |
Wade Guthrie | 92d0636 | 2013-04-25 15:41:30 -0700 | [diff] [blame] | 339 | : frame_type_(kIllegalFrameType), |
| 340 | reason_(std::numeric_limits<uint16_t>::max()), |
| 341 | status_(std::numeric_limits<uint16_t>::max()), |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 342 | frame_(raw_frame) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 343 | const IEEE_80211::ieee80211_frame *frame = |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 344 | reinterpret_cast<const IEEE_80211::ieee80211_frame *>( |
| 345 | frame_.GetConstData()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 346 | |
| 347 | // Now, let's populate the other stuff. |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 348 | if (frame_.GetLength() >= kMinimumFrameByteCount) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 349 | mac_from_ = |
Wade Guthrie | 2193b23 | 2013-06-05 17:09:07 -0700 | [diff] [blame] | 350 | Nl80211AttributeMac::StringFromMacAddress(&frame->destination_mac[0]); |
| 351 | mac_to_ = Nl80211AttributeMac::StringFromMacAddress(&frame->source_mac[0]); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 352 | frame_type_ = frame->frame_control & kFrameTypeMask; |
| 353 | |
| 354 | switch (frame_type_) { |
| 355 | case kAssocResponseFrameType: |
| 356 | case kReassocResponseFrameType: |
| 357 | status_ = le16toh(frame->u.associate_response.status_code); |
| 358 | break; |
| 359 | |
| 360 | case kAuthFrameType: |
| 361 | status_ = le16toh(frame->u.authentiate_message.status_code); |
| 362 | break; |
| 363 | |
| 364 | case kDisassocFrameType: |
| 365 | case kDeauthFrameType: |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 366 | reason_ = le16toh(frame->u.deauthentiate_message.reason_code); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 367 | break; |
| 368 | |
| 369 | default: |
| 370 | break; |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 375 | bool Nl80211Frame::ToString(string *output) const { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 376 | if (!output) { |
| 377 | LOG(ERROR) << "NULL |output|"; |
| 378 | return false; |
| 379 | } |
| 380 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 381 | if (frame_.IsEmpty()) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 382 | output->append(" [no frame]"); |
| 383 | return true; |
| 384 | } |
| 385 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 386 | if (frame_.GetLength() < kMinimumFrameByteCount) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 387 | output->append(" [invalid frame: "); |
| 388 | } else { |
| 389 | StringAppendF(output, " %s -> %s", mac_from_.c_str(), mac_to_.c_str()); |
| 390 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 391 | switch (frame_.GetConstData()[0] & kFrameTypeMask) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 392 | case kAssocResponseFrameType: |
| 393 | StringAppendF(output, "; AssocResponse status: %u: %s", |
| 394 | status_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 395 | Nl80211Message::StringFromStatus(status_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 396 | break; |
| 397 | case kReassocResponseFrameType: |
| 398 | StringAppendF(output, "; ReassocResponse status: %u: %s", |
| 399 | status_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 400 | Nl80211Message::StringFromStatus(status_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 401 | break; |
| 402 | case kAuthFrameType: |
| 403 | StringAppendF(output, "; Auth status: %u: %s", |
| 404 | status_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 405 | Nl80211Message::StringFromStatus(status_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 406 | break; |
| 407 | |
| 408 | case kDisassocFrameType: |
| 409 | StringAppendF(output, "; Disassoc reason %u: %s", |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 410 | reason_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 411 | Nl80211Message::StringFromReason(reason_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 412 | break; |
| 413 | case kDeauthFrameType: |
| 414 | StringAppendF(output, "; Deauth reason %u: %s", |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 415 | reason_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 416 | Nl80211Message::StringFromReason(reason_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 417 | break; |
| 418 | |
| 419 | default: |
| 420 | break; |
| 421 | } |
| 422 | output->append(" [frame: "); |
| 423 | } |
| 424 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 425 | const unsigned char *frame = frame_.GetConstData(); |
| 426 | for (size_t i = 0; i < frame_.GetLength(); ++i) { |
| 427 | StringAppendF(output, "%02x, ", frame[i]); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 428 | } |
| 429 | output->append("]"); |
| 430 | |
| 431 | return true; |
| 432 | } |
| 433 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 434 | bool Nl80211Frame::IsEqual(const Nl80211Frame &other) const { |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 435 | return frame_.Equals(other.frame_); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | // |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 439 | // Specific Nl80211Message types. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 440 | // |
| 441 | |
| 442 | const uint8_t AssociateMessage::kCommand = NL80211_CMD_ASSOCIATE; |
| 443 | const char AssociateMessage::kCommandString[] = "NL80211_CMD_ASSOCIATE"; |
| 444 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 445 | const uint8_t AuthenticateMessage::kCommand = NL80211_CMD_AUTHENTICATE; |
| 446 | const char AuthenticateMessage::kCommandString[] = "NL80211_CMD_AUTHENTICATE"; |
| 447 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 448 | const uint8_t CancelRemainOnChannelMessage::kCommand = |
| 449 | NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL; |
| 450 | const char CancelRemainOnChannelMessage::kCommandString[] = |
| 451 | "NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL"; |
| 452 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 453 | const uint8_t ConnectMessage::kCommand = NL80211_CMD_CONNECT; |
| 454 | const char ConnectMessage::kCommandString[] = "NL80211_CMD_CONNECT"; |
| 455 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 456 | const uint8_t DeauthenticateMessage::kCommand = NL80211_CMD_DEAUTHENTICATE; |
| 457 | const char DeauthenticateMessage::kCommandString[] = |
| 458 | "NL80211_CMD_DEAUTHENTICATE"; |
| 459 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 460 | const uint8_t DeleteStationMessage::kCommand = NL80211_CMD_DEL_STATION; |
| 461 | const char DeleteStationMessage::kCommandString[] = "NL80211_CMD_DEL_STATION"; |
| 462 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 463 | const uint8_t DisassociateMessage::kCommand = NL80211_CMD_DISASSOCIATE; |
| 464 | const char DisassociateMessage::kCommandString[] = "NL80211_CMD_DISASSOCIATE"; |
| 465 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 466 | const uint8_t DisconnectMessage::kCommand = NL80211_CMD_DISCONNECT; |
| 467 | const char DisconnectMessage::kCommandString[] = "NL80211_CMD_DISCONNECT"; |
| 468 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 469 | const uint8_t FrameTxStatusMessage::kCommand = NL80211_CMD_FRAME_TX_STATUS; |
| 470 | const char FrameTxStatusMessage::kCommandString[] = |
| 471 | "NL80211_CMD_FRAME_TX_STATUS"; |
| 472 | |
repo sync | 0efa9f0 | 2012-12-28 13:40:20 -0800 | [diff] [blame] | 473 | const uint8_t GetRegMessage::kCommand = NL80211_CMD_GET_REG; |
| 474 | const char GetRegMessage::kCommandString[] = "NL80211_CMD_GET_REG"; |
| 475 | |
Wade Guthrie | 1f355e8 | 2013-04-11 15:46:12 -0700 | [diff] [blame] | 476 | const uint8_t GetWiphyMessage::kCommand = NL80211_CMD_GET_WIPHY; |
| 477 | const char GetWiphyMessage::kCommandString[] = "NL80211_CMD_GET_WIPHY"; |
| 478 | |
Wade Guthrie | 92d0636 | 2013-04-25 15:41:30 -0700 | [diff] [blame] | 479 | GetWiphyMessage::GetWiphyMessage() : Nl80211Message(kCommand, kCommandString) { |
| 480 | attributes()->CreateAttribute( |
| 481 | NL80211_ATTR_IFINDEX, Bind(&NetlinkAttribute::NewNl80211AttributeFromId)); |
| 482 | } |
| 483 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 484 | const uint8_t JoinIbssMessage::kCommand = NL80211_CMD_JOIN_IBSS; |
| 485 | const char JoinIbssMessage::kCommandString[] = "NL80211_CMD_JOIN_IBSS"; |
| 486 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 487 | const uint8_t MichaelMicFailureMessage::kCommand = |
| 488 | NL80211_CMD_MICHAEL_MIC_FAILURE; |
| 489 | const char MichaelMicFailureMessage::kCommandString[] = |
| 490 | "NL80211_CMD_MICHAEL_MIC_FAILURE"; |
| 491 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 492 | const uint8_t NewScanResultsMessage::kCommand = NL80211_CMD_NEW_SCAN_RESULTS; |
| 493 | const char NewScanResultsMessage::kCommandString[] = |
| 494 | "NL80211_CMD_NEW_SCAN_RESULTS"; |
| 495 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 496 | const uint8_t NewStationMessage::kCommand = NL80211_CMD_NEW_STATION; |
| 497 | const char NewStationMessage::kCommandString[] = "NL80211_CMD_NEW_STATION"; |
| 498 | |
Wade Guthrie | 1f355e8 | 2013-04-11 15:46:12 -0700 | [diff] [blame] | 499 | const uint8_t NewWiphyMessage::kCommand = NL80211_CMD_NEW_WIPHY; |
| 500 | const char NewWiphyMessage::kCommandString[] = "NL80211_CMD_NEW_WIPHY"; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 501 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 502 | const uint8_t NotifyCqmMessage::kCommand = NL80211_CMD_NOTIFY_CQM; |
| 503 | const char NotifyCqmMessage::kCommandString[] = "NL80211_CMD_NOTIFY_CQM"; |
| 504 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 505 | const uint8_t PmksaCandidateMessage::kCommand = NL80211_ATTR_PMKSA_CANDIDATE; |
| 506 | const char PmksaCandidateMessage::kCommandString[] = |
| 507 | "NL80211_ATTR_PMKSA_CANDIDATE"; |
| 508 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 509 | const uint8_t RegBeaconHintMessage::kCommand = NL80211_CMD_REG_BEACON_HINT; |
| 510 | const char RegBeaconHintMessage::kCommandString[] = |
| 511 | "NL80211_CMD_REG_BEACON_HINT"; |
| 512 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 513 | const uint8_t RegChangeMessage::kCommand = NL80211_CMD_REG_CHANGE; |
| 514 | const char RegChangeMessage::kCommandString[] = "NL80211_CMD_REG_CHANGE"; |
| 515 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 516 | const uint8_t RemainOnChannelMessage::kCommand = NL80211_CMD_REMAIN_ON_CHANNEL; |
| 517 | const char RemainOnChannelMessage::kCommandString[] = |
| 518 | "NL80211_CMD_REMAIN_ON_CHANNEL"; |
| 519 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 520 | const uint8_t RoamMessage::kCommand = NL80211_CMD_ROAM; |
| 521 | const char RoamMessage::kCommandString[] = "NL80211_CMD_ROAM"; |
| 522 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 523 | const uint8_t ScanAbortedMessage::kCommand = NL80211_CMD_SCAN_ABORTED; |
| 524 | const char ScanAbortedMessage::kCommandString[] = "NL80211_CMD_SCAN_ABORTED"; |
| 525 | |
Wade Guthrie | 7187247 | 2013-03-05 10:33:38 -0800 | [diff] [blame] | 526 | const uint8_t GetScanMessage::kCommand = NL80211_CMD_GET_SCAN; |
| 527 | const char GetScanMessage::kCommandString[] = "NL80211_CMD_GET_SCAN"; |
| 528 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 529 | const uint8_t TriggerScanMessage::kCommand = NL80211_CMD_TRIGGER_SCAN; |
| 530 | const char TriggerScanMessage::kCommandString[] = "NL80211_CMD_TRIGGER_SCAN"; |
| 531 | |
Wade Guthrie | b9c3feb | 2013-04-25 16:31:19 -0700 | [diff] [blame] | 532 | TriggerScanMessage::TriggerScanMessage() |
Wade Guthrie | 2623f1a | 2013-05-14 15:14:54 -0700 | [diff] [blame] | 533 | : Nl80211Message(kCommand, kCommandString) { |
Wade Guthrie | b9c3feb | 2013-04-25 16:31:19 -0700 | [diff] [blame] | 534 | attributes()->CreateAttribute( |
| 535 | NL80211_ATTR_IFINDEX, Bind(&NetlinkAttribute::NewNl80211AttributeFromId)); |
| 536 | attributes()->CreateAttribute( |
| 537 | NL80211_ATTR_SCAN_FREQUENCIES, |
| 538 | Bind(&NetlinkAttribute::NewNl80211AttributeFromId)); |
| 539 | attributes()->CreateAttribute( |
| 540 | NL80211_ATTR_SCAN_SSIDS, |
| 541 | Bind(&NetlinkAttribute::NewNl80211AttributeFromId)); |
| 542 | } |
| 543 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 544 | const uint8_t UnprotDeauthenticateMessage::kCommand = |
| 545 | NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 546 | const char UnprotDeauthenticateMessage::kCommandString[] = |
| 547 | "NL80211_CMD_UNPROT_DEAUTHENTICATE"; |
| 548 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 549 | const uint8_t UnprotDisassociateMessage::kCommand = |
| 550 | NL80211_CMD_UNPROT_DISASSOCIATE; |
| 551 | const char UnprotDisassociateMessage::kCommandString[] = |
| 552 | "NL80211_CMD_UNPROT_DISASSOCIATE"; |
| 553 | |
Paul Stewart | 2ddf2c6 | 2013-04-16 09:47:34 -0700 | [diff] [blame] | 554 | GetInterfaceMessage::GetInterfaceMessage() |
| 555 | : Nl80211Message(kCommand, kCommandString) { |
| 556 | attributes()->CreateAttribute( |
| 557 | NL80211_ATTR_IFINDEX, Bind(&NetlinkAttribute::NewNl80211AttributeFromId)); |
| 558 | } |
| 559 | |
| 560 | const uint8_t GetInterfaceMessage::kCommand = NL80211_CMD_GET_INTERFACE; |
| 561 | const char GetInterfaceMessage::kCommandString[] = "NL80211_CMD_GET_INTERFACE"; |
| 562 | |
| 563 | const uint8_t NewInterfaceMessage::kCommand = NL80211_CMD_NEW_INTERFACE; |
| 564 | const char NewInterfaceMessage::kCommandString[] = "NL80211_CMD_NEW_INTERFACE"; |
| 565 | |
Wade Guthrie | 12f113a | 2013-03-12 17:15:46 -0700 | [diff] [blame] | 566 | // static |
| 567 | NetlinkMessage *Nl80211Message::CreateMessage(const nlmsghdr *const_msg) { |
| 568 | if (!const_msg) { |
| 569 | LOG(ERROR) << "NULL |const_msg| parameter"; |
| 570 | return NULL; |
| 571 | } |
| 572 | // Casting away constness since, while nlmsg_data doesn't change its |
| 573 | // parameter, it also doesn't declare its paramenter as const. |
| 574 | nlmsghdr *msg = const_cast<nlmsghdr *>(const_msg); |
| 575 | void *payload = nlmsg_data(msg); |
| 576 | genlmsghdr *gnlh = reinterpret_cast<genlmsghdr *>(payload); |
| 577 | scoped_ptr<NetlinkMessage> message; |
| 578 | |
| 579 | switch (gnlh->cmd) { |
| 580 | case AssociateMessage::kCommand: |
| 581 | return new AssociateMessage(); |
| 582 | case AuthenticateMessage::kCommand: |
| 583 | return new AuthenticateMessage(); |
| 584 | case CancelRemainOnChannelMessage::kCommand: |
| 585 | return new CancelRemainOnChannelMessage(); |
| 586 | case ConnectMessage::kCommand: |
| 587 | return new ConnectMessage(); |
| 588 | case DeauthenticateMessage::kCommand: |
| 589 | return new DeauthenticateMessage(); |
| 590 | case DeleteStationMessage::kCommand: |
| 591 | return new DeleteStationMessage(); |
| 592 | case DisassociateMessage::kCommand: |
| 593 | return new DisassociateMessage(); |
| 594 | case DisconnectMessage::kCommand: |
| 595 | return new DisconnectMessage(); |
| 596 | case FrameTxStatusMessage::kCommand: |
| 597 | return new FrameTxStatusMessage(); |
Paul Stewart | 2ddf2c6 | 2013-04-16 09:47:34 -0700 | [diff] [blame] | 598 | case GetInterfaceMessage::kCommand: |
| 599 | return new GetInterfaceMessage(); |
Wade Guthrie | 12f113a | 2013-03-12 17:15:46 -0700 | [diff] [blame] | 600 | case GetRegMessage::kCommand: |
| 601 | return new GetRegMessage(); |
Wade Guthrie | 1f355e8 | 2013-04-11 15:46:12 -0700 | [diff] [blame] | 602 | case GetWiphyMessage::kCommand: |
| 603 | return new GetWiphyMessage(); |
Wade Guthrie | 12f113a | 2013-03-12 17:15:46 -0700 | [diff] [blame] | 604 | case JoinIbssMessage::kCommand: |
| 605 | return new JoinIbssMessage(); |
| 606 | case MichaelMicFailureMessage::kCommand: |
| 607 | return new MichaelMicFailureMessage(); |
Paul Stewart | 2ddf2c6 | 2013-04-16 09:47:34 -0700 | [diff] [blame] | 608 | case NewInterfaceMessage::kCommand: |
| 609 | return new NewInterfaceMessage(); |
Wade Guthrie | 12f113a | 2013-03-12 17:15:46 -0700 | [diff] [blame] | 610 | case NewScanResultsMessage::kCommand: |
| 611 | return new NewScanResultsMessage(); |
| 612 | case NewStationMessage::kCommand: |
| 613 | return new NewStationMessage(); |
Wade Guthrie | 1f355e8 | 2013-04-11 15:46:12 -0700 | [diff] [blame] | 614 | case NewWiphyMessage::kCommand: |
| 615 | return new NewWiphyMessage(); |
Wade Guthrie | 12f113a | 2013-03-12 17:15:46 -0700 | [diff] [blame] | 616 | case NotifyCqmMessage::kCommand: |
| 617 | return new NotifyCqmMessage(); |
| 618 | case PmksaCandidateMessage::kCommand: |
| 619 | return new PmksaCandidateMessage(); |
| 620 | case RegBeaconHintMessage::kCommand: |
| 621 | return new RegBeaconHintMessage(); |
| 622 | case RegChangeMessage::kCommand: |
| 623 | return new RegChangeMessage(); |
| 624 | case RemainOnChannelMessage::kCommand: |
| 625 | return new RemainOnChannelMessage(); |
| 626 | case RoamMessage::kCommand: |
| 627 | return new RoamMessage(); |
| 628 | case ScanAbortedMessage::kCommand: |
| 629 | return new ScanAbortedMessage(); |
| 630 | case TriggerScanMessage::kCommand: |
| 631 | return new TriggerScanMessage(); |
| 632 | case UnprotDeauthenticateMessage::kCommand: |
| 633 | return new UnprotDeauthenticateMessage(); |
| 634 | case UnprotDisassociateMessage::kCommand: |
| 635 | return new UnprotDisassociateMessage(); |
| 636 | default: |
Wade Guthrie | 40d992c | 2013-04-19 11:10:11 -0700 | [diff] [blame] | 637 | LOG(WARNING) << StringPrintf( |
| 638 | "Unknown/unhandled netlink nl80211 message 0x%02x", gnlh->cmd); |
| 639 | return new UnknownNl80211Message(gnlh->cmd); |
Wade Guthrie | 12f113a | 2013-03-12 17:15:46 -0700 | [diff] [blame] | 640 | break; |
| 641 | } |
| 642 | return NULL; |
| 643 | } |
| 644 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 645 | // |
Wade Guthrie | 12f113a | 2013-03-12 17:15:46 -0700 | [diff] [blame] | 646 | // Data Collector |
| 647 | // |
| 648 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 649 | Nl80211MessageDataCollector * |
| 650 | Nl80211MessageDataCollector::GetInstance() { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 651 | return g_datacollector.Pointer(); |
| 652 | } |
| 653 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 654 | Nl80211MessageDataCollector::Nl80211MessageDataCollector() { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 655 | need_to_print[NL80211_ATTR_PMKSA_CANDIDATE] = true; |
| 656 | need_to_print[NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL] = true; |
| 657 | need_to_print[NL80211_CMD_DEL_STATION] = true; |
| 658 | need_to_print[NL80211_CMD_FRAME_TX_STATUS] = true; |
| 659 | need_to_print[NL80211_CMD_JOIN_IBSS] = true; |
| 660 | need_to_print[NL80211_CMD_MICHAEL_MIC_FAILURE] = true; |
| 661 | need_to_print[NL80211_CMD_NEW_WIPHY] = true; |
| 662 | need_to_print[NL80211_CMD_REG_BEACON_HINT] = true; |
| 663 | need_to_print[NL80211_CMD_REG_CHANGE] = true; |
| 664 | need_to_print[NL80211_CMD_REMAIN_ON_CHANNEL] = true; |
| 665 | need_to_print[NL80211_CMD_ROAM] = true; |
| 666 | need_to_print[NL80211_CMD_SCAN_ABORTED] = true; |
| 667 | need_to_print[NL80211_CMD_UNPROT_DEAUTHENTICATE] = true; |
| 668 | need_to_print[NL80211_CMD_UNPROT_DISASSOCIATE] = true; |
| 669 | } |
| 670 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 671 | void Nl80211MessageDataCollector::CollectDebugData( |
| 672 | const Nl80211Message &message, nlmsghdr *msg) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 673 | if (!msg) { |
| 674 | LOG(ERROR) << "NULL |msg| parameter"; |
| 675 | return; |
| 676 | } |
| 677 | |
| 678 | bool doit = false; |
| 679 | |
| 680 | map<uint8_t, bool>::const_iterator node; |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 681 | node = need_to_print.find(message.command()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 682 | if (node != need_to_print.end()) |
| 683 | doit = node->second; |
| 684 | |
| 685 | if (doit) { |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 686 | LOG(INFO) << "@@const unsigned char " |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 687 | << "k" << message.command_string() |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 688 | << "[] = {"; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 689 | |
Christopher Wiley | efd521f | 2012-11-07 17:32:46 -0800 | [diff] [blame] | 690 | int payload_bytes = nlmsg_datalen(msg); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 691 | |
| 692 | size_t bytes = nlmsg_total_size(payload_bytes); |
| 693 | unsigned char *rawdata = reinterpret_cast<unsigned char *>(msg); |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 694 | for (size_t i = 0; i < bytes; ++i) { |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 695 | LOG(INFO) << " 0x" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 696 | << std::hex << std::setfill('0') << std::setw(2) |
| 697 | << + rawdata[i] << ","; |
| 698 | } |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 699 | LOG(INFO) << "};"; |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 700 | need_to_print[message.command()] = false; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 701 | } |
| 702 | } |
| 703 | |
| 704 | } // namespace shill. |