*/
#include <unistd.h>
+#include <sys/capability.h>
#include <csignal>
#include <memory>
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>
#include <cutils/properties.h>
+#include <libminijail.h>
#include <utils/String16.h>
-#include <wifi_hal/driver_tool.h>
-#include <wifi_system/hal_tool.h>
#include <wifi_system/interface_tool.h>
#include "wificond/ipc_constants.h"
#include "wificond/looper_backed_event_loop.h"
#include "wificond/net/netlink_manager.h"
+#include "wificond/net/netlink_utils.h"
+#include "wificond/scanning/scan_utils.h"
#include "wificond/server.h"
using android::net::wifi::IWificond;
-using android::wifi_hal::DriverTool;
-using android::wifi_system::HalTool;
+using android::wifi_system::HostapdManager;
using android::wifi_system::InterfaceTool;
-using android::wificond::ipc_constants::kDevModePropertyKey;
-using android::wificond::ipc_constants::kDevModeServiceName;
+using android::wifi_system::SupplicantManager;
using android::wificond::ipc_constants::kServiceName;
using std::unique_ptr;
android::sp<android::IServiceManager> sm = android::defaultServiceManager();
CHECK_EQ(sm != NULL, true) << "Could not obtain IServiceManager";
- const int8_t dev_mode_on = property_get_bool(kDevModePropertyKey, 0);
- const char* service_name = (dev_mode_on) ? kDevModeServiceName : kServiceName;
- CHECK_EQ(sm->addService(android::String16(service_name), service),
+ CHECK_EQ(sm->addService(android::String16(kServiceName), service),
android::NO_ERROR);
}
+void DropPrivilegesOrCrash() {
+ minijail* j = minijail_new();
+ CHECK(minijail_change_user(j, "wifi") == 0);
+ CHECK(minijail_change_group(j, "wifi") == 0);
+ minijail_use_caps(j,
+ CAP_TO_MASK(CAP_NET_ADMIN) |
+ CAP_TO_MASK(CAP_NET_RAW));
+ minijail_enter(j);
+ minijail_destroy(j);
+}
+
} // namespace
void OnBinderReadReady(int fd) {
android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM));
LOG(INFO) << "wificond is starting up...";
+ DropPrivilegesOrCrash();
+
unique_ptr<android::wificond::LooperBackedEventLoop> event_dispatcher(
new android::wificond::LooperBackedEventLoop());
ScopedSignalHandler scoped_signal_handler(event_dispatcher.get());
android::wificond::EventLoop::kModeInput,
&OnBinderReadReady)) << "Failed to watch binder FD";
+ android::wificond::NetlinkManager netlink_manager(event_dispatcher.get());
+ CHECK(netlink_manager.Start()) << "Failed to start netlink manager";
+ android::wificond::NetlinkUtils netlink_utils(&netlink_manager);
+ android::wificond::ScanUtils scan_utils(&netlink_manager);
- android::sp<android::IBinder> server = new android::wificond::Server(
- unique_ptr<HalTool>(new HalTool),
+ unique_ptr<android::wificond::Server> server(new android::wificond::Server(
unique_ptr<InterfaceTool>(new InterfaceTool),
- unique_ptr<DriverTool>(new DriverTool));
- RegisterServiceOrCrash(server);
- android::wificond::NetlinkManager netlink_manager(event_dispatcher.get());
- netlink_manager.Start();
+ unique_ptr<SupplicantManager>(new SupplicantManager()),
+ unique_ptr<HostapdManager>(new HostapdManager()),
+ &netlink_utils,
+ &scan_utils));
+ server->CleanUpSystemState();
+ RegisterServiceOrCrash(server.get());
event_dispatcher->Poll();
LOG(INFO) << "wificond is about to exit";