net: Add capabilities flag to net_if API

The network device driver can specify what kind of functionality
it supports. Currently there exists one flag that can be used
in ethernet devices that tells if ARP should be enabled or not.

Change-Id: Ieaaefcfc7cdd65f44190248f507ac3cb512a323e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2016-05-23 17:26:32 +03:00
commit 667d15de85
2 changed files with 39 additions and 0 deletions

View file

@ -32,6 +32,12 @@
extern "C" {
#endif
/**
* Network device capabilities.
*/
/* The network interface is an ethernet based */
#define NET_CAP_ARP 0x00000001
/**
* @brief Network Interface unicast IP addresses
*
@ -122,6 +128,9 @@ struct net_if {
/** The actualy device driver instance the net_if is related to */
struct device *dev;
/** Interface capabilities */
uint32_t capabilities;
/** The hardware link address */
struct net_linkaddr link_addr;
@ -372,6 +381,7 @@ static inline void net_if_set_gw(struct net_if *iface,
struct net_if_api {
void (*init)(struct net_if *iface);
int (*send)(struct net_if *iface, struct net_buf *buf);
uint32_t (*capabilities)(struct net_if *iface);
};
#define NET_IF_INIT(dev_name, sfx, _mtu) \

View file

@ -50,6 +50,22 @@ static void net_if_tx_fiber(struct net_if *iface)
buf, net_buf_frags_len(buf->frags));
if (api && api->send) {
#if defined(CONFIG_NET_IPV4)
if (iface->capabilities & NET_CAP_ARP) {
buf = net_arp_prepare(buf);
if (!buf) {
/* Packet was discarded */
continue;
}
/* ARP packet will be sent now and the actual
* packet is sent after the ARP reply has been
* received.
*/
}
#endif /* CONFIG_NET_IPV4 */
if (api->send(iface, buf) < 0) {
net_nbuf_unref(buf);
}
@ -467,9 +483,22 @@ int net_if_init(void)
if (api && api->init) {
api->init(iface);
if (api->capabilities) {
iface->capabilities = api->capabilities(iface);
} else {
iface->capabilities = 0;
}
init_tx_queue(iface);
}
#if defined(CONFIG_NET_IPV4)
if (iface->capabilities & NET_CAP_ARP) {
net_arp_init();
}
#endif
#if defined(CONFIG_NET_IPV6)
iface->hop_limit = CONFIG_NET_INITIAL_HOP_LIMIT;
#endif