blob: c47cc7c69930c7f74e62b4251bb259b34b58bfbd [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/config80211.h"
8#include "shill/ieee80211.h"
9#include "shill/link_monitor.h"
10#include "shill/logging.h"
11#include "shill/metrics.h"
repo syncdc085c82012-12-28 08:54:41 -080012#include "shill/nl80211_message.h"
Wade Guthrie5020b572012-10-12 15:51:14 -070013
Wade Guthrie5020b572012-10-12 15:51:14 -070014namespace shill {
15
Christopher Wileyfe34be02012-11-12 16:02:46 -080016Callback80211Metrics::Callback80211Metrics(Metrics *metrics)
17 : Callback80211Object(),
18 metrics_(metrics) {
Wade Guthrie5020b572012-10-12 15:51:14 -070019}
20
21void Callback80211Metrics::Config80211MessageCallback(
repo syncdc085c82012-12-28 08:54:41 -080022 const Nl80211Message &message) {
Wade Guthriebdcdaa72013-03-04 12:47:12 -080023 SLOG(WiFi, 3) << "Received " << message.command_string()
24 << " (" << + message.command() << ")";
Christopher Wiley764538d2012-11-09 10:58:23 -080025 if (metrics_ &&
Wade Guthriebdcdaa72013-03-04 12:47:12 -080026 message.command() == DeauthenticateMessage::kCommand) {
Wade Guthrie5020b572012-10-12 15:51:14 -070027 Metrics::WiFiDisconnectByWhom by_whom =
Wade Guthrieefe1f0c2013-02-26 17:42:01 -080028 message.const_attributes()->IsFlagAttributeTrue(
repo sync90ee0fa2012-12-18 10:08:08 -080029 NL80211_ATTR_DISCONNECTED_BY_AP) ?
Wade Guthrie5020b572012-10-12 15:51:14 -070030 Metrics::kDisconnectedByAp : Metrics::kDisconnectedNotByAp;
31 uint16_t reason = static_cast<uint16_t>(
32 IEEE_80211::kReasonCodeInvalid);
Wade Guthrie8343f7f2012-12-04 13:52:32 -080033 ByteString rawdata;
Wade Guthrieefe1f0c2013-02-26 17:42:01 -080034 if (message.const_attributes()->GetRawAttributeValue(NL80211_ATTR_FRAME,
35 &rawdata)) {
Wade Guthrie8343f7f2012-12-04 13:52:32 -080036 Nl80211Frame frame(rawdata);
Wade Guthrie5020b572012-10-12 15:51:14 -070037 reason = frame.reason();
38 }
39 IEEE_80211::WiFiReasonCode reason_enum =
40 static_cast<IEEE_80211::WiFiReasonCode>(reason);
41 metrics_->Notify80211Disconnect(by_whom, reason_enum);
42 }
43}
44
Wade Guthrie5020b572012-10-12 15:51:14 -070045} // namespace shill.