]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
AP: Create hostapd_parse_freq_params()
authorJohannes Berg <johannes.berg@intel.com>
Thu, 31 Jul 2025 13:56:57 +0000 (15:56 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 6 Oct 2025 10:21:32 +0000 (13:21 +0300)
Split out hostapd_parse_freq_params() from hostapd_parse_csa_settings()
to be able to use it separately.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Reviewed-by: Peer, Ilan <ilan.peer@intel.com>
Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
src/ap/ctrl_iface_ap.c
src/ap/ctrl_iface_ap.h

index 799aff76597c598da877d5097159614003865354..2afaa4a6254236cdc215e6ee065711dfabab2b1a 100644 (file)
@@ -1127,50 +1127,65 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
 }
 
 
-int hostapd_parse_csa_settings(const char *pos,
-                              struct csa_settings *settings)
+int hostapd_parse_freq_params(const char *pos,
+                             struct hostapd_freq_params *params,
+                             unsigned int freq)
 {
-       char *end;
+       os_memset(params, 0, sizeof(*params));
 
-       os_memset(settings, 0, sizeof(*settings));
-       settings->cs_count = strtol(pos, &end, 10);
-       if (pos == end) {
-               wpa_printf(MSG_ERROR, "chanswitch: invalid cs_count provided");
-               return -1;
-       }
+       if (freq)
+               params->freq = freq;
+       else
+               params->freq = atoi(pos);
 
-       settings->freq_params.freq = atoi(end);
-       if (settings->freq_params.freq == 0) {
-               wpa_printf(MSG_ERROR, "chanswitch: invalid freq provided");
+       if (params->freq == 0) {
+               wpa_printf(MSG_ERROR, "freq_params: invalid freq provided");
                return -1;
        }
 
-#define SET_CSA_SETTING(str) \
+#define SET_FREQ_PARAM(str) \
        do { \
                const char *pos2 = os_strstr(pos, " " #str "="); \
                if (pos2) { \
                        pos2 += sizeof(" " #str "=") - 1; \
-                       settings->freq_params.str = atoi(pos2); \
+                       params->str = atoi(pos2); \
                } \
        } while (0)
 
-       SET_CSA_SETTING(center_freq1);
-       SET_CSA_SETTING(center_freq2);
-       SET_CSA_SETTING(bandwidth);
-       SET_CSA_SETTING(sec_channel_offset);
-       SET_CSA_SETTING(punct_bitmap);
-       settings->freq_params.ht_enabled = !!os_strstr(pos, " ht");
-       settings->freq_params.vht_enabled = !!os_strstr(pos, " vht");
-       settings->freq_params.eht_enabled = !!os_strstr(pos, " eht");
-       settings->freq_params.he_enabled = !!os_strstr(pos, " he") ||
-               settings->freq_params.eht_enabled;
-       settings->block_tx = !!os_strstr(pos, " blocktx");
-#undef SET_CSA_SETTING
+       SET_FREQ_PARAM(center_freq1);
+       SET_FREQ_PARAM(center_freq2);
+       SET_FREQ_PARAM(bandwidth);
+       SET_FREQ_PARAM(sec_channel_offset);
+       SET_FREQ_PARAM(punct_bitmap);
+       params->ht_enabled = !!os_strstr(pos, " ht");
+       params->vht_enabled = !!os_strstr(pos, " vht");
+       params->eht_enabled = !!os_strstr(pos, " eht");
+       params->he_enabled = !!os_strstr(pos, " he") ||
+               params->eht_enabled;
+#undef SET_FREQ_PARAM
 
        return 0;
 }
 
 
+int hostapd_parse_csa_settings(const char *pos,
+                              struct csa_settings *settings)
+{
+       char *end;
+
+       os_memset(settings, 0, sizeof(*settings));
+       settings->cs_count = strtol(pos, &end, 10);
+       if (pos == end) {
+               wpa_printf(MSG_ERROR, "chanswitch: invalid cs_count provided");
+               return -1;
+       }
+
+       settings->block_tx = !!os_strstr(pos, " blocktx");
+
+       return hostapd_parse_freq_params(end, &settings->freq_params, 0);
+}
+
+
 int hostapd_ctrl_iface_stop_ap(struct hostapd_data *hapd)
 {
        return hostapd_drv_stop_ap(hapd);
index 614f0426c1a563168bd1e44e49a20c650035a26c..926a51f8784be41fd9651aed8b3ca36b7bd519d9 100644 (file)
@@ -26,6 +26,9 @@ int hostapd_ctrl_iface_poll_sta(struct hostapd_data *hapd,
                                const char *txtaddr);
 int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
                              size_t buflen);
+int hostapd_parse_freq_params(const char *pos,
+                             struct hostapd_freq_params *params,
+                             unsigned int freq);
 int hostapd_parse_csa_settings(const char *pos,
                               struct csa_settings *settings);
 int hostapd_ctrl_iface_stop_ap(struct hostapd_data *hapd);