#define IFNAME0 'e'
#define IFNAME1 'n'
-static char hostname[16];
-
/**
* In this function, the hardware should be initialized.
* Called from ethernetif_init().
/* device capabilities */
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
-
+
#if ESP_LWIP
#if LWIP_IGMP
-
- netif->flags |= NETIF_FLAG_IGMP;
+ netif->flags |= NETIF_FLAG_IGMP;
#endif
#endif
- /* Do whatever else is needed to initialize interface. */
+ /* Do whatever else is needed to initialize interface. */
}
/**
LWIP_DEBUGF(NETIF_DEBUG,("eth_if=%d netif=%p pbuf=%p len=%d\n", eth_if, netif, p, p->len));
return ERR_IF;
- }
-
+ }
+
#if ESP_LWIP
- q = p;
- u16_t pbuf_x_len = 0;
- pbuf_x_len = q->len;
- if(q->next !=NULL)
- {
- //char cnt = 0;
- struct pbuf *tmp = q->next;
- while(tmp != NULL)
- {
- memcpy( (u8_t *)( (u8_t *)(q->payload) + pbuf_x_len), (u8_t *)tmp->payload , tmp->len );
- pbuf_x_len += tmp->len;
- //cnt++;
- tmp = tmp->next;
- }
+ q = p;
+ u16_t pbuf_x_len = 0;
+ pbuf_x_len = q->len;
+ if(q->next !=NULL) {
+ //char cnt = 0;
+ struct pbuf *tmp = q->next;
+ while(tmp != NULL) {
+ memcpy( (u8_t *)( (u8_t *)(q->payload) + pbuf_x_len), (u8_t *)tmp->payload , tmp->len );
+ pbuf_x_len += tmp->len;
+ //cnt++;
+ tmp = tmp->next;
}
-
- return esp_eth_tx(q->payload, pbuf_x_len);
+ }
+
+ return esp_eth_tx(q->payload, pbuf_x_len);
#else
- for(q = p; q != NULL; q = q->next) {
- return esp_emac_tx(q->payload, q->len);
- }
+ for(q = p; q != NULL; q = q->next) {
+ return esp_emac_tx(q->payload, q->len);
+ }
return ERR_OK;
#endif
}
ethernetif_input(struct netif *netif, void *buffer, uint16_t len)
{
struct pbuf *p;
-
+
if(buffer== NULL || netif == NULL)
- goto _exit;
+ goto _exit;
#if CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE
p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM);
if (p == NULL) {
p->payload = buffer;
p->user_flag = PBUF_USER_FLAG_OWNER_ETH;
p->user_buf = buffer;
-
+
/* full packet send to tcpip_thread to process */
if (netif->input(p, netif) != ERR_OK) {
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
}
#endif
_exit:
-;
+;
}
/**
/* Initialize interface hostname */
#if ESP_LWIP
- sprintf(hostname, "ESP_%02X%02X%02X", netif->hwaddr[3], netif->hwaddr[4], netif->hwaddr[5]);
- netif->hostname = hostname;
-
+ netif->hostname = "espressif";
#else
- sprintf(hostname, "ESP_%02X%02X%02X", netif->hwaddr[3], netif->hwaddr[4], netif->hwaddr[5]);
- netif->hostname = hostname;
+ netif->hostname = "lwip";
#endif
-
+
#endif /* LWIP_NETIF_HOSTNAME */
/*
netif->output_ip6 = ethip6_output;
#endif /* LWIP_IPV6 */
netif->linkoutput = ethernet_low_level_output;
-
+
/* initialize the hardware */
ethernet_low_level_init(netif);
#define IFNAME0 'e'
#define IFNAME1 'n'
-static char hostname[16];
-
/**
* In this function, the hardware should be initialized.
* Called from ethernetif_init().
*/
static void
low_level_init(struct netif *netif)
-{
-
-
-
-
+{
/* set MAC hardware address length */
netif->hwaddr_len = ETHARP_HWADDR_LEN;
/* device capabilities */
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
-
-#if ESP_LWIP
+#if ESP_LWIP
#if LWIP_IGMP
-
- netif->flags |= NETIF_FLAG_IGMP;
+ netif->flags |= NETIF_FLAG_IGMP;
+#endif
#endif
-
- #endif
-
- /* Do whatever else is needed to initialize interface. */
+ /* Do whatever else is needed to initialize interface. */
}
/**
static err_t
low_level_output(struct netif *netif, struct pbuf *p)
{
- wifi_interface_t wifi_if = tcpip_adapter_get_esp_if(netif);
- struct pbuf *q = p;
- err_t ret;
+ wifi_interface_t wifi_if = tcpip_adapter_get_esp_if(netif);
+ struct pbuf *q = p;
+ err_t ret;
- if (wifi_if >= ESP_IF_MAX) {
- return ERR_IF;
- }
+ if (wifi_if >= ESP_IF_MAX) {
+ return ERR_IF;
+ }
- if(q->next == NULL) {
- ret = esp_wifi_internal_tx(wifi_if, q->payload, q->len);
+ if(q->next == NULL) {
+ ret = esp_wifi_internal_tx(wifi_if, q->payload, q->len);
+ } else {
+ LWIP_DEBUGF(PBUF_DEBUG, ("low_level_output: pbuf is a list, application may has bug"));
+ q = pbuf_alloc(PBUF_RAW_TX, p->tot_len, PBUF_RAM);
+ if (q != NULL) {
+ pbuf_copy(q, p);
} else {
- LWIP_DEBUGF(PBUF_DEBUG, ("low_level_output: pbuf is a list, application may has bug"));
- q = pbuf_alloc(PBUF_RAW_TX, p->tot_len, PBUF_RAM);
- if (q != NULL) {
- pbuf_copy(q, p);
- } else {
- return ERR_MEM;
- }
- ret = esp_wifi_internal_tx(wifi_if, q->payload, q->len);
- pbuf_free(q);
+ return ERR_MEM;
}
-
- return ret;
+ ret = esp_wifi_internal_tx(wifi_if, q->payload, q->len);
+ pbuf_free(q);
+ }
+
+ return ret;
}
/**
wlanif_input(struct netif *netif, void *buffer, u16_t len, void* eb)
{
struct pbuf *p;
-
+
if(!buffer || !netif)
- goto _exit;
+ goto _exit;
#if (ESP_L2_TO_L3_COPY == 1)
p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM);
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
pbuf_free(p);
}
-
+
_exit:
-;
+;
}
/**
/* Initialize interface hostname */
#if ESP_LWIP
-//TO_DO
-/*
- 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;
-
+ netif->hostname = "espressif";
#else
- sprintf(hostname, "ESP_%02X%02X%02X", netif->hwaddr[3], netif->hwaddr[4], netif->hwaddr[5]);
- netif->hostname = hostname;
+ netif->hostname = "lwip";
#endif
-
+
#endif /* LWIP_NETIF_HOSTNAME */
/*
netif->output_ip6 = ethip6_output;
#endif /* LWIP_IPV6 */
netif->linkoutput = low_level_output;
-
+
/* initialize the hardware */
low_level_init(netif);
typedef enum {
TCPIP_ADAPTER_IF_STA = 0, /**< ESP32 station interface */
TCPIP_ADAPTER_IF_AP, /**< ESP32 soft-AP interface */
- TCPIP_ADAPTER_IF_ETH, /**< ESP32 ethernet interface */
+ TCPIP_ADAPTER_IF_ETH, /**< ESP32 ethernet interface */
TCPIP_ADAPTER_IF_MAX
} tcpip_adapter_if_t;
} tcpip_adapter_option_id_t;
/**
- * @brief Initialize tcpip adpater
+ * @brief Initialize tcpip adapter
*
* This will initialize TCPIP stack inside.
*/
*/
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
*
* @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
* ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY:interface status error
* @brief Get the hostname from the interface
*
* @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
* ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY:interface status error
esp_err_t tcpip_adapter_set_hostname(tcpip_adapter_if_t tcpip_if, const char *hostname)
{
+#if LWIP_NETIF_HOSTNAME
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) {
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;
}
p_netif = esp_netif[tcpip_if];
if (p_netif != NULL) {
- if (netif_is_up(p_netif)) {
- return ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY;
- } else {
- memset(hostinfo, 0, sizeof(hostinfo));
- memcpy(hostinfo, hostname, strlen(hostname));
- p_netif->hostname = hostinfo;
- return ESP_OK;
- }
+ memset(hostinfo[tcpip_if], 0, sizeof(hostinfo[tcpip_if]));
+ memcpy(hostinfo[tcpip_if], hostname, strlen(hostname));
+ p_netif->hostname = hostinfo[tcpip_if];
+ return ESP_OK;
} 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)
{
+#if LWIP_NETIF_HOSTNAME
struct netif *p_netif = NULL;
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || hostname == NULL) {
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
} else {
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
}
+#else
+ return ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY;
+#endif
}
#endif