From: Michel Stam Date: Mon, 21 Jul 2014 14:40:41 +0000 (+0200) Subject: cdp: Add power requirement to CDPv2 frames X-Git-Tag: 0.7.10~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=619c379964fd317257cad11c220aebe13f73d552;p=thirdparty%2Flldpd.git cdp: Add power requirement to CDPv2 frames LLDP already supports sending power requirements, for IEEE 802.3at. Older Cisco PoE switches do not support LLDP and need a custom CDPv2 frame. This patch enables support if the LLDP MED PoE frame is also sent. --- diff --git a/src/daemon/cdp.c b/src/daemon/cdp.c index 2ff57421..4974b00e 100644 --- a/src/daemon/cdp.c +++ b/src/daemon/cdp.c @@ -34,6 +34,7 @@ cdp_send(struct lldpd *global, const char *platform = "Linux"; struct lldpd_chassis *chassis; struct lldpd_mgmt *mgmt; + struct lldpd_port *port; u_int8_t mcastaddr[] = CDP_MULTICAST_ADDR; u_int8_t llcorg[] = LLC_ORG_CISCO; #ifdef ENABLE_FDP @@ -47,7 +48,8 @@ cdp_send(struct lldpd *global, log_debug("cdp", "send CDP frame on %s", hardware->h_ifname); - chassis = hardware->h_lport.p_chassis; + port = &(hardware->h_lport); + chassis = port->p_chassis; #ifdef ENABLE_FDP if (version == 0) { @@ -202,6 +204,21 @@ cdp_send(struct lldpd *global, POKE_BYTES(platform, strlen(platform)) && POKE_END_CDP_TLV)) goto toobig; + +#ifdef ENABLE_LLDPMED + /* Power use */ + if ((version >= 2) && + port->p_med_cap_enabled && + (port->p_med_power.source != LLDP_MED_POW_SOURCE_LOCAL) && + (port->p_med_power.val > 0) && + (port->p_med_power.val <= 655)) { + if (!( + POKE_START_CDP_TLV(CDP_TLV_POWER_CONSUMPTION) && + POKE_UINT16(port->p_med_power.val * 100) && + POKE_END_CDP_TLV)) + goto toobig; + } +#endif (void)POKE_SAVE(end); /* Compute len and checksum */ diff --git a/src/daemon/cdp.h b/src/daemon/cdp.h index a84601ab..e2d26306 100644 --- a/src/daemon/cdp.h +++ b/src/daemon/cdp.h @@ -43,7 +43,8 @@ enum { CDP_TLV_CAPABILITIES = 4, CDP_TLV_SOFTWARE = 5, CDP_TLV_PLATFORM = 6, - CDP_TLV_NATIVEVLAN = 10 + CDP_TLV_NATIVEVLAN = 10, + CDP_TLV_POWER_CONSUMPTION = 16 }; #define CDP_ADDRESS_PROTO_IP 0xcc