Beispiel #1
0
void ICACHE_FLASH_ATTR dhcps_stop(void)
{
	struct netif * apnetif = (struct netif *)eagle_lwip_getif(0x01);

	udp_disconnect(pcb_dhcps);
	dhcps_lease_flag = true;
    if(apnetif->dhcps_pcb != NULL) {
        udp_remove(apnetif->dhcps_pcb);
        apnetif->dhcps_pcb = NULL;
    }

	//udp_remove(pcb_dhcps);
	list_node *pnode = NULL;
	list_node *pback_node = NULL;
	pnode = plist;
	while (pnode != NULL) {
		pback_node = pnode;
		pnode = pback_node->pnext;
		node_remove_from_list(&plist, pback_node);
		os_free(pback_node->pnode);
		pback_node->pnode = NULL;
		os_free(pback_node);
		pback_node = NULL;
	}
}
Beispiel #2
0
void ICACHE_FLASH_ATTR dhcps_start(struct ip_info *info)
{
	struct netif * apnetif = (struct netif *)eagle_lwip_getif(0x01);

	if(apnetif->dhcps_pcb != NULL) {
        udp_remove(apnetif->dhcps_pcb);
    }

	pcb_dhcps = udp_new();
	if (pcb_dhcps == NULL || info ==NULL) {
		os_printf("dhcps_start(): could not obtain pcb\n");
	}

	apnetif->dhcps_pcb = pcb_dhcps;

	IP4_ADDR(&broadcast_dhcps, 255, 255, 255, 255);

	server_address = info->ip;
	wifi_softap_init_dhcps_lease(server_address.addr);
	client_address_plus.addr = dhcps_lease.start_ip.addr;

	udp_bind(pcb_dhcps, IP_ADDR_ANY, DHCPS_SERVER_PORT);
	udp_recv(pcb_dhcps, handle_dhcp, NULL);
#if DHCPS_DEBUG
	os_printf("dhcps:dhcps_start->udp_recv function Set a receive callback handle_dhcp for UDP_PCB pcb_dhcps\n");
#endif
}
static void
task_if1(struct ETSEventTag *e)
{
    struct netif *myif = eagle_lwip_getif(1);

    if (e->sig == 0) {
        myif->input((struct pbuf *)(e->par), myif);
    }
}
Beispiel #4
0
static void ICACHE_FLASH_ATTR task_if1(struct ETSEventTag *e)
{
    struct netif *myif = eagle_lwip_getif(1);
    if (e->sig == 0) {
    	if(myif != NULL) {
        	myif->input((struct pbuf *)e->par, myif);
    	}
    	else {
    		struct pbuf *p = (struct pbuf *)e->par;
    		ppRecycleRxPkt(p->eb);
    		pbuf_free(p);
    	}
    }
}
Beispiel #5
0
/******************************************************************************
 * FunctionName : espconn_udp_sent
 * Description  : sent data for client or server
 * Parameters   : void *arg -- client or server to send
 * 				  uint8* psent -- Data to send
 *                uint16 length -- Length of data to send
 * Returns      : return espconn error code.
 * - ESPCONN_OK. Successful. No error occured.
 * - ESPCONN_MEM. Out of memory.
 * - ESPCONN_RTE. Could not find route to destination address.
 * - More errors could be returned by lower protocol layers.
*******************************************************************************/
err_t ICACHE_FLASH_ATTR
espconn_udp_sent(void *arg, uint8 *psent, uint16 length)
{
    espconn_msg *pudp_sent = arg;
    struct udp_pcb *upcb = pudp_sent->pcommon.pcb;
    struct pbuf *p, *q ,*p_temp;
    u8_t *data = NULL;
    u16_t cnt = 0;
    u16_t datalen = 0;
    u16_t i = 0;
    err_t err;
    LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %d %p\n", __LINE__, length, upcb));

    if (pudp_sent == NULL || upcb == NULL || psent == NULL || length == 0) {
        return ESPCONN_ARG;
    }

    if ((IP_FRAG_MAX_MTU - 20 - 8) < length) {
        datalen = IP_FRAG_MAX_MTU - 20 - 8;
    } else {
        datalen = length;
    }

    p = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM);
    LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, p));

    if (p != NULL) {
        q = p;

        while (q != NULL) {
            data = (u8_t *)q->payload;
            LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, data));

            for (i = 0; i < q->len; i++) {
                data[i] = ((u8_t *) psent)[cnt++];
            }

            q = q->next;
        }
    } else {
        return ESPCONN_MEM;
    }

    upcb->remote_port = pudp_sent->pespconn->proto.udp->remote_port;
    IP4_ADDR(&upcb->remote_ip, pudp_sent->pespconn->proto.udp->remote_ip[0],
    		pudp_sent->pespconn->proto.udp->remote_ip[1],
    		pudp_sent->pespconn->proto.udp->remote_ip[2],
    		pudp_sent->pespconn->proto.udp->remote_ip[3]);

    LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %x %d\n", __LINE__, upcb->remote_ip, upcb->remote_port));

    struct netif *sta_netif = (struct netif *)eagle_lwip_getif(0x00);
    struct netif *ap_netif =  (struct netif *)eagle_lwip_getif(0x01);
		
    if(wifi_get_opmode() == ESPCONN_AP_STA && default_interface == ESPCONN_AP_STA && sta_netif != NULL && ap_netif != NULL)
    {
    	if(netif_is_up(sta_netif) && netif_is_up(ap_netif) && \
			ip_addr_isbroadcast(&upcb->remote_ip, sta_netif) && \
			ip_addr_isbroadcast(&upcb->remote_ip, ap_netif)) {

    	  p_temp = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM);
    	  if (pbuf_copy (p_temp,p) != ERR_OK) {
    		  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent: copying to new pbuf failed\n"));
    		  return ESPCONN_ARG;
    	  }
		  netif_set_default(sta_netif);
		  err = udp_send(upcb, p_temp);
		  pbuf_free(p_temp);
		  netif_set_default(ap_netif);
    	}
    }
	      err = udp_send(upcb, p);

    LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %d\n", __LINE__, err));

    if (p->ref != 0) {
        LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, p));
        pbuf_free(p);
        pudp_sent->pcommon.ptrbuf = psent + datalen;
        pudp_sent->pcommon.cntr = length - datalen;
        pudp_sent->pcommon.err = err;
        espconn_data_sent(pudp_sent, ESPCONN_SEND);
        if (err > 0)
        	return ESPCONN_IF;
        return err;
    } else {
    	pbuf_free(p);
    	return ESPCONN_RTE;
    }
}
static void ICACHE_FLASH_ATTR
 myProber(void *arg)
{
	struct netif* pIf = eagle_lwip_getif(0);
	ieee80211_send_probereq(pIf,g_sa,g_da,g_bssid,&g_ssid,g_ssidlen);
}
/******************************************************************************
 * FunctionName : espconn_udp_sendto
 * Description  : sent data for UDP
 * Parameters   : void *arg -- UDP to send
 *                uint8* psent -- Data to send
 *                uint16 length -- Length of data to send
 * Returns      : return espconn error code.
 * - ESPCONN_OK. Successful. No error occured.
 * - ESPCONN_MEM. Out of memory.
 * - ESPCONN_RTE. Could not find route to destination address.
 * - More errors could be returned by lower protocol layers.
*******************************************************************************/
err_t ICACHE_FLASH_ATTR
espconn_udp_sendto(void* arg, uint8* psent, uint16 length)
{
    espconn_msg* pudp_sent = arg;
    struct udp_pcb* upcb = pudp_sent->pcommon.pcb;
    struct espconn* pespconn = pudp_sent->pespconn;
    struct pbuf* p, *q , *p_temp;
    struct ip_addr dst_ip;
    u16_t dst_port;
    u8_t* data = NULL;
    u16_t cnt = 0;
    u16_t datalen = 0;
    u16_t i = 0;
    err_t err;
    LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %d %p\n", __LINE__, length, upcb));

    if (pudp_sent == NULL || upcb == NULL || psent == NULL || length == 0) {
        return ESPCONN_ARG;
    }

    if ((IP_MAX_MTU - 20 - 8) < length) {
        datalen = IP_MAX_MTU - 20 - 8;
    } else {
        datalen = length;
    }

    p = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM);
    LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, p));

    if (p != NULL) {
        q = p;

        while (q != NULL) {
            data = (u8_t*)q->payload;
            LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, data));

            for (i = 0; i < q->len; i++) {
                data[i] = ((u8_t*) psent)[cnt++];
            }

            q = q->next;
        }
    } else {
        return ESPCONN_MEM;
    }

    dst_port = pespconn->proto.udp->remote_port;
    IP4_ADDR(&dst_ip, pespconn->proto.udp->remote_ip[0],
             pespconn->proto.udp->remote_ip[1], pespconn->proto.udp->remote_ip[2],
             pespconn->proto.udp->remote_ip[3]);
    LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %x %d\n", __LINE__, upcb->remote_ip, upcb->remote_port));

