shill: Renames Config80211 to NetlinkManager.
The domain of Config80211 has extended to different types of netlink
message communication. That warrants a name change. This CL changes
the name of the class plus a bunch of objects of that class. This
required changing the names of some files.
In addition, a few (half a dozen, maybe) readability issues were
addressed. These include inaccurate header guard comments and bad
indentation.
BUG=None
TEST=unittest
Change-Id: Id0006d5d37a98ed6c138f9982a2aa3624b308757
Reviewed-on: https://gerrit.chromium.org/gerrit/47860
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Commit-Queue: Wade Guthrie <wdg@chromium.org>
Reviewed-by: Wade Guthrie <wdg@chromium.org>
Tested-by: Wade Guthrie <wdg@chromium.org>
diff --git a/Makefile b/Makefile
index 7c718da..1bc0e44 100644
--- a/Makefile
+++ b/Makefile
@@ -201,7 +201,6 @@
byte_string.o \
callback80211_metrics.o \
certificate_file.o \
- config80211.o \
connection.o \
connection_health_checker.o \
control_netlink_attribute.o \
@@ -255,6 +254,7 @@
minijail.o \
modem_info.o \
netlink_attribute.o \
+ netlink_manager.o \
netlink_message.o \
netlink_socket.o \
nl80211_attribute.o \
@@ -331,7 +331,6 @@
crypto_provider_unittest.o \
crypto_rot47_unittest.o \
crypto_util_proxy_unittest.o \
- config80211_unittest.o \
connection_unittest.o \
connection_health_checker_unittest.o \
dbus_adaptor_unittest.o \
@@ -427,6 +426,7 @@
mock_wimax_provider.o \
mock_wimax_service.o \
modem_info_unittest.o \
+ netlink_manager_unittest.o \
netlink_message_unittest.o \
netlink_socket_unittest.o \
nice_mock_control.o \
diff --git a/callback80211_metrics.cc b/callback80211_metrics.cc
index 01369c5..28437ad 100644
--- a/callback80211_metrics.cc
+++ b/callback80211_metrics.cc
@@ -4,23 +4,23 @@
#include "shill/callback80211_metrics.h"
-#include "shill/config80211.h"
#include "shill/ieee80211.h"
#include "shill/logging.h"
#include "shill/metrics.h"
+#include "shill/netlink_manager.h"
#include "shill/nl80211_message.h"
namespace shill {
-Callback80211Metrics::Callback80211Metrics(const Config80211 &config80211,
- Metrics *metrics)
+Callback80211Metrics::Callback80211Metrics(
+ const NetlinkManager &netlink_manager, Metrics *metrics)
: metrics_(metrics),
nl80211_message_type_(NetlinkMessage::kIllegalMessageType) {}
void Callback80211Metrics::InitNl80211FamilyId(
- const Config80211 &config80211) {
+ const NetlinkManager &netlink_manager) {
nl80211_message_type_ =
- config80211.GetMessageType(Nl80211Message::kMessageTypeString);
+ netlink_manager.GetMessageType(Nl80211Message::kMessageTypeString);
}
void Callback80211Metrics::CollectDisconnectStatistics(
diff --git a/callback80211_metrics.h b/callback80211_metrics.h
index a3a54be..6ff50c0 100644
--- a/callback80211_metrics.h
+++ b/callback80211_metrics.h
@@ -11,26 +11,26 @@
#include <base/basictypes.h>
#include <base/memory/weak_ptr.h>
-#include "shill/config80211.h"
+#include "shill/netlink_manager.h"
namespace shill {
-class Config80211;
class Metrics;
+class NetlinkManager;
class NetlinkMessage;
-// Config80211 callback object that sends stuff to UMA metrics.
+// NetlinkManager callback object that sends stuff to UMA metrics.
class Callback80211Metrics :
public base::SupportsWeakPtr<Callback80211Metrics> {
public:
- Callback80211Metrics(const Config80211 &config80211, Metrics *metrics);
+ Callback80211Metrics(const NetlinkManager &netlink_manager, Metrics *metrics);
// This retrieves the numerical id for the "nl80211" family of messages.
// Should only be called (once) at initialization time but must be called
- // only after Config80211 knows about the "nl80211" family.
- void InitNl80211FamilyId(const Config80211 &config80211);
+ // only after NetlinkManager knows about the "nl80211" family.
+ void InitNl80211FamilyId(const NetlinkManager &netlink_manager);
- // Called with each broadcast netlink message that arrives to Config80211.
+ // Called with each broadcast netlink message that arrives to NetlinkManager.
// If the message is a deauthenticate message, the method collects the reason
// for the deauthentication and communicates those to UMA.
void CollectDisconnectStatistics(const NetlinkMessage &msg);
diff --git a/generic_netlink_message.cc b/generic_netlink_message.cc
index c9fa543..fcd4f42 100644
--- a/generic_netlink_message.cc
+++ b/generic_netlink_message.cc
@@ -115,7 +115,7 @@
for (int i = 0; i < CTRL_ATTR_MAX + 1; ++i) {
if (tb[i]) {
- // TODO(wdg): When Nl80211Messages instantiate their own attributes,
+ // TODO(wdg): When NetlinkMessages instantiate their own attributes,
// this call should, instead, call |SetAttributeFromNlAttr|.
attributes_->CreateAndInitAttribute(
i, tb[i], Bind(&NetlinkAttribute::NewControlAttributeFromId));
diff --git a/mock_config80211.h b/mock_config80211.h
deleted file mode 100644
index 1903b35..0000000
--- a/mock_config80211.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef SHILL_MOCK_CONFIG80211_H_
-#define SHILL_MOCK_CONFIG80211_H_
-
-#include <gmock/gmock.h>
-
-#include "shill/config80211.h"
-
-namespace shill {
-
-class MockConfig80211 : public Config80211 {
- public:
- MockConfig80211() {}
- ~MockConfig80211() {}
-};
-
-} // namespace
-
-#endif // SHILL_MOCK_CONFIG80211_H_
diff --git a/mock_netlink_manager.h b/mock_netlink_manager.h
new file mode 100644
index 0000000..a271931
--- /dev/null
+++ b/mock_netlink_manager.h
@@ -0,0 +1,22 @@
+// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHILL_MOCK_NETLINK_MANAGER_H_
+#define SHILL_MOCK_NETLINK_MANAGER_H_
+
+#include <gmock/gmock.h>
+
+#include "shill/netlink_manager.h"
+
+namespace shill {
+
+class MockNetlinkManager : public NetlinkManager {
+ public:
+ MockNetlinkManager() {}
+ ~MockNetlinkManager() {}
+};
+
+} // namespace shill
+
+#endif // SHILL_MOCK_NETLINK_MANAGER_H_
diff --git a/config80211.cc b/netlink_manager.cc
similarity index 85%
rename from config80211.cc
rename to netlink_manager.cc
index 7d09fd1..14dc422 100644
--- a/config80211.cc
+++ b/netlink_manager.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "shill/config80211.h"
+#include "shill/netlink_manager.h"
#include <netlink/netlink.h>
#include <sys/select.h>
@@ -32,31 +32,31 @@
namespace shill {
namespace {
-LazyInstance<Config80211> g_config80211 = LAZY_INSTANCE_INITIALIZER;
+LazyInstance<NetlinkManager> g_netlink_manager = LAZY_INSTANCE_INITIALIZER;
} // namespace
-const char Config80211::kEventTypeConfig[] = "config";
-const char Config80211::kEventTypeScan[] = "scan";
-const char Config80211::kEventTypeRegulatory[] = "regulatory";
-const char Config80211::kEventTypeMlme[] = "mlme";
-const long Config80211::kMaximumNewFamilyWaitSeconds = 1;
-const long Config80211::kMaximumNewFamilyWaitMicroSeconds = 0;
+const char NetlinkManager::kEventTypeConfig[] = "config";
+const char NetlinkManager::kEventTypeScan[] = "scan";
+const char NetlinkManager::kEventTypeRegulatory[] = "regulatory";
+const char NetlinkManager::kEventTypeMlme[] = "mlme";
+const long NetlinkManager::kMaximumNewFamilyWaitSeconds = 1;
+const long NetlinkManager::kMaximumNewFamilyWaitMicroSeconds = 0;
-Config80211::MessageType::MessageType() :
+NetlinkManager::MessageType::MessageType() :
family_id(NetlinkMessage::kIllegalMessageType) {}
-Config80211::Config80211()
+NetlinkManager::NetlinkManager()
: dispatcher_(NULL),
weak_ptr_factory_(this),
- dispatcher_callback_(Bind(&Config80211::OnRawNlMessageReceived,
+ dispatcher_callback_(Bind(&NetlinkManager::OnRawNlMessageReceived,
weak_ptr_factory_.GetWeakPtr())),
sock_(NULL) {}
-Config80211 *Config80211::GetInstance() {
- return g_config80211.Pointer();
+NetlinkManager *NetlinkManager::GetInstance() {
+ return g_netlink_manager.Pointer();
}
-void Config80211::Reset(bool full) {
+void NetlinkManager::Reset(bool full) {
ClearBroadcastHandlers();
message_types_.clear();
if (full) {
@@ -66,7 +66,7 @@
}
}
-void Config80211::OnNewFamilyMessage(const NetlinkMessage &raw_message) {
+void NetlinkManager::OnNewFamilyMessage(const NetlinkMessage &raw_message) {
uint16_t family_id;
string family_name;
@@ -136,7 +136,7 @@
message_types_[family_name].family_id = family_id;
}
-bool Config80211::Init() {
+bool NetlinkManager::Init() {
// Install message factory for control class of messages, which has
// statically-known message type.
message_factory_.AddFactoryMethod(
@@ -156,7 +156,7 @@
return true;
}
-void Config80211::Start(EventDispatcher *dispatcher) {
+void NetlinkManager::Start(EventDispatcher *dispatcher) {
dispatcher_ = dispatcher;
CHECK(dispatcher_);
// Install ourselves in the shill mainloop so we receive messages on the
@@ -164,14 +164,14 @@
dispatcher_handler_.reset(dispatcher_->CreateInputHandler(
file_descriptor(),
dispatcher_callback_,
- Bind(&Config80211::OnReadError, weak_ptr_factory_.GetWeakPtr())));
+ Bind(&NetlinkManager::OnReadError, weak_ptr_factory_.GetWeakPtr())));
}
-int Config80211::file_descriptor() const {
+int NetlinkManager::file_descriptor() const {
return (sock_ ? sock_->file_descriptor() : -1);
}
-uint16_t Config80211::GetFamily(string name,
+uint16_t NetlinkManager::GetFamily(string name,
const NetlinkMessageFactory::FactoryMethod &message_factory) {
MessageType &message_type = message_types_[name];
if (message_type.family_id != NetlinkMessage::kIllegalMessageType) {
@@ -192,7 +192,7 @@
LOG(ERROR) << "Couldn't set string attribute";
return false;
}
- SendMessage(&msg, Bind(&Config80211::OnNewFamilyMessage,
+ SendMessage(&msg, Bind(&NetlinkManager::OnNewFamilyMessage,
weak_ptr_factory_.GetWeakPtr()));
// Wait for a response. The code absolutely needs family_ids for its
@@ -256,7 +256,7 @@
return NetlinkMessage::kIllegalMessageType;
}
-uint16_t Config80211::GetMessageType(string name) const {
+uint16_t NetlinkManager::GetMessageType(string name) const {
map<const string, MessageType>::const_iterator family =
message_types_.find(name);
if (family == message_types_.end()) {
@@ -266,7 +266,7 @@
return family->second.family_id;
}
-bool Config80211::AddBroadcastHandler(const NetlinkMessageHandler &handler) {
+bool NetlinkManager::AddBroadcastHandler(const NetlinkMessageHandler &handler) {
list<NetlinkMessageHandler>::iterator i;
if (FindBroadcastHandler(handler)) {
LOG(WARNING) << "Trying to re-add a handler";
@@ -277,12 +277,12 @@
return false;
}
// And add the handler to the list.
- SLOG(WiFi, 3) << "Config80211::" << __func__ << " - adding handler";
+ SLOG(WiFi, 3) << "NetlinkManager::" << __func__ << " - adding handler";
broadcast_handlers_.push_back(handler);
return true;
}
-bool Config80211::RemoveBroadcastHandler(
+bool NetlinkManager::RemoveBroadcastHandler(
const NetlinkMessageHandler &handler) {
list<NetlinkMessageHandler>::iterator i;
for (i = broadcast_handlers_.begin(); i != broadcast_handlers_.end(); ++i) {
@@ -297,7 +297,7 @@
return false;
}
-bool Config80211::FindBroadcastHandler(const NetlinkMessageHandler &handler)
+bool NetlinkManager::FindBroadcastHandler(const NetlinkMessageHandler &handler)
const {
list<NetlinkMessageHandler>::const_iterator i;
for (i = broadcast_handlers_.begin(); i != broadcast_handlers_.end(); ++i) {
@@ -308,11 +308,11 @@
return false;
}
-void Config80211::ClearBroadcastHandlers() {
+void NetlinkManager::ClearBroadcastHandlers() {
broadcast_handlers_.clear();
}
-bool Config80211::SendMessage(NetlinkMessage *message,
+bool NetlinkManager::SendMessage(NetlinkMessage *message,
const NetlinkMessageHandler &handler) {
if (!message) {
LOG(ERROR) << "Message is NULL.";
@@ -345,7 +345,7 @@
return true;
}
-bool Config80211::RemoveMessageHandler(const NetlinkMessage &message) {
+bool NetlinkManager::RemoveMessageHandler(const NetlinkMessage &message) {
if (!ContainsKey(message_handlers_, message.sequence_number())) {
return false;
}
@@ -353,13 +353,13 @@
return true;
}
-uint32_t Config80211::GetSequenceNumber() {
+uint32_t NetlinkManager::GetSequenceNumber() {
return sock_ ?
sock_->GetSequenceNumber() : NetlinkMessage::kBroadcastSequenceNumber;
}
-bool Config80211::SubscribeToEvents(const string &family_id,
- const string &group_name) {
+bool NetlinkManager::SubscribeToEvents(const string &family_id,
+ const string &group_name) {
if (!ContainsKey(message_types_, family_id)) {
LOG(ERROR) << "Family '" << family_id << "' doesn't exist";
return false;
@@ -378,7 +378,7 @@
return sock_->SubscribeToEvents(group_id);
}
-void Config80211::OnRawNlMessageReceived(InputData *data) {
+void NetlinkManager::OnRawNlMessageReceived(InputData *data) {
if (!data) {
LOG(ERROR) << __func__ << "() called with null header.";
return;
@@ -404,7 +404,7 @@
}
}
-void Config80211::OnNlMessageReceived(nlmsghdr *msg) {
+void NetlinkManager::OnNlMessageReceived(nlmsghdr *msg) {
if (!msg) {
LOG(ERROR) << __func__ << "() called with null header.";
return;
@@ -459,11 +459,11 @@
}
}
-void Config80211::OnReadError(const Error &error) {
- // TODO(wdg): When config80211 is used for scan, et al., this should either be
- // LOG(FATAL) or the code should properly deal with errors, e.g., dropped
- // messages due to the socket buffer being full.
- LOG(ERROR) << "Config80211's netlink Socket read returns error: "
+void NetlinkManager::OnReadError(const Error &error) {
+ // TODO(wdg): When netlink_manager is used for scan, et al., this should
+ // either be LOG(FATAL) or the code should properly deal with errors,
+ // e.g., dropped messages due to the socket buffer being full.
+ LOG(ERROR) << "NetlinkManager's netlink Socket read returns error: "
<< error.message();
}
diff --git a/config80211.h b/netlink_manager.h
similarity index 82%
rename from config80211.h
rename to netlink_manager.h
index cfd92b5..66cffb0 100644
--- a/config80211.h
+++ b/netlink_manager.h
@@ -49,15 +49,15 @@
//
// - Then send the message, passing-in a closure to the handler you created:
//
-// Config80211 *config80211 = Config80211::GetInstance();
-// config80211->SendMessage(&msg, Bind(&SomeClass::MyMessageHandler));
+// NetlinkManager *netlink_manager = NetlinkManager::GetInstance();
+// netlink_manager->SendMessage(&msg, Bind(&SomeClass::MyMessageHandler));
//
-// Config80211 will then save your handler and send your message. When a
+// NetlinkManager will then save your handler and send your message. When a
// response to your message arrives, it'll call your handler.
//
-#ifndef SHILL_CONFIG80211_H_
-#define SHILL_CONFIG80211_H_
+#ifndef SHILL_NETLINK_MANAGER_H_
+#define SHILL_NETLINK_MANAGER_H_
#include <gtest/gtest_prod.h> // for FRIEND_TEST
@@ -82,19 +82,19 @@
class IOHandler;
class NetlinkSocket;
-// Config80211 is a singleton that coordinates sending netlink messages to,
+// NetlinkManager is a singleton that coordinates sending netlink messages to,
// and receiving netlink messages from, the kernel. The first use of this is
// to communicate between user-space and the cfg80211 module that manages wifi
-// drivers. Bring Config80211 up as follows:
-// Config80211 *config80211_ = Config80211::GetInstance();
+// drivers. Bring NetlinkManager up as follows:
+// NetlinkManager *netlink_manager_ = NetlinkManager::GetInstance();
// EventDispatcher dispatcher_;
-// config80211_->Init(); // Initialize the socket.
+// netlink_manager_->Init(); // Initialize the socket.
// // Get message types for all dynamic message types.
// Nl80211Message::SetMessageType(
-// config80211_->GetFamily(Nl80211Message::kMessageTypeString,
+// netlink_manager_->GetFamily(Nl80211Message::kMessageTypeString,
// Bind(&Nl80211Message::CreateMessage)));
-// config80211_->Start(&dispatcher_); // Leave event loop handling to others.
-class Config80211 {
+// netlink_manager_->Start(&dispatcher_);
+class NetlinkManager {
public:
typedef base::Callback<void(const NetlinkMessage &)> NetlinkMessageHandler;
@@ -117,10 +117,10 @@
static const char kEventTypeRegulatory[];
static const char kEventTypeMlme[];
- // Config80211 is a singleton and this is the way to access it.
- static Config80211 *GetInstance();
+ // NetlinkManager is a singleton and this is the way to access it.
+ static NetlinkManager *GetInstance();
- // Performs non-trivial object initialization of the Config80211 singleton.
+ // Performs non-trivial object initialization of the NetlinkManager singleton.
bool Init();
// Passes the job of waiting for, and the subsequent reading from, the
@@ -145,7 +145,7 @@
// the message family.
uint16_t GetMessageType(std::string name) const;
- // Install a Config80211 NetlinkMessageHandler. The handler is a
+ // Install a NetlinkManager NetlinkMessageHandler. The handler is a
// user-supplied object to be called by the system for user-bound messages
// that do not have a corresponding messaage-specific callback.
// |AddBroadcastHandler| should be called before |SubscribeToEvents| since
@@ -161,7 +161,7 @@
// Uninstall all broadcast netlink message handlers.
void ClearBroadcastHandlers();
- // Sends a netlink message to the kernel using the Config80211 socket after
+ // Sends a netlink message to the kernel using the NetlinkManager socket after
// installing a handler to deal with the kernel's response to the message.
// TODO(wdg): Eventually, this should also include a timeout and a callback
// to call in case of timeout.
@@ -176,21 +176,21 @@
bool SubscribeToEvents(const std::string &family, const std::string &group);
// Gets the next sequence number for a NetlinkMessage to be sent over
- // Config80211's netlink socket.
+ // NetlinkManager's netlink socket.
uint32_t GetSequenceNumber();
protected:
- friend struct base::DefaultLazyInstanceTraits<Config80211>;
+ friend struct base::DefaultLazyInstanceTraits<NetlinkManager>;
- explicit Config80211();
+ explicit NetlinkManager();
private:
- friend class Config80211Test;
+ friend class NetlinkManagerTest;
friend class NetlinkMessageTest;
friend class ShillDaemonTest;
- FRIEND_TEST(Config80211Test, AddLinkTest);
- FRIEND_TEST(Config80211Test, BroadcastHandlerTest);
- FRIEND_TEST(Config80211Test, MessageHandlerTest);
+ FRIEND_TEST(NetlinkManagerTest, AddLinkTest);
+ FRIEND_TEST(NetlinkManagerTest, BroadcastHandlerTest);
+ FRIEND_TEST(NetlinkManagerTest, MessageHandlerTest);
FRIEND_TEST(NetlinkMessageTest, Parse_NL80211_CMD_TRIGGER_SCAN);
FRIEND_TEST(NetlinkMessageTest, Parse_NL80211_CMD_NEW_SCAN_RESULTS);
FRIEND_TEST(NetlinkMessageTest, Parse_NL80211_CMD_NEW_STATION);
@@ -217,9 +217,9 @@
void OnRawNlMessageReceived(InputData *data);
// This method processes a message from |OnRawNlMessageReceived| by passing
- // the message to either the Config80211 callback that matches the sequence
+ // the message to either the NetlinkManager callback that matches the sequence
// number of the message or, if there isn't one, to all of the default
- // Config80211 callbacks in |broadcast_handlers_|.
+ // NetlinkManager callbacks in |broadcast_handlers_|.
void OnNlMessageReceived(nlmsghdr *msg);
// Called by InputHandler on exceptional events.
@@ -232,7 +232,7 @@
// Handles a CTRL_CMD_NEWFAMILY message from the kernel.
void OnNewFamilyMessage(const NetlinkMessage &message);
- // Config80211 Handlers, OnRawNlMessageReceived invokes each of these
+ // NetlinkManager Handlers, OnRawNlMessageReceived invokes each of these
// User-supplied callback object when _it_ gets called to read libnl data.
std::list<NetlinkMessageHandler> broadcast_handlers_;
@@ -241,7 +241,7 @@
// Hooks needed to be called by shill's EventDispatcher.
EventDispatcher *dispatcher_;
- base::WeakPtrFactory<Config80211> weak_ptr_factory_;
+ base::WeakPtrFactory<NetlinkManager> weak_ptr_factory_;
base::Callback<void(InputData *)> dispatcher_callback_;
scoped_ptr<IOHandler> dispatcher_handler_;
@@ -249,9 +249,9 @@
std::map<const std::string, MessageType> message_types_;
NetlinkMessageFactory message_factory_;
- DISALLOW_COPY_AND_ASSIGN(Config80211);
+ DISALLOW_COPY_AND_ASSIGN(NetlinkManager);
};
} // namespace shill
-#endif // SHILL_CONFIG80211_H_
+#endif // SHILL_NETLINK_MANAGER_H_
diff --git a/config80211_unittest.cc b/netlink_manager_unittest.cc
similarity index 68%
rename from config80211_unittest.cc
rename to netlink_manager_unittest.cc
index d22a735..f4fb78e 100644
--- a/config80211_unittest.cc
+++ b/netlink_manager_unittest.cc
@@ -7,9 +7,9 @@
// tests the various NetlinkMessage types' ability to parse those
// messages.
-// This file tests the public interface to Config80211.
+// This file tests the public interface to NetlinkManager.
-#include "shill/config80211.h"
+#include "shill/netlink_manager.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -28,7 +28,7 @@
namespace {
-// These data blocks have been collected by shill using Config80211 while,
+// These data blocks have been collected by shill using NetlinkManager while,
// simultaneously (and manually) comparing shill output with that of the 'iw'
// code from which it was derived. The test strings represent the raw packet
// data coming from the kernel. The comments above each of these strings is
@@ -58,28 +58,28 @@
return true;
}
-class Config80211Test : public Test {
+class NetlinkManagerTest : public Test {
public:
- Config80211Test() : config80211_(Config80211::GetInstance()) {
- config80211_->message_types_[Nl80211Message::kMessageTypeString].family_id =
- kNl80211FamilyId;
- config80211_->message_factory_.AddFactoryMethod(
+ NetlinkManagerTest() : netlink_manager_(NetlinkManager::GetInstance()) {
+ netlink_manager_->message_types_[Nl80211Message::kMessageTypeString]
+ .family_id = kNl80211FamilyId;
+ netlink_manager_->message_factory_.AddFactoryMethod(
kNl80211FamilyId, Bind(&Nl80211Message::CreateMessage));
Nl80211Message::SetMessageType(
- config80211_->GetMessageType(Nl80211Message::kMessageTypeString));
+ netlink_manager_->GetMessageType(Nl80211Message::kMessageTypeString));
}
- ~Config80211Test() {
- // Config80211 is a singleton, the sock_ field *MUST* be cleared
- // before "Config80211Test::socket_" gets invalidated, otherwise
+ ~NetlinkManagerTest() {
+ // NetlinkManager is a singleton, the sock_ field *MUST* be cleared
+ // before "NetlinkManagerTest::socket_" gets invalidated, otherwise
// later tests will refer to a corrupted memory.
- config80211_->sock_ = NULL;
+ netlink_manager_->sock_ = NULL;
}
- void SetupConfig80211Object() {
- EXPECT_NE(reinterpret_cast<Config80211 *>(NULL), config80211_);
- config80211_->sock_ = &socket_;
- EXPECT_TRUE(config80211_->Init());
+ void SetupNetlinkManagerObject() {
+ EXPECT_NE(reinterpret_cast<NetlinkManager *>(NULL), netlink_manager_);
+ netlink_manager_->sock_ = &socket_;
+ EXPECT_TRUE(netlink_manager_->Init());
}
protected:
@@ -89,15 +89,15 @@
on_netlink_message_(base::Bind(&MockHandler80211::OnNetlinkMessage,
base::Unretained(this))) {}
MOCK_METHOD1(OnNetlinkMessage, void(const NetlinkMessage &msg));
- const Config80211::NetlinkMessageHandler &on_netlink_message() const {
+ const NetlinkManager::NetlinkMessageHandler &on_netlink_message() const {
return on_netlink_message_;
}
private:
- Config80211::NetlinkMessageHandler on_netlink_message_;
+ NetlinkManager::NetlinkMessageHandler on_netlink_message_;
DISALLOW_COPY_AND_ASSIGN(MockHandler80211);
};
- Config80211 *config80211_;
+ NetlinkManager *netlink_manager_;
MockNetlinkSocket socket_;
};
@@ -109,8 +109,8 @@
// appropriately, and that it calls NetlinkSocket::SubscribeToEvents if input
// is good.)
-TEST_F(Config80211Test, BroadcastHandlerTest) {
- SetupConfig80211Object();
+TEST_F(NetlinkManagerTest, BroadcastHandlerTest) {
+ SetupNetlinkManagerObject();
nlmsghdr *message = const_cast<nlmsghdr *>(
reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_DISCONNECT));
@@ -121,50 +121,50 @@
// Simple, 1 handler, case.
EXPECT_CALL(handler1, OnNetlinkMessage(_)).Times(1);
EXPECT_FALSE(
- config80211_->FindBroadcastHandler(handler1.on_netlink_message()));
- config80211_->AddBroadcastHandler(handler1.on_netlink_message());
+ netlink_manager_->FindBroadcastHandler(handler1.on_netlink_message()));
+ netlink_manager_->AddBroadcastHandler(handler1.on_netlink_message());
EXPECT_TRUE(
- config80211_->FindBroadcastHandler(handler1.on_netlink_message()));
- config80211_->OnNlMessageReceived(message);
+ netlink_manager_->FindBroadcastHandler(handler1.on_netlink_message()));
+ netlink_manager_->OnNlMessageReceived(message);
// Add a second handler.
EXPECT_CALL(handler1, OnNetlinkMessage(_)).Times(1);
EXPECT_CALL(handler2, OnNetlinkMessage(_)).Times(1);
- config80211_->AddBroadcastHandler(handler2.on_netlink_message());
- config80211_->OnNlMessageReceived(message);
+ netlink_manager_->AddBroadcastHandler(handler2.on_netlink_message());
+ netlink_manager_->OnNlMessageReceived(message);
// Verify that a handler can't be added twice.
EXPECT_CALL(handler1, OnNetlinkMessage(_)).Times(1);
EXPECT_CALL(handler2, OnNetlinkMessage(_)).Times(1);
- config80211_->AddBroadcastHandler(handler1.on_netlink_message());
- config80211_->OnNlMessageReceived(message);
+ netlink_manager_->AddBroadcastHandler(handler1.on_netlink_message());
+ netlink_manager_->OnNlMessageReceived(message);
// Check that we can remove a handler.
EXPECT_CALL(handler1, OnNetlinkMessage(_)).Times(0);
EXPECT_CALL(handler2, OnNetlinkMessage(_)).Times(1);
- EXPECT_TRUE(config80211_->RemoveBroadcastHandler(
+ EXPECT_TRUE(netlink_manager_->RemoveBroadcastHandler(
handler1.on_netlink_message()));
- config80211_->OnNlMessageReceived(message);
+ netlink_manager_->OnNlMessageReceived(message);
// Check that re-adding the handler goes smoothly.
EXPECT_CALL(handler1, OnNetlinkMessage(_)).Times(1);
EXPECT_CALL(handler2, OnNetlinkMessage(_)).Times(1);
- config80211_->AddBroadcastHandler(handler1.on_netlink_message());
- config80211_->OnNlMessageReceived(message);
+ netlink_manager_->AddBroadcastHandler(handler1.on_netlink_message());
+ netlink_manager_->OnNlMessageReceived(message);
// Check that ClearBroadcastHandlers works.
- config80211_->ClearBroadcastHandlers();
+ netlink_manager_->ClearBroadcastHandlers();
EXPECT_CALL(handler1, OnNetlinkMessage(_)).Times(0);
EXPECT_CALL(handler2, OnNetlinkMessage(_)).Times(0);
- config80211_->OnNlMessageReceived(message);
+ netlink_manager_->OnNlMessageReceived(message);
}
-TEST_F(Config80211Test, MessageHandlerTest) {
+TEST_F(NetlinkManagerTest, MessageHandlerTest) {
// Setup.
- SetupConfig80211Object();
+ SetupNetlinkManagerObject();
MockHandler80211 handler_broadcast;
- EXPECT_TRUE(config80211_->AddBroadcastHandler(
+ EXPECT_TRUE(netlink_manager_->AddBroadcastHandler(
handler_broadcast.on_netlink_message()));
Nl80211Message sent_message_1(CTRL_CMD_GETFAMILY, kGetFamilyCommandString);
@@ -186,42 +186,42 @@
// Verify that generic handler gets called for a message when no
// message-specific handler has been installed.
EXPECT_CALL(handler_broadcast, OnNetlinkMessage(_)).Times(1);
- config80211_->OnNlMessageReceived(received_message);
+ netlink_manager_->OnNlMessageReceived(received_message);
// Send the message and give our handler. Verify that we get called back.
- EXPECT_TRUE(config80211_->SendMessage(&sent_message_1,
+ EXPECT_TRUE(netlink_manager_->SendMessage(&sent_message_1,
handler_sent_1.on_netlink_message()));
// Make it appear that this message is in response to our sent message.
received_message->nlmsg_seq = socket_.GetLastSequenceNumber();
EXPECT_CALL(handler_sent_1, OnNetlinkMessage(_)).Times(1);
- config80211_->OnNlMessageReceived(received_message);
+ netlink_manager_->OnNlMessageReceived(received_message);
// Verify that broadcast handler is called for the message after the
// message-specific handler is called once.
EXPECT_CALL(handler_broadcast, OnNetlinkMessage(_)).Times(1);
- config80211_->OnNlMessageReceived(received_message);
+ netlink_manager_->OnNlMessageReceived(received_message);
// Install and then uninstall message-specific handler; verify broadcast
// handler is called on message receipt.
- EXPECT_TRUE(config80211_->SendMessage(&sent_message_1,
+ EXPECT_TRUE(netlink_manager_->SendMessage(&sent_message_1,
handler_sent_1.on_netlink_message()));
received_message->nlmsg_seq = socket_.GetLastSequenceNumber();
- EXPECT_TRUE(config80211_->RemoveMessageHandler(sent_message_1));
+ EXPECT_TRUE(netlink_manager_->RemoveMessageHandler(sent_message_1));
EXPECT_CALL(handler_broadcast, OnNetlinkMessage(_)).Times(1);
- config80211_->OnNlMessageReceived(received_message);
+ netlink_manager_->OnNlMessageReceived(received_message);
// Install handler for different message; verify that broadcast handler is
// called for _this_ message.
- EXPECT_TRUE(config80211_->SendMessage(&sent_message_2,
+ EXPECT_TRUE(netlink_manager_->SendMessage(&sent_message_2,
handler_sent_2.on_netlink_message()));
EXPECT_CALL(handler_broadcast, OnNetlinkMessage(_)).Times(1);
- config80211_->OnNlMessageReceived(received_message);
+ netlink_manager_->OnNlMessageReceived(received_message);
// Change the ID for the message to that of the second handler; verify that
// the appropriate handler is called for _that_ message.
received_message->nlmsg_seq = socket_.GetLastSequenceNumber();
EXPECT_CALL(handler_sent_2, OnNetlinkMessage(_)).Times(1);
- config80211_->OnNlMessageReceived(received_message);
+ netlink_manager_->OnNlMessageReceived(received_message);
}
} // namespace shill
diff --git a/netlink_message.cc b/netlink_message.cc
index 9da1b16..08ed514 100644
--- a/netlink_message.cc
+++ b/netlink_message.cc
@@ -169,7 +169,7 @@
string ErrorAckMessage::ToString() const {
string output;
if (error()) {
- StringAppendF(&output, "NL80211_ERROR 0x%" PRIx32 ": %s",
+ StringAppendF(&output, "NETLINK_ERROR 0x%" PRIx32 ": %s",
-error_, strerror(-error_));
} else {
StringAppendF(&output, "ACK");
diff --git a/netlink_message.h b/netlink_message.h
index e19e6b0..8eae625 100644
--- a/netlink_message.h
+++ b/netlink_message.h
@@ -54,9 +54,9 @@
//
// Other message types ("nl80211", for example), are assigned by the kernel
// dynamically. To get the message type, pass a closure to assign the
-// message_type along with the sting to Config80211::GetFamily:
+// message_type along with the sting to NetlinkManager::GetFamily:
//
-// nl80211_type = config80211_->GetFamily(Nl80211Message::kMessageType);
+// nl80211_type = netlink_manager->GetFamily(Nl80211Message::kMessageType);
//
// Do all of this before you start to create NetlinkMessages so that
// NetlinkMessage can be instantiated with a valid |message_type_|.
@@ -91,8 +91,8 @@
size_t num_bytes);
protected:
- friend class Config80211Test;
- FRIEND_TEST(Config80211Test, NL80211_CMD_NOTIFY_CQM);
+ friend class NetlinkManagerTest;
+ FRIEND_TEST(NetlinkManagerTest, NL80211_CMD_NOTIFY_CQM);
// Returns a string of bytes representing an |nlmsghdr|, filled-in, and its
// padding.
diff --git a/netlink_message_unittest.cc b/netlink_message_unittest.cc
index 5eebade..9782b81 100644
--- a/netlink_message_unittest.cc
+++ b/netlink_message_unittest.cc
@@ -34,7 +34,7 @@
namespace {
-// These data blocks have been collected by shill using Config80211 while,
+// These data blocks have been collected by shill using NetlinkManager while,
// simultaneously (and manually) comparing shill output with that of the 'iw'
// code from which it was derived. The test strings represent the raw packet
// data coming from the kernel. The comments above each of these strings is
diff --git a/netlink_socket_unittest.cc b/netlink_socket_unittest.cc
index 0bad453..049313f 100644
--- a/netlink_socket_unittest.cc
+++ b/netlink_socket_unittest.cc
@@ -4,6 +4,8 @@
#include "shill/netlink_socket.h"
+#include <linux/netlink.h>
+
#include <algorithm>
#include <string>
@@ -12,7 +14,7 @@
#include "shill/byte_string.h"
#include "shill/mock_sockets.h"
-#include "shill/nl80211_message.h"
+#include "shill/netlink_message.h"
using std::min;
using std::string;
@@ -54,7 +56,7 @@
class FakeSocketRead {
public:
- FakeSocketRead(const ByteString &next_read_string) {
+ explicit FakeSocketRead(const ByteString &next_read_string) {
next_read_string_ = next_read_string;
}
// Copies |len| bytes of |next_read_string_| into |buf| and clears
diff --git a/nl80211_attribute.h b/nl80211_attribute.h
index 92864a7..8952ae7 100644
--- a/nl80211_attribute.h
+++ b/nl80211_attribute.h
@@ -289,4 +289,4 @@
} // namespace shill
-#endif // SHILL_NLATTRIBUTE_H_
+#endif // SHILL_NL80211_ATTRIBUTE_H_
diff --git a/shill_daemon.cc b/shill_daemon.cc
index 55de12f..9f7e4ae 100644
--- a/shill_daemon.cc
+++ b/shill_daemon.cc
@@ -13,11 +13,11 @@
#include <base/file_path.h>
#include "shill/callback80211_metrics.h"
-#include "shill/config80211.h"
#include "shill/dhcp_provider.h"
#include "shill/diagnostics_reporter.h"
#include "shill/error.h"
#include "shill/logging.h"
+#include "shill/netlink_manager.h"
#include "shill/nl80211_message.h"
#include "shill/nss.h"
#include "shill/proxy_factory.h"
@@ -41,7 +41,7 @@
rtnl_handler_(RTNLHandler::GetInstance()),
routing_table_(RoutingTable::GetInstance()),
dhcp_provider_(DHCPProvider::GetInstance()),
- config80211_(Config80211::GetInstance()),
+ netlink_manager_(NetlinkManager::GetInstance()),
manager_(new Manager(control_,
&dispatcher_,
metrics_.get(),
@@ -49,7 +49,7 @@
config->GetRunDirectory(),
config->GetStorageDirectory(),
config->GetUserStorageDirectoryFormat())),
- callback80211_metrics_(*config80211_, metrics_.get()) {
+ callback80211_metrics_(*netlink_manager_, metrics_.get()) {
}
Daemon::~Daemon() { }
@@ -102,22 +102,22 @@
routing_table_->Start();
dhcp_provider_->Init(control_, &dispatcher_, &glib_);
- if (config80211_) {
- config80211_->Init();
- uint16_t nl80211_family_id = config80211_->GetFamily(
+ if (netlink_manager_) {
+ netlink_manager_->Init();
+ uint16_t nl80211_family_id = netlink_manager_->GetFamily(
Nl80211Message::kMessageTypeString,
Bind(&Nl80211Message::CreateMessage));
if (nl80211_family_id == NetlinkMessage::kIllegalMessageType) {
LOG(FATAL) << "Didn't get a legal message type for 'nl80211' messages.";
}
Nl80211Message::SetMessageType(nl80211_family_id);
- config80211_->Start(&dispatcher_);
+ netlink_manager_->Start(&dispatcher_);
- callback80211_metrics_.InitNl80211FamilyId(*config80211_);
+ callback80211_metrics_.InitNl80211FamilyId(*netlink_manager_);
// Install handlers for NetlinkMessages that don't have specific handlers
// (which are registered by message sequence number).
- config80211_->AddBroadcastHandler(Bind(
+ netlink_manager_->AddBroadcastHandler(Bind(
&Callback80211Metrics::CollectDisconnectStatistics,
callback80211_metrics_.AsWeakPtr()));
}
diff --git a/shill_daemon.h b/shill_daemon.h
index 38ae278..0aef498 100644
--- a/shill_daemon.h
+++ b/shill_daemon.h
@@ -18,12 +18,12 @@
namespace shill {
class Config;
-class Config80211;
class ControlInterface;
class DHCPProvider;
class Error;
class GLib;
class Metrics;
+class NetlinkManager;
class NSS;
class ProxyFactory;
class RoutingTable;
@@ -61,7 +61,7 @@
RTNLHandler *rtnl_handler_;
RoutingTable *routing_table_;
DHCPProvider *dhcp_provider_;
- Config80211 *config80211_;
+ NetlinkManager *netlink_manager_;
scoped_ptr<Manager> manager_;
Callback80211Metrics callback80211_metrics_;
EventDispatcher dispatcher_;
diff --git a/shill_unittest.cc b/shill_unittest.cc
index 0aeff95..8c78409 100644
--- a/shill_unittest.cc
+++ b/shill_unittest.cc
@@ -212,8 +212,8 @@
daemon_.Stop();
}
- void ResetConfig80211() {
- daemon_.config80211_->Reset(true);
+ void ResetNetlinkManager() {
+ daemon_.netlink_manager_->Reset(true);
}
MOCK_METHOD0(TerminationAction, void());
@@ -316,9 +316,9 @@
dispatcher_->PostTask(Bind(&Daemon::Quit, Unretained(&daemon_)));
// TODO(wdg): crbug.com/224712 - Need fix for "GLib-WARNING **: Invalid file
- // descriptor". This requires support for config80211 interface tests.
+ // descriptor". This requires support for netlink_manager interface tests.
daemon_.Run();
- ResetConfig80211();
+ ResetNetlinkManager();
}
} // namespace shill
diff --git a/wifi.cc b/wifi.cc
index 1179d54..1e8b831 100644
--- a/wifi.cc
+++ b/wifi.cc
@@ -20,7 +20,6 @@
#include <chromeos/dbus/service_constants.h>
#include <glib.h>
-#include "shill/config80211.h"
#include "shill/control_interface.h"
#include "shill/dbus_adaptor.h"
#include "shill/device.h"
@@ -31,6 +30,7 @@
#include "shill/logging.h"
#include "shill/manager.h"
#include "shill/metrics.h"
+#include "shill/netlink_manager.h"
#include "shill/nl80211_message.h"
#include "shill/property_accessor.h"
#include "shill/proxy_factory.h"
@@ -96,7 +96,7 @@
supplicant_state_(kInterfaceStateUnknown),
supplicant_bss_("(unknown)"),
need_bss_flush_(false),
- resumed_at_((struct timeval){0}),
+ resumed_at_((struct timeval) {0}),
fast_scans_remaining_(kNumFastScanAttempts),
has_already_completed_(false),
is_debugging_connection_(false),
@@ -105,7 +105,7 @@
bgscan_signal_threshold_dbm_(kDefaultBgscanSignalThresholdDbm),
scan_pending_(false),
scan_interval_seconds_(kDefaultScanIntervalSeconds),
- config80211_(Config80211::GetInstance()) {
+ netlink_manager_(NetlinkManager::GetInstance()) {
PropertyStore *store = this->mutable_store();
store->RegisterDerivedString(
flimflam::kBgscanMethodProperty,
@@ -140,7 +140,7 @@
ScopeLogger::GetInstance()->RegisterScopeEnableChangedCallback(
ScopeLogger::kWiFi,
Bind(&WiFi::OnWiFiDebugScopeChanged, weak_ptr_factory_.GetWeakPtr()));
- CHECK(config80211_);
+ CHECK(netlink_manager_);
SLOG(WiFi, 2) << "WiFi device " << link_name() << " initialized.";
}
@@ -170,14 +170,14 @@
// it when it appears.
ConnectToSupplicant();
// Subscribe to multicast events.
- config80211_->SubscribeToEvents(Nl80211Message::kMessageTypeString,
- Config80211::kEventTypeConfig);
- config80211_->SubscribeToEvents(Nl80211Message::kMessageTypeString,
- Config80211::kEventTypeScan);
- config80211_->SubscribeToEvents(Nl80211Message::kMessageTypeString,
- Config80211::kEventTypeRegulatory);
- config80211_->SubscribeToEvents(Nl80211Message::kMessageTypeString,
- Config80211::kEventTypeMlme);
+ netlink_manager_->SubscribeToEvents(Nl80211Message::kMessageTypeString,
+ NetlinkManager::kEventTypeConfig);
+ netlink_manager_->SubscribeToEvents(Nl80211Message::kMessageTypeString,
+ NetlinkManager::kEventTypeScan);
+ netlink_manager_->SubscribeToEvents(Nl80211Message::kMessageTypeString,
+ NetlinkManager::kEventTypeRegulatory);
+ netlink_manager_->SubscribeToEvents(Nl80211Message::kMessageTypeString,
+ NetlinkManager::kEventTypeMlme);
}
void WiFi::Stop(Error *error, const EnabledStateChangedCallback &callback) {
diff --git a/wifi.h b/wifi.h
index b72ec4a..62c137a 100644
--- a/wifi.h
+++ b/wifi.h
@@ -96,10 +96,10 @@
namespace shill {
-class Config80211;
class Error;
class GeolocationInfo;
class KeyValueStore;
+class NetlinkManager;
class ProxyFactory;
class SupplicantEAPStateHandler;
class SupplicantInterfaceProxyInterface;
@@ -401,7 +401,7 @@
bool scan_pending_;
uint16 scan_interval_seconds_;
- Config80211 *config80211_;
+ NetlinkManager *netlink_manager_;
DISALLOW_COPY_AND_ASSIGN(WiFi);
};
diff --git a/wifi_unittest.cc b/wifi_unittest.cc
index 3b0392d..b718d01 100644
--- a/wifi_unittest.cc
+++ b/wifi_unittest.cc
@@ -32,7 +32,6 @@
#include "shill/key_value_store.h"
#include "shill/logging.h"
#include "shill/manager.h"
-#include "shill/mock_config80211.h"
#include "shill/mock_dbus_manager.h"
#include "shill/mock_device.h"
#include "shill/mock_device_info.h"
@@ -43,6 +42,7 @@
#include "shill/mock_log.h"
#include "shill/mock_manager.h"
#include "shill/mock_metrics.h"
+#include "shill/mock_netlink_manager.h"
#include "shill/mock_profile.h"
#include "shill/mock_rtnl_handler.h"
#include "shill/mock_store.h"
@@ -195,7 +195,7 @@
class WiFiObjectTest : public ::testing::TestWithParam<string> {
public:
- WiFiObjectTest(EventDispatcher *dispatcher)
+ explicit WiFiObjectTest(EventDispatcher *dispatcher)
: event_dispatcher_(dispatcher),
metrics_(NULL),
manager_(&control_interface_, NULL, &metrics_, &glib_),
@@ -234,8 +234,8 @@
wifi_->provider_ = &wifi_provider_;
wifi_->time_ = &time_;
- // TODO(wdg): Flesh out the wifi tests to include config80211.
- wifi_->config80211_ = &config80211_;
+ // TODO(wdg): Flesh out the wifi tests to include netlink_manager.
+ wifi_->netlink_manager_ = &netlink_manager_;
}
virtual void SetUp() {
@@ -325,16 +325,16 @@
// Simulate the course of events when the last enpoint of a service is
// removed.
class EndpointRemovalHandler {
- public:
- EndpointRemovalHandler(WiFiRefPtr wifi, const WiFiServiceRefPtr &service)
- : wifi_(wifi), service_(service) {}
- virtual ~EndpointRemovalHandler() {}
+ public:
+ EndpointRemovalHandler(WiFiRefPtr wifi, const WiFiServiceRefPtr &service)
+ : wifi_(wifi), service_(service) {}
+ virtual ~EndpointRemovalHandler() {}
- WiFiServiceRefPtr OnEndpointRemoved(
- const WiFiEndpointConstRefPtr &endpoint) {
- wifi_->DisassociateFromService(service_);
- return service_;
- }
+ WiFiServiceRefPtr OnEndpointRemoved(
+ const WiFiEndpointConstRefPtr &endpoint) {
+ wifi_->DisassociateFromService(service_);
+ return service_;
+ }
private:
WiFiRefPtr wifi_;
@@ -342,7 +342,7 @@
};
EndpointRemovalHandler *MakeEndpointRemovalHandler(
- WiFiServiceRefPtr &service) {
+ const WiFiServiceRefPtr &service) {
return new EndpointRemovalHandler(wifi_, service);
}
void CancelScanTimer() {
@@ -730,7 +730,7 @@
// and manager so we can perform expectations against them.
MockDBusManager *dbus_manager_;
MockSupplicantEAPStateHandler *eap_state_handler_;
- MockConfig80211 config80211_;
+ MockNetlinkManager netlink_manager_;
private:
scoped_ptr<MockSupplicantInterfaceProxy> supplicant_interface_proxy_;