aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaeMan Park <jaeman@google.com>2021-11-15 04:16:39 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-11-15 04:16:39 +0000
commit496013cc4a77a91202c5adc573455b61db8ecf6d (patch)
treeba18c96751b5bb21ca25889cf7bbb9c5d3e39f92
parent813935e167386d15d57d976463dcf546704664df (diff)
parentc63d9a6d0ca68990d2bc6e392ca2e2478ccbf5fe (diff)
downloadwmediumd-496013cc4a77a91202c5adc573455b61db8ecf6d.tar.gz
Add handler for set_snr and reload_config api command am: c63d9a6d0c
Original change: https://android-review.googlesource.com/c/platform/external/wmediumd/+/1839803 Change-Id: Ie2c83120cd8578a47cd095c0ee3a840afbcd1ab1
-rw-r--r--wmediumd/api.h36
-rw-r--r--wmediumd/config.c45
-rw-r--r--wmediumd/config.h2
-rw-r--r--wmediumd/wmediumd.c67
-rw-r--r--wmediumd/wmediumd.h2
5 files changed, 152 insertions, 0 deletions
diff --git a/wmediumd/api.h b/wmediumd/api.h
index 24e9548..e68c776 100644
--- a/wmediumd/api.h
+++ b/wmediumd/api.h
@@ -36,6 +36,26 @@ enum wmediumd_message {
* with struct wmediumd_tx_start as the payload.
*/
WMEDIUMD_MSG_TX_START,
+
+ /*
+ * TODO(@jaeman) Get list of currnet nodes.
+ */
+ WMEDIUMD_MSG_GET_NODES,
+
+ /*
+ * Set SNR between two nodes.
+ */
+ WMEDIUMD_MSG_SET_SNR,
+
+ /*
+ * Clear and reload configuration at specified path
+ */
+ WMEDIUMD_MSG_RELOAD_CONFIG,
+
+ /*
+ * Clear and reload configuration loaded before
+ */
+ WMEDIUMD_MSG_RELOAD_CURRENT_CONFIG,
};
struct wmediumd_message_header {
@@ -74,4 +94,20 @@ struct wmediumd_tx_start {
uint32_t reserved[3];
};
+#pragma pack(push, 1)
+ struct wmediumd_set_snr {
+ /* MAC address of node 1 */
+ uint8_t node1_mac[6];
+ /* MAC address of node 2 */
+ uint8_t node2_mac[6];
+ /* New SNR between two nodes */
+ uint8_t snr;
+};
+#pragma pack(pop)
+
+struct wmediumd_reload_config {
+ /* path of wmediumd configuration file */
+ char config_path[0];
+};
+
#endif /* _WMEDIUMD_API_H */
diff --git a/wmediumd/config.c b/wmediumd/config.c
index c9a6f5c..5735f28 100644
--- a/wmediumd/config.c
+++ b/wmediumd/config.c
@@ -30,6 +30,7 @@
#include <math.h>
#include "wmediumd.h"
+#include "config.h"
static void string_to_mac_address(const char *str, u8 *addr)
{
@@ -397,6 +398,22 @@ static void mirror_link(struct wmediumd *ctx, int from, int to)
}
}
+int validate_config(const char* file) {
+ struct wmediumd ctx = {};
+
+ INIT_LIST_HEAD(&ctx.stations);
+ INIT_LIST_HEAD(&ctx.clients);
+ INIT_LIST_HEAD(&ctx.clients_to_free);
+
+ int load_result = load_config(&ctx, file, NULL);
+
+ clear_ctx(&ctx);
+
+ if (load_result < 0) return 0;
+
+ return 1;
+}
+
/*
* Loads a config file into memory
*/
@@ -414,6 +431,8 @@ int load_config(struct wmediumd *ctx, const char *file, const char *per_file)
float default_prob_value = 0.0;
bool *link_map = NULL;
+ ctx->config_path = strdup(file);
+
/*initialize the config file*/
cf = &cfg;
config_init(cf);
@@ -655,3 +674,29 @@ fail:
config_destroy(cf);
return -EINVAL;
}
+
+int clear_ctx(struct wmediumd *ctx) {
+ free(ctx->sta_array);
+ free(ctx->intf);
+ free(ctx->snr_matrix);
+ free(ctx->error_prob_matrix);
+ free(ctx->config_path);
+
+ ctx->sta_array = NULL;
+ ctx->intf = NULL;
+ ctx->snr_matrix = NULL;
+ ctx->error_prob_matrix = NULL;
+ ctx->config_path = NULL;
+
+ while (!list_empty(&ctx->stations)) {
+ struct station *station;
+
+ station = list_first_entry(&ctx->stations,
+ struct station, list);
+
+ list_del(&station->list);
+ free(station);
+ }
+
+ return 0;
+}
diff --git a/wmediumd/config.h b/wmediumd/config.h
index f9bcdf4..63f8615 100644
--- a/wmediumd/config.h
+++ b/wmediumd/config.h
@@ -24,6 +24,8 @@
#ifndef CONFIG_H_
#define CONFIG_H_
+int clear_ctx(struct wmediumd *ctx);
+int validate_config(const char* file);
int load_config(struct wmediumd *ctx, const char *file, const char *per_file);
int use_fixed_random_value(struct wmediumd *ctx);
diff --git a/wmediumd/wmediumd.c b/wmediumd/wmediumd.c
index 8a59782..d888a54 100644
--- a/wmediumd/wmediumd.c
+++ b/wmediumd/wmediumd.c
@@ -983,6 +983,55 @@ static void wmediumd_vu_disconnected(struct usfstl_vhost_user_dev *dev)
wmediumd_remove_client(dev->server->data, client);
}
+static int process_set_snr_message(struct wmediumd *ctx, struct wmediumd_set_snr *set_snr) {
+ struct station *node1 = get_station_by_addr(ctx, set_snr->node1_mac);
+ struct station *node2 = get_station_by_addr(ctx, set_snr->node2_mac);
+
+ if (node1 == NULL || node2 == NULL) {
+ return -1;
+ }
+
+ ctx->snr_matrix[ctx->num_stas * node2->index + node1->index] = set_snr->snr;
+ ctx->snr_matrix[ctx->num_stas * node1->index + node2->index] = set_snr->snr;
+
+ return 0;
+}
+
+static int process_reload_config_message(struct wmediumd *ctx,
+ struct wmediumd_reload_config *reload_config) {
+ char *config_path;
+ int result = 0;
+
+ config_path = reload_config->config_path;
+
+ if (validate_config(config_path)) {
+ clear_ctx(ctx);
+ load_config(ctx, config_path, NULL);
+ } else {
+ result = -1;
+ }
+
+ return result;
+}
+
+static int process_reload_current_config_message(struct wmediumd *ctx) {
+ char *config_path;
+ int result = 0;
+
+ config_path = strdup(ctx->config_path);
+
+ if (validate_config(config_path)) {
+ clear_ctx(ctx);
+ load_config(ctx, config_path, NULL);
+ } else {
+ result = -1;
+ }
+
+ free(config_path);
+
+ return result;
+}
+
static const struct usfstl_vhost_user_ops wmediumd_vu_ops = {
.connected = wmediumd_vu_connected,
.handle = wmediumd_vu_handle,
@@ -1068,6 +1117,24 @@ static void wmediumd_api_handler(struct usfstl_loop_entry *entry)
client->flags = control.flags;
break;
+ case WMEDIUMD_MSG_GET_NODES:
+ break;
+ case WMEDIUMD_MSG_SET_SNR:
+ if (process_set_snr_message(ctx, (struct wmediumd_set_snr *)data) < 0) {
+ response = WMEDIUMD_MSG_INVALID;
+ }
+ break;
+ case WMEDIUMD_MSG_RELOAD_CONFIG:
+ if (process_reload_config_message(ctx,
+ (struct wmediumd_reload_config *)data) < 0) {
+ response = WMEDIUMD_MSG_INVALID;
+ }
+ break;
+ case WMEDIUMD_MSG_RELOAD_CURRENT_CONFIG:
+ if (process_reload_current_config_message(ctx) < 0) {
+ response = WMEDIUMD_MSG_INVALID;
+ }
+ break;
case WMEDIUMD_MSG_ACK:
abort();
default:
diff --git a/wmediumd/wmediumd.h b/wmediumd/wmediumd.h
index 4b7ca66..dca4f02 100644
--- a/wmediumd/wmediumd.h
+++ b/wmediumd/wmediumd.h
@@ -229,6 +229,8 @@ struct wmediumd {
u32 need_start_notify;
FILE *pcap_file;
+
+ char *config_path;
};
struct hwsim_tx_rate {