コード例 #1
0
ファイル: netif.c プロジェクト: harmv/lwip
void
netif_init(void)
{
#if LWIP_HAVE_LOOPIF
#if LWIP_IPV4
#define LOOPIF_ADDRINIT &loop_ipaddr, &loop_netmask, &loop_gw,
  ip4_addr_t loop_ipaddr, loop_netmask, loop_gw;
  IP4_ADDR(&loop_gw, 127,0,0,1);
  IP4_ADDR(&loop_ipaddr, 127,0,0,1);
  IP4_ADDR(&loop_netmask, 255,0,0,0);
#else /* LWIP_IPV4 */
#define LOOPIF_ADDRINIT
#endif /* LWIP_IPV4 */

#if NO_SYS
  netif_add(&loop_netif, LOOPIF_ADDRINIT NULL, netif_loopif_init, ip_input);
#else  /* NO_SYS */
  netif_add(&loop_netif, LOOPIF_ADDRINIT NULL, netif_loopif_init, tcpip_input);
#endif /* NO_SYS */

#if LWIP_IPV6
  IP_ADDR6(loop_netif.ip6_addr, 0, 0, 0, PP_HTONL(0x00000001UL));
  loop_netif.ip6_addr_state[0] = IP6_ADDR_VALID;
#endif /* LWIP_IPV6 */

  netif_set_link_up(&loop_netif);
  netif_set_up(&loop_netif);
  netif_set_link_up(&loop_netif);

#endif /* LWIP_HAVE_LOOPIF */
}
コード例 #2
0
ファイル: tun.cpp プロジェクト: blitz/macgyvernet
void initialize_backend(asio::io_service &io)
{
  int fd = open_tun("lwip0");
  CHECK(fd >= 0);

  static TunInterface tunif { io, fd };

  lwip_init();


  LOG(INFO) << "lwIP initialized. Version: " << std::hex << LWIP_VERSION;

  ip_addr_t ipaddr, netmask, gw;

  IP4_ADDR(&gw, 10,0,0,1);
  IP4_ADDR(&ipaddr, 10,0,0,100);
  IP4_ADDR(&netmask, 255,0,0,0);

  netif_add(&tunif, &ipaddr, &netmask, &gw, &tunif,
            &TunInterface::static_netif_init, ip4_input);

  netif_set_default(&tunif);
  netif_set_up(&tunif);
  netif_set_link_up(&tunif);

  tunif.start_timer();

}
コード例 #3
0
/**
* @brief  This function handles Ethernet link status.
* @param  None
* @retval None
*/
void Eth_Link_IT_task( void * pvParameters )
{
  uint32_t pcPHYAddress;
  
  pcPHYAddress = ( uint32_t  ) pvParameters;
  
  for(;;)
  {
    if (xSemaphoreTake( ETH_link_xSemaphore, emacBLOCK_TIME_WAITING_ETH_LINK_IT)==pdTRUE)
    {
      /* Check whether the link interrupt has occurred or not */
      if(((ETH_ReadPHYRegister((uint16_t) pcPHYAddress, PHY_MISR)) & PHY_LINK_STATUS) != 0)
      {
        if((ETH_ReadPHYRegister((uint16_t) pcPHYAddress, PHY_SR) & 1))
        {
          netif_set_link_up(&xnetif);
        }
        else
        {
          netif_set_link_down(&xnetif);
        }
      }
    }
  }
}
コード例 #4
0
ファイル: pktif.c プロジェクト: 10code/lwip
/*-----------------------------------------------------------------------------------*/
static void
low_level_init(struct netif *netif)
{
  char adapter_mac_addr[ETHARP_HWADDR_LEN];
  u8_t my_mac_addr[ETHARP_HWADDR_LEN] = LWIP_MAC_ADDR_BASE;
  int adapter_num = PACKET_LIB_ADAPTER_NR;
  enum link_adapter_event linkstate;

#ifdef PACKET_LIB_GET_ADAPTER_NETADDRESS
  ip_addr_t netaddr;
#define GUID_LEN 128
  char guid[GUID_LEN + 1];
  memset(&guid, 0, sizeof(guid));
  PACKET_LIB_GET_ADAPTER_NETADDRESS(&netaddr);
  if (get_adapter_index_from_addr((struct in_addr *)&netaddr, guid, GUID_LEN) < 0) {
     printf("ERROR initializing network adapter, failed to get GUID for network address %s\n", ip_ntoa(&netaddr));
     LWIP_ASSERT("ERROR initializing network adapter, failed to get GUID for network address!", 0);
     return;
  }
  adapter_num = get_adapter_index(guid);
  if (adapter_num < 0) {
     printf("ERROR finding network adapter with GUID \"%s\"!\n", guid);
     LWIP_ASSERT("ERROR finding network adapter with expected GUID!", 0);
     return;
  }

#else /* PACKET_LIB_GET_ADAPTER_NETADDRESS */
#ifdef PACKET_LIB_ADAPTER_GUID
  /* get adapter index for guid string */
  adapter_num = get_adapter_index(PACKET_LIB_ADAPTER_GUID);
  if (adapter_num < 0) {
    printf("ERROR finding network adapter with GUID \"%s\"!\n", PACKET_LIB_ADAPTER_GUID);
    LWIP_ASSERT("ERROR initializing network adapter!\n", 0);
    return;
  }
#endif /* PACKET_LIB_ADAPTER_GUID */
#endif /* PACKET_LIB_GET_ADAPTER_NETADDRESS */

  /* Do whatever else is needed to initialize interface. */
  if ((netif->state = init_adapter(adapter_num, adapter_mac_addr,
                      ethernetif_process_input, netif, &linkstate)) == NULL) {
    printf("ERROR initializing network adapter %d!\n", PACKET_LIB_ADAPTER_NR);
    LWIP_ASSERT("ERROR initializing network adapter!", 0);
    return;
  }

  /* change the MAC address to a unique value
     so that multiple ethernetifs are supported */
  my_mac_addr[ETHARP_HWADDR_LEN - 1] += netif->num;
  /* Copy MAC addr */
  memcpy(&netif->hwaddr, my_mac_addr, ETHARP_HWADDR_LEN);

  if (linkstate == LINKEVENT_UP) {
    netif_set_link_up(netif);
  } else {
    netif_set_link_down(netif);
  }

  LWIP_DEBUGF(NETIF_DEBUG, ("pktif: eth_addr %02X%02X%02X%02X%02X%02X\n",netif->hwaddr[0],netif->hwaddr[1],netif->hwaddr[2],netif->hwaddr[3],netif->hwaddr[4],netif->hwaddr[5]));
}
コード例 #5
0
int AT91_EMAC_LWIP_Driver::Open(int index)
{
    /* Network interface variables */
    struct ip_addr ipaddr, subnetmask, gateway;
    struct netif *pNetIF;
    int len;
    const SOCK_NetworkConfiguration *iface;

    /* Apply network configuration */
    iface = &g_NetworkConfig.NetworkInterfaces[index];

    len = g_AT91_EMAC_NetIF.hwaddr_len;
    if(len == 0 || iface->macAddressLen < len)
    {
        len = iface->macAddressLen;
        g_AT91_EMAC_NetIF.hwaddr_len = len;
    }
    memcpy(g_AT91_EMAC_NetIF.hwaddr, iface->macAddressBuffer, len);

    if(0 == (iface->flags & SOCK_NETWORKCONFIGURATION_FLAGS_DHCP))
    {
        ipaddr.addr     = iface->ipaddr;
        gateway.addr    = iface->gateway;
        subnetmask.addr = iface->subnetmask;
    }
    else
    {
        /* Set network address variables - this will be set by either DHCP or when the configuration is applied */
        IP4_ADDR(&gateway, 0,0,0,0);
        IP4_ADDR(&ipaddr, 0,0,0,0);
        IP4_ADDR(&subnetmask, 255,255,255,0);
    }

    // PHY Power Up
    CPU_GPIO_EnableOutputPin(g_AT91_EMAC_LWIP_Config.PHY_PD_GPIO_Pin, FALSE);

    // Enable Interrupt
    CPU_INTC_ActivateInterrupt(AT91C_ID_EMAC, (HAL_CALLBACK_FPN)AT91_EMAC_LWIP_interrupt, &g_AT91_EMAC_NetIF);

    g_AT91_EMAC_NetIF.flags = NETIF_FLAG_IGMP | NETIF_FLAG_BROADCAST;

    pNetIF = netif_add( &g_AT91_EMAC_NetIF, &ipaddr, &subnetmask, &gateway, NULL, AT91_EMAC_ethhw_init, ethernet_input );

    netif_set_default( pNetIF );

    LWIP_STATUS_setorclear( LWIP_STATUS_LinkUp, 0 != dm9161_lwip_GetLinkStatus( ) );

    if (LWIP_STATUS_isset(LWIP_STATUS_LinkUp))
    {
        netif_set_link_up( pNetIF );
        netif_set_up     ( pNetIF );

        Network_PostEvent( NETWORK_EVENT_TYPE__AVAILABILITY_CHANGED, NETWORK_EVENT_FLAGS_IS_AVAILABLE );
    }

    /* Initialize the continuation routine for the driver interrupt and receive */    
    InitContinuations( pNetIF );

    return g_AT91_EMAC_NetIF.num;
}
コード例 #6
0
/**
  * @brief  Start lwip service in a certain operation mode.
  * @param[in] uint8_t opmode: the target operation mode.
  * @retval None
  */
