iwd.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/6] ap: update Scanning property when AP starts
@ 2022-11-04 16:37 James Prestwood
  2022-11-04 16:37 ` [PATCH v2 2/6] auto-t: iwd.py: allow certain APIs to be used in AP mode James Prestwood
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: James Prestwood @ 2022-11-04 16:37 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

This wasn't being updated meaning the property is missing until a
scan is issued over DBus.

Rather than duplicate all the property changed calls they were all
factored out into a helper function.
---
 src/ap.c | 55 +++++++++++++++++++++++++------------------------------
 1 file changed, 25 insertions(+), 30 deletions(-)

diff --git a/src/ap.c b/src/ap.c
index 9c82a545..665c1857 100644
--- a/src/ap.c
+++ b/src/ap.c
@@ -3672,6 +3672,28 @@ struct ap_if_data {
 	struct l_dbus_message *pending;
 };
 
+static void ap_properties_changed(struct ap_if_data *ap_if)
+{
+	l_dbus_property_changed(dbus_get_bus(),
+				netdev_get_path(ap_if->netdev),
+				IWD_AP_INTERFACE, "Started");
+	l_dbus_property_changed(dbus_get_bus(),
+				netdev_get_path(ap_if->netdev),
+				IWD_AP_INTERFACE, "Name");
+	l_dbus_property_changed(dbus_get_bus(),
+				netdev_get_path(ap_if->netdev),
+				IWD_AP_INTERFACE, "Frequency");
+	l_dbus_property_changed(dbus_get_bus(),
+				netdev_get_path(ap_if->netdev),
+				IWD_AP_INTERFACE, "PairwiseCiphers");
+	l_dbus_property_changed(dbus_get_bus(),
+				netdev_get_path(ap_if->netdev),
+				IWD_AP_INTERFACE, "GroupCipher");
+	l_dbus_property_changed(dbus_get_bus(),
+				netdev_get_path(ap_if->netdev),
+				IWD_AP_INTERFACE, "Scanning");
+}
+
 static void ap_if_event_func(enum ap_event_type type, const void *event_data,
 				void *user_data)
 {
@@ -3703,21 +3725,8 @@ static void ap_if_event_func(enum ap_event_type type, const void *event_data,
 
 		reply = l_dbus_message_new_method_return(ap_if->pending);
 		dbus_pending_reply(&ap_if->pending, reply);
-		l_dbus_property_changed(dbus_get_bus(),
-					netdev_get_path(ap_if->netdev),
-					IWD_AP_INTERFACE, "Started");
-		l_dbus_property_changed(dbus_get_bus(),
-					netdev_get_path(ap_if->netdev),
-					IWD_AP_INTERFACE, "Name");
-		l_dbus_property_changed(dbus_get_bus(),
-					netdev_get_path(ap_if->netdev),
-					IWD_AP_INTERFACE, "Frequency");
-		l_dbus_property_changed(dbus_get_bus(),
-					netdev_get_path(ap_if->netdev),
-					IWD_AP_INTERFACE, "PairwiseCiphers");
-		l_dbus_property_changed(dbus_get_bus(),
-					netdev_get_path(ap_if->netdev),
-					IWD_AP_INTERFACE, "GroupCipher");
+
+		ap_properties_changed(ap_if);
 
 		l_rtnl_set_linkmode_and_operstate(rtnl,
 					netdev_get_ifindex(ap_if->netdev),
@@ -3730,21 +3739,7 @@ static void ap_if_event_func(enum ap_event_type type, const void *event_data,
 						netdev_get_path(ap_if->netdev),
 						IWD_AP_DIAGNOSTIC_INTERFACE);
 
-		l_dbus_property_changed(dbus_get_bus(),
-					netdev_get_path(ap_if->netdev),
-					IWD_AP_INTERFACE, "Started");
-		l_dbus_property_changed(dbus_get_bus(),
-					netdev_get_path(ap_if->netdev),
-					IWD_AP_INTERFACE, "Name");
-		l_dbus_property_changed(dbus_get_bus(),
-					netdev_get_path(ap_if->netdev),
-					IWD_AP_INTERFACE, "Frequency");
-		l_dbus_property_changed(dbus_get_bus(),
-					netdev_get_path(ap_if->netdev),
-					IWD_AP_INTERFACE, "PairwiseCiphers");
-		l_dbus_property_changed(dbus_get_bus(),
-					netdev_get_path(ap_if->netdev),
-					IWD_AP_INTERFACE, "GroupCipher");
+		ap_properties_changed(ap_if);
 
 		l_rtnl_set_linkmode_and_operstate(rtnl,
 					netdev_get_ifindex(ap_if->netdev),
-- 
2.34.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/6] auto-t: iwd.py: allow certain APIs to be used in AP mode
  2022-11-04 16:37 [PATCH v2 1/6] ap: update Scanning property when AP starts James Prestwood
@ 2022-11-04 16:37 ` James Prestwood
  2022-11-04 16:37 ` [PATCH v2 3/6] auto-t: add test for scanning " James Prestwood
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2022-11-04 16:37 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

AP mode implements a few DBus methods/properties which are named
the same as station: Scan, Scanning, and GetOrderedNetworks. Allow
the Device object to work with these in AP mode by calling the
correct method if the Mode is 'ap'.
---
 autotests/util/iwd.py | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py
index 98b9ea1c..5fa12444 100755
--- a/autotests/util/iwd.py
+++ b/autotests/util/iwd.py
@@ -521,13 +521,16 @@ class Device(IWDDBusAbstract):
     def scanning(self):
         '''
         Reflects whether the device is currently scanning
-        for networks.  net.connman.iwd.Network objects are
-        updated when this property goes from true to false.
+        for networks.  For station devices net.connman.iwd.Network
+        objects are updated when this property goes from true to false
 
         @rtype: boolean
         '''
-        props = self._station_properties()
-        return bool(props['Scanning'])
+        if self._properties['Mode'] == 'station':
+            props = self._station_properties()
+            return bool(props['Scanning'])
+        else:
+            return bool(self._ap.scanning)
 
     @property
     def autoconnect(self):
@@ -544,12 +547,14 @@ class Device(IWDDBusAbstract):
            Possible exception: BusyEx
                                FailedEx
         '''
-        self._iface.Scan(dbus_interface=IWD_STATION_INTERFACE,
+        if self._properties['Mode'] == 'station':
+            self._iface.Scan(dbus_interface=IWD_STATION_INTERFACE,
                                reply_handler=self._success,
                                error_handler=self._failure)
-
-        if wait:
-            self._wait_for_async_op()
+            if wait:
+                self._wait_for_async_op()
+        else:
+            self._ap.scan()
 
     def disconnect(self):
         '''Disconnect from the network
@@ -576,6 +581,9 @@ class Device(IWDDBusAbstract):
            groups the maximum relative signal-strength is the
            main sorting factor.
         '''
+        if self._properties['Mode'] == 'ap':
+            return self._ap.get_ordered_networks()
+
         ordered_networks = []
         if not full_scan:
             for bus_obj in self._station.GetOrderedNetworks():
-- 
2.34.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/6] auto-t: add test for scanning in AP mode
  2022-11-04 16:37 [PATCH v2 1/6] ap: update Scanning property when AP starts James Prestwood
  2022-11-04 16:37 ` [PATCH v2 2/6] auto-t: iwd.py: allow certain APIs to be used in AP mode James Prestwood
