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