diff options
author | Seungjae Yoo <seungjaeyoo@google.com> | 2022-06-08 05:55:51 +0000 |
---|---|---|
committer | Seungjae Yoo <seungjaeyoo@google.com> | 2022-06-19 07:31:56 +0000 |
commit | 4aecc0e6b0a9367428d2b03f2a29b68c1d87ec50 (patch) | |
tree | 79d7c60a23e16a7363e3d7bc0748633e5d9394c1 /wmediumd | |
parent | 881cb168f0ed583585d479d748b68168ea0cd72e (diff) | |
download | wmediumd-4aecc0e6b0a9367428d2b03f2a29b68c1d87ec50.tar.gz |
Support set position API in wmediumd
With set position API in wmediumd, we can connect/disconnect wifi
connection with distance between stations like real world.
Type command "wmediumd_control set_position" to use it.
Bug: 230432123
Test: Creating several cuttlefish instance with "launch_cvd", and
change X/Y position of station with "wmediumd_control set_position".
Then the result could be seen with "wmediumd_control list_stations" and
the cuttlefish screen.
Change-Id: I3858b7af8fdd1172b3a544312fa17cc7583ed042
Diffstat (limited to 'wmediumd')
-rw-r--r-- | wmediumd/api.h | 16 | ||||
-rw-r--r-- | wmediumd/config.c | 34 | ||||
-rw-r--r-- | wmediumd/config.h | 1 | ||||
-rw-r--r-- | wmediumd/wmediumd.c | 20 | ||||
-rw-r--r-- | wmediumd/wmediumd.h | 2 |
5 files changed, 60 insertions, 13 deletions
diff --git a/wmediumd/api.h b/wmediumd/api.h index ba507e4..8fa8fe0 100644 --- a/wmediumd/api.h +++ b/wmediumd/api.h @@ -70,6 +70,11 @@ enum wmediumd_message { WMEDIUMD_MSG_STOP_PCAP, WMEDIUMD_MSG_STATIONS_LIST, + + /* + * Set position of station. + */ + WMEDIUMD_MSG_SET_POSITION, }; struct wmediumd_message_header { @@ -109,7 +114,7 @@ struct wmediumd_tx_start { }; #pragma pack(push, 1) - struct wmediumd_set_snr { +struct wmediumd_set_snr { /* MAC address of node 1 */ uint8_t node1_mac[6]; /* MAC address of node 2 */ @@ -143,6 +148,15 @@ struct wmediumd_station_infos { uint32_t count; struct wmediumd_station_info stations[0]; }; + +struct wmediumd_set_position { + /* MAC address */ + uint8_t mac[6]; + /* X position of station */ + double x; + /* Y position of station */ + double y; +}; #pragma pack(pop) #endif /* _WMEDIUMD_API_H */ diff --git a/wmediumd/config.c b/wmediumd/config.c index fc4986a..0500949 100644 --- a/wmediumd/config.c +++ b/wmediumd/config.c @@ -32,6 +32,14 @@ #include "wmediumd.h" #include "config.h" +#ifndef MIN +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif + +#ifndef MAX +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#endif + static void string_to_mac_address(const char *str, u8 *addr) { int a[ETH_ALEN]; @@ -110,7 +118,7 @@ static int calc_path_loss_free_space(void *model_param, * https://en.wikipedia.org/wiki/Free-space_path_loss */ PL = 20.0 * log10(4.0 * M_PI * d * FREQ_1CH / SPEED_LIGHT); - return PL; + return MAX(PL, 0); } /* * Calculate path loss based on a log distance model @@ -146,7 +154,7 @@ static int calc_path_loss_log_distance(void *model_param, */ PL = PL0 + 10.0 * param->path_loss_exponent * log10(d) + param->Xg; - return PL; + return MAX(PL, 0); } /* * Calculate path loss based on a itu model @@ -176,23 +184,23 @@ static int calc_path_loss_itu(void *model_param, * nFLOORS: number of floors */ PL = 20.0 * log10(FREQ_1CH) + N * log10(d) + param->LF * param->nFLOORS - 28; - return PL; + return MAX(PL, 0); } static void recalc_path_loss(struct wmediumd *ctx) { - int start, end, path_loss; - + int start, end, tx_power, path_loss, signal; for (start = 0; start < ctx->num_stas; start++) { for (end = 0; end < ctx->num_stas; end++) { - if (start == end) + if (start == end) { continue; + } - path_loss = ctx->calc_path_loss(ctx->path_loss_param, - ctx->sta_array[end], ctx->sta_array[start]); - ctx->snr_matrix[ctx->num_stas * start + end] = - ctx->sta_array[start]->tx_power - path_loss - - NOISE_LEVEL; + tx_power = ctx->sta_array[start]->tx_power; + path_loss = ctx->calc_path_loss(ctx->path_loss_param, ctx->sta_array[end], ctx->sta_array[start]); + // Test breakage exists in WifiStatsTests when signal is not negative value. + signal = MIN(tx_power - path_loss, -1); + ctx->snr_matrix[ctx->num_stas * start + end] = signal - NOISE_LEVEL; } } } @@ -700,3 +708,7 @@ int clear_config(struct wmediumd *ctx) { return 0; } + +void calc_path_loss(struct wmediumd *ctx) { + recalc_path_loss(ctx); +}
\ No newline at end of file diff --git a/wmediumd/config.h b/wmediumd/config.h index 471ffe1..feac4c2 100644 --- a/wmediumd/config.h +++ b/wmediumd/config.h @@ -24,6 +24,7 @@ #ifndef CONFIG_H_ #define CONFIG_H_ +void calc_path_loss(struct wmediumd *ctx); int clear_config(struct wmediumd *ctx); int validate_config(const char* file); int load_config(struct wmediumd *ctx, const char *file, const char *per_file); diff --git a/wmediumd/wmediumd.c b/wmediumd/wmediumd.c index 860c214..31f2ce3 100644 --- a/wmediumd/wmediumd.c +++ b/wmediumd/wmediumd.c @@ -1148,6 +1148,21 @@ static int process_get_stations_message(struct wmediumd *ctx, ssize_t *response_ return 0; } +static int process_set_position_message(struct wmediumd *ctx, struct wmediumd_set_position *set_position) { + struct station *node = get_station_by_addr(ctx, set_position->mac); + + if (node == NULL) { + return -1; + } + + node->x = set_position->x; + node->y = set_position->y; + + calc_path_loss(ctx); + + return 0; +} + static const struct usfstl_vhost_user_ops wmediumd_vu_ops = { .connected = wmediumd_vu_connected, .handle = wmediumd_vu_handle, @@ -1268,6 +1283,11 @@ static void wmediumd_api_handler(struct usfstl_loop_entry *entry) case WMEDIUMD_MSG_STOP_PCAP: close_pcapng(ctx); break; + case WMEDIUMD_MSG_SET_POSITION: + if (process_set_position_message(ctx, (struct wmediumd_set_position *)data) < 0) { + response = WMEDIUMD_MSG_INVALID; + } + break; case WMEDIUMD_MSG_ACK: assert(client->wait_for_ack == true); assert(hdr.data_len == 0); diff --git a/wmediumd/wmediumd.h b/wmediumd/wmediumd.h index 4001998..f8bc395 100644 --- a/wmediumd/wmediumd.h +++ b/wmediumd/wmediumd.h @@ -110,7 +110,7 @@ enum { #define VERSION_NR 1 -#define SNR_DEFAULT 90 +#define SNR_DEFAULT 30 #include <stdint.h> #include <stdbool.h> |