wm_netif2.0.3.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /**
  2. * @file wm_netif2.0.3.h
  3. *
  4. * @brief netif203 module
  5. *
  6. * @author dave
  7. *
  8. * Copyright (c) 2014 Winner Microelectronics Co., Ltd.
  9. */
  10. #ifndef WM_NETIF2_0_3_H
  11. #define WM_NETIF2_0_3_H
  12. #include "wm_config.h"
  13. #include "wm_type_def.h"
  14. #include "wm_sockets.h"
  15. #include "wm_wifi.h"
  16. #include "wm_params.h"
  17. /** MACRO for callback EVENT to join AP or create soft-AP successfully */
  18. #define NETIF_WIFI_JOIN_SUCCESS 0x1
  19. /** MACRO for callback EVENT to fail to join AP */
  20. #define NETIF_WIFI_JOIN_FAILED 0x2
  21. /** MACRO for callback EVENT to disconnect from AP or destroy soft-AP */
  22. #define NETIF_WIFI_DISCONNECTED 0x3
  23. /** MACRO for callbck EVENT to get IP address */
  24. #define NETIF_IP_NET_UP 0x4
  25. /** MACRO for callback EVNET to create AP successfully */
  26. #define NETIF_WIFI_SOFTAP_SUCCESS 0x5
  27. /** MACRO for callback EVNET to create soft-AP failed */
  28. #define NETIF_WIFI_SOFTAP_FAILED 0x6
  29. /** MACRO for callback EVNET to close soft-AP */
  30. #define NETIF_WIFI_SOFTAP_CLOSED 0x7
  31. /** MACRO for callback EVNET to inform soft ap's net */
  32. #define NETIF_IP_NET2_UP 0x8
  33. #define NETIF_IPV6_NET_UP 0x9
  34. /** These are the values for ip_addr_t.type */
  35. #define IPADDR_TYPE_V4 0U
  36. #define IPADDR_TYPE_V6 6U
  37. #define IPADDR_TYPE_ANY 46U
  38. #define IPV6_ADDR_MAX_NUM 3
  39. #if 0
  40. struct ip_addr {
  41. u32_t addr;
  42. };
  43. typedef struct ip_addr ip_addr_t;
  44. #endif
  45. #if 0
  46. struct ip4_addr {
  47. u32_t addr;
  48. };
  49. typedef struct ip4_addr ip4_addr_t;
  50. struct ip6_addr {
  51. u32_t addr[4];
  52. };
  53. typedef struct ip6_addr ip6_addr_t;
  54. #if (TLS_CONFIG_IPV4 && TLS_CONFIG_IPV6)
  55. typedef struct _ip_addr {
  56. union {
  57. ip6_addr_t ip6;
  58. ip4_addr_t ip4;
  59. } u_addr;
  60. u8_t type;
  61. } ip_addr_t;
  62. #else
  63. #if TLS_CONFIG_IPV4
  64. typedef ip4_addr_t ip_addr_t;
  65. #else
  66. typedef ip6_addr_t ip_addr_t;
  67. #endif
  68. #endif
  69. #endif
  70. struct tls_ethif {
  71. ip_addr_t ip_addr;
  72. ip_addr_t netmask;
  73. ip_addr_t gw;
  74. #if TLS_CONFIG_IPV6
  75. ip_addr_t ip6_addr[IPV6_ADDR_MAX_NUM];
  76. #endif
  77. ip_addr_t dns1;
  78. ip_addr_t dns2;
  79. u8 status; //0:net down; 1:net up
  80. #if TLS_CONFIG_IPV6
  81. u8 ipv6_status[IPV6_ADDR_MAX_NUM]; //0:net down; 1:net up
  82. #endif
  83. };
  84. //type defination of netif status changed callback.
  85. typedef void (*tls_netif_status_event_fn)(u8 status);
  86. /**
  87. * @defgroup APP_APIs APP APIs
  88. * @brief APP APIs
  89. */
  90. /**
  91. * @addtogroup APP_APIs
  92. * @{
  93. */
  94. /**
  95. * @defgroup NETIF_APIs NETIF APIs
  96. * @brief network interface APIs
  97. */
  98. /**
  99. * @addtogroup NETIF_APIs
  100. * @{
  101. */
  102. /**
  103. * @brief This function is used to initialize TCP/IP Stack
  104. *
  105. * @param[in] None
  106. *
  107. * @retval 0 success
  108. * @retval other failed
  109. *
  110. * @note None
  111. */
  112. int tls_ethernet_init(void);
  113. /**
  114. * @brief This function is used to get IP information stored in
  115. tls_ethif struct
  116. *
  117. * @param[in] None
  118. *
  119. * @retval tls_ethif * Pointer to struct tls_ethif
  120. *
  121. * @note None
  122. */
  123. struct tls_ethif * tls_netif_get_ethif(void);
  124. /**
  125. * @brief This function is used to set tls_ethif status
  126. *
  127. * @param[in] status net status, 0-up, 1-down
  128. *
  129. * @return None
  130. *
  131. * @note None
  132. */
  133. void tls_netif_set_status(u8 status);
  134. /**
  135. * @brief This function is used to start DHCP Client
  136. *
  137. * @param[in] None
  138. *
  139. * @retval 0 success
  140. * @retval Minus failed
  141. *
  142. * @note None
  143. */
  144. err_t tls_dhcp_start(void);
  145. /**
  146. * @brief This function is used to stop DHCP client
  147. *
  148. * @param[in] None
  149. *
  150. * @retval 0 success
  151. * @retval Minus failed
  152. *
  153. * @note None
  154. */
  155. err_t tls_dhcp_stop(void);
  156. /**
  157. * @brief This function is used to change IP information
  158. *
  159. * @param[in] *ipaddr IP address
  160. * @param[in] *netmask netmask
  161. * @param[in] *gw default gateway
  162. *
  163. * @retval 0 success
  164. * @retval Minus failed
  165. *
  166. * @note None
  167. */
  168. err_t tls_netif_set_addr(ip_addr_t *ipaddr,
  169. ip_addr_t *netmask,
  170. ip_addr_t *gw);
  171. /**
  172. * @brief This function is used to set dns servers
  173. *
  174. * @param[in] numdns index of the DNS server to set
  175. must be < DNS_MAX_SERVERS
  176. * @param[in] *dnsserver IP address of the DNS server to set
  177. *
  178. * @return None
  179. *
  180. * @note None
  181. */
  182. void tls_netif_dns_setserver(u8 numdns, ip_addr_t *dnsserver);
  183. /**
  184. * @brief This function is used to bring up an interface,available
  185. for processing traffic
  186. *
  187. * @param[in] None
  188. *
  189. * @retval 0 success
  190. * @retval Minus failed
  191. *
  192. * @note None
  193. */
  194. err_t tls_netif_set_up(void);
  195. /**
  196. * @brief This function is used to bring down an interface,disabling
  197. any traffic processing
  198. *
  199. * @param[in] None
  200. *
  201. * @retval 0 success
  202. * @retval Minus failed
  203. *
  204. * @note None
  205. */
  206. err_t tls_netif_set_down(void);
  207. /**
  208. * @brief This function is used to add netif status changed callback
  209. to event list,if exists, do nothing
  210. *
  211. * @param[in] event_fn pointer to tls_netif_status_event_fn
  212. *
  213. * @retval 0 success
  214. * @retval Minus failed
  215. *
  216. * @note None
  217. */
  218. err_t tls_netif_add_status_event(tls_netif_status_event_fn event_fn);
  219. /**
  220. * @brief This function is used to remove netif status changed
  221. callback function from event list,if not exists, do nothing
  222. *
  223. * @param[in] event_fn pointer to tls_netif_status_event_fn
  224. *
  225. * @retval 0 success
  226. * @retval Minus failed
  227. *
  228. * @note None
  229. */
  230. err_t tls_netif_remove_status_event(tls_netif_status_event_fn event_fn);
  231. /**
  232. * @brief This function is used to get pointer of netif
  233. *
  234. * @param[in] None
  235. *
  236. * @retval pointer of netif
  237. *
  238. * @note None
  239. */
  240. struct netif *tls_get_netif(void);
  241. #if TLS_CONFIG_AP
  242. /**
  243. * @brief Start DHCP Server for a network interface
  244. * *
  245. * @retval DHCPS_ERR_SUCCESS - No error
  246. * @retval DHCPS_ERR_MEM - Out of memory
  247. * @retval DHCPS_ERR_LINKDOWN - The NI is inactive
  248. *
  249. * @note None
  250. */
  251. INT8S tls_dhcps_start(void);
  252. /**
  253. * @brief This function is used to stop DHCP Server
  254. *
  255. * @param[in] None
  256. *
  257. * @retval None
  258. *
  259. * @note None
  260. */
  261. void tls_dhcps_stop(void);
  262. /**
  263. * @brief Start the dns server's service
  264. * *
  265. * @retval DHCPS_ERR_SUCCESS - No error
  266. * @retval DHCPS_ERR_MEM - Out of memory
  267. * @retval DHCPS_ERR_LINKDOWN - The NI is inactive
  268. * @retval DNSS_ERR_PARAM - Input parameter error
  269. *
  270. * @note None
  271. */
  272. INT8S tls_dnss_start(INT8U * DnsName);
  273. /**
  274. * @brief Stop the dns server's service
  275. *
  276. * @param[in] None
  277. *
  278. * @retval None
  279. *
  280. * @note None
  281. */
  282. void tls_dnss_stop(void);
  283. /**
  284. * @brief Get station's ip address by mac address
  285. *
  286. * @param[in] mac station's mac address
  287. *
  288. * @retval ip_addr station's ip address
  289. *
  290. * @note None
  291. */
  292. ip_addr_t *tls_dhcps_getip(const u8_t *mac);
  293. /**
  294. * @brief Get station's mac address by ip address
  295. *
  296. * @param[in] ip station's ip address
  297. *
  298. * @retval u8* station's mac address
  299. *
  300. * @note None
  301. */
  302. u8 *tls_dhcps_getmac(const ip_addr_t *ip);
  303. #endif //TLS_CONFIG_AP
  304. #if TLS_CONFIG_RMMS
  305. /**
  306. * @brief Start remote manager server.
  307. * *
  308. * @retval DHCPS_ERR_SUCCESS - No error
  309. * @retval DHCPS_ERR_MEM - Out of memory
  310. * @retval DHCPS_ERR_LINKDOWN - The NIF is inactive
  311. *
  312. * @note None
  313. */
  314. INT8S tls_rmms_start(void);
  315. /**
  316. * @brief Disable remote manager server
  317. *
  318. * @param[in] None
  319. *
  320. * @retval None
  321. *
  322. * @note None
  323. */
  324. void tls_rmms_stop(void);
  325. #endif
  326. #if TLS_CONFIG_AP
  327. /**
  328. * @brief This is used to bring up an interface for APSTA,available
  329. for processing traffic
  330. *
  331. * @param[in] None
  332. *
  333. * @retval 0 success
  334. * @retval Minus failed
  335. *
  336. * @note Can only be used at APSTA mode
  337. */
  338. err_t tls_netif2_set_up(void);
  339. /**
  340. * @brief This function is used to bring down an interface for APSTA, disabling
  341. any traffic processing
  342. *
  343. * @param[in] None
  344. *
  345. * @retval 0 success
  346. * @retval Minus failed
  347. *
  348. * @note Can only be used at APSTA mode
  349. */
  350. err_t tls_netif2_set_down(void);
  351. /**
  352. * @brief This function is used to change IP information for
  353. a network interface for APSTA
  354. *
  355. * @param[in] *ipaddr IP address
  356. * @param[in] *netmask netmask
  357. * @param[in] *gw default gateway
  358. *
  359. * @retval 0 success
  360. * @retval Minus failed
  361. *
  362. * @note Can only be used at APSTA mode
  363. */
  364. err_t tls_netif2_set_addr(ip_addr_t *ipaddr,
  365. ip_addr_t *netmask,
  366. ip_addr_t *gw);
  367. /***************************************************************************
  368. * Function: tls_dhcps_setdns
  369. * Description: Set dhcp server's dns address.
  370. *
  371. * Input: numdns: the index of the DNS server to set must be less than DNS_MAX_SERVERS
  372. *
  373. * Output: None
  374. *
  375. * Return: None
  376. *
  377. * Date : 2015-3-10
  378. ****************************************************************************/
  379. /**
  380. * @brief Set dhcp server's dns address
  381. *
  382. * @param[in] numdns the index of the DNS server to set must be less than DNS_MAX_SERVERS
  383. *
  384. * @retval None
  385. *
  386. * @note Can only be used at APSTA mode
  387. */
  388. void tls_dhcps_setdns(u8_t numdns);
  389. #endif
  390. /**
  391. * @}
  392. */
  393. /**
  394. * @}
  395. */
  396. #endif //WM_NETIF_H