LCOV - code coverage report
Current view: top level - zephyr/net - ethernet_vlan.h Coverage Total Hit
Test: new.info Lines: 100.0 % 9 9
Test Date: 2025-09-05 22:20:39

            Line data    Source code
       1            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            1 : #define NET_VLAN_TAG_UNSPEC 0x0fff
      33              : 
      34              : /** VLAN ID for forwarding to the native interface (priority tagging) */
      35            1 : #define NET_VLAN_TAG_PRIORITY 0x0000
      36              : 
      37              : /**
      38              :  * @brief Get VLAN identifier from TCI.
      39              :  *
      40              :  * @param tci VLAN tag control information.
      41              :  *
      42              :  * @return VLAN identifier.
      43              :  */
      44            1 : static inline uint16_t net_eth_vlan_get_vid(uint16_t tci)
      45              : {
      46              :         return tci & 0x0fff;
      47              : }
      48              : 
      49              : /**
      50              :  * @brief Get Drop Eligible Indicator from TCI.
      51              :  *
      52              :  * @param tci VLAN tag control information.
      53              :  *
      54              :  * @return Drop eligible indicator.
      55              :  */
      56            1 : static inline uint8_t net_eth_vlan_get_dei(uint16_t tci)
      57              : {
      58              :         return (tci >> 12) & 0x01;
      59              : }
      60              : 
      61              : /**
      62              :  * @brief Get Priority Code Point from TCI.
      63              :  *
      64              :  * @param tci VLAN tag control information.
      65              :  *
      66              :  * @return Priority code point.
      67              :  */
      68            1 : static inline uint8_t net_eth_vlan_get_pcp(uint16_t tci)
      69              : {
      70              :         return (tci >> 13) & 0x07;
      71              : }
      72              : 
      73              : /**
      74              :  * @brief Set VLAN identifier to TCI.
      75              :  *
      76              :  * @param tci VLAN tag control information.
      77              :  * @param vid VLAN identifier.
      78              :  *
      79              :  * @return New TCI value.
      80              :  */
      81            1 : static inline uint16_t net_eth_vlan_set_vid(uint16_t tci, uint16_t vid)
      82              : {
      83              :         return (tci & 0xf000) | (vid & 0x0fff);
      84              : }
      85              : 
      86              : /**
      87              :  * @brief Set Drop Eligible Indicator to TCI.
      88              :  *
      89              :  * @param tci VLAN tag control information.
      90              :  * @param dei Drop eligible indicator.
      91              :  *
      92              :  * @return New TCI value.
      93              :  */
      94            1 : static inline uint16_t net_eth_vlan_set_dei(uint16_t tci, bool dei)
      95              : {
      96              :         return (tci & 0xefff) | ((!!dei) << 12);
      97              : }
      98              : 
      99              : /**
     100              :  * @brief Set Priority Code Point to TCI.
     101              :  *
     102              :  * @param tci VLAN tag control information.
     103              :  * @param pcp Priority code point.
     104              :  *
     105              :  * @return New TCI value.
     106              :  */
     107            1 : static inline uint16_t net_eth_vlan_set_pcp(uint16_t tci, uint8_t pcp)
     108              : {
     109              :         return (tci & 0x1fff) | ((pcp & 0x07) << 13);
     110              : }
     111              : 
     112              : #ifdef __cplusplus
     113              : }
     114              : #endif
     115              : 
     116              : /**
     117              :  * @}
     118              :  */
     119              : 
     120              : 
     121              : #endif /* ZEPHYR_INCLUDE_NET_ETHERNET_VLAN_H_ */
        

Generated by: LCOV version 2.0-1