@@ -13,5 +13,81 @@ Vlan Device Drivers
1313- Supporting ADD_VLAN_CMD and DEL_VLAN_CMD of SIOCSIFVLAN.
1414- We add default PCP because some of our apps may not want to set
1515 PCP manually
16+ - ``include/nuttx/net/ethernet.h ``. Some definitions for 802.1Q VLAN
17+
18+ .. code-block :: c
19+
20+ #define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */
21+ #define VLAN_PRIO_SHIFT 13
22+ #define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator / Drop Eligible Indicator */
23+ #define VLAN_VID_MASK 0x0fff /* VLAN Identifier */
24+ #define VLAN_N_VID 4096
1625
1726 - **Driver **: ``drivers/net/vlan.c ``
27+
28+ Configuration Options
29+ =====================
30+
31+ ``CONFIG_NET_VLAN ``
32+ Enable 802.1Q VLAN interface support.
33+ ``CONFIG_NET_VLAN_COUNT ``
34+ Maximum number of VLAN interfaces per physical Ethernet interface.
35+
36+ Usage
37+ =====
38+
39+ .. code-block :: c
40+
41+ #include <nuttx/net/vlan.h>
42+ #include "netutils/netlib.h"
43+
44+ /* Create a VLAN interface (eth0.100, VLAN ID 100) */
45+
46+ FAR const char *ifname = "eth0";
47+ uint16_t vlanid = 100;
48+ uint8_t priority = 0; /* Default PCP */
49+
50+ int sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL);
51+
52+ if (sockfd >= 0)
53+ {
54+ struct vlan_ioctl_args ifv;
55+
56+ strncpy(ifv.vlan_devname, ifname, sizeof(ifv.device1));
57+ ifv.u.VID = vlanid;
58+ ifv.vlan_qos = priority;
59+ ifv.cmd = ADD_VLAN_CMD;
60+ if (ioctl(sockfd, SIOCSIFVLAN, (unsigned long)&ifv) < 0)
61+ {
62+ /* Handle error */
63+ }
64+ close(sockfd);
65+ }
66+
67+ /* Enable the VLAN interface */
68+
69+ netdev_ifup("eth0.100");
70+
71+ .. code-block :: c
72+
73+ #include <nuttx/net/vlan.h>
74+ #include "netutils/netlib.h"
75+
76+ /* Delete a VLAN interface (eth0.100, VLAN ID 100) */
77+
78+ FAR const char *ifname = "eth0.100";
79+
80+ int sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL);
81+
82+ if (sockfd >= 0)
83+ {
84+ struct vlan_ioctl_args ifv;
85+
86+ strncpy(ifv.vlan_devname, ifname, sizeof(ifv.device1));
87+ ifv.cmd = DEL_VLAN_CMD;
88+ if (ioctl(sockfd, SIOCSIFVLAN, (unsigned long)&ifv) < 0)
89+ {
90+ /* Handle error */
91+ }
92+ close(sockfd);
93+ }
0 commit comments