[RFC 1/4] knownnetworks: set ops on info in __network_info_init

James Prestwood
2023-12-13T17:26:04Z

This function was only used by hotspot as a backdoor to initializing
a network info object. For the hotspot case it has its own ops
structure which is set after calling.

DPP now will need a way to create/update a known network from a
receieved configuration but it only needs the default ops structure
from known networks. Set this automatically within this function.
This won't pose an issue to hotspot as it will just overwrite the
ops pointer to its own implementation.
---
src/knownnetworks.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/knownnetworks.c b/src/knownnetworks.c
index e2d0d515..b8f13cbc 100644
--- a/src/knownnetworks.c
+++ b/src/knownnetworks.c
@@ -125,21 +125,6 @@ void __network_config_parse(const struct l_settings *settings,
}
}

-void __network_info_init(struct network_info *info,
- const char *ssid, enum security security,
- struct network_config *config)
-{
- if (ssid)
- strcpy(info->ssid, ssid);
-
- info->type = security;
-
- memcpy(&info->config, config, sizeof(struct network_config));
-
- if (info->config.is_hidden)
- num_known_hidden_networks++;
-}
-
static void network_info_free(void *data)
{
struct network_info *network = data;
@@ -815,6 +800,23 @@ void known_networks_add(struct network_info *network)
KNOWN_NETWORKS_EVENT_ADDED, network);
}

+void __network_info_init(struct network_info *info,
+ const char *ssid, enum security security,
+ struct network_config *config)
+{
+ if (ssid)
+ strcpy(info->ssid, ssid);
+
+ info->type = security;
+
+ memcpy(&info->config, config, sizeof(struct network_config));
+
+ if (info->config.is_hidden)
+ num_known_hidden_networks++;
+
+ info->ops = &known_network_ops;
+}
+
static void known_network_new(const char *ssid, enum security security,
struct network_config *config)
{
--
2.34.1