Beispiel #1
0
void uip_udppoll(struct uip_driver_s *dev, struct uip_udp_conn *conn)
{
  /* Verify that the UDP connection is valid */

  if (conn->lport != 0)
    {
      /* Setup for the application callback */

      dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
      dev->d_snddata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];

      dev->d_len     = 0;
      dev->d_sndlen  = 0;

      /* Perform the application callback */

      uip_udpcallback(dev, conn, UIP_POLL);

      /* If the application has data to send, setup the UDP/IP header */

      if (dev->d_sndlen > 0)
        {
          uip_udpsend(dev, conn);
          return;
        }
    }

  /* Make sure that d_len is zero meaning that there is nothing to be sent */

  dev->d_len   = 0;
}
Beispiel #2
0
int uip_udpinput(FAR struct uip_driver_s *dev)
{
  struct uip_udp_conn  *conn;
  struct uip_udpip_hdr *pbuf = UDPBUF;
  int ret = OK;

#ifdef CONFIG_NET_STATISTICS
  uip_stat.udp.recv++;
#endif

  /* UDP processing is really just a hack. We don't do anything to the UDP/IP
   * headers, but let the UDP application do all the hard work. If the
   * application sets d_sndlen, it has a packet to send.
   */

  dev->d_len    -= UIP_IPUDPH_LEN;
#ifdef CONFIG_NET_UDP_CHECKSUMS
  dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
  if (pbuf->udpchksum != 0 && uip_udpchksum(dev) != 0xffff)
    {
#ifdef CONFIG_NET_STATISTICS
      uip_stat.udp.drop++;
      uip_stat.udp.chkerr++;
#endif
      nlldbg("Bad UDP checksum\n");
      dev->d_len = 0;
    }
  else
#endif
    {
      /* Demultiplex this UDP packet between the UDP "connections". */

      conn = uip_udpactive(pbuf);
      if (conn)
        {
          uint16_t flags;

          /* Set-up for the application callback */

          dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
          dev->d_snddata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
          dev->d_sndlen  = 0;

          /* Perform the application callback */

          flags = uip_udpcallback(dev, conn, UIP_NEWDATA);

          /* If the operation was successful, the UIP_NEWDATA flag is removed
           * and thus the packet can be deleted (OK will be returned).
           */

          if ((flags & UIP_NEWDATA) != 0)
            {
              /* No.. the packet was not processed now.  Return ERROR so
               * that the driver may retry again later.
               */

              ret = ERROR;
            }

          /* If the application has data to send, setup the UDP/IP header */

          if (dev->d_sndlen > 0)
            {
              uip_udpsend(dev, conn);
            }
        }
      else
        {
          nlldbg("No listener on UDP port\n");
          dev->d_len = 0;
        }
    }

  return ret;
}