Ejemplo n.º 1
0
void
ping_init(void)
{
#if PING_USE_SOCKETS
  sys_thread_new("ping_thread", ping_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
#else /* PING_USE_SOCKETS */
  ping_raw_init();
#endif /* PING_USE_SOCKETS */
}
Ejemplo n.º 2
0
void ping_init(void)
{
#if !ENET_RECEIVE_ALL_INTERRUPT
    uint32_t devNumber = 0; 
    enet_dev_if_t * enetIfPtr;
#if LWIP_HAVE_LOOPIF
    devNumber = fsl_netif0.num - 1;
#else
    devNumber = fsl_netif0.num;
#endif
    enetIfPtr = (enet_dev_if_t *)&enetDevIf[devNumber];
#endif
    ping_raw_init();
    while(1)
    {
#if !ENET_RECEIVE_ALL_INTERRUPT
        ENET_receive(enetIfPtr);
#endif
        sys_check_timeouts();
    }
}
Ejemplo n.º 3
0
bool ICACHE_FLASH_ATTR
ping_start(struct ping_option *ping_opt)
{
	struct ping_msg *pingmsg = NULL;
	pingmsg = (struct ping_msg *)os_zalloc(sizeof(struct ping_msg));
	if (pingmsg == NULL || ping_opt == NULL)
		return false;

	pingmsg->ping_opt = ping_opt;
	if (ping_opt->count != 0)
		pingmsg->max_count = ping_opt->count;
	else
		pingmsg->max_count = DEFAULT_PING_MAX_COUNT;

	if (ping_opt->coarse_time != 0)
		pingmsg->coarse_time = ping_opt->coarse_time * PING_COARSE;
	else
		pingmsg->coarse_time = PING_COARSE;

	pingmsg->ping_start = system_get_time();
	pingmsg->sent_count = pingmsg->max_count;
	return ping_raw_init(pingmsg);
}
Ejemplo n.º 4
0
static int __init lwip_netstack_init(void)
{
	int rc;
	struct vmm_netswitch *nsw;
	struct vmm_devtree_node *node;
	const char *str;
	u8 ip[] = {169, 254, 1, 1};
	u8 mask[] = {255, 255, 255, 0};
	ip_addr_t __ip, __nm, __gw;

	/* Clear lwIP state */
	memset(&lns, 0, sizeof(lns));

	/* Get netstack device tree node if available */
	node = vmm_devtree_getnode(VMM_DEVTREE_PATH_SEPARATOR_STRING
				   VMM_DEVTREE_VMMINFO_NODE_NAME
				   VMM_DEVTREE_PATH_SEPARATOR_STRING
				   VMM_DEVTREE_VMMNET_NODE_NAME
				   VMM_DEVTREE_PATH_SEPARATOR_STRING
				   VMM_DEVTREE_NETSTACK_NODE_NAME);

	/* Retrive preferred IP address */
	if (vmm_devtree_read_string(node, "ipaddr", &str) == VMM_OK) {
		/* Read ip address from netstack node */
		str2ipaddr(ip, str);
	}

	/* Retrive preferred IP address */
	if (vmm_devtree_read_string(node, "netmask", &str) == VMM_OK) {
		/* Read network mask from netstack node */
		str2ipaddr(mask, str);
	}

	/* Retrive preferred netswitch */
	if (vmm_devtree_read_string(node, "netswitch", &str) == VMM_OK) {
		/* Find netswitch with given name */
		nsw = vmm_netswitch_find(str);
	} else {
		/* Get default netswitch */
		nsw = vmm_netswitch_default();
	}
	if (!nsw) {
		vmm_panic("%s: No netswitch found\n", __func__);
	}

	/* Release netstack device tree node */
	vmm_devtree_dref_node(node);

	/* Allocate a netport */
	lns.port = vmm_netport_alloc("lwip-netport", VMM_NETPORT_DEF_QUEUE_SIZE);
	if (!lns.port) {
		vmm_printf("%s: vmm_netport_alloc() failed\n", __func__);
		rc = VMM_ENOMEM;
		goto fail;
	}

	/* Setup a netport */
	lns.port->mtu = 1500;
	lns.port->link_changed = lwip_set_link;
	lns.port->can_receive = lwip_can_receive;
	lns.port->switch2port_xfer = lwip_switch2port_xfer;
	lns.port->priv = &lns;

	/* Register a netport */
	rc = vmm_netport_register(lns.port);
	if (rc) {
		goto fail1;
	}

	/* Initialize lwIP + TCP/IP APIs */
	tcpip_init(NULL, NULL);

	/* Add netif */
	IP4_ADDR(&__ip, ip[0],ip[1],ip[2],ip[3]);
	IP4_ADDR(&__nm, mask[0],mask[1],mask[2],mask[3]);
	IP4_ADDR(&__gw, ip[0],ip[1],ip[2],ip[3]);
	netif_add(&lns.nif, &__ip, &__nm, &__gw, &lns,
		  lwip_netstack_netif_init, ethernet_input);

	/* Set default netif */
	netif_set_default(&lns.nif);

	/* Attach netport with netswitch 
	 * Note: This will cause netport link_change()
	 */
	rc = vmm_netswitch_port_add(nsw, lns.port);
	if (rc) {
		goto fail2;
	}

#if !defined(PING_USE_SOCKETS)
	/* Initalize RAW PCB for ping */
	ping_raw_init();
#endif

	return VMM_OK;

fail2:
	vmm_netport_unregister(lns.port);
fail1:
	vmm_netport_free(lns.port);
fail:
	return rc;
}