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 "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 subscription;
00035 struct upnp_wps_device_sm;
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         /* double-linked list */
00053         struct advertisement_state_machine *next;
00054         struct advertisement_state_machine *prev;
00055         struct upnp_wps_device_sm *sm; /* parent */
00056         enum advertisement_type_enum type;
00057         int state;
00058         int nerrors;
00059         struct sockaddr_in client; /* for M-SEARCH replies */
00060 };
00061 
00062 
00063 /*
00064  * An address of a subscriber (who may have multiple addresses). We are
00065  * supposed to send (via TCP) updates to each subscriber, trying each address
00066  * for a subscriber until we find one that seems to work.
00067  */
00068 struct subscr_addr {
00069         /* double linked list */
00070         struct subscr_addr *next;
00071         struct subscr_addr *prev;
00072         struct subscription *s; /* parent */
00073         char *domain_and_port; /* domain and port part of url */
00074         char *path; /* "filepath" part of url (from "mem") */
00075         struct sockaddr_in saddr; /* address for doing connect */
00076 };
00077 
00078 
00079 /*
00080  * Subscribers to our events are recorded in this struct. This includes a max
00081  * of one outgoing connection (sending an "event message") per subscriber. We
00082  * also have to age out subscribers unless they renew.
00083  */
00084 struct subscription {
00085         /* double linked list */
00086         struct subscription *next;
00087         struct subscription *prev;
00088         struct upnp_wps_device_sm *sm; /* parent */
00089         time_t timeout_time; /* when to age out the subscription */
00090         unsigned next_subscriber_sequence; /* number our messages */
00091         /*
00092          * This uuid identifies the subscription and is randomly generated by
00093          * us and given to the subscriber when the subscription is accepted;
00094          * and is then included with each event sent to the subscriber.
00095          */
00096         u8 uuid[UUID_LEN];
00097         /* Linked list of address alternatives (rotate through on failure) */
00098         struct subscr_addr *addr_list;
00099         int n_addr; /* Number of addresses in list */
00100         struct wps_event_ *event_queue; /* Queued event messages. */
00101         int n_queue; /* How many events are queued */
00102         struct wps_event_ *current_event; /* non-NULL if being sent (not in q)
00103                                            */
00104 };
00105 
00106 
00107 /*
00108  * Our instance data corresponding to one WiFi network interface
00109  * (multiple might share the same wired network interface!).
00110  *
00111  * This is known as an opaque struct declaration to users of the WPS UPnP code.
00112  */
00113 struct upnp_wps_device_sm {
00114         struct upnp_wps_device_ctx *ctx; /* callback table */
00115         struct wps_context *wps;
00116         void *priv;
00117         char *root_dir;
00118         char *desc_url;
00119         int started; /* nonzero if we are active */
00120         char *net_if; /* network interface we use */
00121         char *mac_addr_text; /* mac addr of network i.f. we use */
00122         u8 mac_addr[ETH_ALEN]; /* mac addr of network i.f. we use */
00123         char *ip_addr_text; /* IP address of network i.f. we use */
00124         unsigned ip_addr; /* IP address of network i.f. we use (host order) */
00125         int multicast_sd; /* send multicast messages over this socket */
00126         int ssdp_sd; /* receive discovery UPD packets on socket */
00127         int ssdp_sd_registered; /* nonzero if we must unregister */
00128         unsigned advertise_count; /* how many advertisements done */
00129         struct advertisement_state_machine advertisement;
00130         struct advertisement_state_machine *msearch_replies;
00131         int n_msearch_replies; /* no. of pending M-SEARCH replies */
00132         int web_port; /* our port that others get xml files from */
00133         struct http_server *web_srv;
00134         /* Note: subscriptions are kept in expiry order */
00135         struct subscription *subscriptions; /* linked list */
00136         int n_subscriptions; /* no of current subscriptions */
00137         int event_send_all_queued; /* if we are scheduled to send events soon
00138                                     */
00139 
00140         char *wlanevent; /* the last WLANEvent data */
00141 
00142         /* FIX: maintain separate structures for each UPnP peer */
00143         struct upnp_wps_peer peer;
00144 };
00145 
00146 /* wps_upnp.c */
00147 void format_date(struct wpabuf *buf);
00148 struct subscription * subscription_start(struct upnp_wps_device_sm *sm,
00149                                          const char *callback_urls);
00150 struct subscription * subscription_renew(struct upnp_wps_device_sm *sm,
00151                                          const u8 uuid[UUID_LEN]);
00152 void subscription_unlink(struct subscription *s);
00153 void subscription_destroy(struct subscription *s);
00154 struct subscription * subscription_find(struct upnp_wps_device_sm *sm,
00155                                         const u8 uuid[UUID_LEN]);
00156 int send_wpabuf(int fd, struct wpabuf *buf);
00157 int get_netif_info(const char *net_if, unsigned *ip_addr, char **ip_addr_text,
00158                    u8 mac[ETH_ALEN], char **mac_addr_text);
00159 
00160 /* wps_upnp_ssdp.c */
00161 void msearchreply_state_machine_stop(struct advertisement_state_machine *a);
00162 int advertisement_state_machine_start(struct upnp_wps_device_sm *sm);
00163 void advertisement_state_machine_stop(struct upnp_wps_device_sm *sm,
00164                                       int send_byebye);
00165 void ssdp_listener_stop(struct upnp_wps_device_sm *sm);
00166 int ssdp_listener_start(struct upnp_wps_device_sm *sm);
00167 int ssdp_listener_open(void);
00168 int add_ssdp_network(const char *net_if);
00169 int ssdp_open_multicast_sock(u32 ip_addr);
00170 int ssdp_open_multicast(struct upnp_wps_device_sm *sm);
00171 
00172 /* wps_upnp_web.c */
00173 int web_listener_start(struct upnp_wps_device_sm *sm);
00174 void web_listener_stop(struct upnp_wps_device_sm *sm);
00175 
00176 /* wps_upnp_event.c */
00177 int event_add(struct subscription *s, const struct wpabuf *data);
00178 void event_delete_all(struct subscription *s);
00179 void event_send_all_later(struct upnp_wps_device_sm *sm);
00180 void event_send_stop_all(struct upnp_wps_device_sm *sm);
00181 
00182 #endif /* WPS_UPNP_I_H */
00183 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Sat Nov 21 23:16:55 2009 for hostapd by  doxygen 1.6.1