2007-09-17 00:12:04 +02:00
|
|
|
/****************************************************************************
|
2014-06-27 18:00:28 +02:00
|
|
|
* net/netdev/netdev.h
|
2007-09-17 00:12:04 +02:00
|
|
|
*
|
2015-05-31 16:34:03 +02:00
|
|
|
* Copyright (C) 2014-2015 Gregory Nutt. All rights reserved.
|
2012-09-13 20:32:24 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-09-17 00:12:04 +02:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-27 18:00:28 +02:00
|
|
|
#ifndef __NET_NETDEV_NETDEV_H
|
|
|
|
#define __NET_NETDEV_NETDEV_H
|
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2014-06-27 18:00:28 +02:00
|
|
|
#include <sys/types.h>
|
2015-05-29 19:01:03 +02:00
|
|
|
#include <stdbool.h>
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2014-07-05 03:13:08 +02:00
|
|
|
#include <nuttx/net/ip.h>
|
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-27 18:00:28 +02:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2014-06-27 18:00:28 +02:00
|
|
|
#if CONFIG_NSOCKET_DESCRIPTORS > 0
|
2015-05-31 16:34:03 +02:00
|
|
|
/* List of registered Ethernet device drivers. You must have the network
|
|
|
|
* locked in order to access this list.
|
|
|
|
*
|
|
|
|
* NOTE that this duplicates a declaration in net/tcp/tcp.h
|
2015-05-30 17:12:27 +02:00
|
|
|
*/
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
EXTERN struct net_driver_s *g_netdevices;
|
2014-06-27 18:00:28 +02:00
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2017-07-01 16:39:39 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Callback from netdev_foreach() */
|
|
|
|
|
|
|
|
struct net_driver_s; /* Forward reference */
|
|
|
|
typedef int (*netdev_callback_t)(FAR struct net_driver_s *dev, FAR void *arg);
|
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
/****************************************************************************
|
2014-06-27 18:00:28 +02:00
|
|
|
* Public Function Prototypes
|
2007-09-17 00:12:04 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2015-05-27 22:34:15 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_ifup / netdev_ifdown
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Bring the interface up/down
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2015-02-03 22:40:56 +01:00
|
|
|
|
|
|
|
void netdev_ifup(FAR struct net_driver_s *dev);
|
|
|
|
void netdev_ifdown(FAR struct net_driver_s *dev);
|
|
|
|
|
2015-05-29 19:01:03 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: netdev_verify
|
2015-05-29 19:01:03 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Verify that the specified device still exists
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The caller has locked the network.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
bool netdev_verify(FAR struct net_driver_s *dev);
|
|
|
|
|
2015-05-27 22:34:15 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: netdev_findbyname
|
2015-05-27 22:34:15 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Find a previously registered network device using its assigned
|
|
|
|
* network interface name
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2015-05-27 22:34:15 +02:00
|
|
|
* ifname The interface name of the device of interest
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Pointer to driver on success; null on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2014-06-27 18:00:28 +02:00
|
|
|
|
|
|
|
#if CONFIG_NSOCKET_DESCRIPTORS > 0
|
2014-06-28 00:48:12 +02:00
|
|
|
FAR struct net_driver_s *netdev_findbyname(FAR const char *ifname);
|
2014-06-27 18:00:28 +02:00
|
|
|
#endif
|
|
|
|
|
2017-07-01 16:39:39 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_foreach
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Enumerate each registered network device.
|
|
|
|
*
|
|
|
|
* NOTE: netdev semaphore held throughout enumeration.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-07-01 16:39:39 +02:00
|
|
|
* callback - Will be called for each registered device
|
|
|
|
* arg - User argument passed to callback()
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0:Enumeration completed 1:Enumeration terminated early by callback
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int netdev_foreach(netdev_callback_t callback, FAR void *arg);
|
|
|
|
|
2015-05-27 22:34:15 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: netdev_findby_ipv4addr
|
2015-05-27 22:34:15 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Find a previously registered network device by matching an arbitrary
|
|
|
|
* IPv4 address.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-08-08 22:24:12 +02:00
|
|
|
* lipaddr - Local, bound address of a connection.
|
2015-05-27 22:34:15 +02:00
|
|
|
* ripaddr - Remote address of a connection to use in the lookup
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Pointer to driver on success; null on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2014-06-27 18:00:28 +02:00
|
|
|
|
|
|
|
#if CONFIG_NSOCKET_DESCRIPTORS > 0
|
2015-01-16 15:51:18 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
FAR struct net_driver_s *netdev_findby_ipv4addr(in_addr_t lipaddr,
|
|
|
|
in_addr_t ripaddr);
|
|
|
|
#endif
|
|
|
|
|
2015-05-27 22:34:15 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: netdev_findby_ipv6addr
|
2015-05-27 22:34:15 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Find a previously registered network device by matching an arbitrary
|
|
|
|
* IPv6 address.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-08-08 22:24:12 +02:00
|
|
|
* lipaddr - Local, bound address of a connection.
|
2015-05-27 22:34:15 +02:00
|
|
|
* ripaddr - Remote address of a connection to use in the lookup
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Pointer to driver on success; null on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-16 15:51:18 +01:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
FAR struct net_driver_s *netdev_findby_ipv6addr(const net_ipv6addr_t lipaddr,
|
|
|
|
const net_ipv6addr_t ripaddr);
|
2014-11-23 18:00:22 +01:00
|
|
|
#endif
|
2014-06-27 18:00:28 +02:00
|
|
|
#endif
|
|
|
|
|
2015-11-27 23:39:14 +01:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: netdev_findbyindex
|
2015-11-27 23:39:14 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Find a previously registered network device by its position in the
|
|
|
|
* list of registered devices. NOTE that this function is not a safe way
|
|
|
|
* to enumerate network devices: There could be changes to the list of
|
|
|
|
* registered device causing a given index to be meaningless (unless, of
|
|
|
|
* course, the caller keeps the network locked).
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2015-11-27 23:39:14 +01:00
|
|
|
* index - the index of the interface to file
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Pointer to driver on success; NULL on failure. This function can only
|
|
|
|
* fail if there are fewer registered interfaces than could be indexed.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR struct net_driver_s *netdev_findbyindex(int index);
|
|
|
|
|
2015-05-27 22:34:15 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: netdev_default
|
2015-05-27 22:34:15 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the default network device. REVISIT: At present this function
|
|
|
|
* arbitrarily returns the first UP device at the head of the device
|
|
|
|
* list. Perhaps the default device should be a device name
|
|
|
|
* configuration option?
|
|
|
|
*
|
|
|
|
* So why is this here: It represents my current though for what to do
|
|
|
|
* if a socket is connected with INADDY_ANY. In this case, I suppose we
|
|
|
|
* should use the IP address associated with some default device???
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2015-05-27 22:34:15 +02:00
|
|
|
* NULL
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Pointer to default network driver on success; null on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2014-11-21 21:14:39 +01:00
|
|
|
|
|
|
|
#if CONFIG_NSOCKET_DESCRIPTORS > 0
|
|
|
|
FAR struct net_driver_s *netdev_default(void);
|
|
|
|
#endif
|
|
|
|
|
2015-05-27 22:34:15 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: netdev_ipv4_txnotify
|
2015-05-27 22:34:15 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Notify the device driver that forwards the IPv4 address that new TX
|
|
|
|
* data is available.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2015-05-27 22:34:15 +02:00
|
|
|
* lipaddr - The local address bound to the socket
|
|
|
|
* ripaddr - The remote address to send the data
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2014-06-27 18:00:28 +02:00
|
|
|
|
|
|
|
#if CONFIG_NSOCKET_DESCRIPTORS > 0
|
2015-01-16 19:30:18 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
void netdev_ipv4_txnotify(in_addr_t lipaddr, in_addr_t ripaddr);
|
|
|
|
#endif /* CONFIG_NET_IPv4 */
|
|
|
|
|
2015-05-27 22:34:15 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: netdev_ipv6_txnotify
|
2015-05-27 22:34:15 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Notify the device driver that forwards the IPv4 address that new TX
|
|
|
|
* data is available.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2015-05-27 22:34:15 +02:00
|
|
|
* lipaddr - The local address bound to the socket
|
|
|
|
* ripaddr - The remote address to send the data
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-16 19:30:18 +01:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
void netdev_ipv6_txnotify(FAR const net_ipv6addr_t lipaddr,
|
|
|
|
FAR const net_ipv6addr_t ripaddr);
|
|
|
|
#endif /* CONFIG_NET_IPv6 */
|
|
|
|
#endif /* CONFIG_NSOCKET_DESCRIPTORS > 0 */
|
2014-06-27 18:00:28 +02:00
|
|
|
|
2015-05-27 22:34:15 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: netdev_txnotify_dev
|
2015-05-27 22:34:15 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Notify the device driver that new TX data is available. This variant
|
|
|
|
* would be called when the upper level logic already understands how the
|
|
|
|
* packet will be routed.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2015-05-27 22:34:15 +02:00
|
|
|
* dev - The network device driver state structure.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-05-27 19:39:44 +02:00
|
|
|
void netdev_txnotify_dev(FAR struct net_driver_s *dev);
|
|
|
|
|
2015-05-27 22:34:15 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: netdev_count
|
2015-05-27 22:34:15 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the number of network devices
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2015-05-27 22:34:15 +02:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The number of network devices
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2014-06-27 18:00:28 +02:00
|
|
|
|
|
|
|
#if CONFIG_NSOCKET_DESCRIPTORS > 0
|
|
|
|
int netdev_count(void);
|
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2017-09-19 22:17:05 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_ipv4_ifconf
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the IPv4 configuration of each network adaptor
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-09-19 22:17:05 +02:00
|
|
|
* ifc - A reference to the instance of struct ifconf in which to return
|
|
|
|
* the information.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero is returned on success; a negated errno value is returned on any
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The nework is locked
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
struct ifconf; /* Forward reference */
|
|
|
|
int netdev_ipv4_ifconf(FAR struct ifconf *ifc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_ipv6_ifconf
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the IPv6 configuration of each network adaptor
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-09-19 22:17:05 +02:00
|
|
|
* lifc - A reference to the instance of struct lifconf in which to return
|
|
|
|
* the information.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero is returned on success; a negated errno value is returned on any
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The nework is locked
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
struct lifconf; /* Forward reference */
|
|
|
|
int netdev_ipv6_ifconf(FAR struct lifconf *lifc);
|
|
|
|
#endif
|
|
|
|
|
2017-07-07 14:51:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_dev_lladdrsize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Returns the size of the MAC address associated with a network device.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-08-09 00:27:23 +02:00
|
|
|
* dev - A reference to the device of interest
|
2017-07-07 14:51:52 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The size of the MAC address associated with this device
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-08-09 00:27:23 +02:00
|
|
|
int netdev_dev_lladdrsize(FAR struct net_driver_s *dev);
|
2017-07-07 03:37:01 +02:00
|
|
|
|
2014-06-27 18:00:28 +02:00
|
|
|
#undef EXTERN
|
|
|
|
#ifdef __cplusplus
|
2007-09-17 00:12:04 +02:00
|
|
|
}
|
2014-06-27 18:00:28 +02:00
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2014-06-27 18:00:28 +02:00
|
|
|
#endif /* __NET_NETDEV_NETDEV_H */
|