Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -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 | #include "shill/callback80211_metrics.h" |
| 6 | |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 7 | #include "shill/config80211.h" |
| 8 | #include "shill/ieee80211.h" |
| 9 | #include "shill/link_monitor.h" |
| 10 | #include "shill/logging.h" |
| 11 | #include "shill/metrics.h" |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 12 | #include "shill/nl80211_message.h" |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 13 | |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 14 | namespace shill { |
| 15 | |
Wade Guthrie | c6c8196 | 2013-03-06 15:47:13 -0800 | [diff] [blame^] | 16 | Callback80211Metrics::Callback80211Metrics(const Config80211 &config80211, |
| 17 | Metrics *metrics) |
| 18 | : metrics_(metrics), |
| 19 | nl80211_message_type_(NetlinkMessage::kIllegalMessageType) {} |
| 20 | |
| 21 | void Callback80211Metrics::InitNl80211FamilyId( |
| 22 | const Config80211 &config80211) { |
| 23 | nl80211_message_type_ = |
| 24 | config80211.GetMessageType(Nl80211Message::kMessageTypeString); |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 25 | } |
| 26 | |
Wade Guthrie | c6c8196 | 2013-03-06 15:47:13 -0800 | [diff] [blame^] | 27 | void Callback80211Metrics::CollectDisconnectStatistics( |
| 28 | const NetlinkMessage &netlink_message) { |
| 29 | if (nl80211_message_type_ == NetlinkMessage::kIllegalMessageType) { |
| 30 | LOG(ERROR) << "Somehow, nl80211_message_type_ didn't get set correctly"; |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | // We only handle deauthenticate messages, which are nl80211 messages. |
| 35 | if (netlink_message.message_type() != nl80211_message_type_) { |
| 36 | return; |
| 37 | } |
| 38 | const Nl80211Message &message = |
| 39 | * reinterpret_cast<const Nl80211Message *>(&netlink_message); |
| 40 | |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 41 | SLOG(WiFi, 3) << "Received " << message.command_string() |
| 42 | << " (" << + message.command() << ")"; |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 43 | if (metrics_ && |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 44 | message.command() == DeauthenticateMessage::kCommand) { |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 45 | Metrics::WiFiDisconnectByWhom by_whom = |
Wade Guthrie | efe1f0c | 2013-02-26 17:42:01 -0800 | [diff] [blame] | 46 | message.const_attributes()->IsFlagAttributeTrue( |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 47 | NL80211_ATTR_DISCONNECTED_BY_AP) ? |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 48 | Metrics::kDisconnectedByAp : Metrics::kDisconnectedNotByAp; |
| 49 | uint16_t reason = static_cast<uint16_t>( |
| 50 | IEEE_80211::kReasonCodeInvalid); |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 51 | ByteString rawdata; |
Wade Guthrie | efe1f0c | 2013-02-26 17:42:01 -0800 | [diff] [blame] | 52 | if (message.const_attributes()->GetRawAttributeValue(NL80211_ATTR_FRAME, |
Wade Guthrie | c6c8196 | 2013-03-06 15:47:13 -0800 | [diff] [blame^] | 53 | &rawdata)) { |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 54 | Nl80211Frame frame(rawdata); |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 55 | reason = frame.reason(); |
| 56 | } |
| 57 | IEEE_80211::WiFiReasonCode reason_enum = |
| 58 | static_cast<IEEE_80211::WiFiReasonCode>(reason); |
| 59 | metrics_->Notify80211Disconnect(by_whom, reason_enum); |
| 60 | } |
| 61 | } |
| 62 | |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 63 | } // namespace shill. |