lldp_tlv.h File Reference

TLV parsing and formatting. More...

#include "core/net.h"
#include "lldp/lldp.h"

Go to the source code of this file.

Data Structures

struct  LldpTlv
 TLV structure. More...
 

Macros

#define LLDP_OUI_SIZE   3
 
#define LLDP_MAX_TLV_INFO_LEN   511
 
#define LLDP_MAX_ORG_SPECIFIC_INFO_LEN   507
 
#define LLDP_MIN_CHASSIS_ID_LEN   1
 
#define LLDP_MAX_CHASSIS_ID_LEN   255
 
#define LLDP_MIN_PORT_ID_LEN   1
 
#define LLDP_MAX_PORT_ID_LEN   255
 
#define LLDP_MIN_PORT_DESC_LEN   1
 
#define LLDP_MAX_PORT_DESC_LEN   255
 
#define LLDP_MIN_SYS_NAME_LEN   1
 
#define LLDP_MAX_SYS_NAME_LEN   255
 
#define LLDP_MIN_SYS_DESC_LEN   1
 
#define LLDP_MAX_SYS_DESC_LEN   255
 
#define LLDP_MIN_MGMT_ADDR_LEN   1
 
#define LLDP_MAX_MGMT_ADDR_LEN   31
 
#define LLDP_MIN_OID_LEN   0
 
#define LLDP_MAX_OID_LEN   128
 

Enumerations

enum  LldpTlvType {
  LLDP_TLV_TYPE_END_OF_LLDPDU = 0, LLDP_TLV_TYPE_CHASSIS_ID = 1, LLDP_TLV_TYPE_PORT_ID = 2, LLDP_TLV_TYPE_TIME_TO_LIVE = 3,
  LLDP_TLV_TYPE_PORT_DESC = 4, LLDP_TLV_TYPE_SYS_NAME = 5, LLDP_TLV_TYPE_SYS_DESC = 6, LLDP_TLV_TYPE_SYS_CAP = 7,
  LLDP_TLV_TYPE_MGMT_ADDR = 8, LLDP_TLV_TYPE_ORG_DEFINED = 127
}
 TLV type values. More...
 
enum  LldpChassisIdSubtype {
  LLDP_CHASSIS_ID_SUBTYPE_RESERVED = 0, LLDP_CHASSIS_ID_SUBTYPE_CHASSIS_COMPONENT = 1, LLDP_CHASSIS_ID_SUBTYPE_INTERFACE_ALIAS = 2, LLDP_CHASSIS_ID_SUBTYPE_PORT_COMPONENT = 3,
  LLDP_CHASSIS_ID_SUBTYPE_MAC_ADDR = 4, LLDP_CHASSIS_ID_SUBTYPE_NETWORK_ADDR = 5, LLDP_CHASSIS_ID_SUBTYPE_INTERFACE_NAME = 6, LLDP_CHASSIS_ID_SUBTYPE_LOCALLY_ASSIGNED = 7
}
 Chassis ID subtypes. More...
 
enum  LldpPortIdSubtype {
  LLDP_PORT_ID_SUBTYPE_RESERVED = 0, LLDP_PORT_ID_SUBTYPE_INTERFACE_ALIAS = 1, LLDP_PORT_ID_SUBTYPE_PORT_COMPONENT = 2, LLDP_PORT_ID_SUBTYPE_MAC_ADDR = 3,
  LLDP_PORT_ID_SUBTYPE_NETWORK_ADDR = 4, LLDP_PORT_ID_SUBTYPE_INTERFACE_NAME = 5, LLDP_PORT_ID_SUBTYPE_AGENT_CIRCUIT_ID = 6, LLDP_PORT_ID_SUBTYPE_LOCALLY_ASSIGNED = 7
}
 Port ID subtypes. More...
 
