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