void lwip_net_start(uint8_t opmode)
{
    struct netif *sta_if;
    struct netif *ap_if;

    switch(opmode) {
        case WIFI_MODE_STA_ONLY:
        case WIFI_MODE_REPEATER:
            wifi_connection_register_event_handler(WIFI_EVENT_IOT_PORT_SECURE, wifi_station_port_secure_event_handler);
            wifi_connection_register_event_handler(WIFI_EVENT_IOT_DISCONNECTED, wifi_station_disconnected_event_handler);
        #if USE_DHCP
            sta_if = netif_find_by_type(NETIF_TYPE_STA);
            netif_set_default(sta_if);
            netif_set_status_callback(sta_if, ip_ready_callback);
            dhcp_start(sta_if);
        #endif
            break;
        case WIFI_MODE_AP_ONLY: {
            dhcpd_settings_t dhcpd_settings = {{0},{0},{0},{0},{0},{0},{0}};
            strcpy((char *)dhcpd_settings.dhcpd_server_address, AP_IPADDR);
            strcpy((char *)dhcpd_settings.dhcpd_netmask, AP_NETMASK);
            strcpy((char *)dhcpd_settings.dhcpd_gateway, AP_GATEWAY);
            strcpy((char *)dhcpd_settings.dhcpd_primary_dns, PRIMARY_DNS);
            strcpy((char *)dhcpd_settings.dhcpd_secondary_dns, SECONDARY_DNS);
            strcpy((char *)dhcpd_settings.dhcpd_ip_pool_start, IP_POOL_START);
            strcpy((char *)dhcpd_settings.dhcpd_ip_pool_end, IP_POOL_END);
            ap_if = netif_find_by_type(NETIF_TYPE_AP);
            netif_set_default(ap_if);
            netif_set_link_up(ap_if);
            dhcpd_start(&dhcpd_settings);
            break;
        }
    }
}
コード例 #7
0
/*******************************************************************************
** Name: WebEthIntit
** Input:void
** Return: void
** Owner:zhuzhe
** Date: 2014.6.24
** Time: 11:08:41
*******************************************************************************/
_WEB_TASK_WEBTASK_INIT_
INIT FUN void WebEthIntit(void)
{
    WEB_TASK_CTRL_BLOCK*  pWebTaskControlBlock = gpstWebCtrlBlock;
    WEB_EVENT_CLASS TempWebEventItem;
    struct netif * pNetif  =  pWebTaskControlBlock->pWifiNetif;
    uint32 timeout;


    tcpip_init(NULL, NULL);
    memset(pWebTaskControlBlock->pWifiNetif, 0, sizeof(struct netif));
	netif_add(pWebTaskControlBlock->pWifiNetif, NULL, NULL, NULL, NULL,ethernetif_init, ethernet_input);
    netif_set_default(pWebTaskControlBlock->pWifiNetif);
    netif_set_link_up(pWebTaskControlBlock->pWifiNetif);
    dhcp_start(pWebTaskControlBlock->pWifiNetif);

    do
    {
        vTaskDelay(100);
        if ( netif_is_up(pWebTaskControlBlock->pWifiNetif))
        {
                   rk_printf("IP %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
                   ip4_addr1_16(&(pNetif->ip_addr)), ip4_addr2_16(&(pNetif->ip_addr)),
                   ip4_addr3_16(&(pNetif->ip_addr)), ip4_addr4_16(&(pNetif->ip_addr)));
                   rk_printf("GW %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
                          ip4_addr1_16(&(pNetif->ip_addr)), ip4_addr2_16(&(pNetif->ip_addr)),
                          ip4_addr3_16(&(pNetif->ip_addr)), ip4_addr4_16(&(pNetif->ip_addr)));
                          break;
                      }
                  }
                  while (1);


}
コード例 #8
0
static void tcpip_init_done_callback(void *arg)
{
	rt_device_t device;
	struct eth_device *ethif;
	struct ip_addr ipaddr, netmask, gw;
	struct rt_list_node* node;
	struct rt_object* object;
	struct rt_object_information *information;

	extern struct rt_object_information rt_object_container[];

	LWIP_ASSERT("invalid arg.\n",arg);

	IP4_ADDR(&gw, 0,0,0,0);
	IP4_ADDR(&ipaddr, 0,0,0,0);
	IP4_ADDR(&netmask, 0,0,0,0);

	/* enter critical */
	rt_enter_critical();

	/* for each network interfaces */
	information = &rt_object_container[RT_Object_Class_Device];
	for (node = information->object_list.next; node != &(information->object_list); node = node->next)
	{
		object = rt_list_entry(node, struct rt_object, list);
		device = (rt_device_t) object;
		if (device->type == RT_Device_Class_NetIf)
		{
			ethif = (struct eth_device*)device;

			/* leave critical */
			rt_exit_critical();

			netif_add(ethif->netif, &ipaddr, &netmask, &gw,
				ethif, netif_device_init, tcpip_input);

			if (netif_default == NULL)
				netif_set_default(ethif->netif);

#if LWIP_DHCP
			dhcp_start(ethif->netif);
#else
			netif_set_up(ethif->netif);
#endif

#ifdef LWIP_NETIF_LINK_CALLBACK
			netif_set_link_up(ethif->netif);
#endif

			/* enter critical */
			rt_enter_critical();
		}
	}

	/* leave critical */
	rt_exit_critical();

	rt_sem_release((rt_sem_t)arg);
}
コード例 #9
0
ファイル: NO_SYS_SampleCode.c プロジェクト: ambrop72/badvpn
void 
main(void)
{
  struct netif netif;

  lwip_init();

  netif_add(&netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY, NULL, netif_init, netif_input);
  netif.name[0] = 'e';
  netif.name[1] = '0';
  netif_create_ip6_linklocal_address(&netif, 1);
  netif.ip6_autoconfig_enabled = 1;
  netif_set_status_callback(&netif, netif_status_callback);
  netif_set_default(&netif);
  netif_set_up(&netif);
  
  /* Start DHCP and HTTPD */
  dhcp_start(&netif );
  httpd_init();

  while(1) {
    /* Check link state, e.g. via MDIO communication with PHY */
    if(link_state_changed()) {
      if(link_is_up()) {
        netif_set_link_up(&netif);
      } else {
        netif_set_link_down(&netif);
      }
    }

    /* Check for received frames, feed them to lwIP */
    lock_interrupts();
    struct pbuf* p = queue_try_get(&queue);
    unlock_interrupts();

    if(p != NULL) {
      LINK_STATS_INC(link.recv);
 
      /* Update SNMP stats (only if you use SNMP) */
      MIB2_STATS_NETIF_ADD(netif, ifinoctets, p->tot_len);
      int unicast = ((p->payload[0] & 0x01) == 0);
      if (unicast) {
        MIB2_STATS_NETIF_INC(netif, ifinucastpkts);
      } else {
        MIB2_STATS_NETIF_INC(netif, ifinnucastpkts);
      }

      if(netif.input(p, &netif) != ERR_OK) {
        pbuf_free(p);
      }
    }
     
    /* Cyclic lwIP timers check */
    sys_check_timeouts();
     
    /* your application goes here */
  }
}
コード例 #10
0
/**
 * @brief  This function handles Ethernet link status.
 * @param  None
 * @retval None
 */
