Lines Matching full: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 ether_addr_equal(mac_addr, ap->mac_addr)))
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_memdup(&s->ap_settings, sizeof(*ap->ap_settings));
326 if (ap->ap_settings == NULL)
329 wpa_printf(MSG_DEBUG, "WPS ER: Use cached AP settings");
334 static void wps_er_ap_remove_entry(struct wps_er *er, struct wps_er_ap *ap)
336 wpa_printf(MSG_DEBUG, "WPS ER: Removing AP entry for %s (%s)",
337 inet_ntoa(ap->addr), ap->location);
338 eloop_cancel_timeout(wps_er_ap_timeout, er, ap);
339 wps_er_sta_remove_all(ap);
340 wps_er_ap_event(er->wps, ap, WPS_EV_ER_AP_REMOVE);
341 http_client_free(ap->http);
342 ap->http = NULL;
343 if (ap->wps) {
344 wps_deinit(ap->wps);
345 ap->wps = NULL;
348 dl_list_del(&ap->list);
349 if (ap->subscribed) {
350 dl_list_add(&er->ap_unsubscribing, &ap->list);
351 wps_er_ap_unsubscribe(er, ap);
353 wps_er_ap_free(ap);
360 struct wps_er_ap *ap = user_ctx;
361 wpa_printf(MSG_DEBUG, "WPS ER: AP advertisement timed out");
362 wps_er_ap_remove_entry(er, ap);
366 static int wps_er_get_sid(struct wps_er_ap *ap, char *sid)
373 inet_ntoa(ap->addr), ap->location);
380 "%s (%s): '%s'", inet_ntoa(ap->addr), ap->location,
386 if (uuid_str2bin(pos, ap->sid) < 0) {
388 "%s (%s): '%s'", inet_ntoa(ap->addr), ap->location,
393 uuid_bin2str(ap->sid, txt, sizeof(txt));
395 inet_ntoa(ap->addr), ap->location, txt);
404 struct wps_er_ap *ap = ctx;
409 ap->subscribed = 1;
410 wps_er_get_sid(ap, http_client_get_hdr_line(c, "SID"));
411 wps_er_ap_use_cached_settings(ap->er, ap);
412 wps_er_ap_event(ap->er->wps, ap, WPS_EV_ER_AP_ADD);
420 http_client_free(ap->http);
421 ap->http = NULL;
425 static void wps_er_subscribe(struct wps_er_ap *ap)
431 if (ap->event_sub_url == NULL) {
436 if (ap->http) {
442 url = http_client_url_parse(ap->event_sub_url, &dst, &path);
448 req = wpabuf_alloc(os_strlen(ap->event_sub_url) + 1000);
461 ap->er->ip_addr_text, ap->er->http_port,
462 ap->er->event_id, ap->id, 1800);
467 ap->http = http_client_addr(&dst, req, 1000, wps_er_http_subscribe_cb,
468 ap);
469 if (ap->http == NULL)
474 static void wps_er_ap_get_m1(struct wps_er_ap *ap, struct wpabuf *m1)
483 os_memcpy(ap->pri_dev_type, attr.primary_dev_type, 8);
485 ap->wps_state = *attr.wps_state;
487 os_memcpy(ap->mac_addr, attr.mac_addr, ETH_ALEN);
489 wps_er_subscribe(ap);
493 static void wps_er_get_device_info(struct wps_er_ap *ap)
495 wps_er_send_get_device_info(ap, wps_er_ap_get_m1);
532 static void wps_er_parse_device_description(struct wps_er_ap *ap,
554 ap->friendly_name = xml_get_first_item(data, "friendlyName");
555 wpa_printf(MSG_DEBUG, "WPS ER: friendlyName='%s'", ap->friendly_name);
557 ap->manufacturer = xml_get_first_item(data, "manufacturer");
558 wpa_printf(MSG_DEBUG, "WPS ER: manufacturer='%s'", ap->manufacturer);
560 ap->manufacturer_url = xml_get_first_item(data, "manufacturerURL");
562 ap->manufacturer_url);
564 ap->model_description = xml_get_first_item(data, "modelDescription");
566 ap->model_description);
568 ap->model_name = xml_get_first_item(data, "modelName");
569 wpa_printf(MSG_DEBUG, "WPS ER: modelName='%s'", ap->model_name);
571 ap->model_number = xml_get_first_item(data, "modelNumber");
572 wpa_printf(MSG_DEBUG, "WPS ER: modelNumber='%s'", ap->model_number);
574 ap->model_url = xml_get_first_item(data, "modelURL");
575 wpa_printf(MSG_DEBUG, "WPS ER: modelURL='%s'", ap->model_url);
577 ap->serial_number = xml_get_first_item(data, "serialNumber");
578 wpa_printf(MSG_DEBUG, "WPS ER: serialNumber='%s'", ap->serial_number);
580 ap->udn = xml_get_first_item(data, "UDN");
581 if (ap->udn) {
582 wpa_printf(MSG_DEBUG, "WPS ER: UDN='%s'", ap->udn);
583 pos = os_strstr(ap->udn, "uuid:");
586 if (uuid_str2bin(pos, ap->uuid) < 0)
592 ap->upc = xml_get_first_item(data, "UPC");
593 wpa_printf(MSG_DEBUG, "WPS ER: UPC='%s'", ap->upc);
595 ap->scpd_url = http_link_update(
596 xml_get_first_item(data, "SCPDURL"), ap->location);
597 wpa_printf(MSG_DEBUG, "WPS ER: SCPDURL='%s'", ap->scpd_url);
599 ap->control_url = http_link_update(
600 xml_get_first_item(data, "controlURL"), ap->location);
601 wpa_printf(MSG_DEBUG, "WPS ER: controlURL='%s'", ap->control_url);
603 ap->event_sub_url = http_link_update(
604 xml_get_first_item(data, "eventSubURL"), ap->location);
605 wpa_printf(MSG_DEBUG, "WPS ER: eventSubURL='%s'", ap->event_sub_url);
612 struct wps_er_ap *ap = ctx;
621 wps_er_parse_device_description(ap, reply);
630 http_client_free(ap->http);
631 ap->http = NULL;
633 wps_er_get_device_info(ap);
640 struct wps_er_ap *ap;
642 ap = wps_er_ap_get(er, addr, uuid, NULL);
643 if (ap) {
645 eloop_cancel_timeout(wps_er_ap_timeout, er, ap);
646 eloop_register_timeout(max_age, 0, wps_er_ap_timeout, er, ap);
650 ap = os_zalloc(sizeof(*ap));
651 if (ap == NULL)
653 dl_list_init(&ap->sta);
654 ap->er = er;
655 ap->id = ++er->next_ap_id;
656 ap->location = os_strdup(location);
657 if (ap->location == NULL) {
658 os_free(ap);
661 dl_list_add(&er->ap, &ap->list);
663 ap->addr.s_addr = addr->s_addr;
664 os_memcpy(ap->uuid, uuid, WPS_UUID_LEN);
665 eloop_register_timeout(max_age, 0, wps_er_ap_timeout, er, ap);
667 wpa_printf(MSG_DEBUG, "WPS ER: Added AP entry for %s (%s)",
668 inet_ntoa(ap->addr), ap->location);
671 ap->http = http_client_url(ap->location, NULL, 10000,
672 wps_er_http_dev_desc_cb, ap);
678 struct wps_er_ap *ap;
679 dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
680 if (ap->addr.s_addr == addr->s_addr) {
681 wps_er_ap_remove_entry(er, ap);
690 struct wps_er_ap *prev, *ap;
692 dl_list_for_each_safe(ap, prev, &er->ap, struct wps_er_ap, list)
693 wps_er_ap_remove_entry(er, ap);
756 static struct wps_er_sta * wps_er_add_sta_data(struct wps_er_ap *ap,
761 struct wps_er_sta *sta = wps_er_sta_get(ap, addr, NULL);
780 sta->ap = ap;
781 dl_list_add(&ap->sta, &sta->list);
830 wps_er_sta_event(ap->er->wps, sta, WPS_EV_ER_ENROLLEE_ADD);
836 static void wps_er_process_wlanevent_probe_req(struct wps_er_ap *ap,
859 wps_er_add_sta_data(ap, addr, &attr, 1);
860 wps_registrar_probe_req_rx(ap->er->wps->registrar, addr, msg, 0);
976 if (sta->ap->control_url == NULL) {
977 wpa_printf(MSG_DEBUG, "WPS ER: No controlURL for AP");
982 url = http_client_url_parse(sta->ap->control_url, &dst, &path);
1043 cfg.wps = sta->ap->er->wps;
1051 sta->wps->use_cred = sta->ap->ap_settings;
1052 if (sta->ap->ap_settings) {
1056 os_memcpy(sta->cred, sta->ap->ap_settings,
1068 static void wps_er_process_wlanevent_eap(struct wps_er_ap *ap, const u8 *addr,
1085 sta = wps_er_add_sta_data(ap, addr, &attr, 0);
1111 static void wps_er_process_wlanevent(struct wps_er_ap *ap,
1138 wps_er_process_wlanevent_probe_req(ap, wlan_event_mac, &msg);
1141 wps_er_process_wlanevent_eap(ap, wlan_event_mac, &msg);
1154 struct wps_er_ap *ap = wps_er_ap_get_id(er, ap_id);
1158 if (ap == NULL) {
1159 wpa_printf(MSG_DEBUG, "WPS ER: HTTP event from unknown AP id "
1164 wpa_printf(MSG_MSGDUMP, "WPS ER: HTTP event from AP id %u: %s",
1180 wps_er_process_wlanevent(ap, event);
1257 dl_list_init(&er->ap);
1332 struct wps_er_ap *ap;
1335 dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
1336 wps_er_ap_event(er->wps, ap, WPS_EV_ER_AP_ADD);
1337 dl_list_for_each(sta, &ap->sta, struct wps_er_sta, list)
1350 struct wps_er_ap *ap, *tmp;
1354 dl_list_for_each_safe(ap, tmp, &er->ap_unsubscribing, struct wps_er_ap,
1356 wpa_printf(MSG_DEBUG, "WPS ER: AP entry for %s (%s) still in ap_unsubscribing list - free it",
1357 inet_ntoa(ap->addr), ap->location);
1358 dl_list_del(&ap->list);
1359 wps_er_ap_free(ap);
1392 struct wps_er_ap *ap = ctx;
1401 data.set_sel_reg.uuid = ap->uuid;
1408 data.set_sel_reg.uuid = ap->uuid;
1411 http_client_free(ap->http);
1412 ap->http = NULL;
1415 ap->er->wps->event_cb(ap->er->wps->cb_ctx,
1420 static void wps_er_send_set_sel_reg(struct wps_er_ap *ap, struct wpabuf *msg)
1427 if (ap->control_url == NULL) {
1428 wpa_printf(MSG_DEBUG, "WPS ER: No controlURL for AP");
1432 if (ap->http) {
1433 wpa_printf(MSG_DEBUG, "WPS ER: Pending HTTP request for AP - "
1438 if (ap->wps) {
1439 wpa_printf(MSG_DEBUG, "WPS ER: Pending WPS operation for AP - "
1444 url = http_client_url_parse(ap->control_url, &dst, &path);
1458 ap->http = http_client_addr(&dst, buf, 1000,
1459 wps_er_http_set_sel_reg_cb, ap);
1460 if (ap->http == NULL)
1506 struct wps_er_ap *ap;
1545 dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
1547 os_memcmp(ap->uuid, er->set_sel_reg_uuid_filter,
1550 data.set_sel_reg.uuid = ap->uuid;
1553 wps_er_send_set_sel_reg(ap, msg);
1563 struct wps_er_ap *ap;
1575 ap = wps_er_ap_get(er, NULL, uuid, NULL);
1577 ap = NULL;
1578 if (ap == NULL) {
1580 dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
1581 sta = wps_er_sta_get(ap, addr, uuid);
1583 uuid = ap->uuid;
1591 if (ap->ap_settings == NULL) {
1592 wpa_printf(MSG_DEBUG, "WPS ER: AP settings not known");
1608 struct wps_er_ap *ap = ctx;
1611 wpa_printf(MSG_DEBUG, "WPS ER: AP Settings received");
1612 os_free(ap->ap_settings);
1613 ap->ap_settings = os_malloc(sizeof(*cred));
1614 if (ap->ap_settings) {
1615 os_memcpy(ap->ap_settings, cred, sizeof(*cred));
1616 ap->ap_settings->cred_attr = NULL;
1620 data.ap_settings.uuid = ap->uuid;
1622 ap->er->wps->event_cb(ap->er->wps->cb_ctx, WPS_EV_ER_AP_SETTINGS,
1629 struct wps_er_ap *ap;
1630 dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) {
1632 sta = wps_er_sta_get(ap, addr, NULL);
1643 struct wps_er_ap *ap = ctx;
1654 if (ap->wps) {
1655 wps_deinit(ap->wps);
1656 ap->wps = NULL;
1666 if (ap->wps) {
1667 wps_deinit(ap->wps);
1668 ap->wps = NULL;
1672 http_client_free(ap->http);
1673 ap->http = NULL;
1683 wps_deinit(ap->wps);
1684 ap->wps = NULL;
1687 wps_er_ap_process(ap, buf);
1693 static void wps_er_ap_put_message(struct wps_er_ap *ap,
1701 if (ap->http) {
1703 "with the AP - cannot continue learn");
1707 if (ap->control_url == NULL) {
1708 wpa_printf(MSG_DEBUG, "WPS ER: No controlURL for AP");
1712 url = http_client_url_parse(ap->control_url, &dst, &path);
1726 ap->http = http_client_addr(&dst, buf, 10000,
1727 wps_er_http_put_message_cb, ap);
1728 if (ap->http == NULL) {
1735 if (ap->wps) {
1736 wps_deinit(ap->wps);
1737 ap->wps = NULL;
1742 static void wps_er_ap_process(struct wps_er_ap *ap, struct wpabuf *msg)
1763 res = wps_process_msg(ap->wps, op_code, msg);
1765 struct wpabuf *next = wps_get_msg(ap->wps, &op_code);
1767 wps_er_ap_put_message(ap, next);
1772 wps_deinit(ap->wps);
1773 ap->wps = NULL;
1777 wps_deinit(ap->wps);
1778 ap->wps = NULL;
1781 "AP (res=%d)", res);
1782 wps_deinit(ap->wps);
1783 ap->wps = NULL;
1788 static void wps_er_ap_learn_m1(struct wps_er_ap *ap, struct wpabuf *m1)
1792 if (ap->wps) {
1794 "progress with this AP");
1799 cfg.wps = ap->er->wps;
1801 ap->wps = wps_init(&cfg);
1802 if (ap->wps == NULL)
1804 ap->wps->ap_settings_cb = wps_er_ap_settings_cb;
1805 ap->wps->ap_settings_cb_ctx = ap;
1807 wps_er_ap_process(ap, m1);
1811 static void wps_er_ap_learn(struct wps_er_ap *ap, const char *dev_info)
1817 "from the AP");
1825 ap->m1_handler(ap, info);
1833 struct wps_er_ap *ap = ctx;
1854 http_client_free(ap->http);
1855 ap->http = NULL;
1858 wps_er_ap_learn(ap, dev_info);
1864 static int wps_er_send_get_device_info(struct wps_er_ap *ap,
1865 void (*m1_handler)(struct wps_er_ap *ap,
1873 if (ap->http) {
1875 "with the AP - cannot get device info");
1879 if (ap->control_url == NULL) {
1880 wpa_printf(MSG_DEBUG, "WPS ER: No controlURL for AP");
1884 url = http_client_url_parse(ap->control_url, &dst, &path);
1898 ap->http = http_client_addr(&dst, buf, 10000,
1899 wps_er_http_get_dev_info_cb, ap);
1900 if (ap->http == NULL) {
1905 ap->m1_handler = m1_handler;
1914 struct wps_er_ap *ap;
1919 ap = wps_er_ap_get(er, NULL, uuid, addr);
1920 if (ap == NULL) {
1921 wpa_printf(MSG_DEBUG, "WPS ER: AP not found for learn "
1926 uuid = ap->uuid;
1927 if (ap->wps) {
1929 "with the AP - cannot start learn");
1933 if (wps_er_send_get_device_info(ap, wps_er_ap_learn_m1) < 0)
1947 struct wps_er_ap *ap;
1952 ap = wps_er_ap_get(er, NULL, uuid, addr);
1953 if (ap == NULL) {
1954 wpa_printf(MSG_DEBUG, "WPS ER: AP not found for set config "
1959 os_free(ap->ap_settings);
1960 ap->ap_settings = os_memdup(cred, sizeof(*cred));
1961 if (ap->ap_settings == NULL)
1963 ap->ap_settings->cred_attr = NULL;
1964 wpa_printf(MSG_DEBUG, "WPS ER: Updated local AP settings based set "
1971 static void wps_er_ap_config_m1(struct wps_er_ap *ap, struct wpabuf *m1)
1975 if (ap->wps) {
1977 "progress with this AP");
1982 cfg.wps = ap->er->wps;
1984 cfg.new_ap_settings = ap->ap_settings;
1985 ap->wps = wps_init(&cfg);
1986 if (ap->wps == NULL)
1988 ap->wps->ap_settings_cb = NULL;
1989 ap->wps->ap_settings_cb_ctx = NULL;
1991 wps_er_ap_process(ap, m1);
1999 struct wps_er_ap *ap;
2004 ap = wps_er_ap_get(er, NULL, uuid, addr);
2005 if (ap == NULL) {
2006 wpa_printf(MSG_DEBUG, "WPS ER: AP not found for config "
2011 uuid = ap->uuid;
2012 if (ap->wps) {
2014 "with the AP - cannot start config");
2018 os_free(ap->ap_settings);
2019 ap->ap_settings = os_memdup(cred, sizeof(*cred));
2020 if (ap->ap_settings == NULL)
2022 ap->ap_settings->cred_attr = NULL;
2024 if (wps_er_send_get_device_info(ap, wps_er_ap_config_m1) < 0)
2063 struct wps_er_ap *ap;
2068 ap = wps_er_ap_get(er, NULL, uuid, addr);
2069 if (ap == NULL)
2071 if (ap->ap_settings == NULL) {
2073 "selected AP");
2077 return wps_er_config_token_from_cred(er->wps, ap->ap_settings);
2085 struct wps_er_ap *ap;
2090 ap = wps_er_ap_get(er, NULL, uuid, addr);
2091 if (ap == NULL)
2093 if (ap->ap_settings == NULL) {
2095 "selected AP");
2099 os_memcpy(wps->ssid, ap->ap_settings->ssid, ap->ap_settings->ssid_len);
2100 wps->ssid_len = ap->ap_settings->ssid_len;