2
0

600-ubus_support.patch 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. From: Felix Fietkau <[email protected]>
  2. Date: Sun, 17 Mar 2013 20:47:18 +0000
  3. Subject: [PATCH] hostapd: initial prototype of an ubus binding
  4. Supports listing, removing and banning clients, and hooking into
  5. probe/assoc/auth requests via object subscribe.
  6. --- a/hostapd/Makefile
  7. +++ b/hostapd/Makefile
  8. @@ -166,6 +166,12 @@ OBJS += ../src/common/hw_features_common
  9. OBJS += ../src/eapol_auth/eapol_auth_sm.o
  10. +ifdef CONFIG_UBUS
  11. +CFLAGS += -DUBUS_SUPPORT
  12. +OBJS += ../src/utils/uloop.o
  13. +OBJS += ../src/ap/ubus.o
  14. +LIBS += -lubox -lubus
  15. +endif
  16. ifdef CONFIG_CODE_COVERAGE
  17. CFLAGS += -O0 -fprofile-arcs -ftest-coverage -U_FORTIFY_SOURCE
  18. --- a/src/ap/airtime_policy.c
  19. +++ b/src/ap/airtime_policy.c
  20. @@ -112,8 +112,14 @@ static void set_sta_weights(struct hosta
  21. {
  22. struct sta_info *sta;
  23. - for (sta = hapd->sta_list; sta; sta = sta->next)
  24. - sta_set_airtime_weight(hapd, sta, weight);
  25. + for (sta = hapd->sta_list; sta; sta = sta->next) {
  26. + unsigned int sta_weight = weight;
  27. +
  28. + if (sta->dyn_airtime_weight)
  29. + sta_weight = (weight * sta->dyn_airtime_weight) / 256;
  30. +
  31. + sta_set_airtime_weight(hapd, sta, sta_weight);
  32. + }
  33. }
  34. @@ -244,7 +250,10 @@ int airtime_policy_new_sta(struct hostap
  35. unsigned int weight;
  36. if (hapd->iconf->airtime_mode == AIRTIME_MODE_STATIC) {
  37. - weight = get_weight_for_sta(hapd, sta->addr);
  38. + if (sta->dyn_airtime_weight)
  39. + weight = sta->dyn_airtime_weight;
  40. + else
  41. + weight = get_weight_for_sta(hapd, sta->addr);
  42. if (weight)
  43. return sta_set_airtime_weight(hapd, sta, weight);
  44. }
  45. --- a/src/ap/beacon.c
  46. +++ b/src/ap/beacon.c
  47. @@ -1351,6 +1351,12 @@ void handle_probe_req(struct hostapd_dat
  48. int mld_id;
  49. u16 links;
  50. #endif /* CONFIG_IEEE80211BE */
  51. + struct hostapd_ubus_request req = {
  52. + .type = HOSTAPD_UBUS_PROBE_REQ,
  53. + .mgmt_frame = mgmt,
  54. + .ssi_signal = ssi_signal,
  55. + .elems = &elems,
  56. + };
  57. if (hapd->iconf->rssi_ignore_probe_request && ssi_signal &&
  58. ssi_signal < hapd->iconf->rssi_ignore_probe_request)
  59. @@ -1537,6 +1543,12 @@ void handle_probe_req(struct hostapd_dat
  60. }
  61. #endif /* CONFIG_P2P */
  62. + if (hostapd_ubus_handle_event(hapd, &req)) {
  63. + wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
  64. + MAC2STR(mgmt->sa));
  65. + return;
  66. + }
  67. +
  68. /* TODO: verify that supp_rates contains at least one matching rate
  69. * with AP configuration */
  70. --- a/src/ap/dfs.c
  71. +++ b/src/ap/dfs.c
  72. @@ -1225,6 +1225,8 @@ int hostapd_dfs_pre_cac_expired(struct h
  73. "freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d",
  74. freq, ht_enabled, chan_offset, chan_width, cf1, cf2);
  75. + hostapd_ubus_notify_radar_detected(iface, freq, chan_width, cf1, cf2);
  76. +
  77. /* Proceed only if DFS is not offloaded to the driver */
  78. if (iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
  79. return 0;
  80. --- a/src/ap/drv_callbacks.c
  81. +++ b/src/ap/drv_callbacks.c
  82. @@ -268,6 +268,10 @@ int hostapd_notif_assoc(struct hostapd_d
  83. struct hostapd_iface *iface = hapd->iface;
  84. #endif /* CONFIG_OWE */
  85. bool updated = false;
  86. + struct hostapd_ubus_request req = {
  87. + .type = HOSTAPD_UBUS_ASSOC_REQ,
  88. + .addr = addr,
  89. + };
  90. if (addr == NULL) {
  91. /*
  92. @@ -412,6 +416,12 @@ int hostapd_notif_assoc(struct hostapd_d
  93. goto fail;
  94. }
  95. + if (hostapd_ubus_handle_event(hapd, &req)) {
  96. + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
  97. + MAC2STR(req.addr));
  98. + goto fail;
  99. + }
  100. +
  101. #ifdef CONFIG_P2P
  102. if (elems.p2p) {
  103. wpabuf_free(sta->p2p_ie);
  104. --- a/src/ap/hostapd.c
  105. +++ b/src/ap/hostapd.c
  106. @@ -493,6 +493,7 @@ void hostapd_free_hapd_data(struct hosta
  107. hapd->beacon_set_done = 0;
  108. wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
  109. + hostapd_ubus_free_bss(hapd);
  110. accounting_deinit(hapd);
  111. hostapd_deinit_wpa(hapd);
  112. vlan_deinit(hapd);
  113. @@ -1274,6 +1275,8 @@ static int hostapd_start_beacon(struct h
  114. if (hapd->driver && hapd->driver->set_operstate)
  115. hapd->driver->set_operstate(hapd->drv_priv, 1);
  116. + hostapd_ubus_add_bss(hapd);
  117. +
  118. return 0;
  119. }
  120. @@ -2367,6 +2370,7 @@ static int hostapd_setup_interface_compl
  121. if (err)
  122. goto fail;
  123. + hostapd_ubus_add_iface(iface);
  124. wpa_printf(MSG_DEBUG, "Completing interface initialization");
  125. if (iface->freq) {
  126. #ifdef NEED_AP_MLME
  127. @@ -2586,6 +2590,7 @@ dfs_offload:
  128. fail:
  129. wpa_printf(MSG_ERROR, "Interface initialization failed");
  130. + hostapd_ubus_free_iface(iface);
  131. if (iface->is_no_ir) {
  132. hostapd_set_state(iface, HAPD_IFACE_NO_IR);
  133. @@ -3076,6 +3081,7 @@ void hostapd_interface_deinit_free(struc
  134. (unsigned int) iface->conf->num_bss);
  135. driver = iface->bss[0]->driver;
  136. drv_priv = iface->bss[0]->drv_priv;
  137. + hostapd_ubus_free_iface(iface);
  138. hostapd_interface_deinit(iface);
  139. wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
  140. __func__, driver, drv_priv);
  141. --- a/src/ap/hostapd.h
  142. +++ b/src/ap/hostapd.h
  143. @@ -18,6 +18,7 @@
  144. #include "utils/list.h"
  145. #include "ap_config.h"
  146. #include "drivers/driver.h"
  147. +#include "ubus.h"
  148. #define OCE_STA_CFON_ENABLED(hapd) \
  149. ((hapd->conf->oce & OCE_STA_CFON) && \
  150. @@ -184,6 +185,7 @@ struct hostapd_data {
  151. struct hostapd_iface *iface;
  152. struct hostapd_config *iconf;
  153. struct hostapd_bss_config *conf;
  154. + struct hostapd_ubus_bss ubus;
  155. int interface_added; /* virtual interface added for this BSS */
  156. unsigned int started:1;
  157. unsigned int disabled:1;
  158. @@ -707,6 +709,7 @@ hostapd_alloc_bss_data(struct hostapd_if
  159. struct hostapd_bss_config *bss);
  160. int hostapd_setup_interface(struct hostapd_iface *iface);
  161. int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
  162. +void hostapd_set_own_neighbor_report(struct hostapd_data *hapd);
  163. void hostapd_interface_deinit(struct hostapd_iface *iface);
  164. void hostapd_interface_free(struct hostapd_iface *iface);
  165. struct hostapd_iface * hostapd_alloc_iface(void);
  166. --- a/src/ap/ieee802_11.c
  167. +++ b/src/ap/ieee802_11.c
  168. @@ -2798,7 +2798,7 @@ static void handle_auth(struct hostapd_d
  169. u16 auth_alg, auth_transaction, status_code;
  170. u16 resp = WLAN_STATUS_SUCCESS;
  171. struct sta_info *sta = NULL;
  172. - int res, reply_res;
  173. + int res, reply_res, ubus_resp;
  174. u16 fc;
  175. const u8 *challenge = NULL;
  176. u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
  177. @@ -2807,6 +2807,11 @@ static void handle_auth(struct hostapd_d
  178. struct radius_sta rad_info;
  179. const u8 *dst, *sa, *bssid;
  180. bool mld_sta = false;
  181. + struct hostapd_ubus_request req = {
  182. + .type = HOSTAPD_UBUS_AUTH_REQ,
  183. + .mgmt_frame = mgmt,
  184. + .ssi_signal = rssi,
  185. + };
  186. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
  187. wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
  188. @@ -2998,6 +3003,13 @@ static void handle_auth(struct hostapd_d
  189. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  190. goto fail;
  191. }
  192. + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
  193. + if (ubus_resp) {
  194. + wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
  195. + MAC2STR(mgmt->sa));
  196. + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
  197. + goto fail;
  198. + }
  199. if (res == HOSTAPD_ACL_PENDING)
  200. return;
  201. @@ -5242,7 +5254,7 @@ static void handle_assoc(struct hostapd_
  202. int resp = WLAN_STATUS_SUCCESS;
  203. u16 reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
  204. const u8 *pos;
  205. - int left, i;
  206. + int left, i, ubus_resp;
  207. struct sta_info *sta;
  208. u8 *tmp = NULL;
  209. #ifdef CONFIG_FILS
  210. @@ -5484,6 +5496,11 @@ static void handle_assoc(struct hostapd_
  211. left = res;
  212. }
  213. #endif /* CONFIG_FILS */
  214. + struct hostapd_ubus_request req = {
  215. + .type = HOSTAPD_UBUS_ASSOC_REQ,
  216. + .mgmt_frame = mgmt,
  217. + .ssi_signal = rssi,
  218. + };
  219. /* followed by SSID and Supported rates; and HT capabilities if 802.11n
  220. * is used */
  221. @@ -5586,6 +5603,13 @@ static void handle_assoc(struct hostapd_
  222. if (set_beacon)
  223. ieee802_11_set_beacons(hapd->iface);
  224. + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
  225. + if (ubus_resp) {
  226. + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
  227. + MAC2STR(mgmt->sa));
  228. + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
  229. + goto fail;
  230. + }
  231. fail:
  232. /*
  233. @@ -5836,6 +5860,7 @@ static void handle_disassoc(struct hosta
  234. (unsigned long) len);
  235. return;
  236. }
  237. + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
  238. sta = ap_get_sta(hapd, mgmt->sa);
  239. if (!sta) {
  240. @@ -5867,6 +5892,8 @@ static void handle_deauth(struct hostapd
  241. /* Clear the PTKSA cache entries for PASN */
  242. ptksa_cache_flush(hapd->ptksa, mgmt->sa, WPA_CIPHER_NONE);
  243. + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
  244. +
  245. sta = ap_get_sta(hapd, mgmt->sa);
  246. if (!sta) {
  247. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
  248. --- a/src/ap/rrm.c
  249. +++ b/src/ap/rrm.c
  250. @@ -89,6 +89,9 @@ static void hostapd_handle_beacon_report
  251. return;
  252. wpa_msg(hapd->msg_ctx, MSG_INFO, BEACON_RESP_RX MACSTR " %u %02x %s",
  253. MAC2STR(addr), token, rep_mode, report);
  254. + if (len < sizeof(struct rrm_measurement_beacon_report))
  255. + return;
  256. + hostapd_ubus_notify_beacon_report(hapd, addr, token, rep_mode, (struct rrm_measurement_beacon_report*) pos, len);
  257. }
  258. @@ -352,6 +355,9 @@ void hostapd_handle_radio_measurement(st
  259. mgmt->u.action.u.rrm.action, MAC2STR(mgmt->sa));
  260. switch (mgmt->u.action.u.rrm.action) {
  261. + case WLAN_RRM_LINK_MEASUREMENT_REPORT:
  262. + hostapd_ubus_handle_link_measurement(hapd, buf, len);
  263. + break;
  264. case WLAN_RRM_RADIO_MEASUREMENT_REPORT:
  265. hostapd_handle_radio_msmt_report(hapd, buf, len);
  266. break;
  267. --- a/src/ap/sta_info.c
  268. +++ b/src/ap/sta_info.c
  269. @@ -476,6 +476,7 @@ void ap_handle_timer(void *eloop_ctx, vo
  270. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  271. HOSTAPD_LEVEL_INFO, "deauthenticated due to "
  272. "local deauth request");
  273. + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
  274. ap_free_sta(hapd, sta);
  275. return;
  276. }
  277. @@ -631,6 +632,7 @@ skip_poll:
  278. mlme_deauthenticate_indication(
  279. hapd, sta,
  280. WLAN_REASON_PREV_AUTH_NOT_VALID);
  281. + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
  282. ap_free_sta(hapd, sta);
  283. break;
  284. }
  285. @@ -1448,15 +1450,28 @@ void ap_sta_set_authorized_event(struct
  286. os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
  287. if (authorized) {
  288. + static const char * const auth_algs[] = {
  289. + [WLAN_AUTH_OPEN] = "open",
  290. + [WLAN_AUTH_SHARED_KEY] = "shared",
  291. + [WLAN_AUTH_FT] = "ft",
  292. + [WLAN_AUTH_SAE] = "sae",
  293. + [WLAN_AUTH_FILS_SK] = "fils-sk",
  294. + [WLAN_AUTH_FILS_SK_PFS] = "fils-sk-pfs",
  295. + [WLAN_AUTH_FILS_PK] = "fils-pk",
  296. + [WLAN_AUTH_PASN] = "pasn",
  297. + };
  298. + const char *auth_alg = NULL;
  299. const u8 *dpp_pkhash;
  300. const char *keyid;
  301. char dpp_pkhash_buf[100];
  302. char keyid_buf[100];
  303. char ip_addr[100];
  304. + char alg_buf[100];
  305. dpp_pkhash_buf[0] = '\0';
  306. keyid_buf[0] = '\0';
  307. ip_addr[0] = '\0';
  308. + alg_buf[0] = '\0';
  309. #ifdef CONFIG_P2P
  310. if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) {
  311. os_snprintf(ip_addr, sizeof(ip_addr),
  312. @@ -1467,6 +1482,13 @@ void ap_sta_set_authorized_event(struct
  313. }
  314. #endif /* CONFIG_P2P */
  315. + if (sta->auth_alg < ARRAY_SIZE(auth_algs))
  316. + auth_alg = auth_algs[sta->auth_alg];
  317. +
  318. + if (auth_alg)
  319. + os_snprintf(alg_buf, sizeof(alg_buf),
  320. + " auth_alg=%s", auth_alg);
  321. +
  322. keyid = ap_sta_wpa_get_keyid(hapd, sta);
  323. if (keyid) {
  324. os_snprintf(keyid_buf, sizeof(keyid_buf),
  325. @@ -1485,17 +1507,19 @@ void ap_sta_set_authorized_event(struct
  326. dpp_pkhash, SHA256_MAC_LEN);
  327. }
  328. - wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s%s",
  329. - buf, ip_addr, keyid_buf, dpp_pkhash_buf);
  330. + hostapd_ubus_notify_authorized(hapd, sta, auth_alg);
  331. + wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s%s%s",
  332. + buf, ip_addr, keyid_buf, dpp_pkhash_buf, alg_buf);
  333. if (hapd->msg_ctx_parent &&
  334. hapd->msg_ctx_parent != hapd->msg_ctx)
  335. wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
  336. - AP_STA_CONNECTED "%s%s%s%s",
  337. + AP_STA_CONNECTED "%s%s%s%s%s",
  338. buf, ip_addr, keyid_buf,
  339. - dpp_pkhash_buf);
  340. + dpp_pkhash_buf, alg_buf);
  341. } else {
  342. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
  343. + hostapd_ubus_notify(hapd, "disassoc", sta->addr);
  344. if (hapd->msg_ctx_parent &&
  345. hapd->msg_ctx_parent != hapd->msg_ctx)
  346. --- a/src/ap/sta_info.h
  347. +++ b/src/ap/sta_info.h
  348. @@ -319,6 +319,7 @@ struct sta_info {
  349. #endif /* CONFIG_TESTING_OPTIONS */
  350. #ifdef CONFIG_AIRTIME_POLICY
  351. unsigned int airtime_weight;
  352. + unsigned int dyn_airtime_weight;
  353. struct os_reltime backlogged_until;
  354. #endif /* CONFIG_AIRTIME_POLICY */
  355. --- a/src/ap/vlan_init.c
  356. +++ b/src/ap/vlan_init.c
  357. @@ -22,6 +22,7 @@
  358. static int vlan_if_add(struct hostapd_data *hapd, struct hostapd_vlan *vlan,
  359. int existsok)
  360. {
  361. + bool vlan_exists = iface_exists(vlan->ifname);
  362. int ret;
  363. #ifdef CONFIG_WEP
  364. int i;
  365. @@ -36,7 +37,7 @@ static int vlan_if_add(struct hostapd_da
  366. }
  367. #endif /* CONFIG_WEP */
  368. - if (!iface_exists(vlan->ifname))
  369. + if (!vlan_exists)
  370. ret = hostapd_vlan_if_add(hapd, vlan->ifname);
  371. else if (!existsok)
  372. return -1;
  373. @@ -51,6 +52,9 @@ static int vlan_if_add(struct hostapd_da
  374. if (hapd->wpa_auth)
  375. ret = wpa_auth_ensure_group(hapd->wpa_auth, vlan->vlan_id);
  376. + if (!ret && !vlan_exists)
  377. + hostapd_ubus_add_vlan(hapd, vlan);
  378. +
  379. if (ret == 0)
  380. return ret;
  381. @@ -77,6 +81,8 @@ int vlan_if_remove(struct hostapd_data *
  382. "WPA deinitialization for VLAN %d failed (%d)",
  383. vlan->vlan_id, ret);
  384. + hostapd_ubus_remove_vlan(hapd, vlan);
  385. +
  386. return hostapd_vlan_if_remove(hapd, vlan->ifname);
  387. }
  388. --- a/src/ap/wnm_ap.c
  389. +++ b/src/ap/wnm_ap.c
  390. @@ -479,7 +479,8 @@ static void ieee802_11_rx_bss_trans_mgmt
  391. MAC2STR(addr), reason, hex ? " neighbor=" : "", hex);
  392. os_free(hex);
  393. - ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token);
  394. + if (!hostapd_ubus_notify_bss_transition_query(hapd, addr, dialog_token, reason, pos, end - pos))
  395. + ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token);
  396. }
  397. @@ -501,7 +502,7 @@ static void ieee802_11_rx_bss_trans_mgmt
  398. size_t len)
  399. {
  400. u8 dialog_token, status_code, bss_termination_delay;
  401. - const u8 *pos, *end;
  402. + const u8 *pos, *end, *target_bssid = NULL;
  403. int enabled = hapd->conf->bss_transition;
  404. struct sta_info *sta;
  405. @@ -548,6 +549,7 @@ static void ieee802_11_rx_bss_trans_mgmt
  406. wpa_printf(MSG_DEBUG, "WNM: not enough room for Target BSSID field");
  407. return;
  408. }
  409. + target_bssid = pos;
  410. sta->agreed_to_steer = 1;
  411. eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta);
  412. eloop_register_timeout(2, 0, ap_sta_reset_steer_flag_timer,
  413. @@ -567,6 +569,10 @@ static void ieee802_11_rx_bss_trans_mgmt
  414. MAC2STR(addr), status_code, bss_termination_delay);
  415. }
  416. + hostapd_ubus_notify_bss_transition_response(hapd, sta->addr, dialog_token,
  417. + status_code, bss_termination_delay,
  418. + target_bssid, pos, end - pos);
  419. +
  420. wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
  421. pos, end - pos);
  422. }
  423. --- a/src/ap/wpa_auth_glue.c
  424. +++ b/src/ap/wpa_auth_glue.c
  425. @@ -275,6 +275,7 @@ static void hostapd_wpa_auth_psk_failure
  426. struct hostapd_data *hapd = ctx;
  427. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
  428. MAC2STR(addr));
  429. + hostapd_ubus_notify(hapd, "key-mismatch", addr);
  430. }
  431. --- a/src/utils/eloop.c
  432. +++ b/src/utils/eloop.c
  433. @@ -77,6 +77,9 @@ struct eloop_sock_table {
  434. struct eloop_data {
  435. int max_sock;
  436. + eloop_timeout_poll_handler timeout_poll_cb;
  437. + eloop_poll_handler poll_cb;
  438. +
  439. size_t count; /* sum of all table counts */
  440. #ifdef CONFIG_ELOOP_POLL
  441. size_t max_pollfd_map; /* number of pollfds_map currently allocated */
  442. @@ -1121,6 +1124,12 @@ void eloop_run(void)
  443. os_reltime_sub(&timeout->time, &now, &tv);
  444. else
  445. tv.sec = tv.usec = 0;
  446. + }
  447. +
  448. + if (eloop.timeout_poll_cb && eloop.timeout_poll_cb(&tv, !!timeout))
  449. + timeout = (void *)1;
  450. +
  451. + if (timeout) {
  452. #if defined(CONFIG_ELOOP_POLL) || defined(CONFIG_ELOOP_EPOLL)
  453. timeout_ms = tv.sec * 1000 + tv.usec / 1000;
  454. #endif /* defined(CONFIG_ELOOP_POLL) || defined(CONFIG_ELOOP_EPOLL) */
  455. @@ -1190,7 +1199,8 @@ void eloop_run(void)
  456. eloop.exceptions.changed = 0;
  457. eloop_process_pending_signals();
  458. -
  459. + if (eloop.poll_cb)
  460. + eloop.poll_cb();
  461. /* check if some registered timeouts have occurred */
  462. timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
  463. @@ -1252,6 +1262,14 @@ out:
  464. return;
  465. }
  466. +int eloop_register_cb(eloop_poll_handler poll_cb,
  467. + eloop_timeout_poll_handler timeout_cb)
  468. +{
  469. + eloop.poll_cb = poll_cb;
  470. + eloop.timeout_poll_cb = timeout_cb;
  471. +
  472. + return 0;
  473. +}
  474. void eloop_terminate(void)
  475. {
  476. --- a/src/utils/eloop.h
  477. +++ b/src/utils/eloop.h
  478. @@ -65,6 +65,9 @@ typedef void (*eloop_timeout_handler)(vo
  479. */
  480. typedef void (*eloop_signal_handler)(int sig, void *signal_ctx);
  481. +typedef bool (*eloop_timeout_poll_handler)(struct os_reltime *tv, bool tv_set);
  482. +typedef void (*eloop_poll_handler)(void);
  483. +
  484. /**
  485. * eloop_init() - Initialize global event loop data
  486. * Returns: 0 on success, -1 on failure
  487. @@ -73,6 +76,9 @@ typedef void (*eloop_signal_handler)(int
  488. */
  489. int eloop_init(void);
  490. +int eloop_register_cb(eloop_poll_handler poll_cb,
  491. + eloop_timeout_poll_handler timeout_cb);
  492. +
  493. /**
  494. * eloop_register_read_sock - Register handler for read events
  495. * @sock: File descriptor number for the socket
  496. @@ -320,6 +326,8 @@ int eloop_register_signal_reconfig(eloop
  497. */
  498. int eloop_sock_requeue(void);
  499. +void eloop_add_uloop(void);
  500. +
  501. /**
  502. * eloop_run - Start the event loop
  503. *
  504. --- /dev/null
  505. +++ b/src/utils/uloop.c
  506. @@ -0,0 +1,64 @@
  507. +#include <libubox/uloop.h>
  508. +#include "includes.h"
  509. +#include "common.h"
  510. +#include "eloop.h"
  511. +
  512. +static void eloop_uloop_event_cb(int sock, void *eloop_ctx, void *sock_ctx)
  513. +{
  514. +}
  515. +
  516. +static void eloop_uloop_fd_cb(struct uloop_fd *fd, unsigned int events)
  517. +{
  518. + unsigned int changed = events ^ fd->flags;
  519. +
  520. + if (changed & ULOOP_READ) {
  521. + if (events & ULOOP_READ)
  522. + eloop_register_sock(fd->fd, EVENT_TYPE_READ, eloop_uloop_event_cb, fd, fd);
  523. + else
  524. + eloop_unregister_sock(fd->fd, EVENT_TYPE_READ);
  525. + }
  526. +
  527. + if (changed & ULOOP_WRITE) {
  528. + if (events & ULOOP_WRITE)
  529. + eloop_register_sock(fd->fd, EVENT_TYPE_WRITE, eloop_uloop_event_cb, fd, fd);
  530. + else
  531. + eloop_unregister_sock(fd->fd, EVENT_TYPE_WRITE);
  532. + }
  533. +}
  534. +
  535. +static bool uloop_timeout_poll_handler(struct os_reltime *tv, bool tv_set)
  536. +{
  537. + struct os_reltime tv_uloop;
  538. + int timeout_ms = uloop_get_next_timeout();
  539. +
  540. + if (timeout_ms < 0)
  541. + return false;
  542. +
  543. + tv_uloop.sec = timeout_ms / 1000;
  544. + tv_uloop.usec = (timeout_ms % 1000) * 1000;
  545. +
  546. + if (!tv_set || os_reltime_before(&tv_uloop, tv)) {
  547. + *tv = tv_uloop;
  548. + return true;
  549. + }
  550. +
  551. + return false;
  552. +}
  553. +
  554. +static void uloop_poll_handler(void)
  555. +{
  556. + uloop_run_timeout(0);
  557. +}
  558. +
  559. +void eloop_add_uloop(void)
  560. +{
  561. + static bool init_done = false;
  562. +
  563. + if (!init_done) {
  564. + uloop_init();
  565. + uloop_fd_set_cb = eloop_uloop_fd_cb;
  566. + init_done = true;
  567. + }
  568. +
  569. + eloop_register_cb(uloop_poll_handler, uloop_timeout_poll_handler);
  570. +}
  571. --- a/wpa_supplicant/Makefile
  572. +++ b/wpa_supplicant/Makefile
  573. @@ -189,6 +189,13 @@ ifdef CONFIG_EAPOL_TEST
  574. CFLAGS += -Werror -DEAPOL_TEST
  575. endif
  576. +ifdef CONFIG_UBUS
  577. +CFLAGS += -DUBUS_SUPPORT
  578. +OBJS += ubus.o
  579. +OBJS += ../src/utils/uloop.o
  580. +LIBS += -lubox -lubus
  581. +endif
  582. +
  583. ifdef CONFIG_CODE_COVERAGE
  584. CFLAGS += -O0 -fprofile-arcs -ftest-coverage -U_FORTIFY_SOURCE
  585. LIBS += -lgcov
  586. @@ -1042,6 +1049,9 @@ ifdef CONFIG_CTRL_IFACE_MIB
  587. CFLAGS += -DCONFIG_CTRL_IFACE_MIB
  588. endif
  589. OBJS += ../src/ap/ctrl_iface_ap.o
  590. +ifdef CONFIG_UBUS
  591. +OBJS += ../src/ap/ubus.o
  592. +endif
  593. endif
  594. CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY
  595. --- a/wpa_supplicant/main.c
  596. +++ b/wpa_supplicant/main.c
  597. @@ -203,7 +203,7 @@ int main(int argc, char *argv[])
  598. for (;;) {
  599. c = getopt(argc, argv,
  600. - "b:Bc:C:D:de:f:g:G:hi:I:KLMm:No:O:p:P:qsTtuv::W");
  601. + "b:Bc:C:D:de:f:g:G:hi:I:KLMm:nNo:O:p:P:qsTtuv::W");
  602. if (c < 0)
  603. break;
  604. switch (c) {
  605. @@ -268,6 +268,9 @@ int main(int argc, char *argv[])
  606. params.conf_p2p_dev = optarg;
  607. break;
  608. #endif /* CONFIG_P2P */
  609. + case 'n':
  610. + iface_count = 0;
  611. + break;
  612. case 'o':
  613. params.override_driver = optarg;
  614. break;
  615. --- a/wpa_supplicant/wpa_supplicant.c
  616. +++ b/wpa_supplicant/wpa_supplicant.c
  617. @@ -7716,6 +7716,8 @@ struct wpa_supplicant * wpa_supplicant_a
  618. }
  619. #endif /* CONFIG_P2P */
  620. + wpas_ubus_add_bss(wpa_s);
  621. +
  622. return wpa_s;
  623. }
  624. @@ -7742,6 +7744,8 @@ int wpa_supplicant_remove_iface(struct w
  625. struct wpa_supplicant *parent = wpa_s->parent;
  626. #endif /* CONFIG_MESH */
  627. + wpas_ubus_free_bss(wpa_s);
  628. +
  629. /* Remove interface from the global list of interfaces */
  630. prev = global->ifaces;
  631. if (prev == wpa_s) {
  632. @@ -8088,8 +8092,12 @@ int wpa_supplicant_run(struct wpa_global
  633. eloop_register_signal_terminate(wpa_supplicant_terminate, global);
  634. eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
  635. + wpas_ubus_add(global);
  636. +
  637. eloop_run();
  638. + wpas_ubus_free(global);
  639. +
  640. return 0;
  641. }
  642. --- a/wpa_supplicant/wpa_supplicant_i.h
  643. +++ b/wpa_supplicant/wpa_supplicant_i.h
  644. @@ -21,6 +21,7 @@
  645. #include "config_ssid.h"
  646. #include "wmm_ac.h"
  647. #include "pasn/pasn_common.h"
  648. +#include "ubus.h"
  649. extern const char *const wpa_supplicant_version;
  650. extern const char *const wpa_supplicant_license;
  651. @@ -319,6 +320,8 @@ struct wpa_global {
  652. #endif /* CONFIG_WIFI_DISPLAY */
  653. struct psk_list_entry *add_psk; /* From group formation */
  654. +
  655. + struct ubus_object ubus_global;
  656. };
  657. @@ -693,6 +696,7 @@ struct wpa_supplicant {
  658. unsigned char own_addr[ETH_ALEN];
  659. unsigned char perm_addr[ETH_ALEN];
  660. char ifname[100];
  661. + struct wpas_ubus_bss ubus;
  662. #ifdef CONFIG_MATCH_IFACE
  663. int matched;
  664. #endif /* CONFIG_MATCH_IFACE */
  665. --- a/wpa_supplicant/wps_supplicant.c
  666. +++ b/wpa_supplicant/wps_supplicant.c
  667. @@ -33,6 +33,7 @@
  668. #include "p2p/p2p.h"
  669. #include "p2p_supplicant.h"
  670. #include "wps_supplicant.h"
  671. +#include "ubus.h"
  672. #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
  673. @@ -401,6 +402,8 @@ static int wpa_supplicant_wps_cred(void
  674. wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
  675. cred->cred_attr, cred->cred_attr_len);
  676. + wpas_ubus_notify(wpa_s, cred);
  677. +
  678. if (wpa_s->conf->wps_cred_processing == 1)
  679. return 0;