void netdev_txnotify(const uip_ipaddr_t *raddr)
{
  /* Find the device driver that serves the subnet of the remote address */

  struct uip_driver_s *dev = netdev_findbyaddr(raddr);

  /* The above lookup will fail if the packet is being sent out of our
   * out subnet to a router.  REVISIT:  For now, we fall back and try "eth0".
   */ 

  if (dev == NULL)
    {
      /* If the destination address is not in our subnet, assume eth0 as the
       * default device.
       */

      dev = netdev_findbyname("eth0");
    }

  if (dev && dev->d_txavail)
    {
      /* Notify the device driver that new TX data is available. */

      (void)dev->d_txavail(dev);
    }
}
Ejemplo n.º 2
0
static FAR struct net_driver_s *netdev_ifrdev(FAR struct ifreq *req)
{
  if (!req)
    {
      return NULL;
    }

  /* Find the network device associated with the device name
   * in the request data.
   */

  return netdev_findbyname(req->ifr_name);
}
Ejemplo n.º 3
0
static FAR struct net_driver_s *netdev_imsfdev(FAR struct ip_msfilter *imsf)
{
  if (!imsf)
    {
      return NULL;
    }

  /* Find the network device associated with the device name
   * in the request data.
   */

  return netdev_findbyname(imsf->imsf_name);
}
Ejemplo n.º 4
0
unsigned int netdev_nametoindex(FAR const char *ifname)
{
  FAR struct net_driver_s *dev;
  unsigned int ifindex = -ENODEV;

  /* Find the driver with this name */

  net_lock();
  dev = netdev_findbyname(ifname);
  if (dev != NULL)
    {
      ifindex = dev->d_ifindex;
    }

  net_unlock();
  return ifindex;
}
Ejemplo n.º 5
0
static int netdev_imsfioctl(FAR struct socket *psock, int cmd, struct ip_msfilter *imsf)
{
  FAR struct uip_driver_s *dev;
  int ret = OK;

  nvdbg("cmd: %d\n", cmd);

  /* Find the network device associated with the device name
   * in the request data.
   */

  dev = netdev_findbyname(imsf->imsf_name);
  if (!dev)
    {
      ret = -EINVAL;
      goto errout;
    }

  /* Execute the command */

  switch (cmd)
    {
      case SIOCSIPMSFILTER:  /* Set source filter content */
        {
          if (imsf->imsf_fmode == MCAST_INCLUDE)
            {
              ret = igmp_joingroup(dev, &imsf->imsf_multiaddr);
            }
          else
            {
              DEBUGASSERT(imsf->imsf_fmode == MCAST_EXCLUDE);
              ret = igmp_leavegroup(dev, &imsf->imsf_multiaddr);
            }
        }
        break;

      case SIOCGIPMSFILTER:  /* Retrieve source filter addresses */
      default:
        ret = -EINVAL;
        break;
    }

errout:
  return ret;
}
Ejemplo n.º 6
0
static int netdev_bluetooth_ioctl(FAR struct socket *psock, int cmd,
                                  unsigned long arg)
{
  FAR struct net_driver_s *dev;
  FAR char *ifname;
  int ret = -EINVAL;

  if (arg != 0ul)
    {
      if (WL_IBLUETOOTHCMD(cmd))
        {
          /* Get the name of the Bluetooth device to receive the IOCTL
           * command
           */

          FAR struct btreq_s *btreq =
            (FAR struct btreq_s *)((uintptr_t)arg);

          ifname = btreq->btr_name;
        }
      else
        {
          /* Not a Bluetooth IOCTL command */

          return -ENOTTY;
        }

      /* Find the device with this name */

      dev = netdev_findbyname(ifname);
      ret = -ENODEV;

      if (dev != NULL && dev->d_lltype == NET_LL_BLUETOOTH)
        {
          /* Perform the device IOCTL */

          ret = dev->d_ioctl(dev, cmd, arg);
        }
    }

  return ret;
}
Ejemplo n.º 7
0
static int netdev_pktradio_ioctl(FAR struct socket *psock, int cmd,
                                 unsigned long arg)
{
  FAR struct net_driver_s *dev;
  FAR char *ifname;
  int ret = -ENOTTY;

  if (arg != 0ul)
    {
      if (WL_ISPKTRADIOCMD(cmd))
        {
          /* Get the packet radio device to receive the radio IOCTL
           * command
           */

          FAR struct pktradio_ifreq_s *cmddata =
            (FAR struct pktradio_ifreq_s *)((uintptr_t)arg);

          ifname = cmddata->pifr_name;
        }
      else
        {
          /* Not a packet radio IOCTL command */

          nwarn("WARNING: Not a packet radio IOCTL command: %d\n", cmd);
          return -ENOTTY;
        }

      /* Find the device with this name */

      dev = netdev_findbyname(ifname);
      if (dev != NULL && dev->d_lltype == NET_LL_PKTRADIO)
        {
          /* Perform the device IOCTL */

          ret = dev->d_ioctl(dev, cmd, arg);
        }
    }

  return ret;
}
Ejemplo n.º 8
0
static int netdev_iee802154_ioctl(FAR struct socket *psock, int cmd,
                                  unsigned long arg)
{
  FAR struct net_driver_s *dev;
  FAR char *ifname;
  int ret = -ENOTTY;

  if (arg != 0ul)
    {
      if (_MAC802154IOCVALID(cmd))
        {
          /* Get the IEEE802.15.4 MAC device to receive the radio IOCTL
           * command
           */

          FAR struct ieee802154_netmac_s *netmac =
            (FAR struct ieee802154_netmac_s *)((uintptr_t)arg);

          ifname = netmac->ifr_name;
        }
      else
        {
          /* Not an EEE802.15.4 MAC IOCTL command */

          return -ENOTTY;
        }

      /* Find the device with this name */

      dev = netdev_findbyname(ifname);
      if (dev != NULL && dev->d_lltype == NET_LL_IEEE802154)
        {
          /* Perform the device IOCTL */

          ret = dev->d_ioctl(dev, cmd, arg);
        }
    }

  return ret;
}
Ejemplo n.º 9
0
static int netdev_wifr_ioctl(FAR struct socket *psock, int cmd,
                             FAR struct iwreq *req)
{
  FAR struct net_driver_s *dev;
  int ret = -ENOTTY;

  /* Verify that this is a valid wireless network IOCTL command */

  if (_WLIOCVALID(cmd) && (unsigned)_IOC_NR(cmd) <= WL_NNETCMDS)
    {
      /* Get the wireless device associated with the IOCTL command */

      dev = netdev_findbyname(req->ifr_name);
      if (dev != NULL)
        {
          /* Just forward the IOCTL to the wireless driver */

          ret = dev->d_ioctl(dev, cmd, ((unsigned long)(uintptr_t)req));
        }
    }

  return ret;
}
Ejemplo n.º 10
0
static int netdev_ifrioctl(FAR struct socket *psock, int cmd, struct ifreq *req)
{
  FAR struct uip_driver_s *dev;
  int ret = OK;

  nvdbg("cmd: %d\n", cmd);

  /* Find the network device associated with the device name
   * in the request data.
   */

  dev = netdev_findbyname(req->ifr_name);
  if (!dev)
    {
      ret = -EINVAL;
      goto errout;
    }

  /* Execute the command */

  switch (cmd)
    {
      case SIOCGIFADDR:  /* Get IP address */
        {
          ioctl_getipaddr(&req->ifr_addr, &dev->d_ipaddr);
        }
        break;

      case SIOCSIFADDR:  /* Set IP address */
        {
          ioctl_ifdown(dev);
          ioctl_setipaddr(&dev->d_ipaddr, &req->ifr_addr);
          ioctl_ifup(dev);
        }
        break;

      case SIOCGIFDSTADDR:  /* Get P-to-P address */
        {
          ioctl_getipaddr(&req->ifr_dstaddr, &dev->d_draddr);
        }
        break;

      case SIOCSIFDSTADDR:  /* Set P-to-P address */
        {
          ioctl_setipaddr(&dev->d_draddr, &req->ifr_dstaddr);
        }
        break;

      case SIOCGIFNETMASK:  /* Get network mask */
        {
          ioctl_getipaddr(&req->ifr_addr, &dev->d_netmask);
        }
        break;

      case SIOCSIFNETMASK:  /* Set network mask */
        {
          ioctl_setipaddr(&dev->d_netmask, &req->ifr_addr);
        }
        break;

      case SIOCGIFMTU:  /* Get MTU size */
        {
          req->ifr_mtu = CONFIG_NET_BUFSIZE;
        }
        break;

      case SIOCSIFFLAGS:  /* Sets the interface flags */
        {
          /* Is this a request to bring the interface up? */

          if (req->ifr_flags & IF_FLAG_IFUP)
            {
              /* Yes.. bring the interface up */

              ioctl_ifup(dev);
            }

          /* Is this a request to take the interface down? */

          else if (req->ifr_flags & IF_FLAG_IFDOWN)
            {
              /* Yes.. take the interface down */

              ioctl_ifdown(dev);
            }
        }
        break;

      case SIOCGIFFLAGS:  /* Gets the interface flags */
        {
          req->ifr_flags = 0;

          /* Is the interface running? */

          if (dev->d_flags & IFF_RUNNING)
            {
              /* Yes.. report interface up */

              req->ifr_flags |= IF_FLAG_IFUP;
            }
          else
            {
              /* No.. report interface down */

              req->ifr_flags |= IF_FLAG_IFDOWN;
            }
        }
        break;

      /* MAC address operations only make sense if Ethernet is supported */

#ifdef CONFIG_NET_ETHERNET
      case SIOCGIFHWADDR:  /* Get hardware address */
        {
          req->ifr_hwaddr.sa_family = AF_INETX;
          memcpy(req->ifr_hwaddr.sa_data, dev->d_mac.ether_addr_octet, IFHWADDRLEN);
        }
        break;

      case SIOCSIFHWADDR:  /* Set hardware address -- will not take effect until ifup */
        {
          req->ifr_hwaddr.sa_family = AF_INETX;
          memcpy(dev->d_mac.ether_addr_octet, req->ifr_hwaddr.sa_data, IFHWADDRLEN);
        }
        break;
#endif

      case SIOCDIFADDR:  /* Delete IP address */
        {
          ioctl_ifdown(dev);
          memset(&dev->d_ipaddr, 0, sizeof(uip_ipaddr_t));
        }
        break;

      case SIOCGIFCOUNT:  /* Get number of devices */
        {
          req->ifr_count = netdev_count();
          ret = -ENOSYS;
        }
        break;

      case SIOCGIFBRDADDR:  /* Get broadcast IP address */
      case SIOCSIFBRDADDR:  /* Set broadcast IP address */
        {
          ret = -ENOSYS;
        }
        break;

#ifdef CONFIG_NET_ARPIOCTLS
      case SIOCSARP:  /* Set a ARP mapping */
      case SIOCDARP:  /* Delete an ARP mapping */
      case SIOCGARP:  /* Get an ARP mapping */
# error "IOCTL Commands not implemented"
#endif

      default:
        {
          ret = -EINVAL;
        }
        break;;
    }

errout:
  return ret;
}
Ejemplo n.º 11
0
FAR struct net_driver_s *pkt_find_device(FAR struct pkt_conn_s *conn)
{
  /* REVISIT:  This is bogus.  A better network device lookup is needed. */

  return netdev_findbyname("eth0");
}