hostapd: fix multi-ssid and AP+STA, clean up code
[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,48 @@ 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 +       enum hostapd_hw_mode hw_mode;
74 +       u8 channel;
75 +       int ret;
76 +
77 +       if (!bss)
78 +               return;
79 +
80 +       hw_mode = ieee80211_freq_to_chan(bss->freq, &channel);
81 +       if (asprintf(&cmd, "UPDATE channel=%d sec_chan=0 hw_mode=%d ieee80211n=%d",
82 +                    channel, hw_mode, !!bss->ht_capab) < 0)
83 +               return -1;
84 +
85 +       ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
86 +       free(cmd);
87 +
88 +       if (ret < 0) {
89 +               wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
90 +               return -1;
91 +       }
92 +       return 0;
93 +}
94 +#endif
95 +
96  /* Configure default/group WEP keys for static WEP */
97  int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
98  {
99 @@ -675,8 +717,16 @@ void wpa_supplicant_set_state(struct wpa
100  #endif /* CONFIG_P2P */
101  
102                 sme_sched_obss_scan(wpa_s, 1);
103 +#ifdef MULTICALL
104 +               if (wpa_s->hostapd)
105 +                       hostapd_reload(wpa_s, wpa_s->current_bss);
106 +#endif
107         } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING ||
108                    state == WPA_ASSOCIATED) {
109 +#ifdef MULTICALL
110 +               if (wpa_s->hostapd)
111 +                       hostapd_stop(wpa_s);
112 +#endif
113                 wpa_s->new_connection = 1;
114                 wpa_drv_set_operstate(wpa_s, 0);
115  #ifndef IEEE8021X_EAPOL
116 @@ -2866,6 +2916,21 @@ static int wpa_supplicant_init_iface(str
117                 os_strlcpy(wpa_s->bridge_ifname, iface->bridge_ifname,
118                            sizeof(wpa_s->bridge_ifname));
119         }
120 +#ifdef MULTICALL
121 +       if (iface->hostapd_ctrl) {
122 +               char *cmd = "DOWN";
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 +#endif
135  
136         /* RSNA Supplicant Key Management - INITIALIZE */
137         eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
138 --- a/wpa_supplicant/bss.c
139 +++ b/wpa_supplicant/bss.c
140 @@ -11,6 +11,7 @@
141  #include "utils/common.h"
142  #include "utils/eloop.h"
143  #include "common/ieee802_11_defs.h"
144 +#include "common/ieee802_11_common.h"
145  #include "drivers/driver.h"
146  #include "wpa_supplicant_i.h"
147  #include "config.h"
148 @@ -245,6 +246,9 @@ static void calculate_update_time(const 
149  static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src,
150                              struct os_time *fetch_time)
151  {
152 +       struct ieee80211_ht_capabilities *capab;
153 +       struct ieee802_11_elems elems;
154 +
155         dst->flags = src->flags;
156         os_memcpy(dst->bssid, src->bssid, ETH_ALEN);
157         dst->freq = src->freq;
158 @@ -255,6 +259,12 @@ static void wpa_bss_copy_res(struct wpa_
159         dst->level = src->level;
160         dst->tsf = src->tsf;
161  
162 +       memset(&elems, 0, sizeof(elems));
163 +       ieee802_11_parse_elems((u8 *) (src + 1), src->ie_len, &elems, 0);
164 +       capab = (struct ieee80211_ht_capabilities *) elems.ht_capabilities;
165 +       if (capab)
166 +               dst->ht_capab = le_to_host16(capab->ht_capabilities_info);
167 +
168         calculate_update_time(fetch_time, src->age, &dst->last_update);
169  }
170  
171 --- a/wpa_supplicant/main.c
172 +++ b/wpa_supplicant/main.c
173 @@ -27,7 +27,7 @@ static void usage(void)
174                "  wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
175                "[-g<global ctrl>] \\\n"
176                "        [-G<group>] \\\n"
177 -              "        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
178 +              "        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-H<hostapd path>] "
179                "[-p<driver_param>] \\\n"
180                "        [-b<br_ifname>] [-f<debug file>] [-e<entropy file>] "
181                "\\\n"
182 @@ -72,6 +72,7 @@ static void usage(void)
183  #endif /* CONFIG_DEBUG_LINUX_TRACING */
184         printf("  -t = include timestamp in debug messages\n"
185                "  -h = show this help text\n"
186 +                  "  -H = connect to a hostapd instance to manage state changes\n"
187                "  -L = show license (BSD)\n"
188                "  -o = override driver parameter for new interfaces\n"
189                "  -O = override ctrl_interface parameter for new interfaces\n"
190 @@ -160,7 +161,7 @@ int main(int argc, char *argv[])
191  
192         for (;;) {
193                 c = getopt(argc, argv,
194 -                          "b:Bc:C:D:de:f:g:G:hi:I:KLNo:O:p:P:qsTtuvW");
195 +                          "b:Bc:C:D:de:f:g:G:hH:i:I:KLNo:O:p:P:qsTtuvW");
196                 if (c < 0)
197                         break;
198                 switch (c) {
199 @@ -207,6 +208,9 @@ int main(int argc, char *argv[])
200                         usage();
201                         exitcode = 0;
202                         goto out;
203 +               case 'H':
204 +                       iface->hostapd_ctrl = optarg;
205 +                       break;
206                 case 'i':
207                         iface->ifname = optarg;
208                         break;
209 --- a/wpa_supplicant/bss.h
210 +++ b/wpa_supplicant/bss.h
211 @@ -69,6 +69,8 @@ struct wpa_bss {
212         u8 ssid[32];
213         /** Length of SSID */
214         size_t ssid_len;
215 +       /** HT caapbilities */
216 +       u16 ht_capab;
217         /** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
218         int freq;
219         /** Beacon interval in TUs (host byte order) */