enum  LldpSysCap {
  LLDP_SYS_CAP_OTHER = 0x0001, LLDP_SYS_CAP_REPEATER = 0x0002, LLDP_SYS_CAP_BRIDGE = 0x0004, LLDP_SYS_CAP_WLAN_ACCESS_POINT = 0x0008,
  LLDP_SYS_CAP_ROUTER = 0x0010, LLDP_SYS_CAP_TELEPHONE = 0x0020, LLDP_SYS_CAP_DOCSIS_CABLE_DEVICE = 0x0040, LLDP_SYS_CAP_STATION_ONLY = 0x0080
}
 System capabilities. More...
 
enum  LldpMgmtAddrSubtype { LLDP_MGMT_ADDR_SUBTYPE_OTHER = 0, LLDP_MGMT_ADDR_SUBTYPE_IPV4 = 1, LLDP_MGMT_ADDR_SUBTYPE_IPV6 = 2, LLDP_MGMT_ADDR_SUBTYPE_ALL_802 = 6 }
 Management address subtypes. More...
 
enum  LldpIfNumSubtype { LLDP_IF_NUM_SUBTYPE_UNKNOWN = 1, LLDP_IF_NUM_SUBTYPE_IF_INDEX = 2, LLDP_IF_NUM_SUBTYPE_SYS_PORT_NUM = 3 }
 Interface numbering subtypes. More...
 
enum  LldpOui { LLDP_DOT1_OUI = 0x0080C2, LLDP_DOT3_OUI = 0x00120F, LLDP_MED_OUI = 0x0012BB, LLDP_PNO_OUI = 0x000ECF }
 Organizationally unique identifiers. More...
 

Functions

error_t lldpSetTlv (LldpDataUnit *lldpdu, uint8_t type, uint_t index, const uint8_t *value, size_t length, bool_t replace)
 Add or replace a TLV. More...
 
error_t lldpGetTlv (LldpDataUnit *lldpdu, uint8_t type, uint_t index, const uint8_t **value, size_t *length)
 Search a LLDPDU for a given TLV. More...
 
error_t lldpGetFirstTlv (LldpDataUnit *lldpdu, LldpTlv *tlv)
 Extract the first TLV from an LLDPDU. More...
 
error_t lldpGetNextTlv (LldpDataUnit *lldpdu, LldpTlv *tlv)
 Extract the next TLV from an LLDPDU. More...
 
error_t lldpDeleteTlv (LldpDataUnit *lldpdu, uint8_t type, uint_t index)
 Remove a TLV from a LLDPDU. More...
 
error_t lldpDecodeMgmtAddrTlv (const uint8_t *value, size_t length, const LldpMgmtAddrTlv1 **mgmtAddr1, const LldpMgmtAddrTlv2 **mgmtAddr2)
 Decode the contents of a Management Address TLV. More...
 
error_t lldpSetOrgDefTlv (LldpDataUnit *lldpdu, uint32_t oui, uint8_t subtype, uint_t index, const uint8_t *value, size_t length, bool_t replace)
 Add or replace an organizationally specific TLV. More...
 
error_t lldpGetOrgDefTlv (LldpDataUnit *lldpdu, uint32_t oui, uint8_t subtype, uint_t index, const uint8_t **value, size_t *length)
 Search an LLDPDU for an organizationally specific TLV. More...
 
error_t lldpDeleteOrgDefTlv (LldpDataUnit *lldpdu, uint32_t oui, uint8_t subtype, uint_t index)
 Remove an organizationally specific TLV from a LLDPDU. More...
 

Variables

typedef __packed_struct
 TLV header. More...
 
uint8_t type
 
uint8_t lengthL
 
uint8_t value []
 
 LldpTlvHeader
 
uint8_t chassisId []
 
 LldpChassisIdTlv
 
uint8_t portId []
 
 LldpPortIdTlv
 
 LldpTimeToLiveTlv
 
uint16_t enabledCap
 
 LldpSysCapTlv
 
uint8_t mgmtAddrSubtype
 
