Hey guys,

I am currently trying to ping the device, after hopefully manage to
initiate it. When analyzing the network packages I can noticed that ARP is
working and my computer know the proper MAC but the embedded platform that
is running lwIP is not answering to the ping. Can you please tell me if
there is an option that I need to activate or a method that I need to call
in my loop to be able to respond to pings?

I attached the lwipopts and ethernetif files in case they might be helpful.

Thank you in advance,
Angel C
#include "lwip_driver.h"
#include "efm32.h"
#include "em_cmu.h"
#include "ksz8851snl_driver.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include <lwip/stats.h>
#include <lwip/snmp.h>
#include <lwip/igmp.h>
#include "netif/etharp.h"
#include "netif/ppp_oe.h"

/** Initialization function that should be passed to netif_add */
err_t  LWIP_driver_init(struct netif *netif)
{
  localNetif = netif;
  
  NETIF_INIT_SNMP(netif,snmp_ifType_ethernet_csmacd, 800);
  
  netif->name[0] = IFNAME0;
  netif->name[1] = IFNAME1;
  
  netif->output = etharp_output;
  netif->linkoutput = LWIP_driver_output;
  
  /** set the HW address length */
  netif->hwaddr_len = ETH_MAC_ADDR_LEN;
  
  /** set the HW address */
  KSZ8851SNL_getMACAddress(netif->hwaddr);

  /** set the maximum transfer unit */
  netif->mtu = 1500;

  /** Set the flags according to device capabilities */
  netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_LINK_UP | NETIF_FLAG_ETHARP ;

  /** initialize the timers */
  timestamp_ETH_ARP = *timestamp_current;
  timestamp_ETH_TCP = *timestamp_current;

  /** initialize the hardware */
  KSZ8851SNL_init();

  return ERR_OK;
}

u32_t sys_now(void)
{
  return *timestamp_current; 
}

/** Called when a raw packet is ready to be transmitted. */
err_t LWIP_driver_output(struct netif *netif, struct pbuf *p)
{
  struct pbuf *q;
#if ETH_PAD_SIZE
  pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif
  for(q = p; q != NULL; q = q->next) {
    KSZ8851SNL_send(p->tot_len, p->payload);
  }
#if ETH_PAD_SIZE
  pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif  
  
  LINK_STATS_INC(link.xmit);
  
  return ERR_OK;
}

/** Called when a packet is received */
static void LWIP_driver_input(struct netif *netif)
{
  struct eth_hdr *ethhdr;
  struct pbuf *p;

 /* move received packet into a new pbuf */
  p = low_level_input(netif);
    
  /** no packet could be read, silently ignore this */
  if (p == NULL) return;
  /* points to packet payload, which starts with an Ethernet header */
  ethhdr = p->payload;

 switch (htons(ethhdr->type)) {
    /* IP or ARP packet? */
    case ETHTYPE_IP:
    case ETHTYPE_ARP:
#if PPPOE_SUPPORT
  /* PPPoE packet? */
  case ETHTYPE_PPPOEDISC:
  case ETHTYPE_PPPOE:
#endif /* PPPOE_SUPPORT */
    /* full packet send to tcpip_thread to process */
      if (netif->input(p, netif)!=ERR_OK)
      { 
         LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
         pbuf_free(p);
         p = NULL;
      }
      break;

  default:
    pbuf_free(p);
    p = NULL;
    break;
  }
}

static struct pbuf *low_level_input(struct netif *netif)
{
  struct pbuf *p;
  u16_t len=netif->mtu;

  /* We allocate a pbuf chain of pbufs from the pool. */  
  p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
  if (p != NULL) 
  {
    KSZ8851SNL_receive(p->payload, &(p->len));
    LINK_STATS_INC(link.recv);
  } else 
  {
    //TODO drop packet();
    LINK_STATS_INC(link.memerr);
    LINK_STATS_INC(link.drop);
  }

  return p;  
}

/** Timestamp capabilities */
void LWIP_driver_timestamp_engine(void)
{
  if (abs(timestamp_ETH_ARP - *timestamp_current) >= LWIP_ETH_ARP_INTERVAL) {
      etharp_tmr();
      timestamp_ETH_ARP = *timestamp_current;
  }
  if (abs(timestamp_ETH_TCP - *timestamp_current) >= LWIP_ETH_TCP_INTERVAL) {
      tcp_tmr();
      timestamp_ETH_TCP = *timestamp_current;
  }
  //TODO implement for the others
  if (abs(timestamp_ETH_TCP - *timestamp_current) >= LWIP_ETH_TCP_INTERVAL) {
      igmp_tmr();
      timestamp_ETH_TCP = *timestamp_current;
  }
  
  
}

/** LWIP main loop */
void LWIP_loop(struct netif *netif, uint32_t *global_timestamp)
{
  timestamp_current=global_timestamp;
  while(1)
  {
    LWIP_driver_timestamp_engine();
    LWIP_driver_input(netif);
  }
}
#ifndef _LWIP_DRIVER_H_
#define _LWIP_DRIVER_H_

