]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Move parse_freq() to be a common helper function
authorJintao Lin <jintaolin@chromium.org>
Mon, 18 Dec 2023 18:11:46 +0000 (18:11 +0000)
committerJouni Malinen <j@w1.fi>
Sat, 23 Dec 2023 09:59:19 +0000 (11:59 +0200)
This allows the function to be used outside the context of the
wpa_supplicant control interface implementation.

Signed-off-by: Jintao Lin <jintaolin@chromium.org>
src/common/ieee802_11_common.c
src/common/ieee802_11_common.h
wpa_supplicant/ctrl_iface.c

index 1f71a1df0e0d869dba07c164dbcecb68408d1048..e5464f37845c15d786236d3a4500ee4c30f8d0c4 100644 (file)
@@ -3173,6 +3173,38 @@ enum oper_chan_width op_class_to_ch_width(u8 op_class)
 }
 
 
+/**
+ * chwidth_freq2_to_ch_width - Determine channel width as enum oper_chan_width
+ * @chwidth: Channel width integer
+ * @freq2: Value for frequency 2. 0 is not used
+ * Returns: enum oper_chan_width, -1 on failure
+ */
+int chwidth_freq2_to_ch_width(int chwidth, int freq2)
+{
+       if (freq2 < 0)
+               return -1;
+       if (freq2)
+               return CONF_OPER_CHWIDTH_80P80MHZ;
+
+       switch (chwidth) {
+       case 0:
+       case 20:
+       case 40:
+               return CONF_OPER_CHWIDTH_USE_HT;
+       case 80:
+               return CONF_OPER_CHWIDTH_80MHZ;
+       case 160:
+               return CONF_OPER_CHWIDTH_160MHZ;
+       case 320:
+               return CONF_OPER_CHWIDTH_320MHZ;
+       default:
+               wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
+                          chwidth);
+               return -1;
+       }
+}
+
+
 struct wpabuf * ieee802_11_defrag(const u8 *data, size_t len, bool ext_elem)
 {
        struct wpabuf *buf;
index a7d407b65d91cdd6fc18d6790ac51059f6c822bf..5426b41bb9e63eae5662118664ce3f2a274f1515 100644 (file)
@@ -292,6 +292,7 @@ bool ieee802_11_rsnx_capab_len(const u8 *rsnxe, size_t rsnxe_len,
 bool ieee802_11_rsnx_capab(const u8 *rsnxe, unsigned int capab);
 int op_class_to_bandwidth(u8 op_class);
 enum oper_chan_width op_class_to_ch_width(u8 op_class);
+int chwidth_freq2_to_ch_width(int chwidth, int freq2);
 
 /* element iteration helpers */
 #define for_each_element(_elem, _data, _datalen)                       \
index 9c6050134e4556df212e28e55989f7237d9b0d98..84828a7aed19e7241e400562614db7cb66c9d74f 100644 (file)
@@ -6300,32 +6300,6 @@ static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
 }
 
 
-static int parse_freq(int chwidth, int freq2)
-{
-       if (freq2 < 0)
-               return -1;
-       if (freq2)
-               return CONF_OPER_CHWIDTH_80P80MHZ;
-
-       switch (chwidth) {
-       case 0:
-       case 20:
-       case 40:
-               return CONF_OPER_CHWIDTH_USE_HT;
-       case 80:
-               return CONF_OPER_CHWIDTH_80MHZ;
-       case 160:
-               return CONF_OPER_CHWIDTH_160MHZ;
-       case 320:
-               return CONF_OPER_CHWIDTH_320MHZ;
-       default:
-               wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
-                          chwidth);
-               return -1;
-       }
-}
-
-
 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
                            char *buf, size_t buflen)
 {
@@ -6419,7 +6393,7 @@ static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
        if (pos2)
                chwidth = atoi(pos2 + 18);
 
-       max_oper_chwidth = parse_freq(chwidth, freq2);
+       max_oper_chwidth = chwidth_freq2_to_ch_width(chwidth, freq2);
        if (max_oper_chwidth < 0)
                return -1;
 
@@ -7073,7 +7047,7 @@ static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
        if (pos)
                chwidth = atoi(pos + 18);
 
-       max_oper_chwidth = parse_freq(chwidth, freq2);
+       max_oper_chwidth = chwidth_freq2_to_ch_width(chwidth, freq2);
        if (max_oper_chwidth < 0)
                return -1;
 
@@ -7228,7 +7202,7 @@ static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
        }
 #endif /* CONFIG_ACS */
 
-       max_oper_chwidth = parse_freq(chwidth, freq2);
+       max_oper_chwidth = chwidth_freq2_to_ch_width(chwidth, freq2);
        if (max_oper_chwidth < 0)
                return -1;