uint8_t mgmtAddr []
 
 LldpMgmtAddrTlv1
 
uint32_t ifNum
 
uint8_t oidLen
 
uint8_t oid []
 
 LldpMgmtAddrTlv2
 
uint8_t subtype
 
 LldpOrgDefTlv
 

Detailed Description

TLV parsing and formatting.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file lldp_tlv.h.

Macro Definition Documentation

◆ LLDP_MAX_CHASSIS_ID_LEN

#define LLDP_MAX_CHASSIS_ID_LEN   255

Definition at line 49 of file lldp_tlv.h.

◆ LLDP_MAX_MGMT_ADDR_LEN

#define LLDP_MAX_MGMT_ADDR_LEN   31

Definition at line 74 of file lldp_tlv.h.

◆ LLDP_MAX_OID_LEN

#define LLDP_MAX_OID_LEN   128

Definition at line 79 of file lldp_tlv.h.

◆ LLDP_MAX_ORG_SPECIFIC_INFO_LEN

#define LLDP_MAX_ORG_SPECIFIC_INFO_LEN   507

Definition at line 44 of file lldp_tlv.h.

◆ LLDP_MAX_PORT_DESC_LEN

#define LLDP_MAX_PORT_DESC_LEN   255

Definition at line 59 of file lldp_tlv.h.

◆ LLDP_MAX_PORT_ID_LEN

#define LLDP_MAX_PORT_ID_LEN   255

Definition at line 54 of file lldp_tlv.h.

◆ LLDP_MAX_SYS_DESC_LEN

#define LLDP_MAX_SYS_DESC_LEN   255

Definition at line 69 of file lldp_tlv.h.

◆ LLDP_MAX_SYS_NAME_LEN

#define LLDP_MAX_SYS_NAME_LEN   255

Definition at line 64 of file lldp_tlv.h.

◆ LLDP_MAX_TLV_INFO_LEN

#define LLDP_MAX_TLV_INFO_LEN   511

Definition at line 42 of file lldp_tlv.h.

◆ LLDP_MIN_CHASSIS_ID_LEN

#define LLDP_MIN_CHASSIS_ID_LEN   1

Definition at line 47 of file lldp_tlv.h.

◆ LLDP_MIN_MGMT_ADDR_LEN

#define LLDP_MIN_MGMT_ADDR_LEN   1

Definition at line 72 of file lldp_tlv.h.

◆ LLDP_MIN_OID_LEN

#define LLDP_MIN_OID_LEN   0

Definition at line 77 of file lldp_tlv.h.

◆ LLDP_MIN_PORT_DESC_LEN

#define LLDP_MIN_PORT_DESC_LEN   1

Definition at line 57 of file lldp_tlv.h.

◆ LLDP_MIN_PORT_ID_LEN

#define LLDP_MIN_PORT_ID_LEN   1

Definition at line 52 of file lldp_tlv.h.

◆ LLDP_MIN_SYS_DESC_LEN

#define LLDP_MIN_SYS_DESC_LEN   1

Definition at line 67 of file lldp_tlv.h.

◆ LLDP_MIN_SYS_NAME_LEN

#define LLDP_MIN_SYS_NAME_LEN   1

Definition at line 62 of file lldp_tlv.h.

◆ LLDP_OUI_SIZE

#define LLDP_OUI_SIZE   3

Definition at line 39 of file lldp_tlv.h.

Enumeration Type Documentation

◆ LldpChassisIdSubtype

Chassis ID subtypes.

Enumerator
LLDP_CHASSIS_ID_SUBTYPE_RESERVED 

Reserved.

LLDP_CHASSIS_ID_SUBTYPE_CHASSIS_COMPONENT 

Chassis component.

LLDP_CHASSIS_ID_SUBTYPE_INTERFACE_ALIAS 

Interface alias.

LLDP_CHASSIS_ID_SUBTYPE_PORT_COMPONENT 

Port component.