void Eth_Link_ITHandler(uint16_t PHYAddress) {
	/* Check whether the link interrupt has occurred or not */
	if (((ETH_ReadPHYRegister(PHYAddress, PHY_MISR )) & PHY_LINK_STATUS )!= 0){
		if ((ETH_ReadPHYRegister(PHYAddress, PHY_SR ) & 1)) {
			netif_set_link_up(&gnetif);
		} else {
			netif_set_link_down(&gnetif);
		}
	}
}
コード例 #11
0
static void handleConnectEvt(cbBCM_Handle connHandle, cbBCM_ConnectionInfo info)
{
    (void)info;

    printf("%s\n",__FUNCTION__);

    struct netif* netif = &panIf.hInterface;
    netif_set_link_up(netif);
    panIf.connHandle = connHandle;
}
コード例 #12
0
ファイル: test_ip6.c プロジェクト: 0xc0170/mbed
static void
test_ip6_ll_addr_iter(int expected_ctr1, int expected_ctr2)
{
  fail_unless(linkoutput_ctr == 0);

  /* test that nothing is sent with link uo but netif down */
  netif_set_link_up(&test_netif6);
  ip6_test_handle_timers(500);
  fail_unless(linkoutput_ctr == 0);
  netif_set_link_down(&test_netif6);
  fail_unless(linkoutput_ctr == 0);

  /* test that nothing is sent with link down but netif up */
  netif_set_up(&test_netif6);
  ip6_test_handle_timers(500);
  fail_unless(linkoutput_ctr == 0);
  netif_set_down(&test_netif6);
  fail_unless(linkoutput_ctr == 0);

  /* test what is sent with link up + netif up */
  netif_set_link_up(&test_netif6);
  netif_set_up(&test_netif6);
  ip6_test_handle_timers(500);
  fail_unless(linkoutput_ctr == expected_ctr1);
  netif_set_down(&test_netif6);
  netif_set_link_down(&test_netif6);
  fail_unless(linkoutput_ctr == expected_ctr1);
  linkoutput_ctr = 0;

  netif_set_up(&test_netif6);
  netif_set_link_up(&test_netif6);
  ip6_test_handle_timers(500);
  fail_unless(linkoutput_ctr == expected_ctr2);
  netif_set_link_down(&test_netif6);
  netif_set_down(&test_netif6);
  fail_unless(linkoutput_ctr == expected_ctr2);
  linkoutput_ctr = 0;
}
コード例 #13
0
ファイル: if.c プロジェクト: HBelusca/NasuTek-Odyssey
VOID
TCPUpdateInterfaceLinkStatus(PIP_INTERFACE IF)
{
#if 0
    ULONG OperationalStatus;
    
    GetInterfaceConnectionStatus(IF, &OperationalStatus);
    
    if (OperationalStatus == MIB_IF_OPER_STATUS_OPERATIONAL)
        netif_set_link_up(IF->TCPContext);
    else
        netif_set_link_down(IF->TCPContext);
#endif
}
コード例 #14
0
ファイル: k64f_emac.c プロジェクト: sg-/sdw-workshop
void ENET_Receive_IRQHandler(void) {
    enet_dev_if_t *enetIfPtr = (enet_dev_if_t *)&enetDevIf[BOARD_DEBUG_ENET_INSTANCE];

    if (enet_hal_get_interrupt_status(((enet_dev_if_t *)enetIfPtr)->deviceNumber, kEnetRxFrameInterrupt))
        enet_mac_rx_isr(enetIfHandle);
    if (enet_hal_get_interrupt_status(((enet_dev_if_t *)enetIfPtr)->deviceNumber, kEnetTxFrameInterrupt))
        enet_mac_tx_isr(enetIfHandle);
    if (emac_timer_fired) {
          // TODO: this will have to be replaced with a proper "PHY task" that can detect changes in link status.
        if (k64f_phy_state.connected == STATE_UNKNOWN) {
            k64f_phy_state.connected = 1;
            netif_set_link_up(k64f_enetdata.netif);
        }
        emac_timer_fired = 0;
        sys_check_timeouts();
     }
}
コード例 #15
0
ファイル: ethernetif.c プロジェクト: haitao52198/HD-Elastos
static err_t eth_netif_device_init(struct netif *netif)
{
    struct eth_device *ethif;

    ethif = (struct eth_device*)netif->state;
    if (ethif != NULL)
    {
        rt_device_t device;

        /* get device object */
        device = (rt_device_t) ethif;
        if (rt_device_init(device) != RT_EOK)
        {
            return ERR_IF;
        }

        /* copy device flags to netif flags */
        netif->flags = ethif->flags;

        /* set default netif */
        if (netif_default == NULL)
            netif_set_default(ethif->netif);

#if LWIP_DHCP
        if (ethif->flags & NETIF_FLAG_DHCP)
        {
            /* if this interface uses DHCP, start the DHCP client */
            dhcp_start(ethif->netif);
        }
        else
#endif
        {
            /* set interface up */
            netif_set_up(ethif->netif);
        }

#ifdef LWIP_NETIF_LINK_CALLBACK
        netif_set_link_up(ethif->netif);
#endif

        return ERR_OK;
    }

    return ERR_IF;
}
コード例 #16
0
/* ethernetif APIs */
rt_err_t eth_device_init(struct eth_device* dev, const char* name)
{
	struct netif* pnetif;
	/* allocate memory */
	pnetif = (struct netif*) rt_malloc (sizeof(struct netif));
	if (pnetif == RT_NULL)
	{
		rt_kprintf("malloc netif failed\n");
		return -RT_ERROR;
	}
	rt_memset(pnetif, 0, sizeof(struct netif));


	/* set netif */
	dev->netif = pnetif;
	/* register to rt-thread device manager */
	rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
	dev->parent.type = RT_Device_Class_NetIf;
	rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO);


	/* add netif to lwip */
	/* NOTE: eth_init will be called back by netif_add, we should put some initialization
	         code to eth_init(). See include/lwip/netif.h line 97 */
	eth_dev = dev;
	if (netif_add(pnetif, IP_ADDR_ANY, IP_ADDR_BROADCAST, IP_ADDR_ANY, dev,
		ethernetif_init, ethernet_input) == RT_NULL)
	{
		/* failed, unregister device and free netif */
		rt_device_unregister(&(dev->parent));
		rt_free(pnetif);
		eth_dev = RT_NULL;
		return -RT_ERROR;
	}
	eth_dev = RT_NULL;

	netif_set_default(pnetif);

	/* We bring up the netif here cause we still don't have a call back function
	which indicates the ethernet interface status from the ethernet driver. */
	netif_set_up(pnetif);
	netif_set_link_up(pnetif);

	return RT_EOK;
}
コード例 #17
0
ファイル: driver.c プロジェクト: jkiiski/minix
static void nic_up(struct nic * nic, message * m)
{
	memcpy(nic->netif.hwaddr, m->DL_HWADDR, NETIF_MAX_HWADDR_LEN);

	debug_print("device %s is up MAC : %02x:%02x:%02x:%02x:%02x:%02x",
			nic->name,
			nic->netif.hwaddr[0],
			nic->netif.hwaddr[1],
			nic->netif.hwaddr[2],
			nic->netif.hwaddr[3],
			nic->netif.hwaddr[4],
			nic->netif.hwaddr[5]);

	driver_setup_read(nic);

	netif_set_link_up(&nic->netif);
	netif_set_up(&nic->netif);
}
コード例 #18
0
ファイル: main.c プロジェクト: cr1901/artiq
static void network_init(void)
{
    struct ip4_addr local_ip;
    struct ip4_addr netmask;
    struct ip4_addr gateway_ip;

    init_macadr();
    fsip_or_default(&local_ip, "ip", 192, 168, 0, 42);
    fsip_or_default(&netmask, "netmask", 255, 255, 255, 0);
    fsip_or_default(&gateway_ip, "gateway", 192, 168, 0, 1);

    lwip_init();

    netif_add(&netif, &local_ip, &netmask, &gateway_ip, 0, liteeth_init, ethernet_input);
    netif_set_default(&netif);
    netif_set_up(&netif);
    netif_set_link_up(&netif);
}
コード例 #19
0
ファイル: ethernetif.c プロジェクト: gastonfeng/rt-thread
static err_t eth_netif_device_init(struct netif *netif)
{
    struct eth_device *ethif;

    ethif = (struct eth_device*)netif->state;
    if (ethif != RT_NULL)
    {
        rt_device_t device;

        /* get device object */
        device = (rt_device_t) ethif;
        if (rt_device_init(device) != RT_EOK)
        {
            return ERR_IF;
        }

        /* copy device flags to netif flags */
        netif->flags = (ethif->flags & 0xff);

        /* set default netif */
        if (netif_default == RT_NULL)
            netif_set_default(ethif->netif);

#if LWIP_DHCP
        /* set interface up */
        netif_set_up(ethif->netif);
        /* if this interface uses DHCP, start the DHCP client */
        dhcp_start(ethif->netif);
#else
        /* set interface up */
        netif_set_up(ethif->netif);
#endif

        if (!(ethif->flags & ETHIF_LINK_PHYUP))
        {
            /* set link_up for this netif */
            netif_set_link_up(ethif->netif);
        }

        return ERR_OK;
    }

    return ERR_IF;
}
コード例 #20
0
/**
  * @brief  wifi connected will call this callback function. set lwip status in this function
  * @param[in] wifi_event_t event: not used.
  * @param[in] uint8_t *payload: not used.
  * @param[in] uint32_t length: not used.
  * @retval None
  */
