diff --git a/Documentation/components/drivers/special/net/vlan.rst b/Documentation/components/drivers/special/net/vlan.rst index 186f6d27091b2..064dc07a939ed 100644 --- a/Documentation/components/drivers/special/net/vlan.rst +++ b/Documentation/components/drivers/special/net/vlan.rst @@ -13,5 +13,81 @@ Vlan Device Drivers - Supporting ADD_VLAN_CMD and DEL_VLAN_CMD of SIOCSIFVLAN. - We add default PCP because some of our apps may not want to set PCP manually +- ``include/nuttx/net/ethernet.h``. Some definitions for 802.1Q VLAN + + .. code-block:: c + + #define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */ + #define VLAN_PRIO_SHIFT 13 + #define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator / Drop Eligible Indicator */ + #define VLAN_VID_MASK 0x0fff /* VLAN Identifier */ + #define VLAN_N_VID 4096 - **Driver**: ``drivers/net/vlan.c`` + +Configuration Options +===================== + +``CONFIG_NET_VLAN`` + Enable 802.1Q VLAN interface support. +``CONFIG_NET_VLAN_COUNT`` + Maximum number of VLAN interfaces per physical Ethernet interface. + +Usage +===== + +.. code-block:: c + + #include + #include "netutils/netlib.h" + + /* Create a VLAN interface (eth0.100, VLAN ID 100) */ + + FAR const char *ifname = "eth0"; + uint16_t vlanid = 100; + uint8_t priority = 0; /* Default PCP */ + + int sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL); + + if (sockfd >= 0) + { + struct vlan_ioctl_args ifv; + + strncpy(ifv.vlan_devname, ifname, sizeof(ifv.device1)); + ifv.u.VID = vlanid; + ifv.vlan_qos = priority; + ifv.cmd = ADD_VLAN_CMD; + if (ioctl(sockfd, SIOCSIFVLAN, (unsigned long)&ifv) < 0) + { + /* Handle error */ + } + close(sockfd); + } + + /* Enable the VLAN interface */ + + netdev_ifup("eth0.100"); + +.. code-block:: c + + #include + #include "netutils/netlib.h" + + /* Delete a VLAN interface (eth0.100, VLAN ID 100) */ + + FAR const char *ifname = "eth0.100"; + + int sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL); + + if (sockfd >= 0) + { + struct vlan_ioctl_args ifv; + + strncpy(ifv.vlan_devname, ifname, sizeof(ifv.device1)); + ifv.cmd = DEL_VLAN_CMD; + if (ioctl(sockfd, SIOCSIFVLAN, (unsigned long)&ifv) < 0) + { + /* Handle error */ + } + close(sockfd); + } \ No newline at end of file diff --git a/include/nuttx/net/ethernet.h b/include/nuttx/net/ethernet.h index 76a56b9b199ce..1d1454f517668 100644 --- a/include/nuttx/net/ethernet.h +++ b/include/nuttx/net/ethernet.h @@ -2,7 +2,8 @@ * include/nuttx/net/ethernet.h * * SPDX-License-Identifier: BSD-3-Clause - * SPDX-FileCopyrightText: 2007, 2009-2012, 2015 Gregory Nutt. All rights reserved. + * SPDX-FileCopyrightText: 2007, 2009-2012, 2015 Gregory Nutt. All rights + * reserved. * SPDX-FileCopyrightText: 2001-2003, Adam Dunkels. All rights reserved. * SPDX-FileContributor: Gregory Nutt * SPDX-FileContributor: Adam Dunkels @@ -63,6 +64,16 @@ #define TPID_8021QVLAN ETHERTYPE_VLAN +/* These are some control information associated with QVLAN tagged + * Ethernet packets. + */ + +#define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */ +#define VLAN_PRIO_SHIFT 13 +#define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator / Drop Eligible Indicator */ +#define VLAN_VID_MASK 0x0fff /* VLAN Identifier */ +#define VLAN_N_VID 4096 + /* These are some of the types associated with QVLAN tagged * Ethernet packets. */