LLDP_CHASSIS_ID_SUBTYPE_MAC_ADDR 

MAC address.

LLDP_CHASSIS_ID_SUBTYPE_NETWORK_ADDR 

Network address.

LLDP_CHASSIS_ID_SUBTYPE_INTERFACE_NAME 

Interface name.

LLDP_CHASSIS_ID_SUBTYPE_LOCALLY_ASSIGNED 

Locally assigned.

Definition at line 110 of file lldp_tlv.h.

◆ LldpIfNumSubtype

Interface numbering subtypes.

Enumerator
LLDP_IF_NUM_SUBTYPE_UNKNOWN 

Unknown.

LLDP_IF_NUM_SUBTYPE_IF_INDEX 

Interface index.

LLDP_IF_NUM_SUBTYPE_SYS_PORT_NUM 

System port number.

Definition at line 174 of file lldp_tlv.h.

◆ LldpMgmtAddrSubtype

Management address subtypes.

Enumerator
LLDP_MGMT_ADDR_SUBTYPE_OTHER 

Other.

LLDP_MGMT_ADDR_SUBTYPE_IPV4 

IPv4 address.

LLDP_MGMT_ADDR_SUBTYPE_IPV6 

IPv6 address.

LLDP_MGMT_ADDR_SUBTYPE_ALL_802 

MAC address.

Definition at line 161 of file lldp_tlv.h.

◆ LldpOui

enum LldpOui

Organizationally unique identifiers.

Enumerator
LLDP_DOT1_OUI 

IEEE 802.1.

LLDP_DOT3_OUI 

IEEE 802.3.

LLDP_MED_OUI 

LLDP-MED.

LLDP_PNO_OUI 

PROFIBUS.

Definition at line 186 of file lldp_tlv.h.

◆ LldpPortIdSubtype

Port ID subtypes.

Enumerator
LLDP_PORT_ID_SUBTYPE_RESERVED 

Reserved.

LLDP_PORT_ID_SUBTYPE_INTERFACE_ALIAS 

Interface alias.

LLDP_PORT_ID_SUBTYPE_PORT_COMPONENT 

Port component.

LLDP_PORT_ID_SUBTYPE_MAC_ADDR 

MAC address.

LLDP_PORT_ID_SUBTYPE_NETWORK_ADDR 

Network address.

LLDP_PORT_ID_SUBTYPE_INTERFACE_NAME 

Interface name.

LLDP_PORT_ID_SUBTYPE_AGENT_CIRCUIT_ID 

Agent circuit ID.

LLDP_PORT_ID_SUBTYPE_LOCALLY_ASSIGNED 

Locally assigned.

Definition at line 127 of file lldp_tlv.h.

◆ LldpSysCap

enum LldpSysCap

System capabilities.

Enumerator
LLDP_SYS_CAP_OTHER 

Other.

LLDP_SYS_CAP_REPEATER 

Repeater.

LLDP_SYS_CAP_BRIDGE 

Bridge.

LLDP_SYS_CAP_WLAN_ACCESS_POINT 

WLAN Access Point.

LLDP_SYS_CAP_ROUTER 

Router.

LLDP_SYS_CAP_TELEPHONE 

Telephone.

LLDP_SYS_CAP_DOCSIS_CABLE_DEVICE 

DOCSIS cable device.

LLDP_SYS_CAP_STATION_ONLY 

Station Only.

Definition at line 144 of file lldp_tlv.h.

◆ LldpTlvType

TLV type values.

Enumerator
LLDP_TLV_TYPE_END_OF_LLDPDU 

End Of LLDPDU.

LLDP_TLV_TYPE_CHASSIS_ID 

Chassis ID.

LLDP_TLV_TYPE_PORT_ID 

Port ID.

LLDP_TLV_TYPE_TIME_TO_LIVE 

Time To Live.

LLDP_TLV_TYPE_PORT_DESC 

Port Description.

