2 * Wi-Fi Protected Setup - External Registrar
3 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
22 #include "http_client.h"
23 #include "http_server.h"
27 #include "wps_upnp_i.h"
31 static void wps_er_deinit_finish(void *eloop_data
, void *user_ctx
);
32 static void wps_er_ap_timeout(void *eloop_data
, void *user_ctx
);
33 static void wps_er_sta_timeout(void *eloop_data
, void *user_ctx
);
34 static void wps_er_ap_process(struct wps_er_ap
*ap
, struct wpabuf
*msg
);
35 static int wps_er_send_get_device_info(struct wps_er_ap
*ap
,
36 void (*m1_handler
)(struct wps_er_ap
*ap
,
40 static void wps_er_sta_event(struct wps_context
*wps
, struct wps_er_sta
*sta
,
43 union wps_event_data data
;
44 struct wps_event_er_enrollee
*ev
= &data
.enrollee
;
46 if (wps
->event_cb
== NULL
)
49 os_memset(&data
, 0, sizeof(data
));
51 ev
->mac_addr
= sta
->addr
;
52 ev
->m1_received
= sta
->m1_received
;
53 ev
->config_methods
= sta
->config_methods
;
54 ev
->dev_passwd_id
= sta
->dev_passwd_id
;
55 ev
->pri_dev_type
= sta
->pri_dev_type
;
56 ev
->dev_name
= sta
->dev_name
;
57 ev
->manufacturer
= sta
->manufacturer
;
58 ev
->model_name
= sta
->model_name
;
59 ev
->model_number
= sta
->model_number
;
60 ev
->serial_number
= sta
->serial_number
;
61 wps
->event_cb(wps
->cb_ctx
, event
, &data
);
65 static struct wps_er_sta
* wps_er_sta_get(struct wps_er_ap
*ap
, const u8
*addr
)
67 struct wps_er_sta
*sta
;
68 dl_list_for_each(sta
, &ap
->sta
, struct wps_er_sta
, list
) {
69 if (os_memcmp(sta
->addr
, addr
, ETH_ALEN
) == 0)
76 static void wps_er_sta_free(struct wps_er_sta
*sta
)
78 wps_er_sta_event(sta
->ap
->er
->wps
, sta
, WPS_EV_ER_ENROLLEE_REMOVE
);
81 os_free(sta
->manufacturer
);
82 os_free(sta
->model_name
);
83 os_free(sta
->model_number
);
84 os_free(sta
->serial_number
);
85 os_free(sta
->dev_name
);
86 http_client_free(sta
->http
);
87 eloop_cancel_timeout(wps_er_sta_timeout
, sta
, NULL
);
92 static void wps_er_sta_remove_all(struct wps_er_ap
*ap
)
94 struct wps_er_sta
*prev
, *sta
;
95 dl_list_for_each_safe(sta
, prev
, &ap
->sta
, struct wps_er_sta
, list
)
100 static struct wps_er_ap
* wps_er_ap_get(struct wps_er
*er
,
101 struct in_addr
*addr
, const u8
*uuid
)
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))
114 static struct wps_er_ap
* wps_er_ap_get_id(struct wps_er
*er
, unsigned int id
)
116 struct wps_er_ap
*ap
;
117 dl_list_for_each(ap
, &er
->ap
, struct wps_er_ap
, list
) {
125 static void wps_er_ap_event(struct wps_context
*wps
, struct wps_er_ap
*ap
,
126 enum wps_event event
)
128 union wps_event_data data
;
129 struct wps_event_er_ap
*evap
= &data
.ap
;
131 if (wps
->event_cb
== NULL
)
134 os_memset(&data
, 0, sizeof(data
));
135 evap
->uuid
= ap
->uuid
;
136 evap
->friendly_name
= ap
->friendly_name
;
137 evap
->manufacturer
= ap
->manufacturer
;
138 evap
->manufacturer_url
= ap
->manufacturer_url
;
139 evap
->model_description
= ap
->model_description
;
140 evap
->model_name
= ap
->model_name
;
141 evap
->model_number
= ap
->model_number
;
142 evap
->model_url
= ap
->model_url
;
143 evap
->serial_number
= ap
->serial_number
;
145 evap
->pri_dev_type
= ap
->pri_dev_type
;
146 evap
->wps_state
= ap
->wps_state
;
147 evap
->mac_addr
= ap
->mac_addr
;
148 wps
->event_cb(wps
->cb_ctx
, event
, &data
);
152 static void wps_er_ap_free(struct wps_er_ap
*ap
)
154 http_client_free(ap
->http
);
157 os_free(ap
->location
);
158 os_free(ap
->friendly_name
);
159 os_free(ap
->manufacturer
);
160 os_free(ap
->manufacturer_url
);
161 os_free(ap
->model_description
);
162 os_free(ap
->model_name
);
163 os_free(ap
->model_number
);
164 os_free(ap
->model_url
);
165 os_free(ap
->serial_number
);
169 os_free(ap
->scpd_url
);
170 os_free(ap
->control_url
);
171 os_free(ap
->event_sub_url
);
173 os_free(ap
->ap_settings
);
179 static void wps_er_ap_unsubscribed(struct wps_er
*er
, struct wps_er_ap
*ap
)
181 wpa_printf(MSG_DEBUG
, "WPS ER: Unsubscribed from AP %s (%s)",
182 inet_ntoa(ap
->addr
), ap
->location
);
183 dl_list_del(&ap
->list
);
186 if (er
->deinitializing
&& dl_list_empty(&er
->ap_unsubscribing
)) {
187 eloop_cancel_timeout(wps_er_deinit_finish
, er
, NULL
);
188 wps_er_deinit_finish(er
, NULL
);
193 static void wps_er_http_unsubscribe_cb(void *ctx
, struct http_client
*c
,
194 enum http_client_event event
)
196 struct wps_er_ap
*ap
= ctx
;
200 wpa_printf(MSG_DEBUG
, "WPS ER: Unsubscribed from events");
203 case HTTP_CLIENT_FAILED
:
204 case HTTP_CLIENT_INVALID_REPLY
:
205 case HTTP_CLIENT_TIMEOUT
:
206 wpa_printf(MSG_DEBUG
, "WPS ER: Failed to unsubscribe from "
210 http_client_free(ap
->http
);
214 * Need to get rid of the AP entry regardless of whether we managed to
215 * unsubscribe cleanly or not.
217 wps_er_ap_unsubscribed(ap
->er
, ap
);
221 static void wps_er_ap_unsubscribe(struct wps_er
*er
, struct wps_er_ap
*ap
)
224 struct sockaddr_in dst
;
228 if (ap
->event_sub_url
== NULL
) {
229 wpa_printf(MSG_DEBUG
, "WPS ER: No eventSubURL - cannot "
234 wpa_printf(MSG_DEBUG
, "WPS ER: Pending HTTP request - cannot "
235 "send subscribe request");
239 url
= http_client_url_parse(ap
->event_sub_url
, &dst
, &path
);
241 wpa_printf(MSG_DEBUG
, "WPS ER: Failed to parse eventSubURL");
245 req
= wpabuf_alloc(os_strlen(ap
->event_sub_url
) + 1000);
250 uuid_bin2str(ap
->sid
, sid
, sizeof(sid
));
252 "UNSUBSCRIBE %s HTTP/1.1\r\n"
256 path
, inet_ntoa(dst
.sin_addr
), ntohs(dst
.sin_port
), sid
);
258 wpa_hexdump_ascii(MSG_MSGDUMP
, "WPS ER: Unsubscription request",
259 wpabuf_head(req
), wpabuf_len(req
));
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
);
277 static void wps_er_ap_remove_entry(struct wps_er
*er
, struct wps_er_ap
*ap
)
279 wpa_printf(MSG_DEBUG
, "WPS ER: Removing AP entry for %s (%s)",
280 inet_ntoa(ap
->addr
), ap
->location
);
281 eloop_cancel_timeout(wps_er_ap_timeout
, er
, ap
);
282 wps_er_sta_remove_all(ap
);
283 wps_er_ap_event(er
->wps
, ap
, WPS_EV_ER_AP_REMOVE
);
284 http_client_free(ap
->http
);
291 dl_list_del(&ap
->list
);
292 if (ap
->subscribed
) {
293 dl_list_add(&er
->ap_unsubscribing
, &ap
->list
);
294 wps_er_ap_unsubscribe(er
, ap
);
300 static void wps_er_ap_timeout(void *eloop_data
, void *user_ctx
)
302 struct wps_er
*er
= eloop_data
;
303 struct wps_er_ap
*ap
= user_ctx
;
304 wpa_printf(MSG_DEBUG
, "WPS ER: AP advertisement timed out");
305 wps_er_ap_remove_entry(er
, ap
);
309 static int wps_er_get_sid(struct wps_er_ap
*ap
, char *sid
)
315 wpa_printf(MSG_DEBUG
, "WPS ER: No SID received from %s (%s)",
316 inet_ntoa(ap
->addr
), ap
->location
);
320 pos
= os_strstr(sid
, "uuid:");
322 wpa_printf(MSG_DEBUG
, "WPS ER: Invalid SID received from "
323 "%s (%s): '%s'", inet_ntoa(ap
->addr
), ap
->location
,
329 if (uuid_str2bin(pos
, ap
->sid
) < 0) {
330 wpa_printf(MSG_DEBUG
, "WPS ER: Invalid SID received from "
331 "%s (%s): '%s'", inet_ntoa(ap
->addr
), ap
->location
,
336 uuid_bin2str(ap
->sid
, txt
, sizeof(txt
));
337 wpa_printf(MSG_DEBUG
, "WPS ER: SID for subscription with %s (%s): %s",
338 inet_ntoa(ap
->addr
), ap
->location
, txt
);
344 static void wps_er_http_subscribe_cb(void *ctx
, struct http_client
*c
,
345 enum http_client_event event
)
347 struct wps_er_ap
*ap
= ctx
;
351 wpa_printf(MSG_DEBUG
, "WPS ER: Subscribed to events");
353 wps_er_get_sid(ap
, http_client_get_hdr_line(c
, "SID"));
354 wps_er_ap_event(ap
->er
->wps
, ap
, WPS_EV_ER_AP_ADD
);
356 case HTTP_CLIENT_FAILED
:
357 case HTTP_CLIENT_INVALID_REPLY
:
358 case HTTP_CLIENT_TIMEOUT
:
359 wpa_printf(MSG_DEBUG
, "WPS ER: Failed to subscribe to events");
362 http_client_free(ap
->http
);
367 static void wps_er_subscribe(struct wps_er_ap
*ap
)
370 struct sockaddr_in dst
;
373 if (ap
->event_sub_url
== NULL
) {
374 wpa_printf(MSG_DEBUG
, "WPS ER: No eventSubURL - cannot "
379 wpa_printf(MSG_DEBUG
, "WPS ER: Pending HTTP request - cannot "
380 "send subscribe request");
384 url
= http_client_url_parse(ap
->event_sub_url
, &dst
, &path
);
386 wpa_printf(MSG_DEBUG
, "WPS ER: Failed to parse eventSubURL");
390 req
= wpabuf_alloc(os_strlen(ap
->event_sub_url
) + 1000);
396 "SUBSCRIBE %s HTTP/1.1\r\n"
398 "CALLBACK: <http://%s:%d/event/%u/%u>\r\n"
400 "TIMEOUT: Second-%d\r\n"
402 path
, inet_ntoa(dst
.sin_addr
), ntohs(dst
.sin_port
),
403 ap
->er
->ip_addr_text
, ap
->er
->http_port
,
404 ap
->er
->event_id
, ap
->id
, 1800);
406 wpa_hexdump_ascii(MSG_MSGDUMP
, "WPS ER: Subscription request",
407 wpabuf_head(req
), wpabuf_len(req
));
409 ap
->http
= http_client_addr(&dst
, req
, 1000, wps_er_http_subscribe_cb
,
411 if (ap
->http
== NULL
)
416 static void wps_er_ap_get_m1(struct wps_er_ap
*ap
, struct wpabuf
*m1
)
418 struct wps_parse_attr attr
;
420 if (wps_parse_msg(m1
, &attr
) < 0) {
421 wpa_printf(MSG_DEBUG
, "WPS ER: Failed to parse M1");
424 if (attr
.primary_dev_type
)
425 os_memcpy(ap
->pri_dev_type
, attr
.primary_dev_type
, 8);
427 ap
->wps_state
= *attr
.wps_state
;
429 os_memcpy(ap
->mac_addr
, attr
.mac_addr
, ETH_ALEN
);
431 wps_er_subscribe(ap
);
435 static void wps_er_get_device_info(struct wps_er_ap
*ap
)
437 wps_er_send_get_device_info(ap
, wps_er_ap_get_m1
);
441 static void wps_er_parse_device_description(struct wps_er_ap
*ap
,
442 struct wpabuf
*reply
)
444 /* Note: reply includes null termination after the buffer data */
445 const char *data
= wpabuf_head(reply
);
448 wpa_hexdump_ascii(MSG_MSGDUMP
, "WPS ER: Device info",
449 wpabuf_head(reply
), wpabuf_len(reply
));
451 ap
->friendly_name
= xml_get_first_item(data
, "friendlyName");
452 wpa_printf(MSG_DEBUG
, "WPS ER: friendlyName='%s'", ap
->friendly_name
);
454 ap
->manufacturer
= xml_get_first_item(data
, "manufacturer");
455 wpa_printf(MSG_DEBUG
, "WPS ER: manufacturer='%s'", ap
->manufacturer
);
457 ap
->manufacturer_url
= xml_get_first_item(data
, "manufacturerURL");
458 wpa_printf(MSG_DEBUG
, "WPS ER: manufacturerURL='%s'",
459 ap
->manufacturer_url
);
461 ap
->model_description
= xml_get_first_item(data
, "modelDescription");
462 wpa_printf(MSG_DEBUG
, "WPS ER: modelDescription='%s'",
463 ap
->model_description
);
465 ap
->model_name
= xml_get_first_item(data
, "modelName");
466 wpa_printf(MSG_DEBUG
, "WPS ER: modelName='%s'", ap
->model_name
);
468 ap
->model_number
= xml_get_first_item(data
, "modelNumber");
469 wpa_printf(MSG_DEBUG
, "WPS ER: modelNumber='%s'", ap
->model_number
);
471 ap
->model_url
= xml_get_first_item(data
, "modelURL");
472 wpa_printf(MSG_DEBUG
, "WPS ER: modelURL='%s'", ap
->model_url
);
474 ap
->serial_number
= xml_get_first_item(data
, "serialNumber");
475 wpa_printf(MSG_DEBUG
, "WPS ER: serialNumber='%s'", ap
->serial_number
);
477 ap
->udn
= xml_get_first_item(data
, "UDN");
478 wpa_printf(MSG_DEBUG
, "WPS ER: UDN='%s'", ap
->udn
);
479 pos
= os_strstr(ap
->udn
, "uuid:");
482 uuid_str2bin(pos
, ap
->uuid
);
485 ap
->upc
= xml_get_first_item(data
, "UPC");
486 wpa_printf(MSG_DEBUG
, "WPS ER: UPC='%s'", ap
->upc
);
488 ap
->scpd_url
= http_link_update(
489 xml_get_first_item(data
, "SCPDURL"), ap
->location
);
490 wpa_printf(MSG_DEBUG
, "WPS ER: SCPDURL='%s'", ap
->scpd_url
);
492 ap
->control_url
= http_link_update(
493 xml_get_first_item(data
, "controlURL"), ap
->location
);
494 wpa_printf(MSG_DEBUG
, "WPS ER: controlURL='%s'", ap
->control_url
);
496 ap
->event_sub_url
= http_link_update(
497 xml_get_first_item(data
, "eventSubURL"), ap
->location
);
498 wpa_printf(MSG_DEBUG
, "WPS ER: eventSubURL='%s'", ap
->event_sub_url
);
502 static void wps_er_http_dev_desc_cb(void *ctx
, struct http_client
*c
,
503 enum http_client_event event
)
505 struct wps_er_ap
*ap
= ctx
;
506 struct wpabuf
*reply
;
511 reply
= http_client_get_body(c
);
514 wps_er_parse_device_description(ap
, reply
);
517 case HTTP_CLIENT_FAILED
:
518 case HTTP_CLIENT_INVALID_REPLY
:
519 case HTTP_CLIENT_TIMEOUT
:
520 wpa_printf(MSG_DEBUG
, "WPS ER: Failed to fetch device info");
523 http_client_free(ap
->http
);
526 wps_er_get_device_info(ap
);
530 void wps_er_ap_add(struct wps_er
*er
, const u8
*uuid
, struct in_addr
*addr
,
531 const char *location
, int max_age
)
533 struct wps_er_ap
*ap
;
535 ap
= wps_er_ap_get(er
, addr
, uuid
);
537 /* Update advertisement timeout */
538 eloop_cancel_timeout(wps_er_ap_timeout
, er
, ap
);
539 eloop_register_timeout(max_age
, 0, wps_er_ap_timeout
, er
, ap
);
543 ap
= os_zalloc(sizeof(*ap
));
546 dl_list_init(&ap
->sta
);
548 ap
->id
= ++er
->next_ap_id
;
549 ap
->location
= os_strdup(location
);
550 if (ap
->location
== NULL
) {
554 dl_list_add(&er
->ap
, &ap
->list
);
556 ap
->addr
.s_addr
= addr
->s_addr
;
557 os_memcpy(ap
->uuid
, uuid
, WPS_UUID_LEN
);
558 eloop_register_timeout(max_age
, 0, wps_er_ap_timeout
, er
, ap
);
560 wpa_printf(MSG_DEBUG
, "WPS ER: Added AP entry for %s (%s)",
561 inet_ntoa(ap
->addr
), ap
->location
);
563 /* Fetch device description */
564 ap
->http
= http_client_url(ap
->location
, NULL
, 10000,
565 wps_er_http_dev_desc_cb
, ap
);
569 void wps_er_ap_remove(struct wps_er
*er
, struct in_addr
*addr
)
571 struct wps_er_ap
*ap
;
572 dl_list_for_each(ap
, &er
->ap
, struct wps_er_ap
, list
) {
573 if (ap
->addr
.s_addr
== addr
->s_addr
) {
574 wps_er_ap_remove_entry(er
, ap
);
581 static void wps_er_ap_remove_all(struct wps_er
*er
)
583 struct wps_er_ap
*prev
, *ap
;
584 dl_list_for_each_safe(ap
, prev
, &er
->ap
, struct wps_er_ap
, list
)
585 wps_er_ap_remove_entry(er
, ap
);
589 static void http_put_date(struct wpabuf
*buf
)
591 wpabuf_put_str(buf
, "Date: ");
593 wpabuf_put_str(buf
, "\r\n");
597 static void wps_er_http_resp_not_found(struct http_request
*req
)
600 buf
= wpabuf_alloc(200);
602 http_request_deinit(req
);
607 "HTTP/1.1 404 Not Found\r\n"
608 "Server: unspecified, UPnP/1.0, unspecified\r\n"
609 "Connection: close\r\n");
611 wpabuf_put_str(buf
, "\r\n");
612 http_request_send_and_deinit(req
, buf
);
616 static void wps_er_http_resp_ok(struct http_request
*req
)
619 buf
= wpabuf_alloc(200);
621 http_request_deinit(req
);
626 "HTTP/1.1 200 OK\r\n"
627 "Server: unspecified, UPnP/1.0, unspecified\r\n"
628 "Connection: close\r\n"
629 "Content-Length: 0\r\n");
631 wpabuf_put_str(buf
, "\r\n");
632 http_request_send_and_deinit(req
, buf
);
636 static void wps_er_sta_timeout(void *eloop_data
, void *user_ctx
)
638 struct wps_er_sta
*sta
= eloop_data
;
639 wpa_printf(MSG_DEBUG
, "WPS ER: STA entry timed out");
640 dl_list_del(&sta
->list
);
641 wps_er_sta_free(sta
);
645 static struct wps_er_sta
* wps_er_add_sta_data(struct wps_er_ap
*ap
,
647 struct wps_parse_attr
*attr
,
650 struct wps_er_sta
*sta
= wps_er_sta_get(ap
, addr
);
654 m1
= !probe_req
&& attr
->msg_type
&& *attr
->msg_type
== WPS_M1
;
658 * Only allow new STA entry to be added based on Probe Request
659 * or M1. This will filter out bogus events and anything that
660 * may have been ongoing at the time ER subscribed for events.
662 if (!probe_req
&& !m1
)
665 sta
= os_zalloc(sizeof(*sta
));
668 os_memcpy(sta
->addr
, addr
, ETH_ALEN
);
670 dl_list_add(&ap
->sta
, &sta
->list
);
675 sta
->m1_received
= 1;
677 if (attr
->config_methods
&& (!probe_req
|| !sta
->m1_received
))
678 sta
->config_methods
= WPA_GET_BE16(attr
->config_methods
);
679 if (attr
->uuid_e
&& (!probe_req
|| !sta
->m1_received
))
680 os_memcpy(sta
->uuid
, attr
->uuid_e
, WPS_UUID_LEN
);
681 if (attr
->primary_dev_type
&& (!probe_req
|| !sta
->m1_received
))
682 os_memcpy(sta
->pri_dev_type
, attr
->primary_dev_type
, 8);
683 if (attr
->dev_password_id
&& (!probe_req
|| !sta
->m1_received
))
684 sta
->dev_passwd_id
= WPA_GET_BE16(attr
->dev_password_id
);
686 if (attr
->manufacturer
) {
687 os_free(sta
->manufacturer
);
688 sta
->manufacturer
= os_malloc(attr
->manufacturer_len
+ 1);
689 if (sta
->manufacturer
) {
690 os_memcpy(sta
->manufacturer
, attr
->manufacturer
,
691 attr
->manufacturer_len
);
692 sta
->manufacturer
[attr
->manufacturer_len
] = '\0';
696 if (attr
->model_name
) {
697 os_free(sta
->model_name
);
698 sta
->model_name
= os_malloc(attr
->model_name_len
+ 1);
699 if (sta
->model_name
) {
700 os_memcpy(sta
->model_name
, attr
->model_name
,
701 attr
->model_name_len
);
702 sta
->model_name
[attr
->model_name_len
] = '\0';
706 if (attr
->model_number
) {
707 os_free(sta
->model_number
);
708 sta
->model_number
= os_malloc(attr
->model_number_len
+ 1);
709 if (sta
->model_number
) {
710 os_memcpy(sta
->model_number
, attr
->model_number
,
711 attr
->model_number_len
);
712 sta
->model_number
[attr
->model_number_len
] = '\0';
716 if (attr
->serial_number
) {
717 os_free(sta
->serial_number
);
718 sta
->serial_number
= os_malloc(attr
->serial_number_len
+ 1);
719 if (sta
->serial_number
) {
720 os_memcpy(sta
->serial_number
, attr
->serial_number
,
721 attr
->serial_number_len
);
722 sta
->serial_number
[attr
->serial_number_len
] = '\0';
726 if (attr
->dev_name
) {
727 os_free(sta
->dev_name
);
728 sta
->dev_name
= os_malloc(attr
->dev_name_len
+ 1);
730 os_memcpy(sta
->dev_name
, attr
->dev_name
,
732 sta
->dev_name
[attr
->dev_name_len
] = '\0';
736 eloop_cancel_timeout(wps_er_sta_timeout
, sta
, NULL
);
737 eloop_register_timeout(300, 0, wps_er_sta_timeout
, sta
, NULL
);
740 wps_er_sta_event(ap
->er
->wps
, sta
, WPS_EV_ER_ENROLLEE_ADD
);
746 static void wps_er_process_wlanevent_probe_req(struct wps_er_ap
*ap
,
750 struct wps_parse_attr attr
;
752 wpa_printf(MSG_DEBUG
, "WPS ER: WLANEvent - Probe Request - from "
753 MACSTR
, MAC2STR(addr
));
754 wpa_hexdump_buf(MSG_MSGDUMP
, "WPS ER: WLANEvent - Enrollee's message "
755 "(TLVs from Probe Request)", msg
);
757 if (wps_parse_msg(msg
, &attr
) < 0) {
758 wpa_printf(MSG_DEBUG
, "WPS ER: Failed to parse TLVs in "
759 "WLANEvent message");
763 wps_er_add_sta_data(ap
, addr
, &attr
, 1);
767 static void wps_er_http_put_wlan_response_cb(void *ctx
, struct http_client
*c
,
768 enum http_client_event event
)
770 struct wps_er_sta
*sta
= ctx
;
774 wpa_printf(MSG_DEBUG
, "WPS ER: PutWLANResponse OK");
776 case HTTP_CLIENT_FAILED
:
777 case HTTP_CLIENT_INVALID_REPLY
:
778 case HTTP_CLIENT_TIMEOUT
:
779 wpa_printf(MSG_DEBUG
, "WPS ER: PutWLANResponse failed");
782 http_client_free(sta
->http
);
787 static const char *soap_prefix
=
788 "<?xml version=\"1.0\"?>\n"
789 "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
790 "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
792 static const char *soap_postfix
=
793 "</s:Body>\n</s:Envelope>\n";
794 static const char *urn_wfawlanconfig
=
795 "urn:schemas-wifialliance-org:service:WFAWLANConfig:1";
797 static struct wpabuf
* wps_er_soap_hdr(const struct wpabuf
*msg
,
798 const char *name
, const char *arg_name
,
800 const struct sockaddr_in
*dst
,
801 char **len_ptr
, char **body_ptr
)
803 unsigned char *encoded
;
808 encoded
= base64_encode(wpabuf_head(msg
), wpabuf_len(msg
),
817 buf
= wpabuf_alloc(1000 + encoded_len
);
824 "POST %s HTTP/1.1\r\n"
826 "Content-Type: text/xml; charset=\"utf-8\"\r\n"
828 path
, inet_ntoa(dst
->sin_addr
), ntohs(dst
->sin_port
));
830 *len_ptr
= wpabuf_put(buf
, 0);
833 "SOAPACTION: \"%s#%s\"\r\n"
835 urn_wfawlanconfig
, name
);
837 *body_ptr
= wpabuf_put(buf
, 0);
839 wpabuf_put_str(buf
, soap_prefix
);
840 wpabuf_printf(buf
, "<u:%s xmlns:u=\"", name
);
841 wpabuf_put_str(buf
, urn_wfawlanconfig
);
842 wpabuf_put_str(buf
, "\">\n");
844 wpabuf_printf(buf
, "<%s>%s</%s>\n",
845 arg_name
, (char *) encoded
, arg_name
);
853 static void wps_er_soap_end(struct wpabuf
*buf
, const char *name
,
854 char *len_ptr
, char *body_ptr
)
857 wpabuf_printf(buf
, "</u:%s>\n", name
);
858 wpabuf_put_str(buf
, soap_postfix
);
859 os_snprintf(len_buf
, sizeof(len_buf
), "%d",
860 (int) ((char *) wpabuf_put(buf
, 0) - body_ptr
));
861 os_memcpy(len_ptr
, len_buf
, os_strlen(len_buf
));
865 static void wps_er_sta_send_msg(struct wps_er_sta
*sta
, struct wpabuf
*msg
)
868 char *len_ptr
, *body_ptr
;
869 struct sockaddr_in dst
;
873 wpa_printf(MSG_DEBUG
, "WPS ER: Pending HTTP request for STA - "
874 "ignore new request");
879 if (sta
->ap
->control_url
== NULL
) {
880 wpa_printf(MSG_DEBUG
, "WPS ER: No controlURL for AP");
885 url
= http_client_url_parse(sta
->ap
->control_url
, &dst
, &path
);
887 wpa_printf(MSG_DEBUG
, "WPS ER: Failed to parse controlURL");
892 buf
= wps_er_soap_hdr(msg
, "PutWLANResponse", "NewMessage", path
, &dst
,
893 &len_ptr
, &body_ptr
);
898 wpabuf_printf(buf
, "<NewWLANEventType>%d</NewWLANEventType>\n",
899 UPNP_WPS_WLANEVENT_TYPE_EAP
);
900 wpabuf_printf(buf
, "<NewWLANEventMAC>" MACSTR
"</NewWLANEventMAC>\n",
903 wps_er_soap_end(buf
, "PutWLANResponse", len_ptr
, body_ptr
);
905 sta
->http
= http_client_addr(&dst
, buf
, 1000,
906 wps_er_http_put_wlan_response_cb
, sta
);
907 if (sta
->http
== NULL
)
912 static void wps_er_sta_process(struct wps_er_sta
*sta
, struct wpabuf
*msg
,
913 enum wsc_op_code op_code
)
915 enum wps_process_res res
;
917 res
= wps_process_msg(sta
->wps
, op_code
, msg
);
918 if (res
== WPS_CONTINUE
) {
919 struct wpabuf
*next
= wps_get_msg(sta
->wps
, &op_code
);
921 wps_er_sta_send_msg(sta
, next
);
923 wpa_printf(MSG_DEBUG
, "WPS ER: Protocol run %s with the "
925 res
== WPS_DONE
? "succeeded" : "failed", res
);
926 wps_deinit(sta
->wps
);
928 if (res
== WPS_DONE
) {
929 /* Remove the STA entry after short timeout */
930 eloop_cancel_timeout(wps_er_sta_timeout
, sta
, NULL
);
931 eloop_register_timeout(10, 0, wps_er_sta_timeout
, sta
,
938 static void wps_er_sta_start(struct wps_er_sta
*sta
, struct wpabuf
*msg
)
940 struct wps_config cfg
;
943 wps_deinit(sta
->wps
);
945 os_memset(&cfg
, 0, sizeof(cfg
));
946 cfg
.wps
= sta
->ap
->er
->wps
;
948 cfg
.peer_addr
= sta
->addr
;
950 sta
->wps
= wps_init(&cfg
);
951 if (sta
->wps
== NULL
)
954 sta
->wps
->use_cred
= sta
->ap
->ap_settings
;
956 wps_er_sta_process(sta
, msg
, WSC_MSG
);
960 static void wps_er_process_wlanevent_eap(struct wps_er_ap
*ap
, const u8
*addr
,
963 struct wps_parse_attr attr
;
964 struct wps_er_sta
*sta
;
966 wpa_printf(MSG_DEBUG
, "WPS ER: WLANEvent - EAP - from " MACSTR
,
968 wpa_hexdump_buf(MSG_MSGDUMP
, "WPS ER: WLANEvent - Enrollee's message "
969 "(TLVs from EAP-WSC)", msg
);
971 if (wps_parse_msg(msg
, &attr
) < 0) {
972 wpa_printf(MSG_DEBUG
, "WPS ER: Failed to parse TLVs in "
973 "WLANEvent message");
977 sta
= wps_er_add_sta_data(ap
, addr
, &attr
, 0);
981 if (attr
.msg_type
&& *attr
.msg_type
== WPS_M1
)
982 wps_er_sta_start(sta
, msg
);
984 enum wsc_op_code op_code
= WSC_MSG
;
986 switch (*attr
.msg_type
) {
998 wps_er_sta_process(sta
, msg
, op_code
);
1003 static void wps_er_process_wlanevent(struct wps_er_ap
*ap
,
1004 struct wpabuf
*event
)
1008 u8 wlan_event_mac
[ETH_ALEN
];
1011 wpa_hexdump(MSG_MSGDUMP
, "WPS ER: Received WLANEvent",
1012 wpabuf_head(event
), wpabuf_len(event
));
1013 if (wpabuf_len(event
) < 1 + 17) {
1014 wpa_printf(MSG_DEBUG
, "WPS ER: Too short WLANEvent");
1018 data
= wpabuf_mhead(event
);
1019 wlan_event_type
= data
[0];
1020 if (hwaddr_aton((char *) data
+ 1, wlan_event_mac
) < 0) {
1021 wpa_printf(MSG_DEBUG
, "WPS ER: Invalid WLANEventMAC in "
1026 wpabuf_set(&msg
, data
+ 1 + 17, wpabuf_len(event
) - (1 + 17));
1028 switch (wlan_event_type
) {
1030 wps_er_process_wlanevent_probe_req(ap
, wlan_event_mac
, &msg
);
1033 wps_er_process_wlanevent_eap(ap
, wlan_event_mac
, &msg
);
1036 wpa_printf(MSG_DEBUG
, "WPS ER: Unknown WLANEventType %d",
1043 static void wps_er_http_event(struct wps_er
*er
, struct http_request
*req
,
1046 struct wps_er_ap
*ap
= wps_er_ap_get_id(er
, ap_id
);
1047 struct wpabuf
*event
;
1048 enum http_reply_code ret
;
1051 wpa_printf(MSG_DEBUG
, "WPS ER: HTTP event from unknown AP id "
1053 wps_er_http_resp_not_found(req
);
1056 wpa_printf(MSG_MSGDUMP
, "WPS ER: HTTP event from AP id %u: %s",
1057 ap_id
, http_request_get_data(req
));
1059 event
= xml_get_base64_item(http_request_get_data(req
), "WLANEvent",
1061 if (event
== NULL
) {
1062 wpa_printf(MSG_DEBUG
, "WPS ER: Could not extract WLANEvent "
1063 "from the event notification");
1065 * Reply with OK anyway to avoid getting unregistered from
1068 wps_er_http_resp_ok(req
);
1072 wps_er_process_wlanevent(ap
, event
);
1075 wps_er_http_resp_ok(req
);
1079 static void wps_er_http_notify(struct wps_er
*er
, struct http_request
*req
)
1081 char *uri
= http_request_get_uri(req
);
1083 if (os_strncmp(uri
, "/event/", 7) == 0) {
1084 unsigned int event_id
;
1086 event_id
= atoi(uri
+ 7);
1087 if (event_id
!= er
->event_id
) {
1088 wpa_printf(MSG_DEBUG
, "WPS ER: HTTP event for an "
1089 "unknown event id %u", event_id
);
1092 pos
= os_strchr(uri
+ 7, '/');
1096 wps_er_http_event(er
, req
, atoi(pos
));
1098 wpa_printf(MSG_DEBUG
, "WPS ER: Unknown HTTP NOTIFY for '%s'",
1100 wps_er_http_resp_not_found(req
);
1105 static void wps_er_http_req(void *ctx
, struct http_request
*req
)
1107 struct wps_er
*er
= ctx
;
1108 struct sockaddr_in
*cli
= http_request_get_cli_addr(req
);
1109 enum httpread_hdr_type type
= http_request_get_type(req
);
1112 wpa_printf(MSG_DEBUG
, "WPS ER: HTTP request: '%s' (type %d) from "
1114 http_request_get_uri(req
), type
,
1115 inet_ntoa(cli
->sin_addr
), ntohs(cli
->sin_port
));
1118 case HTTPREAD_HDR_TYPE_NOTIFY
:
1119 wps_er_http_notify(er
, req
);
1122 wpa_printf(MSG_DEBUG
, "WPS ER: Unsupported HTTP request type "
1124 buf
= wpabuf_alloc(200);
1126 http_request_deinit(req
);
1130 "HTTP/1.1 501 Unimplemented\r\n"
1131 "Connection: close\r\n");
1133 wpabuf_put_str(buf
, "\r\n");
1134 http_request_send_and_deinit(req
, buf
);
1141 wps_er_init(struct wps_context
*wps
, const char *ifname
)
1144 struct in_addr addr
;
1146 er
= os_zalloc(sizeof(*er
));
1149 dl_list_init(&er
->ap
);
1150 dl_list_init(&er
->ap_unsubscribing
);
1152 er
->multicast_sd
= -1;
1155 os_strlcpy(er
->ifname
, ifname
, sizeof(er
->ifname
));
1157 os_get_random((unsigned char *) &er
->event_id
, sizeof(er
->event_id
));
1159 if (get_netif_info(ifname
,
1160 &er
->ip_addr
, &er
->ip_addr_text
,
1161 er
->mac_addr
, &er
->mac_addr_text
)) {
1162 wpa_printf(MSG_INFO
, "WPS UPnP: Could not get IP/MAC address "
1163 "for %s. Does it have IP address?", ifname
);
1164 wps_er_deinit(er
, NULL
, NULL
);
1168 if (wps_er_ssdp_init(er
) < 0) {
1169 wps_er_deinit(er
, NULL
, NULL
);
1173 addr
.s_addr
= er
->ip_addr
;
1174 er
->http_srv
= http_server_init(&addr
, -1, wps_er_http_req
, er
);
1175 if (er
->http_srv
== NULL
) {
1176 wps_er_deinit(er
, NULL
, NULL
);
1179 er
->http_port
= http_server_get_port(er
->http_srv
);
1181 wpa_printf(MSG_DEBUG
, "WPS ER: Start (ifname=%s ip_addr=%s "
1183 er
->ifname
, er
->ip_addr_text
, er
->mac_addr_text
);
1189 void wps_er_refresh(struct wps_er
*er
)
1191 struct wps_er_ap
*ap
;
1192 struct wps_er_sta
*sta
;
1194 dl_list_for_each(ap
, &er
->ap
, struct wps_er_ap
, list
) {
1195 wps_er_ap_event(er
->wps
, ap
, WPS_EV_ER_AP_ADD
);
1196 dl_list_for_each(sta
, &ap
->sta
, struct wps_er_sta
, list
)
1197 wps_er_sta_event(er
->wps
, sta
, WPS_EV_ER_ENROLLEE_ADD
);
1200 wps_er_send_ssdp_msearch(er
);
1204 static void wps_er_deinit_finish(void *eloop_data
, void *user_ctx
)
1206 struct wps_er
*er
= eloop_data
;
1207 void (*deinit_done_cb
)(void *ctx
);
1208 void *deinit_done_ctx
;
1210 wpa_printf(MSG_DEBUG
, "WPS ER: Finishing deinit");
1212 deinit_done_cb
= er
->deinit_done_cb
;
1213 deinit_done_ctx
= er
->deinit_done_ctx
;
1214 os_free(er
->ip_addr_text
);
1215 os_free(er
->mac_addr_text
);
1219 deinit_done_cb(deinit_done_ctx
);
1223 void wps_er_deinit(struct wps_er
*er
, void (*cb
)(void *ctx
), void *ctx
)
1227 http_server_deinit(er
->http_srv
);
1228 wps_er_ap_remove_all(er
);
1229 wps_er_ssdp_deinit(er
);
1230 eloop_register_timeout(dl_list_empty(&er
->ap_unsubscribing
) ? 0 : 5, 0,
1231 wps_er_deinit_finish
, er
, NULL
);
1232 wpa_printf(MSG_DEBUG
, "WPS ER: Finish deinit from timeout");
1233 er
->deinitializing
= 1;
1234 er
->deinit_done_cb
= cb
;
1235 er
->deinit_done_ctx
= ctx
;
1239 static void wps_er_http_set_sel_reg_cb(void *ctx
, struct http_client
*c
,
1240 enum http_client_event event
)
1242 struct wps_er_ap
*ap
= ctx
;
1245 case HTTP_CLIENT_OK
:
1246 wpa_printf(MSG_DEBUG
, "WPS ER: SetSelectedRegistrar OK");
1248 case HTTP_CLIENT_FAILED
:
1249 case HTTP_CLIENT_INVALID_REPLY
:
1250 case HTTP_CLIENT_TIMEOUT
:
1251 wpa_printf(MSG_DEBUG
, "WPS ER: SetSelectedRegistrar failed");
1254 http_client_free(ap
->http
);
1259 static void wps_er_send_set_sel_reg(struct wps_er_ap
*ap
, struct wpabuf
*msg
)
1262 char *len_ptr
, *body_ptr
;
1263 struct sockaddr_in dst
;
1266 if (ap
->control_url
== NULL
) {
1267 wpa_printf(MSG_DEBUG
, "WPS ER: No controlURL for AP");
1272 wpa_printf(MSG_DEBUG
, "WPS ER: Pending HTTP request for AP - "
1273 "ignore new request");
1277 url
= http_client_url_parse(ap
->control_url
, &dst
, &path
);
1279 wpa_printf(MSG_DEBUG
, "WPS ER: Failed to parse controlURL");
1283 buf
= wps_er_soap_hdr(msg
, "SetSelectedRegistrar", "NewMessage", path
,
1284 &dst
, &len_ptr
, &body_ptr
);
1289 wps_er_soap_end(buf
, "SetSelectedRegistrar", len_ptr
, body_ptr
);
1291 ap
->http
= http_client_addr(&dst
, buf
, 1000,
1292 wps_er_http_set_sel_reg_cb
, ap
);
1293 if (ap
->http
== NULL
)
1298 static int wps_er_build_selected_registrar(struct wpabuf
*msg
, int sel_reg
)
1300 wpabuf_put_be16(msg
, ATTR_SELECTED_REGISTRAR
);
1301 wpabuf_put_be16(msg
, 1);
1302 wpabuf_put_u8(msg
, !!sel_reg
);
1307 static int wps_er_build_dev_password_id(struct wpabuf
*msg
, u16 dev_passwd_id
)
1309 wpabuf_put_be16(msg
, ATTR_DEV_PASSWORD_ID
);
1310 wpabuf_put_be16(msg
, 2);
1311 wpabuf_put_be16(msg
, dev_passwd_id
);
1316 static int wps_er_build_sel_reg_config_methods(struct wpabuf
*msg
,
1317 u16 sel_reg_config_methods
)
1319 wpabuf_put_be16(msg
, ATTR_SELECTED_REGISTRAR_CONFIG_METHODS
);
1320 wpabuf_put_be16(msg
, 2);
1321 wpabuf_put_be16(msg
, sel_reg_config_methods
);
1326 void wps_er_set_sel_reg(struct wps_er
*er
, int sel_reg
, u16 dev_passwd_id
,
1327 u16 sel_reg_config_methods
)
1330 struct wps_er_ap
*ap
;
1332 msg
= wpabuf_alloc(500);
1336 if (wps_build_version(msg
) ||
1337 wps_er_build_selected_registrar(msg
, sel_reg
) ||
1338 wps_er_build_dev_password_id(msg
, dev_passwd_id
) ||
1339 wps_er_build_sel_reg_config_methods(msg
, sel_reg_config_methods
)) {
1344 dl_list_for_each(ap
, &er
->ap
, struct wps_er_ap
, list
)
1345 wps_er_send_set_sel_reg(ap
, msg
);
1351 int wps_er_pbc(struct wps_er
*er
, const u8
*uuid
)
1353 if (er
== NULL
|| er
->wps
== NULL
)
1357 * TODO: Should enable PBC mode only in a single AP based on which AP
1358 * the Enrollee (uuid) is using. Now, we may end up enabling multiple
1359 * APs in PBC mode which could result in session overlap at the
1362 if (wps_registrar_button_pushed(er
->wps
->registrar
))
1369 static void wps_er_ap_settings_cb(void *ctx
, const struct wps_credential
*cred
)
1371 struct wps_er_ap
*ap
= ctx
;
1372 wpa_printf(MSG_DEBUG
, "WPS ER: AP Settings received");
1373 os_free(ap
->ap_settings
);
1374 ap
->ap_settings
= os_malloc(sizeof(*cred
));
1375 if (ap
->ap_settings
) {
1376 os_memcpy(ap
->ap_settings
, cred
, sizeof(*cred
));
1377 ap
->ap_settings
->cred_attr
= NULL
;
1380 /* TODO: send info through ctrl_iface */
1384 static void wps_er_http_put_message_cb(void *ctx
, struct http_client
*c
,
1385 enum http_client_event event
)
1387 struct wps_er_ap
*ap
= ctx
;
1388 struct wpabuf
*reply
;
1392 case HTTP_CLIENT_OK
:
1393 wpa_printf(MSG_DEBUG
, "WPS ER: PutMessage OK");
1394 reply
= http_client_get_body(c
);
1397 msg
= os_zalloc(wpabuf_len(reply
) + 1);
1400 os_memcpy(msg
, wpabuf_head(reply
), wpabuf_len(reply
));
1402 case HTTP_CLIENT_FAILED
:
1403 case HTTP_CLIENT_INVALID_REPLY
:
1404 case HTTP_CLIENT_TIMEOUT
:
1405 wpa_printf(MSG_DEBUG
, "WPS ER: PutMessage failed");
1407 wps_deinit(ap
->wps
);
1412 http_client_free(ap
->http
);
1417 enum http_reply_code ret
;
1418 buf
= xml_get_base64_item(msg
, "NewOutMessage", &ret
);
1421 wpa_printf(MSG_DEBUG
, "WPS ER: Could not extract "
1422 "NewOutMessage from PutMessage response");
1425 wps_er_ap_process(ap
, buf
);
1431 static void wps_er_ap_put_message(struct wps_er_ap
*ap
,
1432 const struct wpabuf
*msg
)
1435 char *len_ptr
, *body_ptr
;
1436 struct sockaddr_in dst
;
1440 wpa_printf(MSG_DEBUG
, "WPS ER: Pending HTTP operation ongoing "
1441 "with the AP - cannot continue learn");
1445 if (ap
->control_url
== NULL
) {
1446 wpa_printf(MSG_DEBUG
, "WPS ER: No controlURL for AP");
1450 url
= http_client_url_parse(ap
->control_url
, &dst
, &path
);
1452 wpa_printf(MSG_DEBUG
, "WPS ER: Failed to parse controlURL");
1456 buf
= wps_er_soap_hdr(msg
, "PutMessage", "NewInMessage", path
, &dst
,
1457 &len_ptr
, &body_ptr
);
1462 wps_er_soap_end(buf
, "PutMessage", len_ptr
, body_ptr
);
1464 ap
->http
= http_client_addr(&dst
, buf
, 10000,
1465 wps_er_http_put_message_cb
, ap
);
1466 if (ap
->http
== NULL
)
1471 static void wps_er_ap_process(struct wps_er_ap
*ap
, struct wpabuf
*msg
)
1473 enum wps_process_res res
;
1475 res
= wps_process_msg(ap
->wps
, WSC_MSG
, msg
);
1476 if (res
== WPS_CONTINUE
) {
1477 enum wsc_op_code op_code
;
1478 struct wpabuf
*next
= wps_get_msg(ap
->wps
, &op_code
);
1480 wps_er_ap_put_message(ap
, next
);
1483 wpa_printf(MSG_DEBUG
, "WPS ER: Failed to build "
1485 wps_deinit(ap
->wps
);
1489 wpa_printf(MSG_DEBUG
, "WPS ER: Failed to process message from "
1490 "AP (res=%d)", res
);
1491 wps_deinit(ap
->wps
);
1497 static void wps_er_ap_learn_m1(struct wps_er_ap
*ap
, struct wpabuf
*m1
)
1499 struct wps_config cfg
;
1502 wpa_printf(MSG_DEBUG
, "WPS ER: Protocol run already in "
1503 "progress with this AP");
1507 os_memset(&cfg
, 0, sizeof(cfg
));
1508 cfg
.wps
= ap
->er
->wps
;
1510 ap
->wps
= wps_init(&cfg
);
1511 if (ap
->wps
== NULL
)
1513 ap
->wps
->ap_settings_cb
= wps_er_ap_settings_cb
;
1514 ap
->wps
->ap_settings_cb_ctx
= ap
;
1516 wps_er_ap_process(ap
, m1
);
1520 static void wps_er_ap_learn(struct wps_er_ap
*ap
, const char *dev_info
)
1522 struct wpabuf
*info
;
1523 enum http_reply_code ret
;
1525 wpa_printf(MSG_DEBUG
, "WPS ER: Received GetDeviceInfo response (M1) "
1527 info
= xml_get_base64_item(dev_info
, "NewDeviceInfo", &ret
);
1529 wpa_printf(MSG_DEBUG
, "WPS ER: Could not extract "
1530 "NewDeviceInfo from GetDeviceInfo response");
1534 ap
->m1_handler(ap
, info
);
1539 static void wps_er_http_get_dev_info_cb(void *ctx
, struct http_client
*c
,
1540 enum http_client_event event
)
1542 struct wps_er_ap
*ap
= ctx
;
1543 struct wpabuf
*reply
;
1544 char *dev_info
= NULL
;
1547 case HTTP_CLIENT_OK
:
1548 wpa_printf(MSG_DEBUG
, "WPS ER: GetDeviceInfo OK");
1549 reply
= http_client_get_body(c
);
1552 dev_info
= os_zalloc(wpabuf_len(reply
) + 1);
1553 if (dev_info
== NULL
)
1555 os_memcpy(dev_info
, wpabuf_head(reply
), wpabuf_len(reply
));
1557 case HTTP_CLIENT_FAILED
:
1558 case HTTP_CLIENT_INVALID_REPLY
:
1559 case HTTP_CLIENT_TIMEOUT
:
1560 wpa_printf(MSG_DEBUG
, "WPS ER: GetDeviceInfo failed");
1563 http_client_free(ap
->http
);
1567 wps_er_ap_learn(ap
, dev_info
);
1573 static int wps_er_send_get_device_info(struct wps_er_ap
*ap
,
1574 void (*m1_handler
)(struct wps_er_ap
*ap
,
1578 char *len_ptr
, *body_ptr
;
1579 struct sockaddr_in dst
;
1583 wpa_printf(MSG_DEBUG
, "WPS ER: Pending HTTP operation ongoing "
1584 "with the AP - cannot get device info");
1588 if (ap
->control_url
== NULL
) {
1589 wpa_printf(MSG_DEBUG
, "WPS ER: No controlURL for AP");
1593 url
= http_client_url_parse(ap
->control_url
, &dst
, &path
);
1595 wpa_printf(MSG_DEBUG
, "WPS ER: Failed to parse controlURL");
1599 buf
= wps_er_soap_hdr(NULL
, "GetDeviceInfo", NULL
, path
, &dst
,
1600 &len_ptr
, &body_ptr
);
1605 wps_er_soap_end(buf
, "GetDeviceInfo", len_ptr
, body_ptr
);
1607 ap
->http
= http_client_addr(&dst
, buf
, 10000,
1608 wps_er_http_get_dev_info_cb
, ap
);
1609 if (ap
->http
== NULL
) {
1614 ap
->m1_handler
= m1_handler
;
1620 int wps_er_learn(struct wps_er
*er
, const u8
*uuid
, const u8
*pin
,
1623 struct wps_er_ap
*ap
;
1628 ap
= wps_er_ap_get(er
, NULL
, uuid
);
1630 wpa_printf(MSG_DEBUG
, "WPS ER: AP not found for learn "
1635 wpa_printf(MSG_DEBUG
, "WPS ER: Pending operation ongoing "
1636 "with the AP - cannot start learn");
1640 if (wps_er_send_get_device_info(ap
, wps_er_ap_learn_m1
) < 0)
1643 /* TODO: add PIN without SetSelectedRegistrar trigger to all APs */
1644 wps_registrar_add_pin(er
->wps
->registrar
, uuid
, pin
, pin_len
, 0);