Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -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_object.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include <base/memory/weak_ptr.h> |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 10 | #include <base/stringprintf.h> |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 11 | |
| 12 | #include "shill/config80211.h" |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 13 | #include "shill/ieee80211.h" |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 14 | #include "shill/link_monitor.h" |
| 15 | #include "shill/logging.h" |
| 16 | #include "shill/scope_logger.h" |
| 17 | #include "shill/user_bound_nlmessage.h" |
| 18 | |
| 19 | using base::Bind; |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 20 | using base::StringAppendF; |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 21 | using std::string; |
| 22 | |
| 23 | namespace shill { |
| 24 | |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 25 | Callback80211Object::Callback80211Object() |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 26 | : weak_ptr_factory_(this), |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 27 | callback_(Bind(&Callback80211Object::ReceiveConfig80211Message, |
| 28 | weak_ptr_factory_.GetWeakPtr())) { |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | Callback80211Object::~Callback80211Object() { |
| 32 | DeinstallAsCallback(); |
| 33 | } |
| 34 | |
| 35 | void Callback80211Object::Config80211MessageCallback( |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 36 | const UserBoundNlMessage &message) { |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 37 | // Show the simplified version of the message. |
| 38 | string output("@"); |
| 39 | StringAppendF(&output, "%s", message.ToString().c_str()); |
| 40 | SLOG(WiFi, 2) << output; |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 41 | |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 42 | // Show the more complicated version of the message. |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 43 | SLOG(WiFi, 3) << "Received " << message.message_type_string() |
| 44 | << " (" << + message.message_type() << ")"; |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 45 | |
| 46 | scoped_ptr<UserBoundNlMessage::AttributeNameIterator> i; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 47 | for (i.reset(message.GetAttributeNameIterator()); !i->AtEnd(); i->Advance()) { |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 48 | string value = "<unknown>"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 49 | message.GetAttributeString(i->GetName(), &value); |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 50 | SLOG(WiFi, 3) << " Attr:" << message.StringFromAttributeName(i->GetName()) |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 51 | << "=" << value |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 52 | << " Type:" << message.GetAttributeTypeString(i->GetName()); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 56 | bool Callback80211Object::InstallAsBroadcastCallback() { |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 57 | return Config80211::GetInstance()->AddBroadcastCallback(callback_); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | bool Callback80211Object::DeinstallAsCallback() { |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 61 | return Config80211::GetInstance()->RemoveBroadcastCallback(callback_); |
| 62 | } |
| 63 | |
| 64 | void Callback80211Object::ReceiveConfig80211Message( |
| 65 | const UserBoundNlMessage &msg) { |
| 66 | Config80211MessageCallback(msg); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 69 | } // namespace shill. |