Hello Sergio, Simon,
I finally got the LLDP basic frame to work. I am able to send the LLDP frame out of my device and see the same correctly on the wire-shark.
However, do be able to make a proper source code out of it, I would need advise. The fields of the LLDP are static and not expected to change dynamically. Also it is up to the user to decide what is required in the fields and some of the field size may be configured at compile time. How do I do this within the framework of lwIP
As an example, following is the "hack-patch" code.
#if !LWIP_AUTOIP
static
#endif /* LWIP_AUTOIP */
err_t
lldp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr)
{
#if 1
struct pbuf *p;
err_t result = ERR_OK;
struct eth_hdr *ethhdr;
struct lldp_hdr *lldptlv;
LWIP_ASSERT("netif != NULL", netif != NULL);
/* allocate a pbuf for the outgoing ARP request packet */
p = pbuf_alloc(PBUF_RAW, SIZEOF_LLDP_PACKET, PBUF_RAM);
/* could allocate a pbuf for an ARP request? */
if (p == NULL) {
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS,
("etharp_raw: could not allocate pbuf for ARP request.\n"));
ETHARP_STATS_INC(etharp.memerr);
return ERR_MEM;
}
LWIP_ASSERT("check that first pbuf can hold struct etharp_hdr",
(p->len >= SIZEOF_LLDP_PACKET));
ethhdr = (struct eth_hdr *)p->payload;
lldptlv = (struct lldp_hdr *)((u8_t*)ethhdr + SIZEOF_ETH_HDR);
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_raw: sending raw ARP packet.\n"));
lldptlv->chassisid.tlvtype = 0x02;
lldptlv->chassisid.tlvlen = 0x07;
lldptlv->chassisid.tlvsubtype = 0x04;
ETHADDR16_COPY(&lldptlv->chassisid.tlvvalue,ethsrc_addr);
lldptlv->portid.tlvtype = 0x04;
lldptlv->portid.tlvlen = 0x07;
lldptlv->portid.tlvsubtype = 0x03;
ETHADDR16_COPY(&lldptlv->portid.tlvvalue,ethsrc_addr);
lldptlv->ttl.tlvtype = 0x06;
lldptlv->ttl.tlvlen = 0x07;
lldptlv->ttl.tlvsubtype = 0x00;
lldptlv->ttl.tlvvalue[0] = 0x10;
lldptlv->ttl.tlvvalue[1] = 0x00;
lldptlv->ttl.tlvvalue[2] = 0x00;
lldptlv->ttl.tlvvalue[3] = 0x00;
lldptlv->ttl.tlvvalue[4] = 0x00;
lldptlv->ttl.tlvvalue[5] = 0x00;
LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!",
(netif->hwaddr_len == ETHARP_HWADDR_LEN));
/* Write the Ethernet MAC-Addresses */
ETHADDR16_COPY(ðhdr->dest, ðlldpdestmac0);
ETHADDR16_COPY(ðhdr->src, ethsrc_addr);
ethhdr->type = PP_HTONS(ETHTYPE_LLDP);
/* send ARP query */
result = netif->linkoutput(netif, p);
//ETHARP_STATS_INC(etharp.xmit);
/* free ARP query packet */
pbuf_free(p);
p = NULL;
/* could not allocate pbuf for ARP request */
return result;
#endif
}
Regards