@ 2022-11-04 16:37 ` James Prestwood
  2022-11-04 16:37 ` [PATCH v2 4/6] ap: change PairwiseCiphers to string array James Prestwood
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2022-11-04 16:37 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

---
 autotests/testAP/scan_test.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 autotests/testAP/scan_test.py

diff --git a/autotests/testAP/scan_test.py b/autotests/testAP/scan_test.py
new file mode 100644
index 00000000..0935912c
--- /dev/null
+++ b/autotests/testAP/scan_test.py
@@ -0,0 +1,20 @@
+#! /usr/bin/python3
+
+import unittest
+
+from iwd import IWD
+
+class Test(unittest.TestCase):
+    def test_ap_scan(self):
+        wd = IWD(True)
+
+        dev = wd.list_devices(1)[0]
+
+        dev.start_ap('TestAP2', 'Password2')
+
+        dev.scan()
+
+        networks = dev.get_ordered_networks()
+
+        self.assertTrue(len(networks) == 1)
+        self.assertTrue(networks[0]['Name'] == 'TestAP1')
-- 
2.34.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 4/6] ap: change PairwiseCiphers to string array
  2022-11-04 16:37 [PATCH v2 1/6] ap: update Scanning property when AP starts James Prestwood
  2022-11-04 16:37 ` [PATCH v2 2/6] auto-t: iwd.py: allow certain APIs to be used in AP mode James Prestwood
  2022-11-04 16:37 ` [PATCH v2 3/6] auto-t: add test for scanning " James Prestwood
@ 2022-11-04 16:37 ` James Prestwood
  2022-11-04 16:37 ` [PATCH v2 5/6] auto-t: update test to work with PairwiseCiphers array James Prestwood
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2022-11-04 16:37 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

