Lines Matching defs:hapd
33 static int hostapd_wps_upnp_init(struct hostapd_data *hapd,
35 static void hostapd_wps_upnp_deinit(struct hostapd_data *hapd);
60 struct hostapd_data *hapd = iface->bss[j];
63 if (hapd != data->calling_hapd &&
64 (hapd->conf->wps_independent ||
68 ret = data->func(hapd, data->ctx);
77 static int hostapd_wps_for_each(struct hostapd_data *hapd,
81 struct hostapd_iface *iface = hapd->iface;
85 data.calling_hapd = hapd;
98 struct hostapd_data *hapd = ctx;
100 struct hostapd_ssid *ssid = &hapd->conf->ssid;
128 if (hapd->new_psk_cb) {
129 hapd->new_psk_cb(hapd->new_psk_cb_ctx, mac_addr, p2p_dev_addr,
159 struct hostapd_data *hapd = ctx;
160 wpabuf_free(hapd->wps_beacon_ie);
161 hapd->wps_beacon_ie = beacon_ie;
162 wpabuf_free(hapd->wps_probe_resp_ie);
163 hapd->wps_probe_resp_ie = probe_resp_ie;
164 if (hapd->beacon_set_done)
165 ieee802_11_set_beacon(hapd);
166 return hostapd_set_ap_wps_ie(hapd);
173 struct hostapd_data *hapd = ctx;
188 wpa_msg(hapd->msg_ctx, MSG_INFO, "%s", txt);
190 if (hapd->conf->wps_pin_requests) {
193 f = fopen(hapd->conf->wps_pin_requests, "a");
216 static int wps_stop_registrar(struct hostapd_data *hapd, void *ctx)
219 if (hapd != data->current_hapd && hapd->wps != NULL)
220 wps_registrar_complete(hapd->wps->registrar, data->uuid_e,
230 struct hostapd_data *hapd = ctx;
235 wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_REG_SUCCESS MACSTR " %s",
237 if (hapd->wps_reg_success_cb)
238 hapd->wps_reg_success_cb(hapd->wps_reg_success_cb_ctx,
240 data.current_hapd = hapd;
244 hostapd_wps_for_each(hapd, wps_stop_registrar, &data);
255 struct hostapd_data *hapd = ctx;
262 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, WPS_EVENT_ENROLLEE_SEEN MACSTR
290 static void hapd_new_ap_event(struct hostapd_data *hapd, const u8 *attr,
297 wpa_msg(hapd->msg_ctx, MSG_INFO,
304 static int hapd_wps_reconfig_in_memory(struct hostapd_data *hapd,
307 struct hostapd_bss_config *bss = hapd->conf;
405 eloop_register_timeout(0, 100000, wps_reload_config, hapd->iface,
412 static int hapd_wps_cred_cb(struct hostapd_data *hapd, void *ctx)
422 if (hapd->wps == NULL)
439 if ((hapd->conf->wps_cred_processing == 1 ||
440 hapd->conf->wps_cred_processing == 2) && cred->cred_attr) {
441 hapd_new_ap_event(hapd, cred->cred_attr, cred->cred_attr_len);
442 } else if (hapd->conf->wps_cred_processing == 1 ||
443 hapd->conf->wps_cred_processing == 2) {
447 hapd_new_ap_event(hapd, wpabuf_head_u8(attr),
451 wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_NEW_AP_SETTINGS);
453 if (hapd->conf->wps_cred_processing == 1)
456 os_memcpy(hapd->wps->ssid, cred->ssid, cred->ssid_len);
457 hapd->wps->ssid_len = cred->ssid_len;
458 hapd->wps->encr_types = cred->encr_type;
459 hapd->wps->auth_types = cred->auth_type;
461 os_free(hapd->wps->network_key);
462 hapd->wps->network_key = NULL;
463 hapd->wps->network_key_len = 0;
465 if (hapd->wps->network_key == NULL ||
466 hapd->wps->network_key_len < cred->key_len) {
467 hapd->wps->network_key_len = 0;
468 os_free(hapd->wps->network_key);
469 hapd->wps->network_key = os_malloc(cred->key_len);
470 if (hapd->wps->network_key == NULL)
473 hapd->wps->network_key_len = cred->key_len;
474 os_memcpy(hapd->wps->network_key, cred->key, cred->key_len);
476 hapd->wps->wps_state = WPS_STATE_CONFIGURED;
478 if (hapd->iface->config_fname == NULL)
479 return hapd_wps_reconfig_in_memory(hapd, cred);
480 len = os_strlen(hapd->iface->config_fname) + 5;
484 os_snprintf(tmp_fname, len, "%s-new", hapd->iface->config_fname);
486 oconf = fopen(hapd->iface->config_fname, "r");
626 if (rename(tmp_fname, hapd->iface->config_fname) < 0) {
638 eloop_register_timeout(0, 100000, wps_reload_config, hapd->iface,
649 struct hostapd_data *hapd = ctx;
650 return hostapd_wps_for_each(hapd, hapd_wps_cred_cb, (void *) cred);
656 struct hostapd_data *hapd = eloop_data;
658 if (hapd->conf->ap_setup_locked)
660 if (hapd->ap_pin_failures_consecutive >= 10)
664 wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_AP_SETUP_UNLOCKED);
665 hapd->wps->ap_setup_locked = 0;
666 wps_registrar_update_ie(hapd->wps->registrar);
670 static int wps_pwd_auth_fail(struct hostapd_data *hapd, void *ctx)
674 if (!data->enrollee || hapd->conf->ap_pin == NULL || hapd->wps == NULL)
682 hapd->ap_pin_failures++;
683 hapd->ap_pin_failures_consecutive++;
686 hapd->ap_pin_failures, hapd->ap_pin_failures_consecutive);
687 if (hapd->ap_pin_failures < 3)
690 wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_AP_SETUP_LOCKED);
691 hapd->wps->ap_setup_locked = 1;
693 wps_registrar_update_ie(hapd->wps->registrar);
695 if (!hapd->conf->ap_setup_locked &&
696 hapd->ap_pin_failures_consecutive >= 10) {
701 eloop_cancel_timeout(hostapd_wps_reenable_ap_pin, hapd, NULL);
703 } else if (!hapd->conf->ap_setup_locked) {
704 if (hapd->ap_pin_lockout_time == 0)
705 hapd->ap_pin_lockout_time = 60;
706 else if (hapd->ap_pin_lockout_time < 365 * 24 * 60 * 60 &&
707 (hapd->ap_pin_failures % 3) == 0)
708 hapd->ap_pin_lockout_time *= 2;
711 hapd->ap_pin_lockout_time);
712 eloop_cancel_timeout(hostapd_wps_reenable_ap_pin, hapd, NULL);
713 eloop_register_timeout(hapd->ap_pin_lockout_time, 0,
714 hostapd_wps_reenable_ap_pin, hapd,
722 static void hostapd_pwd_auth_fail(struct hostapd_data *hapd,
727 hapd->wps_stats.status = WPS_STATUS_FAILURE;
728 hapd->wps_stats.failure_reason = WPS_EI_AUTH_FAILURE;
729 os_memcpy(hapd->wps_stats.peer_addr, data->peer_macaddr, ETH_ALEN);
731 hostapd_wps_for_each(hapd, wps_pwd_auth_fail, data);
735 static int wps_ap_pin_success(struct hostapd_data *hapd, void *ctx)
737 if (hapd->conf->ap_pin == NULL || hapd->wps == NULL)
740 if (hapd->ap_pin_failures_consecutive == 0)
745 hapd->ap_pin_failures, hapd->ap_pin_failures_consecutive);
746 hapd->ap_pin_failures_consecutive = 0;
752 static void hostapd_wps_ap_pin_success(struct hostapd_data *hapd)
754 hostapd_wps_for_each(hapd, wps_ap_pin_success, NULL);
758 static void hostapd_wps_event_pbc_overlap(struct hostapd_data *hapd)
761 hapd->wps_stats.pbc_status = WPS_PBC_STATUS_OVERLAP;
765 static void hostapd_wps_event_pbc_timeout(struct hostapd_data *hapd)
768 hapd->wps_stats.pbc_status = WPS_PBC_STATUS_TIMEOUT;
772 static void hostapd_wps_event_pbc_active(struct hostapd_data *hapd)
775 hapd->wps_stats.pbc_status = WPS_PBC_STATUS_ACTIVE;
779 static void hostapd_wps_event_pbc_disable(struct hostapd_data *hapd)
782 hapd->wps_stats.pbc_status = WPS_PBC_STATUS_DISABLE;
786 static void hostapd_wps_event_success(struct hostapd_data *hapd,
790 hapd->wps_stats.pbc_status = WPS_PBC_STATUS_DISABLE;
791 hapd->wps_stats.status = WPS_STATUS_SUCCESS;
792 os_memcpy(hapd->wps_stats.peer_addr, success->peer_macaddr, ETH_ALEN);
796 static void hostapd_wps_event_fail(struct hostapd_data *hapd,
800 hapd->wps_stats.status = WPS_STATUS_FAILURE;
801 os_memcpy(hapd->wps_stats.peer_addr, fail->peer_macaddr, ETH_ALEN);
803 hapd->wps_stats.failure_reason = fail->error_indication;
807 wpa_msg(hapd->msg_ctx, MSG_INFO,
812 wpa_msg(hapd->msg_ctx, MSG_INFO,
822 struct hostapd_data *hapd = ctx;
826 wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_M2D);
829 hostapd_wps_event_fail(hapd, &data->fail);
832 hostapd_wps_event_success(hapd, &data->success);
833 wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_SUCCESS);
836 hostapd_pwd_auth_fail(hapd, &data->pwd_auth_fail);
839 hostapd_wps_event_pbc_overlap(hapd);
840 wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_OVERLAP);
843 hostapd_wps_event_pbc_timeout(hapd);
844 wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_TIMEOUT);
847 hostapd_wps_event_pbc_active(hapd);
848 wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_ACTIVE);
851 hostapd_wps_event_pbc_disable(hapd);
852 wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_DISABLE);
867 hostapd_wps_ap_pin_success(hapd);
870 if (hapd->wps_event_cb)
871 hapd->wps_event_cb(hapd->wps_event_cb_ctx, event, data);
877 struct hostapd_data *hapd = ctx;
879 return hapd->iconf->hw_mode == HOSTAPD_MODE_IEEE80211A ?
884 static void hostapd_wps_clear_ies(struct hostapd_data *hapd)
886 wpabuf_free(hapd->wps_beacon_ie);
887 hapd->wps_beacon_ie = NULL;
889 wpabuf_free(hapd->wps_probe_resp_ie);
890 hapd->wps_probe_resp_ie = NULL;
892 hostapd_set_ap_wps_ie(hapd);
904 struct hostapd_data *hapd = iface->bss[j];
905 if (hapd->wps && !hapd->conf->wps_independent &&
906 !is_nil_uuid(hapd->wps->uuid)) {
907 *uuid = hapd->wps->uuid;
949 static int hostapd_wps_set_vendor_ext(struct hostapd_data *hapd,
958 if (hapd->conf->wps_vendor_ext[i] == NULL)
962 wpabuf_dup(hapd->conf->wps_vendor_ext[i]);
974 int hostapd_init_wps(struct hostapd_data *hapd,
981 hostapd_wps_clear_ies(hapd);
992 wps->cb_ctx = hapd;
995 wps->wps_state = hapd->conf->wps_state;
996 wps->ap_setup_locked = hapd->conf->ap_setup_locked;
997 if (is_nil_uuid(hapd->conf->uuid)) {
999 uuid = get_own_uuid(hapd->iface);
1005 uuid_gen_mac_addr(hapd->own_addr, wps->uuid);
1010 os_memcpy(wps->uuid, hapd->conf->uuid, UUID_LEN);
1014 wps->ssid_len = hapd->conf->ssid.ssid_len;
1015 os_memcpy(wps->ssid, hapd->conf->ssid.ssid, wps->ssid_len);
1017 os_memcpy(wps->dev.mac_addr, hapd->own_addr, ETH_ALEN);
1018 wps->dev.device_name = hapd->conf->device_name ?
1019 os_strdup(hapd->conf->device_name) : NULL;
1020 wps->dev.manufacturer = hapd->conf->manufacturer ?
1021 os_strdup(hapd->conf->manufacturer) : NULL;
1022 wps->dev.model_name = hapd->conf->model_name ?
1023 os_strdup(hapd->conf->model_name) : NULL;
1024 wps->dev.model_number = hapd->conf->model_number ?
1025 os_strdup(hapd->conf->model_number) : NULL;
1026 wps->dev.serial_number = hapd->conf->serial_number ?
1027 os_strdup(hapd->conf->serial_number) : NULL;
1029 wps_config_methods_str2bin(hapd->conf->config_methods);
1046 os_memcpy(wps->dev.pri_dev_type, hapd->conf->device_type,
1049 if (hostapd_wps_set_vendor_ext(hapd, wps) < 0) {
1054 wps->dev.os_version = WPA_GET_BE32(hapd->conf->os_version);
1060 hapd->iconf->hw_mode == HOSTAPD_MODE_IEEE80211A ?
1149 cfg.cb_ctx = hapd;
1153 cfg.disable_auto_conf = (hapd->conf->wps_cred_processing == 1) &&
1157 cfg.dualband = interface_count(hapd->iface) > 1;
1174 wps->friendly_name = hapd->conf->friendly_name;
1175 wps->manufacturer_url = hapd->conf->manufacturer_url;
1176 wps->model_description = hapd->conf->model_description;
1177 wps->model_url = hapd->conf->model_url;
1178 wps->upc = hapd->conf->upc;
1181 hostapd_register_probereq_cb(hapd, hostapd_wps_probe_req_rx, hapd);
1183 hapd->wps = wps;
1189 int hostapd_init_wps_complete(struct hostapd_data *hapd)
1191 struct wps_context *wps = hapd->wps;
1197 if (hostapd_wps_upnp_init(hapd, wps) < 0) {
1202 hapd->wps = NULL;
1225 void hostapd_deinit_wps(struct hostapd_data *hapd)
1227 eloop_cancel_timeout(hostapd_wps_reenable_ap_pin, hapd, NULL);
1228 eloop_cancel_timeout(hostapd_wps_ap_pin_timeout, hapd, NULL);
1229 if (hapd->wps == NULL)
1232 hostapd_wps_upnp_deinit(hapd);
1234 wps_registrar_deinit(hapd->wps->registrar);
1235 os_free(hapd->wps->network_key);
1236 wps_device_data_free(&hapd->wps->dev);
1237 wpabuf_free(hapd->wps->dh_pubkey);
1238 wpabuf_free(hapd->wps->dh_privkey);
1239 wps_free_pending_msgs(hapd->wps->upnp_msgs);
1240 hostapd_wps_nfc_clear(hapd->wps);
1241 os_free(hapd->wps);
1242 hapd->wps = NULL;
1243 hostapd_wps_clear_ies(hapd);
1247 void hostapd_update_wps(struct hostapd_data *hapd)
1249 if (hapd->wps == NULL)
1253 hapd->wps->friendly_name = hapd->conf->friendly_name;
1254 hapd->wps->manufacturer_url = hapd->conf->manufacturer_url;
1255 hapd->wps->model_description = hapd->conf->model_description;
1256 hapd->wps->model_url = hapd->conf->model_url;
1257 hapd->wps->upc = hapd->conf->upc;
1260 hostapd_wps_set_vendor_ext(hapd, hapd->wps);
1262 if (hapd->conf->wps_state)
1263 wps_registrar_update_ie(hapd->wps->registrar);
1265 hostapd_deinit_wps(hapd);
1279 static int wps_add_pin(struct hostapd_data *hapd, void *ctx)
1284 if (hapd->wps == NULL)
1286 ret = wps_registrar_add_pin(hapd->wps->registrar, data->addr,
1295 int hostapd_wps_add_pin(struct hostapd_data *hapd, const u8 *addr,
1315 if (hostapd_wps_for_each(hapd, wps_add_pin, &data) < 0)
1321 static int wps_button_pushed(struct hostapd_data *hapd, void *ctx)
1324 if (hapd->wps == NULL)
1326 return wps_registrar_button_pushed(hapd->wps->registrar, p2p_dev_addr);
1330 int hostapd_wps_button_pushed(struct hostapd_data *hapd,
1333 return hostapd_wps_for_each(hapd, wps_button_pushed,
1338 static int wps_cancel(struct hostapd_data *hapd, void *ctx)
1340 if (hapd->wps == NULL)
1343 wps_registrar_wps_cancel(hapd->wps->registrar);
1344 ap_for_each_sta(hapd, ap_sta_wps_cancel, NULL);
1350 int hostapd_wps_cancel(struct hostapd_data *hapd)
1352 return hostapd_wps_for_each(hapd, wps_cancel, NULL);
1361 struct hostapd_data *hapd = ctx;
1365 if (hapd->wps == NULL)
1375 (elems.ssid_len != hapd->conf->ssid.ssid_len ||
1376 os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) !=
1396 wps_registrar_probe_req_rx(hapd->wps->registrar, addr, wps_ie,
1403 hapd->wps_upnp, addr,
1421 struct hostapd_data *hapd = priv;
1440 sta = ap_get_sta(hapd, mac_addr);
1450 for (sta = hapd->sta_list; sta; sta = sta->next) {
1468 p->next = hapd->wps->upnp_msgs;
1469 hapd->wps->upnp_msgs = p;
1475 static int hostapd_wps_upnp_init(struct hostapd_data *hapd,
1480 if (!hapd->conf->upnp_iface)
1487 if (hapd->conf->ap_pin)
1488 ctx->ap_pin = os_strdup(hapd->conf->ap_pin);
1490 hapd->wps_upnp = upnp_wps_device_init(ctx, wps, hapd,
1491 hapd->conf->upnp_iface);
1492 if (hapd->wps_upnp == NULL)
1494 wps->wps_upnp = hapd->wps_upnp;
1500 static void hostapd_wps_upnp_deinit(struct hostapd_data *hapd)
1502 upnp_wps_device_deinit(hapd->wps_upnp, hapd);
1508 int hostapd_wps_get_mib_sta(struct hostapd_data *hapd, const u8 *addr,
1511 if (hapd->wps == NULL)
1513 return wps_registrar_get_info(hapd->wps->registrar, addr, buf, buflen);
1519 struct hostapd_data *hapd = eloop_data;
1521 hostapd_wps_ap_pin_disable(hapd);
1522 wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_AP_PIN_DISABLED);
1526 static void hostapd_wps_ap_pin_enable(struct hostapd_data *hapd, int timeout)
1529 hapd->ap_pin_failures = 0;
1530 hapd->ap_pin_failures_consecutive = 0;
1531 hapd->conf->ap_setup_locked = 0;
1532 if (hapd->wps->ap_setup_locked) {
1533 wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_AP_SETUP_UNLOCKED);
1534 hapd->wps->ap_setup_locked = 0;
1535 wps_registrar_update_ie(hapd->wps->registrar);
1537 eloop_cancel_timeout(hostapd_wps_ap_pin_timeout, hapd, NULL);
1540 hostapd_wps_ap_pin_timeout, hapd, NULL);
1544 static int wps_ap_pin_disable(struct hostapd_data *hapd, void *ctx)
1546 os_free(hapd->conf->ap_pin);
1547 hapd->conf->ap_pin = NULL;
1549 upnp_wps_set_ap_pin(hapd->wps_upnp, NULL);
1551 eloop_cancel_timeout(hostapd_wps_ap_pin_timeout, hapd, NULL);
1556 void hostapd_wps_ap_pin_disable(struct hostapd_data *hapd)
1559 hostapd_wps_for_each(hapd, wps_ap_pin_disable, NULL);
1569 static int wps_ap_pin_set(struct hostapd_data *hapd, void *ctx)
1572 os_free(hapd->conf->ap_pin);
1573 hapd->conf->ap_pin = os_strdup(data->pin_txt);
1575 upnp_wps_set_ap_pin(hapd->wps_upnp, data->pin_txt);
1577 hostapd_wps_ap_pin_enable(hapd, data->timeout);
1582 const char * hostapd_wps_ap_pin_random(struct hostapd_data *hapd, int timeout)
1590 hostapd_wps_for_each(hapd, wps_ap_pin_set, &data);
1591 return hapd->conf->ap_pin;
1595 const char * hostapd_wps_ap_pin_get(struct hostapd_data *hapd)
1597 return hapd->conf->ap_pin;
1601 int hostapd_wps_ap_pin_set(struct hostapd_data *hapd, const char *pin,
1611 return hostapd_wps_for_each(hapd, wps_ap_pin_set, &data);
1615 static int wps_update_ie(struct hostapd_data *hapd, void *ctx)
1617 if (hapd->wps)
1618 wps_registrar_update_ie(hapd->wps->registrar);
1623 void hostapd_wps_update_ie(struct hostapd_data *hapd)
1625 hostapd_wps_for_each(hapd, wps_update_ie, NULL);
1629 int hostapd_wps_config_ap(struct hostapd_data *hapd, const char *ssid,
1674 return wps_registrar_config_ap(hapd->wps->registrar, &cred);
1687 static int wps_add_nfc_password_token(struct hostapd_data *hapd, void *ctx)
1692 if (hapd->wps == NULL)
1694 ret = wps_registrar_add_nfc_password_token(hapd->wps->registrar,
1703 static int hostapd_wps_add_nfc_password_token(struct hostapd_data *hapd,
1711 if (hostapd_wps_for_each(hapd, wps_add_nfc_password_token, &data) < 0)
1717 static int hostapd_wps_nfc_tag_process(struct hostapd_data *hapd,
1730 return hostapd_wps_add_nfc_password_token(hapd, &attr);
1737 int hostapd_wps_nfc_tag_read(struct hostapd_data *hapd,
1757 ret = hostapd_wps_nfc_tag_process(hapd, wps);
1763 struct wpabuf * hostapd_wps_nfc_config_token(struct hostapd_data *hapd,
1768 if (hapd->wps == NULL)
1771 ret = wps_get_oob_cred(hapd->wps);
1785 struct wpabuf * hostapd_wps_nfc_hs_cr(struct hostapd_data *hapd, int ndef)
1791 return hostapd_wps_nfc_config_token(hapd, ndef);
1795 struct wpabuf * hostapd_wps_nfc_token_gen(struct hostapd_data *hapd, int ndef)
1797 if (hapd->conf->wps_nfc_pw_from_config) {
1799 hapd->conf->wps_nfc_dev_pw_id,
1800 hapd->conf->wps_nfc_dh_pubkey,
1801 hapd->conf->wps_nfc_dev_pw);
1804 return wps_nfc_token_gen(ndef, &hapd->conf->wps_nfc_dev_pw_id,
1805 &hapd->conf->wps_nfc_dh_pubkey,
1806 &hapd->conf->wps_nfc_dh_privkey,
1807 &hapd->conf->wps_nfc_dev_pw);
1811 int hostapd_wps_nfc_token_enable(struct hostapd_data *hapd)
1813 struct wps_context *wps = hapd->wps;
1819 if (!hapd->conf->wps_nfc_dh_pubkey ||
1820 !hapd->conf->wps_nfc_dh_privkey ||
1821 !hapd->conf->wps_nfc_dev_pw ||
1822 !hapd->conf->wps_nfc_dev_pw_id)
1826 wps->ap_nfc_dev_pw_id = hapd->conf->wps_nfc_dev_pw_id;
1827 wps->ap_nfc_dh_pubkey = wpabuf_dup(hapd->conf->wps_nfc_dh_pubkey);
1828 wps->ap_nfc_dh_privkey = wpabuf_dup(hapd->conf->wps_nfc_dh_privkey);
1829 pw = hapd->conf->wps_nfc_dev_pw;
1850 void hostapd_wps_nfc_token_disable(struct hostapd_data *hapd)
1852 hostapd_wps_nfc_clear(hapd->wps);