#include <stdbool.h>
#include "netif/etharp.h"
#include "lwip/tcp_impl.h"
#include "lwip/mem.h"
#include "lwip/memp.h"

#define ETH_MAC_ADDR_LEN 6 /**< MAC Address length */
#define IFNAME0 'e'
#define IFNAME1 'n'

/** Initialization function that should be passed to netif_add */
err_t  LWIP_driver_init(struct netif *netif);
/** Called when a raw packet is ready to be transmitted. */
err_t LWIP_driver_output(struct netif *netif, struct pbuf *p);
/** Called when a packet is received */
static void LWIP_driver_input(struct netif *netif);
/** LWIP main loop */
void LWIP_loop(struct netif *netif, uint32_t *global_timestamp);
/** Timestamp capabilities */
void  LWIP_driver_timestamp_engine(void);

static struct pbuf *low_level_input(struct netif *netif);
static void ethernetif_input(struct netif *netif);

static uint32_t timestamp_ETH_ARP;
static uint32_t timestamp_ETH_TCP;
static uint32_t *timestamp_current;

static struct netif *localNetif;

#endif //_LWIP_DRIVER_H_
/** This file is created by Energy Micro, based on the reptile/lwip/src/include/lwip/opt.h
*   with the following aspects that need to be taken into account
*   * unnecesarry options have been removed 
*   * details about each option can be found in the original file
*   * default values are to be found in the original file
*/

#ifndef _LWIP_OPTS_H_
#define _LWIP_OPTS_H_

#define NO_SYS                          1
#define SYS_LIGHTWEIGHT_PROT            (!NO_SYS)
#define MEM_ALIGNMENT                   4
#define MEM_SIZE                        32 * 1024

/** Internal memory pool sizes */
#define MEMP_NUM_PBUF                   16
#define MEMP_NUM_NETBUF                 16
#define MEMP_NUM_RAW_PCB                4
#define MEMP_NUM_UDP_PCB                4
#define MEMP_NUM_TCP_PCB                5
#define MEMP_NUM_TCP_PCB_LISTEN         8
#define MEMP_NUM_TCP_SEG                16
#define MEMP_NUM_REASSDATA              5
#define MEMP_NUM_FRAG_PBUF              15
#define MEMP_NUM_ARP_QUEUE              30
#define MEMP_NUM_IGMP_GROUP             8
#define MEMP_NUM_SYS_TIMEOUT            8
#define MEMP_NUM_TCPIP_MSG_API          8
#define MEMP_NUM_TCPIP_MSG_INPKT        8
#define MEMP_NUM_SNMP_NODE              50
#define MEMP_NUM_SNMP_ROOTNODE          30
#define MEMP_NUM_SNMP_VARBIND           2
#define MEMP_NUM_SNMP_VALUE             3
#define MEMP_NUM_NETDB                  1
#define MEMP_NUM_LOCALHOSTLIST          1
#define MEMP_NUM_PPPOE_INTERFACES       1
#define PBUF_POOL_SIZE                  16

/** ARP options */
#define ETH_PAD_SIZE                    2
#define LWIP_ARP                        1
#if LWIP_ARP == 1
#define ARP_TABLE_SIZE                  30
#define ARP_QUEUEING                    1       
#define ETHARP_TRUST_IP_MAC             0
#define ETHARP_SUPPORT_VLAN             0
#define LWIP_ETH_ARP_INTERVAL           2000 /**< ARP timer interval in miliseconds */
#endif

/** IP options */
#define IP_FORWARD                      1
#define IP_OPTIONS_ALLOWED              1
#define IP_REASSEMBLY                   0
#define IP_FRAG                         0
#define IP_DEFAULT_TTL                  255

/** ICMP options */
#define LWIP_ICMP                       1
#define LWIP_BROADCAST_PING             1
#define LWIP_MULTICAST_PING             1

/** RAW options */
#define LWIP_RAW                        1

/** DHCP options */
#define LWIP_DHCP                       0

/** AUTOIP options */
#define LWIP_AUTOIP                     1
#define LWIP_DHCP_AUTOIP_COOP           0

/** SNMP options */
#define LWIP_SNMP                       1

/** IGMP options */
#define LWIP_IGMP                       1

/** DNS options */
#define LWIP_DNS                        0

/** UDP options */
#define LWIP_UDP                        1
#define LWIP_UDPLITE                    0
#define LWIP_NETBUF_RECVINFO            0

/** TCP options */
#define LWIP_TCP                        1
#if LWIP_TCP
#define LWIP_TCP_TIMESTAMPS             0
#define TCP_WND                         8192
#define TCP_MAXRTX                      10
#define TCP_SYNMAXRTX                   3
#define TCP_QUEUE_OOSEQ                 1
#define TCP_MSS                         1460
#define TCP_SND_BUF                     (8 * TCP_MSS)
#define TCP_SND_QUEUELEN                (2 * TCP_SND_BUF/TCP_MSS)
#define TCP_SNDLOWAT                    (TCP_SND_BUF/2)
#define TCP_LISTEN_BACKLOG              1
#define LWIP_ETH_TCP_INTERVAL 2000 /**< TCP timer interval in miliseconds */
#endif //LWIP TCP

