]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Make check_40mhz_2g4 common
authorJanusz Dziedzic <janusz.dziedzic@tieto.com>
Thu, 8 Jan 2015 11:48:35 +0000 (12:48 +0100)
committerJouni Malinen <j@w1.fi>
Sat, 10 Jan 2015 15:35:53 +0000 (17:35 +0200)
Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
src/ap/hw_features.c
src/common/hw_features_common.c
src/common/hw_features_common.h

index cc0c19d67a20e9e4d4f24d321d110ecc1ccc74f1..6b0a72d832d8c570e310edc158195e794f3fd3de 100644 (file)
@@ -249,13 +249,6 @@ static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface)
 }
 
 
-static void ieee80211n_get_pri_sec_chan(struct wpa_scan_res *bss,
-                                       int *pri_chan, int *sec_chan)
-{
-       return get_pri_sec_chan(bss, pri_chan, sec_chan);
-}
-
-
 static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface,
                                     struct wpa_scan_results *scan_res)
 {
@@ -274,94 +267,16 @@ static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface,
 }
 
 
-static int ieee80211n_check_20mhz_bss(struct wpa_scan_res *bss, int pri_freq,
-                                     int start, int end)
-{
-       return check_20mhz_bss(bss, pri_freq, start, end);
-}
-
-
 static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface,
                                      struct wpa_scan_results *scan_res)
 {
-       int pri_freq, sec_freq;
-       int affected_start, affected_end;
-       size_t i;
-
-       pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
-       if (iface->conf->secondary_channel > 0)
-               sec_freq = pri_freq + 20;
-       else
-               sec_freq = pri_freq - 20;
-       affected_start = (pri_freq + sec_freq) / 2 - 25;
-       affected_end = (pri_freq + sec_freq) / 2 + 25;
-       wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
-                  affected_start, affected_end);
-       for (i = 0; i < scan_res->num; i++) {
-               struct wpa_scan_res *bss = scan_res->res[i];
-               int pri = bss->freq;
-               int sec = pri;
-               int sec_chan, pri_chan;
-               struct ieee802_11_elems elems;
-
-               /* Check for overlapping 20 MHz BSS */
-               if (ieee80211n_check_20mhz_bss(bss, pri_freq, affected_start,
-                                              affected_end)) {
-                       wpa_printf(MSG_DEBUG,
-                                  "Overlapping 20 MHz BSS is found");
-                       return 0;
-               }
-
-               ieee80211n_get_pri_sec_chan(bss, &pri_chan, &sec_chan);
-
-               if (sec_chan) {
-                       if (sec_chan < pri_chan)
-                               sec = pri - 20;
-                       else
-                               sec = pri + 20;
-               }
-
-               if ((pri < affected_start || pri > affected_end) &&
-                   (sec < affected_start || sec > affected_end))
-                       continue; /* not within affected channel range */
-
-               wpa_printf(MSG_DEBUG, "Neighboring BSS: " MACSTR
-                          " freq=%d pri=%d sec=%d",
-                          MAC2STR(bss->bssid), bss->freq, pri_chan, sec_chan);
-
-               if (sec_chan) {
-                       if (pri_freq != pri || sec_freq != sec) {
-                               wpa_printf(MSG_DEBUG, "40 MHz pri/sec "
-                                          "mismatch with BSS " MACSTR
-                                          " <%d,%d> (chan=%d%c) vs. <%d,%d>",
-                                          MAC2STR(bss->bssid),
-                                          pri, sec, pri_chan,
-                                          sec > pri ? '+' : '-',
-                                          pri_freq, sec_freq);
-                               return 0;
-                       }
-               }
+       int pri_chan, sec_chan;
 
-               ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems,
-                                      0);
-               if (elems.ht_capabilities &&
-                   elems.ht_capabilities_len >=
-                   sizeof(struct ieee80211_ht_capabilities)) {
-                       struct ieee80211_ht_capabilities *ht_cap =
-                               (struct ieee80211_ht_capabilities *)
-                               elems.ht_capabilities;
-
-                       if (le_to_host16(ht_cap->ht_capabilities_info) &
-                           HT_CAP_INFO_40MHZ_INTOLERANT) {
-                               wpa_printf(MSG_DEBUG,
-                                          "40 MHz Intolerant is set on channel %d in BSS "
-                                          MACSTR, pri, MAC2STR(bss->bssid));
-                               return 0;
-                       }
-               }
-       }
+       pri_chan = iface->conf->channel;
+       sec_chan = pri_chan + iface->conf->secondary_channel * 4;
 
