wpa_supplicant / hostapd 2.0

wps_upnp_i.h

Go to the documentation of this file.
00001 
00012 #ifndef WPS_UPNP_I_H
00013 #define WPS_UPNP_I_H
00014 
00015 #include "utils/list.h"
00016 #include "http.h"
00017 
00018 #define UPNP_MULTICAST_ADDRESS  "239.255.255.250" /* for UPnP multicasting */
00019 #define UPNP_MULTICAST_PORT 1900 /* UDP port to monitor for UPnP */
00020 
00021 /* min subscribe time per UPnP standard */
00022 #define UPNP_SUBSCRIBE_SEC_MIN 1800
00023 /* subscribe time we use */
00024 #define UPNP_SUBSCRIBE_SEC (UPNP_SUBSCRIBE_SEC_MIN + 1)
00025 
00026 /* "filenames" used in URLs that we service via our "web server": */
00027 #define UPNP_WPS_DEVICE_XML_FILE "wps_device.xml"
00028 #define UPNP_WPS_SCPD_XML_FILE   "wps_scpd.xml"
00029 #define UPNP_WPS_DEVICE_CONTROL_FILE "wps_control"
00030 #define UPNP_WPS_DEVICE_EVENT_FILE "wps_event"
00031 
00032 #define MULTICAST_MAX_READ 1600 /* max bytes we'll read for UPD request */
00033 
00034 
00035 struct upnp_wps_device_sm;
00036 struct wps_registrar;
00037 
00038 
00039 enum advertisement_type_enum {
00040         ADVERTISE_UP = 0,
00041         ADVERTISE_DOWN = 1,
00042         MSEARCH_REPLY = 2
00043 };
00044 
00045 /*
00046  * Advertisements are broadcast via UDP NOTIFYs, and are also the essence of
00047  * the reply to UDP M-SEARCH requests. This struct handles both cases.
00048  *
00049  * A state machine is needed because a number of variant forms must be sent in
00050  * separate packets and spread out in time to avoid congestion.
00051  */
00052 struct advertisement_state_machine {
00053         struct dl_list list;
00054         enum advertisement_type_enum type;
00055         int state;
00056         int nerrors;
00057         struct sockaddr_in client; /* for M-SEARCH replies */
00058 };
00059 
00060 
00061 /*
00062  * An address of a subscriber (who may have multiple addresses). We are
00063  * supposed to send (via TCP) updates to each subscriber, trying each address
00064  * for a subscriber until we find one that seems to work.
00065  */
00066 struct subscr_addr {
00067         struct dl_list list;
00068         char *domain_and_port; /* domain and port part of url */
00069         char *path; /* "filepath" part of url (from "mem") */
00070         struct sockaddr_in saddr; /* address for doing connect */
00071         unsigned num_failures;
00072 };
00073 
00074 
00075 /*
00076  * Subscribers to our events are recorded in this struct. This includes a max
00077  * of one outgoing connection (sending an "event message") per subscriber. We
00078  * also have to age out subscribers unless they renew.
00079  */
00080 struct subscription {
00081         struct dl_list list;
00082         struct upnp_wps_device_sm *sm; /* parent */
00083         time_t timeout_time; /* when to age out the subscription */
00084         unsigned next_subscriber_sequence; /* number our messages */
00085         /*
00086          * This uuid identifies the subscription and is randomly generated by
00087          * us and given to the subscriber when the subscription is accepted;
00088          * and is then included with each event sent to the subscriber.
00089          */
00090         u8 uuid[UUID_LEN];
00091         /* Linked list of address alternatives (rotate through on failure) */
00092         struct dl_list addr_list;
00093         struct dl_list event_queue; /* Queued event messages. */
00094         struct wps_event_ *current_event; /* non-NULL if being sent (not in q)
00095                                            */
00096         int last_event_failed; /* Whether delivery of last event failed */
00097 
00098         /* Information from SetSelectedRegistrar action */
00099         u8 selected_registrar;
00100         u16 dev_password_id;
00101         u16 config_methods;
00102         u8 authorized_macs[WPS_MAX_AUTHORIZED_MACS][ETH_ALEN];
00103         struct wps_registrar *reg;
00104 };
00105 
00106 
00107 struct upnp_wps_device_interface {
00108         struct dl_list list;
00109         struct upnp_wps_device_ctx *ctx; /* callback table */
00110         struct wps_context *wps;
00111         void *priv;
00112 
00113         /* FIX: maintain separate structures for each UPnP peer */
00114         struct upnp_wps_peer peer;
00115 };
00116 
00117 /*
00118  * Our instance data corresponding to the AP device. Note that there may be
00119  * multiple wireless interfaces sharing the same UPnP device instance. Each
00120  * such interface is stored in the list of struct upnp_wps_device_interface
00121  * instances.
00122  *
00123  * This is known as an opaque struct declaration to users of the WPS UPnP code.
00124  */
00125 struct upnp_wps_device_sm {
00126         struct dl_list interfaces; /* struct upnp_wps_device_interface */
00127         char *root_dir;
00128         char *desc_url;
00129         int started; /* nonzero if we are active */
00130         u8 mac_addr[ETH_ALEN]; /* mac addr of network i.f. we use */
00131         char *ip_addr_text; /* IP address of network i.f. we use */
00132         unsigned ip_addr; /* IP address of network i.f. we use (host order) */
00133         int multicast_sd; /* send multicast messages over this socket */
00134         int ssdp_sd; /* receive discovery UPD packets on socket */
00135         int ssdp_sd_registered; /* nonzero if we must unregister */
00136         unsigned advertise_count; /* how many advertisements done */
00137         struct advertisement_state_machine advertisement;
00138         struct dl_list msearch_replies;
00139         int web_port; /* our port that others get xml files from */
00140         struct http_server *web_srv;
00141         /* Note: subscriptions are kept in expiry order */
00142         struct dl_list subscriptions;
00143         int event_send_all_queued; /* if we are scheduled to send events soon
00144                                     */
00145 
00146         char *wlanevent; /* the last WLANEvent data */
00147         enum upnp_wps_wlanevent_type wlanevent_type;
00148         os_time_t last_event_sec;
00149         unsigned int num_events_in_sec;
00150 };
00151 
00152 /* wps_upnp.c */
00153 void format_date(struct wpabuf *buf);
00154 struct subscription * subscription_start(struct upnp_wps_device_sm *sm,
00155                                          const char *callback_urls);
00156 struct subscription * subscription_renew(struct upnp_wps_device_sm *sm,
00157                                          const u8 uuid[UUID_LEN]);
00158 void subscription_destroy(struct subscription *s);
00159 struct subscription * subscription_find(struct upnp_wps_device_sm *sm,
00160                                         const u8 uuid[UUID_LEN]);
00161 void subscr_addr_delete(struct subscr_addr *a);
00162 int send_wpabuf(int fd, struct wpabuf *buf);
00163 int get_netif_info(const char *net_if, unsigned *ip_addr, char **ip_addr_text,
00164                    u8 mac[ETH_ALEN]);
00165 
00166 /* wps_upnp_ssdp.c */
00167 void msearchreply_state_machine_stop(struct advertisement_state_machine *a);
00168 int advertisement_state_machine_start(struct upnp_wps_device_sm *sm);
00169 void advertisement_state_machine_stop(struct upnp_wps_device_sm *sm,
00170                                       int send_byebye);
00171 void ssdp_listener_stop(struct upnp_wps_device_sm *sm);
00172 int ssdp_listener_start(struct upnp_wps_device_sm *sm);
00173 int ssdp_listener_open(void);
00174 int add_ssdp_network(const char *net_if);
00175 int ssdp_open_multicast_sock(u32 ip_addr);
00176 int ssdp_open_multicast(struct upnp_wps_device_sm *sm);
00177 
00178 /* wps_upnp_web.c */
00179 int web_listener_start(struct upnp_wps_device_sm *sm);
00180 void web_listener_stop(struct upnp_wps_device_sm *sm);
00181 
00182 /* wps_upnp_event.c */
00183 int event_add(struct subscription *s, const struct wpabuf *data, int probereq);
00184 void event_delete_all(struct subscription *s);
00185 void event_send_all_later(struct upnp_wps_device_sm *sm);
00186 void event_send_stop_all(struct upnp_wps_device_sm *sm);
00187 
00188 /* wps_upnp_ap.c */
00189 int upnp_er_set_selected_registrar(struct wps_registrar *reg,
00190                                    struct subscription *s,
00191                                    const struct wpabuf *msg);
00192 void upnp_er_remove_notification(struct wps_registrar *reg,
00193                                  struct subscription *s);
00194 
00195 #endif /* WPS_UPNP_I_H */
00196 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines