• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
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 #pragma once
16 
17 #include <common/bk_err.h>
18 #include <components/netif_types.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /**
25  * @brief BK Netif API
26  * @defgroup bk_api_netif BK Netif API
27  * @{
28  */
29 
30 /**
31  * @brief  Initialize the TCP/IP stack
32  *
33  * @attention This API should be called exactly once from application code, when the application starts up.
34  * @return
35  *   - BK_OK: success
36  *   - BK_FAIL: otherwise
37  */
38 bk_err_t bk_netif_init(void);
39 
40 /**
41  * @brief  Set netif interface's IP4 address information
42  *
43  * This function is mainly used to set a static IP on an interface.
44  *
45  * @attention 1. For STA, if this API never calls, it gets the IP address via DHCP by default.
46  * @attention 2. If the interface is already up, we need to stop the interface first
47  *               before calling this API, or restart the interface after the this API
48  *               is called.
49  * @attention 3. Currently no sanity checking for the IP4 address to be configured,
50  *               also no checking about the relationship between ip/mask/gateway/dns,
51  *               the API caller need to guarantee that the correctness of the
52  *               configured info.
53  * @attention 4. Avoid configuring same subnet for STA and AP.
54  *
55  * @param ifx The interface index
56  * @param config the IP4 information of the interface
57  *
58  * @return
59  *   - BK_OK: succeed
60  *   - BK_ERR_NETIF_IF: invalid netif interface ID
61  *   - BK_ERR_NULL_PARAM: config is NULL
62  */
63 bk_err_t bk_netif_set_ip4_config(netif_if_t ifx, const netif_ip4_config_t *config);
64 
65 /**
66  * @brief  Get netif interface's IP address information
67  *
68  * If the interface is up, IP information is read directly from the TCP/IP stack.
69  * If the interface is down, the API just return all 0 information
70  *
71  * @param ifx  netif interface ID
72  * @param config store the IP4 configuration info
73  *
74  * @return
75  *   - BK_OK: succeed
76  *   - BK_ERR_NETIF_IF: invalid netif interface ID
77  *   - BK_ERR_NULL_PARAM: config is NULL
78  */
79 bk_err_t bk_netif_get_ip4_config(netif_if_t ifx, netif_ip4_config_t *config);
80 
81 /**
82  * @brief  Get netif interface's IP6 address information
83  *
84  * If the interface is up, IP6 information is read directly from the TCP/IP stack.
85  * If the interface is down, the API just return all 0 information
86  *
87  * @param ifx  netif interface ID
88  *
89  * @return
90  *   - BK_OK: succeed
91  *   - BK_ERR_NETIF_IF: invalid netif interface ID
92  *   - BK_ERR_NULL_PARAM: config is NULL
93  */
94 bk_err_t bk_netif_get_ip6_addr_info(netif_if_t ifx);
95 
96 /**
97  * @brief  Start the DHCP client for specified interface
98  *
99  * If this API is called, the interface will get the IP address via DHCP.
100  *
101  * If the interface is has a static IP and is already up, we need to stop
102  * the interface (for STA, call bk_wifi_sta_stop() or bk_wifi_sta_disconnect()
103  * to stop the interface) before this API is called, or restart the interface
104  * after this API is called.
105  *
106  * @param ifx  netif interface ID, currently only support NETIF_IF_STA.
107  *
108  * @return
109  *   - BK_OK: succeed
110  *   - BK_ERR_NETIF_IF: invalid netif interface ID
111  */
112 bk_err_t bk_netif_dhcpc_start(netif_if_t ifx);
113 
114 /**
115  * @}
116  */
117 
118 #ifdef __cplusplus
119 }
120 #endif
121