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