static int32_t wifi_station_port_secure_event_handler(wifi_event_t event,
        uint8_t *payload,
        uint32_t length)
{
    struct netif *sta_if;

    sta_if = netif_find_by_type(NETIF_TYPE_STA);
    netif_set_link_up(sta_if);
#ifndef USE_DHCP
   /*This is a private API , which used to inform IP is ready to wifi driver
    *In present, WiFi Driver will do some operation when this API is invoked, such as:
    *Do WiFi&BLE Coexstence relative behavior if BLE is enabled and do Power Saving Status change.
    *This API will be improved, user may need to use new API to replace it in future*/
    wifi_connection_inform_ip_ready();
#endif
    xSemaphoreGive(wifi_connected);
    LOG_I(common, "wifi connected");
    return 0;
}
コード例 #21
0
STATIC mp_obj_t wiznet5k_active(size_t n_args, const mp_obj_t *args) {
    wiznet5k_obj_t *self = MP_OBJ_TO_PTR(args[0]);
    if (n_args == 1) {
        return mp_obj_new_bool(self->netif.flags & NETIF_FLAG_UP);
    } else {
        if (mp_obj_is_true(args[1])) {
            if (!(self->netif.flags & NETIF_FLAG_UP)) {
                wiznet5k_init();
                netif_set_link_up(&self->netif);
                netif_set_up(&self->netif);
            }
        } else {
            if (self->netif.flags & NETIF_FLAG_UP) {
                netif_set_down(&self->netif);
                netif_set_link_down(&self->netif);
                wiznet5k_deinit();
            }
        }
        return mp_const_none;
    }
}
コード例 #22
0
ファイル: init.c プロジェクト: ya-mouse/freertos-np51x0
static void vDemoAppsTask( void *pvParameters )
{
	struct ip_addr  xIpAddr, xNetMast, xGateway;
	static struct netif ftmac100_if;

	vSerialPutString("TASK\n");
	/* The parameters are not used in this function. */
	( void ) pvParameters;

#if 1
	/* Init lwip library */
	tcpip_init( NULL, NULL );

	/* Create and configure the EMAC interface. */
	IP4_ADDR( &xIpAddr, 192, 168, 68, 70 );
	IP4_ADDR( &xNetMast, 255, 255, 255, 0 );
	IP4_ADDR( &xGateway, 192, 168, 68, 66 );
	netif_add( &ftmac100_if, &xIpAddr, &xNetMast, &xGateway, NULL, ftMac100_init, tcpip_input );

	/* make it the default interface */
	netif_set_default( &ftmac100_if );

	/* bring it up */
	netif_set_up( &ftmac100_if );

	/* link is up */
	netif_set_link_up( &ftmac100_if );
#endif
//	if( sys_thread_new( "httpd", http_server_netconn_thread, NULL, 16384, ( tskIDLE_PRIORITY + 2 ) ) == NULL )
//		simple_printf( "apps_init: create task failed!\n");
	vSerialPutString("loop\n");
	for ( ;; )
	{
		/* do nothing, delay very long time, let other tasks
		   to run */
		vTaskDelay( 0xffff );
	}
}
コード例 #23
0
static int32_t _wifi_event_handler(wifi_event_t event,
        uint8_t *payload,
        uint32_t length)
{
    struct netif *sta_if;
    LOG_I(common, "wifi event: %d", event);

    switch(event)
    {
    case WIFI_EVENT_IOT_PORT_SECURE:
        sta_if = netif_find_by_type(NETIF_TYPE_STA);
        netif_set_link_up(sta_if);
        LOG_I(common, "wifi connected");
        break;
    case WIFI_EVENT_IOT_DISCONNECTED:
        sta_if = netif_find_by_type(NETIF_TYPE_STA);
        netif_set_link_down(sta_if);
        LOG_I(common, "wifi disconnected");
        break;
    }

    return 1;
}
コード例 #24
0
ファイル: lwip_tcpecho_sa.c プロジェクト: edarring/lpcopen
/**
 * @brief	main routine for example_lwip_tcpecho_sa_18xx43xx
 * @return	Function should not exit.
 */
