blob: 6c4d6177303c1a3482ee1c2916370df843c44ebc [file] [log] [blame]
Wade Guthrie64b4c142012-08-20 15:21:01 -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_object.h"
6
7#include <string>
8
9#include <base/memory/weak_ptr.h>
Wade Guthrieb1ec8602012-10-18 17:26:14 -070010#include <base/stringprintf.h>
Wade Guthrie64b4c142012-08-20 15:21:01 -070011
12#include "shill/config80211.h"
Wade Guthried4977f22012-08-22 12:37:54 -070013#include "shill/ieee80211.h"
Wade Guthrie64b4c142012-08-20 15:21:01 -070014#include "shill/link_monitor.h"
15#include "shill/logging.h"
Wade Guthried4977f22012-08-22 12:37:54 -070016#include "shill/metrics.h"
Wade Guthrie64b4c142012-08-20 15:21:01 -070017#include "shill/scope_logger.h"
18#include "shill/user_bound_nlmessage.h"
19
20using base::Bind;
Wade Guthrieb1ec8602012-10-18 17:26:14 -070021using base::StringAppendF;
Wade Guthrie64b4c142012-08-20 15:21:01 -070022using std::string;
23
24namespace shill {
25
Wade Guthrie5020b572012-10-12 15:51:14 -070026Callback80211Object::Callback80211Object(Config80211 *config80211)
27 : config80211_(config80211), weak_ptr_factory_(this) {
Wade Guthrie64b4c142012-08-20 15:21:01 -070028}
29
30Callback80211Object::~Callback80211Object() {
31 DeinstallAsCallback();
32}
33
34void Callback80211Object::Config80211MessageCallback(
Wade Guthried4977f22012-08-22 12:37:54 -070035 const UserBoundNlMessage &message) {
Wade Guthrieb1ec8602012-10-18 17:26:14 -070036 // Show the simplified version of the message.
37 string output("@");
38 StringAppendF(&output, "%s", message.ToString().c_str());
39 SLOG(WiFi, 2) << output;
Wade Guthrie64b4c142012-08-20 15:21:01 -070040
Wade Guthrieb1ec8602012-10-18 17:26:14 -070041 // Show the more complicated version of the message.
42 SLOG(WiFi, 3) << "Received " << message.GetMessageTypeString()
43 << " (" << + message.GetMessageType() << ")";
44
45 scoped_ptr<UserBoundNlMessage::AttributeNameIterator> i;
Wade Guthried4977f22012-08-22 12:37:54 -070046 for (i.reset(message.GetAttributeNameIterator()); !i->AtEnd(); i->Advance()) {
Wade Guthrie64b4c142012-08-20 15:21:01 -070047 string value = "<unknown>";
Wade Guthried4977f22012-08-22 12:37:54 -070048 message.GetAttributeString(i->GetName(), &value);
Wade Guthrieb1ec8602012-10-18 17:26:14 -070049 SLOG(WiFi, 3) << " Attr:" << message.StringFromAttributeName(i->GetName())
Wade Guthrie64b4c142012-08-20 15:21:01 -070050 << "=" << value
Wade Guthried4977f22012-08-22 12:37:54 -070051 << " Type:" << message.GetAttributeTypeString(i->GetName());
Wade Guthrie64b4c142012-08-20 15:21:01 -070052 }
53}
54
Wade Guthrieb1ec8602012-10-18 17:26:14 -070055bool Callback80211Object::InstallAsBroadcastCallback() {
Wade Guthrie64b4c142012-08-20 15:21:01 -070056 if (config80211_) {
Wade Guthrieb1ec8602012-10-18 17:26:14 -070057 callback_ = Bind(&Callback80211Object::Config80211MessageCallback,
58 weak_ptr_factory_.GetWeakPtr());
59 return config80211_->AddBroadcastCallback(callback_);
Wade Guthrie64b4c142012-08-20 15:21:01 -070060 }
61 return false;
62}
63
64bool Callback80211Object::DeinstallAsCallback() {
65 if (config80211_) {
Wade Guthrieb1ec8602012-10-18 17:26:14 -070066 config80211_->RemoveBroadcastCallback(callback_);
Wade Guthrie64b4c142012-08-20 15:21:01 -070067 return true;
68 }
69 return false;
70}
71
Wade Guthrie64b4c142012-08-20 15:21:01 -070072} // namespace shill.