Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | // |
| 5 | // This code is derived from the 'iw' source code. The copyright and license |
| 6 | // of that code is as follows: |
| 7 | // |
| 8 | // Copyright (c) 2007, 2008 Johannes Berg |
| 9 | // Copyright (c) 2007 Andy Lutomirski |
| 10 | // Copyright (c) 2007 Mike Kershaw |
| 11 | // Copyright (c) 2008-2009 Luis R. Rodriguez |
| 12 | // |
| 13 | // Permission to use, copy, modify, and/or distribute this software for any |
| 14 | // purpose with or without fee is hereby granted, provided that the above |
| 15 | // copyright notice and this permission notice appear in all copies. |
| 16 | // |
| 17 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 18 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 19 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 20 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 21 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 22 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 23 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 24 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 25 | #include "shill/nl80211_message.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 26 | |
| 27 | #include <ctype.h> |
| 28 | #include <endian.h> |
| 29 | #include <errno.h> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 30 | #include <linux/nl80211.h> |
| 31 | #include <net/if.h> |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 32 | #include <netinet/in.h> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 33 | #include <netlink/attr.h> |
| 34 | #include <netlink/genl/ctrl.h> |
| 35 | #include <netlink/genl/family.h> |
| 36 | #include <netlink/genl/genl.h> |
| 37 | #include <netlink/msg.h> |
| 38 | #include <netlink/netlink.h> |
| 39 | |
| 40 | #include <iomanip> |
| 41 | #include <string> |
| 42 | |
| 43 | #include <base/format_macros.h> |
| 44 | #include <base/stl_util.h> |
| 45 | #include <base/stringprintf.h> |
| 46 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 47 | #include "shill/attribute_list.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 48 | #include "shill/ieee80211.h" |
| 49 | #include "shill/logging.h" |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 50 | #include "shill/netlink_socket.h" |
repo sync | 1538d44 | 2012-12-20 15:24:35 -0800 | [diff] [blame] | 51 | #include "shill/nl80211_attribute.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 52 | #include "shill/scope_logger.h" |
| 53 | |
| 54 | using base::LazyInstance; |
| 55 | using base::StringAppendF; |
| 56 | using base::StringPrintf; |
| 57 | using std::map; |
| 58 | using std::string; |
| 59 | using std::vector; |
| 60 | |
| 61 | namespace shill { |
| 62 | |
| 63 | namespace { |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 64 | LazyInstance<Nl80211MessageDataCollector> g_datacollector = |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 65 | LAZY_INSTANCE_INITIALIZER; |
| 66 | } // namespace |
| 67 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 68 | const char Nl80211Message::kBogusMacAddress[]="XX:XX:XX:XX:XX:XX"; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 69 | |
| 70 | const uint8_t Nl80211Frame::kMinimumFrameByteCount = 26; |
| 71 | const uint8_t Nl80211Frame::kFrameTypeMask = 0xfc; |
| 72 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 73 | const uint32_t Nl80211Message::kIllegalMessage = 0; |
| 74 | const unsigned int Nl80211Message::kEthernetAddressBytes = 6; |
| 75 | map<uint16_t, string> *Nl80211Message::reason_code_string_ = NULL; |
| 76 | map<uint16_t, string> *Nl80211Message::status_code_string_ = NULL; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 77 | |
| 78 | // The nl messages look like this: |
| 79 | // |
| 80 | // XXXXXXXXXXXXXXXXXXX-nlmsg_total_size-XXXXXXXXXXXXXXXXXXX |
| 81 | // XXXXXXXXXXXXXXXXXXX-nlmsg_msg_size-XXXXXXXXXXXXXXXXXXX |
| 82 | // +-- gnhl nlmsg_tail(hdr) --+ |
| 83 | // | nlmsg_next(hdr) --+ |
| 84 | // v XXXXXXXXXXXX-nlmsg_len-XXXXXXXXXXXXXX V |
| 85 | // -----+-----+-+----------------------------------------------+-++---- |
| 86 | // ... | | | payload | || |
| 87 | // | | +------+-+--------+-+--------------------------+ || |
| 88 | // | nl | | | | | | attribs | || |
| 89 | // | msg |p| genl |p| family |p+------+-+-------+-+-------+p|| ... |
| 90 | // | hdr |a| msg |a| header |a| nl |p| pay |p| |a|| |
| 91 | // | |d| hdr |d| |d| attr |a| load |a| ... |d|| |
| 92 | // | | | | | | | |d| |d| | || |
| 93 | // -----+-----+-+----------------------------------------------+-++---- |
| 94 | // ^ ^ ^ ^ |
| 95 | // | | | XXXXXXX <-- nla_len(nlattr) |
| 96 | // | | | +-- nla_data(nlattr) |
| 97 | // | | X-nla_total_size-X |
| 98 | // | | XXXXX-nlmsg_attrlen-XXXXXX |
| 99 | // | +-- nlmsg_data(hdr) +-- nlmsg_attrdata() |
| 100 | // +-- msg = nlmsg_hdr(raw_message) |
| 101 | |
| 102 | // |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 103 | // Nl80211Message |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 104 | // |
| 105 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 106 | // TODO(wdg): do the nlattr parsing inside here. |
| 107 | bool Nl80211Message::Init(nlattr *tb[NL80211_ATTR_MAX + 1], |
| 108 | nlmsghdr *msg) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 109 | if (!tb) { |
| 110 | LOG(ERROR) << "Null |tb| parameter"; |
| 111 | return false; |
| 112 | } |
| 113 | |
| 114 | message_ = msg; |
| 115 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 116 | SLOG(WiFi, 6) << "NL Message " << sequence_number() << " <==="; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 117 | |
| 118 | for (int i = 0; i < NL80211_ATTR_MAX + 1; ++i) { |
| 119 | if (tb[i]) { |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 120 | attributes_.CreateAndInitFromNlAttr(static_cast<nl80211_attrs>(i), tb[i]); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
| 124 | // Convert integer values provided by libnl (for example, from the |
| 125 | // NL80211_ATTR_STATUS_CODE or NL80211_ATTR_REASON_CODE attribute) into |
| 126 | // strings describing the status. |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 127 | if (!reason_code_string_) { |
| 128 | reason_code_string_ = new map<uint16_t, string>; |
| 129 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnspecified] = |
| 130 | "Unspecified reason"; |
| 131 | (*reason_code_string_)[ |
| 132 | IEEE_80211::kReasonCodePreviousAuthenticationInvalid] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 133 | "Previous authentication no longer valid"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 134 | (*reason_code_string_)[IEEE_80211::kReasonCodeSenderHasLeft] = |
| 135 | "Deauthentcated because sending STA is leaving (or has left) IBSS or " |
| 136 | "ESS"; |
| 137 | (*reason_code_string_)[IEEE_80211::kReasonCodeInactivity] = |
| 138 | "Disassociated due to inactivity"; |
| 139 | (*reason_code_string_)[IEEE_80211::kReasonCodeTooManySTAs] = |
| 140 | "Disassociated because AP is unable to handle all currently associated " |
| 141 | "STAs"; |
| 142 | (*reason_code_string_)[IEEE_80211::kReasonCodeNonAuthenticated] = |
| 143 | "Class 2 frame received from nonauthenticated STA"; |
| 144 | (*reason_code_string_)[IEEE_80211::kReasonCodeNonAssociated] = |
| 145 | "Class 3 frame received from nonassociated STA"; |
| 146 | (*reason_code_string_)[IEEE_80211::kReasonCodeDisassociatedHasLeft] = |
| 147 | "Disassociated because sending STA is leaving (or has left) BSS"; |
| 148 | (*reason_code_string_)[ |
| 149 | IEEE_80211::kReasonCodeReassociationNotAuthenticated] = |
| 150 | "STA requesting (re)association is not authenticated with responding " |
| 151 | "STA"; |
| 152 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnacceptablePowerCapability] = |
| 153 | "Disassociated because the information in the Power Capability " |
| 154 | "element is unacceptable"; |
| 155 | (*reason_code_string_)[ |
| 156 | IEEE_80211::kReasonCodeUnacceptableSupportedChannelInfo] = |
| 157 | "Disassociated because the information in the Supported Channels " |
| 158 | "element is unacceptable"; |
| 159 | (*reason_code_string_)[IEEE_80211::kReasonCodeInvalidInfoElement] = |
| 160 | "Invalid information element, i.e., an information element defined in " |
| 161 | "this standard for which the content does not meet the specifications " |
| 162 | "in Clause 7"; |
| 163 | (*reason_code_string_)[IEEE_80211::kReasonCodeMICFailure] = |
| 164 | "Message integrity code (MIC) failure"; |
| 165 | (*reason_code_string_)[IEEE_80211::kReasonCode4WayTimeout] = |
| 166 | "4-Way Handshake timeout"; |
| 167 | (*reason_code_string_)[IEEE_80211::kReasonCodeGroupKeyHandshakeTimeout] = |
| 168 | "Group Key Handshake timeout"; |
| 169 | (*reason_code_string_)[IEEE_80211::kReasonCodeDifferenIE] = |
| 170 | "Information element in 4-Way Handshake different from " |
| 171 | "(Re)Association Request/Probe Response/Beacon frame"; |
| 172 | (*reason_code_string_)[IEEE_80211::kReasonCodeGroupCipherInvalid] = |
| 173 | "Invalid group cipher"; |
| 174 | (*reason_code_string_)[IEEE_80211::kReasonCodePairwiseCipherInvalid] = |
| 175 | "Invalid pairwise cipher"; |
| 176 | (*reason_code_string_)[IEEE_80211::kReasonCodeAkmpInvalid] = |
| 177 | "Invalid AKMP"; |
| 178 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnsupportedRsnIeVersion] = |
| 179 | "Unsupported RSN information element version"; |
| 180 | (*reason_code_string_)[IEEE_80211::kReasonCodeInvalidRsnIeCaps] = |
| 181 | "Invalid RSN information element capabilities"; |
| 182 | (*reason_code_string_)[IEEE_80211::kReasonCode8021XAuth] = |
| 183 | "IEEE 802.1X authentication failed"; |
| 184 | (*reason_code_string_)[IEEE_80211::kReasonCodeCipherSuiteRejected] = |
| 185 | "Cipher suite rejected because of the security policy"; |
| 186 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnspecifiedQoS] = |
| 187 | "Disassociated for unspecified, QoS-related reason"; |
| 188 | (*reason_code_string_)[IEEE_80211::kReasonCodeQoSBandwidth] = |
| 189 | "Disassociated because QoS AP lacks sufficient bandwidth for this " |
| 190 | "QoS STA"; |
| 191 | (*reason_code_string_)[IEEE_80211::kReasonCodeiPoorConditions] = |
| 192 | "Disassociated because excessive number of frames need to be " |
| 193 | "acknowledged, but are not acknowledged due to AP transmissions " |
| 194 | "and/or poor channel conditions"; |
| 195 | (*reason_code_string_)[IEEE_80211::kReasonCodeOutsideTxop] = |
| 196 | "Disassociated because STA is transmitting outside the limits of its " |
| 197 | "TXOPs"; |
| 198 | (*reason_code_string_)[IEEE_80211::kReasonCodeStaLeaving] = |
| 199 | "Requested from peer STA as the STA is leaving the BSS (or resetting)"; |
| 200 | (*reason_code_string_)[IEEE_80211::kReasonCodeUnacceptableMechanism] = |
| 201 | "Requested from peer STA as it does not want to use the mechanism"; |
| 202 | (*reason_code_string_)[IEEE_80211::kReasonCodeSetupRequired] = |
| 203 | "Requested from peer STA as the STA received frames using the " |
| 204 | "mechanism for which a setup is required"; |
| 205 | (*reason_code_string_)[IEEE_80211::kReasonCodeTimeout] = |
| 206 | "Requested from peer STA due to timeout"; |
| 207 | (*reason_code_string_)[IEEE_80211::kReasonCodeCipherSuiteNotSupported] = |
| 208 | "Peer STA does not support the requested cipher suite"; |
| 209 | (*reason_code_string_)[IEEE_80211::kReasonCodeInvalid] = "<INVALID REASON>"; |
| 210 | } |
| 211 | |
| 212 | if (!status_code_string_) { |
| 213 | status_code_string_ = new map<uint16_t, string>; |
| 214 | (*status_code_string_)[IEEE_80211::kStatusCodeSuccessful] = "Successful"; |
| 215 | (*status_code_string_)[IEEE_80211::kStatusCodeFailure] = |
| 216 | "Unspecified failure"; |
| 217 | (*status_code_string_)[IEEE_80211::kStatusCodeAllCapabilitiesNotSupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 218 | "Cannot support all requested capabilities in the capability " |
| 219 | "information field"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 220 | (*status_code_string_)[IEEE_80211::kStatusCodeCantConfirmAssociation] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 221 | "Reassociation denied due to inability to confirm that association " |
| 222 | "exists"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 223 | (*status_code_string_)[IEEE_80211::kStatusCodeAssociationDenied] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 224 | "Association denied due to reason outside the scope of this standard"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 225 | (*status_code_string_)[ |
| 226 | IEEE_80211::kStatusCodeAuthenticationUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 227 | "Responding station does not support the specified authentication " |
| 228 | "algorithm"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 229 | (*status_code_string_)[IEEE_80211::kStatusCodeOutOfSequence] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 230 | "Received an authentication frame with authentication transaction " |
| 231 | "sequence number out of expected sequence"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 232 | (*status_code_string_)[IEEE_80211::kStatusCodeChallengeFailure] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 233 | "Authentication rejected because of challenge failure"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 234 | (*status_code_string_)[IEEE_80211::kStatusCodeFrameTimeout] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 235 | "Authentication rejected due to timeout waiting for next frame in " |
| 236 | "sequence"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 237 | (*status_code_string_)[IEEE_80211::kStatusCodeMaxSta] = |
| 238 | "Association denied because AP is unable to handle additional " |
| 239 | "associated STA"; |
| 240 | (*status_code_string_)[IEEE_80211::kStatusCodeDataRateUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 241 | "Association denied due to requesting station not supporting all of " |
| 242 | "the data rates in the BSSBasicRateSet parameter"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 243 | (*status_code_string_)[IEEE_80211::kStatusCodeShortPreambleUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 244 | "Association denied due to requesting station not supporting the " |
| 245 | "short preamble option"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 246 | (*status_code_string_)[IEEE_80211::kStatusCodePbccUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 247 | "Association denied due to requesting station not supporting the PBCC " |
| 248 | "modulation option"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 249 | (*status_code_string_)[ |
| 250 | IEEE_80211::kStatusCodeChannelAgilityUnsupported] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 251 | "Association denied due to requesting station not supporting the " |
| 252 | "channel agility option"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 253 | (*status_code_string_)[IEEE_80211::kStatusCodeNeedSpectrumManagement] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 254 | "Association request rejected because Spectrum Management capability " |
| 255 | "is required"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 256 | (*status_code_string_)[ |
| 257 | IEEE_80211::kStatusCodeUnacceptablePowerCapability] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 258 | "Association request rejected because the information in the Power " |
| 259 | "Capability element is unacceptable"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 260 | (*status_code_string_)[ |
| 261 | IEEE_80211::kStatusCodeUnacceptableSupportedChannelInfo] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 262 | "Association request rejected because the information in the " |
| 263 | "Supported Channels element is unacceptable"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 264 | (*status_code_string_)[IEEE_80211::kStatusCodeShortTimeSlotRequired] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 265 | "Association request rejected due to requesting station not " |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 266 | "supporting the Short Slot Time option"; |
| 267 | (*status_code_string_)[IEEE_80211::kStatusCodeDssOfdmRequired] = |
| 268 | "Association request rejected due to requesting station not " |
| 269 | "supporting the DSSS-OFDM option"; |
| 270 | (*status_code_string_)[IEEE_80211::kStatusCodeQosFailure] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 271 | "Unspecified, QoS related failure"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 272 | (*status_code_string_)[ |
| 273 | IEEE_80211::kStatusCodeInsufficientBandwithForQsta] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 274 | "Association denied due to QAP having insufficient bandwidth to handle " |
| 275 | "another QSTA"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 276 | (*status_code_string_)[IEEE_80211::kStatusCodePoorConditions] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 277 | "Association denied due to poor channel conditions"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 278 | (*status_code_string_)[IEEE_80211::kStatusCodeQosNotSupported] = |
| 279 | "Association (with QoS BSS) denied due to requesting station not " |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 280 | "supporting the QoS facility"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 281 | (*status_code_string_)[IEEE_80211::kStatusCodeDeclined] = |
| 282 | "The request has been declined"; |
| 283 | (*status_code_string_)[IEEE_80211::kStatusCodeInvalidParameterValues] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 284 | "The request has not been successful as one or more parameters have " |
| 285 | "invalid values"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 286 | (*status_code_string_)[IEEE_80211::kStatusCodeCannotBeHonored] = |
| 287 | "The TS has not been created because the request cannot be honored. " |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 288 | "However, a suggested Tspec is provided so that the initiating QSTA " |
| 289 | "may attempt to send another TS with the suggested changes to the " |
| 290 | "TSpec"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 291 | (*status_code_string_)[IEEE_80211::kStatusCodeInvalidInfoElement] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 292 | "Invalid Information Element"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 293 | (*status_code_string_)[IEEE_80211::kStatusCodeGroupCipherInvalid] = |
| 294 | "Invalid Group Cipher"; |
| 295 | (*status_code_string_)[IEEE_80211::kStatusCodePairwiseCipherInvalid] = |
| 296 | "Invalid Pairwise Cipher"; |
| 297 | (*status_code_string_)[IEEE_80211::kStatusCodeAkmpInvalid] = "Invalid AKMP"; |
| 298 | (*status_code_string_)[IEEE_80211::kStatusCodeUnsupportedRsnIeVersion] = |
| 299 | "Unsupported RSN Information Element version"; |
| 300 | (*status_code_string_)[IEEE_80211::kStatusCodeInvalidRsnIeCaps] = |
| 301 | "Invalid RSN Information Element Capabilities"; |
| 302 | (*status_code_string_)[IEEE_80211::kStatusCodeCipherSuiteRejected] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 303 | "Cipher suite is rejected per security policy"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 304 | (*status_code_string_)[IEEE_80211::kStatusCodeTsDelayNotMet] = |
| 305 | "The TS has not been created. However, the HC may be capable of " |
| 306 | "creating a TS, in response to a request, after the time indicated in " |
| 307 | "the TS Delay element"; |
| 308 | (*status_code_string_)[IEEE_80211::kStatusCodeDirectLinkIllegal] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 309 | "Direct link is not allowed in the BSS by policy"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 310 | (*status_code_string_)[IEEE_80211::kStatusCodeStaNotInBss] = |
| 311 | "Destination STA is not present within this BSS"; |
| 312 | (*status_code_string_)[IEEE_80211::kStatusCodeStaNotInQsta] = |
| 313 | "The destination STA is not a QoS STA"; |
| 314 | (*status_code_string_)[IEEE_80211::kStatusCodeExcessiveListenInterval] = |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 315 | "Association denied because Listen Interval is too large"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 316 | (*status_code_string_)[IEEE_80211::kStatusCodeInvalid] = "<INVALID STATUS>"; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | return true; |
| 320 | } |
| 321 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 322 | // Helper function to provide a string for a MAC address. |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 323 | bool Nl80211Message::GetMacAttributeString(nl80211_attrs id, |
| 324 | string *value) const { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 325 | if (!value) { |
| 326 | LOG(ERROR) << "Null |value| parameter"; |
| 327 | return false; |
| 328 | } |
| 329 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 330 | ByteString data; |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 331 | if (!attributes().GetRawAttributeValue(id, &data)) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 332 | value->assign(kBogusMacAddress); |
| 333 | return false; |
| 334 | } |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 335 | value->assign(StringFromMacAddress(data.GetConstData())); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 336 | |
| 337 | return true; |
| 338 | } |
| 339 | |
| 340 | // Helper function to provide a string for NL80211_ATTR_SCAN_FREQUENCIES. |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 341 | bool Nl80211Message::GetScanFrequenciesAttribute( |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 342 | nl80211_attrs id, vector<uint32_t> *value) const { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 343 | if (!value) { |
| 344 | LOG(ERROR) << "Null |value| parameter"; |
| 345 | return false; |
| 346 | } |
| 347 | |
| 348 | value->clear(); |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 349 | ByteString rawdata; |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 350 | if (!attributes().GetRawAttributeValue(id, &rawdata) && !rawdata.IsEmpty()) |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 351 | return false; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 352 | |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 353 | nlattr *nst = NULL; |
| 354 | // |nla_for_each_attr| requires a non-const parameter even though it |
| 355 | // doesn't change the data. |
| 356 | nlattr *attr_data = reinterpret_cast<nlattr *>(rawdata.GetData()); |
| 357 | int rem_nst; |
| 358 | int len = rawdata.GetLength(); |
| 359 | |
| 360 | nla_for_each_attr(nst, attr_data, len, rem_nst) { |
| 361 | value->push_back(Nl80211Attribute::NlaGetU32(nst)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 362 | } |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 363 | return true; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | // Helper function to provide a string for NL80211_ATTR_SCAN_SSIDS. |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 367 | bool Nl80211Message::GetScanSsidsAttribute( |
| 368 | nl80211_attrs id, vector<string> *value) const { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 369 | if (!value) { |
| 370 | LOG(ERROR) << "Null |value| parameter"; |
| 371 | return false; |
| 372 | } |
| 373 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 374 | ByteString rawdata; |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 375 | if (!attributes().GetRawAttributeValue(id, &rawdata) || rawdata.IsEmpty()) |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 376 | return false; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 377 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 378 | nlattr *nst = NULL; |
| 379 | // |nla_for_each_attr| requires a non-const parameter even though it |
| 380 | // doesn't change the data. |
| 381 | nlattr *data = reinterpret_cast<nlattr *>(rawdata.GetData()); |
| 382 | int rem_nst; |
| 383 | int len = rawdata.GetLength(); |
| 384 | |
| 385 | nla_for_each_attr(nst, data, len, rem_nst) { |
| 386 | value->push_back(StringFromSsid(nla_len(nst), |
| 387 | reinterpret_cast<const uint8_t *>( |
| 388 | nla_data(nst))).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 389 | } |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 390 | return true; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 393 | // Protected members. |
| 394 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 395 | string Nl80211Message::GetHeaderString() const { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 396 | char ifname[IF_NAMESIZE] = ""; |
| 397 | uint32_t ifindex = UINT32_MAX; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 398 | bool ifindex_exists = attributes().GetU32AttributeValue(NL80211_ATTR_IFINDEX, |
| 399 | &ifindex); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 400 | |
| 401 | uint32_t wifi = UINT32_MAX; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 402 | bool wifi_exists = attributes().GetU32AttributeValue(NL80211_ATTR_WIPHY, |
| 403 | &wifi); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 404 | |
| 405 | string output; |
| 406 | if (ifindex_exists && wifi_exists) { |
| 407 | StringAppendF(&output, "%s (phy #%" PRIu32 "): ", |
| 408 | (if_indextoname(ifindex, ifname) ? ifname : "<unknown>"), |
| 409 | wifi); |
| 410 | } else if (ifindex_exists) { |
| 411 | StringAppendF(&output, "%s: ", |
| 412 | (if_indextoname(ifindex, ifname) ? ifname : "<unknown>")); |
| 413 | } else if (wifi_exists) { |
| 414 | StringAppendF(&output, "phy #%" PRIu32 "u: ", wifi); |
| 415 | } |
| 416 | |
| 417 | return output; |
| 418 | } |
| 419 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 420 | string Nl80211Message::StringFromFrame(nl80211_attrs attr_name) const { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 421 | string output; |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 422 | ByteString frame_data; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 423 | if (attributes().GetRawAttributeValue(attr_name, |
| 424 | &frame_data) && !frame_data.IsEmpty()) { |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 425 | Nl80211Frame frame(frame_data); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 426 | frame.ToString(&output); |
| 427 | } else { |
| 428 | output.append(" [no frame]"); |
| 429 | } |
| 430 | |
| 431 | return output; |
| 432 | } |
| 433 | |
| 434 | // static |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 435 | string Nl80211Message::StringFromKeyType(nl80211_key_type key_type) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 436 | switch (key_type) { |
| 437 | case NL80211_KEYTYPE_GROUP: |
| 438 | return "Group"; |
| 439 | case NL80211_KEYTYPE_PAIRWISE: |
| 440 | return "Pairwise"; |
| 441 | case NL80211_KEYTYPE_PEERKEY: |
| 442 | return "PeerKey"; |
| 443 | default: |
| 444 | return "<Unknown Key Type>"; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | // static |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 449 | string Nl80211Message::StringFromMacAddress(const uint8_t *arg) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 450 | string output; |
| 451 | |
| 452 | if (!arg) { |
| 453 | output = kBogusMacAddress; |
| 454 | LOG(ERROR) << "|arg| parameter is NULL."; |
| 455 | } else { |
| 456 | StringAppendF(&output, "%02x", arg[0]); |
| 457 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 458 | for (unsigned int i = 1; i < kEthernetAddressBytes ; ++i) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 459 | StringAppendF(&output, ":%02x", arg[i]); |
| 460 | } |
| 461 | } |
| 462 | return output; |
| 463 | } |
| 464 | |
| 465 | // static |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 466 | string Nl80211Message::StringFromRegInitiator(__u8 initiator) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 467 | switch (initiator) { |
| 468 | case NL80211_REGDOM_SET_BY_CORE: |
| 469 | return "the wireless core upon initialization"; |
| 470 | case NL80211_REGDOM_SET_BY_USER: |
| 471 | return "a user"; |
| 472 | case NL80211_REGDOM_SET_BY_DRIVER: |
| 473 | return "a driver"; |
| 474 | case NL80211_REGDOM_SET_BY_COUNTRY_IE: |
| 475 | return "a country IE"; |
| 476 | default: |
| 477 | return "<Unknown Reg Initiator>"; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | // static |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 482 | string Nl80211Message::StringFromSsid(const uint8_t len, |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 483 | const uint8_t *data) { |
| 484 | string output; |
| 485 | if (!data) { |
| 486 | StringAppendF(&output, "<Error from %s, NULL parameter>", __func__); |
| 487 | LOG(ERROR) << "|data| parameter is NULL."; |
| 488 | return output; |
| 489 | } |
| 490 | |
| 491 | for (int i = 0; i < len; ++i) { |
| 492 | if (data[i] == ' ') |
| 493 | output.append(" "); |
| 494 | else if (isprint(data[i])) |
| 495 | StringAppendF(&output, "%c", static_cast<char>(data[i])); |
| 496 | else |
| 497 | StringAppendF(&output, "\\x%2x", data[i]); |
| 498 | } |
| 499 | |
| 500 | return output; |
| 501 | } |
| 502 | |
| 503 | // static |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 504 | string Nl80211Message::StringFromReason(uint16_t status) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 505 | map<uint16_t, string>::const_iterator match; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 506 | match = reason_code_string_->find(status); |
| 507 | if (match == reason_code_string_->end()) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 508 | string output; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 509 | if (status < IEEE_80211::kReasonCodeMax) { |
| 510 | StringAppendF(&output, "<Reserved Reason:%u>", status); |
| 511 | } else { |
| 512 | StringAppendF(&output, "<Unknown Reason:%u>", status); |
| 513 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 514 | return output; |
| 515 | } |
| 516 | return match->second; |
| 517 | } |
| 518 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 519 | // static |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 520 | string Nl80211Message::StringFromStatus(uint16_t status) { |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 521 | map<uint16_t, string>::const_iterator match; |
| 522 | match = status_code_string_->find(status); |
| 523 | if (match == status_code_string_->end()) { |
| 524 | string output; |
| 525 | if (status < IEEE_80211::kStatusCodeMax) { |
| 526 | StringAppendF(&output, "<Reserved Status:%u>", status); |
| 527 | } else { |
| 528 | StringAppendF(&output, "<Unknown Status:%u>", status); |
| 529 | } |
| 530 | return output; |
| 531 | } |
| 532 | return match->second; |
| 533 | } |
| 534 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 535 | string Nl80211Message::GenericToString() const { |
repo sync | 1538d44 | 2012-12-20 15:24:35 -0800 | [diff] [blame] | 536 | string output; |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 537 | StringAppendF(&output, "Message %s (%d)\n", |
repo sync | 1538d44 | 2012-12-20 15:24:35 -0800 | [diff] [blame] | 538 | message_type_string(), message_type()); |
| 539 | StringAppendF(&output, "%s", attributes_.ToString().c_str()); |
| 540 | return output; |
| 541 | } |
| 542 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 543 | ByteString Nl80211Message::Encode(uint16_t nlmsg_type) const { |
| 544 | // Build netlink header. |
| 545 | nlmsghdr header; |
| 546 | size_t nlmsghdr_with_pad = NLMSG_ALIGN(sizeof(header)); |
| 547 | header.nlmsg_len = nlmsghdr_with_pad; |
| 548 | header.nlmsg_type = nlmsg_type; |
| 549 | header.nlmsg_flags = NLM_F_REQUEST; |
| 550 | header.nlmsg_seq = sequence_number(); |
| 551 | header.nlmsg_pid = getpid(); |
| 552 | |
| 553 | // Build genl message header. |
| 554 | genlmsghdr genl_header; |
| 555 | size_t genlmsghdr_with_pad = NLMSG_ALIGN(sizeof(genl_header)); |
| 556 | header.nlmsg_len += genlmsghdr_with_pad; |
| 557 | genl_header.cmd = message_type(); |
| 558 | genl_header.version = 1; |
| 559 | genl_header.reserved = 0; |
| 560 | |
| 561 | // Assemble attributes (padding is included by AttributeList::Encode). |
| 562 | ByteString attributes = attributes_.Encode(); |
| 563 | header.nlmsg_len += attributes.GetLength(); |
| 564 | |
| 565 | // Now that we know the total message size, build the output ByteString. |
| 566 | ByteString result; |
| 567 | |
| 568 | // Netlink header + pad. |
| 569 | result.Append(ByteString(reinterpret_cast<unsigned char *>(&header), |
| 570 | sizeof(header))); |
| 571 | result.Resize(nlmsghdr_with_pad); // Zero-fill pad space (if any). |
| 572 | |
| 573 | // Genl message header + pad. |
| 574 | result.Append(ByteString(reinterpret_cast<unsigned char *>(&genl_header), |
| 575 | sizeof(genl_header))); |
| 576 | result.Resize(nlmsghdr_with_pad + genlmsghdr_with_pad); // Zero-fill. |
| 577 | |
| 578 | // Attributes including pad. |
| 579 | result.Append(attributes); |
| 580 | |
| 581 | return result; |
| 582 | } |
| 583 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 584 | Nl80211Frame::Nl80211Frame(const ByteString &raw_frame) |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 585 | : frame_type_(kIllegalFrameType), reason_(UINT16_MAX), status_(UINT16_MAX), |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 586 | frame_(raw_frame) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 587 | const IEEE_80211::ieee80211_frame *frame = |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 588 | reinterpret_cast<const IEEE_80211::ieee80211_frame *>( |
| 589 | frame_.GetConstData()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 590 | |
| 591 | // Now, let's populate the other stuff. |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 592 | if (frame_.GetLength() >= kMinimumFrameByteCount) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 593 | mac_from_ = |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 594 | Nl80211Message::StringFromMacAddress(&frame->destination_mac[0]); |
| 595 | mac_to_ = Nl80211Message::StringFromMacAddress(&frame->source_mac[0]); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 596 | frame_type_ = frame->frame_control & kFrameTypeMask; |
| 597 | |
| 598 | switch (frame_type_) { |
| 599 | case kAssocResponseFrameType: |
| 600 | case kReassocResponseFrameType: |
| 601 | status_ = le16toh(frame->u.associate_response.status_code); |
| 602 | break; |
| 603 | |
| 604 | case kAuthFrameType: |
| 605 | status_ = le16toh(frame->u.authentiate_message.status_code); |
| 606 | break; |
| 607 | |
| 608 | case kDisassocFrameType: |
| 609 | case kDeauthFrameType: |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 610 | reason_ = le16toh(frame->u.deauthentiate_message.reason_code); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 611 | break; |
| 612 | |
| 613 | default: |
| 614 | break; |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 619 | bool Nl80211Frame::ToString(string *output) const { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 620 | if (!output) { |
| 621 | LOG(ERROR) << "NULL |output|"; |
| 622 | return false; |
| 623 | } |
| 624 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 625 | if (frame_.IsEmpty()) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 626 | output->append(" [no frame]"); |
| 627 | return true; |
| 628 | } |
| 629 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 630 | if (frame_.GetLength() < kMinimumFrameByteCount) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 631 | output->append(" [invalid frame: "); |
| 632 | } else { |
| 633 | StringAppendF(output, " %s -> %s", mac_from_.c_str(), mac_to_.c_str()); |
| 634 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 635 | switch (frame_.GetConstData()[0] & kFrameTypeMask) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 636 | case kAssocResponseFrameType: |
| 637 | StringAppendF(output, "; AssocResponse status: %u: %s", |
| 638 | status_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 639 | Nl80211Message::StringFromStatus(status_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 640 | break; |
| 641 | case kReassocResponseFrameType: |
| 642 | StringAppendF(output, "; ReassocResponse status: %u: %s", |
| 643 | status_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 644 | Nl80211Message::StringFromStatus(status_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 645 | break; |
| 646 | case kAuthFrameType: |
| 647 | StringAppendF(output, "; Auth status: %u: %s", |
| 648 | status_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 649 | Nl80211Message::StringFromStatus(status_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 650 | break; |
| 651 | |
| 652 | case kDisassocFrameType: |
| 653 | StringAppendF(output, "; Disassoc reason %u: %s", |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 654 | reason_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 655 | Nl80211Message::StringFromReason(reason_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 656 | break; |
| 657 | case kDeauthFrameType: |
| 658 | StringAppendF(output, "; Deauth reason %u: %s", |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 659 | reason_, |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 660 | Nl80211Message::StringFromReason(reason_).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 661 | break; |
| 662 | |
| 663 | default: |
| 664 | break; |
| 665 | } |
| 666 | output->append(" [frame: "); |
| 667 | } |
| 668 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 669 | const unsigned char *frame = frame_.GetConstData(); |
| 670 | for (size_t i = 0; i < frame_.GetLength(); ++i) { |
| 671 | StringAppendF(output, "%02x, ", frame[i]); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 672 | } |
| 673 | output->append("]"); |
| 674 | |
| 675 | return true; |
| 676 | } |
| 677 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 678 | bool Nl80211Frame::IsEqual(const Nl80211Frame &other) const { |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 679 | return frame_.Equals(other.frame_); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 680 | } |
| 681 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 682 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 683 | // |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 684 | // Specific Nl80211Message types. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 685 | // |
| 686 | |
| 687 | const uint8_t AssociateMessage::kCommand = NL80211_CMD_ASSOCIATE; |
| 688 | const char AssociateMessage::kCommandString[] = "NL80211_CMD_ASSOCIATE"; |
| 689 | |
| 690 | string AssociateMessage::ToString() const { |
| 691 | string output(GetHeaderString()); |
| 692 | output.append("assoc"); |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 693 | if (attributes().GetRawAttributeValue(NL80211_ATTR_FRAME, NULL)) |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 694 | output.append(StringFromFrame(NL80211_ATTR_FRAME)); |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 695 | else if (attributes().IsFlagAttributeTrue(NL80211_ATTR_TIMED_OUT)) |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 696 | output.append(": timed out"); |
| 697 | else |
| 698 | output.append(": unknown event"); |
| 699 | return output; |
| 700 | } |
| 701 | |
| 702 | const uint8_t AuthenticateMessage::kCommand = NL80211_CMD_AUTHENTICATE; |
| 703 | const char AuthenticateMessage::kCommandString[] = "NL80211_CMD_AUTHENTICATE"; |
| 704 | |
| 705 | string AuthenticateMessage::ToString() const { |
| 706 | string output(GetHeaderString()); |
| 707 | output.append("auth"); |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 708 | if (attributes().GetRawAttributeValue(NL80211_ATTR_FRAME, NULL)) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 709 | output.append(StringFromFrame(NL80211_ATTR_FRAME)); |
| 710 | } else { |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 711 | output.append(attributes().IsFlagAttributeTrue(NL80211_ATTR_TIMED_OUT) ? |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 712 | ": timed out" : ": unknown event"); |
| 713 | } |
| 714 | return output; |
| 715 | } |
| 716 | |
| 717 | const uint8_t CancelRemainOnChannelMessage::kCommand = |
| 718 | NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL; |
| 719 | const char CancelRemainOnChannelMessage::kCommandString[] = |
| 720 | "NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL"; |
| 721 | |
| 722 | string CancelRemainOnChannelMessage::ToString() const { |
| 723 | string output(GetHeaderString()); |
| 724 | uint32_t freq; |
| 725 | uint64_t cookie; |
| 726 | StringAppendF(&output, |
| 727 | "done with remain on freq %" PRIu32 " (cookie %" PRIx64 ")", |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 728 | (attributes().GetU32AttributeValue(NL80211_ATTR_WIPHY_FREQ, |
| 729 | &freq) ? 0 : freq), |
| 730 | (attributes().GetU64AttributeValue(NL80211_ATTR_COOKIE, |
| 731 | &cookie) ? 0 : cookie)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 732 | return output; |
| 733 | } |
| 734 | |
| 735 | const uint8_t ConnectMessage::kCommand = NL80211_CMD_CONNECT; |
| 736 | const char ConnectMessage::kCommandString[] = "NL80211_CMD_CONNECT"; |
| 737 | |
| 738 | string ConnectMessage::ToString() const { |
| 739 | string output(GetHeaderString()); |
| 740 | |
| 741 | uint16_t status = UINT16_MAX; |
| 742 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 743 | if (!attributes().GetU16AttributeValue(NL80211_ATTR_STATUS_CODE, &status)) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 744 | output.append("unknown connect status"); |
| 745 | } else if (status == 0) { |
| 746 | output.append("connected"); |
| 747 | } else { |
| 748 | output.append("failed to connect"); |
| 749 | } |
| 750 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 751 | if (attributes().GetRawAttributeValue(NL80211_ATTR_MAC, NULL)) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 752 | string mac; |
| 753 | GetMacAttributeString(NL80211_ATTR_MAC, &mac); |
| 754 | StringAppendF(&output, " to %s", mac.c_str()); |
| 755 | } |
| 756 | if (status) |
| 757 | StringAppendF(&output, ", status: %u: %s", status, |
| 758 | StringFromStatus(status).c_str()); |
| 759 | return output; |
| 760 | } |
| 761 | |
| 762 | const uint8_t DeauthenticateMessage::kCommand = NL80211_CMD_DEAUTHENTICATE; |
| 763 | const char DeauthenticateMessage::kCommandString[] = |
| 764 | "NL80211_CMD_DEAUTHENTICATE"; |
| 765 | |
| 766 | string DeauthenticateMessage::ToString() const { |
| 767 | string output(GetHeaderString()); |
| 768 | StringAppendF(&output, "deauth%s", |
| 769 | StringFromFrame(NL80211_ATTR_FRAME).c_str()); |
| 770 | return output; |
| 771 | } |
| 772 | |
| 773 | const uint8_t DeleteStationMessage::kCommand = NL80211_CMD_DEL_STATION; |
| 774 | const char DeleteStationMessage::kCommandString[] = "NL80211_CMD_DEL_STATION"; |
| 775 | |
| 776 | string DeleteStationMessage::ToString() const { |
| 777 | string mac; |
| 778 | GetMacAttributeString(NL80211_ATTR_MAC, &mac); |
| 779 | string output(GetHeaderString()); |
| 780 | StringAppendF(&output, "del station %s", mac.c_str()); |
| 781 | return output; |
| 782 | } |
| 783 | |
| 784 | const uint8_t DisassociateMessage::kCommand = NL80211_CMD_DISASSOCIATE; |
| 785 | const char DisassociateMessage::kCommandString[] = "NL80211_CMD_DISASSOCIATE"; |
| 786 | |
| 787 | string DisassociateMessage::ToString() const { |
| 788 | string output(GetHeaderString()); |
| 789 | StringAppendF(&output, "disassoc%s", |
| 790 | StringFromFrame(NL80211_ATTR_FRAME).c_str()); |
| 791 | return output; |
| 792 | } |
| 793 | |
| 794 | const uint8_t DisconnectMessage::kCommand = NL80211_CMD_DISCONNECT; |
| 795 | const char DisconnectMessage::kCommandString[] = "NL80211_CMD_DISCONNECT"; |
| 796 | |
| 797 | string DisconnectMessage::ToString() const { |
| 798 | string output(GetHeaderString()); |
| 799 | StringAppendF(&output, "disconnected %s", |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 800 | ((attributes().IsFlagAttributeTrue( |
| 801 | NL80211_ATTR_DISCONNECTED_BY_AP)) ? |
| 802 | "(by AP)" : "(local request)")); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 803 | |
| 804 | uint16_t reason = UINT16_MAX; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 805 | if (attributes().GetU16AttributeValue(NL80211_ATTR_REASON_CODE, &reason)) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 806 | StringAppendF(&output, " reason: %u: %s", |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 807 | reason, StringFromReason(reason).c_str()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 808 | } |
| 809 | return output; |
| 810 | } |
| 811 | |
| 812 | const uint8_t FrameTxStatusMessage::kCommand = NL80211_CMD_FRAME_TX_STATUS; |
| 813 | const char FrameTxStatusMessage::kCommandString[] = |
| 814 | "NL80211_CMD_FRAME_TX_STATUS"; |
| 815 | |
| 816 | string FrameTxStatusMessage::ToString() const { |
| 817 | string output(GetHeaderString()); |
| 818 | uint64_t cookie = UINT64_MAX; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 819 | attributes().GetU64AttributeValue(NL80211_ATTR_COOKIE, &cookie); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 820 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 821 | StringAppendF(&output, "mgmt TX status (cookie %" PRIx64 "): %s", cookie, |
| 822 | (attributes().IsFlagAttributeTrue(NL80211_ATTR_ACK) ? |
| 823 | "acked" : "no ack")); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 824 | return output; |
| 825 | } |
| 826 | |
| 827 | const uint8_t JoinIbssMessage::kCommand = NL80211_CMD_JOIN_IBSS; |
| 828 | const char JoinIbssMessage::kCommandString[] = "NL80211_CMD_JOIN_IBSS"; |
| 829 | |
| 830 | string JoinIbssMessage::ToString() const { |
| 831 | string mac; |
| 832 | GetMacAttributeString(NL80211_ATTR_MAC, &mac); |
| 833 | string output(GetHeaderString()); |
| 834 | StringAppendF(&output, "IBSS %s joined", mac.c_str()); |
| 835 | return output; |
| 836 | } |
| 837 | |
| 838 | const uint8_t MichaelMicFailureMessage::kCommand = |
| 839 | NL80211_CMD_MICHAEL_MIC_FAILURE; |
| 840 | const char MichaelMicFailureMessage::kCommandString[] = |
| 841 | "NL80211_CMD_MICHAEL_MIC_FAILURE"; |
| 842 | |
| 843 | string MichaelMicFailureMessage::ToString() const { |
| 844 | string output(GetHeaderString()); |
| 845 | |
| 846 | output.append("Michael MIC failure event:"); |
| 847 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 848 | if (attributes().GetRawAttributeValue(NL80211_ATTR_MAC, NULL)) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 849 | string mac; |
| 850 | GetMacAttributeString(NL80211_ATTR_MAC, &mac); |
| 851 | StringAppendF(&output, " source MAC address %s", mac.c_str()); |
| 852 | } |
| 853 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 854 | { |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 855 | ByteString rawdata; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 856 | if (attributes().GetRawAttributeValue(NL80211_ATTR_KEY_SEQ, |
| 857 | &rawdata) && |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 858 | rawdata.GetLength() == Nl80211Message::kEthernetAddressBytes) { |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 859 | const unsigned char *seq = rawdata.GetConstData(); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 860 | StringAppendF(&output, " seq=%02x%02x%02x%02x%02x%02x", |
| 861 | seq[0], seq[1], seq[2], seq[3], seq[4], seq[5]); |
| 862 | } |
| 863 | } |
| 864 | uint32_t key_type_val = UINT32_MAX; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 865 | if (attributes().GetU32AttributeValue(NL80211_ATTR_KEY_TYPE, &key_type_val)) { |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 866 | nl80211_key_type key_type = static_cast<nl80211_key_type >(key_type_val); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 867 | StringAppendF(&output, " Key Type %s", StringFromKeyType(key_type).c_str()); |
| 868 | } |
| 869 | |
| 870 | uint8_t key_index = UINT8_MAX; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 871 | if (attributes().GetU8AttributeValue(NL80211_ATTR_KEY_IDX, &key_index)) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 872 | StringAppendF(&output, " Key Id %u", key_index); |
| 873 | } |
| 874 | |
| 875 | return output; |
| 876 | } |
| 877 | |
| 878 | const uint8_t NewScanResultsMessage::kCommand = NL80211_CMD_NEW_SCAN_RESULTS; |
| 879 | const char NewScanResultsMessage::kCommandString[] = |
| 880 | "NL80211_CMD_NEW_SCAN_RESULTS"; |
| 881 | |
| 882 | string NewScanResultsMessage::ToString() const { |
| 883 | string output(GetHeaderString()); |
| 884 | output.append("scan finished"); |
| 885 | |
| 886 | { |
| 887 | output.append("; frequencies: "); |
| 888 | vector<uint32_t> list; |
| 889 | if (GetScanFrequenciesAttribute(NL80211_ATTR_SCAN_FREQUENCIES, &list)) { |
| 890 | string str; |
| 891 | for (vector<uint32_t>::const_iterator i = list.begin(); |
| 892 | i != list.end(); ++i) { |
| 893 | StringAppendF(&str, " %" PRIu32 ", ", *i); |
| 894 | } |
| 895 | output.append(str); |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | { |
| 900 | output.append("; SSIDs: "); |
| 901 | vector<string> list; |
| 902 | if (GetScanSsidsAttribute(NL80211_ATTR_SCAN_SSIDS, &list)) { |
| 903 | string str; |
| 904 | for (vector<string>::const_iterator i = list.begin(); |
| 905 | i != list.end(); ++i) { |
| 906 | StringAppendF(&str, "\"%s\", ", i->c_str()); |
| 907 | } |
| 908 | output.append(str); |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | return output; |
| 913 | } |
| 914 | |
| 915 | const uint8_t NewStationMessage::kCommand = NL80211_CMD_NEW_STATION; |
| 916 | const char NewStationMessage::kCommandString[] = "NL80211_CMD_NEW_STATION"; |
| 917 | |
| 918 | string NewStationMessage::ToString() const { |
| 919 | string mac; |
| 920 | GetMacAttributeString(NL80211_ATTR_MAC, &mac); |
| 921 | string output(GetHeaderString()); |
| 922 | StringAppendF(&output, "new station %s", mac.c_str()); |
| 923 | |
| 924 | return output; |
| 925 | } |
| 926 | |
| 927 | const uint8_t NewWifiMessage::kCommand = NL80211_CMD_NEW_WIPHY; |
| 928 | const char NewWifiMessage::kCommandString[] = "NL80211_CMD_NEW_WIPHY"; |
| 929 | |
| 930 | string NewWifiMessage::ToString() const { |
| 931 | string output(GetHeaderString()); |
| 932 | string wifi_name = "None"; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 933 | attributes().GetStringAttributeValue(NL80211_ATTR_WIPHY_NAME, &wifi_name); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 934 | StringAppendF(&output, "renamed to %s", wifi_name.c_str()); |
| 935 | return output; |
| 936 | } |
| 937 | |
| 938 | const uint8_t NotifyCqmMessage::kCommand = NL80211_CMD_NOTIFY_CQM; |
| 939 | const char NotifyCqmMessage::kCommandString[] = "NL80211_CMD_NOTIFY_CQM"; |
| 940 | |
| 941 | string NotifyCqmMessage::ToString() const { |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 942 | // TODO(wdg): use attributes().GetNestedAttributeValue()... |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 943 | static const nla_policy kCqmValidationPolicy[NL80211_ATTR_CQM_MAX + 1] = { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 944 | { NLA_U32, 0, 0 }, // Who Knows? |
| 945 | { NLA_U32, 0, 0 }, // [NL80211_ATTR_CQM_RSSI_THOLD] |
| 946 | { NLA_U32, 0, 0 }, // [NL80211_ATTR_CQM_RSSI_HYST] |
| 947 | { NLA_U32, 0, 0 }, // [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] |
| 948 | }; |
| 949 | |
| 950 | string output(GetHeaderString()); |
| 951 | output.append("connection quality monitor event: "); |
| 952 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 953 | const Nl80211RawAttribute *attribute = |
| 954 | attributes().GetRawAttribute(NL80211_ATTR_CQM); |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 955 | if (!attribute) { |
| 956 | output.append("missing data!"); |
| 957 | return output; |
| 958 | } |
| 959 | |
| 960 | const nlattr *const_data = attribute->data(); |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 961 | // Note that |nla_parse_nested| doesn't change |const_data| but doesn't |
| 962 | // declare itself as 'const', either. Hence the cast. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 963 | nlattr *cqm_attr = const_cast<nlattr *>(const_data); |
| 964 | |
| 965 | nlattr *cqm[NL80211_ATTR_CQM_MAX + 1]; |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 966 | if (!cqm_attr || |
| 967 | nla_parse_nested(cqm, NL80211_ATTR_CQM_MAX, cqm_attr, |
| 968 | const_cast<nla_policy *>(kCqmValidationPolicy))) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 969 | output.append("missing data!"); |
| 970 | return output; |
| 971 | } |
| 972 | if (cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT]) { |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 973 | nl80211_cqm_rssi_threshold_event rssi_event = |
| 974 | static_cast<nl80211_cqm_rssi_threshold_event>( |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 975 | Nl80211Attribute::NlaGetU32( |
| 976 | cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT])); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 977 | if (rssi_event == NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH) |
| 978 | output.append("RSSI went above threshold"); |
| 979 | else |
| 980 | output.append("RSSI went below threshold"); |
| 981 | } else if (cqm[NL80211_ATTR_CQM_PKT_LOSS_EVENT] && |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 982 | attributes().GetRawAttributeValue(NL80211_ATTR_MAC, NULL)) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 983 | string mac; |
| 984 | GetMacAttributeString(NL80211_ATTR_MAC, &mac); |
| 985 | StringAppendF(&output, "peer %s didn't ACK %" PRIu32 " packets", |
| 986 | mac.c_str(), |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 987 | Nl80211Attribute::NlaGetU32( |
| 988 | cqm[NL80211_ATTR_CQM_PKT_LOSS_EVENT])); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 989 | } else { |
| 990 | output.append("unknown event"); |
| 991 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 992 | return output; |
| 993 | } |
| 994 | |
| 995 | const uint8_t PmksaCandidateMessage::kCommand = NL80211_ATTR_PMKSA_CANDIDATE; |
| 996 | const char PmksaCandidateMessage::kCommandString[] = |
| 997 | "NL80211_ATTR_PMKSA_CANDIDATE"; |
| 998 | |
| 999 | string PmksaCandidateMessage::ToString() const { |
| 1000 | string output(GetHeaderString()); |
| 1001 | output.append("PMKSA candidate found"); |
| 1002 | return output; |
| 1003 | } |
| 1004 | |
| 1005 | const uint8_t RegBeaconHintMessage::kCommand = NL80211_CMD_REG_BEACON_HINT; |
| 1006 | const char RegBeaconHintMessage::kCommandString[] = |
| 1007 | "NL80211_CMD_REG_BEACON_HINT"; |
| 1008 | |
| 1009 | string RegBeaconHintMessage::ToString() const { |
| 1010 | string output(GetHeaderString()); |
| 1011 | uint32_t wiphy_idx = UINT32_MAX; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 1012 | attributes().GetU32AttributeValue(NL80211_ATTR_WIPHY, &wiphy_idx); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1013 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 1014 | const Nl80211RawAttribute *freq_before = |
| 1015 | attributes().GetRawAttribute(NL80211_ATTR_FREQ_BEFORE); |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 1016 | if (!freq_before) |
| 1017 | return ""; |
| 1018 | const nlattr *const_before = freq_before->data(); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1019 | ieee80211_beacon_channel chan_before_beacon; |
| 1020 | memset(&chan_before_beacon, 0, sizeof(chan_before_beacon)); |
| 1021 | if (ParseBeaconHintChan(const_before, &chan_before_beacon)) |
| 1022 | return ""; |
| 1023 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 1024 | const Nl80211RawAttribute *freq_after = |
| 1025 | attributes().GetRawAttribute(NL80211_ATTR_FREQ_AFTER); |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 1026 | if (!freq_after) |
| 1027 | return ""; |
| 1028 | |
| 1029 | const nlattr *const_after = freq_after->data(); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1030 | ieee80211_beacon_channel chan_after_beacon; |
| 1031 | memset(&chan_after_beacon, 0, sizeof(chan_after_beacon)); |
| 1032 | if (ParseBeaconHintChan(const_after, &chan_after_beacon)) |
| 1033 | return ""; |
| 1034 | |
| 1035 | if (chan_before_beacon.center_freq != chan_after_beacon.center_freq) |
| 1036 | return ""; |
| 1037 | |
| 1038 | /* A beacon hint is sent _only_ if something _did_ change */ |
| 1039 | output.append("beacon hint:"); |
| 1040 | StringAppendF(&output, "phy%" PRIu32 " %u MHz [%d]:", |
| 1041 | wiphy_idx, chan_before_beacon.center_freq, |
| 1042 | ChannelFromIeee80211Frequency(chan_before_beacon.center_freq)); |
| 1043 | |
| 1044 | if (chan_before_beacon.passive_scan && !chan_after_beacon.passive_scan) |
| 1045 | output.append("\to active scanning enabled"); |
| 1046 | if (chan_before_beacon.no_ibss && !chan_after_beacon.no_ibss) |
| 1047 | output.append("\to beaconing enabled"); |
| 1048 | return output; |
| 1049 | } |
| 1050 | |
| 1051 | int RegBeaconHintMessage::ParseBeaconHintChan(const nlattr *tb, |
| 1052 | ieee80211_beacon_channel *chan) |
| 1053 | const { |
| 1054 | static const nla_policy kBeaconFreqPolicy[ |
| 1055 | NL80211_FREQUENCY_ATTR_MAX + 1] = { |
| 1056 | {0, 0, 0}, |
| 1057 | { NLA_U32, 0, 0 }, // [NL80211_FREQUENCY_ATTR_FREQ] |
| 1058 | {0, 0, 0}, |
| 1059 | { NLA_FLAG, 0, 0 }, // [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] |
| 1060 | { NLA_FLAG, 0, 0 }, // [NL80211_FREQUENCY_ATTR_NO_IBSS] |
| 1061 | }; |
| 1062 | |
| 1063 | if (!tb) { |
| 1064 | LOG(ERROR) << "|tb| parameter is NULL."; |
| 1065 | return -EINVAL; |
| 1066 | } |
| 1067 | |
| 1068 | if (!chan) { |
| 1069 | LOG(ERROR) << "|chan| parameter is NULL."; |
| 1070 | return -EINVAL; |
| 1071 | } |
| 1072 | |
| 1073 | nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; |
| 1074 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 1075 | // Note that |nla_parse_nested| doesn't change its parameters but doesn't |
| 1076 | // declare itself as 'const', either. Hence the cast. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1077 | if (nla_parse_nested(tb_freq, |
| 1078 | NL80211_FREQUENCY_ATTR_MAX, |
| 1079 | const_cast<nlattr *>(tb), |
| 1080 | const_cast<nla_policy *>(kBeaconFreqPolicy))) |
| 1081 | return -EINVAL; |
| 1082 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 1083 | chan->center_freq = Nl80211Attribute::NlaGetU32( |
| 1084 | tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1085 | |
| 1086 | if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN]) |
| 1087 | chan->passive_scan = true; |
| 1088 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS]) |
| 1089 | chan->no_ibss = true; |
| 1090 | |
| 1091 | return 0; |
| 1092 | } |
| 1093 | |
| 1094 | int RegBeaconHintMessage::ChannelFromIeee80211Frequency(int freq) { |
| 1095 | // TODO(wdg): get rid of these magic numbers. |
| 1096 | if (freq == 2484) |
| 1097 | return 14; |
| 1098 | |
| 1099 | if (freq < 2484) |
| 1100 | return (freq - 2407) / 5; |
| 1101 | |
| 1102 | /* FIXME: dot11ChannelStartingFactor (802.11-2007 17.3.8.3.2) */ |
| 1103 | return freq/5 - 1000; |
| 1104 | } |
| 1105 | |
| 1106 | const uint8_t RegChangeMessage::kCommand = NL80211_CMD_REG_CHANGE; |
| 1107 | const char RegChangeMessage::kCommandString[] = "NL80211_CMD_REG_CHANGE"; |
| 1108 | |
| 1109 | string RegChangeMessage::ToString() const { |
| 1110 | string output(GetHeaderString()); |
| 1111 | output.append("regulatory domain change: "); |
| 1112 | |
| 1113 | uint8_t reg_type = UINT8_MAX; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 1114 | attributes().GetU8AttributeValue(NL80211_ATTR_REG_TYPE, ®_type); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1115 | |
| 1116 | uint32_t initiator = UINT32_MAX; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 1117 | attributes().GetU32AttributeValue(NL80211_ATTR_REG_INITIATOR, &initiator); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1118 | |
| 1119 | uint32_t wifi = UINT32_MAX; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 1120 | bool wifi_exists = attributes().GetU32AttributeValue(NL80211_ATTR_WIPHY, |
| 1121 | &wifi); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1122 | |
| 1123 | string alpha2 = "<None>"; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 1124 | attributes().GetStringAttributeValue(NL80211_ATTR_REG_ALPHA2, &alpha2); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1125 | |
| 1126 | switch (reg_type) { |
| 1127 | case NL80211_REGDOM_TYPE_COUNTRY: |
| 1128 | StringAppendF(&output, "set to %s by %s request", |
| 1129 | alpha2.c_str(), StringFromRegInitiator(initiator).c_str()); |
| 1130 | if (wifi_exists) |
| 1131 | StringAppendF(&output, " on phy%" PRIu32, wifi); |
| 1132 | break; |
| 1133 | |
| 1134 | case NL80211_REGDOM_TYPE_WORLD: |
| 1135 | StringAppendF(&output, "set to world roaming by %s request", |
| 1136 | StringFromRegInitiator(initiator).c_str()); |
| 1137 | break; |
| 1138 | |
| 1139 | case NL80211_REGDOM_TYPE_CUSTOM_WORLD: |
| 1140 | StringAppendF(&output, |
| 1141 | "custom world roaming rules in place on phy%" PRIu32 |
| 1142 | " by %s request", |
| 1143 | wifi, StringFromRegInitiator(initiator).c_str()); |
| 1144 | break; |
| 1145 | |
| 1146 | case NL80211_REGDOM_TYPE_INTERSECTION: |
| 1147 | StringAppendF(&output, "intersection used due to a request made by %s", |
| 1148 | StringFromRegInitiator(initiator).c_str()); |
| 1149 | if (wifi_exists) |
| 1150 | StringAppendF(&output, " on phy%" PRIu32, wifi); |
| 1151 | break; |
| 1152 | |
| 1153 | default: |
| 1154 | output.append("unknown source"); |
| 1155 | break; |
| 1156 | } |
| 1157 | return output; |
| 1158 | } |
| 1159 | |
| 1160 | const uint8_t RemainOnChannelMessage::kCommand = NL80211_CMD_REMAIN_ON_CHANNEL; |
| 1161 | const char RemainOnChannelMessage::kCommandString[] = |
| 1162 | "NL80211_CMD_REMAIN_ON_CHANNEL"; |
| 1163 | |
| 1164 | string RemainOnChannelMessage::ToString() const { |
| 1165 | string output(GetHeaderString()); |
| 1166 | |
| 1167 | uint32_t wifi_freq = UINT32_MAX; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 1168 | attributes().GetU32AttributeValue(NL80211_ATTR_WIPHY_FREQ, &wifi_freq); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1169 | |
| 1170 | uint32_t duration = UINT32_MAX; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 1171 | attributes().GetU32AttributeValue(NL80211_ATTR_DURATION, &duration); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1172 | |
| 1173 | uint64_t cookie = UINT64_MAX; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 1174 | attributes().GetU64AttributeValue(NL80211_ATTR_COOKIE, &cookie); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1175 | |
| 1176 | StringAppendF(&output, "remain on freq %" PRIu32 " (%" PRIu32 "ms, cookie %" |
| 1177 | PRIx64 ")", |
| 1178 | wifi_freq, duration, cookie); |
| 1179 | return output; |
| 1180 | } |
| 1181 | |
| 1182 | const uint8_t RoamMessage::kCommand = NL80211_CMD_ROAM; |
| 1183 | const char RoamMessage::kCommandString[] = "NL80211_CMD_ROAM"; |
| 1184 | |
| 1185 | string RoamMessage::ToString() const { |
| 1186 | string output(GetHeaderString()); |
| 1187 | output.append("roamed"); |
| 1188 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 1189 | if (attributes().GetRawAttributeValue(NL80211_ATTR_MAC, NULL)) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1190 | string mac; |
| 1191 | GetMacAttributeString(NL80211_ATTR_MAC, &mac); |
| 1192 | StringAppendF(&output, " to %s", mac.c_str()); |
| 1193 | } |
| 1194 | return output; |
| 1195 | } |
| 1196 | |
| 1197 | const uint8_t ScanAbortedMessage::kCommand = NL80211_CMD_SCAN_ABORTED; |
| 1198 | const char ScanAbortedMessage::kCommandString[] = "NL80211_CMD_SCAN_ABORTED"; |
| 1199 | |
| 1200 | string ScanAbortedMessage::ToString() const { |
| 1201 | string output(GetHeaderString()); |
| 1202 | output.append("scan aborted"); |
| 1203 | |
| 1204 | { |
| 1205 | output.append("; frequencies: "); |
| 1206 | vector<uint32_t> list; |
| 1207 | if (GetScanFrequenciesAttribute(NL80211_ATTR_SCAN_FREQUENCIES, &list)) { |
| 1208 | string str; |
| 1209 | for (vector<uint32_t>::const_iterator i = list.begin(); |
| 1210 | i != list.end(); ++i) { |
| 1211 | StringAppendF(&str, " %" PRIu32 ", ", *i); |
| 1212 | } |
| 1213 | output.append(str); |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | { |
| 1218 | output.append("; SSIDs: "); |
| 1219 | vector<string> list; |
| 1220 | if (GetScanSsidsAttribute(NL80211_ATTR_SCAN_SSIDS, &list)) { |
| 1221 | string str; |
| 1222 | for (vector<string>::const_iterator i = list.begin(); |
| 1223 | i != list.end(); ++i) { |
| 1224 | StringAppendF(&str, "\"%s\", ", i->c_str()); |
| 1225 | } |
| 1226 | output.append(str); |
| 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | return output; |
| 1231 | } |
| 1232 | |
| 1233 | const uint8_t TriggerScanMessage::kCommand = NL80211_CMD_TRIGGER_SCAN; |
| 1234 | const char TriggerScanMessage::kCommandString[] = "NL80211_CMD_TRIGGER_SCAN"; |
| 1235 | |
| 1236 | string TriggerScanMessage::ToString() const { |
| 1237 | string output(GetHeaderString()); |
| 1238 | output.append("scan started"); |
| 1239 | |
| 1240 | { |
| 1241 | output.append("; frequencies: "); |
| 1242 | vector<uint32_t> list; |
| 1243 | if (GetScanFrequenciesAttribute(NL80211_ATTR_SCAN_FREQUENCIES, &list)) { |
| 1244 | string str; |
| 1245 | for (vector<uint32_t>::const_iterator i = list.begin(); |
| 1246 | i != list.end(); ++i) { |
| 1247 | StringAppendF(&str, "%" PRIu32 ", ", *i); |
| 1248 | } |
| 1249 | output.append(str); |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | { |
| 1254 | output.append("; SSIDs: "); |
| 1255 | vector<string> list; |
| 1256 | if (GetScanSsidsAttribute(NL80211_ATTR_SCAN_SSIDS, &list)) { |
| 1257 | string str; |
| 1258 | for (vector<string>::const_iterator i = list.begin(); |
| 1259 | i != list.end(); ++i) { |
| 1260 | StringAppendF(&str, "\"%s\", ", i->c_str()); |
| 1261 | } |
| 1262 | output.append(str); |
| 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | return output; |
| 1267 | } |
| 1268 | |
| 1269 | const uint8_t UnknownMessage::kCommand = 0xff; |
| 1270 | const char UnknownMessage::kCommandString[] = "<Unknown Message Type>"; |
| 1271 | |
| 1272 | string UnknownMessage::ToString() const { |
| 1273 | string output(GetHeaderString()); |
| 1274 | StringAppendF(&output, "unknown event %u", command_); |
| 1275 | return output; |
| 1276 | } |
| 1277 | |
| 1278 | const uint8_t UnprotDeauthenticateMessage::kCommand = |
| 1279 | NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 1280 | const char UnprotDeauthenticateMessage::kCommandString[] = |
| 1281 | "NL80211_CMD_UNPROT_DEAUTHENTICATE"; |
| 1282 | |
| 1283 | string UnprotDeauthenticateMessage::ToString() const { |
| 1284 | string output(GetHeaderString()); |
| 1285 | StringAppendF(&output, "unprotected deauth %s", |
| 1286 | StringFromFrame(NL80211_ATTR_FRAME).c_str()); |
| 1287 | return output; |
| 1288 | } |
| 1289 | |
| 1290 | const uint8_t UnprotDisassociateMessage::kCommand = |
| 1291 | NL80211_CMD_UNPROT_DISASSOCIATE; |
| 1292 | const char UnprotDisassociateMessage::kCommandString[] = |
| 1293 | "NL80211_CMD_UNPROT_DISASSOCIATE"; |
| 1294 | |
| 1295 | string UnprotDisassociateMessage::ToString() const { |
| 1296 | string output(GetHeaderString()); |
| 1297 | StringAppendF(&output, "unprotected disassoc %s", |
| 1298 | StringFromFrame(NL80211_ATTR_FRAME).c_str()); |
| 1299 | return output; |
| 1300 | } |
| 1301 | |
| 1302 | // |
| 1303 | // Factory class. |
| 1304 | // |
| 1305 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 1306 | Nl80211Message *Nl80211MessageFactory::CreateMessage(nlmsghdr *msg) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1307 | if (!msg) { |
| 1308 | LOG(ERROR) << "NULL |msg| parameter"; |
| 1309 | return NULL; |
| 1310 | } |
| 1311 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 1312 | scoped_ptr<Nl80211Message> message; |
| 1313 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1314 | genlmsghdr *gnlh = |
| 1315 | reinterpret_cast<genlmsghdr *>(nlmsg_data(msg)); |
| 1316 | |
| 1317 | if (!gnlh) { |
| 1318 | LOG(ERROR) << "NULL gnlh"; |
| 1319 | return NULL; |
| 1320 | } |
| 1321 | |
| 1322 | switch (gnlh->cmd) { |
| 1323 | case AssociateMessage::kCommand: |
| 1324 | message.reset(new AssociateMessage()); break; |
| 1325 | case AuthenticateMessage::kCommand: |
| 1326 | message.reset(new AuthenticateMessage()); break; |
| 1327 | case CancelRemainOnChannelMessage::kCommand: |
| 1328 | message.reset(new CancelRemainOnChannelMessage()); break; |
| 1329 | case ConnectMessage::kCommand: |
| 1330 | message.reset(new ConnectMessage()); break; |
| 1331 | case DeauthenticateMessage::kCommand: |
| 1332 | message.reset(new DeauthenticateMessage()); break; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1333 | case DeleteStationMessage::kCommand: |
| 1334 | message.reset(new DeleteStationMessage()); break; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1335 | case DisassociateMessage::kCommand: |
| 1336 | message.reset(new DisassociateMessage()); break; |
| 1337 | case DisconnectMessage::kCommand: |
| 1338 | message.reset(new DisconnectMessage()); break; |
| 1339 | case FrameTxStatusMessage::kCommand: |
| 1340 | message.reset(new FrameTxStatusMessage()); break; |
| 1341 | case JoinIbssMessage::kCommand: |
| 1342 | message.reset(new JoinIbssMessage()); break; |
| 1343 | case MichaelMicFailureMessage::kCommand: |
| 1344 | message.reset(new MichaelMicFailureMessage()); break; |
| 1345 | case NewScanResultsMessage::kCommand: |
| 1346 | message.reset(new NewScanResultsMessage()); break; |
| 1347 | case NewStationMessage::kCommand: |
| 1348 | message.reset(new NewStationMessage()); break; |
| 1349 | case NewWifiMessage::kCommand: |
| 1350 | message.reset(new NewWifiMessage()); break; |
| 1351 | case NotifyCqmMessage::kCommand: |
| 1352 | message.reset(new NotifyCqmMessage()); break; |
| 1353 | case PmksaCandidateMessage::kCommand: |
| 1354 | message.reset(new PmksaCandidateMessage()); break; |
| 1355 | case RegBeaconHintMessage::kCommand: |
| 1356 | message.reset(new RegBeaconHintMessage()); break; |
| 1357 | case RegChangeMessage::kCommand: |
| 1358 | message.reset(new RegChangeMessage()); break; |
| 1359 | case RemainOnChannelMessage::kCommand: |
| 1360 | message.reset(new RemainOnChannelMessage()); break; |
| 1361 | case RoamMessage::kCommand: |
| 1362 | message.reset(new RoamMessage()); break; |
| 1363 | case ScanAbortedMessage::kCommand: |
| 1364 | message.reset(new ScanAbortedMessage()); break; |
| 1365 | case TriggerScanMessage::kCommand: |
| 1366 | message.reset(new TriggerScanMessage()); break; |
| 1367 | case UnprotDeauthenticateMessage::kCommand: |
| 1368 | message.reset(new UnprotDeauthenticateMessage()); break; |
| 1369 | case UnprotDisassociateMessage::kCommand: |
| 1370 | message.reset(new UnprotDisassociateMessage()); break; |
| 1371 | |
| 1372 | default: |
| 1373 | message.reset(new UnknownMessage(gnlh->cmd)); break; |
| 1374 | break; |
| 1375 | } |
| 1376 | |
| 1377 | nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1378 | |
| 1379 | // Parse the attributes from the nl message payload (which starts at the |
| 1380 | // header) into the 'tb' array. |
| 1381 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 1382 | genlmsg_attrlen(gnlh, 0), NULL); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1383 | |
| 1384 | if (!message->Init(tb, msg)) { |
| 1385 | LOG(ERROR) << "Message did not initialize properly"; |
| 1386 | return NULL; |
| 1387 | } |
| 1388 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1389 | return message.release(); |
| 1390 | } |
| 1391 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 1392 | Nl80211MessageDataCollector * |
| 1393 | Nl80211MessageDataCollector::GetInstance() { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1394 | return g_datacollector.Pointer(); |
| 1395 | } |
| 1396 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 1397 | Nl80211MessageDataCollector::Nl80211MessageDataCollector() { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1398 | need_to_print[NL80211_ATTR_PMKSA_CANDIDATE] = true; |
| 1399 | need_to_print[NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL] = true; |
| 1400 | need_to_print[NL80211_CMD_DEL_STATION] = true; |
| 1401 | need_to_print[NL80211_CMD_FRAME_TX_STATUS] = true; |
| 1402 | need_to_print[NL80211_CMD_JOIN_IBSS] = true; |
| 1403 | need_to_print[NL80211_CMD_MICHAEL_MIC_FAILURE] = true; |
| 1404 | need_to_print[NL80211_CMD_NEW_WIPHY] = true; |
| 1405 | need_to_print[NL80211_CMD_REG_BEACON_HINT] = true; |
| 1406 | need_to_print[NL80211_CMD_REG_CHANGE] = true; |
| 1407 | need_to_print[NL80211_CMD_REMAIN_ON_CHANNEL] = true; |
| 1408 | need_to_print[NL80211_CMD_ROAM] = true; |
| 1409 | need_to_print[NL80211_CMD_SCAN_ABORTED] = true; |
| 1410 | need_to_print[NL80211_CMD_UNPROT_DEAUTHENTICATE] = true; |
| 1411 | need_to_print[NL80211_CMD_UNPROT_DISASSOCIATE] = true; |
| 1412 | } |
| 1413 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame^] | 1414 | void Nl80211MessageDataCollector::CollectDebugData( |
| 1415 | const Nl80211Message &message, nlmsghdr *msg) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1416 | if (!msg) { |
| 1417 | LOG(ERROR) << "NULL |msg| parameter"; |
| 1418 | return; |
| 1419 | } |
| 1420 | |
| 1421 | bool doit = false; |
| 1422 | |
| 1423 | map<uint8_t, bool>::const_iterator node; |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 1424 | node = need_to_print.find(message.message_type()); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1425 | if (node != need_to_print.end()) |
| 1426 | doit = node->second; |
| 1427 | |
| 1428 | if (doit) { |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 1429 | LOG(INFO) << "@@const unsigned char " |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 1430 | << "k" << message.message_type_string() |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 1431 | << "[] = {"; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1432 | |
Christopher Wiley | efd521f | 2012-11-07 17:32:46 -0800 | [diff] [blame] | 1433 | int payload_bytes = nlmsg_datalen(msg); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1434 | |
| 1435 | size_t bytes = nlmsg_total_size(payload_bytes); |
| 1436 | unsigned char *rawdata = reinterpret_cast<unsigned char *>(msg); |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 1437 | for (size_t i = 0; i < bytes; ++i) { |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 1438 | LOG(INFO) << " 0x" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1439 | << std::hex << std::setfill('0') << std::setw(2) |
| 1440 | << + rawdata[i] << ","; |
| 1441 | } |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 1442 | LOG(INFO) << "};"; |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 1443 | need_to_print[message.message_type()] = false; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | } // namespace shill. |