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 | |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 16 | Callback80211Metrics::Callback80211Metrics(Metrics *metrics) |
| 17 | : Callback80211Object(), |
| 18 | metrics_(metrics) { |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | void Callback80211Metrics::Config80211MessageCallback( |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 22 | const Nl80211Message &message) { |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 23 | SLOG(WiFi, 3) << "Received " << message.message_type_string() |
| 24 | << " (" << + message.message_type() << ")"; |
| 25 | if (metrics_ && |
| 26 | message.message_type() == DeauthenticateMessage::kCommand) { |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 27 | Metrics::WiFiDisconnectByWhom by_whom = |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 28 | message.attributes().IsFlagAttributeTrue( |
| 29 | NL80211_ATTR_DISCONNECTED_BY_AP) ? |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 30 | Metrics::kDisconnectedByAp : Metrics::kDisconnectedNotByAp; |
| 31 | uint16_t reason = static_cast<uint16_t>( |
| 32 | IEEE_80211::kReasonCodeInvalid); |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 33 | ByteString rawdata; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 34 | if (message.attributes().GetRawAttributeValue(NL80211_ATTR_FRAME, |
| 35 | &rawdata)) { |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 36 | Nl80211Frame frame(rawdata); |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 37 | 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 Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 45 | } // namespace shill. |