blob: a309aa816c3a771d4676ef1502503e8db491394c [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) {
Christopher Wiley764538d2012-11-09 10:58:23 -080023 SLOG(WiFi, 3) << "Received " << message.message_type_string()
24 << " (" << + message.message_type() << ")";
25 if (metrics_ &&
26 message.message_type() == DeauthenticateMessage::kCommand) {
Wade Guthrie5020b572012-10-12 15:51:14 -070027 Metrics::WiFiDisconnectByWhom by_whom =
repo sync90ee0fa2012-12-18 10:08:08 -080028 message.attributes().IsFlagAttributeTrue(
29 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;
repo sync90ee0fa2012-12-18 10:08:08 -080034 if (message.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.