ap.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. /*
  2. * WPA Supplicant - Basic AP mode support routines
  3. * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
  4. * Copyright (c) 2009, Atheros Communications
  5. *
  6. * This software may be distributed under the terms of the BSD license.
  7. * See README for more details.
  8. */
  9. #include "utils/includes.h"
  10. #include "utils/common.h"
  11. #include "utils/eloop.h"
  12. #include "utils/uuid.h"
  13. #include "common/ieee802_11_defs.h"
  14. #include "common/wpa_ctrl.h"
  15. #include "eapol_supp/eapol_supp_sm.h"
  16. #include "ap/hostapd.h"
  17. #include "ap/ap_config.h"
  18. #include "ap/ap_drv_ops.h"
  19. #ifdef NEED_AP_MLME
  20. #include "ap/ieee802_11.h"
  21. #endif /* NEED_AP_MLME */
  22. #include "ap/beacon.h"
  23. #include "ap/ieee802_1x.h"
  24. #include "ap/wps_hostapd.h"
  25. #include "ap/ctrl_iface_ap.h"
  26. #include "wps/wps.h"
  27. #include "common/ieee802_11_defs.h"
  28. #include "config_ssid.h"
  29. #include "config.h"
  30. #include "wpa_supplicant_i.h"
  31. #include "driver_i.h"
  32. #include "p2p_supplicant.h"
  33. #include "ap.h"
  34. #include "ap/sta_info.h"
  35. #include "notify.h"
  36. #ifdef CONFIG_WPS
  37. static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
  38. #endif /* CONFIG_WPS */
  39. #ifdef CONFIG_IEEE80211N
  40. static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s,
  41. struct hostapd_config *conf,
  42. struct hostapd_hw_modes *mode)
  43. {
  44. u8 center_chan = 0;
  45. u8 channel = conf->channel;
  46. if (!conf->secondary_channel)
  47. goto no_vht;
  48. center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
  49. if (!center_chan)
  50. goto no_vht;
  51. /* Use 80 MHz channel */
  52. conf->vht_oper_chwidth = 1;
  53. conf->vht_oper_centr_freq_seg0_idx = center_chan;
  54. return;
  55. no_vht:
  56. conf->vht_oper_centr_freq_seg0_idx =
  57. channel + conf->secondary_channel * 2;
  58. }
  59. #endif /* CONFIG_IEEE80211N */
  60. static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
  61. struct wpa_ssid *ssid,
  62. struct hostapd_config *conf)
  63. {
  64. struct hostapd_bss_config *bss = conf->bss[0];
  65. conf->driver = wpa_s->driver;
  66. os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
  67. conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
  68. &conf->channel);
  69. if (conf->hw_mode == NUM_HOSTAPD_MODES) {
  70. wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
  71. ssid->frequency);
  72. return -1;
  73. }
  74. /* TODO: enable HT40 if driver supports it;
  75. * drop to 11b if driver does not support 11g */
  76. #ifdef CONFIG_IEEE80211N
  77. /*
  78. * Enable HT20 if the driver supports it, by setting conf->ieee80211n
  79. * and a mask of allowed capabilities within conf->ht_capab.
  80. * Using default config settings for: conf->ht_op_mode_fixed,
  81. * conf->secondary_channel, conf->require_ht
  82. */
  83. if (wpa_s->hw.modes) {
  84. struct hostapd_hw_modes *mode = NULL;
  85. int i, no_ht = 0;
  86. for (i = 0; i < wpa_s->hw.num_modes; i++) {
  87. if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
  88. mode = &wpa_s->hw.modes[i];
  89. break;
  90. }
  91. }
  92. #ifdef CONFIG_HT_OVERRIDES
  93. if (ssid->disable_ht) {
  94. conf->ieee80211n = 0;
  95. conf->ht_capab = 0;
  96. no_ht = 1;
  97. }
  98. #endif /* CONFIG_HT_OVERRIDES */
  99. if (!no_ht && mode && mode->ht_capab) {
  100. conf->ieee80211n = 1;
  101. #ifdef CONFIG_P2P
  102. if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
  103. (mode->ht_capab &
  104. HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
  105. ssid->ht40)
  106. conf->secondary_channel =
  107. wpas_p2p_get_ht40_mode(wpa_s, mode,
  108. conf->channel);
  109. if (conf->secondary_channel)
  110. conf->ht_capab |=
  111. HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
  112. #endif /* CONFIG_P2P */
  113. /*
  114. * white-list capabilities that won't cause issues
  115. * to connecting stations, while leaving the current
  116. * capabilities intact (currently disabled SMPS).
  117. */
  118. conf->ht_capab |= mode->ht_capab &
  119. (HT_CAP_INFO_GREEN_FIELD |
  120. HT_CAP_INFO_SHORT_GI20MHZ |
  121. HT_CAP_INFO_SHORT_GI40MHZ |
  122. HT_CAP_INFO_RX_STBC_MASK |
  123. HT_CAP_INFO_MAX_AMSDU_SIZE);
  124. if (mode->vht_capab && ssid->vht) {
  125. conf->ieee80211ac = 1;
  126. wpas_conf_ap_vht(wpa_s, conf, mode);
  127. }
  128. }
  129. }
  130. #endif /* CONFIG_IEEE80211N */
  131. #ifdef CONFIG_P2P
  132. if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
  133. (ssid->mode == WPAS_MODE_P2P_GO ||
  134. ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
  135. /* Remove 802.11b rates from supported and basic rate sets */
  136. int *list = os_malloc(4 * sizeof(int));
  137. if (list) {
  138. list[0] = 60;
  139. list[1] = 120;
  140. list[2] = 240;
  141. list[3] = -1;
  142. }
  143. conf->basic_rates = list;
  144. list = os_malloc(9 * sizeof(int));
  145. if (list) {
  146. list[0] = 60;
  147. list[1] = 90;
  148. list[2] = 120;
  149. list[3] = 180;
  150. list[4] = 240;
  151. list[5] = 360;
  152. list[6] = 480;
  153. list[7] = 540;
  154. list[8] = -1;
  155. }
  156. conf->supported_rates = list;
  157. }
  158. bss->isolate = !wpa_s->conf->p2p_intra_bss;
  159. bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
  160. #endif /* CONFIG_P2P */
  161. if (ssid->ssid_len == 0) {
  162. wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
  163. return -1;
  164. }
  165. os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
  166. bss->ssid.ssid_len = ssid->ssid_len;
  167. bss->ssid.ssid_set = 1;
  168. bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
  169. if (ssid->auth_alg)
  170. bss->auth_algs = ssid->auth_alg;
  171. if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
  172. bss->wpa = ssid->proto;
  173. bss->wpa_key_mgmt = ssid->key_mgmt;
  174. bss->wpa_pairwise = ssid->pairwise_cipher;
  175. if (ssid->psk_set) {
  176. os_free(bss->ssid.wpa_psk);
  177. bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
  178. if (bss->ssid.wpa_psk == NULL)
  179. return -1;
  180. os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
  181. bss->ssid.wpa_psk->group = 1;
  182. } else if (ssid->passphrase) {
  183. bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
  184. } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
  185. ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
  186. struct hostapd_wep_keys *wep = &bss->ssid.wep;
  187. int i;
  188. for (i = 0; i < NUM_WEP_KEYS; i++) {
  189. if (ssid->wep_key_len[i] == 0)
  190. continue;
  191. wep->key[i] = os_malloc(ssid->wep_key_len[i]);
  192. if (wep->key[i] == NULL)
  193. return -1;
  194. os_memcpy(wep->key[i], ssid->wep_key[i],
  195. ssid->wep_key_len[i]);
  196. wep->len[i] = ssid->wep_key_len[i];
  197. }
  198. wep->idx = ssid->wep_tx_keyidx;
  199. wep->keys_set = 1;
  200. }
  201. if (ssid->ap_max_inactivity)
  202. bss->ap_max_inactivity = ssid->ap_max_inactivity;
  203. if (ssid->dtim_period)
  204. bss->dtim_period = ssid->dtim_period;
  205. else if (wpa_s->conf->dtim_period)
  206. bss->dtim_period = wpa_s->conf->dtim_period;
  207. if (ssid->beacon_int)
  208. conf->beacon_int = ssid->beacon_int;
  209. else if (wpa_s->conf->beacon_int)
  210. conf->beacon_int = wpa_s->conf->beacon_int;
  211. if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
  212. bss->rsn_pairwise = bss->wpa_pairwise;
  213. bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
  214. bss->rsn_pairwise);
  215. if (bss->wpa && bss->ieee802_1x)
  216. bss->ssid.security_policy = SECURITY_WPA;
  217. else if (bss->wpa)
  218. bss->ssid.security_policy = SECURITY_WPA_PSK;
  219. else if (bss->ieee802_1x) {
  220. int cipher = WPA_CIPHER_NONE;
  221. bss->ssid.security_policy = SECURITY_IEEE_802_1X;
  222. bss->ssid.wep.default_len = bss->default_wep_key_len;
  223. if (bss->default_wep_key_len)
  224. cipher = bss->default_wep_key_len >= 13 ?
  225. WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
  226. bss->wpa_group = cipher;
  227. bss->wpa_pairwise = cipher;
  228. bss->rsn_pairwise = cipher;
  229. } else if (bss->ssid.wep.keys_set) {
  230. int cipher = WPA_CIPHER_WEP40;
  231. if (bss->ssid.wep.len[0] >= 13)
  232. cipher = WPA_CIPHER_WEP104;
  233. bss->ssid.security_policy = SECURITY_STATIC_WEP;
  234. bss->wpa_group = cipher;
  235. bss->wpa_pairwise = cipher;
  236. bss->rsn_pairwise = cipher;
  237. } else {
  238. bss->ssid.security_policy = SECURITY_PLAINTEXT;
  239. bss->wpa_group = WPA_CIPHER_NONE;
  240. bss->wpa_pairwise = WPA_CIPHER_NONE;
  241. bss->rsn_pairwise = WPA_CIPHER_NONE;
  242. }
  243. if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
  244. (bss->wpa_group == WPA_CIPHER_CCMP ||
  245. bss->wpa_group == WPA_CIPHER_GCMP ||
  246. bss->wpa_group == WPA_CIPHER_CCMP_256 ||
  247. bss->wpa_group == WPA_CIPHER_GCMP_256)) {
  248. /*
  249. * Strong ciphers do not need frequent rekeying, so increase
  250. * the default GTK rekeying period to 24 hours.
  251. */
  252. bss->wpa_group_rekey = 86400;
  253. }
  254. #ifdef CONFIG_WPS
  255. /*
  256. * Enable WPS by default for open and WPA/WPA2-Personal network, but
  257. * require user interaction to actually use it. Only the internal
  258. * Registrar is supported.
  259. */
  260. if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
  261. bss->ssid.security_policy != SECURITY_PLAINTEXT)
  262. goto no_wps;
  263. #ifdef CONFIG_WPS2
  264. if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
  265. (!(bss->rsn_pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2)))
  266. goto no_wps; /* WPS2 does not allow WPA/TKIP-only
  267. * configuration */
  268. #endif /* CONFIG_WPS2 */
  269. bss->eap_server = 1;
  270. if (!ssid->ignore_broadcast_ssid)
  271. bss->wps_state = 2;
  272. bss->ap_setup_locked = 2;
  273. if (wpa_s->conf->config_methods)
  274. bss->config_methods = os_strdup(wpa_s->conf->config_methods);
  275. os_memcpy(bss->device_type, wpa_s->conf->device_type,
  276. WPS_DEV_TYPE_LEN);
  277. if (wpa_s->conf->device_name) {
  278. bss->device_name = os_strdup(wpa_s->conf->device_name);
  279. bss->friendly_name = os_strdup(wpa_s->conf->device_name);
  280. }
  281. if (wpa_s->conf->manufacturer)
  282. bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
  283. if (wpa_s->conf->model_name)
  284. bss->model_name = os_strdup(wpa_s->conf->model_name);
  285. if (wpa_s->conf->model_number)
  286. bss->model_number = os_strdup(wpa_s->conf->model_number);
  287. if (wpa_s->conf->serial_number)
  288. bss->serial_number = os_strdup(wpa_s->conf->serial_number);
  289. if (is_nil_uuid(wpa_s->conf->uuid))
  290. os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
  291. else
  292. os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
  293. os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
  294. bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
  295. no_wps:
  296. #endif /* CONFIG_WPS */
  297. if (wpa_s->max_stations &&
  298. wpa_s->max_stations < wpa_s->conf->max_num_sta)
  299. bss->max_num_sta = wpa_s->max_stations;
  300. else
  301. bss->max_num_sta = wpa_s->conf->max_num_sta;
  302. bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
  303. if (wpa_s->conf->ap_vendor_elements) {
  304. bss->vendor_elements =
  305. wpabuf_dup(wpa_s->conf->ap_vendor_elements);
  306. }
  307. return 0;
  308. }
  309. static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
  310. {
  311. #ifdef CONFIG_P2P
  312. struct wpa_supplicant *wpa_s = ctx;
  313. const struct ieee80211_mgmt *mgmt;
  314. size_t hdr_len;
  315. mgmt = (const struct ieee80211_mgmt *) buf;
  316. hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
  317. if (hdr_len > len)
  318. return;
  319. wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
  320. mgmt->u.action.category,
  321. &mgmt->u.action.u.vs_public_action.action,
  322. len - hdr_len, freq);
  323. #endif /* CONFIG_P2P */
  324. }
  325. static void ap_wps_event_cb(void *ctx, enum wps_event event,
  326. union wps_event_data *data)
  327. {
  328. #ifdef CONFIG_P2P
  329. struct wpa_supplicant *wpa_s = ctx;
  330. if (event == WPS_EV_FAIL) {
  331. struct wps_event_fail *fail = &data->fail;
  332. if (wpa_s->parent && wpa_s->parent != wpa_s &&
  333. wpa_s == wpa_s->global->p2p_group_formation) {
  334. /*
  335. * src/ap/wps_hostapd.c has already sent this on the
  336. * main interface, so only send on the parent interface
  337. * here if needed.
  338. */
  339. wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
  340. "msg=%d config_error=%d",
  341. fail->msg, fail->config_error);
  342. }
  343. wpas_p2p_wps_failed(wpa_s, fail);
  344. }
  345. #endif /* CONFIG_P2P */
  346. }
  347. static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
  348. int authorized, const u8 *p2p_dev_addr)
  349. {
  350. wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
  351. }
  352. #ifdef CONFIG_P2P
  353. static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
  354. const u8 *psk, size_t psk_len)
  355. {
  356. struct wpa_supplicant *wpa_s = ctx;
  357. if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
  358. return;
  359. wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
  360. }
  361. #endif /* CONFIG_P2P */
  362. static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
  363. {
  364. #ifdef CONFIG_P2P
  365. struct wpa_supplicant *wpa_s = ctx;
  366. const struct ieee80211_mgmt *mgmt;
  367. size_t hdr_len;
  368. mgmt = (const struct ieee80211_mgmt *) buf;
  369. hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
  370. if (hdr_len > len)
  371. return -1;
  372. wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
  373. mgmt->u.action.category,
  374. &mgmt->u.action.u.vs_public_action.action,
  375. len - hdr_len, freq);
  376. #endif /* CONFIG_P2P */
  377. return 0;
  378. }
  379. static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
  380. const u8 *bssid, const u8 *ie, size_t ie_len,
  381. int ssi_signal)
  382. {
  383. #ifdef CONFIG_P2P
  384. struct wpa_supplicant *wpa_s = ctx;
  385. return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
  386. ssi_signal);
  387. #else /* CONFIG_P2P */
  388. return 0;
  389. #endif /* CONFIG_P2P */
  390. }
  391. static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
  392. const u8 *uuid_e)
  393. {
  394. #ifdef CONFIG_P2P
  395. struct wpa_supplicant *wpa_s = ctx;
  396. wpas_p2p_wps_success(wpa_s, mac_addr, 1);
  397. #endif /* CONFIG_P2P */
  398. }
  399. static void wpas_ap_configured_cb(void *ctx)
  400. {
  401. struct wpa_supplicant *wpa_s = ctx;
  402. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  403. if (wpa_s->ap_configured_cb)
  404. wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
  405. wpa_s->ap_configured_cb_data);
  406. }
  407. int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
  408. struct wpa_ssid *ssid)
  409. {
  410. struct wpa_driver_associate_params params;
  411. struct hostapd_iface *hapd_iface;
  412. struct hostapd_config *conf;
  413. size_t i;
  414. if (ssid->ssid == NULL || ssid->ssid_len == 0) {
  415. wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
  416. return -1;
  417. }
  418. wpa_supplicant_ap_deinit(wpa_s);
  419. wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
  420. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  421. os_memset(&params, 0, sizeof(params));
  422. params.ssid = ssid->ssid;
  423. params.ssid_len = ssid->ssid_len;
  424. switch (ssid->mode) {
  425. case WPAS_MODE_INFRA:
  426. params.mode = IEEE80211_MODE_INFRA;
  427. break;
  428. case WPAS_MODE_IBSS:
  429. params.mode = IEEE80211_MODE_IBSS;
  430. break;
  431. case WPAS_MODE_AP:
  432. case WPAS_MODE_P2P_GO:
  433. case WPAS_MODE_P2P_GROUP_FORMATION:
  434. params.mode = IEEE80211_MODE_AP;
  435. break;
  436. }
  437. if (ssid->frequency == 0)
  438. ssid->frequency = 2462; /* default channel 11 */
  439. params.freq = ssid->frequency;
  440. params.wpa_proto = ssid->proto;
  441. if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
  442. wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
  443. else
  444. wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
  445. params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
  446. wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
  447. 1);
  448. if (wpa_s->pairwise_cipher < 0) {
  449. wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
  450. "cipher.");
  451. return -1;
  452. }
  453. params.pairwise_suite =
  454. wpa_cipher_to_suite_driver(wpa_s->pairwise_cipher);
  455. params.group_suite = params.pairwise_suite;
  456. #ifdef CONFIG_P2P
  457. if (ssid->mode == WPAS_MODE_P2P_GO ||
  458. ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  459. params.p2p = 1;
  460. #endif /* CONFIG_P2P */
  461. if (wpa_s->parent->set_ap_uapsd)
  462. params.uapsd = wpa_s->parent->ap_uapsd;
  463. else
  464. params.uapsd = -1;
  465. if (wpa_drv_associate(wpa_s, &params) < 0) {
  466. wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
  467. return -1;
  468. }
  469. wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
  470. if (hapd_iface == NULL)
  471. return -1;
  472. hapd_iface->owner = wpa_s;
  473. hapd_iface->drv_flags = wpa_s->drv_flags;
  474. hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
  475. hapd_iface->extended_capa = wpa_s->extended_capa;
  476. hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
  477. hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
  478. wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
  479. if (conf == NULL) {
  480. wpa_supplicant_ap_deinit(wpa_s);
  481. return -1;
  482. }
  483. os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
  484. wpa_s->conf->wmm_ac_params,
  485. sizeof(wpa_s->conf->wmm_ac_params));
  486. if (params.uapsd > 0) {
  487. conf->bss[0]->wmm_enabled = 1;
  488. conf->bss[0]->wmm_uapsd = 1;
  489. }
  490. if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
  491. wpa_printf(MSG_ERROR, "Failed to create AP configuration");
  492. wpa_supplicant_ap_deinit(wpa_s);
  493. return -1;
  494. }
  495. #ifdef CONFIG_P2P
  496. if (ssid->mode == WPAS_MODE_P2P_GO)
  497. conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
  498. else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  499. conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
  500. P2P_GROUP_FORMATION;
  501. #endif /* CONFIG_P2P */
  502. hapd_iface->num_bss = conf->num_bss;
  503. hapd_iface->bss = os_calloc(conf->num_bss,
  504. sizeof(struct hostapd_data *));
  505. if (hapd_iface->bss == NULL) {
  506. wpa_supplicant_ap_deinit(wpa_s);
  507. return -1;
  508. }
  509. for (i = 0; i < conf->num_bss; i++) {
  510. hapd_iface->bss[i] =
  511. hostapd_alloc_bss_data(hapd_iface, conf,
  512. conf->bss[i]);
  513. if (hapd_iface->bss[i] == NULL) {
  514. wpa_supplicant_ap_deinit(wpa_s);
  515. return -1;
  516. }
  517. hapd_iface->bss[i]->msg_ctx = wpa_s;
  518. hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
  519. hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
  520. hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
  521. hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
  522. hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
  523. hostapd_register_probereq_cb(hapd_iface->bss[i],
  524. ap_probe_req_rx, wpa_s);
  525. hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
  526. hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
  527. hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
  528. hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
  529. hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
  530. hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
  531. #ifdef CONFIG_P2P
  532. hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
  533. hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
  534. hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
  535. hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
  536. ssid);
  537. #endif /* CONFIG_P2P */
  538. hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
  539. hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
  540. }
  541. os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
  542. hapd_iface->bss[0]->driver = wpa_s->driver;
  543. hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
  544. wpa_s->current_ssid = ssid;
  545. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  546. os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
  547. wpa_s->assoc_freq = ssid->frequency;
  548. if (hostapd_setup_interface(wpa_s->ap_iface)) {
  549. wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
  550. wpa_supplicant_ap_deinit(wpa_s);
  551. return -1;
  552. }
  553. return 0;
  554. }
  555. void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
  556. {
  557. #ifdef CONFIG_WPS
  558. eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
  559. #endif /* CONFIG_WPS */
  560. if (wpa_s->ap_iface == NULL)
  561. return;
  562. wpa_s->current_ssid = NULL;
  563. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  564. wpa_s->assoc_freq = 0;
  565. #ifdef CONFIG_P2P
  566. if (wpa_s->ap_iface->bss)
  567. wpa_s->ap_iface->bss[0]->p2p_group = NULL;
  568. wpas_p2p_group_deinit(wpa_s);
  569. #endif /* CONFIG_P2P */
  570. hostapd_interface_deinit(wpa_s->ap_iface);
  571. hostapd_interface_free(wpa_s->ap_iface);
  572. wpa_s->ap_iface = NULL;
  573. wpa_drv_deinit_ap(wpa_s);
  574. }
  575. void ap_tx_status(void *ctx, const u8 *addr,
  576. const u8 *buf, size_t len, int ack)
  577. {
  578. #ifdef NEED_AP_MLME
  579. struct wpa_supplicant *wpa_s = ctx;
  580. hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
  581. #endif /* NEED_AP_MLME */
  582. }
  583. void ap_eapol_tx_status(void *ctx, const u8 *dst,
  584. const u8 *data, size_t len, int ack)
  585. {
  586. #ifdef NEED_AP_MLME
  587. struct wpa_supplicant *wpa_s = ctx;
  588. hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
  589. #endif /* NEED_AP_MLME */
  590. }
  591. void ap_client_poll_ok(void *ctx, const u8 *addr)
  592. {
  593. #ifdef NEED_AP_MLME
  594. struct wpa_supplicant *wpa_s = ctx;
  595. if (wpa_s->ap_iface)
  596. hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
  597. #endif /* NEED_AP_MLME */
  598. }
  599. void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
  600. {
  601. #ifdef NEED_AP_MLME
  602. struct wpa_supplicant *wpa_s = ctx;
  603. ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
  604. #endif /* NEED_AP_MLME */
  605. }
  606. void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
  607. {
  608. #ifdef NEED_AP_MLME
  609. struct wpa_supplicant *wpa_s = ctx;
  610. struct hostapd_frame_info fi;
  611. os_memset(&fi, 0, sizeof(fi));
  612. fi.datarate = rx_mgmt->datarate;
  613. fi.ssi_signal = rx_mgmt->ssi_signal;
  614. ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
  615. rx_mgmt->frame_len, &fi);
  616. #endif /* NEED_AP_MLME */
  617. }
  618. void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
  619. {
  620. #ifdef NEED_AP_MLME
  621. struct wpa_supplicant *wpa_s = ctx;
  622. ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
  623. #endif /* NEED_AP_MLME */
  624. }
  625. void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
  626. const u8 *src_addr, const u8 *buf, size_t len)
  627. {
  628. ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
  629. }
  630. #ifdef CONFIG_WPS
  631. int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
  632. const u8 *p2p_dev_addr)
  633. {
  634. if (!wpa_s->ap_iface)
  635. return -1;
  636. return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
  637. p2p_dev_addr);
  638. }
  639. int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
  640. {
  641. struct wps_registrar *reg;
  642. int reg_sel = 0, wps_sta = 0;
  643. if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
  644. return -1;
  645. reg = wpa_s->ap_iface->bss[0]->wps->registrar;
  646. reg_sel = wps_registrar_wps_cancel(reg);
  647. wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
  648. ap_sta_wps_cancel, NULL);
  649. if (!reg_sel && !wps_sta) {
  650. wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
  651. "time");
  652. return -1;
  653. }
  654. /*
  655. * There are 2 cases to return wps cancel as success:
  656. * 1. When wps cancel was initiated but no connection has been
  657. * established with client yet.
  658. * 2. Client is in the middle of exchanging WPS messages.
  659. */
  660. return 0;
  661. }
  662. int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
  663. const char *pin, char *buf, size_t buflen,
  664. int timeout)
  665. {
  666. int ret, ret_len = 0;
  667. if (!wpa_s->ap_iface)
  668. return -1;
  669. if (pin == NULL) {
  670. unsigned int rpin = wps_generate_pin();
  671. ret_len = os_snprintf(buf, buflen, "%08d", rpin);
  672. pin = buf;
  673. } else
  674. ret_len = os_snprintf(buf, buflen, "%s", pin);
  675. ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
  676. timeout);
  677. if (ret)
  678. return -1;
  679. return ret_len;
  680. }
  681. static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
  682. {
  683. struct wpa_supplicant *wpa_s = eloop_data;
  684. wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
  685. wpas_wps_ap_pin_disable(wpa_s);
  686. }
  687. static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
  688. {
  689. struct hostapd_data *hapd;
  690. if (wpa_s->ap_iface == NULL)
  691. return;
  692. hapd = wpa_s->ap_iface->bss[0];
  693. wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
  694. hapd->ap_pin_failures = 0;
  695. eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
  696. if (timeout > 0)
  697. eloop_register_timeout(timeout, 0,
  698. wpas_wps_ap_pin_timeout, wpa_s, NULL);
  699. }
  700. void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
  701. {
  702. struct hostapd_data *hapd;
  703. if (wpa_s->ap_iface == NULL)
  704. return;
  705. wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
  706. hapd = wpa_s->ap_iface->bss[0];
  707. os_free(hapd->conf->ap_pin);
  708. hapd->conf->ap_pin = NULL;
  709. eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
  710. }
  711. const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
  712. {
  713. struct hostapd_data *hapd;
  714. unsigned int pin;
  715. char pin_txt[9];
  716. if (wpa_s->ap_iface == NULL)
  717. return NULL;
  718. hapd = wpa_s->ap_iface->bss[0];
  719. pin = wps_generate_pin();
  720. os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
  721. os_free(hapd->conf->ap_pin);
  722. hapd->conf->ap_pin = os_strdup(pin_txt);
  723. if (hapd->conf->ap_pin == NULL)
  724. return NULL;
  725. wpas_wps_ap_pin_enable(wpa_s, timeout);
  726. return hapd->conf->ap_pin;
  727. }
  728. const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
  729. {
  730. struct hostapd_data *hapd;
  731. if (wpa_s->ap_iface == NULL)
  732. return NULL;
  733. hapd = wpa_s->ap_iface->bss[0];
  734. return hapd->conf->ap_pin;
  735. }
  736. int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
  737. int timeout)
  738. {
  739. struct hostapd_data *hapd;
  740. char pin_txt[9];
  741. int ret;
  742. if (wpa_s->ap_iface == NULL)
  743. return -1;
  744. hapd = wpa_s->ap_iface->bss[0];
  745. ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
  746. if (ret < 0 || ret >= (int) sizeof(pin_txt))
  747. return -1;
  748. os_free(hapd->conf->ap_pin);
  749. hapd->conf->ap_pin = os_strdup(pin_txt);
  750. if (hapd->conf->ap_pin == NULL)
  751. return -1;
  752. wpas_wps_ap_pin_enable(wpa_s, timeout);
  753. return 0;
  754. }
  755. void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
  756. {
  757. struct hostapd_data *hapd;
  758. if (wpa_s->ap_iface == NULL)
  759. return;
  760. hapd = wpa_s->ap_iface->bss[0];
  761. /*
  762. * Registrar failed to prove its knowledge of the AP PIN. Disable AP
  763. * PIN if this happens multiple times to slow down brute force attacks.
  764. */
  765. hapd->ap_pin_failures++;
  766. wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
  767. hapd->ap_pin_failures);
  768. if (hapd->ap_pin_failures < 3)
  769. return;
  770. wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
  771. hapd->ap_pin_failures = 0;
  772. os_free(hapd->conf->ap_pin);
  773. hapd->conf->ap_pin = NULL;
  774. }
  775. #ifdef CONFIG_WPS_NFC
  776. struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
  777. int ndef)
  778. {
  779. struct hostapd_data *hapd;
  780. if (wpa_s->ap_iface == NULL)
  781. return NULL;
  782. hapd = wpa_s->ap_iface->bss[0];
  783. return hostapd_wps_nfc_config_token(hapd, ndef);
  784. }
  785. struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
  786. int ndef)
  787. {
  788. struct hostapd_data *hapd;
  789. if (wpa_s->ap_iface == NULL)
  790. return NULL;
  791. hapd = wpa_s->ap_iface->bss[0];
  792. return hostapd_wps_nfc_hs_cr(hapd, ndef);
  793. }
  794. #endif /* CONFIG_WPS_NFC */
  795. #endif /* CONFIG_WPS */
  796. #ifdef CONFIG_CTRL_IFACE
  797. int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
  798. char *buf, size_t buflen)
  799. {
  800. if (wpa_s->ap_iface == NULL)
  801. return -1;
  802. return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
  803. buf, buflen);
  804. }
  805. int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
  806. char *buf, size_t buflen)
  807. {
  808. if (wpa_s->ap_iface == NULL)
  809. return -1;
  810. return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
  811. buf, buflen);
  812. }
  813. int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
  814. char *buf, size_t buflen)
  815. {
  816. if (wpa_s->ap_iface == NULL)
  817. return -1;
  818. return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
  819. buf, buflen);
  820. }
  821. int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
  822. const char *txtaddr)
  823. {
  824. if (wpa_s->ap_iface == NULL)
  825. return -1;
  826. return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
  827. txtaddr);
  828. }
  829. int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
  830. const char *txtaddr)
  831. {
  832. if (wpa_s->ap_iface == NULL)
  833. return -1;
  834. return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
  835. txtaddr);
  836. }
  837. int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
  838. size_t buflen, int verbose)
  839. {
  840. char *pos = buf, *end = buf + buflen;
  841. int ret;
  842. struct hostapd_bss_config *conf;
  843. if (wpa_s->ap_iface == NULL)
  844. return -1;
  845. conf = wpa_s->ap_iface->bss[0]->conf;
  846. if (conf->wpa == 0)
  847. return 0;
  848. ret = os_snprintf(pos, end - pos,
  849. "pairwise_cipher=%s\n"
  850. "group_cipher=%s\n"
  851. "key_mgmt=%s\n",
  852. wpa_cipher_txt(conf->rsn_pairwise),
  853. wpa_cipher_txt(conf->wpa_group),
  854. wpa_key_mgmt_txt(conf->wpa_key_mgmt,
  855. conf->wpa));
  856. if (ret < 0 || ret >= end - pos)
  857. return pos - buf;
  858. pos += ret;
  859. return pos - buf;
  860. }
  861. #endif /* CONFIG_CTRL_IFACE */
  862. int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
  863. {
  864. struct hostapd_iface *iface = wpa_s->ap_iface;
  865. struct wpa_ssid *ssid = wpa_s->current_ssid;
  866. struct hostapd_data *hapd;
  867. if (ssid == NULL || wpa_s->ap_iface == NULL ||
  868. ssid->mode == WPAS_MODE_INFRA ||
  869. ssid->mode == WPAS_MODE_IBSS)
  870. return -1;
  871. #ifdef CONFIG_P2P
  872. if (ssid->mode == WPAS_MODE_P2P_GO)
  873. iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
  874. else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  875. iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
  876. P2P_GROUP_FORMATION;
  877. #endif /* CONFIG_P2P */
  878. hapd = iface->bss[0];
  879. if (hapd->drv_priv == NULL)
  880. return -1;
  881. ieee802_11_set_beacons(iface);
  882. hostapd_set_ap_wps_ie(hapd);
  883. return 0;
  884. }
  885. int ap_switch_channel(struct wpa_supplicant *wpa_s,
  886. struct csa_settings *settings)
  887. {
  888. #ifdef NEED_AP_MLME
  889. if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
  890. return -1;
  891. return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
  892. #else /* NEED_AP_MLME */
  893. return -1;
  894. #endif /* NEED_AP_MLME */
  895. }
  896. int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
  897. {
  898. struct csa_settings settings;
  899. int ret = hostapd_parse_csa_settings(pos, &settings);
  900. if (ret)
  901. return ret;
  902. return ap_switch_channel(wpa_s, &settings);
  903. }
  904. void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
  905. int offset, int width, int cf1, int cf2)
  906. {
  907. if (!wpa_s->ap_iface)
  908. return;
  909. wpa_s->assoc_freq = freq;
  910. hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset, width, cf1, cf1);
  911. }
  912. int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
  913. const u8 *addr)
  914. {
  915. struct hostapd_data *hapd;
  916. struct hostapd_bss_config *conf;
  917. if (!wpa_s->ap_iface)
  918. return -1;
  919. if (addr)
  920. wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
  921. MAC2STR(addr));
  922. else
  923. wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
  924. hapd = wpa_s->ap_iface->bss[0];
  925. conf = hapd->conf;
  926. os_free(conf->accept_mac);
  927. conf->accept_mac = NULL;
  928. conf->num_accept_mac = 0;
  929. os_free(conf->deny_mac);
  930. conf->deny_mac = NULL;
  931. conf->num_deny_mac = 0;
  932. if (addr == NULL) {
  933. conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
  934. return 0;
  935. }
  936. conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
  937. conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
  938. if (conf->accept_mac == NULL)
  939. return -1;
  940. os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
  941. conf->num_accept_mac = 1;
  942. return 0;
  943. }