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 * @ingroup networking 20 * @{ 21 */ 22 23 #include <zephyr/types.h> 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 /** Unspecified VLAN tag value */ 30 #define NET_VLAN_TAG_UNSPEC 0x0fff 31 32 /** 33 * @brief Get VLAN identifier from TCI. 34 * 35 * @param tci VLAN tag control information. 36 * 37 * @return VLAN identifier. 38 */ net_eth_vlan_get_vid(uint16_t tci)39static inline uint16_t net_eth_vlan_get_vid(uint16_t tci) 40 { 41 return tci & 0x0fff; 42 } 43 44 /** 45 * @brief Get Drop Eligible Indicator from TCI. 46 * 47 * @param tci VLAN tag control information. 48 * 49 * @return Drop eligible indicator. 50 */ net_eth_vlan_get_dei(uint16_t tci)51static inline uint8_t net_eth_vlan_get_dei(uint16_t tci) 52 { 53 return (tci >> 12) & 0x01; 54 } 55 56 /** 57 * @brief Get Priority Code Point from TCI. 58 * 59 * @param tci VLAN tag control information. 60 * 61 * @return Priority code point. 62 */ net_eth_vlan_get_pcp(uint16_t tci)63static inline uint8_t net_eth_vlan_get_pcp(uint16_t tci) 64 { 65 return (tci >> 13) & 0x07; 66 } 67 68 /** 69 * @brief Set VLAN identifier to TCI. 70 * 71 * @param tci VLAN tag control information. 72 * @param vid VLAN identifier. 73 * 74 * @return New TCI value. 75 */ net_eth_vlan_set_vid(uint16_t tci,uint16_t vid)76static inline uint16_t net_eth_vlan_set_vid(uint16_t tci, uint16_t vid) 77 { 78 return (tci & 0xf000) | (vid & 0x0fff); 79 } 80 81 /** 82 * @brief Set Drop Eligible Indicator to TCI. 83 * 84 * @param tci VLAN tag control information. 85 * @param dei Drop eligible indicator. 86 * 87 * @return New TCI value. 88 */ net_eth_vlan_set_dei(uint16_t tci,bool dei)89static inline uint16_t net_eth_vlan_set_dei(uint16_t tci, bool dei) 90 { 91 return (tci & 0xefff) | ((!!dei) << 12); 92 } 93 94 /** 95 * @brief Set Priority Code Point to TCI. 96 * 97 * @param tci VLAN tag control information. 98 * @param pcp Priority code point. 99 * 100 * @return New TCI value. 101 */ net_eth_vlan_set_pcp(uint16_t tci,uint8_t pcp)102static inline uint16_t net_eth_vlan_set_pcp(uint16_t tci, uint8_t pcp) 103 { 104 return (tci & 0x1fff) | ((pcp & 0x07) << 13); 105 } 106 107 #ifdef __cplusplus 108 } 109 #endif 110 111 /** 112 * @} 113 */ 114 115 116 #endif /* ZEPHYR_INCLUDE_NET_ETHERNET_VLAN_H_ */ 117