df04d3d4b924bfcb640b4d3b524dfd6b4d5813e0
[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 @@ -305,6 +307,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 @@ -676,8 +725,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 @@ -2778,6 +2835,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 @@ -227,6 +228,8 @@ struct wpa_bss * wpa_bss_get(struct wpa_
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 os_time_t usec;
159
160 dst->flags = src->flags;
161 @@ -239,6 +242,12 @@ static void wpa_bss_copy_res(struct wpa_
162 dst->level = src->level;
163 dst->tsf = src->tsf;
164
165 + memset(&elems, 0, sizeof(elems));
166 + ieee802_11_parse_elems((u8 *) (src + 1), src->ie_len, &elems, 0);
167 + capab = (struct ieee80211_ht_capabilities *) elems.ht_capabilities;
168 + if (capab)
169 + dst->ht_capab = le_to_host16(capab->ht_capabilities_info);
170 +
171 dst->last_update.sec = fetch_time->sec;
172 dst->last_update.usec = fetch_time->usec;
173 dst->last_update.sec -= src->age / 1000;
174 --- a/wpa_supplicant/main.c
175 +++ b/wpa_supplicant/main.c
176 @@ -25,7 +25,7 @@ static void usage(void)
177 "usage:\n"
178 " wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
179 "[-g<global ctrl>] \\\n"
180 - " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
181 + " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-H<hostapd path>]"
182 "[-p<driver_param>] \\\n"
183 " [-b<br_ifname>] [-f<debug file>] [-e<entropy file>] "
184 "\\\n"
185 @@ -67,6 +67,7 @@ static void usage(void)
186 #endif /* CONFIG_DEBUG_LINUX_TRACING */
187 printf(" -t = include timestamp in debug messages\n"
188 " -h = show this help text\n"
189 + " -H = connect to a hostapd instance to manage state changes\n"
190 " -L = show license (BSD)\n"
191 " -o = override driver parameter for new interfaces\n"
192 " -O = override ctrl_interface parameter for new interfaces\n"
193 @@ -155,7 +156,7 @@ int main(int argc, char *argv[])
194
195 for (;;) {
196 c = getopt(argc, argv,
197 - "b:Bc:C:D:de:f:g:hi:KLNo:O:p:P:qsTtuvW");
198 + "b:Bc:C:D:de:f:g:hH:i:KLNo:O:p:P:qsTtuvW");
199 if (c < 0)
200 break;
201 switch (c) {
202 @@ -199,6 +200,9 @@ int main(int argc, char *argv[])
203 usage();
204 exitcode = 0;
205 goto out;
206 + case 'H':
207 + iface->hostapd_ctrl = optarg;
208 + break;
209 case 'i':
210 iface->ifname = optarg;
211 break;
212 --- a/wpa_supplicant/bss.h
213 +++ b/wpa_supplicant/bss.h
214 @@ -69,6 +69,8 @@ struct wpa_bss {
215 u8 ssid[32];
216 /** Length of SSID */
217 size_t ssid_len;
218 + /** HT caapbilities */
219 + u16 ht_capab;
220 /** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
221 int freq;
222 /** Beacon interval in TUs (host byte order) */