tcpip_adapter.h 25.1 KB
Newer Older
M
me-no-dev 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef _TCPIP_ADAPTER_H_
#define _TCPIP_ADAPTER_H_

#include <stdint.h>
#include "rom/queue.h"
#include "esp_wifi_types.h"
21
#include "sdkconfig.h"
M
me-no-dev 已提交
22 23 24

#if CONFIG_TCPIP_LWIP
#include "lwip/ip_addr.h"
25
#include "dhcpserver/dhcpserver.h"
M
me-no-dev 已提交
26

27 28
typedef dhcps_lease_t tcpip_adapter_dhcps_lease_t;

M
me-no-dev 已提交
29 30 31 32 33 34 35 36 37 38 39
#ifdef __cplusplus
extern "C" {
#endif

#define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \
    ip4_addr2_16(ipaddr), \
    ip4_addr3_16(ipaddr), \
    ip4_addr4_16(ipaddr)

#define IPSTR "%d.%d.%d.%d"

M
me-no-dev 已提交
40 41 42 43 44 45 46 47 48 49 50
#define IPV62STR(ipaddr) IP6_ADDR_BLOCK1(&(ipaddr)),     \
    IP6_ADDR_BLOCK2(&(ipaddr)),     \
    IP6_ADDR_BLOCK3(&(ipaddr)),     \
    IP6_ADDR_BLOCK4(&(ipaddr)),     \
    IP6_ADDR_BLOCK5(&(ipaddr)),     \
    IP6_ADDR_BLOCK6(&(ipaddr)),     \
    IP6_ADDR_BLOCK7(&(ipaddr)),     \
    IP6_ADDR_BLOCK8(&(ipaddr))

#define IPV6STR "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x"

51 52
/** @brief IPV4 IP address information
 */
M
me-no-dev 已提交
53
typedef struct {
54 55 56
    ip4_addr_t ip;      /**< Interface IPV4 address */
    ip4_addr_t netmask; /**< Interface IPV4 netmask */
    ip4_addr_t gw;      /**< Interface IPV4 gateway address */
M
me-no-dev 已提交
57 58
} tcpip_adapter_ip_info_t;

59 60
/** @brief IPV6 IP address information
 */
61
typedef struct {
62
    ip6_addr_t ip; /**< Interface IPV6 address */
63 64
} tcpip_adapter_ip6_info_t;

65 66 67 68
/** @brief IP address info of station connected to WLAN AP
 *
 * @note See also wifi_sta_info_t (MAC layer information only)
 */
M
me-no-dev 已提交
69
typedef struct {
70 71
    uint8_t mac[6]; /**< Station MAC address */
    ip4_addr_t ip;  /**< Station assigned IP address */
72
} tcpip_adapter_sta_info_t;
M
me-no-dev 已提交
73

74 75 76 77
/** @brief WLAN AP: Connected stations list
 *
 * Used to retrieve IP address information about connected stations.
 */
M
me-no-dev 已提交
78
typedef struct {
79 80
    tcpip_adapter_sta_info_t sta[ESP_WIFI_MAX_CONN_NUM]; /**< Connected stations */
    int num; /**< Number of connected stations */
81
} tcpip_adapter_sta_list_t;
M
me-no-dev 已提交
82 83 84

#endif

85
#define ESP_ERR_TCPIP_ADAPTER_BASE                  0x5000
M
Me No Dev 已提交
86 87 88 89 90 91 92
#define ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS        ESP_ERR_TCPIP_ADAPTER_BASE + 0x01
#define ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY          ESP_ERR_TCPIP_ADAPTER_BASE + 0x02
#define ESP_ERR_TCPIP_ADAPTER_DHCPC_START_FAILED    ESP_ERR_TCPIP_ADAPTER_BASE + 0x03
#define ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED  ESP_ERR_TCPIP_ADAPTER_BASE + 0x04
#define ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED  ESP_ERR_TCPIP_ADAPTER_BASE + 0x05
#define ESP_ERR_TCPIP_ADAPTER_NO_MEM                ESP_ERR_TCPIP_ADAPTER_BASE + 0x06
#define ESP_ERR_TCPIP_ADAPTER_DHCP_NOT_STOPPED      ESP_ERR_TCPIP_ADAPTER_BASE + 0x07
M
me-no-dev 已提交
93

94
/* @brief On-chip network interfaces */
M
me-no-dev 已提交
95
typedef enum {
96 97 98
    TCPIP_ADAPTER_IF_STA = 0,     /**< Wi-Fi STA (station) interface */
    TCPIP_ADAPTER_IF_AP,          /**< Wi-Fi soft-AP interface */
    TCPIP_ADAPTER_IF_ETH,         /**< Ethernet interface */
M
me-no-dev 已提交
99 100 101
    TCPIP_ADAPTER_IF_MAX
} tcpip_adapter_if_t;

102
/** @brief Type of DNS server */
M
Me No Dev 已提交
103
typedef enum {
104 105 106 107
    TCPIP_ADAPTER_DNS_MAIN= 0,       /**< DNS main server address*/
    TCPIP_ADAPTER_DNS_BACKUP,        /**< DNS backup server address (Wi-Fi STA and Ethernet only) */
    TCPIP_ADAPTER_DNS_FALLBACK,      /**< DNS fallback server address (Wi-Fi STA and Ethernet only) */
    TCPIP_ADAPTER_DNS_MAX
M
Me No Dev 已提交
108 109
} tcpip_adapter_dns_type_t;

110
/** @brief DNS server info */
M
Me No Dev 已提交
111
typedef struct {
112
    ip_addr_t ip; /**< IPV4 address of DNS server */
M
Me No Dev 已提交
113 114
} tcpip_adapter_dns_info_t;

115
/** @brief Status of DHCP client or DHCP server */
M
me-no-dev 已提交
116
typedef enum {
117 118 119
    TCPIP_ADAPTER_DHCP_INIT = 0,    /**< DHCP client/server is in initial state (not yet started) */
    TCPIP_ADAPTER_DHCP_STARTED,     /**< DHCP client/server has been started */
    TCPIP_ADAPTER_DHCP_STOPPED,     /**< DHCP client/server has been stopped */
M
me-no-dev 已提交
120 121 122
    TCPIP_ADAPTER_DHCP_STATUS_MAX
} tcpip_adapter_dhcp_status_t;

123
/** @brief Mode for DHCP client or DHCP server option functions */
M
me-no-dev 已提交
124 125
typedef enum{
    TCPIP_ADAPTER_OP_START = 0,
126 127
    TCPIP_ADAPTER_OP_SET,           /**< Set option */
    TCPIP_ADAPTER_OP_GET,           /**< Get option */
M
me-no-dev 已提交
128
    TCPIP_ADAPTER_OP_MAX
129
} tcpip_adapter_dhcp_option_mode_t;
M
me-no-dev 已提交
130

131 132 133 134
/* Deprecated name for tcpip_adapter_dhcp_option_mode_t, to remove after ESP-IDF V4.0 */
typedef tcpip_adapter_dhcp_option_mode_t tcpip_adapter_option_mode_t;

/** @brief Supported options for DHCP client or DHCP server */
M
me-no-dev 已提交
135
typedef enum{
136 137 138 139 140 141 142 143 144 145 146 147 148 149
    TCPIP_ADAPTER_DOMAIN_NAME_SERVER            = 6,    /**< Domain name server */
    TCPIP_ADAPTER_ROUTER_SOLICITATION_ADDRESS   = 32,   /**< Solicitation router address */
    TCPIP_ADAPTER_REQUESTED_IP_ADDRESS          = 50,   /**< Request specific IP address */
    TCPIP_ADAPTER_IP_ADDRESS_LEASE_TIME         = 51,   /**< Request IP address lease time */
    TCPIP_ADAPTER_IP_REQUEST_RETRY_TIME         = 52,   /**< Request IP address retry counter */
} tcpip_adapter_dhcp_option_id_t;

/* Deprecated name for tcpip_adapter_dhcp_option_id_t, to remove after ESP-IDF V4.0 */
typedef tcpip_adapter_dhcp_option_id_t tcpip_adapter_option_id_t;

/**
 * @brief  Initialize the underlying TCP/IP stack
 *
 * @note This function should be called exactly once from application code, when the application starts up.
M
me-no-dev 已提交
150 151 152 153
 */
void tcpip_adapter_init(void);

/**
154 155 156
 * @brief  Cause the TCP/IP stack to start the Ethernet interface with specified MAC and IP
 *
 * @note This function should be called after the Ethernet MAC hardware is initialized. In the default configuration, application code does not need to call this function - it is called automatically by the default handler for the SYSTEM_EVENT_ETH_START event.
M
me-no-dev 已提交
157
 *
158 159
 * @param[in]  mac Set MAC address of this interface
 * @param[in]  ip_info Set IP address of this interface
M
me-no-dev 已提交
160
 *
161 162 163 164
 * @return
 *         - ESP_OK
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
 *         - ESP_ERR_NO_MEM
M
me-no-dev 已提交
165 166 167 168
 */
esp_err_t tcpip_adapter_eth_start(uint8_t *mac, tcpip_adapter_ip_info_t *ip_info);

/**
169
 * @brief  Cause the TCP/IP stack to start the Wi-Fi station interface with specified MAC and IP
M
me-no-dev 已提交
170 171
 *
 *
172
 * @note This function should be called after the Wi-Fi Station hardware is initialized. In the default configuration, application code does not need to call this function - it is called automatically by the default handler for the SYSTEM_EVENT_STA_START event.
M
me-no-dev 已提交
173
 *
174 175 176 177 178 179 180
 * @param[in]  mac Set MAC address of this interface
 * @param[in]  ip_info Set IP address of this interface
 *
 * @return
 *         - ESP_OK
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
 *         - ESP_ERR_NO_MEM
M
me-no-dev 已提交
181 182 183 184
 */
esp_err_t tcpip_adapter_sta_start(uint8_t *mac, tcpip_adapter_ip_info_t *ip_info);

/**
185
 * @brief  Cause the TCP/IP stack to start the Wi-Fi AP interface with specified MAC and IP
M
me-no-dev 已提交
186
 *
187
 * @note This function should be called after the Wi-Fi AP hardware is initialized. In the default configuration, application code does not need to call this function - it is called automatically by the default handler for the SYSTEM_EVENT_AP_START event.
M
me-no-dev 已提交
188
 *
189
 * DHCP server will be started automatically when this function is called.
M
me-no-dev 已提交
190
 *
191 192
 * @param[in]  mac Set MAC address of this interface
 * @param[in]  ip_info Set IP address of this interface
M
me-no-dev 已提交
193
 *
194 195 196 197
 * @return
 *         - ESP_OK
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
 *         - ESP_ERR_NO_MEM
M
me-no-dev 已提交
198
 */
M
me-no-dev 已提交
199
esp_err_t tcpip_adapter_ap_start(uint8_t *mac, tcpip_adapter_ip_info_t *ip_info);
M
me-no-dev 已提交
200 201

/**
202 203 204
 * @brief  Cause the TCP/IP stack to stop a network interface
 *
 * Causes TCP/IP stack to clean up this interface. This includes stopping the DHCP server or client, if they are started.
M
me-no-dev 已提交
205
 *
206 207
 * @note This API is called by the default Wi-Fi and Ethernet event handlers if the underlying network driver reports that the
 * interface has stopped.
M
me-no-dev 已提交
208
 *
209 210 211
 * @note To stop an interface from application code, call the network-specific API (esp_wifi_stop() or esp_eth_stop()).
 * The driver layer will then send a stop event and the event handler should call this API.
 * Otherwise, the driver and MAC layer will remain started.
M
me-no-dev 已提交
212
 *
213 214 215 216 217 218
 * @param[in]  tcpip_if Interface which will be stopped
 *
 * @return
 *         - ESP_OK
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
 *         - ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY
M
me-no-dev 已提交
219 220 221 222
 */
esp_err_t tcpip_adapter_stop(tcpip_adapter_if_t tcpip_if);

/**
223 224 225 226
 * @brief  Cause the TCP/IP stack to bring up an interface
 *
 * @note This function is called automatically by the default event handlers for the Wi-Fi Station and Ethernet interfaces,
 * in response to the SYSTEM_EVENT_STA_CONNECTED and SYSTEM_EVENT_ETH_CONNECTED events, respectively.
M
me-no-dev 已提交
227
 *
228
 * @note This function is not normally used with Wi-Fi AP interface. If the AP interface is started, it is up.
M
me-no-dev 已提交
229
 *
230
 * @param[in]  tcpip_if Interface to bring up
M
me-no-dev 已提交
231
 *
232 233 234
 * @return
 *         - ESP_OK
 *         - ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY
M
me-no-dev 已提交
235 236 237 238
 */
esp_err_t tcpip_adapter_up(tcpip_adapter_if_t tcpip_if);

/**
239
 * @brief Cause the TCP/IP stack to shutdown an interface
M
me-no-dev 已提交
240
 *
241 242
 * @note This function is called automatically by the default event handlers for the Wi-Fi Station and Ethernet interfaces,
 * in response to the SYSTEM_EVENT_STA_DISCONNECTED and SYSTEM_EVENT_ETH_DISCONNECTED events, respectively.
M
me-no-dev 已提交
243
 *
244
 * @note This function is not normally used with Wi-Fi AP interface. If the AP interface is stopped, it is down.
M
me-no-dev 已提交
245
 *
246 247 248 249 250
 * @param[in]  tcpip_if Interface to shutdown
 *
 * @return
 *         - ESP_OK
 *         - ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY
M
me-no-dev 已提交
251 252 253 254
 */
esp_err_t tcpip_adapter_down(tcpip_adapter_if_t tcpip_if);

/**
255 256 257
 * @brief  Get interface's IP address information
 *
 * If the interface is up, IP information is read directly from the TCP/IP stack.
M
me-no-dev 已提交
258
 *
259 260
 * If the interface is down, IP information is read from a copy kept in the TCP/IP adapter
 * library itself.
M
me-no-dev 已提交
261
 *
262 263
 * @param[in]   tcpip_if Interface to get IP information
 * @param[out]  ip_info If successful, IP information will be returned in this argument.
M
me-no-dev 已提交
264
 *
265 266 267
 * @return
 *         - ESP_OK
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
M
me-no-dev 已提交
268 269 270 271
 */
esp_err_t tcpip_adapter_get_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_ip_info_t *ip_info);

