mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
components/tcpip_adapter: Allow to set different hostname for each interface
This commit is contained in:
parent
fb70126bc8
commit
315b3f979f
16
components/lwip/port/netif/ethernetif.c
Executable file → Normal file
16
components/lwip/port/netif/ethernetif.c
Executable file → Normal file
@ -55,8 +55,6 @@
|
|||||||
#define IFNAME0 'e'
|
#define IFNAME0 'e'
|
||||||
#define IFNAME1 'n'
|
#define IFNAME1 'n'
|
||||||
|
|
||||||
static char hostname[16];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In this function, the hardware should be initialized.
|
* In this function, the hardware should be initialized.
|
||||||
* Called from ethernetif_init().
|
* Called from ethernetif_init().
|
||||||
@ -81,7 +79,6 @@ ethernet_low_level_init(struct netif *netif)
|
|||||||
|
|
||||||
#if ESP_LWIP
|
#if ESP_LWIP
|
||||||
#if LWIP_IGMP
|
#if LWIP_IGMP
|
||||||
|
|
||||||
netif->flags |= NETIF_FLAG_IGMP;
|
netif->flags |= NETIF_FLAG_IGMP;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -119,12 +116,10 @@ ethernet_low_level_output(struct netif *netif, struct pbuf *p)
|
|||||||
q = p;
|
q = p;
|
||||||
u16_t pbuf_x_len = 0;
|
u16_t pbuf_x_len = 0;
|
||||||
pbuf_x_len = q->len;
|
pbuf_x_len = q->len;
|
||||||
if(q->next !=NULL)
|
if(q->next !=NULL) {
|
||||||
{
|
|
||||||
//char cnt = 0;
|
//char cnt = 0;
|
||||||
struct pbuf *tmp = q->next;
|
struct pbuf *tmp = q->next;
|
||||||
while(tmp != NULL)
|
while(tmp != NULL) {
|
||||||
{
|
|
||||||
memcpy( (u8_t *)( (u8_t *)(q->payload) + pbuf_x_len), (u8_t *)tmp->payload , tmp->len );
|
memcpy( (u8_t *)( (u8_t *)(q->payload) + pbuf_x_len), (u8_t *)tmp->payload , tmp->len );
|
||||||
pbuf_x_len += tmp->len;
|
pbuf_x_len += tmp->len;
|
||||||
//cnt++;
|
//cnt++;
|
||||||
@ -211,12 +206,9 @@ ethernetif_init(struct netif *netif)
|
|||||||
/* Initialize interface hostname */
|
/* Initialize interface hostname */
|
||||||
|
|
||||||
#if ESP_LWIP
|
#if ESP_LWIP
|
||||||
sprintf(hostname, "ESP_%02X%02X%02X", netif->hwaddr[3], netif->hwaddr[4], netif->hwaddr[5]);
|
netif->hostname = "espressif";
|
||||||
netif->hostname = hostname;
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
sprintf(hostname, "ESP_%02X%02X%02X", netif->hwaddr[3], netif->hwaddr[4], netif->hwaddr[5]);
|
netif->hostname = "lwip";
|
||||||
netif->hostname = hostname;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* LWIP_NETIF_HOSTNAME */
|
#endif /* LWIP_NETIF_HOSTNAME */
|
||||||
|
28
components/lwip/port/netif/wlanif.c
Executable file → Normal file
28
components/lwip/port/netif/wlanif.c
Executable file → Normal file
@ -56,8 +56,6 @@
|
|||||||
#define IFNAME0 'e'
|
#define IFNAME0 'e'
|
||||||
#define IFNAME1 'n'
|
#define IFNAME1 'n'
|
||||||
|
|
||||||
static char hostname[16];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In this function, the hardware should be initialized.
|
* In this function, the hardware should be initialized.
|
||||||
* Called from ethernetif_init().
|
* Called from ethernetif_init().
|
||||||
@ -68,10 +66,6 @@ static char hostname[16];
|
|||||||
static void
|
static void
|
||||||
low_level_init(struct netif *netif)
|
low_level_init(struct netif *netif)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* set MAC hardware address length */
|
/* set MAC hardware address length */
|
||||||
netif->hwaddr_len = ETHARP_HWADDR_LEN;
|
netif->hwaddr_len = ETHARP_HWADDR_LEN;
|
||||||
|
|
||||||
@ -85,13 +79,9 @@ low_level_init(struct netif *netif)
|
|||||||
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
|
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
|
||||||
|
|
||||||
#if ESP_LWIP
|
#if ESP_LWIP
|
||||||
|
|
||||||
#if LWIP_IGMP
|
#if LWIP_IGMP
|
||||||
|
|
||||||
netif->flags |= NETIF_FLAG_IGMP;
|
netif->flags |= NETIF_FLAG_IGMP;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Do whatever else is needed to initialize interface. */
|
/* Do whatever else is needed to initialize interface. */
|
||||||
@ -208,23 +198,9 @@ wlanif_init(struct netif *netif)
|
|||||||
/* Initialize interface hostname */
|
/* Initialize interface hostname */
|
||||||
|
|
||||||
#if ESP_LWIP
|
#if ESP_LWIP
|
||||||
//TO_DO
|
netif->hostname = "espressif";
|
||||||
/*
|
|
||||||
if ((struct netif *)wifi_get_netif(STATION_IF) == netif) {
|
|
||||||
if (default_hostname == 1) {
|
|
||||||
wifi_station_set_default_hostname(netif->hwaddr);
|
|
||||||
}
|
|
||||||
netif->hostname = hostname;
|
|
||||||
} else {
|
|
||||||
netif->hostname = NULL;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
sprintf(hostname, "ESP_%02X%02X%02X", netif->hwaddr[3], netif->hwaddr[4], netif->hwaddr[5]);
|
|
||||||
netif->hostname = hostname;
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
sprintf(hostname, "ESP_%02X%02X%02X", netif->hwaddr[3], netif->hwaddr[4], netif->hwaddr[5]);
|
netif->hostname = "lwip";
|
||||||
netif->hostname = hostname;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* LWIP_NETIF_HOSTNAME */
|
#endif /* LWIP_NETIF_HOSTNAME */
|
||||||
|
@ -126,7 +126,7 @@ typedef enum{
|
|||||||
} tcpip_adapter_option_id_t;
|
} tcpip_adapter_option_id_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize tcpip adpater
|
* @brief Initialize tcpip adapter
|
||||||
*
|
*
|
||||||
* This will initialize TCPIP stack inside.
|
* This will initialize TCPIP stack inside.
|
||||||
*/
|
*/
|
||||||
@ -411,12 +411,12 @@ esp_interface_t tcpip_adapter_get_esp_if(void *dev);
|
|||||||
*/
|
*/
|
||||||
esp_err_t tcpip_adapter_get_sta_list(wifi_sta_list_t *wifi_sta_list, tcpip_adapter_sta_list_t *tcpip_sta_list);
|
esp_err_t tcpip_adapter_get_sta_list(wifi_sta_list_t *wifi_sta_list, tcpip_adapter_sta_list_t *tcpip_sta_list);
|
||||||
|
|
||||||
#define TCPIP_HOSTNAME_MAX_SIZE 31
|
#define TCPIP_HOSTNAME_MAX_SIZE 32
|
||||||
/**
|
/**
|
||||||
* @brief Set the hostname to the interface
|
* @brief Set the hostname to the interface
|
||||||
*
|
*
|
||||||
* @param[in] tcpip_if: the interface which we will set the hostname
|
* @param[in] tcpip_if: the interface which we will set the hostname
|
||||||
* @param[in] hostname: the host name for set the interfce
|
* @param[in] hostname: the host name for set the interface, the max length of hostname is 32 bytes
|
||||||
*
|
*
|
||||||
* @return ESP_OK:success
|
* @return ESP_OK:success
|
||||||
* ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY:interface status error
|
* ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY:interface status error
|
||||||
@ -428,7 +428,7 @@ esp_err_t tcpip_adapter_set_hostname(tcpip_adapter_if_t tcpip_if, const char *ho
|
|||||||
* @brief Get the hostname from the interface
|
* @brief Get the hostname from the interface
|
||||||
*
|
*
|
||||||
* @param[in] tcpip_if: the interface which we will get the hostname
|
* @param[in] tcpip_if: the interface which we will get the hostname
|
||||||
* @param[in] hostname: the host name from the interfce
|
* @param[in] hostname: the host name from the interface
|
||||||
*
|
*
|
||||||
* @return ESP_OK:success
|
* @return ESP_OK:success
|
||||||
* ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY:interface status error
|
* ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY:interface status error
|
||||||
|
@ -706,34 +706,35 @@ esp_err_t tcpip_adapter_get_sta_list(wifi_sta_list_t *wifi_sta_list, tcpip_adapt
|
|||||||
|
|
||||||
esp_err_t tcpip_adapter_set_hostname(tcpip_adapter_if_t tcpip_if, const char *hostname)
|
esp_err_t tcpip_adapter_set_hostname(tcpip_adapter_if_t tcpip_if, const char *hostname)
|
||||||
{
|
{
|
||||||
|
#if LWIP_NETIF_HOSTNAME
|
||||||
struct netif *p_netif;
|
struct netif *p_netif;
|
||||||
static char hostinfo[TCPIP_HOSTNAME_MAX_SIZE + 1];
|
static char hostinfo[TCPIP_HOSTNAME_MAX_SIZE + 1][TCPIP_ADAPTER_IF_MAX];
|
||||||
|
|
||||||
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || hostname == NULL) {
|
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || hostname == NULL) {
|
||||||
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(hostname) >= TCPIP_HOSTNAME_MAX_SIZE) {
|
if (strlen(hostname) > TCPIP_HOSTNAME_MAX_SIZE) {
|
||||||
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
p_netif = esp_netif[tcpip_if];
|
p_netif = esp_netif[tcpip_if];
|
||||||
if (p_netif != NULL) {
|
if (p_netif != NULL) {
|
||||||
if (netif_is_up(p_netif)) {
|
memset(hostinfo[tcpip_if], 0, sizeof(hostinfo[tcpip_if]));
|
||||||
return ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY;
|
memcpy(hostinfo[tcpip_if], hostname, strlen(hostname));
|
||||||
} else {
|
p_netif->hostname = hostinfo[tcpip_if];
|
||||||
memset(hostinfo, 0, sizeof(hostinfo));
|
|
||||||
memcpy(hostinfo, hostname, strlen(hostname));
|
|
||||||
p_netif->hostname = hostinfo;
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
return ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
return ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_get_hostname(tcpip_adapter_if_t tcpip_if, const char **hostname)
|
esp_err_t tcpip_adapter_get_hostname(tcpip_adapter_if_t tcpip_if, const char **hostname)
|
||||||
{
|
{
|
||||||
|
#if LWIP_NETIF_HOSTNAME
|
||||||
struct netif *p_netif = NULL;
|
struct netif *p_netif = NULL;
|
||||||
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || hostname == NULL) {
|
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || hostname == NULL) {
|
||||||
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
||||||
@ -746,6 +747,9 @@ esp_err_t tcpip_adapter_get_hostname(tcpip_adapter_if_t tcpip_if, const char **h
|
|||||||
} else {
|
} else {
|
||||||
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
return ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user