netapp.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. /*
  2. * netapp.h - CC31xx/CC32xx Host Driver Implementation
  3. *
  4. * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 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
  17. * distribution.
  18. *
  19. * Neither the name of Texas Instruments Incorporated nor the names of
  20. * its contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  27. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  28. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  29. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  30. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. */
  36. /*****************************************************************************/
  37. /* Include files */
  38. /*****************************************************************************/
  39. #include "simplelink.h"
  40. #ifndef __NETAPP_H__
  41. #define __NETAPP_H__
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /*!
  46. \addtogroup netapp
  47. @{
  48. */
  49. /*****************************************************************************/
  50. /* Macro declarations */
  51. /*****************************************************************************/
  52. /*ERROR code*/
  53. #define SL_ERROR_NETAPP_RX_BUFFER_LENGTH_ERROR (-230)
  54. /* Http Server interface */
  55. #define MAX_INPUT_STRING (64) /* because of WPA */
  56. #define MAX_AUTH_NAME_LEN (20)
  57. #define MAX_AUTH_PASSWORD_LEN (20)
  58. #define MAX_AUTH_REALM_LEN (20)
  59. #define MAX_DEVICE_URN_LEN (15+1)
  60. #define MAX_DOMAIN_NAME_LEN (24+1)
  61. #define MAX_ACTION_LEN (30)
  62. /* Important: in case the max len is changed, make sure the struct sl_NetAppHttpServerSendToken_t in protocol.h is padded correctly! */
  63. #define MAX_TOKEN_NAME_LEN (20)
  64. #define MAX_TOKEN_VALUE_LEN MAX_INPUT_STRING
  65. #define NETAPP_MAX_SERVICE_TEXT_SIZE (256)
  66. #define NETAPP_MAX_SERVICE_NAME_SIZE (60)
  67. #define NETAPP_MAX_SERVICE_HOST_NAME_SIZE (64)
  68. /* Server Responses */
  69. #define SL_NETAPP_RESPONSE_NONE (0)
  70. #define SL_NETAPP_HTTPSETTOKENVALUE (1)
  71. #define SL_NETAPP_FAMILY_MASK (0x80)
  72. /* mDNS types */
  73. #define SL_NET_APP_MASK_IPP_TYPE_OF_SERVICE (0x00000001)
  74. #define SL_NET_APP_MASK_DEVICE_INFO_TYPE_OF_SERVICE (0x00000002)
  75. #define SL_NET_APP_MASK_HTTP_TYPE_OF_SERVICE (0x00000004)
  76. #define SL_NET_APP_MASK_HTTPS_TYPE_OF_SERVICE (0x00000008)
  77. #define SL_NET_APP_MASK_WORKSATION_TYPE_OF_SERVICE (0x00000010)
  78. #define SL_NET_APP_MASK_GUID_TYPE_OF_SERVICE (0x00000020)
  79. #define SL_NET_APP_MASK_H323_TYPE_OF_SERVICE (0x00000040)
  80. #define SL_NET_APP_MASK_NTP_TYPE_OF_SERVICE (0x00000080)
  81. #define SL_NET_APP_MASK_OBJECITVE_TYPE_OF_SERVICE (0x00000100)
  82. #define SL_NET_APP_MASK_RDP_TYPE_OF_SERVICE (0x00000200)
  83. #define SL_NET_APP_MASK_REMOTE_TYPE_OF_SERVICE (0x00000400)
  84. #define SL_NET_APP_MASK_RTSP_TYPE_OF_SERVICE (0x00000800)
  85. #define SL_NET_APP_MASK_SIP_TYPE_OF_SERVICE (0x00001000)
  86. #define SL_NET_APP_MASK_SMB_TYPE_OF_SERVICE (0x00002000)
  87. #define SL_NET_APP_MASK_SOAP_TYPE_OF_SERVICE (0x00004000)
  88. #define SL_NET_APP_MASK_SSH_TYPE_OF_SERVICE (0x00008000)
  89. #define SL_NET_APP_MASK_TELNET_TYPE_OF_SERVICE (0x00010000)
  90. #define SL_NET_APP_MASK_TFTP_TYPE_OF_SERVICE (0x00020000)
  91. #define SL_NET_APP_MASK_XMPP_CLIENT_TYPE_OF_SERVICE (0x00040000)
  92. #define SL_NET_APP_MASK_RAOP_TYPE_OF_SERVICE (0x00080000)
  93. #define SL_NET_APP_MASK_ALL_TYPE_OF_SERVICE (0xFFFFFFFF)
  94. /********************************************************************************************************/
  95. /* sl_NetAppDnsGetHostByName error codes */
  96. #define SL_NET_APP_DNS_QUERY_NO_RESPONSE (-159) /* DNS query failed, no response */
  97. #define SL_NET_APP_DNS_NO_SERVER (-161) /* No DNS server was specified */
  98. #define SL_NET_APP_DNS_PARAM_ERROR (-162) /* mDNS parameters error */
  99. #define SL_NET_APP_DNS_QUERY_FAILED (-163) /* DNS query failed; no DNS server sent an 'answer' */
  100. #define SL_NET_APP_DNS_INTERNAL_1 (-164)
  101. #define SL_NET_APP_DNS_INTERNAL_2 (-165)
  102. #define SL_NET_APP_DNS_MALFORMED_PACKET (-166) /* Improperly formed or corrupted DNS packet received */
  103. #define SL_NET_APP_DNS_INTERNAL_3 (-167)
  104. #define SL_NET_APP_DNS_INTERNAL_4 (-168)
  105. #define SL_NET_APP_DNS_INTERNAL_5 (-169)
  106. #define SL_NET_APP_DNS_INTERNAL_6 (-170)
  107. #define SL_NET_APP_DNS_INTERNAL_7 (-171)
  108. #define SL_NET_APP_DNS_INTERNAL_8 (-172)
  109. #define SL_NET_APP_DNS_INTERNAL_9 (-173)
  110. #define SL_NET_APP_DNS_MISMATCHED_RESPONSE (-174) /* Server response type does not match the query request*/
  111. #define SL_NET_APP_DNS_INTERNAL_10 (-175)
  112. #define SL_NET_APP_DNS_INTERNAL_11 (-176)
  113. #define SL_NET_APP_DNS_NO_ANSWER (-177) /* No response for one-shot query */
  114. #define SL_NET_APP_DNS_NO_KNOWN_ANSWER (-178) /* No known answer for query */
  115. #define SL_NET_APP_DNS_NAME_MISMATCH (-179) /* Illegal service name according to the RFC */
  116. #define SL_NET_APP_DNS_NOT_STARTED (-180) /* mDNS is not running */
  117. #define SL_NET_APP_DNS_HOST_NAME_ERROR (-181) /* Host name error. Host name format is not allowed according to RFC 1033,1034,1035, 6763 */
  118. #define SL_NET_APP_DNS_NO_MORE_ENTRIES (-182) /* No more entries be found. */
  119. #define SL_NET_APP_DNS_MAX_SERVICES_ERROR (-200) /* Maximum advertise services are already configured */
  120. #define SL_NET_APP_DNS_IDENTICAL_SERVICES_ERROR (-201) /* Trying to register a service that is already exists */
  121. #define SL_NET_APP_DNS_NOT_EXISTED_SERVICE_ERROR (-203) /* Trying to delete service that does not existed */
  122. #define SL_NET_APP_DNS_ERROR_SERVICE_NAME_ERROR (-204) /* Illegal service name according to the RFC */
  123. #define SL_NET_APP_DNS_RX_PACKET_ALLOCATION_ERROR (-205) /* Retry request */
  124. #define SL_NET_APP_DNS_BUFFER_SIZE_ERROR (-206) /* List size buffer is bigger than internally allowed in the NWP */
  125. #define SL_NET_APP_DNS_NET_APP_SET_ERROR (-207) /* Illegal length of one of the mDNS Set functions */
  126. #define SL_NET_APP_DNS_GET_SERVICE_LIST_FLAG_ERROR (-208)
  127. #define SL_NET_APP_DNS_NO_CONFIGURATION_ERROR (-209)
  128. /* Set Dev name error codes (NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN) */
  129. #define SL_ERROR_DEVICE_NAME_LEN_ERR (-117)
  130. #define SL_ERROR_DEVICE_NAME_INVALID (-118)
  131. /* Set domain name error codes (NETAPP_SET_GET_DEV_CONF_OPT_DOMAIN_NAME) */
  132. #define SL_ERROR_DOMAIN_NAME_LEN_ERR (-119)
  133. #define SL_ERROR_DOMAIN_NAME_INVALID (-120)
  134. /********************************************************************************************************/
  135. /* NetApp application IDs */
  136. #define SL_NET_APP_HTTP_SERVER_ID (1)
  137. #define SL_NET_APP_DHCP_SERVER_ID (2)
  138. #define SL_NET_APP_MDNS_ID (4)
  139. #define SL_NET_APP_DNS_SERVER_ID (8)
  140. #define SL_NET_APP_DEVICE_CONFIG_ID (16)
  141. /* NetApp application set/get options */
  142. #define NETAPP_SET_DHCP_SRV_BASIC_OPT (0)
  143. /* HTTP server set/get options */
  144. #define NETAPP_SET_GET_HTTP_OPT_PORT_NUMBER (0)
  145. #define NETAPP_SET_GET_HTTP_OPT_AUTH_CHECK (1)
  146. #define NETAPP_SET_GET_HTTP_OPT_AUTH_NAME (2)
  147. #define NETAPP_SET_GET_HTTP_OPT_AUTH_PASSWORD (3)
  148. #define NETAPP_SET_GET_HTTP_OPT_AUTH_REALM (4)
  149. #define NETAPP_SET_GET_HTTP_OPT_ROM_PAGES_ACCESS (5)
  150. #define NETAPP_SET_GET_MDNS_CONT_QUERY_OPT (1)
  151. #define NETAPP_SET_GET_MDNS_QEVETN_MASK_OPT (2)
  152. #define NETAPP_SET_GET_MDNS_TIMING_PARAMS_OPT (3)
  153. /* DNS server set/get options */
  154. #define NETAPP_SET_GET_DNS_OPT_DOMAIN_NAME (0)
  155. /* Device Config set/get options */
  156. #define NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN (0)
  157. #define NETAPP_SET_GET_DEV_CONF_OPT_DOMAIN_NAME (1)
  158. /*****************************************************************************/
  159. /* Structure/Enum declarations */
  160. /*****************************************************************************/
  161. typedef struct
  162. {
  163. _u32 PacketsSent;
  164. _u32 PacketsReceived;
  165. _u16 MinRoundTime;
  166. _u16 MaxRoundTime;
  167. _u16 AvgRoundTime;
  168. _u32 TestTime;
  169. }SlPingReport_t;
  170. typedef struct
  171. {
  172. _u32 PingIntervalTime; /* delay between pings, in milliseconds */
  173. _u16 PingSize; /* ping packet size in bytes */
  174. _u16 PingRequestTimeout; /* timeout time for every ping in milliseconds */
  175. _u32 TotalNumberOfAttempts; /* max number of ping requests. 0 - forever */
  176. _u32 Flags; /* flag - 0 report only when finished, 1 - return response for every ping, 2 - stop after 1 successful ping. */
  177. _u32 Ip; /* IPv4 address or IPv6 first 4 bytes */
  178. _u32 Ip1OrPaadding;
  179. _u32 Ip2OrPaadding;
  180. _u32 Ip3OrPaadding;
  181. }SlPingStartCommand_t;
  182. typedef struct _slHttpServerString_t
  183. {
  184. _u8 len;
  185. _u8 *data;
  186. } slHttpServerString_t;
  187. typedef struct _slHttpServerData_t
  188. {
  189. _u8 value_len;
  190. _u8 name_len;
  191. _u8 *token_value;
  192. _u8 *token_name;
  193. } slHttpServerData_t;
  194. typedef struct _slHttpServerPostData_t
  195. {
  196. slHttpServerString_t action;
  197. slHttpServerString_t token_name;
  198. slHttpServerString_t token_value;
  199. }slHttpServerPostData_t;
  200. typedef union
  201. {
  202. slHttpServerString_t httpTokenName; /* SL_NETAPP_HTTPGETTOKENVALUE */
  203. slHttpServerPostData_t httpPostData; /* SL_NETAPP_HTTPPOSTTOKENVALUE */
  204. } SlHttpServerEventData_u;
  205. typedef union
  206. {
  207. slHttpServerString_t token_value;
  208. } SlHttpServerResponsedata_u;
  209. typedef struct
  210. {
  211. _u32 Event;
  212. SlHttpServerEventData_u EventData;
  213. }SlHttpServerEvent_t;
  214. typedef struct
  215. {
  216. _u32 Response;
  217. SlHttpServerResponsedata_u ResponseData;
  218. }SlHttpServerResponse_t;
  219. typedef struct
  220. {
  221. _u32 lease_time;
  222. _u32 ipv4_addr_start;
  223. _u32 ipv4_addr_last;
  224. }SlNetAppDhcpServerBasicOpt_t;
  225. /*mDNS parameters*/
  226. typedef enum
  227. {
  228. SL_NET_APP_FULL_SERVICE_WITH_TEXT_IPV4_TYPE = 1,
  229. SL_NET_APP_FULL_SERVICE_IPV4_TYPE,
  230. SL_NET_APP_SHORT_SERVICE_IPV4_TYPE
  231. } SlNetAppGetServiceListType_e;
  232. typedef struct
  233. {
  234. _u32 service_ipv4;
  235. _u16 service_port;
  236. _u16 Reserved;
  237. }SlNetAppGetShortServiceIpv4List_t;
  238. typedef struct
  239. {
  240. _u32 service_ipv4;
  241. _u16 service_port;
  242. _u16 Reserved;
  243. _u8 service_name[NETAPP_MAX_SERVICE_NAME_SIZE];
  244. _u8 service_host[NETAPP_MAX_SERVICE_HOST_NAME_SIZE];
  245. }SlNetAppGetFullServiceIpv4List_t;
  246. typedef struct
  247. {
  248. _u32 service_ipv4;
  249. _u16 service_port;
  250. _u16 Reserved;
  251. _u8 service_name[NETAPP_MAX_SERVICE_NAME_SIZE];
  252. _u8 service_host[NETAPP_MAX_SERVICE_HOST_NAME_SIZE];
  253. _u8 service_text[NETAPP_MAX_SERVICE_TEXT_SIZE];
  254. }SlNetAppGetFullServiceWithTextIpv4List_t;
  255. typedef struct
  256. {
  257. /*The below parameters are used to configure the advertise times and interval
  258. For example:
  259. If:
  260. Period is set to T
  261. Repetitions are set to P
  262. Telescopic factor is K=2
  263. The transmission shall be:
  264. advertise P times
  265. wait T
  266. advertise P times
  267. wait 4 * T
  268. advertise P time
  269. wait 16 * T ... (till max time reached / configuration changed / query issued)
  270. */
  271. _u32 t; /* Number of ticks for the initial period. Default is 100 ticks for 1 second. */
  272. _u32 p; /* Number of repetitions. Default value is 1 */
  273. _u32 k; /* Telescopic factor. Default value is 2. */
  274. _u32 RetransInterval;/* Announcing retransmission interval */
  275. _u32 Maxinterval; /* Announcing max period interval */
  276. _u32 max_time; /* Announcing max time */
  277. }SlNetAppServiceAdvertiseTimingParameters_t;
  278. /*****************************************************************************/
  279. /* Types declarations */
  280. /*****************************************************************************/
  281. typedef void (*P_SL_DEV_PING_CALLBACK)(SlPingReport_t*);
  282. /*****************************************************************************/
  283. /* Function prototypes */
  284. /*****************************************************************************/
  285. /*!
  286. \brief Starts a network application
  287. Gets and starts network application for the current WLAN mode
  288. \param[in] AppBitMap application bitmap, could be one or combination of the following: \n
  289. - SL_NET_APP_HTTP_SERVER_ID
  290. - SL_NET_APP_DHCP_SERVER_ID
  291. - SL_NET_APP_MDNS_ID
  292. \return On error, negative number is returned
  293. \sa Stop one or more the above started applications using sl_NetAppStop
  294. \note This command activates the application for the current WLAN mode (AP or STA)
  295. \warning
  296. \par Example:
  297. \code
  298. For example: Starting internal HTTP server + DHCP server:
  299. sl_NetAppStart(SL_NET_APP_HTTP_SERVER_ID | SL_NET_APP_DHCP_SERVER_ID)
  300. \endcode
  301. */
  302. #if _SL_INCLUDE_FUNC(sl_NetAppStart)
  303. _i16 sl_NetAppStart(const _u32 AppBitMap);
  304. #endif
  305. /*!
  306. \brief Stops a network application
  307. Gets and stops network application for the current WLAN mode
  308. \param[in] AppBitMap application id, could be one of the following: \n
  309. - SL_NET_APP_HTTP_SERVER_ID
  310. - SL_NET_APP_DHCP_SERVER_ID
  311. - SL_NET_APP_MDNS_ID
  312. \return On error, negative number is returned
  313. \sa
  314. \note This command disables the application for the current active WLAN mode (AP or STA)
  315. \warning
  316. \par Example:
  317. \code
  318. For example: Stopping internal HTTP server:
  319. sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID);
  320. \endcode
  321. */
  322. #if _SL_INCLUDE_FUNC(sl_NetAppStop)
  323. _i16 sl_NetAppStop(const _u32 AppBitMap);
  324. #endif
  325. /*!
  326. \brief Get host IP by name
  327. Obtain the IP Address of machine on network, by machine name.
  328. \param[in] hostname host name
  329. \param[in] usNameLen name length
  330. \param[out] out_ip_addr This parameter is filled in with
  331. host IP address. In case that host name is not
  332. resolved, out_ip_addr is zero.
  333. \param[in] family protocol family
  334. \return On success, 0 is returned.
  335. On error, negative is returned
  336. SL_POOL_IS_EMPTY may be return in case there are no resources in the system
  337. In this case try again later or increase MAX_CONCURRENT_ACTIONS
  338. Possible DNS error codes:
  339. - SL_NET_APP_DNS_QUERY_NO_RESPONSE
  340. - SL_NET_APP_DNS_NO_SERVER
  341. - SL_NET_APP_DNS_QUERY_FAILED
  342. - SL_NET_APP_DNS_MALFORMED_PACKET
  343. - SL_NET_APP_DNS_MISMATCHED_RESPONSE
  344. \sa
  345. \note Only one sl_NetAppDnsGetHostByName can be handled at a time.
  346. Calling this API while the same command is called from another thread, may result
  347. in one of the two scenarios:
  348. 1. The command will wait (internal) until the previous command finish, and then be executed.
  349. 2. There are not enough resources and POOL_IS_EMPTY error will return.
  350. In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try
  351. again later to issue the command.
  352. \warning
  353. In case an IP address in a string format is set as input, without any prefix (e.g. "1.2.3.4") the device will not
  354. try to access the DNS and it will return the input address on the 'out_ip_addr' field
  355. \par Example:
  356. \code
  357. _u32 DestinationIP;
  358. sl_NetAppDnsGetHostByName("www.google.com", strlen("www.google.com"), &DestinationIP,SL_AF_INET);
  359. Addr.sin_family = SL_AF_INET;
  360. Addr.sin_port = sl_Htons(80);
  361. Addr.sin_addr.s_addr = sl_Htonl(DestinationIP);
  362. AddrSize = sizeof(SlSockAddrIn_t);
  363. SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
  364. \endcode
  365. */
  366. #if _SL_INCLUDE_FUNC(sl_NetAppDnsGetHostByName)
  367. _i16 sl_NetAppDnsGetHostByName(_i8 * hostname,const _u16 usNameLen, _u32* out_ip_addr,const _u8 family );
  368. #endif
  369. /*!
  370. \brief Return service attributes like IP address, port and text according to service name
  371. \par
  372. The user sets a service name Full/Part (see example below), and should get:
  373. - IP of service
  374. - The port of service
  375. - The text of service
  376. Hence it can make a connection to the specific service and use it.
  377. It is similar to get host by name method.
  378. It is done by a single shot query with PTR type on the service name.
  379. The command that is sent is from constant parameters and variables parameters.
  380. \param[in] pService Service name can be full or partial. \n
  381. Example for full service name:
  382. 1. PC1._ipp._tcp.local
  383. 2. PC2_server._ftp._tcp.local \n
  384. .
  385. Example for partial service name:
  386. 1. _ipp._tcp.local
  387. 2. _ftp._tcp.local
  388. \param[in] ServiceLen The length of the service name (in_pService).
  389. \param[in] Family IPv4 or IPv6 (SL_AF_INET , SL_AF_INET6).
  390. \param[out] pAddr Contains the IP address of the service.
  391. \param[out] pPort Contains the port of the service.
  392. \param[out] pTextLen Has 2 options. One as Input field and the other one as output:
  393. - Input: \n
  394. Contains the max length of the text that the user wants to get.\n
  395. It means that if the text len of service is bigger that its value than
  396. the text is cut to inout_TextLen value.
  397. - Output: \n
  398. Contain the length of the text that is returned. Can be full text or part of the text (see above).
  399. \param[out] pOut_pText Contains the text of the service full or partial
  400. \return On success, zero is returned
  401. SL_POOL_IS_EMPTY may be return in case there are no resources in the system
  402. In this case try again later or increase MAX_CONCURRENT_ACTIONS
  403. In case No service is found error SL_NET_APP_DNS_NO_ANSWER will be returned
  404. \note The returns attributes belongs to the first service found.
  405. There may be other services with the same service name that will response to the query.
  406. The results of these responses are saved in the peer cache of the Device and should be read by another API.
  407. Only one sl_NetAppDnsGetHostByService can be handled at a time.
  408. Calling this API while the same command is called from another thread, may result
  409. in one of the two scenarios:
  410. 1. The command will wait (internal) until the previous command finish, and then be executed.
  411. 2. There are not enough resources and SL_POOL_IS_EMPTY error will return.
  412. In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try
  413. again later to issue the command.
  414. \warning Text length can be 120 bytes only
  415. */
  416. #if _SL_INCLUDE_FUNC(sl_NetAppDnsGetHostByService)
  417. _i32 sl_NetAppDnsGetHostByService(_i8 *pServiceName, /* string containing all (or only part): name + subtype + service */
  418. const _u8 ServiceLen,
  419. const _u8 Family, /* 4-IPv4 , 16-IPv6 */
  420. _u32 pAddr[],
  421. _u32 *pPort,
  422. _u16 *pTextLen, /* in: max len , out: actual len */
  423. _i8 *pText
  424. );
  425. #endif
  426. /*!
  427. \brief Get service List
  428. Insert into out pBuffer a list of peer's services that are the NWP.
  429. The list is in a form of service struct. The user should chose the type
  430. of the service struct like:
  431. - Full service parameters with text.
  432. - Full service parameters.
  433. - Short service parameters (port and IP only) especially for tiny hosts.
  434. The different types of struct are made to give the
  435. Possibility to save memory in the host
  436. The user also chose how many max services to get and start point index
  437. NWP peer cache.
  438. For example:
  439. 1. Get max of 3 full services from index 0.Up to 3 full services
  440. from index 0 are inserted into pBuffer (services that are in indexes 0,1,2).
  441. 2. Get max of 4 full services from index 3.Up to 4 full services
  442. from index 3 are inserted into pBuffer (services that are in indexes 3,4,5,6).
  443. 3. Get max of 2 int services from index 6.Up to 2 int services
  444. from index 6 are inserted into pBuffer (services that are in indexes 6,7).
  445. See below - command parameters.
  446. \param[in] indexOffset - The start index in the peer cache that from it the first service is returned.
  447. \param[in] MaxServiceCount - The Max services that can be returned if existed or if not exceed the max index
  448. in the peer cache
  449. \param[in] Flags - an ENUM number that means which service struct to use (means which types of service to fill)
  450. - use SlNetAppGetFullServiceWithTextIpv4List_t
  451. - use SlNetAppGetFullServiceIpv4List_t
  452. - use SlNetAppGetShortServiceIpv4List_t
  453. \param[out] Buffer - The Services are inserted into this buffer. In the struct form according to the bit that is set in the Flags
  454. input parameter.
  455. \return ServiceFoundCount - The number of the services that were inserted into the buffer. zero means no service is found
  456. negative number means an error
  457. \sa sl_NetAppMDNSRegisterService
  458. \note
  459. \warning
  460. if the out pBuffer size is bigger than an RX packet(1480), than
  461. an error is returned because there
  462. is no place in the RX packet.
  463. The size is a multiply of MaxServiceCount and size of service struct(that is set
  464. according to flag value).
  465. */
  466. #if _SL_INCLUDE_FUNC(sl_NetAppGetServiceList)
  467. _i16 sl_NetAppGetServiceList(const _u8 IndexOffest,
  468. const _u8 MaxServiceCount,
  469. const _u8 Flags,
  470. _i8 *pBuffer,
  471. const _u32 RxBufferLength
  472. );
  473. #endif
  474. /*!
  475. \brief Unregister mDNS service
  476. This function deletes the mDNS service from the mDNS package and the database.
  477. The mDNS service that is to be unregistered is a service that the application no longer wishes to provide. \n
  478. The service name should be the full service name according to RFC
  479. of the DNS-SD - meaning the value in name field in the SRV answer.
  480. Examples for service names:
  481. 1. PC1._ipp._tcp.local
  482. 2. PC2_server._ftp._tcp.local
  483. \param[in] pServiceName Full service name. \n
  484. Example for service name:
  485. 1. PC1._ipp._tcp.local
  486. 2. PC2_server._ftp._tcp.local
  487. \param[in] ServiceLen The length of the service.
  488. \return On success, zero is returned
  489. \sa sl_NetAppMDNSRegisterService
  490. \note
  491. \warning
  492. The size of the service length should be smaller than 255.
  493. */
  494. #if _SL_INCLUDE_FUNC(sl_NetAppMDNSUnRegisterService)
  495. _i16 sl_NetAppMDNSUnRegisterService(const _i8 *pServiceName,const _u8 ServiceNameLen);
  496. #endif
  497. /*!
  498. \brief Register a new mDNS service
  499. \par
  500. This function registers a new mDNS service to the mDNS package and the DB.
  501. This registered service is a service offered by the application.
  502. The service name should be full service name according to RFC
  503. of the DNS-SD - meaning the value in name field in the SRV answer.
  504. Example for service name:
  505. 1. PC1._ipp._tcp.local
  506. 2. PC2_server._ftp._tcp.local
  507. If the option is_unique is set, mDNS probes the service name to make sure
  508. it is unique before starting to announce the service on the network.
  509. Instance is the instance portion of the service name.
  510. \param[in] ServiceLen The length of the service.
  511. \param[in] TextLen The length of the service should be smaller than 64.
  512. \param[in] port The port on this target host port.
  513. \param[in] TTL The TTL of the service
  514. \param[in] Options bitwise parameters: \n
  515. - bit 0 - service is unique (means that the service needs to be unique)
  516. - bit 31 - for internal use if the service should be added or deleted (set means ADD).
  517. - bit 1-30 for future.
  518. \param[in] pServiceName The service name.
  519. Example for service name: \n
  520. 1. PC1._ipp._tcp.local
  521. 2. PC2_server._ftp._tcp.local
  522. \param[in] pText The description of the service.
  523. should be as mentioned in the RFC
  524. (according to type of the service IPP,FTP...)
  525. \return On success, zero is returned
  526. Possible error codes:
  527. - Maximum advertise services are already configured.
  528. Delete another existed service that is registered and then register again the new service
  529. - Trying to register a service that is already exists
  530. - Trying to delete service that does not existed
  531. - Illegal service name according to the RFC
  532. - Retry request
  533. - Illegal length of one of the mDNS Set functions
  534. - mDNS is not operational as the device has no IP.Connect the device to an AP to get an IP address.
  535. - mDNS parameters error
  536. - mDNS internal cache error
  537. - mDNS internal error
  538. - Adding a service is not allowed as it is already exist (duplicate service)
  539. - mDNS is not running
  540. - Host name error. Host name format is not allowed according to RFC 1033,1034,1035, 6763
  541. - List size buffer is bigger than internally allowed in the NWP (API get service list),
  542. change the APIs’ parameters to decrease the size of the list
  543. \sa sl_NetAppMDNSUnRegisterService
  544. \warning 1) Temporary - there is an allocation on stack of internal buffer.
  545. Its size is NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. \n
  546. It means that the sum of the text length and service name length cannot be bigger than
  547. NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.\n
  548. If it is - An error is returned. \n
  549. 2) According to now from certain constraints the variables parameters are set in the
  550. attribute part (contain constant parameters)
  551. */
  552. #if _SL_INCLUDE_FUNC(sl_NetAppMDNSRegisterService)
  553. _i16 sl_NetAppMDNSRegisterService( const _i8* pServiceName,
  554. const _u8 ServiceNameLen,
  555. const _i8* pText,
  556. const _u8 TextLen,
  557. const _u16 Port,
  558. const _u32 TTL,
  559. _u32 Options);
  560. #endif
  561. /*!
  562. \brief send ICMP ECHO_REQUEST to network hosts
  563. Ping uses the ICMP protocol's mandatory ECHO_REQUEST
  564. \param[in] pPingParams Pointer to the ping request structure: \n
  565. - if flags parameter is set to 0, ping will report back once all requested pings are done (as defined by TotalNumberOfAttempts). \n
  566. - if flags parameter is set to 1, ping will report back after every ping, for TotalNumberOfAttempts.
  567. - if flags parameter is set to 2, ping will stop after the first successful ping, and report back for the successful ping, as well as any preceding failed ones.
  568. For stopping an ongoing ping activity, set parameters IP address to 0
  569. \param[in] family SL_AF_INET or SL_AF_INET6
  570. \param[out] pReport Ping pReport
  571. \param[out] pCallback Callback function upon completion.
  572. If callback is NULL, the API is blocked until data arrives
  573. \return On success, zero is returned. On error, -1 is returned
  574. SL_POOL_IS_EMPTY may be return in case there are no resources in the system
  575. In this case try again later or increase MAX_CONCURRENT_ACTIONS
  576. \sa sl_NetAppPingReport
  577. \note Only one sl_NetAppPingStart can be handled at a time.
  578. Calling this API while the same command is called from another thread, may result
  579. in one of the two scenarios:
  580. 1. The command will wait (internal) until the previous command finish, and then be executed.
  581. 2. There are not enough resources and SL_POOL_IS_EMPTY error will return.
  582. In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try
  583. again later to issue the command.
  584. \warning
  585. \par Example:
  586. \code
  587. An example of sending 20 ping requests and reporting results to a callback routine when
  588. all requests are sent:
  589. // callback routine
  590. void pingRes(SlPingReport_t* pReport)
  591. {
  592. // handle ping results
  593. }
  594. // ping activation
  595. void PingTest()
  596. {
  597. SlPingReport_t report;
  598. SlPingStartCommand_t pingCommand;
  599. pingCommand.Ip = SL_IPV4_VAL(10,1,1,200); // destination IP address is 10.1.1.200
  600. pingCommand.PingSize = 150; // size of ping, in bytes
  601. pingCommand.PingIntervalTime = 100; // delay between pings, in milliseconds
  602. pingCommand.PingRequestTimeout = 1000; // timeout for every ping in milliseconds
  603. pingCommand.TotalNumberOfAttempts = 20; // max number of ping requests. 0 - forever
  604. pingCommand.Flags = 0; // report only when finished
  605. sl_NetAppPingStart( &pingCommand, SL_AF_INET, &report, pingRes ) ;
  606. }
  607. \endcode
  608. */
  609. #if _SL_INCLUDE_FUNC(sl_NetAppPingStart)
  610. _i16 sl_NetAppPingStart(const SlPingStartCommand_t* pPingParams,const _u8 family,SlPingReport_t *pReport,const P_SL_DEV_PING_CALLBACK pPingCallback);
  611. #endif
  612. /*!
  613. \brief Internal function for setting network application configurations
  614. \return On success, zero is returned. On error, -1 is
  615. returned
  616. \param[in] AppId Application id, could be one of the following: \n
  617. - SL_NET_APP_HTTP_SERVER_ID
  618. - SL_NET_APP_DHCP_SERVER_ID
  619. - SL_NET_APP_MDNS_ID
  620. - SL_NET_APP_DEVICE_CONFIG_ID
  621. \param[in] SetOptions set option, could be one of the following: \n
  622. - SL_NET_APP_DHCP_SERVER_ID
  623. - NETAPP_SET_DHCP_SRV_BASIC_OPT
  624. - SL_NET_APP_HTTP_SERVER_ID
  625. - NETAPP_SET_GET_HTTP_OPT_PORT_NUMBER
  626. - NETAPP_SET_GET_HTTP_OPT_AUTH_CHECK
  627. - NETAPP_SET_GET_HTTP_OPT_AUTH_NAME
  628. - NETAPP_SET_GET_HTTP_OPT_AUTH_PASSWORD
  629. - NETAPP_SET_GET_HTTP_OPT_AUTH_REALM
  630. - NETAPP_SET_GET_HTTP_OPT_ROM_PAGES_ACCESS
  631. - SL_NET_APP_MDNS_ID
  632. - NETAPP_SET_GET_MDNS_CONT_QUERY_OPT
  633. - NETAPP_SET_GET_MDNS_QEVETN_MASK_OPT
  634. - NETAPP_SET_GET_MDNS_TIMING_PARAMS_OPT
  635. - SL_NET_APP_DEVICE_CONFIG_ID
  636. - NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN
  637. - NETAPP_SET_GET_DEV_CONF_OPT_DOMAIN_NAME
  638. \param[in] OptionLen option structure length
  639. \param[in] pOptionValues pointer to the option structure
  640. \sa
  641. \note
  642. \warning
  643. \par
  644. \code
  645. Set DHCP Server (AP mode) parameters example:
  646. SlNetAppDhcpServerBasicOpt_t dhcpParams;
  647. _u8 outLen = sizeof(SlNetAppDhcpServerBasicOpt_t);
  648. dhcpParams.lease_time = 4096; // lease time (in seconds) of the IP Address
  649. dhcpParams.ipv4_addr_start = SL_IPV4_VAL(192,168,1,10); // first IP Address for allocation. IP Address should be set as Hex number - i.e. 0A0B0C01 for (10.11.12.1)
  650. dhcpParams.ipv4_addr_last = SL_IPV4_VAL(192,168,1,16); // last IP Address for allocation. IP Address should be set as Hex number - i.e. 0A0B0C01 for (10.11.12.1)
  651. sl_NetAppStop(SL_NET_APP_DHCP_SERVER_ID); // Stop DHCP server before settings
  652. sl_NetAppSet(SL_NET_APP_DHCP_SERVER_ID, NETAPP_SET_DHCP_SRV_BASIC_OPT, outLen, (_u8* )&dhcpParams); // set parameters
  653. sl_NetAppStart(SL_NET_APP_DHCP_SERVER_ID); // Start DHCP server with new settings
  654. \endcode
  655. \code
  656. Set Device URN name example:
  657. Device name, maximum length of 33 characters
  658. Device name affects URN name, own SSID name in AP mode, and WPS file "device name" in WPS I.E (STA-WPS / P2P)
  659. In case no device URN name set, the default name is "mysimplelink"
  660. Allowed characters in device name are: 'a - z' , 'A - Z' , '0-9' and '-'
  661. _u8 *my_device = "MY-SIMPLELINK-DEV";
  662. sl_NetAppSet (SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, strlen(my_device), (_u8 *) my_device);
  663. \endcode
  664. */
  665. #if _SL_INCLUDE_FUNC(sl_NetAppSet)
  666. _i32 sl_NetAppSet(const _u8 AppId ,const _u8 Option,const _u8 OptionLen,const _u8 *pOptionValue);
  667. #endif
  668. /*!
  669. \brief Internal function for getting network applications configurations
  670. \return On success, zero is returned. On error, -1 is
  671. returned
  672. \param[in] AppId Application id, could be one of the following: \n
  673. - SL_NET_APP_HTTP_SERVER_ID
  674. - SL_NET_APP_DHCP_SERVER_ID
  675. - SL_NET_APP_MDNS_ID
  676. - SL_NET_APP_DEVICE_CONFIG_ID
  677. \param[in] SetOptions set option, could be one of the following: \n
  678. - SL_NET_APP_DHCP_SERVER_ID
  679. - NETAPP_SET_DHCP_SRV_BASIC_OPT
  680. - SL_NET_APP_HTTP_SERVER_ID
  681. - NETAPP_SET_GET_HTTP_OPT_PORT_NUMBER
  682. - NETAPP_SET_GET_HTTP_OPT_AUTH_CHECK
  683. - NETAPP_SET_GET_HTTP_OPT_AUTH_NAME
  684. - NETAPP_SET_GET_HTTP_OPT_AUTH_PASSWORD
  685. - NETAPP_SET_GET_HTTP_OPT_AUTH_REALM
  686. - NETAPP_SET_GET_HTTP_OPT_ROM_PAGES_ACCESS
  687. - SL_NET_APP_MDNS_ID
  688. - NETAPP_SET_GET_MDNS_CONT_QUERY_OPT
  689. - NETAPP_SET_GET_MDNS_QEVETN_MASK_OPT
  690. - NETAPP_SET_GET_MDNS_TIMING_PARAMS_OPT
  691. - SL_NET_APP_DEVICE_CONFIG_ID
  692. - NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN
  693. - NETAPP_SET_GET_DEV_CONF_OPT_DOMAIN_NAME
  694. \param[in] OptionLen The length of the allocated memory as input, when the
  695. function complete, the value of this parameter would be
  696. the len that actually read from the device.
  697. If the device return length that is longer from the input
  698. value, the function will cut the end of the returned structure
  699. and will return ESMALLBUF
  700. \param[out] pValues pointer to the option structure which will be filled with the response from the device
  701. \sa
  702. \note
  703. \warning
  704. \par
  705. \code
  706. Get DHCP Server parameters example:
  707. SlNetAppDhcpServerBasicOpt_t dhcpParams;
  708. _u8 outLen = sizeof(SlNetAppDhcpServerBasicOpt_t);
  709. sl_NetAppGet(SL_NET_APP_DHCP_SERVER_ID, NETAPP_SET_DHCP_SRV_BASIC_OPT, &outLen, (_u8* )&dhcpParams);
  710. printf("DHCP Start IP %d.%d.%d.%d End IP %d.%d.%d.%d Lease time seconds %d\n",
  711. SL_IPV4_BYTE(dhcpParams.ipv4_addr_start,3),SL_IPV4_BYTE(dhcpParams.ipv4_addr_start,2),
  712. SL_IPV4_BYTE(dhcpParams.ipv4_addr_start,1),SL_IPV4_BYTE(dhcpParams.ipv4_addr_start,0),
  713. SL_IPV4_BYTE(dhcpParams.ipv4_addr_last,3),SL_IPV4_BYTE(dhcpParams.ipv4_addr_last,2),
  714. SL_IPV4_BYTE(dhcpParams.ipv4_addr_last,1),SL_IPV4_BYTE(dhcpParams.ipv4_addr_last,0),
  715. dhcpParams.lease_time);
  716. \endcode
  717. \code
  718. Get Device URN name example:
  719. Maximum length of 33 characters of device name.
  720. Device name affects URN name, own SSID name in AP mode, and WPS file "device name" in WPS I.E (STA-WPS / P2P)
  721. in case no device URN name set, the default name is "mysimplelink"
  722. _u8 my_device_name[35];
  723. sl_NetAppGet (SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, strlen(my_device_name), (_u8 *)my_device_name);
  724. \endcode
  725. */
  726. #if _SL_INCLUDE_FUNC(sl_NetAppGet)
  727. _i32 sl_NetAppGet(const _u8 AppId,const _u8 Option,_u8 *pOptionLen, _u8 *pOptionValue);
  728. #endif
  729. /*!
  730. Close the Doxygen group.
  731. @}
  732. */
  733. #ifdef __cplusplus
  734. }
  735. #endif /* __cplusplus */
  736. #endif /* __NETAPP_H__ */