/**
272 273 274
 * @brief  Set interface's IP address information
 *
 * This function is mainly used to set a static IP on an interface.
M
me-no-dev 已提交
275
 *
276
 * If the interface is up, the new IP information is set directly in the TCP/IP stack.
M
me-no-dev 已提交
277
 *
278 279
 * The copy of IP information kept in the TCP/IP adapter library is also updated (this
 * copy is returned if the IP is queried while the interface is still down.)
M
me-no-dev 已提交
280
 *
281
 * @note DHCP client/server must be stopped before setting new IP information.
M
me-no-dev 已提交
282
 *
283 284 285 286 287 288 289 290 291 292
 * @note Calling this interface for the Wi-Fi STA or Ethernet interfaces may generate a
 * SYSTEM_EVENT_STA_GOT_IP or SYSTEM_EVENT_ETH_GOT_IP event.
 *
 * @param[in] tcpip_if Interface to set IP information
 * @param[in] ip_info IP information to set on the specified interface
 *
 * @return
 *      - ESP_OK
 *      - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
 *      - ESP_ERR_TCPIP_ADAPTER_DHCP_NOT_STOPPED If DHCP server or client is still running
M
me-no-dev 已提交
293
 */
294
esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, const tcpip_adapter_ip_info_t *ip_info);
M
me-no-dev 已提交
295

M
Me No Dev 已提交
296
/**
297 298 299
 * @brief  Set DNS Server information
 *
 * This function behaves differently for different interfaces:
M
Me No Dev 已提交
300
 *
301 302 303 304
 * - For Wi-Fi Station interface and Ethernet interface, up to three types of DNS server can be set (in order of priority):
 *   - Main DNS Server (TCPIP_ADAPTER_DNS_MAIN)
 *   - Backup DNS Server (TCPIP_ADAPTER_DNS_BACKUP)
 *   - Fallback DNS Server (TCPIP_ADAPTER_DNS_FALLBACK)
M
Me No Dev 已提交
305
 *
306
 *   If DHCP client is enabled, main and backup DNS servers will be updated automatically from the DHCP lease if the relevant DHCP options are set. Fallback DNS Server is never updated from the DHCP lease and is designed to be set via this API.
M
Me No Dev 已提交
307
 *
308
 *   If DHCP client is disabled, all DNS server types can be set via this API only.
M
Me No Dev 已提交
309
 *
310 311 312 313 314 315 316 317 318 319
 * - For Wi-Fi AP interface, the Main DNS Server setting is used by the DHCP server to provide a DNS Server option to DHCP clients (Wi-Fi stations).
 *   - The default Main DNS server is the IP of the Wi-Fi AP interface itself.
 *   - This function can override it by setting server type TCPIP_ADAPTER_DNS_MAIN.
 *   - Other DNS Server types are not supported for the Wi-Fi AP interface.
 *
 * @param[in]  tcpip_if Interface to set DNS Server information
 * @param[in]  type Type of DNS Server to set: TCPIP_ADAPTER_DNS_MAIN, TCPIP_ADAPTER_DNS_BACKUP, TCPIP_ADAPTER_DNS_FALLBACK
 * @param[in]  dns  DNS Server address to set
 *
 * @return
M
Me No Dev 已提交
320 321 322 323 324 325
 *      - ESP_OK on success
 *      - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS invalid params
 */
esp_err_t tcpip_adapter_set_dns_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dns_type_t type, tcpip_adapter_dns_info_t *dns);

/**
326 327 328
 * @brief  Get DNS Server information
 *
 * Return the currently configured DNS Server address for the specified interface and Server type.
M
Me No Dev 已提交
329
 *
330 331
 * This may be result of a previous call to tcpip_adapter_set_dns_info(). If the interface's DHCP client is enabled,
 * the Main or Backup DNS Server may be set by the current DHCP lease.
M
Me No Dev 已提交
332
 *
333 334 335
 * @param[in]  tcpip_if Interface to get DNS Server information
 * @param[in]  type Type of DNS Server to get: TCPIP_ADAPTER_DNS_MAIN, TCPIP_ADAPTER_DNS_BACKUP, TCPIP_ADAPTER_DNS_FALLBACK
 * @param[out] dns  DNS Server result is written here on success
M
Me No Dev 已提交
336
 *
337
 * @return
M
Me No Dev 已提交
338 339 340 341 342
 *      - ESP_OK on success
 *      - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS invalid params
 */
esp_err_t tcpip_adapter_get_dns_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dns_type_t type, tcpip_adapter_dns_info_t *dns);

M
me-no-dev 已提交
343 344 345
/**
 * @brief  Get interface's old IP information
 *
346
 * Returns an "old" IP address previously stored for the interface when the valid IP changed.
M
me-no-dev 已提交
347
 *
348 349
 * If the IP lost timer has expired (meaning the interface was down for longer than the configured interval)
 * then the old IP information will be zero.
M
me-no-dev 已提交
350
 *
351 352 353 354 355 356
 * @param[in]   tcpip_if Interface to get old IP information
 * @param[out]  ip_info If successful, IP information will be returned in this argument.
 *
 * @return
 *         - ESP_OK
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
M
me-no-dev 已提交
357 358 359 360
 */
esp_err_t tcpip_adapter_get_old_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_ip_info_t *ip_info);

/**
361 362 363 364 365
 * @brief  Set interface old IP information
 *
 * This function is called from the DHCP client for the Wi-Fi STA and Ethernet interfaces, before a new IP is set. It is also called from the default handlers for the SYSTEM_EVENT_STA_CONNECTED and SYSTEM_EVENT_ETH_CONNECTED events.
 *
 * Calling this function stores the previously configured IP, which can be used to determine if the IP changes in the future.
M
me-no-dev 已提交
366
 *
367
 * If the interface is disconnected or down for too long, the "IP lost timer" will expire (after the configured interval) and set the old IP information to zero.
M
me-no-dev 已提交
368
 *
369 370
 * @param[in]  tcpip_if Interface to set old IP information
 * @param[in]  ip_info Store the old IP information for the specified interface
M
me-no-dev 已提交
371
 *
372 373 374
 * @return
 *         - ESP_OK
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
M
me-no-dev 已提交
375
 */
376
esp_err_t tcpip_adapter_set_old_ip_info(tcpip_adapter_if_t tcpip_if, const tcpip_adapter_ip_info_t *ip_info);
M
me-no-dev 已提交
377 378


379
/**
380
 * @brief  Create interface link-local IPv6 address
381
 *
382
 * Cause the TCP/IP stack to create a link-local IPv6 address for the specified interface.
383
 *
384
 * This function also registers a callback for the specified interface, so that if the link-local address becomes verified as the preferred address then a SYSTEM_EVENT_GOT_IP6 event will be sent.
385
 *
386
 * @param[in]  tcpip_if Interface to create a link-local IPv6 address
387
 *
388 389 390
 * @return
 *         - ESP_OK
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
391 392 393 394
 */
esp_err_t tcpip_adapter_create_ip6_linklocal(tcpip_adapter_if_t tcpip_if);

/**
395
 * @brief  Get interface link-local IPv6 address
396
 *
397 398
 * If the specified interface is up and a preferred link-local IPv6 address
 * has been created for the interface, return a copy of it.
399
 *
400 401
 * @param[in]  tcpip_if Interface to get link-local IPv6 address
 * @param[out] if_ip6 IPv6 information will be returned in this argument if successful.
402
 *
403 404 405
 * @return
 *      - ESP_OK
 *      - ESP_FAIL If interface is down, does not have a link-local IPv6 address, or the link-local IPv6 address is not a preferred address.
406 407 408
 */
esp_err_t tcpip_adapter_get_ip6_linklocal(tcpip_adapter_if_t tcpip_if, ip6_addr_t *if_ip6);

M
me-no-dev 已提交
409 410 411 412 413 414 415
#if 0
esp_err_t tcpip_adapter_get_mac(tcpip_adapter_if_t tcpip_if, uint8_t *mac);

esp_err_t tcpip_adapter_set_mac(tcpip_adapter_if_t tcpip_if, uint8_t *mac);
#endif

/**
416
 * @brief  Get DHCP Server status
M
me-no-dev 已提交
417
 *
418 419
 * @param[in]   tcpip_if Interface to get status of DHCP server.
 * @param[out]  status If successful, the status of the DHCP server will be returned in this argument.
M
me-no-dev 已提交
420
 *
421 422
 * @return
 *         - ESP_OK
M
me-no-dev 已提交
423 424 425 426
 */
esp_err_t tcpip_adapter_dhcps_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status);

/**
427
 * @brief  Set or Get DHCP server option
M
me-no-dev 已提交
428
 *
429 430 431 432
 * @param[in] opt_op TCPIP_ADAPTER_OP_SET to set an option, TCPIP_ADAPTER_OP_GET to get an option.
 * @param[in] opt_id Option index to get or set, must be one of the supported enum values.
 * @param[inout] opt_val Pointer to the option parameter.
 * @param[in] opt_len Length of the option parameter.
M
me-no-dev 已提交
433
 *
434 435 436 437 438
 * @return
 *         - ESP_OK
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
 *         - ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED
 *         - ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED
M
me-no-dev 已提交
439
 */
440
esp_err_t tcpip_adapter_dhcps_option(tcpip_adapter_dhcp_option_mode_t opt_op, tcpip_adapter_dhcp_option_id_t opt_id, void *opt_val, uint32_t opt_len);
M
me-no-dev 已提交
441 442 443 444

/**
 * @brief  Start DHCP server
 *
445
 * @note   Currently DHCP server is only supported on the Wi-Fi AP interface.
M
me-no-dev 已提交
446
 *
447
 * @param[in]  tcpip_if Interface to start DHCP server. Must be TCPIP_ADAPTER_IF_AP.
M
me-no-dev 已提交
448
 *
449 450 451 452
 * @return
 *         - ESP_OK
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
 *         - ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED
M
me-no-dev 已提交
453 454 455 456 457 458
 */
esp_err_t tcpip_adapter_dhcps_start(tcpip_adapter_if_t tcpip_if);

/**
 * @brief  Stop DHCP server
 *
459
 * @note   Currently DHCP server is only supported on the Wi-Fi AP interface.
M
me-no-dev 已提交
460
 *
461
 * @param[in]  tcpip_if Interface to stop DHCP server. Must be TCPIP_ADAPTER_IF_AP.
M
me-no-dev 已提交
462
 *
463 464 465 466 467
 * @return
 *      - ESP_OK
 *      - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
 *      - ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED
 *      - ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY
M
me-no-dev 已提交
468 469 470 471 472 473
 */
esp_err_t tcpip_adapter_dhcps_stop(tcpip_adapter_if_t tcpip_if);

/**
 * @brief  Get DHCP client status
 *
474 475
 * @param[in]  tcpip_if Interface to get status of DHCP client
 * @param[out] status If successful, the status of DHCP client will be returned in this argument.
M
me-no-dev 已提交
476
 *
477 478
 * @return
 *         - ESP_OK
M
me-no-dev 已提交
479 480 481 482 483 484
 */
esp_err_t tcpip_adapter_dhcpc_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status);

/**
 * @brief  Set or Get DHCP client's option
 *
485
 * @note This function is not yet implemented
M
me-no-dev 已提交
486
 *
487 488 489 490
 * @param[in] opt_op TCPIP_ADAPTER_OP_SET to set an option, TCPIP_ADAPTER_OP_GET to get an option.
 * @param[in] opt_id Option index to get or set, must be one of the supported enum values.
 * @param[inout] opt_val Pointer to the option parameter.
 * @param[in] opt_len Length of the option parameter.
M
me-no-dev 已提交
491
 *
492 493
 * @return
 *         - ESP_ERR_NOT_SUPPORTED (not implemented)
M
me-no-dev 已提交
494
 */
495
esp_err_t tcpip_adapter_dhcpc_option(tcpip_adapter_dhcp_option_mode_t opt_op, tcpip_adapter_dhcp_option_id_t opt_id, void *opt_val, uint32_t opt_len);
M
me-no-dev 已提交
496 497

/**
498
 * @brief Start DHCP client
M
me-no-dev 已提交
499
 *
500
 * @note DHCP Client is only supported for the Wi-Fi station and Ethernet interfaces.
M
me-no-dev 已提交
501
 *
502
 * @note The default event handlers for the SYSTEM_EVENT_STA_CONNECTED and SYSTEM_EVENT_ETH_CONNECTED events call this function.
M
me-no-dev 已提交
503
 *
504 505 506 507 508 509 510
 * @param[in]  tcpip_if Interface to start the DHCP client
 *
 * @return
 *         - ESP_OK
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
 *         - ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED
 *         - ESP_ERR_TCPIP_ADAPTER_DHCPC_START_FAILED
M
me-no-dev 已提交
511 512 513 514 515 516
 */
esp_err_t tcpip_adapter_dhcpc_start(tcpip_adapter_if_t tcpip_if);

/**
 * @brief  Stop DHCP client
 *
517 518 519
 * @note DHCP Client is only supported for the Wi-Fi station and Ethernet interfaces.
 *
 * @note Calling tcpip_adapter_stop() or tcpip_adapter_down() will also stop the DHCP Client if it is running.
M
me-no-dev 已提交
520
 *
521
 * @param[in] tcpip_if Interface to stop the DHCP client
M
me-no-dev 已提交
522
 *
523 524 525 526 527
 * @return
 *      - ESP_OK
 *      - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
 *      - ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED
 *      - ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY
M
me-no-dev 已提交
528 529 530
 */
esp_err_t tcpip_adapter_dhcpc_stop(tcpip_adapter_if_t tcpip_if);

531
/**
532 533 534
 * @brief  Receive an Ethernet frame from the Ethernet interface
 *
 * This function will automatically be installed by esp_eth_init(). The Ethernet driver layer will then call this function to forward frames to the TCP/IP stack.
535
 *
536
 * @note Application code does not usually need to use this function directly.
537
 *
538 539 540
 * @param[in]  buffer Received data
 * @param[in]  len Length of the data frame
 * @param[in]  eb Pointer to internal Wi-Fi buffer (ignored for Ethernet)
541
 *
542 543
 * @return
 *         - ESP_OK
544
 */
M
me-no-dev 已提交
545 546
esp_err_t tcpip_adapter_eth_input(void *buffer, uint16_t len, void *eb);

M
me-no-dev 已提交
547
/**
548
 * @brief  Receive an 802.11 data frame from the Wi-Fi Station interface
M
me-no-dev 已提交
549
 *
550
 * This function should be installed by calling esp_wifi_reg_rxcb(). The Wi-Fi driver layer will then call this function to forward frames to the TCP/IP stack.
M
me-no-dev 已提交
551
 *
552
 * @note Installation happens automatically in the default handler for the SYSTEM_EVENT_STA_CONNECTED event.
M
me-no-dev 已提交
553
 *
554 555 556 557 558 559 560 561
 * @note Application code does not usually need to call this function directly.
 *
 * @param[in]  buffer Received data
 * @param[in]  len Length of the data frame
 * @param[in]  eb Pointer to internal Wi-Fi buffer
 *
 * @return
 *         - ESP_OK
M
me-no-dev 已提交
562 563 564 565
 */
esp_err_t tcpip_adapter_sta_input(void *buffer, uint16_t len, void *eb);

/**
566 567 568
 * @brief  Receive an 802.11 data frame from the Wi-Fi AP interface
 *
 * This function should be installed by calling esp_wifi_reg_rxcb(). The Wi-Fi driver layer will then call this function to forward frames to the TCP/IP stack.
M
me-no-dev 已提交
569
 *
570
 * @note Installation happens automatically in the default handler for the SYSTEM_EVENT_AP_START event.
M
me-no-dev 已提交
571
 *
572
 * @note Application code does not usually need to call this function directly.
M
me-no-dev 已提交
573
 *
574 575 576 577 578 579
 * @param[in]  buffer Received data
 * @param[in]  len Length of the data frame
 * @param[in]  eb Pointer to internal Wi-Fi buffer
 *
 * @return
 *         - ESP_OK
M
me-no-dev 已提交
580 581 582 583
 */
esp_err_t tcpip_adapter_ap_input(void *buffer, uint16_t len, void *eb);

