hostapd: fix encrypted mesh channel settings
[oweals/openwrt.git] / package / network / services / hostapd / patches / 370-ap_sta_support.patch
1 --- a/wpa_supplicant/wpa_supplicant_i.h
2 +++ b/wpa_supplicant/wpa_supplicant_i.h
3 @@ -101,6 +101,11 @@ struct wpa_interface {
4         const char *ifname;
5  
6         /**
7 +        * hostapd_ctrl - path to hostapd control socket for notification
8 +        */
9 +       const char *hostapd_ctrl;
10 +
11 +       /**
12          * bridge_ifname - Optional bridge interface name
13          *
14          * If the driver interface (ifname) is included in a Linux bridge
15 @@ -513,6 +518,8 @@ struct wpa_supplicant {
16  #endif /* CONFIG_CTRL_IFACE_BINDER */
17         char bridge_ifname[16];
18  
19 +       struct wpa_ctrl *hostapd;
20 +
21         char *confname;
22         char *confanother;
23  
24 --- a/wpa_supplicant/Makefile
25 +++ b/wpa_supplicant/Makefile
26 @@ -26,6 +26,10 @@ CFLAGS += $(EXTRA_CFLAGS)
27  CFLAGS += -I$(abspath ../src)
28  CFLAGS += -I$(abspath ../src/utils)
29  
30 +ifdef MULTICALL
31 +CFLAGS += -DMULTICALL
32 +endif
33 +
34  -include .config
35  -include $(if $(MULTICALL),../hostapd/.config)
36  
37 @@ -117,6 +121,8 @@ OBJS_c += ../src/utils/common.o
38  OBJS_c += ../src/common/cli.o
39  OBJS += wmm_ac.o
40  
41 +OBJS += ../src/common/wpa_ctrl.o
42 +
43  ifndef CONFIG_OS
44  ifdef CONFIG_NATIVE_WINDOWS
45  CONFIG_OS=win32
46 --- a/wpa_supplicant/wpa_supplicant.c
47 +++ b/wpa_supplicant/wpa_supplicant.c
48 @@ -125,6 +125,55 @@ static void wpas_update_fils_connect_par
49  #endif /* CONFIG_FILS && IEEE8021X_EAPOL */
50  
51  
52 +static int hostapd_stop(struct wpa_supplicant *wpa_s)
53 +{
54 +       const char *cmd = "STOP_AP";
55 +       char buf[256];
56 +       size_t len = sizeof(buf);
57 +
58 +       if (wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL) < 0) {
59 +               wpa_printf(MSG_ERROR, "\nFailed to stop hostapd AP interfaces\n");
60 +               return -1;
61 +       }
62 +       return 0;
63 +}
64 +
65 +static int hostapd_reload(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
66 +{
67 +       char *cmd = NULL;
68 +       char buf[256];
69 +       size_t len = sizeof(buf);
70 +       enum hostapd_hw_mode hw_mode;
71 +       u8 channel;
72 +       int sec_chan = 0;
73 +       int ret;
74 +
75 +       if (!bss)
76 +               return -1;
77 +
78 +       if (bss->ht_param & HT_INFO_HT_PARAM_STA_CHNL_WIDTH) {
79 +               int sec = bss->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
80 +               if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
81 +                       sec_chan = 1;
82 +               else if (sec ==  HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
83 +                       sec_chan = -1;
84 +       }
85 +
86 +       hw_mode = ieee80211_freq_to_chan(bss->freq, &channel);
87 +       if (asprintf(&cmd, "UPDATE channel=%d sec_chan=%d hw_mode=%d",
88 +                    channel, sec_chan, hw_mode) < 0)
89 +               return -1;
90 +
91 +       ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
92 +       free(cmd);
93 +
94 +       if (ret < 0) {
95 +               wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
96 +               return -1;
97 +       }
98 +       return 0;
99 +}
100 +
101  /* Configure default/group WEP keys for static WEP */
102  int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
103  {
104 @@ -893,12 +942,16 @@ void wpa_supplicant_set_state(struct wpa
105  
106                 sme_sched_obss_scan(wpa_s, 1);
107  
108 +               if (wpa_s->hostapd)
109 +                       hostapd_reload(wpa_s, wpa_s->current_bss);
110  #if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL)
111                 if (!fils_hlp_sent && ssid && ssid->eap.erp)
112                         wpas_update_fils_connect_params(wpa_s);
113  #endif /* CONFIG_FILS && IEEE8021X_EAPOL */
114         } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING ||
115                    state == WPA_ASSOCIATED) {
116 +               if (wpa_s->hostapd)
117 +                       hostapd_stop(wpa_s);
118                 wpa_s->new_connection = 1;
119                 wpa_drv_set_operstate(wpa_s, 0);
120  #ifndef IEEE8021X_EAPOL
121 @@ -5351,6 +5404,20 @@ static int wpa_supplicant_init_iface(str
122                            sizeof(wpa_s->bridge_ifname));
123         }
124  
125 +       if (iface->hostapd_ctrl) {
126 +               char *cmd = "STOP_AP";
127 +               char buf[256];
128 +               int len = sizeof(buf);
129 +
130 +               wpa_s->hostapd = wpa_ctrl_open(iface->hostapd_ctrl);
131 +               if (!wpa_s->hostapd) {
132 +                       wpa_printf(MSG_ERROR, "\nFailed to connect to hostapd\n");
133 +                       return -1;
134 +               }
135 +               if (hostapd_stop(wpa_s) < 0)
136 +                       return -1;
137 +       }
138 +
139         /* RSNA Supplicant Key Management - INITIALIZE */
140         eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
141         eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
142 @@ -5672,6 +5739,11 @@ static void wpa_supplicant_deinit_iface(
143         if (terminate)
144                 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING);
145  
146 +       if (wpa_s->hostapd) {
147 +               wpa_ctrl_close(wpa_s->hostapd);
148 +               wpa_s->hostapd = NULL;
149 +       }
150 +
151         if (wpa_s->ctrl_iface) {
152                 wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
153                 wpa_s->ctrl_iface = NULL;
154 --- a/wpa_supplicant/bss.c
155 +++ b/wpa_supplicant/bss.c
156 @@ -11,6 +11,7 @@
157  #include "utils/common.h"
158  #include "utils/eloop.h"
159  #include "common/ieee802_11_defs.h"
160 +#include "common/ieee802_11_common.h"
161  #include "drivers/driver.h"
162  #include "eap_peer/eap.h"
163  #include "wpa_supplicant_i.h"
164 @@ -290,6 +291,10 @@ void calculate_update_time(const struct
165  static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src,
166                              struct os_reltime *fetch_time)
167  {
168 +       struct ieee80211_ht_capabilities *capab;
169 +       struct ieee80211_ht_operation *oper;
170 +       struct ieee802_11_elems elems;
171 +
172         dst->flags = src->flags;
173         os_memcpy(dst->bssid, src->bssid, ETH_ALEN);
174         dst->freq = src->freq;
175 @@ -302,6 +307,15 @@ static void wpa_bss_copy_res(struct wpa_
176         dst->est_throughput = src->est_throughput;
177         dst->snr = src->snr;
178  
179 +       memset(&elems, 0, sizeof(elems));
180 +       ieee802_11_parse_elems((u8 *) (src + 1), src->ie_len, &elems, 0);
181 +       capab = (struct ieee80211_ht_capabilities *) elems.ht_capabilities;
182 +       oper = (struct ieee80211_ht_operation *) elems.ht_operation;
183 +       if (capab)
184 +               dst->ht_capab = le_to_host16(capab->ht_capabilities_info);
185 +       if (oper)
186 +               dst->ht_param = oper->ht_param;
187 +
188         calculate_update_time(fetch_time, src->age, &dst->last_update);
189  }
190  
191 --- a/wpa_supplicant/main.c
192 +++ b/wpa_supplicant/main.c
193 @@ -34,7 +34,7 @@ static void usage(void)
194                "vW] [-P<pid file>] "
195                "[-g<global ctrl>] \\\n"
196                "        [-G<group>] \\\n"
197 -              "        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
198 +              "        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-H<hostapd path>] "
199                "[-p<driver_param>] \\\n"
200                "        [-b<br_ifname>] [-e<entropy file>]"
201  #ifdef CONFIG_DEBUG_FILE
202 @@ -74,6 +74,7 @@ static void usage(void)
203                "  -g = global ctrl_interface\n"
204                "  -G = global ctrl_interface group\n"
205                "  -h = show this help text\n"
206 +              "  -H = connect to a hostapd instance to manage state changes\n"
207                "  -i = interface name\n"
208                "  -I = additional configuration file\n"
209                "  -K = include keys (passwords, etc.) in debug output\n"
210 @@ -201,7 +202,7 @@ int main(int argc, char *argv[])
211  
212         for (;;) {
213                 c = getopt(argc, argv,
214 -                          "b:Bc:C:D:de:f:g:G:hi:I:KLMm:No:O:p:P:qsTtuvW");
215 +                          "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:No:O:p:P:qsTtuvW");
216                 if (c < 0)
217                         break;
218                 switch (c) {
219 @@ -248,6 +249,9 @@ int main(int argc, char *argv[])
220                         usage();
221                         exitcode = 0;
222                         goto out;
223 +               case 'H':
224 +                       iface->hostapd_ctrl = optarg;
225 +                       break;
226                 case 'i':
227                         iface->ifname = optarg;
228                         break;
229 --- a/wpa_supplicant/bss.h
230 +++ b/wpa_supplicant/bss.h
231 @@ -80,6 +80,10 @@ struct wpa_bss {
232         u8 ssid[SSID_MAX_LEN];
233         /** Length of SSID */
234         size_t ssid_len;
235 +       /** HT capabilities */
236 +       u16 ht_capab;
237 +       /* Five octets of HT Operation Information */
238 +       u8 ht_param;
239         /** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
240         int freq;
241         /** Beacon interval in TUs (host byte order) */