blob: dedf2abbb45dbb59168ce544caa210bf3338bbee [file] [log] [blame]
Wade Guthrie5020b572012-10-12 15:51:14 -07001// 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 Guthrie5020b572012-10-12 15:51:14 -07007#include "shill/ieee80211.h"
Wade Guthrie5020b572012-10-12 15:51:14 -07008#include "shill/logging.h"
9#include "shill/metrics.h"
Wade Guthriebb9fca22013-04-10 17:21:42 -070010#include "shill/netlink_manager.h"
repo syncdc085c82012-12-28 08:54:41 -080011#include "shill/nl80211_message.h"
Wade Guthrie5020b572012-10-12 15:51:14 -070012
Wade Guthrie5020b572012-10-12 15:51:14 -070013namespace shill {
14
Wade Guthriebb9fca22013-04-10 17:21:42 -070015Callback80211Metrics::Callback80211Metrics(
16 const NetlinkManager &netlink_manager, Metrics *metrics)
Wade Guthrie318445d2013-05-16 14:05:28 -070017 : metrics_(metrics) {}
Wade Guthrie5020b572012-10-12 15:51:14 -070018
Wade Guthriec6c81962013-03-06 15:47:13 -080019void Callback80211Metrics::CollectDisconnectStatistics(
20 const NetlinkMessage &netlink_message) {
Wade Guthriec6c81962013-03-06 15:47:13 -080021 // We only handle deauthenticate messages, which are nl80211 messages.
Wade Guthrie318445d2013-05-16 14:05:28 -070022 if (netlink_message.message_type() != Nl80211Message::GetMessageType()) {
Wade Guthriec6c81962013-03-06 15:47:13 -080023 return;
24 }
25 const Nl80211Message &message =
26 * reinterpret_cast<const Nl80211Message *>(&netlink_message);
27
Christopher Wiley764538d2012-11-09 10:58:23 -080028 if (metrics_ &&
Wade Guthriebdcdaa72013-03-04 12:47:12 -080029 message.command() == DeauthenticateMessage::kCommand) {
Wade Guthrie0b1ebf12013-04-12 09:53:33 -070030 SLOG(WiFi, 3) << "Handling Deauthenticate Message";
Wade Guthrie5020b572012-10-12 15:51:14 -070031 Metrics::WiFiDisconnectByWhom by_whom =
Wade Guthrieefe1f0c2013-02-26 17:42:01 -080032 message.const_attributes()->IsFlagAttributeTrue(
repo sync90ee0fa2012-12-18 10:08:08 -080033 NL80211_ATTR_DISCONNECTED_BY_AP) ?
Wade Guthrie5020b572012-10-12 15:51:14 -070034 Metrics::kDisconnectedByAp : Metrics::kDisconnectedNotByAp;
35 uint16_t reason = static_cast<uint16_t>(
36 IEEE_80211::kReasonCodeInvalid);
Wade Guthrie8343f7f2012-12-04 13:52:32 -080037 ByteString rawdata;
Wade Guthrieefe1f0c2013-02-26 17:42:01 -080038 if (message.const_attributes()->GetRawAttributeValue(NL80211_ATTR_FRAME,
Wade Guthriec6c81962013-03-06 15:47:13 -080039 &rawdata)) {
Wade Guthrie8343f7f2012-12-04 13:52:32 -080040 Nl80211Frame frame(rawdata);
Wade Guthrie5020b572012-10-12 15:51:14 -070041 reason = frame.reason();
42 }
43 IEEE_80211::WiFiReasonCode reason_enum =
44 static_cast<IEEE_80211::WiFiReasonCode>(reason);
45 metrics_->Notify80211Disconnect(by_whom, reason_enum);
46 }
47}
48
Wade Guthrie5020b572012-10-12 15:51:14 -070049} // namespace shill.