Wireless Daemon for Linux
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.01.org
Subject: [PATCH 08/11] hwsim: add iftype/cipher disabling through DBus
Date: Thu, 17 Dec 2020 11:36:08 -0800	[thread overview]
Message-ID: <20201217193611.1177006-8-prestwoj@gmail.com> (raw)
In-Reply-To: <20201217193611.1177006-1-prestwoj@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4746 bytes --]

Update the Dbus API to allow disabling iftypes and ciphers
just as you can with the command line.
---
 tools/hwsim.c | 141 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 84 insertions(+), 57 deletions(-)

diff --git a/tools/hwsim.c b/tools/hwsim.c
index 6a1eb348..62a7d66d 100644
--- a/tools/hwsim.c
+++ b/tools/hwsim.c
@@ -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)
 {
-- 
2.26.2

  parent reply	other threads:[~2020-12-17 19:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-17 19:36 [PATCH 01/11] hwsim: add --no-register option James Prestwood
2020-12-17 19:36 ` [PATCH 02/11] hwsim: check pending_create_msg before replying James Prestwood
2020-12-17 19:36 ` [PATCH 03/11] auto-t: fix hwsim.py to use Destroy rather than Remove James Prestwood
2020-12-17 19:36 ` [PATCH 04/11] hwsim: change radio Create() to take a dictionary James Prestwood
2020-12-17 19:36 ` [PATCH 05/11] auto-t: update hwsim radio create to use dictionary James Prestwood
2020-12-17 19:36 ` [PATCH 06/11] test-runner: add wait_for_dbus_service James Prestwood
2020-12-17 19:36 ` [PATCH 07/11] test-runner: start hwsim always (optionally --no-register) James Prestwood
2020-12-17 19:36 ` James Prestwood [this message]
2020-12-17 19:36 ` [PATCH 09/11] auto-t: add iftype/cipher disable to hwsim.py James Prestwood
2020-12-17 19:36 ` [PATCH 10/11] test-runner: Use DBus for hwsim radios James Prestwood
2020-12-17 19:36 ` [PATCH 11/11] auto-t: fix hwsim.py spoof frame James Prestwood
2020-12-18  2:15 ` [PATCH 01/11] hwsim: add --no-register option Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201217193611.1177006-8-prestwoj@gmail.com \
    --to=prestwoj@gmail.com \
    --cc=iwd@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox