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