xref: /dflybsd-src/contrib/wpa_supplicant/src/wps/wps_upnp_i.h (revision 3a84a4273475ed07d0ab1c2dfeffdfedef35d9cd)
16d49e1aeSJan Lentfer /*
26d49e1aeSJan Lentfer  * UPnP for WPS / internal definitions
36d49e1aeSJan Lentfer  * Copyright (c) 2000-2003 Intel Corporation
46d49e1aeSJan Lentfer  * Copyright (c) 2006-2007 Sony Corporation
56d49e1aeSJan Lentfer  * Copyright (c) 2008-2009 Atheros Communications
66d49e1aeSJan Lentfer  * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
76d49e1aeSJan Lentfer  *
86d49e1aeSJan Lentfer  * See wps_upnp.c for more details on licensing and code history.
96d49e1aeSJan Lentfer  */
106d49e1aeSJan Lentfer 
116d49e1aeSJan Lentfer #ifndef WPS_UPNP_I_H
126d49e1aeSJan Lentfer #define WPS_UPNP_I_H
136d49e1aeSJan Lentfer 
143ff40c12SJohn Marino #include "utils/list.h"
153ff40c12SJohn Marino #include "http.h"
163ff40c12SJohn Marino 
176d49e1aeSJan Lentfer #define UPNP_MULTICAST_ADDRESS  "239.255.255.250" /* for UPnP multicasting */
186d49e1aeSJan Lentfer #define UPNP_MULTICAST_PORT 1900 /* UDP port to monitor for UPnP */
196d49e1aeSJan Lentfer 
206d49e1aeSJan Lentfer /* min subscribe time per UPnP standard */
216d49e1aeSJan Lentfer #define UPNP_SUBSCRIBE_SEC_MIN 1800
226d49e1aeSJan Lentfer /* subscribe time we use */
236d49e1aeSJan Lentfer #define UPNP_SUBSCRIBE_SEC (UPNP_SUBSCRIBE_SEC_MIN + 1)
246d49e1aeSJan Lentfer 
256d49e1aeSJan Lentfer /* "filenames" used in URLs that we service via our "web server": */
266d49e1aeSJan Lentfer #define UPNP_WPS_DEVICE_XML_FILE "wps_device.xml"
276d49e1aeSJan Lentfer #define UPNP_WPS_SCPD_XML_FILE   "wps_scpd.xml"
286d49e1aeSJan Lentfer #define UPNP_WPS_DEVICE_CONTROL_FILE "wps_control"
296d49e1aeSJan Lentfer #define UPNP_WPS_DEVICE_EVENT_FILE "wps_event"
306d49e1aeSJan Lentfer 
313ff40c12SJohn Marino #define MULTICAST_MAX_READ 1600 /* max bytes we'll read for UPD request */
326d49e1aeSJan Lentfer 
333ff40c12SJohn Marino 
346d49e1aeSJan Lentfer struct upnp_wps_device_sm;
353ff40c12SJohn Marino struct wps_registrar;
366d49e1aeSJan Lentfer 
376d49e1aeSJan Lentfer 
386d49e1aeSJan Lentfer enum advertisement_type_enum {
396d49e1aeSJan Lentfer 	ADVERTISE_UP = 0,
406d49e1aeSJan Lentfer 	ADVERTISE_DOWN = 1,
416d49e1aeSJan Lentfer 	MSEARCH_REPLY = 2
426d49e1aeSJan Lentfer };
436d49e1aeSJan Lentfer 
446d49e1aeSJan Lentfer /*
456d49e1aeSJan Lentfer  * Advertisements are broadcast via UDP NOTIFYs, and are also the essence of
466d49e1aeSJan Lentfer  * the reply to UDP M-SEARCH requests. This struct handles both cases.
476d49e1aeSJan Lentfer  *
486d49e1aeSJan Lentfer  * A state machine is needed because a number of variant forms must be sent in
496d49e1aeSJan Lentfer  * separate packets and spread out in time to avoid congestion.
506d49e1aeSJan Lentfer  */
516d49e1aeSJan Lentfer struct advertisement_state_machine {
523ff40c12SJohn Marino 	struct dl_list list;
536d49e1aeSJan Lentfer 	enum advertisement_type_enum type;
546d49e1aeSJan Lentfer 	int state;
556d49e1aeSJan Lentfer 	int nerrors;
566d49e1aeSJan Lentfer 	struct sockaddr_in client; /* for M-SEARCH replies */
576d49e1aeSJan Lentfer };
586d49e1aeSJan Lentfer 
596d49e1aeSJan Lentfer 
606d49e1aeSJan Lentfer /*
616d49e1aeSJan Lentfer  * An address of a subscriber (who may have multiple addresses). We are
626d49e1aeSJan Lentfer  * supposed to send (via TCP) updates to each subscriber, trying each address
636d49e1aeSJan Lentfer  * for a subscriber until we find one that seems to work.
646d49e1aeSJan Lentfer  */
656d49e1aeSJan Lentfer struct subscr_addr {
663ff40c12SJohn Marino 	struct dl_list list;
676d49e1aeSJan Lentfer 	char *domain_and_port; /* domain and port part of url */
686d49e1aeSJan Lentfer 	char *path; /* "filepath" part of url (from "mem") */
696d49e1aeSJan Lentfer 	struct sockaddr_in saddr; /* address for doing connect */
703ff40c12SJohn Marino 	unsigned num_failures;
716d49e1aeSJan Lentfer };
726d49e1aeSJan Lentfer 
736d49e1aeSJan Lentfer 
746d49e1aeSJan Lentfer /*
756d49e1aeSJan Lentfer  * Subscribers to our events are recorded in this struct. This includes a max
766d49e1aeSJan Lentfer  * of one outgoing connection (sending an "event message") per subscriber. We
776d49e1aeSJan Lentfer  * also have to age out subscribers unless they renew.
786d49e1aeSJan Lentfer  */
796d49e1aeSJan Lentfer struct subscription {
803ff40c12SJohn Marino 	struct dl_list list;
816d49e1aeSJan Lentfer 	struct upnp_wps_device_sm *sm; /* parent */
826d49e1aeSJan Lentfer 	time_t timeout_time; /* when to age out the subscription */
836d49e1aeSJan Lentfer 	unsigned next_subscriber_sequence; /* number our messages */
846d49e1aeSJan Lentfer 	/*
856d49e1aeSJan Lentfer 	 * This uuid identifies the subscription and is randomly generated by
866d49e1aeSJan Lentfer 	 * us and given to the subscriber when the subscription is accepted;
876d49e1aeSJan Lentfer 	 * and is then included with each event sent to the subscriber.
886d49e1aeSJan Lentfer 	 */
896d49e1aeSJan Lentfer 	u8 uuid[UUID_LEN];
906d49e1aeSJan Lentfer 	/* Linked list of address alternatives (rotate through on failure) */
913ff40c12SJohn Marino 	struct dl_list addr_list;
923ff40c12SJohn Marino 	struct dl_list event_queue; /* Queued event messages. */
936d49e1aeSJan Lentfer 	struct wps_event_ *current_event; /* non-NULL if being sent (not in q)
946d49e1aeSJan Lentfer 					   */
953ff40c12SJohn Marino 	int last_event_failed; /* Whether delivery of last event failed */
963ff40c12SJohn Marino 
973ff40c12SJohn Marino 	/* Information from SetSelectedRegistrar action */
983ff40c12SJohn Marino 	u8 selected_registrar;
993ff40c12SJohn Marino 	u16 dev_password_id;
1003ff40c12SJohn Marino 	u16 config_methods;
1013ff40c12SJohn Marino 	u8 authorized_macs[WPS_MAX_AUTHORIZED_MACS][ETH_ALEN];
1023ff40c12SJohn Marino 	struct wps_registrar *reg;
1036d49e1aeSJan Lentfer };
1046d49e1aeSJan Lentfer 
1056d49e1aeSJan Lentfer 
1063ff40c12SJohn Marino struct upnp_wps_device_interface {
1073ff40c12SJohn Marino 	struct dl_list list;
1083ff40c12SJohn Marino 	struct upnp_wps_device_ctx *ctx; /* callback table */
1093ff40c12SJohn Marino 	struct wps_context *wps;
1103ff40c12SJohn Marino 	void *priv;
1113ff40c12SJohn Marino 
112*a1157835SDaniel Fojt 	struct dl_list peers; /* active UPnP peer sessions */
1133ff40c12SJohn Marino };
1143ff40c12SJohn Marino 
1156d49e1aeSJan Lentfer /*
1163ff40c12SJohn Marino  * Our instance data corresponding to the AP device. Note that there may be
1173ff40c12SJohn Marino  * multiple wireless interfaces sharing the same UPnP device instance. Each
1183ff40c12SJohn Marino  * such interface is stored in the list of struct upnp_wps_device_interface
1193ff40c12SJohn Marino  * instances.
1206d49e1aeSJan Lentfer  *
1216d49e1aeSJan Lentfer  * This is known as an opaque struct declaration to users of the WPS UPnP code.
1226d49e1aeSJan Lentfer  */
1236d49e1aeSJan Lentfer struct upnp_wps_device_sm {
1243ff40c12SJohn Marino 	struct dl_list interfaces; /* struct upnp_wps_device_interface */
1256d49e1aeSJan Lentfer 	char *root_dir;
1266d49e1aeSJan Lentfer 	char *desc_url;
1276d49e1aeSJan Lentfer 	int started; /* nonzero if we are active */
1286d49e1aeSJan Lentfer 	u8 mac_addr[ETH_ALEN]; /* mac addr of network i.f. we use */
1296d49e1aeSJan Lentfer 	char *ip_addr_text; /* IP address of network i.f. we use */
1306d49e1aeSJan Lentfer 	unsigned ip_addr; /* IP address of network i.f. we use (host order) */
1316d49e1aeSJan Lentfer 	int multicast_sd; /* send multicast messages over this socket */
1326d49e1aeSJan Lentfer 	int ssdp_sd; /* receive discovery UPD packets on socket */
1336d49e1aeSJan Lentfer 	int ssdp_sd_registered; /* nonzero if we must unregister */
1346d49e1aeSJan Lentfer 	unsigned advertise_count; /* how many advertisements done */
1356d49e1aeSJan Lentfer 	struct advertisement_state_machine advertisement;
1363ff40c12SJohn Marino 	struct dl_list msearch_replies;
1376d49e1aeSJan Lentfer 	int web_port; /* our port that others get xml files from */
1383ff40c12SJohn Marino 	struct http_server *web_srv;
1396d49e1aeSJan Lentfer 	/* Note: subscriptions are kept in expiry order */
1403ff40c12SJohn Marino 	struct dl_list subscriptions;
1416d49e1aeSJan Lentfer 	int event_send_all_queued; /* if we are scheduled to send events soon
1426d49e1aeSJan Lentfer 				    */
1436d49e1aeSJan Lentfer 
1446d49e1aeSJan Lentfer 	char *wlanevent; /* the last WLANEvent data */
1453ff40c12SJohn Marino 	enum upnp_wps_wlanevent_type wlanevent_type;
1463ff40c12SJohn Marino 	os_time_t last_event_sec;
1473ff40c12SJohn Marino 	unsigned int num_events_in_sec;
1486d49e1aeSJan Lentfer };
1496d49e1aeSJan Lentfer 
1506d49e1aeSJan Lentfer /* wps_upnp.c */
1516d49e1aeSJan Lentfer void format_date(struct wpabuf *buf);
1526d49e1aeSJan Lentfer struct subscription * subscription_start(struct upnp_wps_device_sm *sm,
1536d49e1aeSJan Lentfer 					 const char *callback_urls);
1546d49e1aeSJan Lentfer struct subscription * subscription_renew(struct upnp_wps_device_sm *sm,
1556d49e1aeSJan Lentfer 					 const u8 uuid[UUID_LEN]);
1566d49e1aeSJan Lentfer void subscription_destroy(struct subscription *s);
1576d49e1aeSJan Lentfer struct subscription * subscription_find(struct upnp_wps_device_sm *sm,
1586d49e1aeSJan Lentfer 					const u8 uuid[UUID_LEN]);
1593ff40c12SJohn Marino void subscr_addr_delete(struct subscr_addr *a);
1603ff40c12SJohn Marino int get_netif_info(const char *net_if, unsigned *ip_addr, char **ip_addr_text,
1613ff40c12SJohn Marino 		   u8 mac[ETH_ALEN]);
1626d49e1aeSJan Lentfer 
1636d49e1aeSJan Lentfer /* wps_upnp_ssdp.c */
1646d49e1aeSJan Lentfer void msearchreply_state_machine_stop(struct advertisement_state_machine *a);
1656d49e1aeSJan Lentfer int advertisement_state_machine_start(struct upnp_wps_device_sm *sm);
1666d49e1aeSJan Lentfer void advertisement_state_machine_stop(struct upnp_wps_device_sm *sm,
1676d49e1aeSJan Lentfer 				      int send_byebye);
1686d49e1aeSJan Lentfer void ssdp_listener_stop(struct upnp_wps_device_sm *sm);
1696d49e1aeSJan Lentfer int ssdp_listener_start(struct upnp_wps_device_sm *sm);
1703ff40c12SJohn Marino int ssdp_listener_open(void);
1713ff40c12SJohn Marino int add_ssdp_network(const char *net_if);
1723ff40c12SJohn Marino int ssdp_open_multicast_sock(u32 ip_addr, const char *forced_ifname);
1736d49e1aeSJan Lentfer int ssdp_open_multicast(struct upnp_wps_device_sm *sm);
1746d49e1aeSJan Lentfer 
1756d49e1aeSJan Lentfer /* wps_upnp_web.c */
1766d49e1aeSJan Lentfer int web_listener_start(struct upnp_wps_device_sm *sm);
1776d49e1aeSJan Lentfer void web_listener_stop(struct upnp_wps_device_sm *sm);
1786d49e1aeSJan Lentfer 
1796d49e1aeSJan Lentfer /* wps_upnp_event.c */
1803ff40c12SJohn Marino int event_add(struct subscription *s, const struct wpabuf *data, int probereq);
1816d49e1aeSJan Lentfer void event_delete_all(struct subscription *s);
1826d49e1aeSJan Lentfer void event_send_all_later(struct upnp_wps_device_sm *sm);
1836d49e1aeSJan Lentfer void event_send_stop_all(struct upnp_wps_device_sm *sm);
1846d49e1aeSJan Lentfer 
1853ff40c12SJohn Marino /* wps_upnp_ap.c */
1863ff40c12SJohn Marino int upnp_er_set_selected_registrar(struct wps_registrar *reg,
1873ff40c12SJohn Marino 				   struct subscription *s,
1883ff40c12SJohn Marino 				   const struct wpabuf *msg);
1893ff40c12SJohn Marino void upnp_er_remove_notification(struct wps_registrar *reg,
1903ff40c12SJohn Marino 				 struct subscription *s);
1913ff40c12SJohn Marino 
1926d49e1aeSJan Lentfer #endif /* WPS_UPNP_I_H */
193