1
0

370-ap_sta_support.patch 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. --- a/wpa_supplicant/wpa_supplicant_i.h
  2. +++ b/wpa_supplicant/wpa_supplicant_i.h
  3. @@ -100,6 +100,11 @@ struct wpa_interface {
  4. const char *ifname;
  5. /**
  6. + * hostapd_ctrl - path to hostapd control socket for notification
  7. + */
  8. + const char *hostapd_ctrl;
  9. +
  10. + /**
  11. * bridge_ifname - Optional bridge interface name
  12. *
  13. * If the driver interface (ifname) is included in a Linux bridge
  14. @@ -484,6 +489,8 @@ struct wpa_supplicant {
  15. #endif /* CONFIG_CTRL_IFACE_BINDER */
  16. char bridge_ifname[16];
  17. + struct wpa_ctrl *hostapd;
  18. +
  19. char *confname;
  20. char *confanother;
  21. --- a/wpa_supplicant/Makefile
  22. +++ b/wpa_supplicant/Makefile
  23. @@ -26,6 +26,10 @@ CFLAGS += $(EXTRA_CFLAGS)
  24. CFLAGS += -I$(abspath ../src)
  25. CFLAGS += -I$(abspath ../src/utils)
  26. +ifdef MULTICALL
  27. +CFLAGS += -DMULTICALL
  28. +endif
  29. +
  30. -include .config
  31. -include $(if $(MULTICALL),../hostapd/.config)
  32. @@ -115,6 +119,8 @@ OBJS_c += ../src/utils/common.o
  33. OBJS_c += ../src/common/cli.o
  34. OBJS += wmm_ac.o
  35. +OBJS += ../src/common/wpa_ctrl.o
  36. +
  37. ifndef CONFIG_OS
  38. ifdef CONFIG_NATIVE_WINDOWS
  39. CONFIG_OS=win32
  40. --- a/wpa_supplicant/wpa_supplicant.c
  41. +++ b/wpa_supplicant/wpa_supplicant.c
  42. @@ -112,6 +112,55 @@ const char *const wpa_supplicant_full_li
  43. "\n";
  44. #endif /* CONFIG_NO_STDOUT_DEBUG */
  45. +static int hostapd_stop(struct wpa_supplicant *wpa_s)
  46. +{
  47. + const char *cmd = "STOP_AP";
  48. + char buf[256];
  49. + size_t len = sizeof(buf);
  50. +
  51. + if (wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL) < 0) {
  52. + wpa_printf(MSG_ERROR, "\nFailed to stop hostapd AP interfaces\n");
  53. + return -1;
  54. + }
  55. + return 0;
  56. +}
  57. +
  58. +static int hostapd_reload(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
  59. +{
  60. + char *cmd = NULL;
  61. + char buf[256];
  62. + size_t len = sizeof(buf);
  63. + enum hostapd_hw_mode hw_mode;
  64. + u8 channel;
  65. + int sec_chan = 0;
  66. + int ret;
  67. +
  68. + if (!bss)
  69. + return -1;
  70. +
  71. + if (bss->ht_param & HT_INFO_HT_PARAM_STA_CHNL_WIDTH) {
  72. + int sec = bss->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
  73. + if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
  74. + sec_chan = 1;
  75. + else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
  76. + sec_chan = -1;
  77. + }
  78. +
  79. + hw_mode = ieee80211_freq_to_chan(bss->freq, &channel);
  80. + if (asprintf(&cmd, "UPDATE channel=%d sec_chan=%d hw_mode=%d",
  81. + channel, sec_chan, hw_mode) < 0)
  82. + return -1;
  83. +
  84. + ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
  85. + free(cmd);
  86. +
  87. + if (ret < 0) {
  88. + wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
  89. + return -1;
  90. + }
  91. + return 0;
  92. +}
  93. +
  94. /* Configure default/group WEP keys for static WEP */
  95. int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
  96. {
  97. @@ -819,8 +868,12 @@ void wpa_supplicant_set_state(struct wpa
  98. wpas_p2p_completed(wpa_s);
  99. sme_sched_obss_scan(wpa_s, 1);
  100. + if (wpa_s->hostapd)
  101. + hostapd_reload(wpa_s, wpa_s->current_bss);
  102. } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING ||
  103. state == WPA_ASSOCIATED) {
  104. + if (wpa_s->hostapd)
  105. + hostapd_stop(wpa_s);
  106. wpa_s->new_connection = 1;
  107. wpa_drv_set_operstate(wpa_s, 0);
  108. #ifndef IEEE8021X_EAPOL
  109. @@ -4790,6 +4843,20 @@ static int wpa_supplicant_init_iface(str
  110. sizeof(wpa_s->bridge_ifname));
  111. }
  112. + if (iface->hostapd_ctrl) {
  113. + char *cmd = "STOP_AP";
  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. @@ -5083,6 +5150,11 @@ static void wpa_supplicant_deinit_iface(
  130. if (terminate)
  131. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING);
  132. + if (wpa_s->hostapd) {
  133. + wpa_ctrl_close(wpa_s->hostapd);
  134. + wpa_s->hostapd = NULL;
  135. + }
  136. +
  137. if (wpa_s->ctrl_iface) {
  138. wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
  139. wpa_s->ctrl_iface = NULL;
  140. --- a/wpa_supplicant/bss.c
  141. +++ b/wpa_supplicant/bss.c
  142. @@ -11,6 +11,7 @@
  143. #include "utils/common.h"
  144. #include "utils/eloop.h"
  145. #include "common/ieee802_11_defs.h"
  146. +#include "common/ieee802_11_common.h"
  147. #include "drivers/driver.h"
  148. #include "eap_peer/eap.h"
  149. #include "wpa_supplicant_i.h"
  150. @@ -290,6 +291,10 @@ static void calculate_update_time(const
  151. static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src,
  152. struct os_reltime *fetch_time)
  153. {
  154. + struct ieee80211_ht_capabilities *capab;
  155. + struct ieee80211_ht_operation *oper;
  156. + struct ieee802_11_elems elems;
  157. +
  158. dst->flags = src->flags;
  159. os_memcpy(dst->bssid, src->bssid, ETH_ALEN);
  160. dst->freq = src->freq;
  161. @@ -302,6 +307,15 @@ static void wpa_bss_copy_res(struct wpa_
  162. dst->est_throughput = src->est_throughput;
  163. dst->snr = src->snr;
  164. + memset(&elems, 0, sizeof(elems));
  165. + ieee802_11_parse_elems((u8 *) (src + 1), src->ie_len, &elems, 0);
  166. + capab = (struct ieee80211_ht_capabilities *) elems.ht_capabilities;
  167. + oper = (struct ieee80211_ht_operation *) elems.ht_operation;
  168. + if (capab)
  169. + dst->ht_capab = le_to_host16(capab->ht_capabilities_info);
  170. + if (oper)
  171. + dst->ht_param = oper->ht_param;
  172. +
  173. calculate_update_time(fetch_time, src->age, &dst->last_update);
  174. }
  175. --- a/wpa_supplicant/main.c
  176. +++ b/wpa_supplicant/main.c
  177. @@ -34,7 +34,7 @@ static void usage(void)
  178. "vW] [-P<pid file>] "
  179. "[-g<global ctrl>] \\\n"
  180. " [-G<group>] \\\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>] [-e<entropy file>]"
  185. #ifdef CONFIG_DEBUG_FILE
  186. @@ -74,6 +74,7 @@ static void usage(void)
  187. " -g = global ctrl_interface\n"
  188. " -G = global ctrl_interface group\n"
  189. " -h = show this help text\n"
  190. + " -H = connect to a hostapd instance to manage state changes\n"
  191. " -i = interface name\n"
  192. " -I = additional configuration file\n"
  193. " -K = include keys (passwords, etc.) in debug output\n"
  194. @@ -201,7 +202,7 @@ int main(int argc, char *argv[])
  195. for (;;) {
  196. c = getopt(argc, argv,
  197. - "b:Bc:C:D:de:f:g:G:hi:I:KLMm:No:O:p:P:qsTtuvW");
  198. + "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:No:O:p:P:qsTtuvW");
  199. if (c < 0)
  200. break;
  201. switch (c) {
  202. @@ -248,6 +249,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. @@ -80,6 +80,10 @@ struct wpa_bss {
  215. u8 ssid[SSID_MAX_LEN];
  216. /** Length of SSID */
  217. size_t ssid_len;
  218. + /** HT capabilities */
  219. + u16 ht_capab;
  220. + /* Five octets of HT Operation Information */
  221. + u8 ht_param;
  222. /** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
  223. int freq;
  224. /** Beacon interval in TUs (host byte order) */