A comma separated list as a string was ok for pure display purposes
but if any processing needed to be done on these values by external
consumers it really makes more sense to use a DBus array.
---
 src/ap.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/src/ap.c b/src/ap.c
index 665c1857..69412174 100644
--- a/src/ap.c
+++ b/src/ap.c
@@ -3154,11 +3154,10 @@ static enum ie_rsn_cipher_suite ap_string_to_cipher(const char *str)
 		return 0;
 }
 
-static char *ap_ciphers_to_string(uint16_t ciphers)
+static char **ap_ciphers_to_strv(uint16_t ciphers)
 {
 	uint16_t i;
 	char **list = l_strv_new();
-	char *ret;
 
 	for (i = 0; i < 16; i++) {
 		if (!(ciphers & (1 << i)))
@@ -3168,9 +3167,7 @@ static char *ap_ciphers_to_string(uint16_t ciphers)
 					ie_rsn_cipher_suite_to_string(1 << i));
 	}
 
-	ret = l_strjoinv(list, ',');
-	l_strv_free(list);
-	return ret;
+	return list;
 }
 
 static int ap_load_config(struct ap_state *ap, const struct l_settings *config,
@@ -4096,15 +4093,22 @@ static bool ap_dbus_property_get_pairwise(struct l_dbus *dbus,
 					void *user_data)
 {
 	struct ap_if_data *ap_if = user_data;
-	char *list;
+	char **ciphers;
+	size_t i;
 
 	if (!ap_if->ap || !ap_if->ap->started)
 		return false;
 
-	list = ap_ciphers_to_string(ap_if->ap->ciphers);
+	ciphers = ap_ciphers_to_strv(ap_if->ap->ciphers);
+
+	l_dbus_message_builder_enter_array(builder, "s");
+
+	for (i = 0; ciphers[i]; i++)
+		l_dbus_message_builder_append_basic(builder, 's', ciphers[i]);
+
+	l_dbus_message_builder_leave_array(builder);
 
-	l_dbus_message_builder_append_basic(builder, 's', list);
-	l_free(list);
+	l_strv_free(ciphers);
 
 	return true;
 }
@@ -4115,15 +4119,16 @@ static bool ap_dbus_property_get_group(struct l_dbus *dbus,
 					void *user_data)
 {
 	struct ap_if_data *ap_if = user_data;
-	char *cipher;
+	char **cipher;
 
 	if (!ap_if->ap || !ap_if->ap->started)
 		return false;
 
-	cipher = ap_ciphers_to_string(ap_if->ap->group_cipher);
+	cipher = ap_ciphers_to_strv(ap_if->ap->group_cipher);
 
-	l_dbus_message_builder_append_basic(builder, 's', cipher);
-	l_free(cipher);
+	/* Group cipher will only ever be a single value */
+	l_dbus_message_builder_append_basic(builder, 's', cipher[0]);
+	l_strv_free(cipher);
 
 	return true;
 }
@@ -4149,7 +4154,7 @@ static void ap_setup_interface(struct l_dbus_interface *interface)
 					ap_dbus_property_get_scanning, NULL);
 	l_dbus_interface_property(interface, "Frequency", 0, "u",
 					ap_dbus_property_get_freq, NULL);
-	l_dbus_interface_property(interface, "PairwiseCiphers", 0, "s",
+	l_dbus_interface_property(interface, "PairwiseCiphers", 0, "as",
 					ap_dbus_property_get_pairwise, NULL);
 	l_dbus_interface_property(interface, "GroupCipher", 0, "s",
 					ap_dbus_property_get_group, NULL);
-- 
2.34.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 5/6] auto-t: update test to work with PairwiseCiphers array
  2022-11-04 16:37 [PATCH v2 1/6] ap: update Scanning property when AP starts James Prestwood
                   ` (2 preceding siblings ...)
  2022-11-04 16:37 ` [PATCH v2 4/6] ap: change PairwiseCiphers to string array James Prestwood
