ap.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  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 = 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 = wpa_s->pairwise_cipher;
  454. params.group_suite = params.pairwise_suite;
  455. #ifdef CONFIG_P2P
  456. if (ssid->mode == WPAS_MODE_P2P_GO ||
  457. ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  458. params.p2p = 1;
  459. #endif /* CONFIG_P2P */
  460. if (wpa_s->parent->set_ap_uapsd)
  461. params.uapsd = wpa_s->parent->ap_uapsd;
  462. else
  463. params.uapsd = -1;
  464. if (wpa_drv_associate(wpa_s, &params) < 0) {
  465. wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
  466. return -1;
  467. }
  468. wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
  469. if (hapd_iface == NULL)
  470. return -1;
  471. hapd_iface->owner = wpa_s;
  472. hapd_iface->drv_flags = wpa_s->drv_flags;
  473. hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
  474. hapd_iface->extended_capa = wpa_s->extended_capa;
  475. hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
  476. hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
  477. wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
  478. if (conf == NULL) {
  479. wpa_supplicant_ap_deinit(wpa_s);
  480. return -1;
  481. }
  482. os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
  483. wpa_s->conf->wmm_ac_params,
  484. sizeof(wpa_s->conf->wmm_ac_params));
  485. if (params.uapsd > 0) {
  486. conf->bss[0]->wmm_enabled = 1;
  487. conf->bss[0]->wmm_uapsd = 1;
  488. }
  489. if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
  490. wpa_printf(MSG_ERROR, "Failed to create AP configuration");
  491. wpa_supplicant_ap_deinit(wpa_s);
  492. return -1;
  493. }
  494. #ifdef CONFIG_P2P
  495. if (ssid->mode == WPAS_MODE_P2P_GO)
  496. conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
  497. else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  498. conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
  499. P2P_GROUP_FORMATION;
  500. #endif /* CONFIG_P2P */
  501. hapd_iface->num_bss = conf->num_bss;
  502. hapd_iface->bss = os_calloc(conf->num_bss,
  503. sizeof(struct hostapd_data *));
  504. if (hapd_iface->bss == NULL) {
  505. wpa_supplicant_ap_deinit(wpa_s);
  506. return -1;
  507. }
  508. for (i = 0; i < conf->num_bss; i++) {
  509. hapd_iface->bss[i] =
  510. hostapd_alloc_bss_data(hapd_iface, conf,
  511. conf->bss[i]);
  512. if (hapd_iface->bss[i] == NULL) {
  513. wpa_supplicant_ap_deinit(wpa_s);
  514. return -1;
  515. }
  516. hapd_iface->bss[i]->msg_ctx = wpa_s;
  517. hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
  518. hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
  519. hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
  520. hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
  521. hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
  522. hostapd_register_probereq_cb(hapd_iface->bss[i],
  523. ap_probe_req_rx, wpa_s);
  524. hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
  525. hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
  526. hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
  527. hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
  528. hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
  529. hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
  530. #ifdef CONFIG_P2P
  531. hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
  532. hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
  533. hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
  534. hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
  535. ssid);
  536. #endif /* CONFIG_P2P */
  537. hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
  538. hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
  539. }
  540. os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
  541. hapd_iface->bss[0]->driver = wpa_s->driver;
  542. hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
  543. wpa_s->current_ssid = ssid;
  544. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  545. os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
  546. wpa_s->assoc_freq = ssid->frequency;
  547. if (hostapd_setup_interface(wpa_s->ap_iface)) {
  548. wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
  549. wpa_supplicant_ap_deinit(wpa_s);
  550. return -1;
  551. }
  552. return 0;
  553. }
  554. void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
  555. {
  556. #ifdef CONFIG_WPS
  557. eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
  558. #endif /* CONFIG_WPS */
  559. if (wpa_s->ap_iface == NULL)
  560. return;
  561. wpa_s->current_ssid = NULL;
  562. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  563. wpa_s->assoc_freq = 0;
  564. #ifdef CONFIG_P2P
  565. if (wpa_s->ap_iface->bss)
  566. wpa_s->ap_iface->bss[0]->p2p_group = NULL;
  567. wpas_p2p_group_deinit(wpa_s);
  568. #endif /* CONFIG_P2P */
  569. hostapd_interface_deinit(wpa_s->ap_iface);
  570. hostapd_interface_free(wpa_s->ap_iface);
  571. wpa_s->ap_iface = NULL;
  572. wpa_drv_deinit_ap(wpa_s);
  573. }
  574. void ap_tx_status(void *ctx, const u8 *addr,
  575. const u8 *buf, size_t len, int ack)
  576. {
  577. #ifdef NEED_AP_MLME
  578. struct wpa_supplicant *wpa_s = ctx;
  579. hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
  580. #endif /* NEED_AP_MLME */
  581. }
  582. void ap_eapol_tx_status(void *ctx, const u8 *dst,
  583. const u8 *data, size_t len, int ack)
  584. {
  585. #ifdef NEED_AP_MLME
  586. struct wpa_supplicant *wpa_s = ctx;
  587. hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
  588. #endif /* NEED_AP_MLME */
  589. }
  590. void ap_client_poll_ok(void *ctx, const u8 *addr)
  591. {
  592. #ifdef NEED_AP_MLME
  593. struct wpa_supplicant *wpa_s = ctx;
  594. if (wpa_s->ap_iface)
  595. hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
  596. #endif /* NEED_AP_MLME */
  597. }
  598. void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
  599. {
  600. #ifdef NEED_AP_MLME
  601. struct wpa_supplicant *wpa_s = ctx;
  602. ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
  603. #endif /* NEED_AP_MLME */
  604. }
  605. void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
  606. {
  607. #ifdef NEED_AP_MLME
  608. struct wpa_supplicant *wpa_s = ctx;
  609. struct hostapd_frame_info fi;
  610. os_memset(&fi, 0, sizeof(fi));
  611. fi.datarate = rx_mgmt->datarate;
  612. fi.ssi_signal = rx_mgmt->ssi_signal;
  613. ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
  614. rx_mgmt->frame_len, &fi);
  615. #endif /* NEED_AP_MLME */
  616. }
  617. void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
  618. {
  619. #ifdef NEED_AP_MLME
  620. struct wpa_supplicant *wpa_s = ctx;
  621. ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
  622. #endif /* NEED_AP_MLME */
  623. }
  624. void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
  625. const u8 *src_addr, const u8 *buf, size_t len)
  626. {
  627. ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
  628. }
  629. #ifdef CONFIG_WPS
  630. int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
  631. const u8 *p2p_dev_addr)
  632. {
  633. if (!wpa_s->ap_iface)
  634. return -1;
  635. return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
  636. p2p_dev_addr);
  637. }
  638. int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
  639. {
  640. struct wps_registrar *reg;
  641. int reg_sel = 0, wps_sta = 0;
  642. if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
  643. return -1;
  644. reg = wpa_s->ap_iface->bss[0]->wps->registrar;
  645. reg_sel = wps_registrar_wps_cancel(reg);
  646. wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
  647. ap_sta_wps_cancel, NULL);
  648. if (!reg_sel && !wps_sta) {
  649. wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
  650. "time");
  651. return -1;
  652. }
  653. /*
  654. * There are 2 cases to return wps cancel as success:
  655. * 1. When wps cancel was initiated but no connection has been
  656. * established with client yet.
  657. * 2. Client is in the middle of exchanging WPS messages.
  658. */
  659. return 0;
  660. }
  661. int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
  662. const char *pin, char *buf, size_t buflen,
  663. int timeout)
  664. {
  665. int ret, ret_len = 0;
  666. if (!wpa_s->ap_iface)
  667. return -1;
  668. if (pin == NULL) {
  669. unsigned int rpin = wps_generate_pin();
  670. ret_len = os_snprintf(buf, buflen, "%08d", rpin);
  671. pin = buf;
  672. } else
  673. ret_len = os_snprintf(buf, buflen, "%s", pin);
  674. ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
  675. timeout);
  676. if (ret)
  677. return -1;
  678. return ret_len;
  679. }
  680. static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
  681. {
  682. struct wpa_supplicant *wpa_s = eloop_data;
  683. wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
  684. wpas_wps_ap_pin_disable(wpa_s);
  685. }
  686. static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
  687. {
  688. struct hostapd_data *hapd;
  689. if (wpa_s->ap_iface == NULL)
  690. return;
  691. hapd = wpa_s->ap_iface->bss[0];
  692. wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
  693. hapd->ap_pin_failures = 0;
  694. eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
  695. if (timeout > 0)
  696. eloop_register_timeout(timeout, 0,
  697. wpas_wps_ap_pin_timeout, wpa_s, NULL);
  698. }
  699. void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
  700. {
  701. struct hostapd_data *hapd;
  702. if (wpa_s->ap_iface == NULL)
  703. return;
  704. wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
  705. hapd = wpa_s->ap_iface->bss[0];
  706. os_free(hapd->conf->ap_pin);
  707. hapd->conf->ap_pin = NULL;
  708. eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
  709. }
  710. const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
  711. {
  712. struct hostapd_data *hapd;
  713. unsigned int pin;
  714. char pin_txt[9];
  715. if (wpa_s->ap_iface == NULL)
  716. return NULL;
  717. hapd = wpa_s->ap_iface->bss[0];
  718. pin = wps_generate_pin();
  719. os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
  720. os_free(hapd->conf->ap_pin);
  721. hapd->conf->ap_pin = os_strdup(pin_txt);
  722. if (hapd->conf->ap_pin == NULL)
  723. return NULL;
  724. wpas_wps_ap_pin_enable(wpa_s, timeout);
  725. return hapd->conf->ap_pin;
  726. }
  727. const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
  728. {
  729. struct hostapd_data *hapd;
  730. if (wpa_s->ap_iface == NULL)
  731. return NULL;
  732. hapd = wpa_s->ap_iface->bss[0];
  733. return hapd->conf->ap_pin;
  734. }
  735. int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
  736. int timeout)
  737. {
  738. struct hostapd_data *hapd;
  739. char pin_txt[9];
  740. int ret;
  741. if (wpa_s->ap_iface == NULL)
  742. return -1;
  743. hapd = wpa_s->ap_iface->bss[0];
  744. ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
  745. if (ret < 0 || ret >= (int) sizeof(pin_txt))
  746. return -1;
  747. os_free(hapd->conf->ap_pin);
  748. hapd->conf->ap_pin = os_strdup(pin_txt);
  749. if (hapd->conf->ap_pin == NULL)
  750. return -1;
  751. wpas_wps_ap_pin_enable(wpa_s, timeout);
  752. return 0;
  753. }
  754. void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
  755. {
  756. struct hostapd_data *hapd;
  757. if (wpa_s->ap_iface == NULL)
  758. return;
  759. hapd = wpa_s->ap_iface->bss[0];
  760. /*
  761. * Registrar failed to prove its knowledge of the AP PIN. Disable AP
  762. * PIN if this happens multiple times to slow down brute force attacks.
  763. */
  764. hapd->ap_pin_failures++;
  765. wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
  766. hapd->ap_pin_failures);
  767. if (hapd->ap_pin_failures < 3)
  768. return;
  769. wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
  770. hapd->ap_pin_failures = 0;
  771. os_free(hapd->conf->ap_pin);
  772. hapd->conf->ap_pin = NULL;
  773. }
  774. #ifdef CONFIG_WPS_NFC
  775. struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
  776. int ndef)
  777. {
  778. struct hostapd_data *hapd;
  779. if (wpa_s->ap_iface == NULL)
  780. return NULL;
  781. hapd = wpa_s->ap_iface->bss[0];
  782. return hostapd_wps_nfc_config_token(hapd, ndef);
  783. }
  784. struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
  785. int ndef)
  786. {
  787. struct hostapd_data *hapd;
  788. if (wpa_s->ap_iface == NULL)
  789. return NULL;
  790. hapd = wpa_s->ap_iface->bss[0];
  791. return hostapd_wps_nfc_hs_cr(hapd, ndef);
  792. }
  793. #endif /* CONFIG_WPS_NFC */
  794. #endif /* CONFIG_WPS */
  795. #ifdef CONFIG_CTRL_IFACE
  796. int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
  797. char *buf, size_t buflen)
  798. {
  799. if (wpa_s->ap_iface == NULL)
  800. return -1;
  801. return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
  802. buf, buflen);
  803. }
  804. int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
  805. char *buf, size_t buflen)
  806. {
  807. if (wpa_s->ap_iface == NULL)
  808. return -1;
  809. return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
  810. buf, buflen);
  811. }
  812. int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
  813. char *buf, size_t buflen)
  814. {
  815. if (wpa_s->ap_iface == NULL)
  816. return -1;
  817. return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
  818. buf, buflen);
  819. }
  820. int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
  821. const char *txtaddr)
  822. {
  823. if (wpa_s->ap_iface == NULL)
  824. return -1;
  825. return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
  826. txtaddr);
  827. }
  828. int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
  829. const char *txtaddr)
  830. {
  831. if (wpa_s->ap_iface == NULL)
  832. return -1;
  833. return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
  834. txtaddr);
  835. }
  836. int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
  837. size_t buflen, int verbose)
  838. {
  839. char *pos = buf, *end = buf + buflen;
  840. int ret;
  841. struct hostapd_bss_config *conf;
  842. if (wpa_s->ap_iface == NULL)
  843. return -1;
  844. conf = wpa_s->ap_iface->bss[0]->conf;
  845. if (conf->wpa == 0)
  846. return 0;
  847. ret = os_snprintf(pos, end - pos,
  848. "pairwise_cipher=%s\n"
  849. "group_cipher=%s\n"
  850. "key_mgmt=%s\n",
  851. wpa_cipher_txt(conf->rsn_pairwise),
  852. wpa_cipher_txt(conf->wpa_group),
  853. wpa_key_mgmt_txt(conf->wpa_key_mgmt,
  854. conf->wpa));
  855. if (ret < 0 || ret >= end - pos)
  856. return pos - buf;
  857. pos += ret;
  858. return pos - buf;
  859. }
  860. #endif /* CONFIG_CTRL_IFACE */
  861. int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
  862. {
  863. struct hostapd_iface *iface = wpa_s->ap_iface;
  864. struct wpa_ssid *ssid = wpa_s->current_ssid;
  865. struct hostapd_data *hapd;
  866. if (ssid == NULL || wpa_s->ap_iface == NULL ||
  867. ssid->mode == WPAS_MODE_INFRA ||
  868. ssid->mode == WPAS_MODE_IBSS)
  869. return -1;
  870. #ifdef CONFIG_P2P
  871. if (ssid->mode == WPAS_MODE_P2P_GO)
  872. iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
  873. else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  874. iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
  875. P2P_GROUP_FORMATION;
  876. #endif /* CONFIG_P2P */
  877. hapd = iface->bss[0];
  878. if (hapd->drv_priv == NULL)
  879. return -1;
  880. ieee802_11_set_beacons(iface);
  881. hostapd_set_ap_wps_ie(hapd);
  882. return 0;
  883. }
  884. int ap_switch_channel(struct wpa_supplicant *wpa_s,
  885. struct csa_settings *settings)
  886. {
  887. #ifdef NEED_AP_MLME
  888. if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
  889. return -1;
  890. return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
  891. #else /* NEED_AP_MLME */
  892. return -1;
  893. #endif /* NEED_AP_MLME */
  894. }
  895. int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
  896. {
  897. struct csa_settings settings;
  898. int ret = hostapd_parse_csa_settings(pos, &settings);
  899. if (ret)
  900. return ret;
  901. return ap_switch_channel(wpa_s, &settings);
  902. }
  903. void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
  904. int offset, int width, int cf1, int cf2)
  905. {
  906. if (!wpa_s->ap_iface)
  907. return;
  908. wpa_s->assoc_freq = freq;
  909. hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset, width, cf1, cf1);
  910. }
  911. int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
  912. const u8 *addr)
  913. {
  914. struct hostapd_data *hapd;
  915. struct hostapd_bss_config *conf;
  916. if (!wpa_s->ap_iface)
  917. return -1;
  918. if (addr)
  919. wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
  920. MAC2STR(addr));
  921. else
  922. wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
  923. hapd = wpa_s->ap_iface->bss[0];
  924. conf = hapd->conf;
  925. os_free(conf->accept_mac);
  926. conf->accept_mac = NULL;
  927. conf->num_accept_mac = 0;
  928. os_free(conf->deny_mac);
  929. conf->deny_mac = NULL;
  930. conf->num_deny_mac = 0;
  931. if (addr == NULL) {
  932. conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
  933. return 0;
  934. }
  935. conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
  936. conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
  937. if (conf->accept_mac == NULL)
  938. return -1;
  939. os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
  940. conf->num_accept_mac = 1;
  941. return 0;
  942. }