lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] problem configuring two Ethernet ports


From: rocco brandi
Subject: [lwip-users] problem configuring two Ethernet ports
Date: Wed, 22 Jun 2011 10:58:11 +0100 (BST)

hi everyone!
 
i'm trying to configure a microcontroller that have two ethernet ports.
so, i create two netif, assign to each one different IP address and different MAC address, the same input functions and the two different version of the same output function (the difference is only in the port number). here is the code:
 
struct netif netif0;
struct netif netif1;
 
int InitPhy( void );
int InitMac( void );

err_t myif_link_output0(struct netif *netif, struct pbuf *p);
err_t myif_link_output1(struct netif *netif, struct pbuf *p);
 
static struct ip_addr ipaddr0, netmask0, gw0,ipaddr1, netmask1, gw1;
 
IP4_ADDR(&gw0, 192,168,1,240);
 IP4_ADDR(&ipaddr0, 192,168,0,141);
 IP4_ADDR(&netmask0, 255,255,255,0);
 
 IP4_ADDR(&gw1, 192,168,1,240);
 IP4_ADDR(&ipaddr1, 192,168,0,140);
 IP4_ADDR(&netmask1, 255,255,255,0); 
 
  lwip_init();
 httpd_init(); 
 
 netif_add(&netif0, &ipaddr0, &netmask0, &gw0, NULL, low_level_init0, ethernet_input);
 netif_add(&netif1, &ipaddr1, &netmask1, &gw1, NULL, low_level_init1, ethernet_input);
       
 netif1.linkoutput = myif_link_output1;
 netif1.output = etharp_output;
    netif_set_default(&netif1);          
 netif_set_up(&netif1); 
 
 netif0.linkoutput = myif_link_output0;
 netif0.output = etharp_output;
    netif_set_default(&netif0);        
 netif_set_up(&netif0);
 
 where the low_level_init and myif_link_output functions are the followers:
 
err_t
myif_link_output0(struct netif *netif, struct pbuf *p){
 ETHERNET_FRAME_T* ptFrame;
 void* hFrame;
 unsigned int uPortNo = 0;
 if( ETH_OKAY == EthStdMac_GetFrame(uPortNo, &ptFrame, &hFrame) )
 {
    memcpy( ptFrame, p->payload, p->len );
    
    EthStdMac_Send( uPortNo, hFrame, max(60, p->len ), 0 );
 }
 return ERR_OK;
}

err_t
myif_link_output1(struct netif *netif, struct pbuf *p){
 ETHERNET_FRAME_T* ptFrame;
 void* hFrame;
 unsigned int uPortNo=1;
 
 if( ETH_OKAY == EthStdMac_GetFrame(uPortNo, &ptFrame, &hFrame) )
 {
          memcpy( ptFrame, p->payload, p->len );
    
  EthStdMac_Send( uPortNo, hFrame, max(60, p->len ), 0 );
 }
 return ERR_OK;
}

err_t
low_level_init0(struct netif *netif)
{
 
  /* set MAC hardware address length */
  netif->hwaddr_len = ETHARP_HWADDR_LEN;
  /* set MAC hardware address */
        netif->hwaddr[0] = 0x00;
        netif->hwaddr[1] = 0xb2;
        netif->hwaddr[2] = 0x23;
        netif->hwaddr[3] = 0x34;
        netif->hwaddr[4] = 0x45;
        netif->hwaddr[5] = 0x00;
  
  /* maximum transfer unit */
  netif->mtu = 1500;
 
  /* 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;
 
  /* Do whatever else is needed to initialize interface. */ 
  return ERR_OK;
}

err_t
low_level_init1(struct netif *netif)
{
 
  /* set MAC hardware address length */
  netif->hwaddr_len = ETHARP_HWADDR_LEN;
  /* set MAC hardware address */
        netif->hwaddr[0] = 0x00;
        netif->hwaddr[1] = 0xb4;
        netif->hwaddr[2] = 0x43;
        netif->hwaddr[3] = 0x32;
        netif->hwaddr[4] = 0x21;
        netif->hwaddr[5] = 0x00;
  
  /* maximum transfer unit */
  netif->mtu = 1500;
 
  /* 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;
 
  /* Do whatever else is needed to initialize interface. */ 
  return ERR_OK;
}
 
 
so, what happens? when I ask for a ping, both ports work properly.
but if I want, for example, send the demo web page of lwip (digiting on a web browser one of the two IP address) the behaviour depends on the order of neti_add instructions:
 
in this order
 
 netif_add(&netif0, &ipaddr0, &netmask0, &gw0, NULL, low_level_init0, ethernet_input);
 netif_add(&netif1, &ipaddr1, &netmask1, &gw1, NULL, low_level_init1, ethernet_input);
the port1 (IP address 192.168.0.140) works properly, I can see the web page but the port0 (IP address 192.168.141) don't answer to the TCP handshake (seen through wireshark);
 
but if I exchange the instructions
 
netif_add(&netif1, &ipaddr1, &netmask1, &gw1, NULL, low_level_init1, ethernet_input);
netif_add(&netif0, &ipaddr0, &netmask0, &gw0, NULL, low_level_init0, ethernet_input);
now the port0 works properly and the port1 don't answer the handshake!!!!
 
how is it possible? how can I fix it?
 
thanks a lot! ^_^
 
Rocco

reply via email to

[Prev in Thread] Current Thread [Next in Thread]