예제 #1
0
/**
 * This function should do the actual transmission of the packet. The packet is
 * contained in the pbuf that is passed to the function. This pbuf
 * might be chained.
 *
 * @param netif the lwip network interface structure for this ethernetif
 * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
 * @return ERR_OK if the packet could be sent
 *         an err_t value if the packet couldn't be sent
 *
 * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
 *       strange results. You might consider waiting for space in the DMA queue
 *       to become availale since the stack doesn't retry to send a packet
 *       dropped because of memory failure (except for the TCP timers).
 */
static err_t
ethernet_low_level_output(struct netif *netif, struct pbuf *p)
{
  struct pbuf *q;
  esp_interface_t eth_if = tcpip_adapter_get_esp_if(netif);

  if (eth_if != ESP_IF_ETH) {
    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;
    }
  }

  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);
  }
  return ERR_OK;
#endif
}
예제 #2
0
void dhcp_ip_addr_erase(void *netif)
{
    nvs_handle nvs;
    struct netif *net = (struct netif *)netif;
    esp_interface_t netif_id = tcpip_adapter_get_esp_if(net);

    if(VALID_NETIF_ID(netif_id)) {
        if (nvs_open(DHCP_NAMESPACE, NVS_READWRITE, &nvs) == ESP_OK) {
            nvs_erase_key(nvs, interface_key[netif_id]);
            nvs_commit(nvs);
            nvs_close(nvs);
        }
    }
}
예제 #3
0
void dhcp_ip_addr_store(void *netif)
{
    nvs_handle nvs;
    struct netif *net = (struct netif *)netif;
    struct dhcp *dhcp = netif_dhcp_data(net);
    uint32_t ip_addr = dhcp->offered_ip_addr.addr;
    esp_interface_t netif_id = tcpip_adapter_get_esp_if(net);

    if(VALID_NETIF_ID(netif_id)) {
        if (restored_ip_addr[netif_id] != ip_addr) {
            if (nvs_open(DHCP_NAMESPACE, NVS_READWRITE, &nvs) == ESP_OK) {
                nvs_set_u32(nvs, interface_key[netif_id], ip_addr);
                nvs_commit(nvs);
                nvs_close(nvs);
            }
        }
    }
}
예제 #4
0
bool dhcp_ip_addr_restore(void *netif)
{
    nvs_handle nvs;
    bool err = false;
    struct netif *net = (struct netif *)netif;
    struct dhcp *dhcp = netif_dhcp_data(net);
    esp_interface_t netif_id = tcpip_adapter_get_esp_if(net);

    if(VALID_NETIF_ID(netif_id)) {
        uint32_t *ip_addr = &dhcp->offered_ip_addr.addr;
        if (nvs_open(DHCP_NAMESPACE, NVS_READONLY, &nvs) == ESP_OK) {
            if (nvs_get_u32(nvs, interface_key[netif_id], ip_addr) == ESP_OK) {
                restored_ip_addr[netif_id] = *ip_addr;
                err = true;
            }
            nvs_close(nvs);
        }
    }
    return err;
}