LLDP_TLV_TYPE_SYS_NAME 

System Name.

LLDP_TLV_TYPE_SYS_DESC 

System Description.

LLDP_TLV_TYPE_SYS_CAP 

System Capabilities.

LLDP_TLV_TYPE_MGMT_ADDR 

Management Address.

LLDP_TLV_TYPE_ORG_DEFINED 

Organizationally Specific TLVs.

Definition at line 91 of file lldp_tlv.h.

Function Documentation

◆ lldpDecodeMgmtAddrTlv()

error_t lldpDecodeMgmtAddrTlv ( const uint8_t *  value,
size_t  length,
const LldpMgmtAddrTlv1 **  mgmtAddr1,
const LldpMgmtAddrTlv2 **  mgmtAddr2 
)

Decode the contents of a Management Address TLV.

Parameters
[in]valuePointer to the TLV value to decode
[in]lengthLength of the TLV value, in bytes
[out]mgmtAddr1First part of the Management Address TLV
[out]mgmtAddr2Second part of the Management Address TLV
Returns
Error code

Definition at line 380 of file lldp_tlv.c.

◆ lldpDeleteOrgDefTlv()

error_t lldpDeleteOrgDefTlv ( LldpDataUnit lldpdu,
uint32_t  oui,
uint8_t  subtype,
uint_t  index 
)

Remove an organizationally specific TLV from a LLDPDU.

Parameters
[in]lldpduPointer to the LLDP data unit
[in]ouiOrganizationally unique identifier
[in]subtypeOrganizationally defined subtype
[in]indexTLV occurrence index
Returns
Error code

Definition at line 719 of file lldp_tlv.c.

◆ lldpDeleteTlv()

error_t lldpDeleteTlv ( LldpDataUnit lldpdu,
uint8_t  type,
uint_t  index 
)

Remove a TLV from a LLDPDU.

Parameters
[in]lldpduPointer to the LLDP data unit
[in]typeTLV type
[in]indexTLV occurrence index
Returns
Error code

Definition at line 320 of file lldp_tlv.c.

◆ lldpGetFirstTlv()

error_t lldpGetFirstTlv ( LldpDataUnit lldpdu,
LldpTlv tlv 
)

Extract the first TLV from an LLDPDU.

Parameters
[in]lldpduPointer to the LLDP data unit
[out]tlvNext TLV
Returns
Error code

Definition at line 247 of file lldp_tlv.c.

◆ lldpGetNextTlv()

error_t lldpGetNextTlv ( LldpDataUnit lldpdu,
LldpTlv tlv 
)

Extract the next TLV from an LLDPDU.

Parameters
[in]lldpduPointer to the LLDP data unit
[out]tlvNext TLV
Returns
Error code

Definition at line 264 of file lldp_tlv.c.

◆ lldpGetOrgDefTlv()

error_t lldpGetOrgDefTlv ( LldpDataUnit lldpdu,
uint32_t  oui,
uint8_t  subtype,
uint_t  index,
const uint8_t **  value,
size_t *  length 
)

Search an LLDPDU for an organizationally specific TLV.

Parameters
[in]lldpduPointer to the LLDP data unit
[in]ouiOrganizationally unique identifier
[in]subtypeOrganizationally defined subtype
[in]indexTLV occurrence index
[out]valueOrganizationally defined information string
[out]lengthLength of the information string, in bytes
Returns
Error code

Definition at line 651 of file lldp_tlv.c.

◆ lldpGetTlv()

error_t lldpGetTlv ( LldpDataUnit lldpdu,
uint8_t  type,
uint_t  index,
const uint8_t **  value,
size_t *  length 
)

Search a LLDPDU for a given TLV.

Parameters
[in]lldpduPointer to the LLDP data unit
[in]typeTLV type
[in]indexTLV occurrence index
[out]valueTLV information string
[out]lengthLength of the information string, in bytes
Returns
Error code