#if LWIP_IPV6 || LWIP_IGMP
    ipX_addr_t* dst_ip_route = ip_2_ipX(&dst_ip);

    if (ipX_addr_ismulticast(PCB_ISIPV6(upcb), dst_ip_route)) {
        /* For multicast, find a netif based on source address. */
#if LWIP_IPV6
        if (PCB_ISIPV6(upcb)) {
            dst_ip_route = &upcb->local_ip;
        } else
#endif /* LWIP_IPV6 */
        {
#if LWIP_IGMP
            upcb->multicast_ip.addr = dst_ip.addr;
#endif /* LWIP_IGMP */
        }
    }

#endif /* LWIP_IPV6 || LWIP_IGMP */

    struct netif* sta_netif = (struct netif*)eagle_lwip_getif(0x00);
    struct netif* ap_netif = (struct netif*)eagle_lwip_getif(0x01);

    if (wifi_get_opmode() == ESPCONN_AP_STA && default_interface == ESPCONN_AP_STA && sta_netif != NULL && ap_netif != NULL) {
        if (netif_is_up(sta_netif) && netif_is_up(ap_netif) && \
                ip_addr_isbroadcast(&(upcb->remote_ip.ip4), sta_netif) && \
                ip_addr_isbroadcast(&(upcb->remote_ip.ip4), ap_netif)) {

            p_temp = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM);

            if (pbuf_copy(p_temp, p) != ERR_OK) {
                LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sendto: copying to new pbuf failed\n"));
                return ESPCONN_ARG;
            }

            netif_set_default(sta_netif);
            err = udp_sendto(upcb, p_temp, &dst_ip, dst_port);
            pbuf_free(p_temp);
            netif_set_default(ap_netif);
        }
    }

    err = udp_sendto(upcb, p, &dst_ip, dst_port);

    if (p->ref != 0) {
        pbuf_free(p);
        pudp_sent->pcommon.ptrbuf = psent + datalen;
        pudp_sent->pcommon.cntr = length - datalen;
        pudp_sent->pcommon.err = err;
        espconn_data_sent(pudp_sent, ESPCONN_SENDTO);

        if (err > 0) {
            return ESPCONN_IF;
        }

        return err;
    } else {
        pbuf_free(p);
        return ESPCONN_RTE;
    }
}
Beispiel #8
0
static int IRAM _send(netdev_t *netdev, const iolist_t *iolist)
{
    ESP_WIFI_DEBUG("%p %p", netdev, iolist);

    assert(netdev != NULL);
    assert(iolist != NULL);

    if (_in_send) {
        return 0;
    }
    _in_send = true;

    esp_wifi_netdev_t *dev = (esp_wifi_netdev_t*)netdev;

    critical_enter();
    if (dev->state != ESP_WIFI_CONNECTED) {
        ESP_WIFI_DEBUG("WiFi is still not connected to AP, cannot send");
        _in_send = false;
        critical_exit();
        return -EIO;
    }

    if (wifi_get_opmode() != ESP_WIFI_MODE) {
        ESP_WIFI_DEBUG("WiFi is not in correct mode, cannot send");
        _in_send = false;
        critical_exit();
        return -EIO;
    }

    const iolist_t *iol = iolist;
    size_t iol_len = 0;

    /* determine the frame size */
    while (iol) {
        iol_len += iol->iol_len;
        iol = iol->iol_next;
    }

    /* limit checks */
    if (iol_len > ETHERNET_MAX_LEN) {
        ESP_WIFI_DEBUG("frame length exceeds the maximum (%u > %u)",
                       iol_len, ETHERNET_MAX_LEN);
        _in_send = false;
        critical_exit();
        return -EBADMSG;
    }

    if (iol_len < sizeof(ethernet_hdr_t)) {
        ESP_WIFI_DEBUG("frame length is less than the size of an Ethernet"
                       "header (%u < %u)", iol_len, sizeof(ethernet_hdr_t));
        _in_send = false;
        critical_exit();
        return -EBADMSG;
    }

    struct netif *sta_netif = (struct netif *)eagle_lwip_getif(ESP_WIFI_STATION_IF);
    netif_set_default(sta_netif);

    struct pbuf *pb;

    if (get_free_heap_size() < ESP_WIFI_HEAP_MARGIN ||
        (pb = pbuf_alloc(PBUF_LINK, iol_len, PBUF_RAM)) == NULL ||
        (pb->tot_len < iol_len)) {
        ESP_WIFI_LOG_ERROR("could not allocate buffer to send %d bytes ", iol_len);
        /*
         * The memory of EPS8266 is quite small. Therefore, it may happen on
         * heavy network load that we run into out of memory and we have
         * to wait until lwIP pbuf has been flushed. We slow down sending a bit.
         */
        critical_exit();
        /* wait 20 ms */
        xtimer_usleep(20 * US_PER_MS);

        _in_send = false;
        return -EIO;
    }

    struct pbuf *pbi = pb;
    uint8_t *pbi_payload = pb->payload;
    size_t pbi_pos = 0;

    /* prepare lwIP packet buffer direct from iolist without any buffer */
    for (const iolist_t *iol = iolist; iol && pbi; iol = iol->iol_next) {
        uint8_t *iol_base = iol->iol_base;
        for (unsigned i = 0; i < iol->iol_len && pbi; i++) {
            pbi_payload[pbi_pos++] = iol_base[i];
            if (pbi_pos >= pbi->len) {
                pbi = pbi->next;
            }
        }
    }

#if ENABLE_DEBUG
    pbi = pb;
    pbi_pos = 0;

    for (; pbi; pbi = pbi->next) {
        memcpy(_send_pkt_buf + pbi_pos, pbi->payload, pbi->len);
        pbi_pos += pbi->len;
    }

    const ethernet_hdr_t* hdr = (const ethernet_hdr_t *)_send_pkt_buf;

    ESP_WIFI_DEBUG("send %u byte to " MAC_STR,
                   (unsigned)iol_len, MAC_STR_ARG(hdr->dst));
#if MODULE_OD
    od_hex_dump(_send_pkt_buf, iol_len, OD_WIDTH_DEFAULT);
#endif /* MODULE_OD */
#endif /* ENABLE_DEBUG */

    critical_exit();
    /* sta_netif->linkoutput = ieee80211_output_pbuf */
    err_t res = sta_netif->linkoutput(sta_netif, pb);
    pbuf_free(pb);

    if (res == ERR_OK) {
        /* There was no ieee80211_output_pbuf error and no send timeout. */
        netdev->event_callback(netdev, NETDEV_EVENT_TX_COMPLETE);
        _in_send = false;
        return iol_len;
    }
    else {
        /* There was either a ieee80211_output_pbuf error or send timed out. */
        _in_send = false;
        return -EIO;
    }
}