int main(void)
{
	uint32_t physts;
	ip_addr_t ipaddr, netmask, gw;

	prvSetupHardware();

	/* Initialize LWIP */
	lwip_init();

	LWIP_DEBUGF(LWIP_DBG_ON, ("Starting LWIP TCP echo server...\n"));

	/* Static IP assignment */
#if LWIP_DHCP
	IP4_ADDR(&gw, 0, 0, 0, 0);
	IP4_ADDR(&ipaddr, 0, 0, 0, 0);
	IP4_ADDR(&netmask, 0, 0, 0, 0);
#else
	IP4_ADDR(&gw, 10, 1, 10, 1);
	IP4_ADDR(&ipaddr, 10, 1, 10, 234);
	IP4_ADDR(&netmask, 255, 255, 255, 0);
	APP_PRINT_IP(&ipaddr);
#endif

	/* Add netif interface for lpc17xx_8x */
	netif_add(&lpc_netif, &ipaddr, &netmask, &gw, NULL, lpc_enetif_init,
			  ethernet_input);
	netif_set_default(&lpc_netif);
	netif_set_up(&lpc_netif);

#if LWIP_DHCP
	dhcp_start(&lpc_netif);
#endif

	/* Initialize and start application */
	echo_init();

	/* This could be done in the sysTick ISR, but may stay in IRQ context
	   too long, so do this stuff with a background loop. */
	while (1) {
		/* Handle packets as part of this loop, not in the IRQ handler */
		lpc_enetif_input(&lpc_netif);

		/* lpc_rx_queue will re-qeueu receive buffers. This normally occurs
		   automatically, but in systems were memory is constrained, pbufs
		   may not always be able to get allocated, so this function can be
		   optionally enabled to re-queue receive buffers. */
#if 0
		while (lpc_rx_queue(&lpc_netif)) {}
#endif

		/* Free TX buffers that are done sending */
		lpc_tx_reclaim(&lpc_netif);

		/* LWIP timers - ARP, DHCP, TCP, etc. */
		sys_check_timeouts();

		/* Call the PHY status update state machine once in a while
		   to keep the link status up-to-date */
		physts = lpcPHYStsPoll();

		/* Only check for connection state when the PHY status has changed */
		if (physts & PHY_LINK_CHANGED) {
			if (physts & PHY_LINK_CONNECTED) {
				Board_LED_Set(0, true);

				/* Set interface speed and duplex */
				if (physts & PHY_LINK_SPEED100) {
					Chip_ENET_SetSpeed(LPC_ETHERNET, 1);
					NETIF_INIT_SNMP(&lpc_netif, snmp_ifType_ethernet_csmacd, 100000000);
				}
				else {
					Chip_ENET_SetSpeed(LPC_ETHERNET, 0);
					NETIF_INIT_SNMP(&lpc_netif, snmp_ifType_ethernet_csmacd, 10000000);
				}
				if (physts & PHY_LINK_FULLDUPLX) {
					Chip_ENET_SetDuplex(LPC_ETHERNET, true);
				}
				else {
					Chip_ENET_SetDuplex(LPC_ETHERNET, false);
				}

				netif_set_link_up(&lpc_netif);
			}
			else {
				Board_LED_Set(0, false);
				netif_set_link_down(&lpc_netif);
			}

			DEBUGOUT("Link connect status: %d\r\n", ((physts & PHY_LINK_CONNECTED) != 0));
		}
	}

	/* Never returns, for warning only */
	return 0;
}
コード例 #25
0
/** \brief  Update PHY status from passed value
 *
 *  This function updates the current PHY status based on the
 *  passed PHY status word. The PHY status indicate if the link
 *  is active, the connection speed, and duplex.
 *
 *  \param[in]    netif   NETIF structure
 *  \param[in]    linksts Status word with link state
 *  \param[in]    sdsts   Status word with speed and duplex states
 *  \return        1 if the status has changed, otherwise 0
 */
