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)
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;
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) {
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));
335 static void wps_er_ap_remove_entry(struct wps_er *er, struct wps_er_ap *ap)
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;
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);
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) {
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) {
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,
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) {
1433 if (ap->http) {
1439 if (ap->wps) {
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) {
1609 struct wps_er_ap *ap = ctx;
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;
1663 if (ap->wps) {
1664 wps_deinit(ap->wps);
1665 ap->wps = NULL;
1669 http_client_free(ap->http);
1670 ap->http = NULL;
1680 wps_deinit(ap->wps);
1681 ap->wps = NULL;
1684 wps_er_ap_process(ap, buf);
1690 static void wps_er_ap_put_message(struct wps_er_ap *ap,
1698 if (ap->http) {
1704 if (ap->control_url == NULL) {
1709 url = http_client_url_parse(ap->control_url, &dst, &path);
1723 ap->http = http_client_addr(&dst, buf, 10000,
1724 wps_er_http_put_message_cb, ap);
1725 if (ap->http == NULL)
1730 static void wps_er_ap_process(struct wps_er_ap *ap, struct wpabuf *msg)
1751 res = wps_process_msg(ap->wps, op_code, msg);
1753 struct wpabuf *next = wps_get_msg(ap->wps, &op_code);
1755 wps_er_ap_put_message(ap, next);
1760 wps_deinit(ap->wps);
1761 ap->wps = NULL;
1765 wps_deinit(ap->wps);
1766 ap->wps = NULL;
1770 wps_deinit(ap->wps);
1771 ap->wps = NULL;
1776 static void wps_er_ap_learn_m1(struct wps_er_ap *ap, struct wpabuf *m1)
1780 if (ap->wps) {
1787 cfg.wps = ap->er->wps;
1789 ap->wps = wps_init(&cfg);
1790 if (ap->wps == NULL)
1792 ap->wps->ap_settings_cb = wps_er_ap_settings_cb;
1793 ap->wps->ap_settings_cb_ctx = ap;
1795 wps_er_ap_process(ap, m1);
1799 static void wps_er_ap_learn(struct wps_er_ap *ap, const char *dev_info)
1813 ap->m1_handler(ap, info);
1821 struct wps_er_ap *ap = ctx;
1842 http_client_free(ap->http);
1843 ap->http = NULL;
1846 wps_er_ap_learn(ap, dev_info);
1852 static int wps_er_send_get_device_info(struct wps_er_ap *ap,
1853 void (*m1_handler)(struct wps_er_ap *ap,
1861 if (ap->http) {
1867 if (ap->control_url == NULL) {
1872 url = http_client_url_parse(ap->control_url, &dst, &path);
1886 ap->http = http_client_addr(&dst, buf, 10000,
1887 wps_er_http_get_dev_info_cb, ap);
1888 if (ap->http == NULL) {
1893 ap->m1_handler = m1_handler;
1902 struct wps_er_ap *ap;
1907 ap = wps_er_ap_get(er, NULL, uuid, addr);
1908 if (ap == NULL) {
1914 uuid = ap->uuid;
1915 if (ap->wps) {
1921 if (wps_er_send_get_device_info(ap, wps_er_ap_learn_m1) < 0)
1935 struct wps_er_ap *ap;
1940 ap = wps_er_ap_get(er, NULL, uuid, addr);
1941 if (ap == NULL) {
1947 os_free(ap->ap_settings);
1948 ap->ap_settings = os_malloc(sizeof(*cred));
1949 if (ap->ap_settings == NULL)
1951 os_memcpy(ap->ap_settings, cred, sizeof(*cred));
1952 ap->ap_settings->cred_attr = NULL;
1960 static void wps_er_ap_config_m1(struct wps_er_ap *ap, struct wpabuf *m1)
1964 if (ap->wps) {
1971 cfg.wps = ap->er->wps;
1973 cfg.new_ap_settings = ap->ap_settings;
1974 ap->wps = wps_init(&cfg);
1975 if (ap->wps == NULL)
1977 ap->wps->ap_settings_cb = NULL;
1978 ap->wps->ap_settings_cb_ctx = NULL;
1980 wps_er_ap_process(ap, m1);
1988 struct wps_er_ap *ap;
1993 ap = wps_er_ap_get(er, NULL, uuid, addr);
1994 if (ap == NULL) {
2000 uuid = ap->uuid;
2001 if (ap->wps) {
2007 os_free(ap->ap_settings);
2008 ap->ap_settings = os_malloc(sizeof(*cred));
2009 if (ap->ap_settings == NULL)
2011 os_memcpy(ap->ap_settings, cred, sizeof(*cred));
2012 ap->ap_settings->cred_attr = NULL;
2014 if (wps_er_send_get_device_info(ap, wps_er_ap_config_m1) < 0)
2053 struct wps_er_ap *ap;
2058 ap = wps_er_ap_get(er, NULL, uuid, addr);
2059 if (ap == NULL)
2061 if (ap->ap_settings == NULL) {
2067 return wps_er_config_token_from_cred(er->wps, ap->ap_settings);
2075 struct wps_er_ap *ap;
2080 ap = wps_er_ap_get(er, NULL, uuid, addr);
2081 if (ap == NULL)
2083 if (ap->ap_settings == NULL) {
2089 os_memcpy(wps->ssid, ap->ap_settings->ssid, ap->ap_settings->ssid_len);
2090 wps->ssid_len = ap->ap_settings->ssid_len;