1 /** @file
2  * @brief VLAN specific definitions.
3  *
4  * Virtual LAN specific definitions.
5  */
6 
7 /*
8  * Copyright (c) 2018 Intel Corporation
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  */
12 
13 #ifndef ZEPHYR_INCLUDE_NET_ETHERNET_VLAN_H_
14 #define ZEPHYR_INCLUDE_NET_ETHERNET_VLAN_H_
15 
16 /**
17  * @brief VLAN definitions and helpers
18  * @defgroup vlan_api Virtual LAN definitions and helpers
19  * @since 1.12
20  * @version 0.8.0
21  * @ingroup networking
22  * @{
23  */
24 
25 #include <zephyr/types.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /** Unspecified VLAN tag value */
32 #define NET_VLAN_TAG_UNSPEC 0x0fff
33 
34 /**
35  * @brief Get VLAN identifier from TCI.
36  *
37  * @param tci VLAN tag control information.
38  *
39  * @return VLAN identifier.
40  */
net_eth_vlan_get_vid(uint16_t tci)41 static inline uint16_t net_eth_vlan_get_vid(uint16_t tci)
42 {
43 	return tci & 0x0fff;
44 }
45 
46 /**
47  * @brief Get Drop Eligible Indicator from TCI.
48  *
49  * @param tci VLAN tag control information.
50  *
51  * @return Drop eligible indicator.
52  */
net_eth_vlan_get_dei(uint16_t tci)53 static inline uint8_t net_eth_vlan_get_dei(uint16_t tci)
54 {
55 	return (tci >> 12) & 0x01;
56 }
57 
58 /**
59  * @brief Get Priority Code Point from TCI.
60  *
61  * @param tci VLAN tag control information.
62  *
63  * @return Priority code point.
64  */
net_eth_vlan_get_pcp(uint16_t tci)65 static inline uint8_t net_eth_vlan_get_pcp(uint16_t tci)
66 {
67 	return (tci >> 13) & 0x07;
68 }
69 
70 /**
71  * @brief Set VLAN identifier to TCI.
72  *
73  * @param tci VLAN tag control information.
74  * @param vid VLAN identifier.
75  *
76  * @return New TCI value.
77  */
net_eth_vlan_set_vid(uint16_t tci,uint16_t vid)78 static inline uint16_t net_eth_vlan_set_vid(uint16_t tci, uint16_t vid)
79 {
80 	return (tci & 0xf000) | (vid & 0x0fff);
81 }
82 
83 /**
84  * @brief Set Drop Eligible Indicator to TCI.
85  *
86  * @param tci VLAN tag control information.
87  * @param dei Drop eligible indicator.
88  *
89  * @return New TCI value.
90  */
net_eth_vlan_set_dei(uint16_t tci,bool dei)91 static inline uint16_t net_eth_vlan_set_dei(uint16_t tci, bool dei)
92 {
93 	return (tci & 0xefff) | ((!!dei) << 12);
94 }
95 
96 /**
97  * @brief Set Priority Code Point to TCI.
98  *
99  * @param tci VLAN tag control information.
100  * @param pcp Priority code point.
101  *
102  * @return New TCI value.
103  */
net_eth_vlan_set_pcp(uint16_t tci,uint8_t pcp)104 static inline uint16_t net_eth_vlan_set_pcp(uint16_t tci, uint8_t pcp)
105 {
106 	return (tci & 0x1fff) | ((pcp & 0x07) << 13);
107 }
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 /**
114  * @}
115  */
116 
117 
118 #endif /* ZEPHYR_INCLUDE_NET_ETHERNET_VLAN_H_ */
119