/**
584
 * @brief  Get network interface index
M
me-no-dev 已提交
585
 *
586
 * Get network interface from TCP/IP implementation-specific interface pointer.
M
me-no-dev 已提交
587
 *
588
 * @param[in]  dev Implementation-specific TCP/IP stack interface pointer.
M
me-no-dev 已提交
589
 *
590 591 592 593 594
 * @return
 *         - ESP_IF_WIFI_STA
 *         - ESP_IF_WIFI_AP
 *         - ESP_IF_ETH
 *         - ESP_IF_MAX - invalid parameter
M
me-no-dev 已提交
595
 */
M
me-no-dev 已提交
596
esp_interface_t tcpip_adapter_get_esp_if(void *dev);
M
me-no-dev 已提交
597 598

/**
599
 * @brief  Get IP information for stations connected to the Wi-Fi AP interface
M
me-no-dev 已提交
600
 *
601 602
 * @param[in]   wifi_sta_list Wi-Fi station info list, returned from esp_wifi_ap_get_sta_list()
 * @param[out]  tcpip_sta_list IP layer station info list, corresponding to MAC addresses provided in wifi_sta_list
M
me-no-dev 已提交
603
 *
604 605 606 607
 * @return
 *         - ESP_OK
 *         - ESP_ERR_TCPIP_ADAPTER_NO_MEM
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
M
me-no-dev 已提交
608
 */
609
esp_err_t tcpip_adapter_get_sta_list(const wifi_sta_list_t *wifi_sta_list, tcpip_adapter_sta_list_t *tcpip_sta_list);
M
me-no-dev 已提交
610

M
me-no-dev 已提交
611
#define TCPIP_HOSTNAME_MAX_SIZE    32
M
me-no-dev 已提交
612
/**
613
 * @brief  Set the hostname of an interface
M
me-no-dev 已提交
614
 *
615 616
 * @param[in]   tcpip_if Interface to set the hostname
 * @param[in]   hostname New hostname for the interface. Maximum length 32 bytes.
M
me-no-dev 已提交
617
 *
618 619 620 621
 * @return
 *         - ESP_OK - success
 *         - ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY - interface status error
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS - parameter error
M
me-no-dev 已提交
622 623 624
 */
esp_err_t tcpip_adapter_set_hostname(tcpip_adapter_if_t tcpip_if, const char *hostname);

M
me-no-dev 已提交
625
/**
626
 * @brief  Get interface hostname.
M
me-no-dev 已提交
627
 *
628 629
 * @param[in]   tcpip_if Interface to get the hostname
 * @param[out]   hostname Returns a pointer to the hostname. May be NULL if no hostname is set. If set non-NULL, pointer remains valid (and string may change if the hostname changes).
M
me-no-dev 已提交
630
 *
631 632 633 634
 * @return
 *         - ESP_OK - success
 *         - ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY - interface status error
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS - parameter error
M
me-no-dev 已提交
635 636 637
 */
esp_err_t tcpip_adapter_get_hostname(tcpip_adapter_if_t tcpip_if, const char **hostname);

M
Me No Dev 已提交
638
/**
639 640 641
 * @brief  Get the TCP/IP stack-specific interface that is assigned to a given interface
 *
 * @note For lwIP, this returns a pointer to a netif structure.
M
Me No Dev 已提交
642
 *
643 644
 * @param[in]  tcpip_if Interface to get the implementation-specific interface
 * @param[out] netif Pointer to the implementation-specific interface
M
Me No Dev 已提交
645
 *
646 647 648 649
 * @return
 *         - ESP_OK - success
 *         - ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY - interface status error
 *         - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS - parameter error
M
Me No Dev 已提交
650 651 652
 */
esp_err_t tcpip_adapter_get_netif(tcpip_adapter_if_t tcpip_if, void ** netif);

M
Me No Dev 已提交
653 654 655
/**
 * @brief  Test if supplied interface is up or down
 *
656
 * @param[in]   tcpip_if Interface to test up/down status
M
Me No Dev 已提交
657
 *
658 659 660
 * @return
 *         - true - Interface is up
 *         - false - Interface is down
M
Me No Dev 已提交
661 662 663
 */
bool tcpip_adapter_is_netif_up(tcpip_adapter_if_t tcpip_if);

M
me-no-dev 已提交
664 665 666 667 668
#ifdef __cplusplus
}
#endif

#endif /*  _TCPIP_ADAPTER_H_ */