unable to read ARP response from board

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

unable to read ARP response from board

samyuktar
Hello,

I am using a CC1352P1 LaunchXL from Texas Instruments, on which I have built
lwIP. I am using a ENC28J60 SPI-Ethernet bridge and have written my own
driver to configure the chip for ethernet and have also written my own
transmit, receive and init functions. I have verified the init and transmit
functions by sending raw ethernet packets between my device and my computer
and am able to sniff the packets in Wireshark. (Note: I manually entered the
computer's mac address and the device's mac address).

Now, I want to get some minimal UDP and IP working. I set my computer's IP
address to something static manually, and set my device's IP - I get my
device to send an gratituous ARP request with it's MAC address.  I can see
this on wireshark - this tells the computer that my device's MAC address is
tied to my device's IP address, so that when I try to ping my device's IP
address from my computer, I can see the ping going to the correct IP and MAC
address.

However, my device does not respond to the ping (and how will it, since it
does not know the MAC address of my computer?) Am I supposed to manually
send an ARP request to the computer requesting the computer's MAC address,
or is it done somewhere in the init functions?

So here's my code so far:



struct netif mynetif;
static ip4_addr_t ip_addr, netmask, gw, dest_ip;

struct pbuf *p;
void* state;

netif_status_callback_fn status_callback;



static void default_netif_add(void)
{
  IP4_ADDR(&gw, 192,168,1,1);
  IP4_ADDR(&ip_addr, 192,168,1,10);
  IP4_ADDR(&netmask, 255,255,255,0);
  IP4_ADDR(&dest_ip, 192,168,1,11);
  /* First add the interface - ethernetif_init is defined in ethernetif.c,
for NO_SYS=0 input function is ethernetif_input */
  /* set this netif as the default */

  netif_set_default(netif_add(&mynetif, &ip_addr, &netmask,
                              &gw, NULL, (netif_init_fn) ethernetif_init,
ethernet_input));
  /* Bring the interface up */
  netif_set_up(&mynetif);

  /* Bring the link up */
  netif_set_link_up(&mynetif);
}

static void create_arp_response(ip4_addr_t *adr)
{
  int k;
  struct eth_hdr *ethhdr;
  struct etharp_hdr *etharphdr;
  struct pbuf *p = pbuf_alloc(PBUF_RAW, sizeof(struct eth_hdr) +
sizeof(struct etharp_hdr), PBUF_RAM);
  if(p == NULL) {
    FAIL_RET();
  }
  ethhdr = (struct eth_hdr*)p->payload;
  etharphdr = (struct etharp_hdr*)(ethhdr + 1);
 
  ethhdr->dest = test_ethaddr_dest;
  ethhdr->src = test_ethaddr_src;
  ethhdr->type = htons(ETHTYPE_ARP);
 
  etharphdr->hwtype = htons(LWIP_IANA_HWTYPE_ETHERNET);
  etharphdr->proto = htons(ETHTYPE_IP);
  etharphdr->hwlen = ETHARP_HWADDR_LEN;
  etharphdr->protolen = sizeof(ip4_addr_t);
  etharphdr->opcode = htons(ARP_REPLY);
 
  SMEMCPY(&etharphdr->sipaddr, adr, sizeof(ip4_addr_t));
  SMEMCPY(&etharphdr->dipaddr, &ip_addr, sizeof(ip4_addr_t));
 
  k = 6;
  while(k > 0) {
    k--;
    /* Write the ARP MAC-Addresses */
    etharphdr->shwaddr.addr[k] = test_ethaddr_src.addr[k];
    etharphdr->dhwaddr.addr[k] = test_ethaddr_dest.addr[k];
    /* Write the Ethernet MAC-Addresses */
    ethhdr->dest.addr[k] = test_ethaddr_dest.addr[k];
    ethhdr->src.addr[k]  = test_ethaddr_src.addr[k];
  }
 
  ethernet_input(p, &mynetif);
}

void minimal_udp_send(void){
        struct udp_pcb *pcb;
        struct pbuf *p;
        unsigned char buffer[8] = "my name";
        err_t err;
        unsigned port = 7;
        unsigned pc_port = 4343;
        uint8_t buflen = 8;
        /* create new UDP PCB structure */
        pcb = udp_new();
        err = udp_bind(pcb, &ip_addr, port);
        err= udp_connect(pcb, &dest_ip, pc_port);

  p = pbuf_alloc(PBUF_TRANSPORT,buflen,PBUF_RAM);
  p->payload = buffer;
       
        udp_send(pcb,p->payload);

}


/*
 *  =============== netstackThread ==============
 *  Add the network interface, ethernet interface
 */
void netstackThread(void *arg0)
{
        struct pbuf *q;
        lwip_init();
        default_netif_add();
        q = pbuf_alloc(PBUF_TRANSPORT,8,PBUF_RAM);  
       
// unsigned char buffer[8] = "my name";
// q->payload = buffer;
// netif_loop_output(&mynetif, q);
        create_arp_response(&ip_addr);
        while(1)
                etharp_query(&mynetif, q, &dest_ip);
// etharp_find_addr(&mynetif, &gw, );
        minimal_udp_send();
}


Here's my Wireshark gratituous ARP sent from my device:

<http://lwip.100.n7.nabble.com/file/t2316/Screen_Shot_2019-11-20_at_5.png>


Here's a response I *once* got from my computer and captured on Wireshark
(but I don't get it now - not sure what I changed: )

<http://lwip.100.n7.nabble.com/file/t2316/Screen_Shot_2019-11-20_at_10.png>

Here's what happens on Wireshark when I ping my device's IP address:

<http://lwip.100.n7.nabble.com/file/t2316/Screen_Shot_2019-11-20_at_6.png>

Please help me out :D






--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users