wps_upnp_i.h 6.6 KB

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