3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 14:49:24 +01:00

hwsim: Refactor create/list/destroy action logic

This commit is contained in:
Tim Kourt 2016-07-07 11:33:38 -07:00 committed by Denis Kenzior
parent a7916ebdf2
commit 0b8d641d2e

View File

@ -68,10 +68,13 @@ enum {
static struct l_genl_family *hwsim; static struct l_genl_family *hwsim;
static bool create_action; static const char *options;
static bool list_action;
static const char *list_option; static enum action {
static const char *destroy_action; ACTION_CREATE,
ACTION_DESTROY,
ACTION_LIST,
} action;
static bool keep_radios_attr; static bool keep_radios_attr;
static bool no_vif_attr; static bool no_vif_attr;
@ -244,6 +247,8 @@ static void hwsim_ready(void *user_data)
{ {
struct l_genl_msg *msg; struct l_genl_msg *msg;
int ret; int ret;
size_t msg_size;
uint32_t radio_id;
ret = l_genl_family_register(hwsim, "config", hwsim_config, ret = l_genl_family_register(hwsim, "config", hwsim_config,
NULL, NULL); NULL, NULL);
@ -253,8 +258,27 @@ static void hwsim_ready(void *user_data)
return; return;
} }
if (create_action) { switch (action) {
size_t msg_size = 0; case ACTION_LIST:
msg = l_genl_msg_new_sized(HWSIM_CMD_GET_RADIO,
options ? 8 : 4);
if (options) {
radio_id = atoi(options);
l_genl_msg_append_attr(msg, HWSIM_ATTR_RADIO_ID,
4, &radio_id);
l_genl_family_send(hwsim, msg, list_callback,
NULL, list_callback_done);
} else {
l_genl_family_dump(hwsim, msg, list_callback,
NULL, list_callback_done);
}
break;
case ACTION_CREATE:
msg_size = 0;
if (!keep_radios_attr) if (!keep_radios_attr)
msg_size += 4; msg_size += 4;
@ -289,30 +313,23 @@ static void hwsim_ready(void *user_data)
0, NULL); 0, NULL);
l_genl_family_send(hwsim, msg, create_callback, NULL, NULL); l_genl_family_send(hwsim, msg, create_callback, NULL, NULL);
return;
} else if (destroy_action) { break;
uint32_t id = atoi(destroy_action);
case ACTION_DESTROY:
radio_id = atoi(options);
msg = l_genl_msg_new_sized(HWSIM_CMD_DEL_RADIO, 8); msg = l_genl_msg_new_sized(HWSIM_CMD_DEL_RADIO, 8);
l_genl_msg_append_attr(msg, HWSIM_ATTR_RADIO_ID, 4, &id); l_genl_msg_append_attr(msg, HWSIM_ATTR_RADIO_ID, 4, &radio_id);
l_genl_family_send(hwsim, msg, destroy_callback, NULL, NULL); l_genl_family_send(hwsim, msg, destroy_callback, NULL, NULL);
} else if (list_action) {
msg = l_genl_msg_new_sized(HWSIM_CMD_GET_RADIO,
list_option ? 8 : 4);
if (list_option) { break;
uint32_t id = atoi(list_option);
l_genl_msg_append_attr(msg, HWSIM_ATTR_RADIO_ID, default:
4, &id);
l_genl_family_send(hwsim, msg, list_callback,
NULL, list_callback_done);
} else {
l_genl_family_dump(hwsim, msg, list_callback,
NULL, list_callback_done);
}
} else
l_main_quit(); l_main_quit();
break;
}
} }
static void hwsim_disappeared(void *user_data) static void hwsim_disappeared(void *user_data)
@ -379,7 +396,7 @@ int main(int argc, char *argv[])
switch (opt) { switch (opt) {
case ':': case ':':
if (optopt == 'L') { if (optopt == 'L') {
list_action = true; action = ACTION_LIST;
actions++; actions++;
} else { } else {
printf("option '-%c' requires an argument\n", printf("option '-%c' requires an argument\n",
@ -387,16 +404,17 @@ int main(int argc, char *argv[])
} }
break; break;
case 'L': case 'L':
list_action = true; action = ACTION_LIST;
list_option = optarg; options = optarg;
actions++; actions++;
break; break;
case 'C': case 'C':
create_action = true; action = ACTION_CREATE;
actions++; actions++;
break; break;
case 'D': case 'D':
destroy_action = optarg; action = ACTION_DESTROY;
options = optarg;
actions++; actions++;
break; break;
case 'k': case 'k':