blob: 72c86a11e81b6cbdb72adf9ec7f072f4348cf4c5 [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"
16#include "shill/scope_logger.h"
17#include "shill/user_bound_nlmessage.h"
18
19using base::Bind;
Wade Guthrieb1ec8602012-10-18 17:26:14 -070020using base::StringAppendF;
Wade Guthrie64b4c142012-08-20 15:21:01 -070021using std::string;
22
23namespace shill {
24
Christopher Wileyfe34be02012-11-12 16:02:46 -080025Callback80211Object::Callback80211Object()
Wade Guthrie5d3d6de2012-11-02 11:08:34 -070026 : weak_ptr_factory_(this),
Christopher Wileyfe34be02012-11-12 16:02:46 -080027 callback_(Bind(&Callback80211Object::ReceiveConfig80211Message,
28 weak_ptr_factory_.GetWeakPtr())) {
Wade Guthrie64b4c142012-08-20 15:21:01 -070029}
30
31Callback80211Object::~Callback80211Object() {
32 DeinstallAsCallback();
33}
34
35void Callback80211Object::Config80211MessageCallback(
Wade Guthried4977f22012-08-22 12:37:54 -070036 const UserBoundNlMessage &message) {
Wade Guthrieb1ec8602012-10-18 17:26:14 -070037 // Show the simplified version of the message.
38 string output("@");
39 StringAppendF(&output, "%s", message.ToString().c_str());
40 SLOG(WiFi, 2) << output;
Wade Guthrie64b4c142012-08-20 15:21:01 -070041
Wade Guthrieb1ec8602012-10-18 17:26:14 -070042 // Show the more complicated version of the message.
Christopher Wiley764538d2012-11-09 10:58:23 -080043 SLOG(WiFi, 3) << "Received " << message.message_type_string()
44 << " (" << + message.message_type() << ")";
Wade Guthrieb1ec8602012-10-18 17:26:14 -070045
46 scoped_ptr<UserBoundNlMessage::AttributeNameIterator> i;
Wade Guthried4977f22012-08-22 12:37:54 -070047 for (i.reset(message.GetAttributeNameIterator()); !i->AtEnd(); i->Advance()) {
Wade Guthrie64b4c142012-08-20 15:21:01 -070048 string value = "<unknown>";
Wade Guthried4977f22012-08-22 12:37:54 -070049 message.GetAttributeString(i->GetName(), &value);
Wade Guthrieb1ec8602012-10-18 17:26:14 -070050 SLOG(WiFi, 3) << " Attr:" << message.StringFromAttributeName(i->GetName())
Wade Guthrie64b4c142012-08-20 15:21:01 -070051 << "=" << value
Wade Guthried4977f22012-08-22 12:37:54 -070052 << " Type:" << message.GetAttributeTypeString(i->GetName());
Wade Guthrie64b4c142012-08-20 15:21:01 -070053 }
54}
55
Wade Guthrieb1ec8602012-10-18 17:26:14 -070056bool Callback80211Object::InstallAsBroadcastCallback() {
Christopher Wileyfe34be02012-11-12 16:02:46 -080057 return Config80211::GetInstance()->AddBroadcastCallback(callback_);
Wade Guthrie64b4c142012-08-20 15:21:01 -070058}
59
60bool Callback80211Object::DeinstallAsCallback() {
Christopher Wileyfe34be02012-11-12 16:02:46 -080061 return Config80211::GetInstance()->RemoveBroadcastCallback(callback_);
62}
63
64void Callback80211Object::ReceiveConfig80211Message(
65 const UserBoundNlMessage &msg) {
66 Config80211MessageCallback(msg);
Wade Guthrie64b4c142012-08-20 15:21:01 -070067}
68
Wade Guthrie64b4c142012-08-20 15:21:01 -070069} // namespace shill.