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


wpa_supplicant
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:34:36