upnp.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #ifndef _PRO_UPNP_H_
  2. #define _PRO_UPNP_H_
  3. /*
  4. * Copyright (C) 2012 by egnite GmbH
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the copyright holders nor the names of
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  31. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * For additional information see http://www.ethernut.de/
  35. */
  36. /*!
  37. * \file pro/upnp.h
  38. * \brief UPnP library.
  39. *
  40. * \verbatim File version $Id: upnp.h 4921 2013-01-04 14:11:21Z haraldkipp $ \endverbatim
  41. */
  42. #include <pro/soap.h>
  43. #include <pro/ssdp.h>
  44. #define UPNP_STYPE_UI1 1
  45. #define UPNP_STYPE_UI2 2
  46. #define UPNP_STYPE_UI4 3
  47. #define UPNP_STYPE_I1 4
  48. #define UPNP_STYPE_I2 5
  49. #define UPNP_STYPE_I4 6
  50. #define UPNP_STYPE_INT 7
  51. #define UPNP_STYPE_R4 8
  52. #define UPNP_STYPE_R8 9
  53. #define UPNP_STYPE_NUMBER 10
  54. #define UPNP_STYPE_FIXED_14_4 11
  55. #define UPNP_STYPE_FLOAT 12
  56. #define UPNP_STYPE_CHAR 13
  57. #define UPNP_STYPE_STRING 14
  58. #define UPNP_STYPE_DATE 15
  59. #define UPNP_STYPE_DATETIME 16
  60. #define UPNP_STYPE_DATETIME_TZ 17
  61. #define UPNP_STYPE_BOOLEAN 18
  62. #define UPNP_STYPE_BIN_BASE64 19
  63. #define UPNP_STYPE_BIN_HEX 20
  64. #define UPNP_STYPE_URI 21
  65. #define UPNP_STYPE_UUID 22
  66. #define UPNP_STYPE_LAST UPNP_STYPE_UUID
  67. typedef struct _UPNP_DEVICE_INFO UPNP_DEVICE_INFO;
  68. typedef struct _UPNP_MODEL_INFO UPNP_MODEL_INFO;
  69. typedef struct _UPNP_MANUFACTURER_INFO UPNP_MANUFACTURER_INFO;
  70. typedef struct _UPNP_SERVICE_INFO UPNP_SERVICE_INFO;
  71. typedef struct _UPNP_VARIABLE UPNP_VARIABLE;
  72. struct _UPNP_VARIABLE {
  73. int ustv_type;
  74. char *ustv_name;
  75. int ustv_events;
  76. char *ustv_default;
  77. UPNP_VARIABLE *ustv_next;
  78. };
  79. struct _UPNP_SERVICE_INFO {
  80. char *usvc_url_scpd;
  81. char *usvc_url_ctrl;
  82. char *usvc_url_event;
  83. SOAP_PROCEDURE *usvc_proc;
  84. UPNP_VARIABLE *usvc_stv;
  85. };
  86. struct _UPNP_MANUFACTURER_INFO {
  87. /*! \brief Manufacturer name (required). */
  88. char *umnf_name;
  89. /*! \brief Manufacturer URL (optional). */
  90. char *umnf_url;
  91. };
  92. struct _UPNP_MODEL_INFO {
  93. /*! \brief Model name (required). */
  94. char *umdl_name;
  95. /*! \brief Model number (recommended). */
  96. char *umdl_num;
  97. /*! \brief Model description (recommended). */
  98. char *umdl_desc;
  99. /*! \brief Model URL (optional). */
  100. char *umdl_url;
  101. };
  102. struct _UPNP_DEVICE_INFO {
  103. /*! \brief Friendly device name (required).
  104. * Short description for end user in less than 64 characters.
  105. */
  106. char *udev_name;
  107. /*! \brief Presentation URL (recommended). */
  108. char *udev_presentation;
  109. /*! \brief Model information. */
  110. UPNP_MODEL_INFO *udev_mdl;
  111. /*! \brief Manufacturer information. */
  112. UPNP_MANUFACTURER_INFO *udev_mnf;
  113. };
  114. /*!
  115. * \brief Register a local UPnP device tree.
  116. *
  117. * \param parent Pointer to the parent device structure. This is typically
  118. * a NULL pointer and only set for embedded devices.
  119. * \param sdev Pointer to an initialized device tree structure, including
  120. * all provided services and UPnP informations.
  121. *
  122. * \return 0 on success or -1 on failure.
  123. */
  124. extern int UpnpRegisterDeviceTree(SSDP_DEVICE *parent, SSDP_DEVICE *sdev);
  125. /*!
  126. * \brief Register UPnP service observer.
  127. *
  128. * This function will initiate a service discovery for the given number of
  129. * seconds and will normally not return before the discovery has finished.
  130. * During this time however, the SSDP background receiver may already call
  131. * the observer function for each discovered service.
  132. *
  133. * The following code fragment demonstrates how to implement a simple
  134. * network service discovery:
  135. * \code
  136. * #include <pro/upnp.h>
  137. *
  138. * int RendererObserver(SSDP_SERVICE *ssvc, int_fast8_t removal)
  139. * {
  140. * UPNP_DEVICE_INFO *udev = ssvc->ssvc_dev->sdev_info;
  141. *
  142. * if (removal) {
  143. * printf("%s disappears\n", udev->udev_name);
  144. * } else {
  145. * printf("%s discovered\n", udev->udev_name);
  146. * }
  147. * return 0;
  148. * }
  149. *
  150. * UpnpRegisterServiceObserver(RendererObserver, "schemas-upnp-org", "RenderingControl", 5);
  151. * \endcode
  152. *
  153. * \param cb This observer function will be called when a service of
  154. * the specified type appears or disappears.
  155. * \param domain Type domain of the service to observe.
  156. * \param type Type name of the service to observe.
  157. * \param mxwait Maximum discovery time in seconds, which should be within
  158. * 1 to 120. Recommended values are within 3 to 5.
  159. *
  160. * \return 0 on success or -1 on failure.
  161. */
  162. extern int UpnpRegisterServiceObserver(SSDP_OBSERVER_FUNCTION cb, const char *domain, const char *type, int_fast8_t mxwait);
  163. /*!
  164. * \brief Get UPnP service procedure by name.
  165. *
  166. * \param ssvc Specifies the service.
  167. * \param name Procedure name.
  168. *
  169. * \return Pointer to the procedure or NULL if not found.
  170. */
  171. extern SOAP_PROCEDURE *UpnpServiceProcByName(const SSDP_SERVICE *ssvc, const char *name);
  172. /*!
  173. * \brief Call UPnP service.
  174. *
  175. * \param ssvc Specifies the service to call.
  176. * \param proc Specifies the procedure to call.
  177. * \param tmo Maximum number of milliseconds to wait for response.
  178. *
  179. * \return 0 on success or -1 on failure.
  180. */
  181. extern int UpnpServiceProcCall(SSDP_SERVICE *ssvc, SOAP_PROCEDURE *proc, uint32_t tmo);
  182. /*!
  183. * \brief Get index of a specified UPnP variable type name.
  184. *
  185. * \param string Pointer to the type name.
  186. *
  187. * \return Type index (UPNP_STYPE) or 0 for unknown types.
  188. */
  189. extern int UpnpVarTypeIndex(const char *string);
  190. /*!
  191. * \brief Get string of a specified UPnP variable type.
  192. *
  193. * \param type Any UPNP_STYPE.
  194. *
  195. * \return Pointer to the type name. Unknown types will be returned
  196. * as a question mark.
  197. */
  198. extern const char *UpnpVarTypeString(int type);
  199. extern void UpnpDumpDevice(const SSDP_DEVICE *sdev);
  200. #endif