hostapd: fix AP+STA reconnects
[openwrt.git] / package / hostapd / patches / 453-ap_sta_support.patch
1 --- a/wpa_supplicant/wpa_supplicant_i.h
2 +++ b/wpa_supplicant/wpa_supplicant_i.h
3 @@ -98,6 +98,8 @@ struct wpa_interface {
4          * receiving of EAPOL frames from an additional interface.
5          */
6         const char *bridge_ifname;
7 +
8 +       const char *hostapd_ctrl;
9  };
10  
11  /**
12 @@ -316,6 +318,8 @@ struct wpa_supplicant {
13  #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
14         char bridge_ifname[16];
15  
16 +       struct wpa_ctrl *hostapd;
17 +
18         char *confname;
19         struct wpa_config *conf;
20         int countermeasures;
21 --- a/wpa_supplicant/Makefile
22 +++ b/wpa_supplicant/Makefile
23 @@ -51,6 +51,11 @@ OBJS_p += ../src/utils/wpa_debug.o
24  OBJS_p += ../src/utils/wpabuf.o
25  OBJS_c = wpa_cli.o ../src/common/wpa_ctrl.o
26  
27 +ifdef MULTICALL
28 +OBJS += ../src/common/wpa_ctrl.o
29 +CFLAGS += -DMULTICALL
30 +endif
31 +
32  -include .config
33  -include $(if $(MULTICALL),../hostapd/.config)
34  
35 --- a/wpa_supplicant/wpa_supplicant.c
36 +++ b/wpa_supplicant/wpa_supplicant.c
37 @@ -120,6 +120,55 @@ extern int wpa_debug_show_keys;
38  extern int wpa_debug_timestamp;
39  extern struct wpa_driver_ops *wpa_drivers[];
40  
41 +#ifdef MULTICALL
42 +static int hostapd_stop(struct wpa_supplicant *wpa_s)
43 +{
44 +       const char *cmd = "DOWN";
45 +       char buf[256];
46 +       int len = sizeof(buf);
47 +
48 +       if (wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL) < 0) {
49 +               wpa_printf(MSG_ERROR, "\nFailed to stop hostapd AP interfaces\n");
50 +               return -1;
51 +       }
52 +       return 0;
53 +}
54 +
55 +static int hostapd_reload(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
56 +{
57 +       char *cmd = NULL;
58 +       char buf[256];
59 +       int len = sizeof(buf);
60 +       int channel, hw_mode;
61 +       int ret;
62 +
63 +       if (!bss)
64 +               return;
65 +
66 +       if (bss->freq < 4000) {
67 +               hw_mode = HOSTAPD_MODE_IEEE80211G;
68 +               channel = (bss->freq - 2407) / 5;
69 +       } else {
70 +               hw_mode = HOSTAPD_MODE_IEEE80211A;
71 +               channel = (bss->freq - 5000) / 5;
72 +       }
73 +
74 +       if (asprintf(&cmd, "RELOAD channel=%d sec_chan=0 hw_mode=%d ht_capab_mask=%d ieee80211n=%d",
75 +                    channel, hw_mode, bss->ht_capab, !!bss->ht_capab) < 0) {
76 +               return -1;
77 +       }
78 +
79 +       ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
80 +       free(cmd);
81 +
82 +       if (ret < 0) {
83 +               wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
84 +               return -1;
85 +       }
86 +       return 0;
87 +}
88 +#endif
89 +
90  /* Configure default/group WEP keys for static WEP */
91  int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
92  {
93 @@ -548,8 +597,14 @@ void wpa_supplicant_set_state(struct wpa
94  #ifndef IEEE8021X_EAPOL
95                 wpa_drv_set_supp_port(wpa_s, 1);
96  #endif
97 +#ifdef MULTICALL
98 +               if (wpa_s->hostapd)
99 +                       hostapd_reload(wpa_s, wpa_s->current_bss);
100 +#endif
101         } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING ||
102                    state == WPA_ASSOCIATED) {
103 +               if (wpa_s->hostapd)
104 +                       hostapd_stop(wpa_s);
105                 wpa_s->new_connection = 1;
106                 wpa_drv_set_operstate(wpa_s, 0);
107  #ifndef IEEE8021X_EAPOL
108 @@ -1957,6 +2012,21 @@ static int wpa_supplicant_init_iface(str
109                 os_strlcpy(wpa_s->bridge_ifname, iface->bridge_ifname,
110                            sizeof(wpa_s->bridge_ifname));
111         }
112 +#ifdef MULTICALL
113 +       if (iface->hostapd_ctrl) {
114 +               char *cmd = "DOWN";
115 +               char buf[256];
116 +               int len = sizeof(buf);
117 +
118 +               wpa_s->hostapd = wpa_ctrl_open(iface->hostapd_ctrl);
119 +               if (!wpa_s->hostapd) {
120 +                       wpa_printf(MSG_ERROR, "\nFailed to connect to hostapd\n");
121 +                       return -1;
122 +               }
123 +               if (hostapd_stop(wpa_s) < 0)
124 +                       return -1;
125 +       }
126 +#endif
127  
128         /* RSNA Supplicant Key Management - INITIALIZE */
129         eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
130 --- a/wpa_supplicant/bss.c
131 +++ b/wpa_supplicant/bss.c
132 @@ -17,6 +17,7 @@
133  #include "utils/common.h"
134  #include "utils/eloop.h"
135  #include "common/ieee802_11_defs.h"
136 +#include "common/ieee802_11_common.h"
137  #include "drivers/driver.h"
138  #include "wpa_supplicant_i.h"
139  #include "config.h"
140 @@ -89,6 +90,8 @@ struct wpa_bss * wpa_bss_get(struct wpa_
141  
142  static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src)
143  {
144 +       struct ieee80211_ht_capabilities *capab;
145 +       struct ieee802_11_elems elems;
146         os_time_t usec;
147  
148         dst->flags = src->flags;
149 @@ -101,6 +104,12 @@ static void wpa_bss_copy_res(struct wpa_
150         dst->level = src->level;
151         dst->tsf = src->tsf;
152  
153 +       memset(&elems, 0, sizeof(elems));
154 +       ieee802_11_parse_elems((u8 *) (src + 1), src->ie_len, &elems, 0);
155 +       capab = (struct ieee80211_ht_capabilities *) elems.ht_capabilities;
156 +       if (capab)
157 +               dst->ht_capab = le_to_host16(capab->ht_capabilities_info);
158 +
159         os_get_time(&dst->last_update);
160         dst->last_update.sec -= src->age / 1000;
161         usec = (src->age % 1000) * 1000;
162 --- a/wpa_supplicant/bss.h
163 +++ b/wpa_supplicant/bss.h
164 @@ -56,6 +56,7 @@ struct wpa_bss {
165         unsigned int flags;
166         u8 bssid[ETH_ALEN];
167         u8 ssid[32];
168 +       u16 ht_capab;
169         size_t ssid_len;
170         int freq;
171         u16 beacon_int;
172 --- a/wpa_supplicant/main.c
173 +++ b/wpa_supplicant/main.c
174 @@ -31,7 +31,7 @@ static void usage(void)
175                "usage:\n"
176                "  wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
177                "[-g<global ctrl>] \\\n"
178 -              "        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
179 +              "        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-H<hostapd path>]"
180                "[-p<driver_param>] \\\n"
181                "        [-b<br_ifname>] [-f<debug file>] \\\n"
182                "        [-o<override driver>] [-O<override ctrl>] \\\n"
183 @@ -67,6 +67,7 @@ static void usage(void)
184  #endif /* CONFIG_DEBUG_SYSLOG */
185         printf("  -t = include timestamp in debug messages\n"
186                "  -h = show this help text\n"
187 +                  "  -H = connect to a hostapd instance to manage state changes\n"
188                "  -L = show license (GPL and BSD)\n"
189                "  -o = override driver parameter for new interfaces\n"
190                "  -O = override ctrl_interface parameter for new interfaces\n"
191 @@ -143,7 +144,7 @@ int main(int argc, char *argv[])
192         wpa_supplicant_fd_workaround();
193  
194         for (;;) {
195 -               c = getopt(argc, argv, "b:Bc:C:D:df:g:hi:KLNo:O:p:P:qstuvW");
196 +               c = getopt(argc, argv, "b:Bc:C:D:df:g:hH:i:KLNo:O:p:P:qstuvW");
197                 if (c < 0)
198                         break;
199                 switch (c) {
200 @@ -184,6 +185,9 @@ int main(int argc, char *argv[])
201                         usage();
202                         exitcode = 0;
203                         goto out;
204 +               case 'H':
205 +                       iface->hostapd_ctrl = optarg;
206 +                       break;
207                 case 'i':
208                         iface->ifname = optarg;
209                         break;