Browse Source

WPS UPnP: Add IP address and port details into debug messages

This makes it much easier to debug operations with multiple external
Registrars.
Jouni Malinen 16 years ago
parent
commit
745f8b664d
3 changed files with 28 additions and 16 deletions
  1. 1 1
      src/wps/wps_upnp.c
  2. 13 5
      src/wps/wps_upnp_event.c
  3. 14 10
      src/wps/wps_upnp_web.c

+ 1 - 1
src/wps/wps_upnp.c

@@ -465,7 +465,7 @@ static void subscr_addr_list_create(struct subscription *s,
 
 int send_wpabuf(int fd, struct wpabuf *buf)
 {
-	wpa_printf(MSG_DEBUG, "WPS UPnP: %lu byte response",
+	wpa_printf(MSG_DEBUG, "WPS UPnP: Send %lu byte message",
 		   (unsigned long) wpabuf_len(buf));
 	errno = 0;
 	if (write(fd, wpabuf_head(buf), wpabuf_len(buf)) !=

+ 13 - 5
src/wps/wps_upnp_event.c

@@ -187,7 +187,8 @@ static void event_retry(struct wps_event_ *e, int do_next_address)
 	if (do_next_address)
 		e->retry++;
 	if (e->retry >= s->n_addr) {
-		wpa_printf(MSG_DEBUG, "WPS UPnP: Giving up on sending event");
+		wpa_printf(MSG_DEBUG, "WPS UPnP: Giving up on sending event "
+			   "for %s", e->addr->domain_and_port);
 		return;
 	}
 	event_enqueue_at_begin(s, e);
@@ -226,20 +227,25 @@ static void event_got_response_handler(struct httpread *handle, void *cookie,
 			reply_code = httpread_reply_code_get(hread);
 			if (reply_code == HTTP_OK) {
 				wpa_printf(MSG_DEBUG,
-					   "WPS UPnP: Got event reply OK");
+					   "WPS UPnP: Got event reply OK from "
+					   "%s", e->addr->domain_and_port);
 				event_delete(e);
 				goto send_more;
 			} else {
 				wpa_printf(MSG_DEBUG, "WPS UPnP: Got event "
-					   "error reply code %d", reply_code);
+					   "error reply code %d from %s",
+					   reply_code,
+					   e->addr->domain_and_port);
 				goto bad;
 			}
 		} else {
 			wpa_printf(MSG_DEBUG, "WPS UPnP: Got bogus event "
-				   "response %d", en);
+				   "response %d from %s", en,
+				   e->addr->domain_and_port);
 		}
 	} else {
-		wpa_printf(MSG_DEBUG, "WPS UPnP: Event response timeout/fail");
+		wpa_printf(MSG_DEBUG, "WPS UPnP: Event response timeout/fail "
+			   "for %s", e->addr->domain_and_port);
 		goto bad;
 	}
 	event_retry(e, 1);
@@ -313,6 +319,8 @@ static void event_send_tx_ready(int sock, void *eloop_ctx, void *sock_ctx)
 	/* we could: Turn blocking back on? */
 	fcntl(e->sd, F_SETFL, 0);
 #endif
