mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-11-01 18:04:12 +08:00
Merge pull request #588 from DrDoof/feat/lldp-tx
lldp: complete the transmitted TLVs and announce shutdown
This commit is contained in:
3 files changed
+62
-7
No files matched your search
+41
-5
@@ -47,7 +47,7 @@ struct lldp_pkt {
|
||||
struct rtl_tag rtl_tag;
|
||||
uint16_t ether_type;
|
||||
|
||||
uint8_t payload[64];
|
||||
uint8_t payload[LLDP_MAX_PAYLOAD];
|
||||
};
|
||||
|
||||
#define LLDP_O ((__xdata struct lldp_pkt *)&uip_buf[RTL_FRAME_DESC_SIZE])
|
||||
@@ -59,7 +59,7 @@ struct lldp_pkt {
|
||||
// the length at any point
|
||||
#define LLDP_TYPE(value) (value << 1)
|
||||
|
||||
void lldp_send(void) __banked __reentrant
|
||||
static void lldp_send_ports(uint16_t ttl, uint16_t ports) __reentrant
|
||||
{
|
||||
__xdata uint8_t *p;
|
||||
uint8_t port_position;
|
||||
@@ -81,18 +81,44 @@ void lldp_send(void) __banked __reentrant
|
||||
*p++ = LLDP_TYPE(LLDP_PORT_ID_TLV_TYPE);
|
||||
*p++ = LLDP_PORT_ID_TLV_LENGTH;
|
||||
*p++ = LLDP_PORT_ID_TLV_SUBTYPE;
|
||||
memcpyc(p, LLDP_PORT_ID_PREFIX, LLDP_PORT_ID_PREFIX_LENGTH);
|
||||
p += LLDP_PORT_ID_PREFIX_LENGTH;
|
||||
port_position = (p-LLDP_O->payload);
|
||||
*p++ = '0'; // filled in per port below
|
||||
|
||||
//TTL
|
||||
*p++ = LLDP_TYPE(LLDP_TTL_TLV_TYPE);
|
||||
*p++ = LLDP_TTL_TLV_LENGTH;
|
||||
*p++ = 0x00; //padding
|
||||
*p++ = LLDP_TTL_TTL_SECONDS;
|
||||
*p++ = ttl >> 8;
|
||||
*p++ = ttl & 0xff;
|
||||
|
||||
p += lldp_sysname(p);
|
||||
p += lldp_sysdesc(p);
|
||||
|
||||
//System Capabilities: supported, enabled
|
||||
*p++ = LLDP_TYPE(LLDP_CAPABILITIES_TLV_TYPE);
|
||||
*p++ = LLDP_CAPABILITIES_TLV_LENGTH;
|
||||
*p++ = LLDP_CAPABILITY_BRIDGE >> 8;
|
||||
*p++ = LLDP_CAPABILITY_BRIDGE & 0xff;
|
||||
*p++ = LLDP_CAPABILITY_BRIDGE >> 8;
|
||||
*p++ = LLDP_CAPABILITY_BRIDGE & 0xff;
|
||||
|
||||
//Management Address: IPv4
|
||||
if (uip_hostaddr[0] | uip_hostaddr[1]) {
|
||||
*p++ = LLDP_TYPE(LLDP_MGMT_ADDR_TLV_TYPE);
|
||||
*p++ = LLDP_MGMT_ADDR_TLV_LENGTH;
|
||||
*p++ = LLDP_MGMT_ADDR_STR_LENGTH;
|
||||
*p++ = LLDP_MGMT_ADDR_SUBTYPE_IPV4;
|
||||
memcpy(p, (__xdata uint8_t *)uip_hostaddr, sizeof(uip_ipaddr_t));
|
||||
p += sizeof(uip_ipaddr_t);
|
||||
*p++ = LLDP_MGMT_IF_NUMBERING_UNKNOWN;
|
||||
*p++ = 0; //interface number
|
||||
*p++ = 0;
|
||||
*p++ = 0;
|
||||
*p++ = 0;
|
||||
*p++ = 0; //OID length
|
||||
}
|
||||
|
||||
// End of LLDPDU TLV
|
||||
*p++ = 0x00; //padding
|
||||
*p++ = 0x00; //padding
|
||||
@@ -115,7 +141,7 @@ void lldp_send(void) __banked __reentrant
|
||||
|
||||
for (uint8_t port = MACHINE_MIN_PORT; port <= MACHINE_MAX_PORT; port++) {
|
||||
|
||||
if ((1 << port) & lldp_logical_port_status) {
|
||||
if ((1 << port) & ports) {
|
||||
LLDP_O->payload[port_position] = '0' + machine.log_to_phys_port[port];
|
||||
LLDP_O->rtl_tag.pmask = HTONS((uint16_t)1 << port);
|
||||
|
||||
@@ -124,6 +150,16 @@ void lldp_send(void) __banked __reentrant
|
||||
}
|
||||
}
|
||||
|
||||
void lldp_send(void) __banked __reentrant
|
||||
{
|
||||
lldp_send_ports(LLDP_TTL_TTL_SECONDS, lldp_logical_port_status);
|
||||
}
|
||||
|
||||
void lldp_shutdown(uint16_t ports) __banked __reentrant
|
||||
{
|
||||
lldp_send_ports(0, ports);
|
||||
}
|
||||
|
||||
void lldp_set_addresses(void) __banked {
|
||||
// LLDP destination multicast addr: 01:80:c2:00:00:0e
|
||||
memcpyc(LLDP_O->dst.addr, "\x01\x80\xc2\x00\x00\x0e", MAC_ADDR_LEN);
|
||||
|
||||
Reference in new issue
Block a user