hostapd: update to version 2016-09-05
[lede.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 @@ -100,6 +100,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 @@ -484,6 +489,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 @@ -114,6 +118,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 @@ -112,6 +112,55 @@ const char *const wpa_supplicant_full_li
49  "\n";
50  #endif /* CONFIG_NO_STDOUT_DEBUG */
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 @@ -812,8 +861,12 @@ void wpa_supplicant_set_state(struct wpa
105                 wpas_p2p_completed(wpa_s);
106  
107                 sme_sched_obss_scan(wpa_s, 1);
108 +               if (wpa_s->hostapd)
109 +                       hostapd_reload(wpa_s, wpa_s->current_bss);
110         } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING ||
111                    state == WPA_ASSOCIATED) {
112 +               if (wpa_s->hostapd)
113 +                       hostapd_stop(wpa_s);
114                 wpa_s->new_connection = 1;
115                 wpa_drv_set_operstate(wpa_s, 0);
116  #ifndef IEEE8021X_EAPOL
117 @@ -4748,6 +4801,20 @@ static int wpa_supplicant_init_iface(str
118                            sizeof(wpa_s->bridge_ifname));
119         }
120  
121 +       if (iface->hostapd_ctrl) {
122 +               char *cmd = "STOP_AP";
123 +               char buf[256];
124 +               int len = sizeof(buf);
125 +
126 +               wpa_s->hostapd = wpa_ctrl_open(iface->hostapd_ctrl);
127 +               if (!wpa_s->hostapd) {
128 +                       wpa_printf(MSG_ERROR, "\nFailed to connect to hostapd\n");
129 +                       return -1;
130 +               }
131 +               if (hostapd_stop(wpa_s) < 0)
132 +                       return -1;
133 +       }
134 +
135         /* RSNA Supplicant Key Management - INITIALIZE */
136         eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
137         eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
138 @@ -5041,6 +5108,11 @@ static void wpa_supplicant_deinit_iface(
139         if (terminate)
140                 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING);
141  
142 +       if (wpa_s->hostapd) {
143 +               wpa_ctrl_close(wpa_s->hostapd);
144 +               wpa_s->hostapd = NULL;
145 +       }
146 +
147         if (wpa_s->ctrl_iface) {
148                 wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
149                 wpa_s->ctrl_iface = NULL;
150 --- a/wpa_supplicant/bss.c
151 +++ b/wpa_supplicant/bss.c
152 @@ -11,6 +11,7 @@
153  #include "utils/common.h"
154  #include "utils/eloop.h"
155  #include "common/ieee802_11_defs.h"
156 +#include "common/ieee802_11_common.h"
157  #include "drivers/driver.h"
158  #include "eap_peer/eap.h"
159  #include "wpa_supplicant_i.h"
160 @@ -288,6 +289,10 @@ static void calculate_update_time(const
161  static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src,
162                              struct os_reltime *fetch_time)
163  {
164 +       struct ieee80211_ht_capabilities *capab;
165 +       struct ieee80211_ht_operation *oper;
166 +       struct ieee802_11_elems elems;
167 +
168         dst->flags = src->flags;
169         os_memcpy(dst->bssid, src->bssid, ETH_ALEN);
170         dst->freq = src->freq;
171 @@ -300,6 +305,15 @@ static void wpa_bss_copy_res(struct wpa_
172         dst->est_throughput = src->est_throughput;
173         dst->snr = src->snr;
174  
175 +       memset(&elems, 0, sizeof(elems));
176 +       ieee802_11_parse_elems((u8 *) (src + 1), src->ie_len, &elems, 0);
177 +       capab = (struct ieee80211_ht_capabilities *) elems.ht_capabilities;
178 +       oper = (struct ieee80211_ht_operation *) elems.ht_operation;
179 +       if (capab)
180 +               dst->ht_capab = le_to_host16(capab->ht_capabilities_info);
181 +       if (oper)
182 +               dst->ht_param = oper->ht_param;
183 +
184         calculate_update_time(fetch_time, src->age, &dst->last_update);
185  }
186  
187 --- a/wpa_supplicant/main.c
188 +++ b/wpa_supplicant/main.c
189 @@ -34,7 +34,7 @@ static void usage(void)
190                "vW] [-P<pid file>] "
191                "[-g<global ctrl>] \\\n"
192                "        [-G<group>] \\\n"
193 -              "        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
194 +              "        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-H<hostapd path>] "
195                "[-p<driver_param>] \\\n"
196                "        [-b<br_ifname>] [-e<entropy file>]"
197  #ifdef CONFIG_DEBUG_FILE
198 @@ -74,6 +74,7 @@ static void usage(void)
199                "  -g = global ctrl_interface\n"
200                "  -G = global ctrl_interface group\n"
201                "  -h = show this help text\n"
202 +              "  -H = connect to a hostapd instance to manage state changes\n"
203                "  -i = interface name\n"
204                "  -I = additional configuration file\n"
205                "  -K = include keys (passwords, etc.) in debug output\n"
206 @@ -201,7 +202,7 @@ int main(int argc, char *argv[])
207  
208         for (;;) {
209                 c = getopt(argc, argv,
210 -                          "b:Bc:C:D:de:f:g:G:hi:I:KLMm:No:O:p:P:qsTtuvW");
211 +                          "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:No:O:p:P:qsTtuvW");
212                 if (c < 0)
213                         break;
214                 switch (c) {
215 @@ -248,6 +249,9 @@ int main(int argc, char *argv[])
216                         usage();
217                         exitcode = 0;
218                         goto out;
219 +               case 'H':
220 +                       iface->hostapd_ctrl = optarg;
221 +                       break;
222                 case 'i':
223                         iface->ifname = optarg;
224                         break;
225 --- a/wpa_supplicant/bss.h
226 +++ b/wpa_supplicant/bss.h
227 @@ -79,6 +79,10 @@ struct wpa_bss {
228         u8 ssid[SSID_MAX_LEN];
229         /** Length of SSID */
230         size_t ssid_len;
231 +       /** HT capabilities */
232 +       u16 ht_capab;
233 +       /* Five octets of HT Operation Information */
234 +       u8 ht_param;
235         /** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
236         int freq;
237         /** Beacon interval in TUs (host byte order) */