From 76574fdd2b396c56a582f3e3a29dd2322cc459cd Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 26 Jan 2026 18:18:21 +0100 Subject: [PATCH] confd: minor, coding style Also, gcc complains that ap_op may be used unset, so let's set it to the only safe default there is. Signed-off-by: Joachim Wiberg --- src/confd/src/if-wifi.c | 42 +++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/confd/src/if-wifi.c b/src/confd/src/if-wifi.c index 43a1e43c..39b61c36 100644 --- a/src/confd/src/if-wifi.c +++ b/src/confd/src/if-wifi.c @@ -1,11 +1,4 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -#include -#include - -#include "interfaces.h" - -#define WPA_SUPPLICANT_CONF "/etc/wpa_supplicant-%s.conf" - /* * WiFi Interface Management * @@ -14,6 +7,13 @@ * configuration (hostapd) is handled by hardware.c. */ +#include +#include + +#include "interfaces.h" + +#define WPA_SUPPLICANT_CONF "/etc/wpa_supplicant-%s.conf" + /* * Determine WiFi mode from YANG configuration */ @@ -25,28 +25,35 @@ typedef enum wifi_mode_t { static wifi_mode_t wifi_get_mode(struct lyd_node *wifi) { - struct lyd_node *ap = lydx_get_child(wifi, "access-point"); + struct lyd_node *ap; - if (ap && (lydx_get_op(ap) != LYDX_OP_DELETE)) - return wifi_ap; - else - return wifi_station; /* Need to return station even if "station" also is false, since that is the default scanning mode */ + ap = lydx_get_child(wifi, "access-point"); + if (ap) { + if (lydx_get_op(ap) != LYDX_OP_DELETE) + return wifi_ap; + } + + /* + * Need to return station even if "station" also is false, + * because station is the default scanning mode. + */ + return wifi_station; } int wifi_mode_changed(struct lyd_node *wifi) { + enum lydx_op ap_op = LYDX_OP_DELETE; struct lyd_node *ap; - enum lydx_op ap_op; if (!wifi) return 0; ap = lydx_get_child(wifi, "access-point"); - if (ap) ap_op = lydx_get_op(ap); - ERROR("MODE CHANGED: %d", ap && (ap_op == LYDX_OP_CREATE || ap_op == LYDX_OP_DELETE)); + DEBUG("MODE CHANGED: %d", ap && (ap_op == LYDX_OP_CREATE || ap_op == LYDX_OP_DELETE)); + return (ap && (ap_op == LYDX_OP_CREATE || ap_op == LYDX_OP_DELETE)); } @@ -70,21 +77,20 @@ static int wifi_gen_station(struct lyd_node *cif) radio = lydx_get_cattr(wifi, "radio"); station = lydx_get_child(wifi, "station"); - /* If station is NULL, we're in scan-only mode (no station container) */ if (station) { ssid = lydx_get_cattr(station, "ssid"); security = lydx_get_child(station, "security"); security_mode = lydx_get_cattr(security, "mode"); secret_name = lydx_get_cattr(security, "secret"); } else { + /* If station is NULL, we're in scan-only mode (no station container) */ ssid = NULL; security = NULL; security_mode = "disabled"; secret_name = NULL; } - radio_node = lydx_get_xpathf(cif, - "../../hardware/component[name='%s']/wifi-radio", radio); + radio_node = lydx_get_xpathf(cif, "../../hardware/component[name='%s']/wifi-radio", radio); country = lydx_get_cattr(radio_node, "country-code"); if (secret_name && strcmp(security_mode, "disabled") != 0) {