static s32_t lpc_update_phy_sts(struct netif *netif, u32_t linksts, u32_t sdsts)
{
	s32_t changed = 0;

	/* Update link active status */
	if (linksts & LAN8_LINK_STATUS)
		physts.phy_link_active = 1;
	else
		physts.phy_link_active = 0;

	switch (sdsts & LAN8_SPEEDMASK) {
		case LAN8_SPEED100F:
		default:
			physts.phy_speed_100mbs = 1;
			physts.phy_full_duplex = 1;
			break;

		case LAN8_SPEED10F:
			physts.phy_speed_100mbs = 0;
			physts.phy_full_duplex = 1;
			break;

		case LAN8_SPEED100H:
			physts.phy_speed_100mbs = 1;
			physts.phy_full_duplex = 0;
			break;

		case LAN8_SPEED10H:
			physts.phy_speed_100mbs = 0;
			physts.phy_full_duplex = 0;
			break;
	}

	if (physts.phy_speed_100mbs != olddphysts.phy_speed_100mbs) {
		changed = 1;
		if (physts.phy_speed_100mbs) {
			/* 100MBit mode. */
			lpc_emac_set_speed(1);

			NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);
		}
		else {
			/* 10MBit mode. */
			lpc_emac_set_speed(0);

			NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 10000000);
		}

		olddphysts.phy_speed_100mbs = physts.phy_speed_100mbs;
	}

	if (physts.phy_full_duplex != olddphysts.phy_full_duplex) {
		changed = 1;
		if (physts.phy_full_duplex)
			lpc_emac_set_duplex(1);
		else
			lpc_emac_set_duplex(0);

		olddphysts.phy_full_duplex = physts.phy_full_duplex;
	}

	if (physts.phy_link_active != olddphysts.phy_link_active) {
		changed = 1;
#if NO_SYS == 1
		if (physts.phy_link_active)
            netif_set_link_up(netif);
		else
			netif_set_link_down(netif);
#else
		if (physts.phy_link_active)
            tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_up,
                (void*) netif, 1);
         else
            tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_down,
                (void*) netif, 1);
#endif

		olddphysts.phy_link_active = physts.phy_link_active;
	}

	return changed;
}
コード例 #26
0
ファイル: pcapif.c プロジェクト: killvxk/lwip-allnetworks
/** Low-level initialization: find the correct adapter and initialize it.
 */
