blob: 27b5bc32fb6aa2a96e4ebfaf558a5cc560396b8c [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"
Wade Guthrie5020b572012-10-12 15:51:14 -070012#include "shill/user_bound_nlmessage.h"
13
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(
22 const UserBoundNlMessage &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 =
28 message.AttributeExists(NL80211_ATTR_DISCONNECTED_BY_AP) ?
29 Metrics::kDisconnectedByAp : Metrics::kDisconnectedNotByAp;
30 uint16_t reason = static_cast<uint16_t>(
31 IEEE_80211::kReasonCodeInvalid);
32 void *rawdata = NULL;
33 int frame_byte_count = 0;
34 if (message.GetRawAttributeData(NL80211_ATTR_FRAME, &rawdata,
35 &frame_byte_count)) {
36 const uint8_t *frame_data = reinterpret_cast<const uint8_t *>(rawdata);
37 Nl80211Frame frame(frame_data, frame_byte_count);
38 reason = frame.reason();
39 }
40 IEEE_80211::WiFiReasonCode reason_enum =
41 static_cast<IEEE_80211::WiFiReasonCode>(reason);
42 metrics_->Notify80211Disconnect(by_whom, reason_enum);
43 }
44}
45
Wade Guthrie5020b572012-10-12 15:51:14 -070046} // namespace shill.