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