static void
pcapif_low_level_init(struct netif *netif)
{
  u8_t my_mac_addr[ETHARP_HWADDR_LEN] = LWIP_MAC_ADDR_BASE;
  int adapter_num = PACKET_LIB_ADAPTER_NR;
  struct pcapif_private *pa;

  /* If 'state' is != NULL at this point, we assume it is an 'int' giving
     the index of the adapter to use (+ 1 because 0==NULL is invalid).
     This can be used to instantiate multiple PCAP drivers. */
  if (netif->state != NULL) {
    adapter_num = ((int)netif->state) - 1;
    if (adapter_num < 0) {
      printf("ERROR: invalid adapter index \"%d\"!\n", adapter_num);
      LWIP_ASSERT("ERROR initializing network adapter!\n", 0);
      return;
    }
  }

#ifdef PACKET_LIB_GET_ADAPTER_NETADDRESS
  ip_addr_t netaddr;
#define GUID_LEN 128
  char guid[GUID_LEN + 1];
  memset(&guid, 0, sizeof(guid));
  PACKET_LIB_GET_ADAPTER_NETADDRESS(&netaddr);
  if (get_adapter_index_from_addr((struct in_addr *)&netaddr, guid, GUID_LEN) < 0) {
     printf("ERROR initializing network adapter, failed to get GUID for network address %s\n", ip_ntoa(&netaddr));
     LWIP_ASSERT("ERROR initializing network adapter, failed to get GUID for network address!", 0);
     return;
  }
  adapter_num = get_adapter_index(guid);
  if (adapter_num < 0) {
     printf("ERROR finding network adapter with GUID \"%s\"!\n", guid);
     LWIP_ASSERT("ERROR finding network adapter with expected GUID!", 0);
     return;
  }

#else /* PACKET_LIB_GET_ADAPTER_NETADDRESS */
#ifdef PACKET_LIB_ADAPTER_GUID
  /* get adapter index for guid string */
  adapter_num = get_adapter_index(PACKET_LIB_ADAPTER_GUID);
  if (adapter_num < 0) {
    printf("ERROR finding network adapter with GUID \"%s\"!\n", PACKET_LIB_ADAPTER_GUID);
    LWIP_ASSERT("ERROR initializing network adapter!\n", 0);
    return;
  }
#endif /* PACKET_LIB_ADAPTER_GUID */
#endif /* PACKET_LIB_GET_ADAPTER_NETADDRESS */

  /* Do whatever else is needed to initialize interface. */
  pa = pcapif_init_adapter(adapter_num, netif);
  if (pa == NULL) {
    printf("ERROR initializing network adapter %d!\n", adapter_num);
    LWIP_ASSERT("ERROR initializing network adapter!", 0);
    return;
  }
  netif->state = pa;

  /* change the MAC address to a unique value
     so that multiple ethernetifs are supported */
  /* @todo: this does NOT support multiple processes using this adapter! */
  my_mac_addr[ETHARP_HWADDR_LEN - 1] += netif->num;
  /* Copy MAC addr */
  memcpy(&netif->hwaddr, my_mac_addr, ETHARP_HWADDR_LEN);

  /* get the initial link state of the selected interface */
#if PCAPIF_HANDLE_LINKSTATE
  pa->last_link_event = pcapifh_linkstate_get(pa->link_state);
  if (pa->last_link_event == PCAPIF_LINKEVENT_DOWN) {
    netif_set_link_down(netif);
  } else {
    netif_set_link_up(netif);
  }
  sys_timeout(PCAPIF_LINKCHECK_INTERVAL_MS, pcapif_check_linkstate, netif);
#endif /* PCAPIF_HANDLE_LINKSTATE */

#if PCAPIF_RX_USE_THREAD
  pa->rx_run = 1;
  pa->rx_running = 1;
  sys_thread_new("pcapif_rxthread", pcapif_input_thread, netif, 0, 0);
#endif

  LWIP_DEBUGF(NETIF_DEBUG, ("pcapif: eth_addr %02X%02X%02X%02X%02X%02X\n",netif->hwaddr[0],netif->hwaddr[1],netif->hwaddr[2],netif->hwaddr[3],netif->hwaddr[4],netif->hwaddr[5]));
}
コード例 #27
0
static void tcpip_init_done_callback(void *arg)
{
    rt_device_t device;
    struct eth_device *ethif;
    struct ip_addr ipaddr, netmask, gw;
    struct rt_list_node* node;
    struct rt_object* object;
    struct rt_object_information *information;

    extern struct rt_object_information rt_object_container[];

    LWIP_ASSERT("invalid arg.\n",arg);

    IP4_ADDR(&gw, 0,0,0,0);
    IP4_ADDR(&ipaddr, 0,0,0,0);
    IP4_ADDR(&netmask, 0,0,0,0);

    /* enter critical */
    rt_enter_critical();

    /* for each network interfaces */
    information = &rt_object_container[RT_Object_Class_Device];
    for (node = information->object_list.next;
         node != &(information->object_list);
         node = node->next)
    {
        object = rt_list_entry(node, struct rt_object, list);
        device = (rt_device_t)object;
        if (device->type == RT_Device_Class_NetIf)
        {
            ethif = (struct eth_device *)device;

            /* leave critical */
            rt_exit_critical();

            netif_add(ethif->netif, &ipaddr, &netmask, &gw,
                      ethif, netif_device_init, tcpip_input);

            if (netif_default == RT_NULL)
                netif_set_default(ethif->netif);
#ifdef LWIP_IPV6
            ethif->netif->output_ip6 = ethip6_output;
            netif_create_ip6_linklocal_address(ethif->netif, 1);
#ifdef LWIP_IPV6_AUTOCONFIG
            ethif->netif->ip6_autoconfig_enabled = 1;
#endif
#ifdef LWIP_IPV6_MLD
            ethif->netif->mld_mac_filter = NULL;
#endif
#endif

#if LWIP_DHCP
            if (ethif->flags & NETIF_FLAG_DHCP)
            {
                /* if this interface uses DHCP, start the DHCP client */
                dhcp_start(ethif->netif);
            }
            else
#endif
            {
                /* set interface up */
                netif_set_up(ethif->netif);
            }

#ifdef LWIP_NETIF_LINK_CALLBACK
            netif_set_link_up(ethif->netif);
#endif

            /* enter critical */
            rt_enter_critical();
        }
    }

    /* leave critical */
    rt_exit_critical();
    rt_sem_release((rt_sem_t)arg);
}
コード例 #28
0
ファイル: lwip_drv.cpp プロジェクト: bratkov/tmos
//*****************************************************************************
//
//! Service the lwIP timers.
//!
//! This function services all of the lwIP periodic timers, including TCP and
//! Host timers.  This should be called from the lwIP context, which may be
//! the Ethernet interrupt (in the case of a non-RTOS system) or the lwIP
//! thread, in the event that an RTOS is used.
//!
//! \return None.
//
//*****************************************************************************
static void lwIPServiceTimers(struct netif *netif)
{
	LWIP_DRIVER_DATA* drv_data = (LWIP_DRIVER_DATA*)netif;
	MAC_Type* mac = (MAC_Type*)netif->state;
    //
    // Service the MDIX timer.
    //
    if(drv_data->timer_main > drv_data->timer_mdix)
    {
        //
        // See if there has not been a link for 2 seconds.
        //
        if((EthernetPHYRead(mac, PHY_MR1) & PHY_MR1_LINK) == 0)
        {
            // There has not been a link for 2 seconds, so flip the MDI/MDIX
            // switch.  This is handled automatically by Fury rev A2, but is
            // harmless.
            //
        	mac->MDIX  ^= MAC_MDIX_EN;
       	    if (netif->flags & NETIF_FLAG_LINK_UP)
			{
#if LWIP_DHCP
                autoip_stop(netif);
                dhcp_start(netif);
#endif
				netif_set_link_down(netif);
			}
		}
		else
			netif_set_link_up(netif);
        //
        // Reset the MDIX timer.
        //
    	drv_data->timer_mdix = drv_data->timer_main + 2048;
    }

    //
    // Service the host timer.
    //
#if HOST_TMR_INTERVAL
    if(drv_data->timer_main > drv_data->timer_host )
    {
    	drv_data->timer_host = drv_data->timer_main + HOST_TMR_INTERVAL;
        lwIPHostTimerHandler();
    }
#endif

    //
    // Service the ARP timer.
    //
#if LWIP_ARP
    if(drv_data->timer_main > drv_data->timer_arp)
    {
    	drv_data->timer_arp = drv_data->timer_main + ARP_TMR_INTERVAL;
        etharp_tmr();
    }
#endif

    //
    // Service the TCP timer.
    //
#if LWIP_TCP
    if(drv_data->timer_main > drv_data->timer_tcp)
    {
    	drv_data->timer_tcp = drv_data->timer_main + TCP_TMR_INTERVAL;
        tcp_tmr();
    }
#endif

    //
    // Service the AutoIP timer.
    //
#if LWIP_AUTOIP
    if(drv_data->timer_main - drv_data->timer_autoIP)
    {
    	drv_data->timer_autoIP = drv_data->timer_main + AUTOIP_TMR_INTERVAL;
        autoip_tmr();
    }
#endif

    //
    // Service the DCHP Coarse Timer.
    //
#if LWIP_DHCP
    if(drv_data->timer_main > drv_data->timer_DHCPCoarse)
    {
    	drv_data->timer_DHCPCoarse = drv_data->timer_main + DHCP_COARSE_TIMER_MSECS;
        dhcp_coarse_tmr();
    }
#endif

    //
    // Service the DCHP Fine Timer.
    //
#if LWIP_DHCP
    if(drv_data->timer_main > drv_data->timer_DHCPFine)
    {
    	drv_data->timer_DHCPFine = drv_data->timer_main + DHCP_FINE_TIMER_MSECS;
        dhcp_fine_tmr();
    }
#endif
}
コード例 #29
0
ファイル: VBoxNetLwipNAT.cpp プロジェクト: bayasist/vbox
void VBoxNetLwipNAT::onLwipTcpIpInit(void* arg)
{
    AssertPtrReturnVoid(arg);
    VBoxNetLwipNAT *pNat = static_cast<VBoxNetLwipNAT *>(arg);

    HRESULT hrc = com::Initialize();
    Assert(!FAILED(hrc));

    proxy_arp_hook = pxremap_proxy_arp;
    proxy_ip4_divert_hook = pxremap_ip4_divert;

    proxy_na_hook = pxremap_proxy_na;
    proxy_ip6_divert_hook = pxremap_ip6_divert;

    /* lwip thread */
    RTNETADDRIPV4 network;
    RTNETADDRIPV4 address = g_pLwipNat->getIpv4Address();
    RTNETADDRIPV4 netmask = g_pLwipNat->getIpv4Netmask();
    network.u = address.u & netmask.u;

    ip_addr LwipIpAddr, LwipIpNetMask, LwipIpNetwork;

    memcpy(&LwipIpAddr, &address, sizeof(ip_addr));
    memcpy(&LwipIpNetMask, &netmask, sizeof(ip_addr));
    memcpy(&LwipIpNetwork, &network, sizeof(ip_addr));

    netif *pNetif = netif_add(&g_pLwipNat->m_LwipNetIf /* Lwip Interface */,
                              &LwipIpAddr /* IP address*/,
                              &LwipIpNetMask /* Network mask */,
                              &LwipIpAddr /* gateway address, @todo: is self IP acceptable? */,
                              g_pLwipNat /* state */,
                              VBoxNetLwipNAT::netifInit /* netif_init_fn */,
                              tcpip_input /* netif_input_fn */);

    AssertPtrReturnVoid(pNetif);

    LogRel(("netif %c%c%d: mac %RTmac\n",
            pNetif->name[0], pNetif->name[1], pNetif->num,
            pNetif->hwaddr));
    LogRel(("netif %c%c%d: inet %RTnaipv4 netmask %RTnaipv4\n",
            pNetif->name[0], pNetif->name[1], pNetif->num,
            pNetif->ip_addr, pNetif->netmask));
    for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) {
        if (!ip6_addr_isinvalid(netif_ip6_addr_state(pNetif, i))) {
            LogRel(("netif %c%c%d: inet6 %RTnaipv6\n",
                    pNetif->name[0], pNetif->name[1], pNetif->num,
                    netif_ip6_addr(pNetif, i)));
        }
    }

    netif_set_up(pNetif);
    netif_set_link_up(pNetif);

    if (pNat->m_ProxyOptions.ipv6_enabled) {
        /*
         * XXX: lwIP currently only ever calls mld6_joingroup() in
         * nd6_tmr() for fresh tentative addresses, which is a wrong place
         * to do it - but I'm not keen on fixing this properly for now
         * (with correct handling of interface up and down transitions,
         * etc).  So stick it here as a kludge.
         */
        for (int i = 0; i <= 1; ++i) {
            ip6_addr_t *paddr = netif_ip6_addr(pNetif, i);

            ip6_addr_t solicited_node_multicast_address;
            ip6_addr_set_solicitednode(&solicited_node_multicast_address,
                                       paddr->addr[3]);
            mld6_joingroup(paddr, &solicited_node_multicast_address);
        }

        /*
         * XXX: We must join the solicited-node multicast for the
         * addresses we do IPv6 NA-proxy for.  We map IPv6 loopback to
         * proxy address + 1.  We only need the low 24 bits, and those are
         * fixed.
         */
        {
            ip6_addr_t solicited_node_multicast_address;

            ip6_addr_set_solicitednode(&solicited_node_multicast_address,
                                       /* last 24 bits of the address */
                                       PP_HTONL(0x00000002));
            mld6_netif_joingroup(pNetif,  &solicited_node_multicast_address);
        }
    }

    proxy_init(&g_pLwipNat->m_LwipNetIf, &g_pLwipNat->m_ProxyOptions);

    natServiceProcessRegisteredPf(g_pLwipNat->m_vecPortForwardRule4);
    natServiceProcessRegisteredPf(g_pLwipNat->m_vecPortForwardRule6);
}
コード例 #30
0
/**
 * @brief	main routine for example_lwip_tcpecho_sa_17xx40xx
 * @return	Function should not exit.
 */