/** Pbuf options */
#define PBUF_POOL_BUFSIZE               1520		// + sizeof(pbuf) = 1536 = 12 cache lines of 128 bytes
#define PBUF_LINK_HLEN                  (14 + ETH_PAD_SIZE)

/** Network Interfaces options */
#define LWIP_NETIF_HOSTNAME             1
#define LWIP_NETIF_API                  (!NO_SYS)
#define LWIP_NETIF_HWADDRHINT           1
#define LWIP_NETIF_LOOPBACK             1
#define LWIP_NETIF_LINK_CALLBACK        1

/** LOOPIF options */
#define LWIP_HAVE_LOOPIF                0

/** Thread options */
#define TCPIP_MBOX_SIZE                 32
#define DEFAULT_UDP_RECVMBOX_SIZE       32
#define DEFAULT_TCP_RECVMBOX_SIZE       32
#define DEFAULT_ACCEPTMBOX_SIZE         4

/** thread priorities are in VDK terms - 1 is highest, 30 is lowest */
#define TCPIP_THREAD_PRIO               5
#define DEFAULT_THREAD_PRIO             10
#define LOW_THREAD_PRIO                 29

/** Sequential layer options */
#define LWIP_NETCONN                    (!NO_SYS)

/** Socket options */
#define LWIP_SOCKET                     (!NO_SYS)
#define LWIP_COMPAT_SOCKETS             1
#define LWIP_TCP_KEEPALIVE              1
#define LWIP_SO_RCVTIMEO                1
#define LWIP_SO_RCVBUF                  0
#define SO_REUSE                        1
#define SO_REUSE_RXTOALL                1

/** Statistics options */
#define LWIP_STATS                      1
#define LWIP_STATS_LARGE                1
#if LWIP_STATS
#define LINK_STATS                      1
#define IP_STATS                        1
#define IPFRAG_STATS                    1
#define ICMP_STATS                      1
#define IGMP_STATS                      1
#define UDP_STATS                       1
#define TCP_STATS                       1
#define MEM_STATS                       1
#define MEMP_STAT                       1
#define SYS_STATS                       1
#define LWIP_STATS_DISPLAY              1
#endif /* STATS */
#define LWIP_PROVIDE_ERRNO              1

/** Debugging options */
#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_ALL
#define LWIP_DEBUG 1
#define LWIP_DBG_TYPES_ON               LWIP_DBG_STATE
#define ETHARP_DEBUG                    LWIP_DBG_ON
#define NETIF_DEBUG                     LWIP_DBG_ON
#define PBUF_DEBUG                      LWIP_DBG_ON
#define API_LIB_DEBUG                   LWIP_DBG_ON
#define API_MSG_DEBUG                   LWIP_DBG_ON
#define SOCKETS_DEBUG                   LWIP_DBG_ON
#define ICMP_DEBUG                      LWIP_DBG_ON
#define IGMP_DEBUG                      LWIP_DBG_ON
#define INET_DEBUG                      LWIP_DBG_ON
#define IP_DEBUG                        LWIP_DBG_ON
#define IP_REASS_DEBUG                  LWIP_DBG_ON
#define RAW_DEBUG                       LWIP_DBG_ON
#define MEM_DEBUG                       LWIP_DBG_ON
#define MEMP_DEBUG                      LWIP_DBG_ON
#define SYS_DEBUG                       LWIP_DBG_ON
#define TIMERS_DEBUG                    LWIP_DBG_ON
#define TCP_DEBUG                       LWIP_DBG_ON
#define TCP_INPUT_DEBUG                 LWIP_DBG_ON
#define TCP_FR_DEBUG                    LWIP_DBG_ON
#define TCP_RTO_DEBUG                   LWIP_DBG_ON
#define TCP_CWND_DEBUG                  LWIP_DBG_ON
#define TCP_WND_DEBUG                   LWIP_DBG_ON
#define TCP_OUTPUT_DEBUG                LWIP_DBG_ON
#define TCP_RST_DEBUG                   LWIP_DBG_ON
#define TCP_QLEN_DEBUG                  LWIP_DBG_ON
#define UDP_DEBUG                       LWIP_DBG_ON
#define TCPIP_DEBUG                     LWIP_DBG_ON
#define PPP_DEBUG                       LWIP_DBG_ON
#define SLIP_DEBUG                      LWIP_DBG_ON
#define DHCP_DEBUG                      LWIP_DBG_ON
#define AUTOIP_DEBUG                    LWIP_DBG_ON
#define SNMP_MSG_DEBUG                  LWIP_DBG_ON
#define SNMP_MIB_DEBUG                  LWIP_DBG_ON
#define DNS_DEBUG                       LWIP_DBG_ON


#endif // _LWIP_OPTS_H_
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to