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.
21 #include "http_client.h"
22 #include "http_server.h"
26 #include "wps_upnp_i.h"
30 * send notification of new AP device with wpa_msg
31 * re-send notifications with wpa_msg if ER re-started (to update wpa_gui-qt4)
32 * (also re-send SSDP M-SEARCH in this case to find new APs)
33 * parse UPnP event messages
36 static void wps_er_ap_timeout(void *eloop_data, void *user_ctx);
37 static void wps_er_sta_timeout(void *eloop_data, void *user_ctx);
41 struct wps_er_sta *next;
45 u8 uuid[WPS_UUID_LEN];
55 struct http_client *http;
59 struct wps_er_ap *next;
61 struct wps_er_sta *sta; /* list of STAs/Enrollees using this AP */
64 struct http_client *http;
68 char *manufacturer_url;
69 char *model_description;
86 struct wps_context *wps;
88 char *mac_addr_text; /* mac addr of network i.f. we use */
89 u8 mac_addr[ETH_ALEN]; /* mac addr of network i.f. we use */
90 char *ip_addr_text; /* IP address of network i.f. we use */
91 unsigned ip_addr; /* IP address of network i.f. we use (host order) */
95 struct http_server *http_srv;
97 unsigned int next_ap_id;
101 static struct wps_er_sta * wps_er_sta_get(struct wps_er_ap *ap, const u8 *addr)
103 struct wps_er_sta *sta = ap->sta;
105 if (os_memcmp(sta->addr, addr, ETH_ALEN) == 0)
113 static void wps_er_sta_free(struct wps_er_sta *sta)
116 wps_deinit(sta->wps);
117 os_free(sta->manufacturer);
118 os_free(sta->model_name);
119 os_free(sta->model_number);
120 os_free(sta->serial_number);
121 os_free(sta->dev_name);
122 http_client_free(sta->http);
123 eloop_cancel_timeout(wps_er_sta_timeout, sta, NULL);
128 static void wps_er_sta_remove_all(struct wps_er_ap *ap)
130 struct wps_er_sta *prev, *sta;
138 wps_er_sta_free(prev);
143 static void wps_er_pin_needed_cb(void *ctx, const u8 *uuid_e,
144 const struct wps_device_data *dev)
146 wpa_printf(MSG_DEBUG, "WPS ER: PIN needed");
150 static struct wps_er_ap * wps_er_ap_get(struct wps_er *er,
151 struct in_addr *addr)
153 struct wps_er_ap *ap;
154 for (ap = er->ap; ap; ap = ap->next) {
155 if (ap->addr.s_addr == addr->s_addr)
162 static struct wps_er_ap * wps_er_ap_get_id(struct wps_er *er, unsigned int id)
164 struct wps_er_ap *ap;
165 for (ap = er->ap; ap; ap = ap->next) {
173 static void wps_er_ap_free(struct wps_er *er, struct wps_er_ap *ap)
175 /* TODO: if ap->subscribed, unsubscribe from events if the AP is still
177 wpa_printf(MSG_DEBUG, "WPS ER: Removing AP entry for %s (%s)",
178 inet_ntoa(ap->addr), ap->location);
179 eloop_cancel_timeout(wps_er_ap_timeout, er, ap);
180 os_free(ap->location);
181 http_client_free(ap->http);
183 os_free(ap->friendly_name);
184 os_free(ap->manufacturer);
185 os_free(ap->manufacturer_url);
186 os_free(ap->model_description);
187 os_free(ap->model_name);
188 os_free(ap->model_number);
189 os_free(ap->model_url);
190 os_free(ap->serial_number);
194 os_free(ap->scpd_url);
195 os_free(ap->control_url);
196 os_free(ap->event_sub_url);
198 wps_er_sta_remove_all(ap);
204 static void wps_er_ap_timeout(void *eloop_data, void *user_ctx)
206 struct wps_er *er = eloop_data;
207 struct wps_er_ap *ap = user_ctx;
208 wpa_printf(MSG_DEBUG, "WPS ER: AP advertisement timed out");
209 wps_er_ap_free(er, ap);
213 static void wps_er_http_subscribe_cb(void *ctx, struct http_client *c,
214 enum http_client_event event)
216 struct wps_er_ap *ap = ctx;
220 wpa_printf(MSG_DEBUG, "WPS ER: Subscribed to events");
222 case HTTP_CLIENT_FAILED:
223 case HTTP_CLIENT_INVALID_REPLY:
224 case HTTP_CLIENT_TIMEOUT:
225 wpa_printf(MSG_DEBUG, "WPS ER: Failed to subscribe to events");
228 http_client_free(ap->http);
233 static void wps_er_subscribe(struct wps_er_ap *ap)
236 struct sockaddr_in dst;
239 if (ap->event_sub_url == NULL) {
240 wpa_printf(MSG_DEBUG, "WPS ER: No eventSubURL - cannot "
245 wpa_printf(MSG_DEBUG, "WPS ER: Pending HTTP request - cannot "
246 "send subscribe request");
250 url = http_client_url_parse(ap->event_sub_url, &dst, &path);
252 wpa_printf(MSG_DEBUG, "WPS ER: Failed to parse eventSubURL");
256 req = wpabuf_alloc(os_strlen(ap->event_sub_url) + 1000);
262 "SUBSCRIBE %s HTTP/1.1\r\n"
264 "CALLBACK: <http://%s:%d/event/%d>\r\n"
266 "TIMEOUT: Second-%d\r\n"
268 path, inet_ntoa(dst.sin_addr), ntohs(dst.sin_port),
269 ap->er->ip_addr_text, ap->er->http_port, ap->id, 1800);
271 wpa_hexdump_ascii(MSG_MSGDUMP, "WPS ER: Subscription request",
272 wpabuf_head(req), wpabuf_len(req));
274 ap->http = http_client_addr(&dst, req, 1000, wps_er_http_subscribe_cb,
276 if (ap->http == NULL)
281 static void wps_er_parse_device_description(struct wps_er_ap *ap,
282 struct wpabuf *reply)
284 /* Note: reply includes null termination after the buffer data */
285 const char *data = wpabuf_head(reply);
287 wpa_hexdump_ascii(MSG_MSGDUMP, "WPS ER: Device info",
288 wpabuf_head(reply), wpabuf_len(reply));
290 ap->friendly_name = xml_get_first_item(data, "friendlyName");
291 wpa_printf(MSG_DEBUG, "WPS ER: friendlyName='%s'", ap->friendly_name);
293 ap->manufacturer = xml_get_first_item(data, "manufacturer");
294 wpa_printf(MSG_DEBUG, "WPS ER: manufacturer='%s'", ap->manufacturer);
296 ap->manufacturer_url = xml_get_first_item(data, "manufacturerURL");
297 wpa_printf(MSG_DEBUG, "WPS ER: manufacturerURL='%s'",
298 ap->manufacturer_url);
300 ap->model_description = xml_get_first_item(data, "modelDescription");
301 wpa_printf(MSG_DEBUG, "WPS ER: modelDescription='%s'",
302 ap->model_description);
304 ap->model_name = xml_get_first_item(data, "modelName");
305 wpa_printf(MSG_DEBUG, "WPS ER: modelName='%s'", ap->model_name);
307 ap->model_number = xml_get_first_item(data, "modelNumber");
308 wpa_printf(MSG_DEBUG, "WPS ER: modelNumber='%s'", ap->model_number);
310 ap->model_url = xml_get_first_item(data, "modelURL");
311 wpa_printf(MSG_DEBUG, "WPS ER: modelURL='%s'", ap->model_url);
313 ap->serial_number = xml_get_first_item(data, "serialNumber");
314 wpa_printf(MSG_DEBUG, "WPS ER: serialNumber='%s'", ap->serial_number);
316 ap->udn = xml_get_first_item(data, "UDN");
317 wpa_printf(MSG_DEBUG, "WPS ER: UDN='%s'", ap->udn);
319 ap->upc = xml_get_first_item(data, "UPC");
320 wpa_printf(MSG_DEBUG, "WPS ER: UPC='%s'", ap->upc);
322 ap->scpd_url = http_link_update(
323 xml_get_first_item(data, "SCPDURL"), ap->location);
324 wpa_printf(MSG_DEBUG, "WPS ER: SCPDURL='%s'", ap->scpd_url);
326 ap->control_url = http_link_update(
327 xml_get_first_item(data, "controlURL"), ap->location);
328 wpa_printf(MSG_DEBUG, "WPS ER: controlURL='%s'", ap->control_url);
330 ap->event_sub_url = http_link_update(
331 xml_get_first_item(data, "eventSubURL"), ap->location);
332 wpa_printf(MSG_DEBUG, "WPS ER: eventSubURL='%s'", ap->event_sub_url);
336 static void wps_er_http_dev_desc_cb(void *ctx, struct http_client *c,
337 enum http_client_event event)
339 struct wps_er_ap *ap = ctx;
340 struct wpabuf *reply;
345 reply = http_client_get_body(c);
348 wps_er_parse_device_description(ap, reply);
351 case HTTP_CLIENT_FAILED:
352 case HTTP_CLIENT_INVALID_REPLY:
353 case HTTP_CLIENT_TIMEOUT:
354 wpa_printf(MSG_DEBUG, "WPS ER: Failed to fetch device info");
357 http_client_free(ap->http);
360 wps_er_subscribe(ap);
364 static void wps_er_ap_add(struct wps_er *er, struct in_addr *addr,
365 const char *location, int max_age)
367 struct wps_er_ap *ap;
369 ap = wps_er_ap_get(er, addr);
371 /* Update advertisement timeout */
372 eloop_cancel_timeout(wps_er_ap_timeout, er, ap);
373 eloop_register_timeout(max_age, 0, wps_er_ap_timeout, er, ap);
377 ap = os_zalloc(sizeof(*ap));
381 ap->id = ++er->next_ap_id;
382 ap->location = os_strdup(location);
383 if (ap->location == NULL) {
390 ap->addr.s_addr = addr->s_addr;
391 eloop_register_timeout(max_age, 0, wps_er_ap_timeout, er, ap);
393 wpa_printf(MSG_DEBUG, "WPS ER: Added AP entry for %s (%s)",
394 inet_ntoa(ap->addr), ap->location);
396 /* Fetch device description */
397 ap->http = http_client_url(ap->location, NULL, 10000,
398 wps_er_http_dev_desc_cb, ap);
402 static void wps_er_ap_remove(struct wps_er *er, struct in_addr *addr)
404 struct wps_er_ap *prev = NULL, *ap = er->ap;
407 if (ap->addr.s_addr == addr->s_addr) {
409 prev->next = ap->next;
412 wps_er_ap_free(er, ap);
421 static void wps_er_ap_remove_all(struct wps_er *er)
423 struct wps_er_ap *prev, *ap;
431 wps_er_ap_free(er, prev);
436 static void wps_er_ssdp_rx(int sd, void *eloop_ctx, void *sock_ctx)
438 struct wps_er *er = eloop_ctx;
439 struct sockaddr_in addr; /* client address */
442 char buf[MULTICAST_MAX_READ], *pos, *pos2, *start;
443 int wfa = 0, byebye = 0;
445 char *location = NULL;
447 addr_len = sizeof(addr);
448 nread = recvfrom(sd, buf, sizeof(buf) - 1, 0,
449 (struct sockaddr *) &addr, &addr_len);
454 wpa_printf(MSG_DEBUG, "WPS ER: Received SSDP from %s",
455 inet_ntoa(addr.sin_addr));
456 wpa_hexdump_ascii(MSG_MSGDUMP, "WPS ER: Received SSDP contents",
459 if (sd == er->multicast_sd) {
460 /* Reply to M-SEARCH */
461 if (os_strncmp(buf, "HTTP/1.1 200 OK", 15) != 0)
462 return; /* unexpected response header */
464 /* Unsolicited message (likely NOTIFY or M-SEARCH) */
465 if (os_strncmp(buf, "NOTIFY ", 7) != 0)
466 return; /* only process notifications */
469 for (start = buf; start && *start; start = pos) {
470 pos = os_strchr(start, '\n');
476 if (os_strstr(start, "schemas-wifialliance-org:device:"
479 if (os_strstr(start, "schemas-wifialliance-org:service:"
482 if (os_strncasecmp(start, "LOCATION:", 9) == 0) {
484 while (*start == ' ')
487 } else if (os_strncasecmp(start, "NTS:", 4) == 0) {
488 if (os_strstr(start, "ssdp:byebye"))
490 } else if (os_strncasecmp(start, "CACHE-CONTROL:", 14) == 0) {
492 while (*start == ' ')
494 pos2 = os_strstr(start, "max-age=");
498 max_age = atoi(pos2);
503 return; /* Not WPS advertisement/reply */
506 wps_er_ap_remove(er, &addr.sin_addr);
511 return; /* Unknown location */
514 return; /* No max-age reported */
516 wpa_printf(MSG_DEBUG, "WPS ER: AP discovered: %s "
517 "(packet source: %s max-age: %d)",
518 location, inet_ntoa(addr.sin_addr), max_age);
520 wps_er_ap_add(er, &addr.sin_addr, location, max_age);
524 static void wps_er_send_ssdp_msearch(struct wps_er *er)
527 struct sockaddr_in dest;
529 msg = wpabuf_alloc(500);
534 "M-SEARCH * HTTP/1.1\r\n"
535 "HOST: 239.255.255.250:1900\r\n"
536 "MAN: \"ssdp:discover\"\r\n"
538 "ST: urn:schemas-wifialliance-org:device:WFADevice:1"
542 os_memset(&dest, 0, sizeof(dest));
543 dest.sin_family = AF_INET;
544 dest.sin_addr.s_addr = inet_addr(UPNP_MULTICAST_ADDRESS);
545 dest.sin_port = htons(UPNP_MULTICAST_PORT);
547 if (sendto(er->multicast_sd, wpabuf_head(msg), wpabuf_len(msg), 0,
548 (struct sockaddr *) &dest, sizeof(dest)) < 0)
549 wpa_printf(MSG_DEBUG, "WPS ER: M-SEARCH sendto failed: "
550 "%d (%s)", errno, strerror(errno));
556 static void http_put_date(struct wpabuf *buf)
558 wpabuf_put_str(buf, "Date: ");
560 wpabuf_put_str(buf, "\r\n");
564 static void wps_er_http_resp_not_found(struct http_request *req)
567 buf = wpabuf_alloc(200);
569 http_request_deinit(req);
574 "HTTP/1.1 404 Not Found\r\n"
575 "Server: unspecified, UPnP/1.0, unspecified\r\n"
576 "Connection: close\r\n");
578 wpabuf_put_str(buf, "\r\n");
579 http_request_send_and_deinit(req, buf);
583 static void wps_er_http_resp_ok(struct http_request *req)
586 buf = wpabuf_alloc(200);
588 http_request_deinit(req);
593 "HTTP/1.1 200 OK\r\n"
594 "Server: unspecified, UPnP/1.0, unspecified\r\n"
595 "Connection: close\r\n"
596 "Content-Length: 0\r\n");
598 wpabuf_put_str(buf, "\r\n");
599 http_request_send_and_deinit(req, buf);
603 static void wps_er_sta_timeout(void *eloop_data, void *user_ctx)
605 struct wps_er_sta *sta = eloop_data;
606 wpa_printf(MSG_DEBUG, "WPS ER: STA entry timed out");
607 wps_er_sta_free(sta);
611 static struct wps_er_sta * wps_er_add_sta_data(struct wps_er_ap *ap,
613 struct wps_parse_attr *attr,
616 struct wps_er_sta *sta = wps_er_sta_get(ap, addr);
619 sta = os_zalloc(sizeof(*sta));
622 os_memcpy(sta->addr, addr, ETH_ALEN);
629 sta->m1_received = 1;
631 if (attr->config_methods && (!probe_req || !sta->m1_received))
632 sta->config_methods = WPA_GET_BE16(attr->config_methods);
633 if (attr->uuid_e && (!probe_req || !sta->m1_received))
634 os_memcpy(sta->uuid, attr->uuid_e, WPS_UUID_LEN);
635 if (attr->primary_dev_type && (!probe_req || !sta->m1_received))
636 os_memcpy(sta->pri_dev_type, attr->primary_dev_type, 8);
637 if (attr->dev_password_id && (!probe_req || !sta->m1_received))
638 sta->dev_passwd_id = WPA_GET_BE16(attr->dev_password_id);
640 if (attr->manufacturer) {
641 os_free(sta->manufacturer);
642 sta->manufacturer = os_malloc(attr->manufacturer_len + 1);
643 if (sta->manufacturer) {
644 os_memcpy(sta->manufacturer, attr->manufacturer,
645 attr->manufacturer_len);
646 sta->manufacturer[attr->manufacturer_len] = '\0';
650 if (attr->model_name) {
651 os_free(sta->model_name);
652 sta->model_name = os_malloc(attr->model_name_len + 1);
653 if (sta->model_name) {
654 os_memcpy(sta->model_name, attr->model_name,
655 attr->model_name_len);
656 sta->model_name[attr->model_name_len] = '\0';
660 if (attr->model_number) {
661 os_free(sta->model_number);
662 sta->model_number = os_malloc(attr->model_number_len + 1);
663 if (sta->model_number) {
664 os_memcpy(sta->model_number, attr->model_number,
665 attr->model_number_len);
666 sta->model_number[attr->model_number_len] = '\0';
670 if (attr->serial_number) {
671 os_free(sta->serial_number);
672 sta->serial_number = os_malloc(attr->serial_number_len + 1);
673 if (sta->serial_number) {
674 os_memcpy(sta->serial_number, attr->serial_number,
675 attr->serial_number_len);
676 sta->serial_number[attr->serial_number_len] = '\0';
680 if (attr->dev_name) {
681 os_free(sta->dev_name);
682 sta->dev_name = os_malloc(attr->dev_name_len + 1);
684 os_memcpy(sta->dev_name, attr->dev_name,
686 sta->dev_name[attr->dev_name_len] = '\0';
690 eloop_cancel_timeout(wps_er_sta_timeout, sta, NULL);
691 eloop_register_timeout(300, 0, wps_er_sta_timeout, sta, NULL);
693 /* TODO: wpa_msg indication if new STA */
699 static void wps_er_process_wlanevent_probe_req(struct wps_er_ap *ap,
703 struct wps_parse_attr attr;
705 wpa_printf(MSG_DEBUG, "WPS ER: WLANEvent - Probe Request - from "
706 MACSTR, MAC2STR(addr));
707 wpa_hexdump_buf(MSG_MSGDUMP, "WPS ER: WLANEvent - Enrollee's message "
708 "(TLVs from Probe Request)", msg);
710 if (wps_parse_msg(msg, &attr) < 0) {
711 wpa_printf(MSG_DEBUG, "WPS ER: Failed to parse TLVs in "
712 "WLANEvent message");
716 wps_er_add_sta_data(ap, addr, &attr, 1);
720 static void wps_er_sta_send_msg(struct wps_er_sta *sta, struct wpabuf *msg)
722 /* TODO: send msg as UPnP POST: PutWLANResponse(NewMessage,
723 * NewWLANEventType, NewWLANEventMAC) */
729 static void wps_er_sta_process(struct wps_er_sta *sta, struct wpabuf *msg)
731 enum wps_process_res res;
733 res = wps_process_msg(sta->wps, WSC_MSG, msg);
734 if (res == WPS_CONTINUE) {
735 enum wsc_op_code op_code;
736 struct wpabuf *next = wps_get_msg(sta->wps, &op_code);
738 wps_er_sta_send_msg(sta, next);
743 static void wps_er_sta_start(struct wps_er_sta *sta, struct wpabuf *msg)
745 struct wps_config cfg;
748 wps_deinit(sta->wps);
750 os_memset(&cfg, 0, sizeof(cfg));
751 cfg.wps = sta->ap->er->wps;
753 cfg.peer_addr = sta->addr;
755 sta->wps = wps_init(&cfg);
756 if (sta->wps == NULL)
759 wps_er_sta_process(sta, msg);
763 static void wps_er_process_wlanevent_eap(struct wps_er_ap *ap, const u8 *addr,
766 struct wps_parse_attr attr;
767 struct wps_er_sta *sta;
769 wpa_printf(MSG_DEBUG, "WPS ER: WLANEvent - EAP - from " MACSTR,
771 wpa_hexdump_buf(MSG_MSGDUMP, "WPS ER: WLANEvent - Enrollee's message "
772 "(TLVs from EAP-WSC)", msg);
774 if (wps_parse_msg(msg, &attr) < 0) {
775 wpa_printf(MSG_DEBUG, "WPS ER: Failed to parse TLVs in "
776 "WLANEvent message");
780 sta = wps_er_add_sta_data(ap, addr, &attr, 0);
782 if (attr.msg_type && *attr.msg_type == WPS_M1)
783 wps_er_sta_start(sta, msg);
785 wps_er_sta_process(sta, msg);
789 static void wps_er_process_wlanevent(struct wps_er_ap *ap,
790 struct wpabuf *event)
794 u8 wlan_event_mac[ETH_ALEN];
797 wpa_hexdump(MSG_MSGDUMP, "WPS ER: Received WLANEvent",
798 wpabuf_head(event), wpabuf_len(event));
799 if (wpabuf_len(event) < 1 + 17) {
800 wpa_printf(MSG_DEBUG, "WPS ER: Too short WLANEvent");
804 data = wpabuf_mhead(event);
805 wlan_event_type = data[0];
806 if (hwaddr_aton((char *) data + 1, wlan_event_mac) < 0) {
807 wpa_printf(MSG_DEBUG, "WPS ER: Invalid WLANEventMAC in "
812 wpabuf_set(&msg, data + 1 + 17, wpabuf_len(event) - (1 + 17));
814 switch (wlan_event_type) {
816 wps_er_process_wlanevent_probe_req(ap, wlan_event_mac, &msg);
819 wps_er_process_wlanevent_eap(ap, wlan_event_mac, &msg);
822 wpa_printf(MSG_DEBUG, "WPS ER: Unknown WLANEventType %d",
829 static void wps_er_http_event(struct wps_er *er, struct http_request *req,
832 struct wps_er_ap *ap = wps_er_ap_get_id(er, ap_id);
833 struct wpabuf *event;
834 enum http_reply_code ret;
837 wpa_printf(MSG_DEBUG, "WPS ER: HTTP event from unknown AP id "
839 wps_er_http_resp_not_found(req);
842 wpa_printf(MSG_MSGDUMP, "WPS ER: HTTP event from AP id %u: %s",
843 ap_id, http_request_get_data(req));
845 event = xml_get_base64_item(http_request_get_data(req), "WLANEvent",
848 wpa_printf(MSG_DEBUG, "WPS ER: Could not extract WLANEvent "
849 "from the event notification");
851 * Reply with OK anyway to avoid getting unregistered from
854 wps_er_http_resp_ok(req);
858 wps_er_process_wlanevent(ap, event);
861 wps_er_http_resp_ok(req);
865 static void wps_er_http_notify(struct wps_er *er, struct http_request *req)
867 char *uri = http_request_get_uri(req);
869 if (os_strncmp(uri, "/event/", 7) == 0) {
870 wps_er_http_event(er, req, atoi(uri + 7));
872 wpa_printf(MSG_DEBUG, "WPS ER: Unknown HTTP NOTIFY for '%s'",
874 wps_er_http_resp_not_found(req);
879 static void wps_er_http_req(void *ctx, struct http_request *req)
881 struct wps_er *er = ctx;
882 struct sockaddr_in *cli = http_request_get_cli_addr(req);
883 enum httpread_hdr_type type = http_request_get_type(req);
886 wpa_printf(MSG_DEBUG, "WPS ER: HTTP request: '%s' (type %d) from "
888 http_request_get_uri(req), type,
889 inet_ntoa(cli->sin_addr), ntohs(cli->sin_port));
892 case HTTPREAD_HDR_TYPE_NOTIFY:
893 wps_er_http_notify(er, req);
896 wpa_printf(MSG_DEBUG, "WPS ER: Unsupported HTTP request type "
898 buf = wpabuf_alloc(200);
900 http_request_deinit(req);
904 "HTTP/1.1 501 Unimplemented\r\n"
905 "Connection: close\r\n");
907 wpabuf_put_str(buf, "\r\n");
908 http_request_send_and_deinit(req, buf);
915 wps_er_init(struct wps_context *wps, const char *ifname)
918 struct wps_registrar_config rcfg;
921 er = os_zalloc(sizeof(*er));
925 er->multicast_sd = -1;
928 os_strlcpy(er->ifname, ifname, sizeof(er->ifname));
930 os_memset(&rcfg, 0, sizeof(rcfg));
931 rcfg.pin_needed_cb = wps_er_pin_needed_cb;
934 if (get_netif_info(ifname,
935 &er->ip_addr, &er->ip_addr_text,
936 er->mac_addr, &er->mac_addr_text)) {
937 wpa_printf(MSG_INFO, "WPS UPnP: Could not get IP/MAC address "
938 "for %s. Does it have IP address?", ifname);
943 if (add_ssdp_network(ifname)) {
948 er->multicast_sd = ssdp_open_multicast_sock(er->ip_addr);
949 if (er->multicast_sd < 0) {
954 er->ssdp_sd = ssdp_listener_open();
955 if (er->ssdp_sd < 0) {
959 if (eloop_register_sock(er->multicast_sd, EVENT_TYPE_READ,
960 wps_er_ssdp_rx, er, NULL) ||
961 eloop_register_sock(er->ssdp_sd, EVENT_TYPE_READ,
962 wps_er_ssdp_rx, er, NULL)) {
967 addr.s_addr = er->ip_addr;
968 er->http_srv = http_server_init(&addr, -1, wps_er_http_req, er);
969 if (er->http_srv == NULL) {
973 er->http_port = http_server_get_port(er->http_srv);
975 wpa_printf(MSG_DEBUG, "WPS ER: Start (ifname=%s ip_addr=%s "
977 er->ifname, er->ip_addr_text, er->mac_addr_text);
979 wps_er_send_ssdp_msearch(er);
985 void wps_er_deinit(struct wps_er *er)
989 http_server_deinit(er->http_srv);
990 wps_er_ap_remove_all(er);
991 if (er->multicast_sd >= 0) {
992 eloop_unregister_sock(er->multicast_sd, EVENT_TYPE_READ);
993 close(er->multicast_sd);
995 if (er->ssdp_sd >= 0) {
996 eloop_unregister_sock(er->ssdp_sd, EVENT_TYPE_READ);
999 os_free(er->ip_addr_text);
1000 os_free(er->mac_addr_text);