+	wpa_printf(MSG_DEBUG, "WPS UPnP: Sending event to %s",
+		   e->addr->domain_and_port);
 	if (send_wpabuf(e->sd, buf) < 0) {
 		event_retry(e, 1);
 		goto bad;

+ 14 - 10
src/wps/wps_upnp_web.c

@@ -51,6 +51,7 @@ struct web_connection {
 	struct web_connection *prev;
 	struct upnp_wps_device_sm *sm; /* parent */
 	int sd; /* socket to read from */
+	struct sockaddr_in cli_addr;
 	int sd_registered; /* nonzero if we must cancel registration */
 	struct httpread *hread; /* state machine for reading socket */
 	int n_rcvd_data; /* how much data read so far */
@@ -689,6 +690,7 @@ static void web_connection_parse_get(struct web_connection *c, char *filename)
 	if (filename == NULL)
 		filename = "(null)"; /* just in case */
 	if (os_strcasecmp(filename, UPNP_WPS_DEVICE_XML_FILE) == 0) {
+		wpa_printf(MSG_DEBUG, "WPS UPnP: HTTP GET for device XML");
 		req = GET_DEVICE_XML_FILE;
 		extra_len = 3000;
 		if (sm->wps->friendly_name)
@@ -702,11 +704,12 @@ static void web_connection_parse_get(struct web_connection *c, char *filename)
 		if (sm->wps->upc)
 			extra_len += os_strlen(sm->wps->upc);
 	} else if (!os_strcasecmp(filename, UPNP_WPS_SCPD_XML_FILE)) {
+		wpa_printf(MSG_DEBUG, "WPS UPnP: HTTP GET for SCPD XML");
 		req = GET_SCPD_XML_FILE;
 		extra_len = os_strlen(wps_scpd_xml);
 	} else {
 		/* File not found */
-		wpa_printf(MSG_DEBUG, "WPS UPnP: File not found: %s",
+		wpa_printf(MSG_DEBUG, "WPS UPnP: HTTP GET file not found: %s",
 			   filename);
 		buf = wpabuf_alloc(200);
 		if (buf == NULL)
@@ -1465,6 +1468,7 @@ static void web_connection_parse_subscribe(struct web_connection *c,
 		ret = HTTP_PRECONDITION_FAILED;
 		goto error;
 	}
+	wpa_printf(MSG_DEBUG, "WPS UPnP: HTTP SUBSCRIBE for event");
 	end = os_strchr(h, '\n');
 
 	for (; end != NULL; h = end + 1) {
@@ -1595,8 +1599,6 @@ static void web_connection_parse_subscribe(struct web_connection *c,
 	/* And empty line to terminate header: */
 	wpabuf_put_str(buf, "\r\n");
 
-	wpa_hexdump_ascii(MSG_MSGDUMP, "WPS UPnP SUBSCRIBE response",
-			  wpabuf_head(buf), wpabuf_len(buf));
 	send_wpabuf(c->sd, buf);
 	wpabuf_free(buf);
 	os_free(callback_urls);
@@ -1669,6 +1671,7 @@ static void web_connection_parse_unsubscribe(struct web_connection *c,
 		ret = HTTP_PRECONDITION_FAILED;
 		goto send_msg;
 	}
+	wpa_printf(MSG_DEBUG, "WPS UPnP: HTTP UNSUBSCRIBE for event");
 	end = os_strchr(h, '\n');
 
 	for (; end != NULL; h = end + 1) {
@@ -1776,7 +1779,9 @@ static void web_connection_check_data(struct web_connection *c)
 	while (*filename == '/')
 		filename++;
 
-	wpa_printf(MSG_DEBUG, "WPS UPnP: Got HTTP request type %d", htype);
+	wpa_printf(MSG_DEBUG, "WPS UPnP: Got HTTP request type %d from %s:%d",
+		   htype, inet_ntoa(c->cli_addr.sin_addr),
+		   htons(c->cli_addr.sin_port));
 
 	switch (htype) {
 	case HTTPREAD_HDR_TYPE_GET:
@@ -1821,14 +1826,13 @@ static void web_connection_got_file_handler(struct httpread *handle,
 /* web_connection_start - Start web connection
  * @sm: WPS UPnP state machine from upnp_wps_device_init()
  * @sd: Socket descriptor
- * @ip_addr: of client, in host byte order
- * @ip_port: of client, in native byte order
+ * @addr: Client address
  *
- * The socket descriptor sd is handed over for ownership by the WPs UPnP
+ * The socket descriptor sd is handed over for ownership by the WPS UPnP
  * state machine.
  */
 static void web_connection_start(struct upnp_wps_device_sm *sm,
-				 int sd, unsigned ip_addr, unsigned ip_port)
+				 int sd, struct sockaddr_in *addr)
 {
 	struct web_connection *c = NULL;
 
@@ -1841,6 +1845,7 @@ static void web_connection_start(struct upnp_wps_device_sm *sm,
 	c = os_zalloc(sizeof(*c));
 	if (c == NULL)
 		return;
+	os_memcpy(&c->cli_addr, addr, sizeof(c->cli_addr));
 	c->sm = sm;
 	c->sd = sd;
 #if 0
@@ -1908,8 +1913,7 @@ static void web_listener_handler(int sd, void *eloop_ctx, void *sock_ctx)
 			   errno, strerror(errno), sm->web_sd);
 		return;
 	}
-	web_connection_start(sm, new_sd, addr.sin_addr.s_addr,
-			     htons(addr.sin_port));
+	web_connection_start(sm, new_sd, &addr);
 }