Definition at line 200 of file lldp_tlv.c.

◆ lldpSetOrgDefTlv()

error_t lldpSetOrgDefTlv ( LldpDataUnit lldpdu,
uint32_t  oui,
uint8_t  subtype,
uint_t  index,
const uint8_t *  value,
size_t  length,
bool_t  replace 
)

Add or replace an organizationally specific TLV.

Parameters
[in]lldpduPointer to the LLDP data unit
[in]ouiOrganizationally unique identifier
[in]subtypeOrganizationally defined subtype
[in]indexTLV occurrence index
[in]valueOrganizationally defined information string
[in]lengthLength of the information string, in bytes
[in]replaceReplace the existing TLV if a match is found
Returns
Error code

Definition at line 452 of file lldp_tlv.c.

◆ lldpSetTlv()

error_t lldpSetTlv ( LldpDataUnit lldpdu,
uint8_t  type,
uint_t  index,
const uint8_t *  value,
size_t  length,
bool_t  replace 
)

Add or replace a TLV.

Parameters
[in]lldpduPointer to the LLDP data unit
[in]typeTLV type
[in]indexTLV occurrence index
[in]valueTLV information string
[in]lengthLength of the information string, in bytes
[in]replaceReplace the existing TLV if a match is found
Returns
Error code

Definition at line 56 of file lldp_tlv.c.

Variable Documentation

◆ __packed_struct

typedef __packed_struct
Initial value:
{
uint8_t lengthH : 1

TLV header.

Organizationally Specific TLV.

Management Address TLV (part 2)

Management Address TLV (part 1)

System Capabilities TLV.

Time To Live TLV.

Port ID TLV.

Chassis ID TLV.

Definition at line 220 of file lldp_tlv.h.

◆ chassisId

uint8_t chassisId[]

Definition at line 243 of file lldp_tlv.h.

◆ enabledCap

uint16_t enabledCap

Definition at line 275 of file lldp_tlv.h.

◆ ifNum

uint32_t ifNum

Definition at line 298 of file lldp_tlv.h.

◆ lengthL

uint8_t lengthL

Definition at line 230 of file lldp_tlv.h.

◆ LldpChassisIdTlv

LldpChassisIdTlv

Definition at line 244 of file lldp_tlv.h.

◆ LldpMgmtAddrTlv1

LldpMgmtAddrTlv1

Definition at line 288 of file lldp_tlv.h.

◆ LldpMgmtAddrTlv2

LldpMgmtAddrTlv2

Definition at line 301 of file lldp_tlv.h.

◆ LldpOrgDefTlv

LldpOrgDefTlv

Definition at line 313 of file lldp_tlv.h.

◆ LldpPortIdTlv

LldpPortIdTlv

Definition at line 255 of file lldp_tlv.h.

◆ LldpSysCapTlv

LldpSysCapTlv

Definition at line 276 of file lldp_tlv.h.

◆ LldpTimeToLiveTlv

LldpTimeToLiveTlv

Definition at line 265 of file lldp_tlv.h.

◆ LldpTlvHeader

LldpTlvHeader

Definition at line 233 of file lldp_tlv.h.

◆ mgmtAddr

uint8_t mgmtAddr[]

Definition at line 287 of file lldp_tlv.h.

◆ mgmtAddrSubtype

uint8_t mgmtAddrSubtype

Definition at line 286 of file lldp_tlv.h.

◆ oid

uint8_t oid[]

Definition at line 300 of file lldp_tlv.h.

◆ oidLen

uint8_t oidLen

Definition at line 299 of file lldp_tlv.h.

◆ portId

uint8_t portId[]

Definition at line 254 of file lldp_tlv.h.

◆ subtype

uint8_t subtype

Definition at line 311 of file lldp_tlv.h.

◆ type

uint8_t type

Definition at line 229 of file lldp_tlv.h.

◆ value

uint8_t value[]

Definition at line 231 of file lldp_tlv.h.