-       return 1;
+       return check_40mhz_2g4(iface->current_mode, scan_res, pri_chan,
+                              sec_chan);
 }
 
 
index ce729ff2ef601d3628b484381557e2abcb250a3f..942380b856dee97c5d7c4835f5620839dec44cce 100644 (file)
@@ -265,3 +265,92 @@ int check_20mhz_bss(struct wpa_scan_res *bss, int pri_freq, int start, int end)
        }
        return 0;
 }
+
+
+int check_40mhz_2g4(struct hostapd_hw_modes *mode,
+                   struct wpa_scan_results *scan_res, int pri_chan,
+                   int sec_chan)
+{
+       int pri_freq, sec_freq;
+       int affected_start, affected_end;
+       size_t i;
+
+       if (!mode || !scan_res || !pri_chan || !sec_chan)
+               return 0;
+
+       if (pri_chan == sec_chan)
+               return 0;
+
+       pri_freq = hw_get_freq(mode, pri_chan);
+       sec_freq = hw_get_freq(mode, sec_chan);
+
+       affected_start = (pri_freq + sec_freq) / 2 - 25;
+       affected_end = (pri_freq + sec_freq) / 2 + 25;
+       wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
+                  affected_start, affected_end);
+       for (i = 0; i < scan_res->num; i++) {
+               struct wpa_scan_res *bss = scan_res->res[i];
+               int pri = bss->freq;
+               int sec = pri;
+               struct ieee802_11_elems elems;
+
+               /* Check for overlapping 20 MHz BSS */
+               if (check_20mhz_bss(bss, pri_freq, affected_start,
+                                   affected_end)) {
+                       wpa_printf(MSG_DEBUG,
+                                  "Overlapping 20 MHz BSS is found");
+                       return 0;
+               }
+
+               get_pri_sec_chan(bss, &pri_chan, &sec_chan);
+
+               if (sec_chan) {
+                       if (sec_chan < pri_chan)
+                               sec = pri - 20;
+                       else
+                               sec = pri + 20;
+               }
+
+               if ((pri < affected_start || pri > affected_end) &&
+                   (sec < affected_start || sec > affected_end))
+                       continue; /* not within affected channel range */
+
+               wpa_printf(MSG_DEBUG, "Neighboring BSS: " MACSTR
+                          " freq=%d pri=%d sec=%d",
+                          MAC2STR(bss->bssid), bss->freq, pri_chan, sec_chan);
+
+               if (sec_chan) {
+                       if (pri_freq != pri || sec_freq != sec) {
+                               wpa_printf(MSG_DEBUG,
+                                          "40 MHz pri/sec mismatch with BSS "
+                                          MACSTR
+                                          " <%d,%d> (chan=%d%c) vs. <%d,%d>",
+                                          MAC2STR(bss->bssid),
+                                          pri, sec, pri_chan,
+                                          sec > pri ? '+' : '-',
+                                          pri_freq, sec_freq);
+                               return 0;
+                       }
+               }
+
+               ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems,
+                                      0);
+               if (elems.ht_capabilities &&
+                   elems.ht_capabilities_len >=
+                   sizeof(struct ieee80211_ht_capabilities)) {
+                       struct ieee80211_ht_capabilities *ht_cap =
+                               (struct ieee80211_ht_capabilities *)
+                               elems.ht_capabilities;
+
+                       if (le_to_host16(ht_cap->ht_capabilities_info) &
+                           HT_CAP_INFO_40MHZ_INTOLERANT) {
+                               wpa_printf(MSG_DEBUG,
+                                          "40 MHz Intolerant is set on channel %d in BSS "
+                                          MACSTR, pri, MAC2STR(bss->bssid));
+                               return 0;
+                       }
+               }
+       }
+
+       return 1;
+}
index 8a03d749715b1bd967aa975684069260a1c89e25..046fccdec8dff2dfddf32df5dc5d369c497cff4c 100644 (file)
@@ -27,5 +27,8 @@ int check_40mhz_5g(struct hostapd_hw_modes *mode,
                   struct wpa_scan_results *scan_res, int pri_chan,
                   int sec_chan);
 int check_20mhz_bss(struct wpa_scan_res *bss, int pri_freq, int start, int end);
+int check_40mhz_2g4(struct hostapd_hw_modes *mode,
+                   struct wpa_scan_results *scan_res, int pri_chan,
+                   int sec_chan);
 
 #endif /* HW_FEATURES_COMMON_H */