3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-25 09:39:25 +01:00

hwsim: add iftype/cipher disabling through DBus

Update the Dbus API to allow disabling iftypes and ciphers
just as you can with the command line.
This commit is contained in:
James Prestwood 2020-12-17 11:36:08 -08:00 committed by Denis Kenzior
parent fe0879f7d1
commit 5567caf64a

View File

@ -195,6 +195,62 @@ static void do_debug(const char *str, void *user_data)
l_info("%s%s", prefix, str);
}
static void hwsim_disable_support(const char *disable,
const struct hwsim_support *map, uint32_t *mask)
{
char **list = l_strsplit(disable, ',');
char **iter = list;
int i;
while (*iter) {
for (i = 0; map[i].name; i++) {
if (!strcmp(map[i].name, *iter))
*mask &= ~(map[i].value);
}
iter++;
}
l_strfreev(list);
}
static bool is_cipher_disabled(const char *args, enum crypto_cipher cipher)
{
char **list = l_strsplit(args, ',');
char **iter = list;
int i;
while (*iter) {
for (i = 0; cipher_map[i].name; i++) {
if (!strcmp(*iter, cipher_map[i].name) &&
cipher == cipher_map[i].value) {
printf("disable cipher: %s\n", cipher_map[i].name);
l_strfreev(list);
return true;
}
}
iter++;
}
l_strfreev(list);
return false;
}
static void hwsim_disable_ciphers(const char *disable)
{
uint8_t i;
for (i = 0; i < L_ARRAY_SIZE(hwsim_supported_ciphers); i++) {
if (is_cipher_disabled(disable, hwsim_supported_ciphers[i]))
continue;
hwsim_ciphers[hwsim_num_ciphers] = hwsim_supported_ciphers[i];
hwsim_num_ciphers++;
}
}
static void create_callback(struct l_genl_msg *msg, void *user_data)
{
struct l_genl_attr attr;
@ -1604,6 +1660,8 @@ static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus,
const char *key;
const char *name = NULL;
bool p2p = false;
const char *disabled_iftypes = NULL;
const char *disabled_ciphers = NULL;
if (pending_create_msg)
return dbus_error_busy(message);
@ -1620,7 +1678,12 @@ static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus,
else if (!strcmp(key, "P2P"))
ret = l_dbus_message_iter_get_variant(&variant,
"b", &p2p);
else if (!strcmp(key, "InterfaceTypeDisable"))
ret = l_dbus_message_iter_get_variant(&variant, "s",
&disabled_iftypes);
else if (!strcmp(key, "CipherTypeDisable"))
ret = l_dbus_message_iter_get_variant(&variant, "s",
&disabled_ciphers);
if (!ret)
goto invalid;
}
@ -1638,6 +1701,26 @@ static struct l_dbus_message *radio_manager_create(struct l_dbus *dbus,
l_genl_msg_append_attr(new_msg, HWSIM_ATTR_SUPPORT_P2P_DEVICE,
0, NULL);
if (disabled_iftypes) {
hwsim_disable_support(disabled_iftypes, iftype_map,
&hwsim_iftypes);
if (hwsim_iftypes != HWSIM_DEFAULT_IFTYPES)
l_genl_msg_append_attr(new_msg,
HWSIM_ATTR_IFTYPE_SUPPORT,
4, &hwsim_iftypes);
}
if (disabled_ciphers) {
hwsim_disable_ciphers(disabled_ciphers);
if (hwsim_num_ciphers)
l_genl_msg_append_attr(new_msg, HWSIM_ATTR_CIPHER_SUPPORT,
sizeof(uint32_t) * hwsim_num_ciphers,
hwsim_ciphers);
}
l_genl_family_send(hwsim, new_msg, radio_manager_create_callback,
pending_create_msg, NULL);
@ -2525,62 +2608,6 @@ error:
l_main_quit();
}
static void hwsim_disable_support(char *disable,
const struct hwsim_support *map, uint32_t *mask)
{
char **list = l_strsplit(disable, ',');
char **iter = list;
int i;
while (*iter) {
for (i = 0; map[i].name; i++) {
if (!strcmp(map[i].name, *iter))
*mask &= ~(map[i].value);
}
iter++;
}
l_strfreev(list);
}
static bool is_cipher_disabled(char *args, enum crypto_cipher cipher)
{
char **list = l_strsplit(args, ',');
char **iter = list;
int i;
while (*iter) {
for (i = 0; cipher_map[i].name; i++) {
if (!strcmp(*iter, cipher_map[i].name) &&
cipher == cipher_map[i].value) {
printf("disable cipher: %s\n", cipher_map[i].name);
l_strfreev(list);
return true;
}
}
iter++;
}
l_strfreev(list);
return false;
}
static void hwsim_disable_ciphers(char *disable)
{
uint8_t i;
for (i = 0; i < L_ARRAY_SIZE(hwsim_supported_ciphers); i++) {
if (is_cipher_disabled(disable, hwsim_supported_ciphers[i]))
continue;
hwsim_ciphers[hwsim_num_ciphers] = hwsim_supported_ciphers[i];
hwsim_num_ciphers++;
}
}
static void family_discovered(const struct l_genl_family_info *info,
void *user_data)
{