Home | History | Annotate | Download | only in wps

Lines Matching defs:ap

28 static void wps_er_ap_process(struct wps_er_ap *ap, struct wpabuf *msg);
29 static int wps_er_send_get_device_info(struct wps_er_ap *ap,
30 void (*m1_handler)(struct wps_er_ap *ap,
59 static struct wps_er_sta * wps_er_sta_get(struct wps_er_ap *ap, const u8 *addr,
63 dl_list_for_each(sta, &ap->sta, struct wps_er_sta, list) {
76 wps_er_sta_event(sta->ap->er->wps, sta, WPS_EV_ER_ENROLLEE_REMOVE);
91 static void wps_er_sta_remove_all(struct wps_er_ap *ap)
94 dl_list_for_each_safe(sta, prev, &ap->sta, struct wps_er_sta, list)
103 struct wps_er_ap *ap;
104 dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
105 if ((addr == NULL || ap->addr.s_addr == addr->s_addr) &&
107 os_memcmp(uuid, ap->uuid, WPS_UUID_LEN) == 0) &&
109 os_memcmp(mac_addr, ap->mac_addr, ETH_ALEN) == 0))
110 return ap;
118 struct wps_er_ap *ap;
119 dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
120 if (ap->id == id)
121 return ap;
127 static void wps_er_ap_event(struct wps_context *wps, struct wps_er_ap *ap,
131 struct wps_event_er_ap *evap = &data.ap;
137 evap->uuid = ap->uuid;
138 evap->friendly_name = ap->friendly_name;
139 evap->manufacturer = ap->manufacturer;
140 evap->manufacturer_url = ap->manufacturer_url;
141 evap->model_description = ap->model_description;
142 evap->model_name = ap->model_name;
143 evap->model_number = ap->model_number;
144 evap->model_url = ap->model_url;
145 evap->serial_number = ap->serial_number;
146 evap->upc = ap->upc;
147 evap->pri_dev_type = ap->pri_dev_type;
148 evap->wps_state = ap->wps_state;
149 evap->mac_addr = ap->mac_addr;
154 static void wps_er_ap_free(struct wps_er_ap *ap)
156 http_client_free(ap->http);
157 ap->http = NULL;
159 os_free(ap->location);
160 os_free(ap->friendly_name);
161 os_free(ap->manufacturer);
162 os_free(ap->manufacturer_url);
163 os_free(ap->model_description);
164 os_free(ap->model_name);
165 os_free(ap->model_number);
166 os_free(ap->model_url);
167 os_free(ap->serial_number);
168 os_free(ap->udn);
169 os_free(ap->upc);
171 os_free(ap->scpd_url);
172 os_free(ap->control_url);
173 os_free(ap->event_sub_url);
175 os_free(ap->ap_settings);
177 os_free(ap);
181 static void wps_er_ap_unsubscribed(struct wps_er *er, struct wps_er_ap *ap)
183 wpa_printf(MSG_DEBUG, "WPS ER: Unsubscribed from AP %s (%s)",
184 inet_ntoa(ap->addr), ap->location);
185 dl_list_del(&ap->list);
186 wps_er_ap_free(ap);
196 struct wps_er_ap *ap = ctx;
201 ap->subscribed = 0;
210 http_client_free(ap->http);
211 ap->http = NULL;
214 * Need to get rid of the AP entry regardless of whether we managed to
217 wps_er_ap_unsubscribed(ap->er, ap);
221 static void wps_er_ap_unsubscribe(struct wps_er *er, struct wps_er_ap *ap)
228 if (ap->event_sub_url == NULL) {
233 if (ap->http) {
239 url = http_client_url_parse(ap->event_sub_url, &dst, &path);
245 req = wpabuf_alloc(os_strlen(ap->event_sub_url) + 1000);
250 uuid_bin2str(ap->sid, sid, sizeof(sid));
261 ap->http = http_client_addr(&dst, req, 1000,
262 wps_er_http_unsubscribe_cb, ap);
263 if (ap->http == NULL) {
271 * Need to get rid of the AP entry even when we fail to unsubscribe
274 wps_er_ap_unsubscribed(ap->er, ap);
291 struct wps_er_ap *ap;
294 ap = wps_er_ap_get(er, addr, NULL, NULL);
295 if (ap == NULL || ap->ap_settings == NULL)
298 settings = wps_er_ap_get_settings(er, ap->uuid);
303 os_memcpy(settings->uuid, ap->uuid, WPS_UUID_LEN);
306 os_memcpy(&settings->ap_settings, ap->ap_settings,
314 struct wps_er_ap *ap)
318 if (ap->ap_settings)
321 s = wps_er_ap_get_settings(ap->er, ap->uuid);
325 ap->ap_settings = os_malloc(sizeof(*ap->ap_settings));
326 if (ap->ap_settings == NULL)
329 os_memcpy(ap->ap_settings, &s->ap_settings, sizeof(*ap->ap_settings));
330 wpa_printf(MSG_DEBUG, "WPS ER: Use cached AP settings");
335 static void wps_er_ap_remove_entry(struct wps_er *er, struct wps_er_ap *ap)
337 wpa_printf(MSG_DEBUG, "WPS ER: Removing AP entry for %s (%s)",
338 inet_ntoa(ap->addr), ap->location);
339 eloop_cancel_timeout(wps_er_ap_timeout, er, ap);
340 wps_er_sta_remove_all(ap);
341 wps_er_ap_event(er->wps, ap, WPS_EV_ER_AP_REMOVE);
342 http_client_free(ap->http);
343 ap->http = NULL;
344 if (ap->wps) {
345 wps_deinit(ap->wps);
346 ap->wps = NULL;
349 dl_list_del(&ap->list);
350 if (ap->subscribed) {
351 dl_list_add(&er->ap_unsubscribing, &ap->list);
352 wps_er_ap_unsubscribe(er, ap);
354 wps_er_ap_free(ap);
361 struct wps_er_ap *ap = user_ctx;
362 wpa_printf(MSG_DEBUG, "WPS ER: AP advertisement timed out");
363 wps_er_ap_remove_entry(er, ap);
367 static int wps_er_get_sid(struct wps_er_ap *ap, char *sid)
374 inet_ntoa(ap->addr), ap->location);
381 "%s (%s): '%s'", inet_ntoa(ap->addr), ap->location,
387 if (uuid_str2bin(pos, ap->sid) < 0) {
389 "%s (%s): '%s'", inet_ntoa(ap->addr), ap->location,
394 uuid_bin2str(ap->sid, txt, sizeof(txt));
396 inet_ntoa(ap->addr), ap->location, txt);
405 struct wps_er_ap *ap = ctx;
410 ap->subscribed = 1;
411 wps_er_get_sid(ap, http_client_get_hdr_line(c, "SID"));
412 wps_er_ap_use_cached_settings(ap->er, ap);
413 wps_er_ap_event(ap->er->wps, ap, WPS_EV_ER_AP_ADD);
421 http_client_free(ap->http);
422 ap->http = NULL;
426 static void wps_er_subscribe(struct wps_er_ap *ap)
432 if (ap->event_sub_url == NULL) {
437 if (ap->http) {
443 url = http_client_url_parse(ap->event_sub_url, &dst, &path);
449 req = wpabuf_alloc(os_strlen(ap->event_sub_url) + 1000);
462 ap->er->ip_addr_text, ap->er->http_port,
463 ap->er->event_id, ap->id, 1800);
468 ap->http = http_client_addr(&dst, req, 1000, wps_er_http_subscribe_cb,
469 ap);
470 if (ap->http == NULL)
475 static void wps_er_ap_get_m1(struct wps_er_ap *ap, struct wpabuf *m1)
484 os_memcpy(ap->pri_dev_type, attr.primary_dev_type, 8);
486 ap->wps_state = *attr.wps_state;
488 os_memcpy(ap->mac_addr, attr.mac_addr, ETH_ALEN);
490 wps_er_subscribe(ap);
494 static void wps_er_get_device_info(struct wps_er_ap *ap)
496 wps_er_send_get_device_info(ap, wps_er_ap_get_m1);
533 static void wps_er_parse_device_description(struct wps_er_ap *ap,
555 ap->friendly_name = xml_get_first_item(data, "friendlyName");
556 wpa_printf(MSG_DEBUG, "WPS ER: friendlyName='%s'", ap->friendly_name);
558 ap->manufacturer = xml_get_first_item(data, "manufacturer");
559 wpa_printf(MSG_DEBUG, "WPS ER: manufacturer='%s'", ap->manufacturer);
561 ap->manufacturer_url = xml_get_first_item(data, "manufacturerURL");
563 ap->manufacturer_url);
565 ap->model_description = xml_get_first_item(data, "modelDescription");
567 ap->model_description);
569 ap->model_name = xml_get_first_item(data, "modelName");
570 wpa_printf(MSG_DEBUG, "WPS ER: modelName='%s'", ap->model_name);
572 ap->model_number = xml_get_first_item(data, "modelNumber");
573 wpa_printf(MSG_DEBUG, "WPS ER: modelNumber='%s'", ap->model_number);
575 ap->model_url = xml_get_first_item(data, "modelURL");
576 wpa_printf(MSG_DEBUG, "WPS ER: modelURL='%s'", ap->model_url);
578 ap->serial_number = xml_get_first_item(data, "serialNumber");
579 wpa_printf(MSG_DEBUG, "WPS ER: serialNumber='%s'", ap->serial_number);
581 ap->udn = xml_get_first_item(data, "UDN");
582 if (ap->udn) {
583 wpa_printf(MSG_DEBUG, "WPS ER: UDN='%s'", ap->udn);
584 pos = os_strstr(ap->udn, "uuid:");
587 if (uuid_str2bin(pos, ap->uuid) < 0)
593 ap->upc = xml_get_first_item(data, "UPC");
594 wpa_printf(MSG_DEBUG, "WPS ER: UPC='%s'", ap->upc);
596 ap->scpd_url = http_link_update(
597 xml_get_first_item(data, "SCPDURL"), ap->location);
598 wpa_printf(MSG_DEBUG, "WPS ER: SCPDURL='%s'", ap->scpd_url);
600 ap->control_url = http_link_update(
601 xml_get_first_item(data, "controlURL"), ap->location);
602 wpa_printf(MSG_DEBUG, "WPS ER: controlURL='%s'", ap->control_url);
604 ap->event_sub_url = http_link_update(
605 xml_get_first_item(data, "eventSubURL"), ap->location);
606 wpa_printf(MSG_DEBUG, "WPS ER: eventSubURL='%s'", ap->event_sub_url);
613 struct wps_er_ap *ap = ctx;
622 wps_er_parse_device_description(ap, reply);
631 http_client_free(ap->http);
632 ap->http = NULL;
634 wps_er_get_device_info(ap);
641 struct wps_er_ap *ap;
643 ap = wps_er_ap_get(er, addr, uuid, NULL);
644 if (ap) {
646 eloop_cancel_timeout(wps_er_ap_timeout, er, ap);
647 eloop_register_timeout(max_age, 0, wps_er_ap_timeout, er, ap);
651 ap = os_zalloc(sizeof(*ap));
652 if (ap == NULL)
654 dl_list_init(&ap->sta);
655 ap->er = er;
656 ap->id = ++er->next_ap_id;
657 ap->location = os_strdup(location);
658 if (ap->location == NULL) {
659 os_free(ap);
662 dl_list_add(&er->ap, &ap->list);
664 ap->addr.s_addr = addr->s_addr;
665 os_memcpy(ap->uuid, uuid, WPS_UUID_LEN);
666 eloop_register_timeout(max_age, 0, wps_er_ap_timeout, er, ap);
668 wpa_printf(MSG_DEBUG, "WPS ER: Added AP entry for %s (%s)",
669 inet_ntoa(ap->addr), ap->location);
672 ap->http = http_client_url(ap->location, NULL, 10000,
673 wps_er_http_dev_desc_cb, ap);
679 struct wps_er_ap *ap;
680 dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
681 if (ap->addr.s_addr == addr->s_addr) {
682 wps_er_ap_remove_entry(er, ap);
691 struct wps_er_ap *prev, *ap;
693 dl_list_for_each_safe(ap, prev, &er->ap, struct wps_er_ap, list)
694 wps_er_ap_remove_entry(er, ap);
757 static struct wps_er_sta * wps_er_add_sta_data(struct wps_er_ap *ap,
762 struct wps_er_sta *sta = wps_er_sta_get(ap, addr, NULL);
781 sta->ap = ap;
782 dl_list_add(&ap->sta, &sta->list);
831 wps_er_sta_event(ap->er->wps, sta, WPS_EV_ER_ENROLLEE_ADD);
837 static void wps_er_process_wlanevent_probe_req(struct wps_er_ap *ap,
860 wps_er_add_sta_data(ap, addr, &attr, 1);
861 wps_registrar_probe_req_rx(ap->er->wps->registrar, addr, msg, 0);
977 if (sta->ap->control_url == NULL) {
978 wpa_printf(MSG_DEBUG, "WPS ER: No controlURL for AP");
983 url = http_client_url_parse(sta->ap->control_url, &dst, &path);
1044 cfg.wps = sta->ap->er->wps;
1052 sta->wps->use_cred = sta->ap->ap_settings;
1053 if (sta->ap->ap_settings) {
1057 os_memcpy(sta->cred, sta->ap->ap_settings,
1069 static void wps_er_process_wlanevent_eap(struct wps_er_ap *ap, const u8 *addr,
1086 sta = wps_er_add_sta_data(ap, addr, &attr, 0);
1112 static void wps_er_process_wlanevent(struct wps_er_ap *ap,
1139 wps_er_process_wlanevent_probe_req(ap, wlan_event_mac, &msg);
1142 wps_er_process_wlanevent_eap(ap, wlan_event_mac, &msg);
1155 struct wps_er_ap *ap = wps_er_ap_get_id(er, ap_id);
1159 if (ap == NULL) {
1160 wpa_printf(MSG_DEBUG, "WPS ER: HTTP event from unknown AP id "
1165 wpa_printf(MSG_MSGDUMP, "WPS ER: HTTP event from AP id %u: %s",
1181 wps_er_process_wlanevent(ap, event);
1258 dl_list_init(&er->ap);
1333 struct wps_er_ap *ap;
1336 dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
1337 wps_er_ap_event(er->wps, ap, WPS_EV_ER_AP_ADD);
1338 dl_list_for_each(sta, &ap->sta, struct wps_er_sta, list)
1351 struct wps_er_ap *ap, *tmp;
1355 dl_list_for_each_safe(ap, tmp, &er->ap_unsubscribing, struct wps_er_ap,
1357 wpa_printf(MSG_DEBUG, "WPS ER: AP entry for %s (%s) still in ap_unsubscribing list - free it",
1358 inet_ntoa(ap->addr), ap->location);
1359 dl_list_del(&ap->list);
1360 wps_er_ap_free(ap);
1393 struct wps_er_ap *ap = ctx;
1402 data.set_sel_reg.uuid = ap->uuid;
1409 data.set_sel_reg.uuid = ap->uuid;
1412 http_client_free(ap->http);
1413 ap->http = NULL;
1416 ap->er->wps->event_cb(ap->er->wps->cb_ctx,
1421 static void wps_er_send_set_sel_reg(struct wps_er_ap *ap, struct wpabuf *msg)
1428 if (ap->control_url == NULL) {
1429 wpa_printf(MSG_DEBUG, "WPS ER: No controlURL for AP");
1433 if (ap->http) {
1434 wpa_printf(MSG_DEBUG, "WPS ER: Pending HTTP request for AP - "
1439 if (ap->wps) {
1440 wpa_printf(MSG_DEBUG, "WPS ER: Pending WPS operation for AP - "
1445 url = http_client_url_parse(ap->control_url, &dst, &path);
1459 ap->http = http_client_addr(&dst, buf, 1000,
1460 wps_er_http_set_sel_reg_cb, ap);
1461 if (ap->http == NULL)
1507 struct wps_er_ap *ap;
1546 dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
1548 os_memcmp(ap->uuid, er->set_sel_reg_uuid_filter,
1551 data.set_sel_reg.uuid = ap->uuid;
1554 wps_er_send_set_sel_reg(ap, msg);
1564 struct wps_er_ap *ap;
1576 ap = wps_er_ap_get(er, NULL, uuid, NULL);
1578 ap = NULL;
1579 if (ap == NULL) {
1581 dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
1582 sta = wps_er_sta_get(ap, addr, uuid);
1584 uuid = ap->uuid;
1592 if (ap->ap_settings == NULL) {
1593 wpa_printf(MSG_DEBUG, "WPS ER: AP settings not known");
1609 struct wps_er_ap *ap = ctx;
1612 wpa_printf(MSG_DEBUG, "WPS ER: AP Settings received");
1613 os_free(ap->ap_settings);
1614 ap->ap_settings = os_malloc(sizeof(*cred));
1615 if (ap->ap_settings) {
1616 os_memcpy(ap->ap_settings, cred, sizeof(*cred));
1617 ap->ap_settings->cred_attr = NULL;
1621 data.ap_settings.uuid = ap->uuid;
1623 ap->er->wps->event_cb(ap->er->wps->cb_ctx, WPS_EV_ER_AP_SETTINGS,
1630 struct wps_er_ap *ap;
1631 dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
1633 sta = wps_er_sta_get(ap, addr, NULL);
1644 struct wps_er_ap *ap = ctx;
1655 if (ap->wps) {
1656 wps_deinit(ap->wps);
1657 ap->wps = NULL;
1667 if (ap->wps) {
1668 wps_deinit(ap->wps);
1669 ap->wps = NULL;
1673 http_client_free(ap->http);
1674 ap->http = NULL;
1684 wps_deinit(ap->wps);
1685 ap->wps = NULL;
1688 wps_er_ap_process(ap, buf);
1694 static void wps_er_ap_put_message(struct wps_er_ap *ap,
1702 if (ap->http) {
1704 "with the AP - cannot continue learn");
1708 if (ap->control_url == NULL) {
1709 wpa_printf(MSG_DEBUG, "WPS ER: No controlURL for AP");
1713 url = http_client_url_parse(ap->control_url, &dst, &path);
1727 ap->http = http_client_addr(&dst, buf, 10000,
1728 wps_er_http_put_message_cb, ap);
1729 if (ap->http == NULL) {
1736 if (ap->wps) {
1737 wps_deinit(ap->wps);
1738 ap->wps = NULL;
1743 static void wps_er_ap_process(struct wps_er_ap *ap, struct wpabuf *msg)
1764 res = wps_process_msg(ap->wps, op_code, msg);
1766 struct wpabuf *next = wps_get_msg(ap->wps, &op_code);
1768 wps_er_ap_put_message(ap, next);
1773 wps_deinit(ap->wps);
1774 ap->wps = NULL;
1778 wps_deinit(ap->wps);
1779 ap->wps = NULL;
1782 "AP (res=%d)", res);
1783 wps_deinit(ap->wps);
1784 ap->wps = NULL;
1789 static void wps_er_ap_learn_m1(struct wps_er_ap *ap, struct wpabuf *m1)
1793 if (ap->wps) {
1795 "progress with this AP");
1800 cfg.wps = ap->er->wps;
1802 ap->wps = wps_init(&cfg);
1803 if (ap->wps == NULL)
1805 ap->wps->ap_settings_cb = wps_er_ap_settings_cb;
1806 ap->wps->ap_settings_cb_ctx = ap;
1808 wps_er_ap_process(ap, m1);
1812 static void wps_er_ap_learn(struct wps_er_ap *ap, const char *dev_info)
1818 "from the AP");
1826 ap->m1_handler(ap, info);
1834 struct wps_er_ap *ap = ctx;
1855 http_client_free(ap->http);
1856 ap->http = NULL;
1859 wps_er_ap_learn(ap, dev_info);
1865 static int wps_er_send_get_device_info(struct wps_er_ap *ap,
1866 void (*m1_handler)(struct wps_er_ap *ap,
1874 if (ap->http) {
1876 "with the AP - cannot get device info");
1880 if (ap->control_url == NULL) {
1881 wpa_printf(MSG_DEBUG, "WPS ER: No controlURL for AP");
1885 url = http_client_url_parse(ap->control_url, &dst, &path);
1899 ap->http = http_client_addr(&dst, buf, 10000,
1900 wps_er_http_get_dev_info_cb, ap);
1901 if (ap->http == NULL) {
1906 ap->m1_handler = m1_handler;
1915 struct wps_er_ap *ap;
1920 ap = wps_er_ap_get(er, NULL, uuid, addr);
1921 if (ap == NULL) {
1922 wpa_printf(MSG_DEBUG, "WPS ER: AP not found for learn "
1927 uuid = ap->uuid;
1928 if (ap->wps) {
1930 "with the AP - cannot start learn");
1934 if (wps_er_send_get_device_info(ap, wps_er_ap_learn_m1) < 0)
1948 struct wps_er_ap *ap;
1953 ap = wps_er_ap_get(er, NULL, uuid, addr);
1954 if (ap == NULL) {
1955 wpa_printf(MSG_DEBUG, "WPS ER: AP not found for set config "
1960 os_free(ap->ap_settings);
1961 ap->ap_settings = os_malloc(sizeof(*cred));
1962 if (ap->ap_settings == NULL)
1964 os_memcpy(ap->ap_settings, cred, sizeof(*cred));
1965 ap->ap_settings->cred_attr = NULL;
1966 wpa_printf(MSG_DEBUG, "WPS ER: Updated local AP settings based set "
1973 static void wps_er_ap_config_m1(struct wps_er_ap *ap, struct wpabuf *m1)
1977 if (ap->wps) {
1979 "progress with this AP");
1984 cfg.wps = ap->er->wps;
1986 cfg.new_ap_settings = ap->ap_settings;
1987 ap->wps = wps_init(&cfg);
1988 if (ap->wps == NULL)
1990 ap->wps->ap_settings_cb = NULL;
1991 ap->wps->ap_settings_cb_ctx = NULL;
1993 wps_er_ap_process(ap, m1);
2001 struct wps_er_ap *ap;
2006 ap = wps_er_ap_get(er, NULL, uuid, addr);
2007 if (ap == NULL) {
2008 wpa_printf(MSG_DEBUG, "WPS ER: AP not found for config "
2013 uuid = ap->uuid;
2014 if (ap->wps) {
2016 "with the AP - cannot start config");
2020 os_free(ap->ap_settings);
2021 ap->ap_settings = os_malloc(sizeof(*cred));
2022 if (ap->ap_settings == NULL)
2024 os_memcpy(ap->ap_settings, cred, sizeof(*cred));
2025 ap->ap_settings->cred_attr = NULL;
2027 if (wps_er_send_get_device_info(ap, wps_er_ap_config_m1) < 0)
2066 struct wps_er_ap *ap;
2071 ap = wps_er_ap_get(er, NULL, uuid, addr);
2072 if (ap == NULL)
2074 if (ap->ap_settings == NULL) {
2076 "selected AP");
2080 return wps_er_config_token_from_cred(er->wps, ap->ap_settings);
2088 struct wps_er_ap *ap;
2093 ap = wps_er_ap_get(er, NULL, uuid, addr);
2094 if (ap == NULL)
2096 if (ap->ap_settings == NULL) {
2098 "selected AP");
2102 os_memcpy(wps->ssid, ap->ap_settings->ssid, ap->ap_settings->ssid_len);
2103 wps->ssid_len = ap->ap_settings->ssid_len;