wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
wps_upnp_i.h
Go to the documentation of this file.
1 
10 #ifndef WPS_UPNP_I_H
11 #define WPS_UPNP_I_H
12 
13 #include "utils/list.h"
14 #include "http.h"
15 
16 #define UPNP_MULTICAST_ADDRESS "239.255.255.250" /* for UPnP multicasting */
17 #define UPNP_MULTICAST_PORT 1900 /* UDP port to monitor for UPnP */
18 
19 /* min subscribe time per UPnP standard */
20 #define UPNP_SUBSCRIBE_SEC_MIN 1800
21 /* subscribe time we use */
22 #define UPNP_SUBSCRIBE_SEC (UPNP_SUBSCRIBE_SEC_MIN + 1)
23 
24 /* "filenames" used in URLs that we service via our "web server": */
25 #define UPNP_WPS_DEVICE_XML_FILE "wps_device.xml"
26 #define UPNP_WPS_SCPD_XML_FILE "wps_scpd.xml"
27 #define UPNP_WPS_DEVICE_CONTROL_FILE "wps_control"
28 #define UPNP_WPS_DEVICE_EVENT_FILE "wps_event"
29 
30 #define MULTICAST_MAX_READ 1600 /* max bytes we'll read for UPD request */
31 
32 
33 struct upnp_wps_device_sm;
34 struct wps_registrar;
35 
36 
37 enum advertisement_type_enum {
38  ADVERTISE_UP = 0,
39  ADVERTISE_DOWN = 1,
40  MSEARCH_REPLY = 2
41 };
42 
43 /*
44  * Advertisements are broadcast via UDP NOTIFYs, and are also the essence of
45  * the reply to UDP M-SEARCH requests. This struct handles both cases.
46  *
47  * A state machine is needed because a number of variant forms must be sent in
48  * separate packets and spread out in time to avoid congestion.
49  */
51  struct dl_list list;
52  enum advertisement_type_enum type;
53  int state;
54  int nerrors;
55  struct sockaddr_in client; /* for M-SEARCH replies */
56 };
57 
58 
59 /*
60  * An address of a subscriber (who may have multiple addresses). We are
61  * supposed to send (via TCP) updates to each subscriber, trying each address
62  * for a subscriber until we find one that seems to work.
63  */
64 struct subscr_addr {
65  struct dl_list list;
66  char *domain_and_port; /* domain and port part of url */
67  char *path; /* "filepath" part of url (from "mem") */
68  struct sockaddr_in saddr; /* address for doing connect */
69  unsigned num_failures;
70 };
71 
72 
73 /*
74  * Subscribers to our events are recorded in this struct. This includes a max
75  * of one outgoing connection (sending an "event message") per subscriber. We
76  * also have to age out subscribers unless they renew.
77  */
78 struct subscription {
79  struct dl_list list;
80  struct upnp_wps_device_sm *sm; /* parent */
81  time_t timeout_time; /* when to age out the subscription */
82  unsigned next_subscriber_sequence; /* number our messages */
83  /*
84  * This uuid identifies the subscription and is randomly generated by
85  * us and given to the subscriber when the subscription is accepted;
86  * and is then included with each event sent to the subscriber.
87  */
88  u8 uuid[UUID_LEN];
89  /* Linked list of address alternatives (rotate through on failure) */
90  struct dl_list addr_list;
91  struct dl_list event_queue; /* Queued event messages. */
92  struct wps_event_ *current_event; /* non-NULL if being sent (not in q)
93  */
94  int last_event_failed; /* Whether delivery of last event failed */
95 
96  /* Information from SetSelectedRegistrar action */
97  u8 selected_registrar;
98  u16 dev_password_id;
99  u16 config_methods;
100  u8 authorized_macs[WPS_MAX_AUTHORIZED_MACS][ETH_ALEN];
101  struct wps_registrar *reg;
102 };
103 
104 
106  struct dl_list list;
107  struct upnp_wps_device_ctx *ctx; /* callback table */
108  struct wps_context *wps;
109  void *priv;
110 
111  /* FIX: maintain separate structures for each UPnP peer */
112  struct upnp_wps_peer peer;
113 };
114 
115 /*
116  * Our instance data corresponding to the AP device. Note that there may be
117  * multiple wireless interfaces sharing the same UPnP device instance. Each
118  * such interface is stored in the list of struct upnp_wps_device_interface
119  * instances.
120  *
121  * This is known as an opaque struct declaration to users of the WPS UPnP code.
122  */
124  struct dl_list interfaces; /* struct upnp_wps_device_interface */
125  char *root_dir;
126  char *desc_url;
127  int started; /* nonzero if we are active */
128  u8 mac_addr[ETH_ALEN]; /* mac addr of network i.f. we use */
129  char *ip_addr_text; /* IP address of network i.f. we use */
130  unsigned ip_addr; /* IP address of network i.f. we use (host order) */
131  int multicast_sd; /* send multicast messages over this socket */
132  int ssdp_sd; /* receive discovery UPD packets on socket */
133  int ssdp_sd_registered; /* nonzero if we must unregister */
134  unsigned advertise_count; /* how many advertisements done */
135  struct advertisement_state_machine advertisement;
136  struct dl_list msearch_replies;
137  int web_port; /* our port that others get xml files from */
138  struct http_server *web_srv;
139  /* Note: subscriptions are kept in expiry order */
140  struct dl_list subscriptions;
141  int event_send_all_queued; /* if we are scheduled to send events soon
142  */
143 
144  char *wlanevent; /* the last WLANEvent data */
145  enum upnp_wps_wlanevent_type wlanevent_type;
146  os_time_t last_event_sec;
147  unsigned int num_events_in_sec;
148 };
149 
150 /* wps_upnp.c */
151 void format_date(struct wpabuf *buf);
153  const char *callback_urls);
154 struct subscription * subscription_renew(struct upnp_wps_device_sm *sm,
155  const u8 uuid[UUID_LEN]);
156 void subscription_destroy(struct subscription *s);
157 struct subscription * subscription_find(struct upnp_wps_device_sm *sm,
158  const u8 uuid[UUID_LEN]);
159 void subscr_addr_delete(struct subscr_addr *a);
160 int get_netif_info(const char *net_if, unsigned *ip_addr, char **ip_addr_text,
161  u8 mac[ETH_ALEN]);
162 
163 /* wps_upnp_ssdp.c */
167  int send_byebye);
168 void ssdp_listener_stop(struct upnp_wps_device_sm *sm);
170 int ssdp_listener_open(void);
171 int add_ssdp_network(const char *net_if);
172 int ssdp_open_multicast_sock(u32 ip_addr, const char *forced_ifname);
174 
175 /* wps_upnp_web.c */
176 int web_listener_start(struct upnp_wps_device_sm *sm);
177 void web_listener_stop(struct upnp_wps_device_sm *sm);
178 
179 /* wps_upnp_event.c */
180 int event_add(struct subscription *s, const struct wpabuf *data, int probereq);
181 void event_delete_all(struct subscription *s);
182 void event_send_all_later(struct upnp_wps_device_sm *sm);
183 void event_send_stop_all(struct upnp_wps_device_sm *sm);
184 
185 /* wps_upnp_ap.c */
186 int upnp_er_set_selected_registrar(struct wps_registrar *reg,
187  struct subscription *s,
188  const struct wpabuf *msg);
189 void upnp_er_remove_notification(struct wps_registrar *reg,
190  struct subscription *s);
191 
192 #endif /* WPS_UPNP_I_H */
Definition: http_server.c:25
Definition: wps_upnp.h:26
void ssdp_listener_stop(struct upnp_wps_device_sm *sm)
Stop SSDP listered.
Definition: wps_upnp_ssdp.c:673
int add_ssdp_network(const char *net_if)
Add routing entry for SSDP.
Definition: wps_upnp_ssdp.c:806
Definition: wps_registrar.c:137
int advertisement_state_machine_start(struct upnp_wps_device_sm *sm)
Start SSDP advertisements.
Definition: wps_upnp_ssdp.c:340
Definition: wpabuf.h:16
Definition: wps_upnp_i.h:123
HTTP for WPS Copyright (c) 2006-2007 Sony Corporation Copyright (c) 2008-2009 Atheros Communications ...
Definition: wps_upnp_i.h:105
int get_netif_info(const char *net_if, unsigned *ip_addr, char **ip_addr_text, u8 mac[ETH_ALEN])
Get hw and IP addresses for network device.
Definition: wps_upnp.c:894
Doubly-linked list.
Doubly-linked list.
Definition: list.h:12
int ssdp_open_multicast(struct upnp_wps_device_sm *sm)
Open socket for sending multicast SSDP messages.
Definition: wps_upnp_ssdp.c:941
struct subscription * subscription_start(struct upnp_wps_device_sm *sm, const char *callback_urls)
Remember a UPnP control point to send events to.
Definition: wps_upnp.c:691
Definition: wps_upnp_i.h:50
void msearchreply_state_machine_stop(struct advertisement_state_machine *a)
Stop M-SEARCH reply state machine.
Definition: wps_upnp_ssdp.c:375
Definition: wps_upnp.h:17
int ssdp_listener_start(struct upnp_wps_device_sm *sm)
Set up for receiving discovery (UDP) packets.
Definition: wps_upnp_ssdp.c:777
void advertisement_state_machine_stop(struct upnp_wps_device_sm *sm, int send_byebye)
Stop SSDP advertisements.
Definition: wps_upnp_ssdp.c:227
Definition: wps_upnp_i.h:78
Definition: wps_upnp_event.c:47
Definition: wps_upnp_i.h:64
int event_add(struct subscription *s, const struct wpabuf *data, int probereq)
Add a new event to a queue.
Definition: wps_upnp_event.c:372
Long term WPS context data.
Definition: wps.h:623