Split wifi_relay into host and guest versions
BUG: 78296257
Test: Local build after the wifi_relay split
Change-Id: I71b232555201199973055e5d5b121a35dcbad47d
diff --git a/common/commands/Android.bp b/common/commands/Android.bp
index 4392d9d..8264fcc 100644
--- a/common/commands/Android.bp
+++ b/common/commands/Android.bp
@@ -14,5 +14,4 @@
// limitations under the License.
subdirs = [
- "wifi_relay",
]
diff --git a/guest/commands/Android.bp b/guest/commands/Android.bp
index 2f0e565..11624ca 100644
--- a/guest/commands/Android.bp
+++ b/guest/commands/Android.bp
@@ -13,3 +13,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+subdirs = [
+ "wifi_setup",
+]
diff --git a/common/commands/wifi_relay/Android.bp b/guest/commands/wifi_setup/Android.bp
similarity index 81%
copy from common/commands/wifi_relay/Android.bp
copy to guest/commands/wifi_setup/Android.bp
index c496ef0..9df9660 100644
--- a/common/commands/wifi_relay/Android.bp
+++ b/guest/commands/wifi_setup/Android.bp
@@ -14,7 +14,7 @@
// limitations under the License.
//
cc_binary {
- name: "wifi_relay",
+ name: "wifi_setup",
srcs: [
"cmd.cpp",
"mac80211_hwsim.cpp",
@@ -35,13 +35,6 @@
header_libs: [
"cuttlefish_glog",
],
- target: {
- host: {
- static_libs: [
- "libcuttlefish_host_config",
- ],
- },
- },
- defaults: ["cuttlefish_host_and_guest", "cuttlefish_native_isa"]
+ defaults: ["cuttlefish_guest_only", "cuttlefish_native_isa"]
}
diff --git a/common/commands/wifi_relay/cmd.cpp b/guest/commands/wifi_setup/cmd.cpp
similarity index 97%
copy from common/commands/wifi_relay/cmd.cpp
copy to guest/commands/wifi_setup/cmd.cpp
index 7e5a88d..f847640 100644
--- a/common/commands/wifi_relay/cmd.cpp
+++ b/guest/commands/wifi_setup/cmd.cpp
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "common/commands/wifi_relay/cmd.h"
+#include "guest/commands/wifi_setup/cmd.h"
namespace cvd {
diff --git a/common/commands/wifi_relay/cmd.h b/guest/commands/wifi_setup/cmd.h
similarity index 100%
copy from common/commands/wifi_relay/cmd.h
copy to guest/commands/wifi_setup/cmd.h
diff --git a/common/commands/wifi_relay/mac80211_hwsim.cpp b/guest/commands/wifi_setup/mac80211_hwsim.cpp
similarity index 94%
rename from common/commands/wifi_relay/mac80211_hwsim.cpp
rename to guest/commands/wifi_setup/mac80211_hwsim.cpp
index ab52a15..b2e3c8c 100644
--- a/common/commands/wifi_relay/mac80211_hwsim.cpp
+++ b/guest/commands/wifi_setup/mac80211_hwsim.cpp
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-#include "common/commands/wifi_relay/mac80211_hwsim.h"
+#include "guest/commands/wifi_setup/mac80211_hwsim.h"
-#include "common/commands/wifi_relay/mac80211_hwsim_driver.h"
+#include "guest/commands/wifi_setup/mac80211_hwsim_driver.h"
#include <glog/logging.h>
#include <netlink/genl/ctrl.h>
@@ -181,14 +181,12 @@
goto bail;
}
-#if !defined(CUTTLEFISH_HOST)
res = registerOrSubscribe(mMAC);
if (res < 0) {
mInitCheck = res;
goto bail;
}
-#endif
mInitCheck = 0;
return;
@@ -323,11 +321,7 @@
return;
}
-#ifdef CUTTLEFISH_HOST
- LOG(VERBOSE) << "------------------- Host -> Guest -----------------------";
-#else
LOG(VERBOSE) << "------------------- Guest -> Host -----------------------";
-#endif
genlmsghdr *hdr = genlmsg_hdr(msg.get());
if (hdr->cmd != HWSIM_CMD_FRAME) {
@@ -360,9 +354,7 @@
remoteEntry.second->send(nla_data(attr), nla_len(attr));
}
-#if !defined(CUTTLEFISH_HOST)
ackFrame(msg.get());
-#endif
}
@@ -378,19 +370,11 @@
mMac80211Family,
0,
NLM_F_REQUEST,
-#ifdef CUTTLEFISH_HOST
- HWSIM_CMD_SUBSCRIBE,
-#else
HWSIM_CMD_REGISTER,
-#endif
0);
-#ifdef CUTTLEFISH_HOST
- nla_put(msg.get(), HWSIM_ATTR_ADDR_RECEIVER, ETH_ALEN, &mac[0]);
-#else
// HWSIM_CMD_REGISTER is a global command not specific to a MAC.
(void)mac;
-#endif
int res = nl_send_auto_complete(mSock.get(), msg.get());
@@ -407,13 +391,6 @@
int Mac80211HwSim::addRemote(
const MacAddress &mac,
vsoc::wifi::WifiExchangeView *wifiExchange) {
-#ifdef CUTTLEFISH_HOST
- int res = registerOrSubscribe(mac);
-
- if (res < 0) {
- return res;
- }
-#endif
std::lock_guard<std::mutex> autoLock(mRemotesLock);
diff --git a/common/commands/wifi_relay/mac80211_hwsim.h b/guest/commands/wifi_setup/mac80211_hwsim.h
similarity index 100%
copy from common/commands/wifi_relay/mac80211_hwsim.h
copy to guest/commands/wifi_setup/mac80211_hwsim.h
diff --git a/common/commands/wifi_relay/mac80211_hwsim_driver.h b/guest/commands/wifi_setup/mac80211_hwsim_driver.h
similarity index 100%
copy from common/commands/wifi_relay/mac80211_hwsim_driver.h
copy to guest/commands/wifi_setup/mac80211_hwsim_driver.h
diff --git a/common/commands/wifi_relay/netlink.h b/guest/commands/wifi_setup/netlink.h
similarity index 100%
copy from common/commands/wifi_relay/netlink.h
copy to guest/commands/wifi_setup/netlink.h
diff --git a/common/commands/wifi_relay/nl_client.cpp b/guest/commands/wifi_setup/nl_client.cpp
similarity index 97%
copy from common/commands/wifi_relay/nl_client.cpp
copy to guest/commands/wifi_setup/nl_client.cpp
index a00fab1..8064987 100644
--- a/common/commands/wifi_relay/nl_client.cpp
+++ b/guest/commands/wifi_setup/nl_client.cpp
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "common/commands/wifi_relay/nl_client.h"
+#include "guest/commands/wifi_setup/nl_client.h"
#include <glog/logging.h>
diff --git a/common/commands/wifi_relay/nl_client.h b/guest/commands/wifi_setup/nl_client.h
similarity index 97%
rename from common/commands/wifi_relay/nl_client.h
rename to guest/commands/wifi_setup/nl_client.h
index 74bc122..43581bd 100644
--- a/common/commands/wifi_relay/nl_client.h
+++ b/guest/commands/wifi_setup/nl_client.h
@@ -22,7 +22,7 @@
#include <netlink/genl/genl.h>
-#include "common/commands/wifi_relay/cmd.h"
+#include "guest/commands/wifi_setup/cmd.h"
namespace cvd {
diff --git a/common/commands/wifi_relay/wifi_relay.cpp b/guest/commands/wifi_setup/wifi_relay.cpp
similarity index 92%
rename from common/commands/wifi_relay/wifi_relay.cpp
rename to guest/commands/wifi_setup/wifi_relay.cpp
index 2b21765..99d1e8d 100644
--- a/common/commands/wifi_relay/wifi_relay.cpp
+++ b/guest/commands/wifi_setup/wifi_relay.cpp
@@ -16,12 +16,8 @@
#include "wifi_relay.h"
-#include "common/commands/wifi_relay/mac80211_hwsim_driver.h"
-#include "common/commands/wifi_relay/nl_client.h"
-
-#if defined(CUTTLEFISH_HOST)
-#include "host/libs/config/host_config.h"
-#endif
+#include "guest/commands/wifi_setup/mac80211_hwsim_driver.h"
+#include "guest/commands/wifi_setup/nl_client.h"
#include <linux/netdevice.h>
#include <linux/nl80211.h>
@@ -33,10 +29,8 @@
#include <fstream>
-#if !defined(CUTTLEFISH_HOST)
DEFINE_string(
iface_name, "wlan0", "Name of the wifi interface to be created.");
-#endif
WifiRelay::WifiRelay(
const Mac80211HwSim::MacAddress &localMAC,
@@ -50,11 +44,7 @@
init_check_ = mMac80211HwSim->addRemote(
remoteMAC,
-#if defined(CUTTLEFISH_HOST)
- vsoc::wifi::WifiExchangeView::GetInstance(vsoc::GetDomain().c_str())
-#else
vsoc::wifi::WifiExchangeView::GetInstance()
-#endif
);
}
@@ -232,20 +222,12 @@
::android::base::InitLogging(argv, android::base::StderrLogger);
gflags::ParseCommandLineFlags(&argc, &argv, true);
- auto wifi_view = vsoc::wifi::WifiExchangeView::GetInstance(
-#if defined(CUTTLEFISH_HOST)
- vsoc::GetDomain().c_str()
-#endif
- );
+ auto wifi_view = vsoc::wifi::WifiExchangeView::GetInstance();
Mac80211HwSim::MacAddress guestMAC = wifi_view->GetGuestMACAddress();
Mac80211HwSim::MacAddress hostMAC = wifi_view->GetHostMACAddress();
-#ifdef CUTTLEFISH_HOST
- WifiRelay relay(hostMAC, guestMAC);
-#else
WifiRelay relay(guestMAC, hostMAC);
-#endif
int res = relay.initCheck();
if (res < 0) {
@@ -259,7 +241,6 @@
exit(1);
}
-#if !defined(CUTTLEFISH_HOST)
cvd::NlClient client(NETLINK_GENERIC);
if (!client.Init()) {
LOG(ERROR) << "Could not open Netlink Generic.";
@@ -324,7 +305,6 @@
LOG(ERROR) << "Failed to update interface.";
exit(1);
}
-#endif // !defined(CUTTLEFISH_HOST)
relay.run();
diff --git a/common/commands/wifi_relay/wifi_relay.h b/guest/commands/wifi_setup/wifi_relay.h
similarity index 94%
copy from common/commands/wifi_relay/wifi_relay.h
copy to guest/commands/wifi_setup/wifi_relay.h
index 2edc6db..8ca57aa 100644
--- a/common/commands/wifi_relay/wifi_relay.h
+++ b/guest/commands/wifi_setup/wifi_relay.h
@@ -16,7 +16,7 @@
#pragma once
-#include "common/commands/wifi_relay/mac80211_hwsim.h"
+#include "guest/commands/wifi_setup/mac80211_hwsim.h"
#include <errno.h>
#include <memory>
diff --git a/host/commands/Android.bp b/host/commands/Android.bp
index 1680f9b..58aa3c3 100644
--- a/host/commands/Android.bp
+++ b/host/commands/Android.bp
@@ -17,4 +17,5 @@
"launch",
"stop_cvd",
"record_audio",
+ "wifi_relay",
]
diff --git a/common/commands/wifi_relay/Android.bp b/host/commands/wifi_relay/Android.bp
similarity index 82%
rename from common/commands/wifi_relay/Android.bp
rename to host/commands/wifi_relay/Android.bp
index c496ef0..7d88220 100644
--- a/common/commands/wifi_relay/Android.bp
+++ b/host/commands/wifi_relay/Android.bp
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-cc_binary {
+cc_binary_host {
name: "wifi_relay",
srcs: [
"cmd.cpp",
@@ -31,17 +31,10 @@
],
static_libs: [
"libgflags",
+ "libcuttlefish_host_config",
],
header_libs: [
"cuttlefish_glog",
],
- target: {
- host: {
- static_libs: [
- "libcuttlefish_host_config",
- ],
- },
- },
- defaults: ["cuttlefish_host_and_guest", "cuttlefish_native_isa"]
+ defaults: ["cuttlefish_host_only"]
}
-
diff --git a/common/commands/wifi_relay/cmd.cpp b/host/commands/wifi_relay/cmd.cpp
similarity index 97%
rename from common/commands/wifi_relay/cmd.cpp
rename to host/commands/wifi_relay/cmd.cpp
index 7e5a88d..a1ed6ca 100644
--- a/common/commands/wifi_relay/cmd.cpp
+++ b/host/commands/wifi_relay/cmd.cpp
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "common/commands/wifi_relay/cmd.h"
+#include "host/commands/wifi_relay/cmd.h"
namespace cvd {
diff --git a/common/commands/wifi_relay/cmd.h b/host/commands/wifi_relay/cmd.h
similarity index 100%
rename from common/commands/wifi_relay/cmd.h
rename to host/commands/wifi_relay/cmd.h
diff --git a/common/commands/wifi_relay/mac80211_hwsim.cpp b/host/commands/wifi_relay/mac80211_hwsim.cpp
similarity index 93%
copy from common/commands/wifi_relay/mac80211_hwsim.cpp
copy to host/commands/wifi_relay/mac80211_hwsim.cpp
index ab52a15..099e4aa 100644
--- a/common/commands/wifi_relay/mac80211_hwsim.cpp
+++ b/host/commands/wifi_relay/mac80211_hwsim.cpp
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-#include "common/commands/wifi_relay/mac80211_hwsim.h"
+#include "host/commands/wifi_relay/mac80211_hwsim.h"
-#include "common/commands/wifi_relay/mac80211_hwsim_driver.h"
+#include "host/commands/wifi_relay/mac80211_hwsim_driver.h"
#include <glog/logging.h>
#include <netlink/genl/ctrl.h>
@@ -180,16 +180,6 @@
mInitCheck = -ENODEV;
goto bail;
}
-
-#if !defined(CUTTLEFISH_HOST)
- res = registerOrSubscribe(mMAC);
-
- if (res < 0) {
- mInitCheck = res;
- goto bail;
- }
-#endif
-
mInitCheck = 0;
return;
@@ -323,11 +313,7 @@
return;
}
-#ifdef CUTTLEFISH_HOST
LOG(VERBOSE) << "------------------- Host -> Guest -----------------------";
-#else
- LOG(VERBOSE) << "------------------- Guest -> Host -----------------------";
-#endif
genlmsghdr *hdr = genlmsg_hdr(msg.get());
if (hdr->cmd != HWSIM_CMD_FRAME) {
@@ -359,11 +345,6 @@
// on the destination address.
remoteEntry.second->send(nla_data(attr), nla_len(attr));
}
-
-#if !defined(CUTTLEFISH_HOST)
- ackFrame(msg.get());
-#endif
-
}
int Mac80211HwSim::registerOrSubscribe(const MacAddress &mac) {
@@ -378,19 +359,10 @@
mMac80211Family,
0,
NLM_F_REQUEST,
-#ifdef CUTTLEFISH_HOST
HWSIM_CMD_SUBSCRIBE,
-#else
- HWSIM_CMD_REGISTER,
-#endif
0);
-#ifdef CUTTLEFISH_HOST
nla_put(msg.get(), HWSIM_ATTR_ADDR_RECEIVER, ETH_ALEN, &mac[0]);
-#else
- // HWSIM_CMD_REGISTER is a global command not specific to a MAC.
- (void)mac;
-#endif
int res = nl_send_auto_complete(mSock.get(), msg.get());
@@ -407,13 +379,11 @@
int Mac80211HwSim::addRemote(
const MacAddress &mac,
vsoc::wifi::WifiExchangeView *wifiExchange) {
-#ifdef CUTTLEFISH_HOST
int res = registerOrSubscribe(mac);
if (res < 0) {
return res;
}
-#endif
std::lock_guard<std::mutex> autoLock(mRemotesLock);
diff --git a/common/commands/wifi_relay/mac80211_hwsim.h b/host/commands/wifi_relay/mac80211_hwsim.h
similarity index 100%
rename from common/commands/wifi_relay/mac80211_hwsim.h
rename to host/commands/wifi_relay/mac80211_hwsim.h
diff --git a/common/commands/wifi_relay/mac80211_hwsim_driver.h b/host/commands/wifi_relay/mac80211_hwsim_driver.h
similarity index 100%
rename from common/commands/wifi_relay/mac80211_hwsim_driver.h
rename to host/commands/wifi_relay/mac80211_hwsim_driver.h
diff --git a/common/commands/wifi_relay/netlink.h b/host/commands/wifi_relay/netlink.h
similarity index 100%
rename from common/commands/wifi_relay/netlink.h
rename to host/commands/wifi_relay/netlink.h
diff --git a/common/commands/wifi_relay/nl_client.cpp b/host/commands/wifi_relay/nl_client.cpp
similarity index 97%
rename from common/commands/wifi_relay/nl_client.cpp
rename to host/commands/wifi_relay/nl_client.cpp
index a00fab1..d03226d 100644
--- a/common/commands/wifi_relay/nl_client.cpp
+++ b/host/commands/wifi_relay/nl_client.cpp
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "common/commands/wifi_relay/nl_client.h"
+#include "host/commands/wifi_relay/nl_client.h"
#include <glog/logging.h>
diff --git a/common/commands/wifi_relay/nl_client.h b/host/commands/wifi_relay/nl_client.h
similarity index 97%
copy from common/commands/wifi_relay/nl_client.h
copy to host/commands/wifi_relay/nl_client.h
index 74bc122..596b312 100644
--- a/common/commands/wifi_relay/nl_client.h
+++ b/host/commands/wifi_relay/nl_client.h
@@ -22,7 +22,7 @@
#include <netlink/genl/genl.h>
-#include "common/commands/wifi_relay/cmd.h"
+#include "host/commands/wifi_relay/cmd.h"
namespace cvd {
diff --git a/common/commands/wifi_relay/wifi_relay.cpp b/host/commands/wifi_relay/wifi_relay.cpp
similarity index 72%
copy from common/commands/wifi_relay/wifi_relay.cpp
copy to host/commands/wifi_relay/wifi_relay.cpp
index 2b21765..00f8d42 100644
--- a/common/commands/wifi_relay/wifi_relay.cpp
+++ b/host/commands/wifi_relay/wifi_relay.cpp
@@ -16,12 +16,10 @@
#include "wifi_relay.h"
-#include "common/commands/wifi_relay/mac80211_hwsim_driver.h"
-#include "common/commands/wifi_relay/nl_client.h"
+#include "host/commands/wifi_relay/mac80211_hwsim_driver.h"
+#include "host/commands/wifi_relay/nl_client.h"
-#if defined(CUTTLEFISH_HOST)
#include "host/libs/config/host_config.h"
-#endif
#include <linux/netdevice.h>
#include <linux/nl80211.h>
@@ -33,10 +31,7 @@
#include <fstream>
-#if !defined(CUTTLEFISH_HOST)
-DEFINE_string(
- iface_name, "wlan0", "Name of the wifi interface to be created.");
-#endif
+using vsoc::wifi::WifiExchangeView;
WifiRelay::WifiRelay(
const Mac80211HwSim::MacAddress &localMAC,
@@ -50,12 +45,7 @@
init_check_ = mMac80211HwSim->addRemote(
remoteMAC,
-#if defined(CUTTLEFISH_HOST)
- vsoc::wifi::WifiExchangeView::GetInstance(vsoc::GetDomain().c_str())
-#else
- vsoc::wifi::WifiExchangeView::GetInstance()
-#endif
- );
+ WifiExchangeView::GetInstance(vsoc::GetDomain().c_str()));
}
int WifiRelay::initCheck() const {
@@ -232,20 +222,12 @@
::android::base::InitLogging(argv, android::base::StderrLogger);
gflags::ParseCommandLineFlags(&argc, &argv, true);
- auto wifi_view = vsoc::wifi::WifiExchangeView::GetInstance(
-#if defined(CUTTLEFISH_HOST)
- vsoc::GetDomain().c_str()
-#endif
- );
+ auto wifi_view = vsoc::wifi::WifiExchangeView::GetInstance(vsoc::GetDomain().c_str());
Mac80211HwSim::MacAddress guestMAC = wifi_view->GetGuestMACAddress();
Mac80211HwSim::MacAddress hostMAC = wifi_view->GetHostMACAddress();
-#ifdef CUTTLEFISH_HOST
WifiRelay relay(hostMAC, guestMAC);
-#else
- WifiRelay relay(guestMAC, hostMAC);
-#endif
int res = relay.initCheck();
if (res < 0) {
@@ -258,74 +240,6 @@
exit(1);
}
-
-#if !defined(CUTTLEFISH_HOST)
- cvd::NlClient client(NETLINK_GENERIC);
- if (!client.Init()) {
- LOG(ERROR) << "Could not open Netlink Generic.";
- exit(1);
- }
-
- cvd::NlClient nlRoute(NETLINK_ROUTE);
- if (!nlRoute.Init()) {
- LOG(ERROR) << "Could not open Netlink Route.";
- exit(1);
- }
-
- std::thread([&client, &nlRoute] {
- for (;;) {
- fd_set rs;
- FD_ZERO(&rs);
-
- int fdGeneric = nl_socket_get_fd(client.Sock());
- int fdRoute = nl_socket_get_fd(nlRoute.Sock());
-
- FD_SET(fdGeneric, &rs);
- FD_SET(fdRoute, &rs);
-
- int maxFd = std::max(fdGeneric, fdRoute);
-
- int res = select(maxFd + 1, &rs, nullptr, nullptr, nullptr);
-
- if (res == 0) {
- continue;
- } else if (res < 0) {
- continue;
- }
-
- if (FD_ISSET(fdGeneric, &rs)) {
- nl_recvmsgs_default(client.Sock());
- }
-
- if (FD_ISSET(fdRoute, &rs)) {
- nl_recvmsgs_default(nlRoute.Sock());
- }
- }
- }).detach();
-
- const std::string phyName = FLAGS_iface_name + "_phy";
- if (createRadio(&client, relay.mac80211Family(), phyName.c_str()) < 0) {
- LOG(ERROR) << "Could not create radio.";
- exit(1);
- }
-
- int phyIndex = getPhyIndex(phyName);
- CHECK_GE(phyIndex, 0);
- LOG(VERBOSE) << "Got PHY index " << phyIndex;
-
- int ifaceIndex = getInterfaceIndex(
- &client, relay.nl80211Family(), static_cast<uint32_t>(phyIndex));
-
- CHECK_GE(ifaceIndex, 0);
- LOG(VERBOSE) << "Got interface index " << ifaceIndex;
-
- if (updateInterface(
- &nlRoute, ifaceIndex, FLAGS_iface_name, &guestMAC[0]) < 0) {
- LOG(ERROR) << "Failed to update interface.";
- exit(1);
- }
-#endif // !defined(CUTTLEFISH_HOST)
-
relay.run();
return 0;
diff --git a/common/commands/wifi_relay/wifi_relay.h b/host/commands/wifi_relay/wifi_relay.h
similarity index 95%
rename from common/commands/wifi_relay/wifi_relay.h
rename to host/commands/wifi_relay/wifi_relay.h
index 2edc6db..669b1af 100644
--- a/common/commands/wifi_relay/wifi_relay.h
+++ b/host/commands/wifi_relay/wifi_relay.h
@@ -16,7 +16,7 @@
#pragma once
-#include "common/commands/wifi_relay/mac80211_hwsim.h"
+#include "host/commands/wifi_relay/mac80211_hwsim.h"
#include <errno.h>
#include <memory>