hostapd: update to latest git version
[15.05/openwrt.git] / package / network / services / hostapd / patches / 453-ap_sta_support.patch
1 --- a/wpa_supplicant/wpa_supplicant_i.h
2 +++ b/wpa_supplicant/wpa_supplicant_i.h
3 @@ -96,6 +96,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 @@ -328,6 +333,8 @@ struct wpa_supplicant {
16  #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
17         char bridge_ifname[16];
18  
19 +       struct wpa_ctrl *hostapd;
20 +
21         char *confname;
22         char *confanother;
23         struct wpa_config *conf;
24 --- a/wpa_supplicant/Makefile
25 +++ b/wpa_supplicant/Makefile
26 @@ -13,6 +13,10 @@ PKG_CONFIG ?= pkg-config
27  CFLAGS += -I../src
28  CFLAGS += -I../src/utils
29  
30 +ifdef MULTICALL
31 +CFLAGS += -DMULTICALL
32 +endif
33 +
34  -include .config
35  -include $(if $(MULTICALL),../hostapd/.config)
36  
37 @@ -76,6 +80,10 @@ OBJS_c = wpa_cli.o ../src/common/wpa_ctr
38  OBJS_c += ../src/utils/wpa_debug.o
39  OBJS_c += ../src/utils/common.o
40  
41 +ifdef MULTICALL
42 +OBJS += ../src/common/wpa_ctrl.o
43 +endif
44 +
45  ifndef CONFIG_OS
46  ifdef CONFIG_NATIVE_WINDOWS
47  CONFIG_OS=win32
48 --- a/wpa_supplicant/wpa_supplicant.c
49 +++ b/wpa_supplicant/wpa_supplicant.c
50 @@ -109,6 +109,55 @@ extern int wpa_debug_show_keys;
51  extern int wpa_debug_timestamp;
52  extern struct wpa_driver_ops *wpa_drivers[];
53  
54 +#ifdef MULTICALL
55 +static int hostapd_stop(struct wpa_supplicant *wpa_s)
56 +{
57 +       const char *cmd = "DOWN";
58 +       char buf[256];
59 +       int len = sizeof(buf);
60 +
61 +       if (wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL) < 0) {
62 +               wpa_printf(MSG_ERROR, "\nFailed to stop hostapd AP interfaces\n");
63 +               return -1;
64 +       }
65 +       return 0;
66 +}
67 +
68 +static int hostapd_reload(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
69 +{
70 +       char *cmd = NULL;
71 +       char buf[256];
72 +       int len = sizeof(buf);
73 +       int channel, hw_mode;
74 +       int ret;
75 +
76 +       if (!bss)
77 +               return;
78 +
79 +       if (bss->freq < 4000) {
80 +               hw_mode = HOSTAPD_MODE_IEEE80211G;
81 +               channel = (bss->freq - 2407) / 5;
82 +       } else {
83 +               hw_mode = HOSTAPD_MODE_IEEE80211A;
84 +               channel = (bss->freq - 5000) / 5;
85 +       }
86 +
87 +       if (asprintf(&cmd, "UPDATE channel=%d sec_chan=0 hw_mode=%d ieee80211n=%d",
88 +                    channel, hw_mode, !!bss->ht_capab) < 0) {
89 +               return -1;
90 +       }
91 +
92 +       ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
93 +       free(cmd);
94 +
95 +       if (ret < 0) {
96 +               wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
97 +               return -1;
98 +       }
99 +       return 0;
100 +}
101 +#endif
102 +
103  /* Configure default/group WEP keys for static WEP */
104  int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
105  {
106 @@ -675,8 +724,16 @@ void wpa_supplicant_set_state(struct wpa
107  #endif /* CONFIG_P2P */
108  
109                 sme_sched_obss_scan(wpa_s, 1);
110 +#ifdef MULTICALL
111 +               if (wpa_s->hostapd)
112 +                       hostapd_reload(wpa_s, wpa_s->current_bss);
113 +#endif
114         } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING ||
115                    state == WPA_ASSOCIATED) {
116 +#ifdef MULTICALL
117 +               if (wpa_s->hostapd)
118 +                       hostapd_stop(wpa_s);
119 +#endif
120                 wpa_s->new_connection = 1;
121                 wpa_drv_set_operstate(wpa_s, 0);
122  #ifndef IEEE8021X_EAPOL
123 @@ -2866,6 +2923,21 @@ static int wpa_supplicant_init_iface(str
124                 os_strlcpy(wpa_s->bridge_ifname, iface->bridge_ifname,
125                            sizeof(wpa_s->bridge_ifname));
126         }
127 +#ifdef MULTICALL
128 +       if (iface->hostapd_ctrl) {
129 +               char *cmd = "DOWN";
130 +               char buf[256];
131 +               int len = sizeof(buf);
132 +
133 +               wpa_s->hostapd = wpa_ctrl_open(iface->hostapd_ctrl);
134 +               if (!wpa_s->hostapd) {
135 +                       wpa_printf(MSG_ERROR, "\nFailed to connect to hostapd\n");
136 +                       return -1;
137 +               }
138 +               if (hostapd_stop(wpa_s) < 0)
139 +                       return -1;
140 +       }
141 +#endif
142  
143         /* RSNA Supplicant Key Management - INITIALIZE */
144         eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
145 --- a/wpa_supplicant/bss.c
146 +++ b/wpa_supplicant/bss.c
147 @@ -11,6 +11,7 @@
148  #include "utils/common.h"
149  #include "utils/eloop.h"
150  #include "common/ieee802_11_defs.h"
151 +#include "common/ieee802_11_common.h"
152  #include "drivers/driver.h"
153  #include "wpa_supplicant_i.h"
154  #include "config.h"
155 @@ -245,6 +246,9 @@ static void calculate_update_time(const 
156  static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src,
157                              struct os_time *fetch_time)
158  {
159 +       struct ieee80211_ht_capabilities *capab;
160 +       struct ieee802_11_elems elems;
161 +
162         dst->flags = src->flags;
163         os_memcpy(dst->bssid, src->bssid, ETH_ALEN);
164         dst->freq = src->freq;
165 @@ -255,6 +259,12 @@ static void wpa_bss_copy_res(struct wpa_
166         dst->level = src->level;
167         dst->tsf = src->tsf;
168  
169 +       memset(&elems, 0, sizeof(elems));
170 +       ieee802_11_parse_elems((u8 *) (src + 1), src->ie_len, &elems, 0);
171 +       capab = (struct ieee80211_ht_capabilities *) elems.ht_capabilities;
172 +       if (capab)
173 +               dst->ht_capab = le_to_host16(capab->ht_capabilities_info);
174 +
175         calculate_update_time(fetch_time, src->age, &dst->last_update);
176  }
177  
178 --- a/wpa_supplicant/main.c
179 +++ b/wpa_supplicant/main.c
180 @@ -27,7 +27,7 @@ static void usage(void)
181                "  wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
182                "[-g<global ctrl>] \\\n"
183                "        [-G<group>] \\\n"
184 -              "        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
185 +              "        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-H<hostapd path>] "
186                "[-p<driver_param>] \\\n"
187                "        [-b<br_ifname>] [-f<debug file>] [-e<entropy file>] "
188                "\\\n"
189 @@ -72,6 +72,7 @@ static void usage(void)
190  #endif /* CONFIG_DEBUG_LINUX_TRACING */
191         printf("  -t = include timestamp in debug messages\n"
192                "  -h = show this help text\n"
193 +                  "  -H = connect to a hostapd instance to manage state changes\n"
194                "  -L = show license (BSD)\n"
195                "  -o = override driver parameter for new interfaces\n"
196                "  -O = override ctrl_interface parameter for new interfaces\n"
197 @@ -160,7 +161,7 @@ int main(int argc, char *argv[])
198  
199         for (;;) {
200                 c = getopt(argc, argv,
201 -                          "b:Bc:C:D:de:f:g:G:hi:I:KLNo:O:p:P:qsTtuvW");
202 +                          "b:Bc:C:D:de:f:g:G:hH:i:I:KLNo:O:p:P:qsTtuvW");
203                 if (c < 0)
204                         break;
205                 switch (c) {
206 @@ -207,6 +208,9 @@ int main(int argc, char *argv[])
207                         usage();
208                         exitcode = 0;
209                         goto out;
210 +               case 'H':
211 +                       iface->hostapd_ctrl = optarg;
212 +                       break;
213                 case 'i':
214                         iface->ifname = optarg;
215                         break;
216 --- a/wpa_supplicant/bss.h
217 +++ b/wpa_supplicant/bss.h
218 @@ -69,6 +69,8 @@ struct wpa_bss {
219         u8 ssid[32];
220         /** Length of SSID */
221         size_t ssid_len;
222 +       /** HT caapbilities */
223 +       u16 ht_capab;
224         /** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
225         int freq;
226         /** Beacon interval in TUs (host byte order) */