@ 2022-11-04 16:37 ` James Prestwood
  2022-11-04 16:38 ` [PATCH v2 6/6] doc: document AP properties PairwiseCiphers/GroupCipher James Prestwood
  2022-11-04 17:54 ` [PATCH v2 1/6] ap: update Scanning property when AP starts Denis Kenzior
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2022-11-04 16:37 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

---
 autotests/testAP-no-support/connection_test.py | 2 +-
 autotests/testAP/connection_test.py            | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/autotests/testAP-no-support/connection_test.py b/autotests/testAP-no-support/connection_test.py
index d7a13f51..47c06262 100644
--- a/autotests/testAP-no-support/connection_test.py
+++ b/autotests/testAP-no-support/connection_test.py
@@ -27,7 +27,7 @@ class Test(unittest.TestCase):
         dev_ap.start_ap('TestAP2', 'Password2')
 
         self.assertTrue(dev_ap.group_cipher == 'TKIP')
-        self.assertTrue(dev_ap.pairwise_ciphers == 'TKIP')
+        self.assertIn('TKIP', dev_ap.pairwise_ciphers)
 
         ordered_network = dev_sta.get_ordered_network('TestAP2')
 
diff --git a/autotests/testAP/connection_test.py b/autotests/testAP/connection_test.py
index 53dcfaba..a9135c26 100644
--- a/autotests/testAP/connection_test.py
+++ b/autotests/testAP/connection_test.py
@@ -60,7 +60,7 @@ class Test(unittest.TestCase):
                 dev1.start_ap('TestAP2')
 
                 self.assertTrue(dev1.group_cipher == group)
-                self.assertTrue(dev1.pairwise_ciphers == pairwise)
+                self.assertIn(pairwise, dev1.pairwise_ciphers)
 
                 try:
                     validate(wd, dev2, dev1, 'TestAP2', 'Password2', ip_checks=False)
-- 
2.34.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 6/6] doc: document AP properties PairwiseCiphers/GroupCipher
  2022-11-04 16:37 [PATCH v2 1/6] ap: update Scanning property when AP starts James Prestwood
                   ` (3 preceding siblings ...)
  2022-11-04 16:37 ` [PATCH v2 5/6] auto-t: update test to work with PairwiseCiphers array James Prestwood
@ 2022-11-04 16:38 ` James Prestwood
  2022-11-04 17:54 ` [PATCH v2 1/6] ap: update Scanning property when AP starts Denis Kenzior
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2022-11-04 16:38 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

---
 doc/access-point-api.txt | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/doc/access-point-api.txt b/doc/access-point-api.txt
index 63e61d49..839feb26 100644
--- a/doc/access-point-api.txt
+++ b/doc/access-point-api.txt
@@ -71,3 +71,15 @@ Properties	boolean Started [readonly]
 		uint32 Frequency [readonly, optional]
 
 			The frequency that the Access Point is operating on.
+
+		array{string} PairwiseCiphers [readonly, optional]
+
+			List of pairwise ciphers the access point supports.
+			The same format as setting a list of ciphers for an AP
+			profile, i.e. TKIP, CCMP-128, GCMP-128, CCMP-256 etc.
+
+		string GroupCipher [readonly, optional]
+
+			The group cipher suite the access point is using.
+			Possible values are the same as what could be included
+			in the PairwiseCiphers list.
-- 
2.34.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/6] ap: update Scanning property when AP starts
  2022-11-04 16:37 [PATCH v2 1/6] ap: update Scanning property when AP starts James Prestwood
                   ` (4 preceding siblings ...)
  2022-11-04 16:38 ` [PATCH v2 6/6] doc: document AP properties PairwiseCiphers/GroupCipher James Prestwood
@ 2022-11-04 17:54 ` Denis Kenzior
  5 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2022-11-04 17:54 UTC (permalink / raw)
  To: James Prestwood, iwd

Hi James,

On 11/4/22 11:37, James Prestwood wrote:
> This wasn't being updated meaning the property is missing until a
> scan is issued over DBus.
> 
> Rather than duplicate all the property changed calls they were all
> factored out into a helper function.
> ---
>   src/ap.c | 55 +++++++++++++++++++++++++------------------------------
>   1 file changed, 25 insertions(+), 30 deletions(-)
> 

All applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-11-04 17:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-04 16:37 [PATCH v2 1/6] ap: update Scanning property when AP starts James Prestwood
2022-11-04 16:37 ` [PATCH v2 2/6] auto-t: iwd.py: allow certain APIs to be used in AP mode James Prestwood
2022-11-04 16:37 ` [PATCH v2 3/6] auto-t: add test for scanning " James Prestwood
2022-11-04 16:37 ` [PATCH v2 4/6] ap: change PairwiseCiphers to string array James Prestwood
2022-11-04 16:37 ` [PATCH v2 5/6] auto-t: update test to work with PairwiseCiphers array James Prestwood
2022-11-04 16:38 ` [PATCH v2 6/6] doc: document AP properties PairwiseCiphers/GroupCipher James Prestwood
2022-11-04 17:54 ` [PATCH v2 1/6] ap: update Scanning property when AP starts Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).