aboutsummaryrefslogtreecommitdiff
path: root/wmediumd
diff options
context:
space:
mode:
authorSeungjae Yoo <seungjaeyoo@google.com>2023-04-11 14:43:41 +0900
committerSeungjae Yoo <seungjaeyoo@google.com>2023-04-17 15:37:35 +0900
commitf0058e9439a3206ed5f61b6864044abd96d539f7 (patch)
treebf147033c7996651571bc641b782aba0e4842b27 /wmediumd
parentbc21ed09e5f19133942a5812fb2adddda55bfce4 (diff)
downloadwmediumd-f0058e9439a3206ed5f61b6864044abd96d539f7.tar.gz
Add SetPosition into WmediumdService
Bug: 273384914 Test: cvd env cvd-1 call WmediumdService SetPosition "mac_address:'42:00:00:00:01:00' x_pos:100.0 y_pos:100.0" && wmediumd_control list_stations Change-Id: I4229047e125191a051a7fbd629530a0beac224c1
Diffstat (limited to 'wmediumd')
-rw-r--r--wmediumd/grpc.h42
-rw-r--r--wmediumd/wmediumd.c48
-rw-r--r--wmediumd/wmediumd.h5
3 files changed, 92 insertions, 3 deletions
diff --git a/wmediumd/grpc.h b/wmediumd/grpc.h
new file mode 100644
index 0000000..69084f2
--- /dev/null
+++ b/wmediumd/grpc.h
@@ -0,0 +1,42 @@
+/*
+ *
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+#define GRPC_MSG_BUF_MAX 1024
+
+// Do not use_zero, the type of the message queue should be positive value.
+enum wmediumd_grpc_type {
+ GRPC_REQUEST = 1,
+ GRPC_RESPONSE,
+};
+
+// Do not use zero, writing zero to eventfd doesn't throw an event.
+enum wmediumd_grpc_request_type {
+ REQUEST_SET_POSITION = 1,
+};
+
+// Do not use zero, writing zero to eventfd doesn't throw an event.
+enum wmediumd_grpc_response_type {
+ RESPONSE_INVALID = 1,
+ RESPONSE_ACK,
+};
+
+struct wmediumd_grpc_message {
+ long type;
+ char data[GRPC_MSG_BUF_MAX];
+}; \ No newline at end of file
diff --git a/wmediumd/wmediumd.c b/wmediumd/wmediumd.c
index 2b1e9a4..0f4f050 100644
--- a/wmediumd/wmediumd.c
+++ b/wmediumd/wmediumd.c
@@ -39,6 +39,7 @@
#include <unistd.h>
#include <stdarg.h>
#include <endian.h>
+#include <sys/msg.h>
#include <usfstl/loop.h>
#include <usfstl/sched.h>
#include <usfstl/schedctrl.h>
@@ -50,6 +51,7 @@
#include "config.h"
#include "api.h"
#include "pmsr.h"
+#include "grpc.h"
USFSTL_SCHEDULER(scheduler);
@@ -1518,6 +1520,43 @@ static void close_pcapng(struct wmediumd *ctx) {
static void init_pcapng(struct wmediumd *ctx, const char *filename);
+static void wmediumd_grpc_service_handler(struct usfstl_loop_entry *entry) {
+ struct wmediumd *ctx = entry->data;
+
+ // Receive request type from WmediumdService
+ uint64_t request_type;
+ read(entry->fd, &request_type, sizeof(uint64_t));
+
+ struct wmediumd_grpc_message request_body;
+ uint64_t response_type;
+
+ // Receive request body from WmediumdService and do the task.
+ // TODO(273384914): Support more request types.
+ switch (request_type) {
+ case REQUEST_SET_POSITION:
+ if (msgrcv(ctx->msq_id, &request_body, sizeof(struct wmediumd_set_position), GRPC_REQUEST, 0) != sizeof(struct wmediumd_set_position)) {
+ w_logf(ctx, LOG_ERR, "%s: failed to get set_position request body\n", __func__);
+ }
+
+ if (process_set_position_message(ctx, (struct wmediumd_set_position *)(request_body.data)) < 0) {
+ w_logf(ctx, LOG_ERR, "%s: failed to execute set_position\n", __func__);
+ response_type = RESPONSE_INVALID;
+ }
+ response_type = RESPONSE_ACK;
+ break;
+ default:
+ w_logf(ctx, LOG_ERR, "%s: unknown request type\n", __func__);
+ response_type = RESPONSE_INVALID;
+ break;
+ }
+
+ // TODO(273384914): Send response with response_type
+ return;
+}
+
+// TODO(273384914): Deprecate messages used in wmediumd_control after
+// implementing in wmediumd_grpc_service_handler to be used in the command
+// 'cvd env'.
static void wmediumd_api_handler(struct usfstl_loop_entry *entry)
{
struct client *client = container_of(entry, struct client, loop);
@@ -1871,7 +1910,7 @@ static void init_pcapng(struct wmediumd *ctx, const char *filename)
#define VIRTIO_F_VERSION_1 32
#endif
-int wmediumd_main(int argc, char *argv[])
+int wmediumd_main(int argc, char *argv[], int event_fd, int msq_id)
{
int opt;
struct wmediumd ctx = {};
@@ -2022,6 +2061,13 @@ int wmediumd_main(int argc, char *argv[])
usfstl_sched_wallclock_init(&scheduler, 1000);
}
+ // Control event_fd to communicate WmediumdService.
+ ctx.grpc_loop.handler = wmediumd_grpc_service_handler;
+ ctx.grpc_loop.data = &ctx;
+ ctx.grpc_loop.fd = event_fd;
+ usfstl_loop_register(&ctx.grpc_loop);
+ ctx.msq_id = msq_id;
+
while (1) {
if (time_socket) {
usfstl_sched_next(&scheduler);
diff --git a/wmediumd/wmediumd.h b/wmediumd/wmediumd.h
index c40f111..695f871 100644
--- a/wmediumd/wmediumd.h
+++ b/wmediumd/wmediumd.h
@@ -214,9 +214,10 @@ struct client {
struct wmediumd {
int timerfd;
+ int msq_id;
struct nl_sock *sock;
- struct usfstl_loop_entry nl_loop;
+ struct usfstl_loop_entry nl_loop, grpc_loop;
struct usfstl_sched_ctrl *ctrl;
@@ -310,7 +311,7 @@ int get_max_index(void);
extern "C" {
#endif
-int wmediumd_main(int argc, char *argv[]);
+int wmediumd_main(int argc, char *argv[], int event_fd, int msq_id);
#ifdef __cplusplus
}