int main(void)
{
	uint32_t physts;
	ip_addr_t ipaddr, netmask, gw;
	static int prt_ip = 0;

	prvSetupHardware();






	/* Initialize LWIP */
	lwip_init();



	///LWIP_DEBUGF(LWIP_DBG_ON, ("Starting LWIP TCP echo server...\n"));

	/* Static IP assignment */

	IP4_ADDR(&gw, 0, 0, 0, 0);
	IP4_ADDR(&ipaddr, 0, 0, 0, 0);
	IP4_ADDR(&netmask, 0, 0, 0, 0);

	/* Add netif interface for lpc17xx_8x */


	netif_add(&lpc_netif, &ipaddr, &netmask, &gw, NULL, lpc_enetif_init,  ethernet_input);
	netif_set_default(&lpc_netif);
	netif_set_up(&lpc_netif);


	dhcp_start(&lpc_netif);



	uint8_t fl = 0 ;



	while (1)

	{



		/* Handle packets as part of this loop, not in the IRQ handler */



				lpc_enetif_input(&lpc_netif);



				/* lpc_rx_queue will re-qeueu receive buffers. This normally occurs
				   automatically, but in systems were memory is constrained, pbufs
				   may not always be able to get allocated, so this function can be
				   optionally enabled to re-queue receive buffers. */

		#if 0
				while (lpc_rx_queue(&lpc_netif)) {}
		#endif

				/* Free TX buffers that are done sending */
				lpc_tx_reclaim(&lpc_netif);

				/* LWIP timers - ARP, DHCP, TCP, etc. */
				sys_check_timeouts();

				/* Call the PHY status update state machine once in a while
				   to keep the link status up-to-date */
				physts = lpcPHYStsPoll();

				/* Only check for connection state when the PHY status has changed */

				if (physts & PHY_LINK_CHANGED)
				{
					if (physts & PHY_LINK_CONNECTED)
					{



						prt_ip = 0;

						/* Set interface speed and duplex */
						if (physts & PHY_LINK_SPEED100)
						{
							Chip_ENET_Set100Mbps(LPC_ETHERNET);
							NETIF_INIT_SNMP(&lpc_netif, snmp_ifType_ethernet_csmacd, 100000000);
						}
						else
						{
							Chip_ENET_Set10Mbps(LPC_ETHERNET);
							NETIF_INIT_SNMP(&lpc_netif, snmp_ifType_ethernet_csmacd, 10000000);
						}
						if (physts & PHY_LINK_FULLDUPLX) {
							Chip_ENET_SetFullDuplex(LPC_ETHERNET);
						}
						else {
							Chip_ENET_SetHalfDuplex(LPC_ETHERNET);
						}

						netif_set_link_up(&lpc_netif);
					}
					else
					{



						netif_set_link_down(&lpc_netif);
					}

					DEBUGOUT("Link connect status: %d\r\n", ((physts & PHY_LINK_CONNECTED) != 0));
				}

				/* Print IP address info */

				if (!prt_ip)
				{
					if (lpc_netif.ip_addr.addr)
					{
						static char tmp_buff[16];
						DEBUGOUT("IP_ADDR    : %s\r\n", ipaddr_ntoa_r((const ip_addr_t *) &lpc_netif.ip_addr, tmp_buff, 16));
						DEBUGOUT("NET_MASK   : %s\r\n", ipaddr_ntoa_r((const ip_addr_t *) &lpc_netif.netmask, tmp_buff, 16));
						DEBUGOUT("GATEWAY_IP : %s\r\n", ipaddr_ntoa_r((const ip_addr_t *) &lpc_netif.gw, tmp_buff, 16));
						prt_ip = 1;




						mqttAppInit();

						mqttAppConnect();



						//////   mqttAppDisconnect();


					}
				}

				if(mqttIsConnected()==1)
				{
					mqttAppHandle();


					if (fl == 0)
					{



						mqttAppSubscribe("lpc/#");
						mqttAppSubscribe("lpc/teste");


						fl = 1;

					}

				}








	}



	return 0;
}