d4b6c1da04dfab4d7745e26ba8987f086734bc75
[openwrt/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,8 @@ 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 +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 @@ -109,6 +109,46 @@ extern int wpa_debug_show_keys;
49 extern int wpa_debug_timestamp;
50 extern struct wpa_driver_ops *wpa_drivers[];
51
52 +static int hostapd_stop(struct wpa_supplicant *wpa_s)
53 +{
54 + const char *cmd = "DOWN";
55 + char buf[256];
56 + int 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 + int len = sizeof(buf);
70 + enum hostapd_hw_mode hw_mode;
71 + u8 channel;
72 + int ret;
73 +
74 + if (!bss)
75 + return;
76 +
77 + hw_mode = ieee80211_freq_to_chan(bss->freq, &channel);
78 + if (asprintf(&cmd, "UPDATE channel=%d sec_chan=0 hw_mode=%d ieee80211n=%d",
79 + channel, hw_mode, !!bss->ht_capab) < 0)
80 + return -1;
81 +
82 + ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
83 + free(cmd);
84 +
85 + if (ret < 0) {
86 + wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
87 + return -1;
88 + }
89 + return 0;
90 +}
91 +
92 /* Configure default/group WEP keys for static WEP */
93 int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
94 {
95 @@ -676,8 +716,12 @@ void wpa_supplicant_set_state(struct wpa
96 #endif /* CONFIG_P2P */
97
98 sme_sched_obss_scan(wpa_s, 1);
99 + if (wpa_s->hostapd)
100 + hostapd_reload(wpa_s, wpa_s->current_bss);
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 @@ -2875,6 +2919,20 @@ static int wpa_supplicant_init_iface(str
109 sizeof(wpa_s->bridge_ifname));
110 }
111
112 + if (iface->hostapd_ctrl) {
113 + char *cmd = "DOWN";
114 + char buf[256];
115 + int len = sizeof(buf);
116 +
117 + wpa_s->hostapd = wpa_ctrl_open(iface->hostapd_ctrl);
118 + if (!wpa_s->hostapd) {
119 + wpa_printf(MSG_ERROR, "\nFailed to connect to hostapd\n");
120 + return -1;
121 + }
122 + if (hostapd_stop(wpa_s) < 0)
123 + return -1;
124 + }
125 +
126 /* RSNA Supplicant Key Management - INITIALIZE */
127 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
128 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
129 --- a/wpa_supplicant/bss.c
130 +++ b/wpa_supplicant/bss.c
131 @@ -11,6 +11,7 @@
132 #include "utils/common.h"
133 #include "utils/eloop.h"
134 #include "common/ieee802_11_defs.h"
135 +#include "common/ieee802_11_common.h"
136 #include "drivers/driver.h"
137 #include "wpa_supplicant_i.h"
138 #include "config.h"
139 @@ -245,6 +246,9 @@ static void calculate_update_time(const
140 static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src,
141 struct os_time *fetch_time)
142 {
143 + struct ieee80211_ht_capabilities *capab;
144 + struct ieee802_11_elems elems;
145 +
146 dst->flags = src->flags;
147 os_memcpy(dst->bssid, src->bssid, ETH_ALEN);
148 dst->freq = src->freq;
149 @@ -255,6 +259,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 calculate_update_time(fetch_time, src->age, &dst->last_update);
160 }
161
162 --- a/wpa_supplicant/main.c
163 +++ b/wpa_supplicant/main.c
164 @@ -27,7 +27,7 @@ static void usage(void)
165 " wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
166 "[-g<global ctrl>] \\\n"
167 " [-G<group>] \\\n"
168 - " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
169 + " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-H<hostapd path>] "
170 "[-p<driver_param>] \\\n"
171 " [-b<br_ifname>] [-f<debug file>] [-e<entropy file>] "
172 "\\\n"
173 @@ -72,6 +72,7 @@ static void usage(void)
174 #endif /* CONFIG_DEBUG_LINUX_TRACING */
175 printf(" -t = include timestamp in debug messages\n"
176 " -h = show this help text\n"
177 + " -H = connect to a hostapd instance to manage state changes\n"
178 " -L = show license (BSD)\n"
179 " -o = override driver parameter for new interfaces\n"
180 " -O = override ctrl_interface parameter for new interfaces\n"
181 @@ -160,7 +161,7 @@ int main(int argc, char *argv[])
182
183 for (;;) {
184 c = getopt(argc, argv,
185 - "b:Bc:C:D:de:f:g:G:hi:I:KLNo:O:p:P:qsTtuvW");
186 + "b:Bc:C:D:de:f:g:G:hH:i:I:KLNo:O:p:P:qsTtuvW");
187 if (c < 0)
188 break;
189 switch (c) {
190 @@ -207,6 +208,9 @@ int main(int argc, char *argv[])
191 usage();
192 exitcode = 0;
193 goto out;
194 + case 'H':
195 + iface->hostapd_ctrl = optarg;
196 + break;
197 case 'i':
198 iface->ifname = optarg;
199 break;
200 --- a/wpa_supplicant/bss.h
201 +++ b/wpa_supplicant/bss.h
202 @@ -69,6 +69,8 @@ struct wpa_bss {
203 u8 ssid[32];
204 /** Length of SSID */
205 size_t ssid_len;
206 + /** HT caapbilities */
207 + u16 ht_capab;
208 /** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
209 int freq;
210 /** Beacon interval in TUs (host byte order) */